From: Jonathan Wakely Date: Wed, 13 Sep 2023 09:57:08 +0000 (+0100) Subject: libstdc++: Support dg-additional-files in tests X-Git-Tag: basepoints/gcc-15~6148 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9da3c935e3f46e32d9f801f07916634dc9a65886;p=thirdparty%2Fgcc.git libstdc++: Support dg-additional-files in tests Some tests rely on text files with specific content being present in the test directory. This has historically been done by copying testsuite/data/*.tst and testsuite/data/*.txt to the test dir at the start, in the libstdc++_init procedure. Some tests modify their data files, so if the same test runs more than once in the same directory the second and subsequent tests will see the modified files, and FAIL because the content of the file is not in the expected state. This change adds support for the dg-additional-files directive from the main compiler testsuite and changes v3_target_compile to copy the specified files to the directory where the test will run. This ensures that a fresh copy of the files is present each time the test runs. Eventually all tests could be transitioned to use dg-additional-files and then libstdc++_init could be changed to remove the initial copy of all files. This change only adds dg-additional-files to the tests that modify their files and FAIL when re-run in the same directory. The tests that rely on additional data files have comments containing the strings "@require@" and "@diff@" which seem to be related to the libstdc++-v3/mkcheck.in testing script that was removed in 2003. Those comments can be used to find tests that should be migrated to use the new dg-additional-files support, and then the comments can be removed. libstdc++-v3/ChangeLog: * testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc: Use dg-additional-files. Remove @require@ and @diff@ comments. * testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc: Likewise. * testsuite/27_io/basic_filebuf/seekpos/char/1-io.cc: Likewise. * testsuite/27_io/basic_filebuf/seekpos/char/2-io.cc: Likewise. * testsuite/lib/dg-options.exp (v3_additional_files): New global variable. (dg-additional-files): New proc. * testsuite/lib/libstdc++.exp (v3_target_compile): Copy additional files to test directory. --- diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc index c812c528f26f..5afa33e596ed 100644 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc @@ -21,14 +21,12 @@ // { dg-require-fileio "" } // { dg-require-binary-io "" } +// { dg-additional-files "seekoff-1io.tst" } #include #include #include -// @require@ %-*.tst %-*.txt -// @diff@ %-*.tst %*.txt - const char name_01[] = "seekoff-1io.tst"; void test05() diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc index 4cfaf68c74eb..cd3f765d236c 100644 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc @@ -21,14 +21,12 @@ // { dg-require-fileio "" } // { dg-require-binary-io "" } +// { dg-additional-files "seekoff-2io.tst" } #include #include #include -// @require@ %-*.tst %-*.txt -// @diff@ %-*.tst %*.txt - const char name_01[] = "seekoff-2io.tst"; void test05() diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-io.cc index 57eabe382140..4566ebd27d93 100644 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-io.cc +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-io.cc @@ -20,14 +20,12 @@ // 27.8.1.4 Overridden virtual functions // { dg-require-fileio "" } +// { dg-additional-files "seekpos-1io.tst" } #include #include #include -// @require@ %-*.tst %-*.txt -// @diff@ %-*.tst %*.txt - const char name_01[] = "seekpos-1io.tst"; // file with data in it void test05() diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-io.cc index 714c3d60d2c5..8500dd59df80 100644 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-io.cc +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-io.cc @@ -20,14 +20,12 @@ // 27.8.1.4 Overridden virtual functions // { dg-require-fileio "" } +// { dg-additional-files "seekpos-2io.tst" } #include #include #include -// @require@ %-*.tst %-*.txt -// @diff@ %-*.tst %*.txt - const char name_01[] = "seekpos-2io.tst"; // file with data in it void test05() diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp index 7ee32fbbf717..e4975f3e8baa 100644 --- a/libstdc++-v3/testsuite/lib/dg-options.exp +++ b/libstdc++-v3/testsuite/lib/dg-options.exp @@ -373,3 +373,11 @@ proc dg-additional-options { args } { eval lappend extra-tool-flags [lindex $args 1] } } + +set v3_additional_files "" + +# Process a { dg-additional-files "filelist" } directive in the test. +proc dg-additional-files { line filelist } { + global v3_additional_files + set v3_additional_files $filelist +} diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp index 271f8772cafa..fde687d8bc1a 100644 --- a/libstdc++-v3/testsuite/lib/libstdc++.exp +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp @@ -143,7 +143,8 @@ proc libstdc++_init { testfile } { global dg-do-what-default set dg-do-what-default run - # Copy any required data files. + # Copy all required data files. + # TODO: Use dg-additional-files in individual tests instead of doing this. v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"] v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"] @@ -519,6 +520,12 @@ proc v3_target_compile { source dest type options } { lappend options "compiler=$cxx_final" lappend options "timeout=[timeout_value]" + global v3_additional_files + foreach file [split $v3_additional_files " "] { + global srcdir + v3-copy-file "$srcdir/data/$file" $file + } + set comp_output [target_compile $source $dest $type $options] return $comp_output