Skip to content

Commit 120e752

Browse files
committed
tests: add basic tests for RTSan
1 parent 14194bb commit 120e752

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

tests/sanitizers/lit.local.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ if (sys != 'FreeBSD') and (sys != 'Windows') and not (sys == 'Linux' and config.
1414
if 'tsan' in config.enabled_rt_libs:
1515
config.available_features.add('TSan')
1616

17+
# Windows currently does not have real-time sanitizer support
18+
if sys != 'Windows':
19+
if 'rtsan' in config.enabled_rt_libs:
20+
config.available_features.add('RTSan')
21+
1722
# FreeBSD ASan and MSan don't cope well with ASLR (might do with FreeBSD 14 according to https://github.com/llvm/llvm-project/pull/73439)
1823
if sys != 'FreeBSD':
1924
if 'asan' in config.enabled_rt_libs:

tests/sanitizers/rtsan_dmain_unsafe.d

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Test druntime real-time violations
2+
3+
// REQUIRES: RTSan
4+
5+
// RUN: %ldc -g -O2 -fsanitize=realtime %s -of=%t%exe
6+
// RUN: not %t%exe 2>&1 | FileCheck %s
7+
import ldc.attributes;
8+
9+
// CHECK: ERROR: RealtimeSanitizer: blocking-call
10+
void main()
11+
{
12+
// CHECK-NEXT: Call to blocking function `rt_init`
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Test simple realtime violations (marked blocking)
2+
3+
// REQUIRES: RTSan
4+
5+
// RUN: %ldc -g -O0 -fsanitize=realtime %s -of=%t%exe
6+
// RUN: not %t%exe 2>&1 | FileCheck %s
7+
import ldc.attributes;
8+
9+
// CHECK: ERROR: RealtimeSanitizer: blocking-call
10+
@realTimeUnsafe
11+
int blocking_function()
12+
{
13+
return 42;
14+
}
15+
16+
extern (C) int main(int argc, char** argv)
17+
{
18+
// CHECK: Call to blocking function `_D21rtsan_marked_blocking17blocking_functionFZi`
19+
return blocking_function();
20+
}

tests/sanitizers/rtsan_sleep.d

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Test simple realtime violations
2+
3+
// REQUIRES: RTSan
4+
5+
// RUN: %ldc -g -O0 -fsanitize=realtime %s -of=%t%exe
6+
// RUN: not %t%exe 2>&1 | FileCheck %s
7+
8+
extern (C) uint sleep(uint seconds);
9+
10+
// CHECK: ERROR: RealtimeSanitizer: unsafe-library-call
11+
void blocking_function()
12+
{
13+
cast(void) sleep(3);
14+
}
15+
16+
extern (C) int main(int argc, char** argv)
17+
{
18+
blocking_function();
19+
return 0;
20+
}

0 commit comments

Comments
 (0)