[compiler-rt] 898d52b - [compiler-rt][rtsan] Fix failing file permissions test by checking umask (#106095)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 28 13:08:44 PDT 2024


Author: Chris Apple
Date: 2024-08-28T13:08:40-07:00
New Revision: 898d52b819496ba70d0ca29cc7b60237108ae2b4

URL: https://github.com/llvm/llvm-project/commit/898d52b819496ba70d0ca29cc7b60237108ae2b4
DIFF: https://github.com/llvm/llvm-project/commit/898d52b819496ba70d0ca29cc7b60237108ae2b4.diff

LOG: [compiler-rt][rtsan] Fix failing file permissions test by checking umask (#106095)

This reverts:

d8d8d659685b114f31d1c42d6d18c3bc6d98b171

Added: 
    

Modified: 
    compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
index f91d694dd1e051..0eeaf9da67098e 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
@@ -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); };


        


More information about the llvm-commits mailing list