Skip to content

[flang][unittests] fix test broken when run as root #119604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions flang/unittests/Runtime/AccessTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -166,6 +172,10 @@ TEST(AccessTests, TestRead) {

ASSERT_EQ(unlink(path.c_str()), 0);

if (userSkipsPermissionChecks()) {
return;
}

ASSERT_EQ(res, 0);
}

Expand All @@ -181,6 +191,10 @@ TEST(AccessTests, TestNotRead) {

ASSERT_EQ(unlink(path.c_str()), 0);

if (userSkipsPermissionChecks()) {
return;
}

ASSERT_NE(res, 0);
}

Expand All @@ -195,6 +209,10 @@ TEST(AccessTests, TestWrite) {

ASSERT_EQ(unlink(path.c_str()), 0);

if (userSkipsPermissionChecks()) {
return;
}

ASSERT_EQ(res, 0);
}

Expand All @@ -210,6 +228,10 @@ TEST(AccessTests, TestNotWrite) {

ASSERT_EQ(unlink(path.c_str()), 0);

if (userSkipsPermissionChecks()) {
return;
}

ASSERT_NE(res, 0);
}

Expand All @@ -225,6 +247,10 @@ TEST(AccessTests, TestReadWrite) {

ASSERT_EQ(unlink(path.c_str()), 0);

if (userSkipsPermissionChecks()) {
return;
}

ASSERT_EQ(res, 0);
}

Expand All @@ -242,6 +268,10 @@ TEST(AccessTests, TestNotReadWrite0) {

ASSERT_EQ(unlink(path.c_str()), 0);

if (userSkipsPermissionChecks()) {
return;
}

ASSERT_NE(res, 0);
}

Expand All @@ -259,6 +289,10 @@ TEST(AccessTests, TestNotReadWrite1) {

ASSERT_EQ(unlink(path.c_str()), 0);

if (userSkipsPermissionChecks()) {
return;
}

ASSERT_NE(res, 0);
}

Expand All @@ -276,6 +310,10 @@ TEST(AccessTests, TestNotReadWrite2) {

ASSERT_EQ(unlink(path.c_str()), 0);

if (userSkipsPermissionChecks()) {
return;
}

ASSERT_NE(res, 0);
}

Expand All @@ -290,6 +328,10 @@ TEST(AccessTests, TestExecute) {

ASSERT_EQ(unlink(path.c_str()), 0);

if (userSkipsPermissionChecks()) {
return;
}

ASSERT_EQ(res, 0);
}

Expand All @@ -305,6 +347,10 @@ TEST(AccessTests, TestNotExecute) {

ASSERT_EQ(unlink(path.c_str()), 0);

if (userSkipsPermissionChecks()) {
return;
}

ASSERT_NE(res, 0);
}

Expand All @@ -321,6 +367,10 @@ TEST(AccessTests, TestRWX) {

ASSERT_EQ(unlink(path.c_str()), 0);

if (userSkipsPermissionChecks()) {
return;
}

ASSERT_EQ(res, 0);
}

Expand All @@ -340,6 +390,10 @@ TEST(AccessTests, TestNotRWX0) {

ASSERT_EQ(unlink(path.c_str()), 0);

if (userSkipsPermissionChecks()) {
return;
}

ASSERT_NE(res, 0);
}

Expand All @@ -359,6 +413,10 @@ TEST(AccessTests, TestNotRWX1) {

ASSERT_EQ(unlink(path.c_str()), 0);

if (userSkipsPermissionChecks()) {
return;
}

ASSERT_NE(res, 0);
}

Expand All @@ -378,6 +436,10 @@ TEST(AccessTests, TestNotRWX2) {

ASSERT_EQ(unlink(path.c_str()), 0);

if (userSkipsPermissionChecks()) {
return;
}

ASSERT_NE(res, 0);
}

Expand All @@ -397,6 +459,10 @@ TEST(AccessTests, TestNotRWX3) {

ASSERT_EQ(unlink(path.c_str()), 0);

if (userSkipsPermissionChecks()) {
return;
}

ASSERT_NE(res, 0);
}

Expand All @@ -416,6 +482,10 @@ TEST(AccessTests, TestNotRWX4) {

ASSERT_EQ(unlink(path.c_str()), 0);

if (userSkipsPermissionChecks()) {
return;
}

ASSERT_NE(res, 0);
}

Expand Down
Loading