[flang-commits] [flang] 32403f7 - [flang][unittests] fix test broken when run as root (#119604)
via flang-commits
flang-commits at lists.llvm.org
Thu Dec 12 01:41:48 PST 2024
Author: Tom Eccles
Date: 2024-12-12T09:41:44Z
New Revision: 32403f79f4fcdb74b1576eed19cde7b104191808
URL: https://github.com/llvm/llvm-project/commit/32403f79f4fcdb74b1576eed19cde7b104191808
DIFF: https://github.com/llvm/llvm-project/commit/32403f79f4fcdb74b1576eed19cde7b104191808.diff
LOG: [flang][unittests] fix test broken when run as root (#119604)
It is convenient to run tests as root inside of a docker container.
The test (and the library function it is testing) are already
unsupported on Windows so it is safe to use UNIX-isms here.
Added:
Modified:
flang/unittests/Runtime/AccessTest.cpp
Removed:
################################################################################
diff --git a/flang/unittests/Runtime/AccessTest.cpp b/flang/unittests/Runtime/AccessTest.cpp
index 66f19f78c7cfb6..c2a2d7d398220c 100644
--- a/flang/unittests/Runtime/AccessTest.cpp
+++ b/flang/unittests/Runtime/AccessTest.cpp
@@ -32,6 +32,12 @@ struct AccessType {
} // namespace
+static bool userSkipsPermissionChecks() {
+ // The tests in this file assume normal permission checks apply to the user
+ // running the tests. This isn't true when the test is run by root.
+ return geteuid() == 0;
+}
+
static std::string addPIDSuffix(const char *name) {
std::stringstream ss;
ss << name;
@@ -166,6 +172,10 @@ TEST(AccessTests, TestRead) {
ASSERT_EQ(unlink(path.c_str()), 0);
+ if (userSkipsPermissionChecks()) {
+ return;
+ }
+
ASSERT_EQ(res, 0);
}
@@ -181,6 +191,10 @@ TEST(AccessTests, TestNotRead) {
ASSERT_EQ(unlink(path.c_str()), 0);
+ if (userSkipsPermissionChecks()) {
+ return;
+ }
+
ASSERT_NE(res, 0);
}
@@ -195,6 +209,10 @@ TEST(AccessTests, TestWrite) {
ASSERT_EQ(unlink(path.c_str()), 0);
+ if (userSkipsPermissionChecks()) {
+ return;
+ }
+
ASSERT_EQ(res, 0);
}
@@ -210,6 +228,10 @@ TEST(AccessTests, TestNotWrite) {
ASSERT_EQ(unlink(path.c_str()), 0);
+ if (userSkipsPermissionChecks()) {
+ return;
+ }
+
ASSERT_NE(res, 0);
}
@@ -225,6 +247,10 @@ TEST(AccessTests, TestReadWrite) {
ASSERT_EQ(unlink(path.c_str()), 0);
+ if (userSkipsPermissionChecks()) {
+ return;
+ }
+
ASSERT_EQ(res, 0);
}
@@ -242,6 +268,10 @@ TEST(AccessTests, TestNotReadWrite0) {
ASSERT_EQ(unlink(path.c_str()), 0);
+ if (userSkipsPermissionChecks()) {
+ return;
+ }
+
ASSERT_NE(res, 0);
}
@@ -259,6 +289,10 @@ TEST(AccessTests, TestNotReadWrite1) {
ASSERT_EQ(unlink(path.c_str()), 0);
+ if (userSkipsPermissionChecks()) {
+ return;
+ }
+
ASSERT_NE(res, 0);
}
@@ -276,6 +310,10 @@ TEST(AccessTests, TestNotReadWrite2) {
ASSERT_EQ(unlink(path.c_str()), 0);
+ if (userSkipsPermissionChecks()) {
+ return;
+ }
+
ASSERT_NE(res, 0);
}
@@ -290,6 +328,10 @@ TEST(AccessTests, TestExecute) {
ASSERT_EQ(unlink(path.c_str()), 0);
+ if (userSkipsPermissionChecks()) {
+ return;
+ }
+
ASSERT_EQ(res, 0);
}
@@ -305,6 +347,10 @@ TEST(AccessTests, TestNotExecute) {
ASSERT_EQ(unlink(path.c_str()), 0);
+ if (userSkipsPermissionChecks()) {
+ return;
+ }
+
ASSERT_NE(res, 0);
}
@@ -321,6 +367,10 @@ TEST(AccessTests, TestRWX) {
ASSERT_EQ(unlink(path.c_str()), 0);
+ if (userSkipsPermissionChecks()) {
+ return;
+ }
+
ASSERT_EQ(res, 0);
}
@@ -340,6 +390,10 @@ TEST(AccessTests, TestNotRWX0) {
ASSERT_EQ(unlink(path.c_str()), 0);
+ if (userSkipsPermissionChecks()) {
+ return;
+ }
+
ASSERT_NE(res, 0);
}
@@ -359,6 +413,10 @@ TEST(AccessTests, TestNotRWX1) {
ASSERT_EQ(unlink(path.c_str()), 0);
+ if (userSkipsPermissionChecks()) {
+ return;
+ }
+
ASSERT_NE(res, 0);
}
@@ -378,6 +436,10 @@ TEST(AccessTests, TestNotRWX2) {
ASSERT_EQ(unlink(path.c_str()), 0);
+ if (userSkipsPermissionChecks()) {
+ return;
+ }
+
ASSERT_NE(res, 0);
}
@@ -397,6 +459,10 @@ TEST(AccessTests, TestNotRWX3) {
ASSERT_EQ(unlink(path.c_str()), 0);
+ if (userSkipsPermissionChecks()) {
+ return;
+ }
+
ASSERT_NE(res, 0);
}
@@ -416,6 +482,10 @@ TEST(AccessTests, TestNotRWX4) {
ASSERT_EQ(unlink(path.c_str()), 0);
+ if (userSkipsPermissionChecks()) {
+ return;
+ }
+
ASSERT_NE(res, 0);
}
More information about the flang-commits
mailing list