public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-3991] libstdc++: Support dg-additional-files in tests
@ 2023-09-14 13:27 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-09-14 13:27 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:9da3c935e3f46e32d9f801f07916634dc9a65886

commit r14-3991-g9da3c935e3f46e32d9f801f07916634dc9a65886
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Sep 13 10:57:08 2023 +0100

    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:
---
 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc | 4 +---
 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc | 4 +---
 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-io.cc | 4 +---
 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-io.cc | 4 +---
 libstdc++-v3/testsuite/lib/dg-options.exp                       | 8 ++++++++
 libstdc++-v3/testsuite/lib/libstdc++.exp                        | 9 ++++++++-
 6 files changed, 20 insertions(+), 13 deletions(-)

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 c812c528f26..5afa33e596e 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 <fstream>
 #include <testsuite_hooks.h>
 #include <testsuite_io.h>
 
-// @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 4cfaf68c74e..cd3f765d236 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 <fstream>
 #include <testsuite_hooks.h>
 #include <testsuite_io.h>
 
-// @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 57eabe38214..4566ebd27d9 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 <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() 
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 714c3d60d2c..8500dd59df8 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 <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() 
diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp
index 7ee32fbbf71..e4975f3e8ba 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 271f8772caf..fde687d8bc1 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-14 13:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-14 13:27 [gcc r14-3991] libstdc++: Support dg-additional-files in tests Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).