aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/dg.exp5
-rw-r--r--gcc/testlib/elna-dg.exp127
-rw-r--r--testsuite/runnable/multi_module/helper.elna4
-rw-r--r--testsuite/runnable/multi_module/sut.elna5
4 files changed, 115 insertions, 26 deletions
diff --git a/gcc/dg.exp b/gcc/dg.exp
index a490409..71e7105 100644
--- a/gcc/dg.exp
+++ b/gcc/dg.exp
@@ -23,7 +23,10 @@ load_lib elna-dg.exp
dg-init
# Main loop.
-elna-dg-runtest [lsort [find $srcdir/$subdir *.elna]]
+# Single-module .elna files and multi-module directories,
+# both exactly one level below the category directories.
+elna-dg-runtest-single [lsort [glob -nocomplain $srcdir/$subdir/*/*.elna]]
+elna-dg-runtest-multi [lsort [glob -nocomplain -type d $srcdir/$subdir/*/*]]
# All done.
dg-finish
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}
diff --git a/testsuite/runnable/multi_module/helper.elna b/testsuite/runnable/multi_module/helper.elna
new file mode 100644
index 0000000..9148ba6
--- /dev/null
+++ b/testsuite/runnable/multi_module/helper.elna
@@ -0,0 +1,4 @@
+proc multiply*(x, y: Int): Int
+return x * y
+
+end.
diff --git a/testsuite/runnable/multi_module/sut.elna b/testsuite/runnable/multi_module/sut.elna
new file mode 100644
index 0000000..fb26a26
--- /dev/null
+++ b/testsuite/runnable/multi_module/sut.elna
@@ -0,0 +1,5 @@
+import helper
+
+begin
+ assert(multiply(3, 4) = 12)
+end.