From b6877fa9b8d7c98ba52f4d3bd79a5989f2beb96c Mon Sep 17 00:00:00 2001 From: Tom Eccles Date: Wed, 11 Dec 2024 18:22:42 +0000 Subject: [PATCH] [flang][unittests] fix test broken when run as root 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. --- flang/unittests/Runtime/AccessTest.cpp | 70 ++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/flang/unittests/Runtime/AccessTest.cpp b/flang/unittests/Runtime/AccessTest.cpp index 66f19f78c7cfb..c2a2d7d398220 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); }