public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10214] libstdc++: Skip filesystem tests that depend on permissions [PR90787]
@ 2021-10-13 15:29 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2021-10-13 15:29 UTC (permalink / raw)
To: gcc-cvs, libstdc++-cvs
https://gcc.gnu.org/g:4be4888d6bddbcc106efeb19e18c380e7c1d041a
commit r10-10214-g4be4888d6bddbcc106efeb19e18c380e7c1d041a
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 10d36dfe42b..2f6c3a04acd 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/iterators/directory_iterator.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/iterators/directory_iterator.cc
@@ -57,24 +57,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 86a03c3c787..283024fe287 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
@@ -60,54 +60,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 8b8e1fb77ad..71da9675521 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc
@@ -80,10 +80,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 ad24fede03a..8615906384c 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/is_empty.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/is_empty.cc
@@ -28,10 +28,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 b5315b43f71..1a19ab66c1e 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/remove.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/remove.cc
@@ -77,19 +77,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 2760e79432b..24d69b30fdd 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/remove_all.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/remove_all.cc
@@ -143,9 +143,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;
@@ -173,7 +173,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 2f65d3dca5f..cc15ff47868 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/status.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/status.cc
@@ -56,10 +56,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 4184dda0272..a297fc05359 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc
@@ -69,6 +69,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 72a2db5cf9b..8c51ef836ca 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
@@ -95,10 +95,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 82f39aa347f..6044a11e436 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 1c073e125f9..e9569c2dd53 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 26cb6be8eec..1443ef1c871 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 6fd4f531ccd..ccb805beb0c 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 4bed583d15c..ff35d64f4b0 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 574c4c6c016..1a3061c64f0 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 3791a0108d7..dd90f717b05 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 df2344fae92..54fb42598f0 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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-10-13 15:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13 15:29 [gcc r10-10214] libstdc++: Skip filesystem tests that depend on permissions [PR90787] 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).