[compiler-rt] a5e1898 - [rtsan] NFC: Simplify 64 file offset naming in unit tests (#114908)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 5 07:02:48 PST 2024


Author: Chris Apple
Date: 2024-11-05T07:02:41-08:00
New Revision: a5e189877ac3a50fb3ee385b8a434b691677537a

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

LOG: [rtsan] NFC: Simplify 64 file offset naming in unit tests (#114908)

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
index 8ed933fad51b11..bf7ea4ffe8599c 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -41,23 +41,10 @@
 #include <sys/uio.h>
 
 #if _FILE_OFFSET_BITS == 64 && SANITIZER_GLIBC
-const char *const kCreatFunctionName = "creat64";
-const char *const kFcntlFunctionName = "fcntl64";
-const char *const kFopenFunctionName = "fopen64";
-const char *const kOpenAtFunctionName = "openat64";
-const char *const kOpenFunctionName = "open64";
-const char *const kPreadFunctionName = "pread64";
-const char *const kPwriteFunctionName = "pwrite64";
-const char *const kMmapFunctionName = "mmap64";
+// Under these conditions, some system calls are `foo64` instead of `foo`
+#define MAYBE_APPEND_64(func) func "64"
 #else
-const char *const kCreatFunctionName = "creat";
-const char *const kFcntlFunctionName = "fcntl";
-const char *const kFopenFunctionName = "fopen";
-const char *const kOpenAtFunctionName = "openat";
-const char *const kOpenFunctionName = "open";
-const char *const kPreadFunctionName = "pread";
-const char *const kPwriteFunctionName = "pwrite";
-const char *const kMmapFunctionName = "mmap";
+#define MAYBE_APPEND_64(func) func
 #endif
 
 using namespace testing;
@@ -187,7 +174,7 @@ TEST(TestRtsanInterceptors, MmapDiesWhenRealtime) {
     void *_ = mmap(nullptr, 8, PROT_READ | PROT_WRITE,
                    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   };
-  ExpectRealtimeDeath(Func, kMmapFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("mmap"));
   ExpectNonRealtimeSurvival(Func);
 }
 
@@ -244,13 +231,13 @@ TEST(TestRtsanInterceptors, NanosleepDiesWhenRealtime) {
 
 TEST_F(RtsanFileTest, OpenDiesWhenRealtime) {
   auto Func = [this]() { open(GetTemporaryFilePath(), O_RDONLY); };
-  ExpectRealtimeDeath(Func, kOpenFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("open"));
   ExpectNonRealtimeSurvival(Func);
 }
 
 TEST_F(RtsanFileTest, OpenatDiesWhenRealtime) {
   auto Func = [this]() { openat(0, GetTemporaryFilePath(), O_RDONLY); };
-  ExpectRealtimeDeath(Func, kOpenAtFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("openat"));
   ExpectNonRealtimeSurvival(Func);
 }
 
@@ -275,13 +262,13 @@ TEST_F(RtsanFileTest, OpenCreatesFileWithProperMode) {
 
 TEST_F(RtsanFileTest, CreatDiesWhenRealtime) {
   auto Func = [this]() { creat(GetTemporaryFilePath(), S_IWOTH | S_IROTH); };
-  ExpectRealtimeDeath(Func, kCreatFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("creat"));
   ExpectNonRealtimeSurvival(Func);
 }
 
 TEST(TestRtsanInterceptors, FcntlDiesWhenRealtime) {
   auto Func = []() { fcntl(0, F_GETFL); };
-  ExpectRealtimeDeath(Func, kFcntlFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("fcntl"));
   ExpectNonRealtimeSurvival(Func);
 }
 
@@ -300,7 +287,7 @@ TEST_F(RtsanFileTest, FcntlFlockDiesWhenRealtime) {
     ASSERT_THAT(fcntl(fd, F_GETLK, &lock), Eq(0));
     ASSERT_THAT(lock.l_type, F_UNLCK);
   };
-  ExpectRealtimeDeath(Func, kFcntlFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("fcntl"));
   ExpectNonRealtimeSurvival(Func);
 
   close(fd);
@@ -322,7 +309,7 @@ TEST_F(RtsanFileTest, FcntlSetFdDiesWhenRealtime) {
     ASSERT_THAT(fcntl(fd, F_GETFD), Eq(old_flags));
   };
 
-  ExpectRealtimeDeath(Func, kFcntlFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("fcntl"));
   ExpectNonRealtimeSurvival(Func);
 
   close(fd);
@@ -340,7 +327,7 @@ TEST_F(RtsanFileTest, FopenDiesWhenRealtime) {
     EXPECT_THAT(f, Ne(nullptr));
   };
 
-  ExpectRealtimeDeath(Func, kFopenFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("fopen"));
   ExpectNonRealtimeSurvival(Func);
 }
 
@@ -428,7 +415,7 @@ TEST_F(RtsanOpenedFileTest, PreadDiesWhenRealtime) {
     char c{};
     pread(GetOpenFd(), &c, 1, 0);
   };
-  ExpectRealtimeDeath(Func, kPreadFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("pread"));
   ExpectNonRealtimeSurvival(Func);
 }
 
@@ -447,7 +434,7 @@ TEST_F(RtsanOpenedFileTest, PwriteDiesWhenRealtime) {
     char c = 'a';
     pwrite(GetOpenFd(), &c, 1, 0);
   };
-  ExpectRealtimeDeath(Func, kPwriteFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("pwrite"));
   ExpectNonRealtimeSurvival(Func);
 }
 


        


More information about the llvm-commits mailing list