aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2021-08-20 14:51:06 +0100
committerJonathan Wakely <jwakely@redhat.com>2021-08-20 15:15:22 +0100
commit29b2fd371f18169141e20b90effa7205db68fb11 (patch)
treedca45d74011db75326d251aaf6aaecc4d986844a
parent1b507b1e3c58c063b9cf803dff80c28d4626cb5d (diff)
downloadgcc-29b2fd371f18169141e20b90effa7205db68fb11.zip
gcc-29b2fd371f18169141e20b90effa7205db68fb11.tar.gz
gcc-29b2fd371f18169141e20b90effa7205db68fb11.tar.bz2
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.
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/iterators/directory_iterator.cc36
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc97
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc6
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/is_empty.cc6
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/remove.cc21
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/remove_all.cc7
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/status.cc6
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc3
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc6
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/iterators/directory_iterator.cc32
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc98
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/operations/exists.cc6
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/operations/is_empty.cc6
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/operations/remove.cc21
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/operations/remove_all.cc7
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc3
-rw-r--r--libstdc++-v3/testsuite/util/testsuite_fs.h18
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 b49b4ae..b432e88 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 4de25c7..29a9f48 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 c4cb764..f99a334 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 40d83ed..1160574 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 3136d9d..70f3cf0 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 9a49dca..c02e8c3 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 5348901..4cabdcb 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 9920280..bb4c185 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 58d5841..1cfda58 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
@@ -101,10 +101,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 50e9bad..abc705d 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 f200d59..a9a81c8 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 9e33de6..79fe970 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 7eaba7f..a474fa2 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 c9f08eb..fedbf47 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 87fd2dd..dc067e7 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 d6d251e..badd8a8 100644
--- a/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc
+++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc
@@ -102,6 +102,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 1eadf7f..674b60b 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;
};
+ 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