public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-9133] libstdc++: Skip filesystem tests that depend on permissions [PR90787] Date: Tue, 12 Oct 2021 19:40:56 +0000 (GMT) [thread overview] Message-ID: <20211012194056.F193C3858C27@sourceware.org> (raw) https://gcc.gnu.org/g:cec047eaeb3ca40be65500d140a3a3f16db742e1 commit r11-9133-gcec047eaeb3ca40be65500d140a3a3f16db742e1 Author: Jonathan Wakely <jwakely@redhat.com> Date: Fri Aug 20 14:51:06 2021 +0100 libstdc++: Skip filesystem tests that depend on permissions [PR90787] Tests that depend on filesystem permissions FAIL if run on Windows or as root. Add a helper function to detect those cases, so the tests can skip those checks gracefully. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: PR libstdc++/90787 * testsuite/27_io/filesystem/iterators/directory_iterator.cc: Use new __gnu_test::permissions_are_testable() function. * testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc: Likewise. * testsuite/27_io/filesystem/operations/exists.cc: Likewise. * testsuite/27_io/filesystem/operations/is_empty.cc: Likewise. * testsuite/27_io/filesystem/operations/remove.cc: Likewise. * testsuite/27_io/filesystem/operations/remove_all.cc: Likewise. * testsuite/27_io/filesystem/operations/status.cc: Likewise. * testsuite/27_io/filesystem/operations/symlink_status.cc: Likewise. * testsuite/27_io/filesystem/operations/temp_directory_path.cc: Likewise. * testsuite/experimental/filesystem/iterators/directory_iterator.cc: Likewise. * testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc: Likewise. * testsuite/experimental/filesystem/operations/exists.cc: Likewise. * testsuite/experimental/filesystem/operations/is_empty.cc: Likewise. * testsuite/experimental/filesystem/operations/remove.cc: Likewise. * testsuite/experimental/filesystem/operations/remove_all.cc: Likewise. * testsuite/experimental/filesystem/operations/temp_directory_path.cc: Likewise. * testsuite/util/testsuite_fs.h (__gnu_test::permissions_are_testable): New function to guess whether testing permissions will work. (cherry picked from commit 29b2fd371f18169141e20b90effa7205db68fb11) Diff: --- .../filesystem/iterators/directory_iterator.cc | 36 ++++---- .../iterators/recursive_directory_iterator.cc | 97 ++++++++++----------- .../27_io/filesystem/operations/exists.cc | 6 +- .../27_io/filesystem/operations/is_empty.cc | 6 +- .../27_io/filesystem/operations/remove.cc | 21 +++-- .../27_io/filesystem/operations/remove_all.cc | 7 +- .../27_io/filesystem/operations/status.cc | 6 +- .../27_io/filesystem/operations/symlink_status.cc | 3 + .../filesystem/operations/temp_directory_path.cc | 6 +- .../filesystem/iterators/directory_iterator.cc | 32 +++---- .../iterators/recursive_directory_iterator.cc | 98 +++++++++++----------- .../experimental/filesystem/operations/exists.cc | 6 +- .../experimental/filesystem/operations/is_empty.cc | 6 +- .../experimental/filesystem/operations/remove.cc | 21 +++-- .../filesystem/operations/remove_all.cc | 7 +- .../filesystem/operations/temp_directory_path.cc | 3 + libstdc++-v3/testsuite/util/testsuite_fs.h | 18 +++- 17 files changed, 197 insertions(+), 182 deletions(-) diff --git a/libstdc++-v3/testsuite/27_io/filesystem/iterators/directory_iterator.cc b/libstdc++-v3/testsuite/27_io/filesystem/iterators/directory_iterator.cc index b49b4ae2fea..b432e8833ba 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/iterators/directory_iterator.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/iterators/directory_iterator.cc @@ -56,24 +56,26 @@ test01() ++iter; VERIFY( iter == end(iter) ); -#if !(defined(__MINGW32__) || defined(__MINGW64__)) - // Test inaccessible directory. - ec = bad_ec; - permissions(p, fs::perms::none, ec); - VERIFY( !ec ); - iter = fs::directory_iterator(p, ec); - VERIFY( ec ); - VERIFY( iter == end(iter) ); - - // Test inaccessible directory, skipping permission denied. - const auto opts = fs::directory_options::skip_permission_denied; - ec = bad_ec; - iter = fs::directory_iterator(p, opts, ec); - VERIFY( !ec ); - VERIFY( iter == end(iter) ); -#endif + if (__gnu_test::permissions_are_testable()) + { + // Test inaccessible directory. + ec = bad_ec; + permissions(p, fs::perms::none, ec); + VERIFY( !ec ); + iter = fs::directory_iterator(p, ec); + VERIFY( ec ); + VERIFY( iter == end(iter) ); + + // Test inaccessible directory, skipping permission denied. + const auto opts = fs::directory_options::skip_permission_denied; + ec = bad_ec; + iter = fs::directory_iterator(p, opts, ec); + VERIFY( !ec ); + VERIFY( iter == end(iter) ); + + permissions(p, fs::perms::owner_all, ec); + } - permissions(p, fs::perms::owner_all, ec); remove_all(p, ec); } diff --git a/libstdc++-v3/testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc b/libstdc++-v3/testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc index 4de25c780e0..29a9f480649 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc @@ -59,54 +59,55 @@ test01() ++iter; VERIFY( iter == end(iter) ); -#if ! (defined (__MINGW32__) || defined(__MINGW64__)) - // Test inaccessible directory. - ec = bad_ec; - permissions(p, fs::perms::none, ec); - VERIFY( !ec ); - iter = fs::recursive_directory_iterator(p, ec); - VERIFY( ec ); - VERIFY( iter == end(iter) ); - - // Test inaccessible directory, skipping permission denied. - const auto opts = fs::directory_options::skip_permission_denied; - iter = fs::recursive_directory_iterator(p, opts, ec); - VERIFY( !ec ); - VERIFY( iter == end(iter) ); - - // Test inaccessible sub-directory. - ec = bad_ec; - permissions(p, fs::perms::owner_all, ec); - VERIFY( !ec ); - ec = bad_ec; - permissions(p/"d1/d2", fs::perms::none, ec); - VERIFY( !ec ); - ec = bad_ec; - iter = fs::recursive_directory_iterator(p, ec); - VERIFY( !ec ); - VERIFY( iter != end(iter) ); - VERIFY( iter->path() == p/"d1" ); - ++iter; // should recurse into d1 - VERIFY( iter != end(iter) ); - VERIFY( iter->path() == p/"d1/d2" ); - iter.increment(ec); // should fail to recurse into p/d1/d2 - VERIFY( ec ); - VERIFY( iter == end(iter) ); - - // Test inaccessible sub-directory, skipping permission denied. - ec = bad_ec; - iter = fs::recursive_directory_iterator(p, opts, ec); - VERIFY( !ec ); - VERIFY( iter != end(iter) ); - VERIFY( iter->path() == p/"d1" ); - ++iter; // should recurse into d1 - VERIFY( iter != end(iter) ); - VERIFY( iter->path() == p/"d1/d2" ); - ec = bad_ec; - iter.increment(ec); // should fail to recurse into p/d1/d2, so skip it - VERIFY( !ec ); - VERIFY( iter == end(iter) ); -#endif + if (__gnu_test::permissions_are_testable()) + { + // Test inaccessible directory. + ec = bad_ec; + permissions(p, fs::perms::none, ec); + VERIFY( !ec ); + iter = fs::recursive_directory_iterator(p, ec); + VERIFY( ec ); + VERIFY( iter == end(iter) ); + + // Test inaccessible directory, skipping permission denied. + const auto opts = fs::directory_options::skip_permission_denied; + iter = fs::recursive_directory_iterator(p, opts, ec); + VERIFY( !ec ); + VERIFY( iter == end(iter) ); + + // Test inaccessible sub-directory. + ec = bad_ec; + permissions(p, fs::perms::owner_all, ec); + VERIFY( !ec ); + ec = bad_ec; + permissions(p/"d1/d2", fs::perms::none, ec); + VERIFY( !ec ); + ec = bad_ec; + iter = fs::recursive_directory_iterator(p, ec); + VERIFY( !ec ); + VERIFY( iter != end(iter) ); + VERIFY( iter->path() == p/"d1" ); + ++iter; // should recurse into d1 + VERIFY( iter != end(iter) ); + VERIFY( iter->path() == p/"d1/d2" ); + iter.increment(ec); // should fail to recurse into p/d1/d2 + VERIFY( ec ); + VERIFY( iter == end(iter) ); + + // Test inaccessible sub-directory, skipping permission denied. + ec = bad_ec; + iter = fs::recursive_directory_iterator(p, opts, ec); + VERIFY( !ec ); + VERIFY( iter != end(iter) ); + VERIFY( iter->path() == p/"d1" ); + ++iter; // should recurse into d1 + VERIFY( iter != end(iter) ); + VERIFY( iter->path() == p/"d1/d2" ); + ec = bad_ec; + iter.increment(ec); // should fail to recurse into p/d1/d2, so skip it + VERIFY( !ec ); + VERIFY( iter == end(iter) ); + } permissions(p/"d1/d2", fs::perms::owner_all, ec); remove_all(p, ec); diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc index c4cb7648e91..f99a3346ed0 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc @@ -79,10 +79,8 @@ test03() void test04() { -#if defined(__MINGW32__) || defined(__MINGW64__) - // filesystem permissions not supported - return; -#endif + if (!__gnu_test::permissions_are_testable()) + return; using std::filesystem::perms; using std::filesystem::perm_options; diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/is_empty.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/is_empty.cc index 40d83eda6f3..11605748501 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/operations/is_empty.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/is_empty.cc @@ -27,10 +27,8 @@ namespace fs = std::filesystem; void test01() { -#if defined(__MINGW32__) || defined(__MINGW64__) - // filesystem permissions not supported - return; -#endif + if (!__gnu_test::permissions_are_testable()) + return; auto p = __gnu_test::nonexistent_path(); create_directory(p); diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/remove.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/remove.cc index 3136d9dddbe..70f3cf0eaf4 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/operations/remove.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/remove.cc @@ -76,19 +76,18 @@ test01() VERIFY( !n ); VERIFY( exists(dir/"a/b") ); -#if defined(__MINGW32__) || defined(__MINGW64__) - // No permissions support -#else - permissions(dir, fs::perms::none, ec); - if (!ec) + if (__gnu_test::permissions_are_testable()) { - ec.clear(); - n = remove(dir/"a/b", ec); - VERIFY( ec ); - VERIFY( !n ); - permissions(dir, fs::perms::owner_all, ec); + permissions(dir, fs::perms::none, ec); + if (!ec) + { + ec.clear(); + n = remove(dir/"a/b", ec); + VERIFY( ec ); + VERIFY( !n ); + permissions(dir, fs::perms::owner_all, ec); + } } -#endif ec = bad_ec; n = remove(dir/"a/b", ec); diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/remove_all.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/remove_all.cc index 9a49dcaf03c..c02e8c3c575 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/operations/remove_all.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/remove_all.cc @@ -142,9 +142,9 @@ test03() void test04() { -#if defined(__MINGW32__) || defined(__MINGW64__) - // no permissions -#else + if (!__gnu_test::permissions_are_testable()) + return; + // PR libstdc++/93201 std::error_code ec; std::uintmax_t n; @@ -172,7 +172,6 @@ test04() fs::permissions(dir, fs::perms::owner_write, fs::perm_options::add); fs::remove_all(dir, ec); f.path.clear(); -#endif } int diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/status.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/status.cc index 53489017669..4cabdcbe7f7 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/operations/status.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/status.cc @@ -55,10 +55,8 @@ test02() void test03() { -#if defined(__MINGW32__) || defined(__MINGW64__) - // No permissions support - return; -#endif + if (!__gnu_test::permissions_are_testable()) + return; fs::path dir = __gnu_test::nonexistent_path(); fs::create_directory(dir); diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc index 99202808976..bb4c185dd33 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc @@ -68,6 +68,9 @@ test02() void test03() { + if (!__gnu_test::permissions_are_testable()) + return; + fs::path dir = __gnu_test::nonexistent_path(); fs::create_directory(dir); __gnu_test::scoped_file d(dir, __gnu_test::scoped_file::adopt_file); diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc index ff84a0a4531..b55cd6c60b6 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc @@ -94,10 +94,8 @@ test02() void test03() { -#if defined(__MINGW32__) || defined(__MINGW64__) - // No permissions support - return; -#endif + if (!__gnu_test::permissions_are_testable()) + return; clean_env(); diff --git a/libstdc++-v3/testsuite/experimental/filesystem/iterators/directory_iterator.cc b/libstdc++-v3/testsuite/experimental/filesystem/iterators/directory_iterator.cc index 50e9bad638e..abc705d7696 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/iterators/directory_iterator.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/iterators/directory_iterator.cc @@ -53,22 +53,24 @@ test01() ++iter; VERIFY( iter == end(iter) ); -#if !(defined(__MINGW32__) || defined(__MINGW64__)) - // Test inaccessible directory. - permissions(p, fs::perms::none, ec); - VERIFY( !ec ); - iter = fs::directory_iterator(p, ec); - VERIFY( ec ); - VERIFY( iter == end(iter) ); - - // Test inaccessible directory, skipping permission denied. - const auto opts = fs::directory_options::skip_permission_denied; - iter = fs::directory_iterator(p, opts, ec); - VERIFY( !ec ); - VERIFY( iter == end(iter) ); -#endif + if (__gnu_test::permissions_are_testable()) + { + // Test inaccessible directory. + permissions(p, fs::perms::none, ec); + VERIFY( !ec ); + iter = fs::directory_iterator(p, ec); + VERIFY( ec ); + VERIFY( iter == end(iter) ); + + // Test inaccessible directory, skipping permission denied. + const auto opts = fs::directory_options::skip_permission_denied; + iter = fs::directory_iterator(p, opts, ec); + VERIFY( !ec ); + VERIFY( iter == end(iter) ); + + permissions(p, fs::perms::owner_all, ec); + } - permissions(p, fs::perms::owner_all, ec); remove_all(p, ec); } diff --git a/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc b/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc index f200d597e81..a9a81c8c4cb 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc @@ -61,54 +61,58 @@ test01() ++iter; VERIFY( iter == end(iter) ); - // Test inaccessible directory. - ec = bad_ec; - permissions(p, fs::perms::none, ec); - VERIFY( !ec ); - iter = fs::recursive_directory_iterator(p, ec); - VERIFY( ec ); - VERIFY( iter == end(iter) ); - - // Test inaccessible directory, skipping permission denied. - const auto opts = fs::directory_options::skip_permission_denied; - ec = bad_ec; - iter = fs::recursive_directory_iterator(p, opts, ec); - VERIFY( !ec ); - VERIFY( iter == end(iter) ); - - // Test inaccessible sub-directory. - ec = bad_ec; - permissions(p, fs::perms::owner_all, ec); - VERIFY( !ec ); - ec = bad_ec; - permissions(p/"d1/d2", fs::perms::none, ec); - VERIFY( !ec ); - ec = bad_ec; - iter = fs::recursive_directory_iterator(p, ec); - VERIFY( !ec ); - VERIFY( iter != end(iter) ); - VERIFY( iter->path() == p/"d1" ); - ++iter; // should recurse into d1 - VERIFY( iter != end(iter) ); - VERIFY( iter->path() == p/"d1/d2" ); - iter.increment(ec); // should fail to recurse into p/d1/d2 - VERIFY( ec ); - VERIFY( iter == end(iter) ); - - // Test inaccessible sub-directory, skipping permission denied. - ec = bad_ec; - iter = fs::recursive_directory_iterator(p, opts, ec); - VERIFY( !ec ); - VERIFY( iter != end(iter) ); - VERIFY( iter->path() == p/"d1" ); - ++iter; // should recurse into d1 - VERIFY( iter->path() == p/"d1/d2" ); - ec = bad_ec; - iter.increment(ec); // should fail to recurse into p/d1/d2, so skip it - VERIFY( !ec ); - VERIFY( iter == end(iter) ); + if (__gnu_test::permissions_are_testable()) + { + // Test inaccessible directory. + ec = bad_ec; + permissions(p, fs::perms::none, ec); + VERIFY( !ec ); + iter = fs::recursive_directory_iterator(p, ec); + VERIFY( ec ); + VERIFY( iter == end(iter) ); + + // Test inaccessible directory, skipping permission denied. + const auto opts = fs::directory_options::skip_permission_denied; + ec = bad_ec; + iter = fs::recursive_directory_iterator(p, opts, ec); + VERIFY( !ec ); + VERIFY( iter == end(iter) ); + + // Test inaccessible sub-directory. + ec = bad_ec; + permissions(p, fs::perms::owner_all, ec); + VERIFY( !ec ); + ec = bad_ec; + permissions(p/"d1/d2", fs::perms::none, ec); + VERIFY( !ec ); + ec = bad_ec; + iter = fs::recursive_directory_iterator(p, ec); + VERIFY( !ec ); + VERIFY( iter != end(iter) ); + VERIFY( iter->path() == p/"d1" ); + ++iter; // should recurse into d1 + VERIFY( iter != end(iter) ); + VERIFY( iter->path() == p/"d1/d2" ); + iter.increment(ec); // should fail to recurse into p/d1/d2 + VERIFY( ec ); + VERIFY( iter == end(iter) ); + + // Test inaccessible sub-directory, skipping permission denied. + ec = bad_ec; + iter = fs::recursive_directory_iterator(p, opts, ec); + VERIFY( !ec ); + VERIFY( iter != end(iter) ); + VERIFY( iter->path() == p/"d1" ); + ++iter; // should recurse into d1 + VERIFY( iter->path() == p/"d1/d2" ); + ec = bad_ec; + iter.increment(ec); // should fail to recurse into p/d1/d2, so skip it + VERIFY( !ec ); + VERIFY( iter == end(iter) ); + + permissions(p/"d1/d2", fs::perms::owner_all, ec); + } - permissions(p/"d1/d2", fs::perms::owner_all, ec); remove_all(p, ec); } diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/exists.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/exists.cc index 9e33de6d04a..79fe970e9f3 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/operations/exists.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/exists.cc @@ -74,10 +74,8 @@ test03() void test04() { -#if defined(__MINGW32__) || defined(__MINGW64__) - // filesystem permissions not supported - return; -#endif + if (!__gnu_test::permissions_are_testable()) + return; using perms = std::experimental::filesystem::perms; path p = __gnu_test::nonexistent_path(); diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/is_empty.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/is_empty.cc index 7eaba7f1173..a474fa2a37f 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/operations/is_empty.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/is_empty.cc @@ -28,10 +28,8 @@ namespace fs = std::experimental::filesystem; void test01() { -#if defined(__MINGW32__) || defined(__MINGW64__) - // filesystem permissions not supported - return; -#endif + if (!__gnu_test::permissions_are_testable()) + return; auto p = __gnu_test::nonexistent_path(); create_directory(p); diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/remove.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/remove.cc index c9f08eb2d12..fedbf4714b5 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/operations/remove.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/remove.cc @@ -78,19 +78,18 @@ test01() VERIFY( !n ); VERIFY( exists(dir/"a/b") ); -#if defined(__MINGW32__) || defined(__MINGW64__) - // No permissions support -#else - permissions(dir, fs::perms::none, ec); - if (!ec) + if (__gnu_test::permissions_are_testable()) { - ec.clear(); - n = remove(dir/"a/b", ec); - VERIFY( ec ); - VERIFY( !n ); - permissions(dir, fs::perms::owner_all, ec); + permissions(dir, fs::perms::none, ec); + if (!ec) + { + ec.clear(); + n = remove(dir/"a/b", ec); + VERIFY( ec ); + VERIFY( !n ); + permissions(dir, fs::perms::owner_all, ec); + } } -#endif ec = bad_ec; n = remove(dir/"a/b", ec); diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/remove_all.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/remove_all.cc index 87fd2dde41d..dc067e79e80 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/operations/remove_all.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/remove_all.cc @@ -111,9 +111,9 @@ test02() void test04() { -#if defined(__MINGW32__) || defined(__MINGW64__) - // no permissions -#else + if (!__gnu_test::permissions_are_testable()) + return; + // PR libstdc++/93201 std::error_code ec; std::uintmax_t n; @@ -139,7 +139,6 @@ test04() fs::permissions(dir, fs::perms::owner_write|fs::perms::add_perms); fs::remove_all(dir, ec); f.path.clear(); -#endif } int diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc index 3e0833f597b..03e777b0041 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc @@ -95,6 +95,9 @@ test02() void test03() { + if (!__gnu_test::permissions_are_testable()) + return; + auto p = __gnu_test::nonexistent_path(); create_directories(p/"tmp"); permissions(p, fs::perms::none); diff --git a/libstdc++-v3/testsuite/util/testsuite_fs.h b/libstdc++-v3/testsuite/util/testsuite_fs.h index 1eadf7fa767..0d32a616840 100644 --- a/libstdc++-v3/testsuite/util/testsuite_fs.h +++ b/libstdc++-v3/testsuite/util/testsuite_fs.h @@ -34,7 +34,7 @@ namespace test_fs = std::experimental::filesystem; #include <fstream> #include <string> #include <cstdio> -#include <unistd.h> // unlink, close, getpid +#include <unistd.h> // unlink, close, getpid, geteuid #if defined(_GNU_SOURCE) || _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200112L #include <stdlib.h> // mkstemp @@ -160,5 +160,21 @@ namespace __gnu_test path_type path; }; + inline bool + permissions_are_testable(bool print_msg = true) + { + bool testable = false; +#if !(defined __MINGW32__ || defined __MINGW64__) + if (geteuid() != 0) + testable = true; + // XXX on Linux the CAP_DAC_OVERRIDE and CAP_DAC_READ_SEARCH capabilities + // can give normal users extra permissions for files and directories. + // We ignore that possibility here. +#endif + if (print_msg && !testable) + std::puts("Skipping tests that depend on filesystem permissions"); + return testable; + } + } // namespace __gnu_test #endif
reply other threads:[~2021-10-12 19:40 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211012194056.F193C3858C27@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).