]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: testsuite: conditionalize symlink tests
authorAlexandre Oliva <oliva@adacore.com>
Fri, 24 Jun 2022 02:20:50 +0000 (23:20 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Fri, 24 Jun 2022 02:25:52 +0000 (23:25 -0300)
Several filesystem tests expect to be able to create symlinks even
when !defined (_GLIBCXX_HAVE_SYMLINK), and fail predictably, reducing
the amount of testing of other filesystem features.

They are already skipped for mingw targets.  I've extended the
skipping to other targets in which _GLIBCXX_HAVE_SYMLINK is undefined,
through a new NO_SYMLINKS macro in testsuite_fs.h that guards
skippable portions of tests, and dg-require-target-fs-symlinks for
tests that would be reduced to nothing.

for  libstdc++-v3/ChangeLog

* testsuite/util/testsuite_fs.h (NO_SYMLINKS): Define on
mingw and when create_symlink is a dummy.
* testsuite/27_io/filesystem/operations/symlink_status.cc:
Drop mingw xfail.
(test01, test02): Don't create symlinks when NO_SYMLINKS is
defined.
* testsuite/27_io/filesystem/operations/canonical.cc (test03):
Likewise.
* testsuite/27_io/filesystem/operations/copy.cc (test02):
Likewise.
* testsuite/27_io/filesystem/operations/create_directories.cc
(test04): Likewise.
* testsuite/27_io/filesystem/operations/create_directory.cc
(test01): Likewise.
* testsuite/27_io/filesystem/operations/permissions.cc
(test03, test04): Likewise.
* testsuite/27_io/filesystem/operations/remove.cc (test01):
Likewise.
* testsuite/27_io/filesystem/operations/remove_all.cc (test01):
Likewise.
* testsuite/27_io/filesystem/operations/rename.cc
(test_symlinks): Likewise.
* testsuite/27_io/filesystem/operations/weakly_canonical.cc
(test01): Likewise.
* testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc
(test06): Likewise.
* testsuite/experimental/filesystem/operations/copy.cc
(test01): Likewise.
* testsuite/experimental/filesystem/operations/create_directories.cc
(test04): Likewise.
* testsuite/experimental/filesystem/operations/create_directory.cc
(test01): Likewise.
* testsuite/experimental/filesystem/operations/permissions.cc
(test03, test04): Likewise.
* testsuite/experimental/filesystem/operations/remove.cc
(test01): Likewise.
* testsuite/experimental/filesystem/operations/remove_all.cc
(test01): Likewise.
* testsuite/experimental/filesystem/operations/rename.cc
(test01): Likewise.
* testsuite/lib/libstdc++.exp
(v3_check_preprocessor_condition): Add optional inc parameter.
Add it to the test program after include bits/c++config.h.
(check_v3_target_fs_symlinks): New.
* testsuite/lib/dg-options.exp
(dg-require-target-fs-symlinks): New.
* testsuite/27_io/filesystem/operations/read_symlink.cc:
Replace mingw xfail with require target-fs-symlinks.
* testsuite/experimental/filesystem/operations/read_symlink.cc:
Likewise.

23 files changed:
libstdc++-v3/testsuite/27_io/filesystem/operations/canonical.cc
libstdc++-v3/testsuite/27_io/filesystem/operations/copy.cc
libstdc++-v3/testsuite/27_io/filesystem/operations/create_directories.cc
libstdc++-v3/testsuite/27_io/filesystem/operations/create_directory.cc
libstdc++-v3/testsuite/27_io/filesystem/operations/permissions.cc
libstdc++-v3/testsuite/27_io/filesystem/operations/read_symlink.cc
libstdc++-v3/testsuite/27_io/filesystem/operations/remove.cc
libstdc++-v3/testsuite/27_io/filesystem/operations/remove_all.cc
libstdc++-v3/testsuite/27_io/filesystem/operations/rename.cc
libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc
libstdc++-v3/testsuite/27_io/filesystem/operations/weakly_canonical.cc
libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc
libstdc++-v3/testsuite/experimental/filesystem/operations/copy.cc
libstdc++-v3/testsuite/experimental/filesystem/operations/create_directories.cc
libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc
libstdc++-v3/testsuite/experimental/filesystem/operations/permissions.cc
libstdc++-v3/testsuite/experimental/filesystem/operations/read_symlink.cc
libstdc++-v3/testsuite/experimental/filesystem/operations/remove.cc
libstdc++-v3/testsuite/experimental/filesystem/operations/remove_all.cc
libstdc++-v3/testsuite/experimental/filesystem/operations/rename.cc
libstdc++-v3/testsuite/lib/dg-options.exp
libstdc++-v3/testsuite/lib/libstdc++.exp
libstdc++-v3/testsuite/util/testsuite_fs.h

index bc7ef0de2b7165a5aa872bf15aa50a3fa93667bc..9c432b25acfb63b5c8a51bbccb38054027f3d262 100644 (file)
@@ -111,9 +111,12 @@ test03()
   fs::path foo = dir/"foo", bar = dir/"bar";
   fs::create_directory(foo);
   fs::create_directory(bar);
+#ifdef NO_SYMLINKS
 #if defined(__MINGW32__) || defined(__MINGW64__)
-  // No symlink support
   const fs::path baz = dir/"foo\\\\..\\bar///";
+#else
+  const fs::path baz = dir/"foo//../bar///";
+#endif
 #else
   fs::create_symlink("../bar", foo/"baz");
   const fs::path baz = dir/"foo//./baz///";
index f3081f4b64ebc42e9c41291a54a86083debeb8ba..f9fb4dff77ecdcedb3af218ef333f7c17c41786d 100644 (file)
@@ -66,11 +66,7 @@ test01()
 void
 test02()
 {
-#if defined(__MINGW32__) || defined(__MINGW64__)
-  // No symlink support
-  return;
-#endif
-
+#ifndef NO_SYMLINKS
   const std::error_code bad_ec = make_error_code(std::errc::invalid_argument);
   auto from = __gnu_test::nonexistent_path();
   std::error_code ec;
@@ -110,6 +106,7 @@ test02()
 
   remove(from, ec);
   remove(to, ec);
+#endif
 }
 
 // Test is_regular_file(f) case.
index 4a7ba1fcb494462d931f2619b93567c63afe6ccc..2b48c152e39a9a4a077f6a9b234412f80e10bd37 100644 (file)
@@ -148,9 +148,7 @@ test03()
 void
 test04()
 {
-#if defined(__MINGW32__) || defined(__MINGW64__)
-  // no symlinks
-#else
+#ifndef NO_SYMLINKS
   // PR libstdc++/101510
   // create_directories reports an error if the path is a symlink to a dir
   std::error_code ec = make_error_code(std::errc::invalid_argument);
index 90f98302c00f84c55e92c4ddfc6c8e8850b91dba..aa59f7f3ee22db50ec6b1b66191a69f72db7339b 100644 (file)
@@ -70,9 +70,7 @@ test01()
     VERIFY( e.path1() == f );
   }
 
-#if defined(__MINGW32__) || defined(__MINGW64__)
-  // no symlinks
-#else
+#ifndef NO_SYMLINKS
   // PR libstdc++/101510 create_directory on an existing symlink to a directory
   fs::create_directory(p/"dir");
   auto link = p/"link";
index deed759be80e97e2ee7fd2201a44d3939eff4b04..ee5afd529bac4bdc8566f89c1171b152a4779b1d 100644 (file)
@@ -76,6 +76,7 @@ test02()
 void
 test03()
 {
+#ifndef NO_SYMLINKS
   using std::filesystem::perms;
   using std::filesystem::perm_options;
 
@@ -111,11 +112,13 @@ test03()
     VERIFY( !caught );
 
   remove(p);
+#endif
 }
 
 void
 test04()
 {
+#ifndef NO_SYMLINKS
   using perms = std::filesystem::perms;
 
   auto p = __gnu_test::nonexistent_path();
@@ -137,6 +140,7 @@ test04()
   VERIFY( ec == ec2 );
 
   remove(p);
+#endif
 }
 
 void
index 68bbab33bc9e26447c6af5db7677bdcaf9ae9ce2..030d6271de525ae8eb1732045e76919b6ca11bff 100644 (file)
@@ -17,7 +17,7 @@
 
 // { dg-do run { target c++17 } }
 // { dg-require-filesystem-ts "" }
-// { dg-xfail-if "symlinks not supported" { *-*-mingw* } }
+// { dg-require-target-fs-symlinks "" }
 
 #include <filesystem>
 #include <testsuite_hooks.h>
index 26f2d548f82d50ecec0ffe42b6ba17d0a965045f..f769723ae30fa129ad4f8033fa5d32d22ffdee0f 100644 (file)
@@ -41,9 +41,7 @@ test01()
   VERIFY( !ec );
   VERIFY( !n );
 
-#if defined(__MINGW32__) || defined(__MINGW64__)
-  // No symlink support
-#else
+#ifndef NO_SYMLINKS
   auto link = __gnu_test::nonexistent_path();
   create_symlink(p, link);  // dangling symlink
   ec = bad_ec;
index 943d85c0cc2e36343d6ad1463fa0a9484b73ea99..d5266a4644913e07a0335578264e22a7ef5d2ed2 100644 (file)
@@ -41,9 +41,7 @@ test01()
   VERIFY( !ec );
   VERIFY( n == 0 );
 
-#if defined(__MINGW32__) || defined(__MINGW64__)
-  // No symlink support
-#else
+#ifndef NO_SYMLINKS
   auto link = __gnu_test::nonexistent_path();
   create_symlink(p, link);  // dangling symlink
   ec = bad_ec;
index f23a2862a0b99aaf74939b44933f507f800ed2cc..b74e1133a76181043710bb0fa73ad4582e8f2af8 100644 (file)
@@ -75,9 +75,7 @@ test01()
 void
 test_symlinks()
 {
-#if defined(__MINGW32__) || defined(__MINGW64__)
-  // No symlink support
-#else
+#ifndef NO_SYMLINKS
   std::error_code ec;
   const std::error_code bad_ec = make_error_code(std::errc::invalid_argument);
 
index ef973b7807b8a103985b2a4baedcc865414e6570..e00e4aaa78e77d669b73224fb12aff84da27b9b3 100644 (file)
@@ -17,7 +17,6 @@
 
 // { dg-do run { target c++17 } }
 // { dg-require-filesystem-ts "" }
-// { dg-xfail-if "symlinks not supported" { *-*-mingw* } }
 
 #include <filesystem>
 #include <testsuite_hooks.h>
@@ -39,6 +38,7 @@ test01()
   fs::file_status st2 = fs::symlink_status(dot);
   VERIFY( st2.type() == fs::file_type::directory );
 
+#ifndef NO_SYMLINKS
   fs::path link = __gnu_test::nonexistent_path();
   create_directory_symlink(dot, link);
   __gnu_test::scoped_file l(link, __gnu_test::scoped_file::adopt_file);
@@ -49,6 +49,7 @@ test01()
   st2 = fs::symlink_status(link, ec);
   VERIFY( !ec );
   VERIFY( st2.type() == fs::file_type::symlink );
+#endif
 }
 
 void
@@ -68,6 +69,7 @@ test02()
 void
 test03()
 {
+#ifndef NO_SYMLINKS
   if (!__gnu_test::permissions_are_testable())
     return;
 
@@ -111,6 +113,7 @@ test03()
   VERIFY( st2.type() == fs::file_type::symlink );
 
   fs::permissions(dir, fs::perms::owner_all, ec);
+#endif
 }
 
 void
index 244b753f84d1d647e27577393766f0f0b3c9e58d..ad164f52809f6a4b7079c5687d8808f8cbae95ae 100644 (file)
@@ -39,9 +39,7 @@ test01()
   fs::create_directory(bar/"baz");
   fs::path p;
 
-#if defined(__MINGW32__) || defined(__MINGW64__)
-  // No symlink support
-#else
+#ifndef NO_SYMLINKS
   fs::create_symlink("../bar", foo/"bar");
 
   p = fs::weakly_canonical(dir/"foo//./bar///../biz/.");
index a201415921cfc3eb894e68db638d80ca15b7cb03..393fb315593692689a5c72a9cbdd7f7e6e319310 100644 (file)
@@ -188,7 +188,7 @@ test05()
 void
 test06()
 {
-#if !(defined __MINGW32__ || defined __MINGW64__)
+#ifndef NO_SYMLINKS
   auto p = __gnu_test::nonexistent_path();
   create_directories(p/"d1/d2");
   create_directory_symlink("d1", p/"link");
index ca38328c5da153b823632fbf39e87a4a47bf7356..021897cfede6e55c4895dc042cddca82b03021e8 100644 (file)
@@ -67,11 +67,7 @@ test01()
 void
 test02()
 {
-#if defined(__MINGW32__) || defined(__MINGW64__)
-  // No symlink support
-  return;
-#endif
-
+#ifndef NO_SYMLINKS
   auto from = __gnu_test::nonexistent_path();
   std::error_code ec, bad = std::make_error_code(std::errc::invalid_argument);
 
@@ -109,6 +105,7 @@ test02()
 
   remove(from, ec);
   remove(to, ec);
+#endif
 }
 
 // Test is_regular_file(f) case.
index 03060c6cbb33e97b6dcb99dba09d2b7d7c33524c..df27748ff99a36eaf0cef30236abd557072cf92c 100644 (file)
@@ -147,9 +147,7 @@ test03()
 void
 test04()
 {
-#if defined(__MINGW32__) || defined(__MINGW64__)
-  // no symlinks
-#else
+#ifndef NO_SYMLINKS
   // PR libstdc++/101510
   // create_directories reports an error if the path is a symlink to a dir
   std::error_code ec = make_error_code(std::errc::invalid_argument);
index 67e5fddca009491ac20060170180d297b857544e..5e9346d5c73e5dc1690ab617a6c2e14083a1f69d 100644 (file)
@@ -69,9 +69,7 @@ test01()
     VERIFY( e.path1() == f );
   }
 
-#if defined(__MINGW32__) || defined(__MINGW64__)
-  // no symlinks
-#else
+#ifndef NO_SYMLINKS
   // PR libstdc++/101510 create_directory on an existing symlink to a directory
   fs::create_directory(p/"dir");
   auto link = p/"link";
index 833aa13dd158ba2b49d78f68a88e34089cc7a6b8..5866e334d7b460dde5cbb106b95dce1b8002b199 100644 (file)
@@ -72,6 +72,7 @@ test02()
 void
 test03()
 {
+#ifndef NO_SYMLINKS
   using perms = std::experimental::filesystem::perms;
 
   __gnu_test::scoped_file f;
@@ -95,11 +96,13 @@ test03()
   VERIFY( ec == ec2 );
 
   remove(p);
+#endif
 }
 
 void
 test04()
 {
+#ifndef NO_SYMLINKS
   using perms = std::experimental::filesystem::perms;
 
   auto p = __gnu_test::nonexistent_path();
@@ -120,6 +123,7 @@ test04()
   VERIFY( ec == ec2 );
 
   remove(p);
+#endif
 }
 
 void
index 75dae3eac5108a1cdc1058e9610ff2b711b6fd53..d0a90976a71155c32bc9f15bb34a1d07bd6e7975 100644 (file)
@@ -18,7 +18,7 @@
 // { dg-options "-DUSE_FILESYSTEM_TS -lstdc++fs" }
 // { dg-do run { target c++11 } }
 // { dg-require-filesystem-ts "" }
-// { dg-xfail-if "symlinks not supported" { *-*-mingw* } }
+// { dg-require-target-fs-symlinks "" }
 
 #include <experimental/filesystem>
 #include <testsuite_hooks.h>
index c01f140ee592a211846460202e3b1e6a4c2e38f9..4ffc74093b8a03a19df8f507da8c0da86f0fe92b 100644 (file)
@@ -42,10 +42,7 @@ test01()
   VERIFY( !ec );
   VERIFY( !n );
 
-#if defined(__MINGW32__) || defined(__MINGW64__)
-  // No symlink support
-  return;
-#else
+#ifndef NO_SYMLINKS
   auto link = __gnu_test::nonexistent_path();
   create_symlink(p, link);  // dangling symlink
   ec = bad_ec;
index 4b0ce85cf9754cee11a1d5fe844f20e51d88cf43..11c07d4f781e975ed2b66c38bf8dd3caa2b73bae 100644 (file)
@@ -42,9 +42,7 @@ test01()
   VERIFY( !ec );
   VERIFY( n == 0 );
 
-#if defined(__MINGW32__) || defined(__MINGW64__)
-  // No symlink support
-#else
+#ifndef NO_SYMLINKS
   auto link = __gnu_test::nonexistent_path();
   create_symlink(p, link);  // dangling symlink
   ec = bad_ec;
index 46776e80994e262ea583c648c5325ba2bf5db8c4..37e743b770fdf45d8f7d69fcb07bb852b5fa70ee 100644 (file)
@@ -75,9 +75,7 @@ test01()
 void
 test_symlinks()
 {
-#if defined(__MINGW32__) || defined(__MINGW64__)
-  // No symlink support
-#else
+#ifndef NO_SYMLINKS
   std::error_code ec;
   const std::error_code bad_ec = make_error_code(std::errc::invalid_argument);
 
index 15f37da468a5be9bc6bfec61d02179ce7f185dd5..e624a69460ed6d06529a3a7516dc1e32457787dd 100644 (file)
@@ -241,6 +241,15 @@ proc dg-require-filesystem-ts { args } {
     return
 }
 
+proc dg-require-target-fs-symlinks { args } {
+    if { ![ check_v3_target_fs_symlinks ] } {
+       upvar dg-do-what dg-do-what
+       set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
+       return
+    }
+    return
+}
+
 proc add_options_for_no_pch { flags } {
     # This forces any generated and possibly included PCH to be invalid.
     return "-D__GLIBCXX__=99999999"
index 93fdfee687ddb88cebe8f710be42e3624d70bbdc..03f47e8d77242eb034bc980da24dbcb90c6d27e0 100644 (file)
@@ -974,13 +974,16 @@ proc v3_try_preprocess { name code flags } {
 }
 
 # Return 1 if COND evaluates to true in the preprocessor, 0 otherwise.
-# The <bits/c++config.h> config header is included.
-proc v3_check_preprocessor_condition { name cond } {
+# The <bits/c++config.h> config header is included, and INC, if given,
+# is pasted between it and the condition evaluation, so it can be used
+# for additional #include's.
+proc v3_check_preprocessor_condition { name cond { inc "" } } {
     global cxxflags
     global DEFAULT_CXXFLAGS
 
     set code "
        #include <bits/c++config.h>
+       $inc
        #if ! ($cond)
        #error '$cond' is false
        #endif
@@ -1267,6 +1270,14 @@ proc check_v3_target_filesystem_ts { } {
     }]
 }
 
+# Return 1 if the libstdc++ filesystem create_symlinks implementation
+# is not an always-failing dummy.
+proc check_v3_target_fs_symlinks { } {
+    set inc "#include <testsuite_fs.h>"
+    set cond "!defined NO_SYMLINKS"
+    return [v3_check_preprocessor_condition fs_symlinks $cond $inc]
+}
+
 # Return 1 if the "cxx11" ABI is in use using the current flags, 0 otherwise.
 # Any flags provided by RUNTESTFLAGS or a target board will be used here.
 # Flags added in the test by dg-options or dg-add-options will not be used.
index 9358a04e56c1f3edbb40632f4dac714d4afbf6f3..03af7ae96e31af9b845d0e0153571dc07aebf21e 100644 (file)
@@ -42,6 +42,10 @@ namespace test_fs = std::experimental::filesystem;
 #include <random>   // std::random_device
 #endif
 
+#ifndef _GLIBCXX_HAVE_SYMLINK
+#define NO_SYMLINKS
+#endif
+
 namespace __gnu_test
 {
 #define PATH_CHK(p1, p2, fn) \