[compiler-rt] [compiler-rt][rtsan] Fix failing file permissions test (PR #106095)
Chris Apple via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 27 07:15:59 PDT 2024
https://github.com/cjappl updated https://github.com/llvm/llvm-project/pull/106095
>From 4d96eafb50b79c5d0c053b8ea76d58d64a0d6213 Mon Sep 17 00:00:00 2001
From: Chris Apple <cja-private at pm.me>
Date: Mon, 26 Aug 2024 07:16:54 -0700
Subject: [PATCH 1/2] Revert "[rtsan][compiler-rt] Disable file permissions
test causing build failure (#106079)"
This reverts commit 11ba2eee59c6c7269b2dae27247048f828143274.
---
.../rtsan/tests/rtsan_test_interceptors.cpp | 32 ++++++++-----------
1 file changed, 13 insertions(+), 19 deletions(-)
diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
index f91d694dd1e051..4c4c8f86db484c 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
@@ -193,25 +193,19 @@ 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 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));
+}
TEST_F(RtsanFileTest, CreatDiesWhenRealtime) {
auto func = [this]() { creat(GetTemporaryFilePath(), S_IWOTH | S_IROTH); };
>From 462f1f1b89726d724520f071ea3209bdc6c3159e Mon Sep 17 00:00:00 2001
From: Chris Apple <cja-private at pm.me>
Date: Mon, 26 Aug 2024 08:36:21 -0700
Subject: [PATCH 2/2] [compiler-rt][rtsan] Fix failing file permissions test
---
compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
index 4c4c8f86db484c..0eeaf9da67098e 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
@@ -194,6 +194,9 @@ TEST_F(RtsanFileTest, OpenatDiesWhenRealtime) {
}
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);
@@ -204,7 +207,9 @@ TEST_F(RtsanFileTest, OpenCreatesFileWithProperMode) {
ASSERT_THAT(stat(GetTemporaryFilePath(), &st), Eq(0));
// Mask st_mode to get permission bits only
- ASSERT_THAT(st.st_mode & 0777, Eq(mode));
+ 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) {
More information about the llvm-commits
mailing list