xref: /llvm-project/compiler-rt/test/rtsan/deduplicate_errors.cpp (revision 595e484c0808f2410fa7f1ac4d630c1871c447fb)
1 // RUN: %clangxx -fsanitize=realtime %s -o %t
2 // RUN: env RTSAN_OPTIONS="halt_on_error=false,print_stats_on_exit=true" %run %t 2>&1 | FileCheck %s
3 // RUN: env RTSAN_OPTIONS="halt_on_error=false,suppress_equal_stacks=false" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-DUPLICATES
4 
5 // UNSUPPORTED: ios
6 
7 // Intent: Ensure all errors are deduplicated.
8 
9 #include <unistd.h>
10 
11 const int kNumViolations = 10;
12 
13 void violation() [[clang::nonblocking]] {
14   for (int i = 0; i < kNumViolations; i++)
15     usleep(1);
16 }
17 
18 void violation2() [[clang::nonblocking]] {
19   for (int i = 0; i < kNumViolations; i++)
20     violation();
21 }
22 
23 void double_violation() [[clang::nonblocking]] {
24   violation();
25   violation2();
26 }
27 
28 int main() {
29   violation();        // 1 unique errors here, but 10 total
30   violation2();       // 1 unique errors here, but 100 total
31   double_violation(); // 2 unique errors here, but 110 total
32   return 0;
33 }
34 
35 // CHECK-COUNT-4: ==ERROR:
36 // CHECK-NOT: ==ERROR:
37 
38 // CHECK: RealtimeSanitizer exit stats:
39 // CHECK-NEXT: Total error count: 220
40 // CHECK-NEXT: Unique error count: 4
41 
42 // CHECK-DUPLICATES-COUNT-220: ==ERROR:
43 // CHECK-DUPLICATES-NOT: ==ERROR:
44