Skip to content

[compiler-rt][rtsan] Fix failing file permissions test #106095

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 2 commits into from
Aug 28, 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
37 changes: 18 additions & 19 deletions compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,25 +193,24 @@ TEST_F(RtsanFileTest, OpenatDiesWhenRealtime) {
ExpectNonRealtimeSurvival(func);
}

// FIXME: This fails on the build machines, but not locally!
// see https://github.com/llvm/llvm-project/pull/105732#issuecomment-2310286530
// Value of: st.st_mode & 0777
// Expected: is equal to 420
// Actual: 384
// TEST_F(RtsanFileTest, OpenCreatesFileWithProperMode) {
// const int mode = S_IRGRP | S_IROTH | S_IRUSR | S_IWUSR;
//
// const int fd = open(GetTemporaryFilePath(), O_CREAT | O_WRONLY, mode);
// ASSERT_THAT(fd, Ne(-1));
// close(fd);
//
// struct stat st;
// ASSERT_THAT(stat(GetTemporaryFilePath(), &st), Eq(0));
//
// // Mask st_mode to get permission bits only
//
// //ASSERT_THAT(st.st_mode & 0777, Eq(mode)); FAILED ASSERTION
// }
TEST_F(RtsanFileTest, OpenCreatesFileWithProperMode) {
const mode_t existing_umask = umask(0);
umask(existing_umask);

const int mode = S_IRGRP | S_IROTH | S_IRUSR | S_IWUSR;

const int fd = open(GetTemporaryFilePath(), O_CREAT | O_WRONLY, mode);
ASSERT_THAT(fd, Ne(-1));
close(fd);

struct stat st;
ASSERT_THAT(stat(GetTemporaryFilePath(), &st), Eq(0));

// Mask st_mode to get permission bits only
const mode_t actual_mode = st.st_mode & 0777;
const mode_t expected_mode = mode & ~existing_umask;
ASSERT_THAT(actual_mode, Eq(expected_mode));
}

TEST_F(RtsanFileTest, CreatDiesWhenRealtime) {
auto func = [this]() { creat(GetTemporaryFilePath(), S_IWOTH | S_IROTH); };
Expand Down
Loading