diff options
Diffstat (limited to 'gcc/testsuite/lib')
-rw-r--r-- | gcc/testsuite/lib/gcc-dg.exp | 1 | ||||
-rw-r--r-- | gcc/testsuite/lib/htmltest.py | 9 | ||||
-rw-r--r-- | gcc/testsuite/lib/scanhtml.exp | 90 |
3 files changed, 100 insertions, 0 deletions
diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp index 6dd8fa3..312c4b8 100644 --- a/gcc/testsuite/lib/gcc-dg.exp +++ b/gcc/testsuite/lib/gcc-dg.exp @@ -26,6 +26,7 @@ load_lib scanipa.exp load_lib scanwpaipa.exp load_lib scanlang.exp load_lib scansarif.exp +load_lib scanhtml.exp load_lib timeout.exp load_lib timeout-dg.exp load_lib prune.exp diff --git a/gcc/testsuite/lib/htmltest.py b/gcc/testsuite/lib/htmltest.py new file mode 100644 index 0000000..b249ea6 --- /dev/null +++ b/gcc/testsuite/lib/htmltest.py @@ -0,0 +1,9 @@ +import os +import xml.etree.ElementTree as ET + +def html_tree_from_env(): + # return parsed HTML content as an ET from an HTML_PATH file + html_filename = os.environ['HTML_PATH'] + html_filename += '.html' + print('html_filename: %r' % html_filename) + return ET.parse(html_filename) diff --git a/gcc/testsuite/lib/scanhtml.exp b/gcc/testsuite/lib/scanhtml.exp new file mode 100644 index 0000000..6d8f398 --- /dev/null +++ b/gcc/testsuite/lib/scanhtml.exp @@ -0,0 +1,90 @@ +# Copyright (C) 2000-2025 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. + +# Various utilities for scanning HTML output, used by gcc-dg.exp and +# g++-dg.exp. +# +# This is largely borrowed from scansarif.exp. + +proc html-pytest-format-line { args } { + global subdir + + set testcase [lindex $args 0] + set pytest_script [lindex $args 1] + set output_line [lindex $args 2] + + set index [string first "::" $output_line] + set test_output [string range $output_line [expr $index + 2] [string length $output_line]] + + return "$subdir/$testcase ${pytest_script}::${test_output}" +} + +# Call by dg-final to run a pytest Python script. +# We pass filename of a test via HTML_PATH environment variable. + +proc run-html-pytest { args } { + global srcdir subdir + # Extract the test file name from the arguments. + set testcase [lindex $args 0] + + verbose "Running HTML $testcase in $srcdir/$subdir" 2 + set testcase [remote_download host $testcase] + + set pytest_script [lindex $args 1] + if { ![check_effective_target_pytest3] } { + unsupported "$pytest_script pytest python3 is missing" + return + } + + setenv HTML_PATH $testcase + set libdir "${srcdir}/lib" + + # Set/prepend libdir to PYTHONPATH + if [info exists ::env(PYTHONPATH)] { + set old_PYTHONPATH $::env(PYTHONPATH) + setenv PYTHONPATH "${libdir}:${old_PYTHONPATH}" + } else { + setenv PYTHONPATH "${libdir}" + } + + verbose "PYTHONPATH=[getenv PYTHONPATH]" 2 + + spawn -noecho python3 -m pytest --color=no -rap -s --tb=no $srcdir/$subdir/$pytest_script + + if [info exists old_PYTHONPATH] { + setenv PYTHONPATH ${old_PYTHONPATH} + } + + set prefix "\[^\r\n\]*" + expect { + -re "FAILED($prefix)\[^\r\n\]+\r\n" { + set output [html-pytest-format-line $testcase $pytest_script $expect_out(1,string)] + fail $output + exp_continue + } + -re "ERROR($prefix)\[^\r\n\]+\r\n" { + set output [html-pytest-format-line $testcase $pytest_script $expect_out(1,string)] + fail $output + exp_continue + } + -re "PASSED($prefix)\[^\r\n\]+\r\n" { + set output [html-pytest-format-line $testcase $pytest_script $expect_out(1,string)] + pass $output + exp_continue + } + } +} + |