aboutsummaryrefslogtreecommitdiff
path: root/gcc/testlib
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-07-22 10:45:37 +0200
committerEugen Wissner <belka@caraus.de>2026-07-22 10:46:39 +0200
commitbd9fe800349dc139cc5841980bcae96e0d18e2db (patch)
tree749202e865dd63b4cc7180c786918c6317597d05 /gcc/testlib
parent5cc2947143f2a6ebd4ef1ae4d25ab956b87de808 (diff)
downloadelna-bd9fe800349dc139cc5841980bcae96e0d18e2db.tar.gz
Support multi-module GCC tests
Diffstat (limited to 'gcc/testlib')
-rw-r--r--gcc/testlib/elna-dg.exp127
1 files changed, 102 insertions, 25 deletions
diff --git a/gcc/testlib/elna-dg.exp b/gcc/testlib/elna-dg.exp
index 5142884..93c7762 100644
--- a/gcc/testlib/elna-dg.exp
+++ b/gcc/testlib/elna-dg.exp
@@ -88,7 +88,7 @@ proc elna-convert-directive { line_var directive dg_name } {
# base - absolute path to the source directory, e.g. .../testsuite/elna.dg
# test - relative path from testsuite, e.g. fail_compilation/file_name.elna
#
-proc elna-convert-test { base test } {
+proc elna-convert-test { base test { extra_lines "" } } {
set type [file dirname $test]
set target $test
@@ -108,11 +108,17 @@ proc elna-convert-test { base test } {
close $fin
+ # Append caller-supplied extra directives (e.g. dg-additional-sources).
+ foreach line $extra_lines {
+ puts $fout $line
+ }
+
# Suppress excess output so stray diagnostics do not fail the test.
puts $fout "(* { dg-prune-output .* } *)"
# Emit category-specific expectation.
- switch $type {
+ set category [lindex [file split $test] 0]
+ switch $category {
compilable {
# Assert that an output file was produced.
puts $fout "(* { dg-final { output-exists } } *)"
@@ -126,7 +132,7 @@ proc elna-convert-test { base test } {
close $fout
- # Reaches up one stack frame (into elna-dg-runtest) and links the
+ # Reaches up one stack frame (into the runtest proc) and links the
# caller's cleanup_extra_files variable to the local name cleanups.
upvar 1 cleanup_extra_files cleanups
# This ensures the converted file gets deleted after the test runs.
@@ -136,40 +142,111 @@ proc elna-convert-test { base test } {
}
#
-# Main loop for convert each test to dejagnu.
+# Handles a multi-module test directory.
#
-proc elna-dg-runtest { testcases } {
+# Requires sut.elna (system under test) as the primary module;
+# all other .elna files are passed as dg-additional-sources.
+#
+# base - absolute path to the source directory.
+# test - relative path from testsuite, e.g. group/test_name.
+#
+proc elna-handle-multimodule { base test } {
+ upvar 1 cleanup_extra_files cleanups
+
+ set dir "$base/$test"
+
+ # Find all .elna files recursively inside the test directory.
+ set modules [lsort [find $dir *.elna]]
+ if { [llength $modules] == 0 } {
+ return ""
+ }
+
+ # Allocate sut.elna as the primary module, collect the rest.
+ set main_module ""
+ set extra_sources ""
+ foreach module $modules {
+ if { [file tail $module] == "sut.elna" } {
+ set main_module $module
+ } else {
+ lappend extra_sources $module
+ }
+ }
+ if { $main_module == "" } {
+ error "multi-module test directory \"$test\" must contain sut.elna"
+ }
+
+ # Build extra directives: -I for imports and dg-additional-sources.
+ set extra_lines ""
+ lappend extra_lines "(* { dg-additional-options \"-I$dir\" } *)"
+ foreach src $extra_sources {
+ set src_rel [string range $src [expr {[string length $dir] + 1}] end]
+ file copy $src $test
+ lappend cleanups [file join $test $src_rel]
+ lappend extra_lines "(* { dg-additional-sources \"$src_rel\" } *)"
+ }
+
+ # Convert the primary module, passing the extra directives.
+ set main_rel [file join $test [file tail $main_module]]
+ return [elna-convert-test $base $main_rel $extra_lines]
+}
+
+#
+# Runs a converted test file through dejagnu and cleans up afterwards.
+#
+proc elna-dg-run-one { target type cleanup_extra_files } {
+ global dg-do-what-default
+
+ switch $type {
+ runnable { set dg-do-what-default "run" }
+ default { set dg-do-what-default "compile" }
+ }
+
+ dg-test $target "" ""
+ file delete $target
+ foreach srcfile $cleanup_extra_files {
+ file delete $srcfile
+ }
+}
+
+#
+# Converts and runs single-module .elna test files.
+#
+proc elna-dg-runtest-single { testcases } {
global dg-do-what-default
- # Saves dejagnu's current "what to do" setting so different test
- # types don't leak settings between tests.
set saved-dg-do-what-default ${dg-do-what-default}
foreach test $testcases {
set type [file tail [file dirname $test]]
set name [file tail $test]
set base [file dirname [file dirname $test]]
-
set cleanup_extra_files ""
- # Calls the converter, $target receives the relative path of
- # the converted file.
- set target "[elna-convert-test $base $type/$name]"
-
- switch $type {
- runnable {
- set dg-do-what-default "run"
- }
- compilable -
- fail_compilation {
- set dg-do-what-default "compile"
- }
- }
- dg-test $target "" ""
+ set target [elna-convert-test $base $type/$name]
+ elna-dg-run-one $target $type $cleanup_extra_files
+ }
+
+ set dg-do-what-default ${saved-dg-do-what-default}
+}
+
+#
+# Converts and runs multi-module test directories.
+#
+proc elna-dg-runtest-multi { testcases } {
+ global dg-do-what-default
+ set saved-dg-do-what-default ${dg-do-what-default}
+
+ foreach test $testcases {
+ set type [file tail [file dirname $test]]
+ set name [file tail $test]
+ set base [file dirname [file dirname $test]]
+ set cleanup_extra_files ""
- foreach srcfile $cleanup_extra_files {
- file delete $srcfile
+ set target [elna-handle-multimodule $base $type/$name]
+ if { $target == "" } {
+ continue
}
- file delete $target
+
+ elna-dg-run-one $target $type $cleanup_extra_files
}
set dg-do-what-default ${saved-dg-do-what-default}