Skip to content

Commit f056657

Browse files
committed
[compiler-rt][rtsan] Introduce RTsan lit tests
1 parent f77e8f7 commit f056657

File tree

5 files changed

+50
-19
lines changed

5 files changed

+50
-19
lines changed

compiler-rt/lib/rtsan/tests/CMakeLists.txt

+7-8
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,13 @@ endif()
6060
foreach(arch ${RTSAN_TEST_ARCH})
6161
set(RtsanTestObjects)
6262

63-
# TODO: Re-enable once -fsanitize=realtime exists in clang driver
64-
#generate_compiler_rt_tests(RtsanTestObjects
65-
# RtsanUnitTests "Rtsan-${arch}-Test" ${arch}
66-
# COMPILE_DEPS ${RTSAN_UNITTEST_HEADERS}
67-
# SOURCES ${RTSAN_INST_TEST_SOURCES} ${COMPILER_RT_GOOGLETEST_SOURCES}
68-
# DEPS rtsan
69-
# CFLAGS ${RTSAN_UNITTEST_CFLAGS} -fsanitize=realtime
70-
# LINK_FLAGS ${RTSAN_UNITTEST_LINK_FLAGS} -fsanitize=realtime)
63+
generate_compiler_rt_tests(RtsanTestObjects
64+
RtsanUnitTests "Rtsan-${arch}-Test" ${arch}
65+
COMPILE_DEPS ${RTSAN_UNITTEST_HEADERS}
66+
SOURCES ${RTSAN_INST_TEST_SOURCES} ${COMPILER_RT_GOOGLETEST_SOURCES}
67+
DEPS rtsan
68+
CFLAGS ${RTSAN_UNITTEST_CFLAGS} -fsanitize=realtime
69+
LINK_FLAGS ${RTSAN_UNITTEST_LINK_FLAGS} -fsanitize=realtime)
7170

7271
set(RTSAN_TEST_RUNTIME RTRtsanTest.${arch})
7372
if(APPLE)

compiler-rt/test/rtsan/CMakeLists.txt

-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
2-
3-
4-
5-
######
6-
# TODO: Full lit tests coming in a future review when we introduce the codegen
7-
######
8-
9-
10-
11-
121
set(RTSAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
132

143
set(RTSAN_TESTSUITES)

compiler-rt/test/rtsan/test_rtsan.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clangxx -fsanitize=realtime %s -o %t
2+
// RUN: not %run %t 2>&1 | FileCheck %s
3+
// UNSUPPORTED: ios
4+
5+
// Intent: Ensure that an intercepted call in a [[clang::nonblocking]] function
6+
// is flagged as an error. Basic smoke test.
7+
8+
#include <stdlib.h>
9+
10+
void violation() [[clang::nonblocking]] { void *Ptr = malloc(2); }
11+
12+
int main() {
13+
violation();
14+
return 0;
15+
// CHECK: {{.*Real-time violation.*}}
16+
// CHECK: {{.*malloc*}}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %clangxx %s -o %t
2+
// RUN: %run %t 2>&1 | FileCheck %s
3+
// UNSUPPORTED: ios
4+
5+
// Intent: Ensure [[clang::nonblocking]] has no impact if -fsanitize=realtime is not used
6+
7+
#include <stdio.h>
8+
#include <stdlib.h>
9+
10+
// In this test, we don't use the -fsanitize=realtime flag, so nothing
11+
// should happen here
12+
void violation() [[clang::nonblocking]] { void *Ptr = malloc(2); }
13+
14+
int main() {
15+
printf("Starting run\n");
16+
violation();
17+
printf("No violations ended the program\n");
18+
return 0;
19+
// CHECK: {{.*Starting run.*}}
20+
// CHECK NOT: {{.*Real-time violation.*}}
21+
// CHECK NOT: {{.*malloc*}}
22+
// CHECK: {{.*No violations ended the program.*}}
23+
}

compiler-rt/test/sanitizer_common/lit.common.cfg.py

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
tool_options = "HWASAN_OPTIONS"
1919
if not config.has_lld:
2020
config.unsupported = True
21+
elif config.tool_name == "rtsan":
22+
tool_cflags = ["-fsanitize=realtime"]
23+
tool_options = "RTSAN_OPTIONS"
2124
elif config.tool_name == "tsan":
2225
tool_cflags = ["-fsanitize=thread"]
2326
tool_options = "TSAN_OPTIONS"

0 commit comments

Comments
 (0)