]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Support dg-additional-files in tests
authorJonathan Wakely <jwakely@redhat.com>
Wed, 13 Sep 2023 09:57:08 +0000 (10:57 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 14 Sep 2023 12:58:34 +0000 (13:58 +0100)
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.

libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc
libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc
libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-io.cc
libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-io.cc
libstdc++-v3/testsuite/lib/dg-options.exp
libstdc++-v3/testsuite/lib/libstdc++.exp

index c812c528f26f42a6b6fb40b24dbc4054351741eb..5afa33e596ed1589825343bf41782da901669743 100644 (file)
 
 // { dg-require-fileio "" }
 // { dg-require-binary-io "" }
+// { dg-additional-files "seekoff-1io.tst" }
 
 #include <fstream>
 #include <testsuite_hooks.h>
 #include <testsuite_io.h>
 
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %*.txt
-
 const char name_01[] = "seekoff-1io.tst";
 
 void test05() 
index 4cfaf68c74ebbd30e70caa6290bde38234fab400..cd3f765d236ccb0eb378965edabf35c0f2ebc694 100644 (file)
 
 // { dg-require-fileio "" }
 // { dg-require-binary-io "" }
+// { dg-additional-files "seekoff-2io.tst" }
 
 #include <fstream>
 #include <testsuite_hooks.h>
 #include <testsuite_io.h>
 
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %*.txt
-
 const char name_01[] = "seekoff-2io.tst";
 
 void test05() 
index 57eabe38214044ef330cb755466644da545f92a7..4566ebd27d93cb46588676f0f3b510fa516851ea 100644 (file)
 // 27.8.1.4 Overridden virtual functions
 
 // { dg-require-fileio "" }
+// { dg-additional-files "seekpos-1io.tst" }
 
 #include <fstream>
 #include <testsuite_hooks.h>
 #include <testsuite_io.h>
 
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %*.txt
-
 const char name_01[] = "seekpos-1io.tst"; // file with data in it
 
 void test05() 
index 714c3d60d2c56d0a40b7a1ed443ef1f37bfe25a4..8500dd59df80f1fa946d3b462f3f1e4cdd0af54c 100644 (file)
 // 27.8.1.4 Overridden virtual functions
 
 // { dg-require-fileio "" }
+// { dg-additional-files "seekpos-2io.tst" }
 
 #include <fstream>
 #include <testsuite_hooks.h>
 #include <testsuite_io.h>
 
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %*.txt
-
 const char name_01[] = "seekpos-2io.tst"; // file with data in it
 
 void test05() 
index 7ee32fbbf7176c071999cc65a2398f38925dc481..e4975f3e8baa554163ad53b674a7372f4e97c8e1 100644 (file)
@@ -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
+}
index 271f8772cafa811c932e36580ed63ae6e666077f..fde687d8bc1a45081fa2925b9bcd8e32658b8459 100644 (file)
@@ -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