Skip to content

Commit a5e1898

Browse files
authored
[rtsan] NFC: Simplify 64 file offset naming in unit tests (llvm#114908)
1 parent ba60f6d commit a5e1898

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

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

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,10 @@
4141
#include <sys/uio.h>
4242

4343
#if _FILE_OFFSET_BITS == 64 && SANITIZER_GLIBC
44-
const char *const kCreatFunctionName = "creat64";
45-
const char *const kFcntlFunctionName = "fcntl64";
46-
const char *const kFopenFunctionName = "fopen64";
47-
const char *const kOpenAtFunctionName = "openat64";
48-
const char *const kOpenFunctionName = "open64";
49-
const char *const kPreadFunctionName = "pread64";
50-
const char *const kPwriteFunctionName = "pwrite64";
51-
const char *const kMmapFunctionName = "mmap64";
44+
// Under these conditions, some system calls are `foo64` instead of `foo`
45+
#define MAYBE_APPEND_64(func) func "64"
5246
#else
53-
const char *const kCreatFunctionName = "creat";
54-
const char *const kFcntlFunctionName = "fcntl";
55-
const char *const kFopenFunctionName = "fopen";
56-
const char *const kOpenAtFunctionName = "openat";
57-
const char *const kOpenFunctionName = "open";
58-
const char *const kPreadFunctionName = "pread";
59-
const char *const kPwriteFunctionName = "pwrite";
60-
const char *const kMmapFunctionName = "mmap";
47+
#define MAYBE_APPEND_64(func) func
6148
#endif
6249

6350
using namespace testing;
@@ -187,7 +174,7 @@ TEST(TestRtsanInterceptors, MmapDiesWhenRealtime) {
187174
void *_ = mmap(nullptr, 8, PROT_READ | PROT_WRITE,
188175
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
189176
};
190-
ExpectRealtimeDeath(Func, kMmapFunctionName);
177+
ExpectRealtimeDeath(Func, MAYBE_APPEND_64("mmap"));
191178
ExpectNonRealtimeSurvival(Func);
192179
}
193180

@@ -244,13 +231,13 @@ TEST(TestRtsanInterceptors, NanosleepDiesWhenRealtime) {
244231

245232
TEST_F(RtsanFileTest, OpenDiesWhenRealtime) {
246233
auto Func = [this]() { open(GetTemporaryFilePath(), O_RDONLY); };
247-
ExpectRealtimeDeath(Func, kOpenFunctionName);
234+
ExpectRealtimeDeath(Func, MAYBE_APPEND_64("open"));
248235
ExpectNonRealtimeSurvival(Func);
249236
}
250237

251238
TEST_F(RtsanFileTest, OpenatDiesWhenRealtime) {
252239
auto Func = [this]() { openat(0, GetTemporaryFilePath(), O_RDONLY); };
253-
ExpectRealtimeDeath(Func, kOpenAtFunctionName);
240+
ExpectRealtimeDeath(Func, MAYBE_APPEND_64("openat"));
254241
ExpectNonRealtimeSurvival(Func);
255242
}
256243

@@ -275,13 +262,13 @@ TEST_F(RtsanFileTest, OpenCreatesFileWithProperMode) {
275262

276263
TEST_F(RtsanFileTest, CreatDiesWhenRealtime) {
277264
auto Func = [this]() { creat(GetTemporaryFilePath(), S_IWOTH | S_IROTH); };
278-
ExpectRealtimeDeath(Func, kCreatFunctionName);
265+
ExpectRealtimeDeath(Func, MAYBE_APPEND_64("creat"));
279266
ExpectNonRealtimeSurvival(Func);
280267
}
281268

282269
TEST(TestRtsanInterceptors, FcntlDiesWhenRealtime) {
283270
auto Func = []() { fcntl(0, F_GETFL); };
284-
ExpectRealtimeDeath(Func, kFcntlFunctionName);
271+
ExpectRealtimeDeath(Func, MAYBE_APPEND_64("fcntl"));
285272
ExpectNonRealtimeSurvival(Func);
286273
}
287274

@@ -300,7 +287,7 @@ TEST_F(RtsanFileTest, FcntlFlockDiesWhenRealtime) {
300287
ASSERT_THAT(fcntl(fd, F_GETLK, &lock), Eq(0));
301288
ASSERT_THAT(lock.l_type, F_UNLCK);
302289
};
303-
ExpectRealtimeDeath(Func, kFcntlFunctionName);
290+
ExpectRealtimeDeath(Func, MAYBE_APPEND_64("fcntl"));
304291
ExpectNonRealtimeSurvival(Func);
305292

306293
close(fd);
@@ -322,7 +309,7 @@ TEST_F(RtsanFileTest, FcntlSetFdDiesWhenRealtime) {
322309
ASSERT_THAT(fcntl(fd, F_GETFD), Eq(old_flags));
323310
};
324311

325-
ExpectRealtimeDeath(Func, kFcntlFunctionName);
312+
ExpectRealtimeDeath(Func, MAYBE_APPEND_64("fcntl"));
326313
ExpectNonRealtimeSurvival(Func);
327314

328315
close(fd);
@@ -340,7 +327,7 @@ TEST_F(RtsanFileTest, FopenDiesWhenRealtime) {
340327
EXPECT_THAT(f, Ne(nullptr));
341328
};
342329

343-
ExpectRealtimeDeath(Func, kFopenFunctionName);
330+
ExpectRealtimeDeath(Func, MAYBE_APPEND_64("fopen"));
344331
ExpectNonRealtimeSurvival(Func);
345332
}
346333

@@ -428,7 +415,7 @@ TEST_F(RtsanOpenedFileTest, PreadDiesWhenRealtime) {
428415
char c{};
429416
pread(GetOpenFd(), &c, 1, 0);
430417
};
431-
ExpectRealtimeDeath(Func, kPreadFunctionName);
418+
ExpectRealtimeDeath(Func, MAYBE_APPEND_64("pread"));
432419
ExpectNonRealtimeSurvival(Func);
433420
}
434421

@@ -447,7 +434,7 @@ TEST_F(RtsanOpenedFileTest, PwriteDiesWhenRealtime) {
447434
char c = 'a';
448435
pwrite(GetOpenFd(), &c, 1, 0);
449436
};
450-
ExpectRealtimeDeath(Func, kPwriteFunctionName);
437+
ExpectRealtimeDeath(Func, MAYBE_APPEND_64("pwrite"));
451438
ExpectNonRealtimeSurvival(Func);
452439
}
453440

0 commit comments

Comments
 (0)