[compiler-rt] [compiler-rt][rtsan] Introduce first end to end RTsan lit tests, enable instrumented unit tests (PR #105732)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 14:15:47 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Chris Apple (cjappl)

<details>
<summary>Changes</summary>

We can run our full end to end test suite now that #<!-- -->102622 has been merged

---
Full diff: https://github.com/llvm/llvm-project/pull/105732.diff


5 Files Affected:

- (modified) compiler-rt/lib/rtsan/tests/CMakeLists.txt (+7-8) 
- (modified) compiler-rt/test/rtsan/CMakeLists.txt (-11) 
- (added) compiler-rt/test/rtsan/test_rtsan.cpp (+17) 
- (added) compiler-rt/test/rtsan/test_rtsan_inactive.cpp (+23) 
- (modified) compiler-rt/test/sanitizer_common/lit.common.cfg.py (+3) 


``````````diff
diff --git a/compiler-rt/lib/rtsan/tests/CMakeLists.txt b/compiler-rt/lib/rtsan/tests/CMakeLists.txt
index 3b783c90c26585..0320bbad592186 100644
--- a/compiler-rt/lib/rtsan/tests/CMakeLists.txt
+++ b/compiler-rt/lib/rtsan/tests/CMakeLists.txt
@@ -60,14 +60,13 @@ endif()
 foreach(arch ${RTSAN_TEST_ARCH})
   set(RtsanTestObjects)
 
-  # TODO: Re-enable once -fsanitize=realtime exists in clang driver
-  #generate_compiler_rt_tests(RtsanTestObjects
-  #  RtsanUnitTests "Rtsan-${arch}-Test" ${arch}
-  #  COMPILE_DEPS ${RTSAN_UNITTEST_HEADERS}
-  #  SOURCES ${RTSAN_INST_TEST_SOURCES} ${COMPILER_RT_GOOGLETEST_SOURCES}
-  #  DEPS rtsan
-  #  CFLAGS ${RTSAN_UNITTEST_CFLAGS} -fsanitize=realtime
-  #  LINK_FLAGS ${RTSAN_UNITTEST_LINK_FLAGS} -fsanitize=realtime)
+  generate_compiler_rt_tests(RtsanTestObjects
+    RtsanUnitTests "Rtsan-${arch}-Test" ${arch}
+    COMPILE_DEPS ${RTSAN_UNITTEST_HEADERS}
+    SOURCES ${RTSAN_INST_TEST_SOURCES} ${COMPILER_RT_GOOGLETEST_SOURCES}
+    DEPS rtsan
+    CFLAGS ${RTSAN_UNITTEST_CFLAGS} -fsanitize=realtime
+    LINK_FLAGS ${RTSAN_UNITTEST_LINK_FLAGS} -fsanitize=realtime)
 
   set(RTSAN_TEST_RUNTIME RTRtsanTest.${arch})
   if(APPLE)
diff --git a/compiler-rt/test/rtsan/CMakeLists.txt b/compiler-rt/test/rtsan/CMakeLists.txt
index e1f9eb39408dc1..59fc5a29703fea 100644
--- a/compiler-rt/test/rtsan/CMakeLists.txt
+++ b/compiler-rt/test/rtsan/CMakeLists.txt
@@ -1,14 +1,3 @@
-
-
-
-
-######
-# TODO: Full lit tests coming in a future review when we introduce the codegen
-######
-
-
-
-
 set(RTSAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 
 set(RTSAN_TESTSUITES)
diff --git a/compiler-rt/test/rtsan/test_rtsan.cpp b/compiler-rt/test/rtsan/test_rtsan.cpp
new file mode 100644
index 00000000000000..101aadc56e9608
--- /dev/null
+++ b/compiler-rt/test/rtsan/test_rtsan.cpp
@@ -0,0 +1,17 @@
+// RUN: %clangxx -fsanitize=realtime %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// UNSUPPORTED: ios
+
+// Intent: Ensure that an intercepted call in a [[clang::nonblocking]] function
+//         is flagged as an error. Basic smoke test.
+
+#include <stdlib.h>
+
+void violation() [[clang::nonblocking]] { void *Ptr = malloc(2); }
+
+int main() {
+  violation();
+  return 0;
+  // CHECK: {{.*Real-time violation.*}}
+  // CHECK: {{.*malloc*}}
+}
diff --git a/compiler-rt/test/rtsan/test_rtsan_inactive.cpp b/compiler-rt/test/rtsan/test_rtsan_inactive.cpp
new file mode 100644
index 00000000000000..86907df6dfa161
--- /dev/null
+++ b/compiler-rt/test/rtsan/test_rtsan_inactive.cpp
@@ -0,0 +1,23 @@
+// RUN: %clangxx %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+// UNSUPPORTED: ios
+
+// Intent: Ensure [[clang::nonblocking]] has no impact if -fsanitize=realtime is not used
+
+#include <stdio.h>
+#include <stdlib.h>
+
+// In this test, we don't use the -fsanitize=realtime flag, so nothing
+// should happen here
+void violation() [[clang::nonblocking]] { void *Ptr = malloc(2); }
+
+int main() {
+  printf("Starting run\n");
+  violation();
+  printf("No violations ended the program\n");
+  return 0;
+  // CHECK: {{.*Starting run.*}}
+  // CHECK NOT: {{.*Real-time violation.*}}
+  // CHECK NOT: {{.*malloc*}}
+  // CHECK: {{.*No violations ended the program.*}}
+}
diff --git a/compiler-rt/test/sanitizer_common/lit.common.cfg.py b/compiler-rt/test/sanitizer_common/lit.common.cfg.py
index 04af4816eb6e78..5406e8838f2fcf 100644
--- a/compiler-rt/test/sanitizer_common/lit.common.cfg.py
+++ b/compiler-rt/test/sanitizer_common/lit.common.cfg.py
@@ -18,6 +18,9 @@
     tool_options = "HWASAN_OPTIONS"
     if not config.has_lld:
         config.unsupported = True
+elif config.tool_name == "rtsan":
+    tool_cflags = ["-fsanitize=realtime"]
+    tool_options = "RTSAN_OPTIONS"
 elif config.tool_name == "tsan":
     tool_cflags = ["-fsanitize=thread"]
     tool_options = "TSAN_OPTIONS"

``````````

</details>


https://github.com/llvm/llvm-project/pull/105732


More information about the llvm-commits mailing list