diff options
Diffstat (limited to 'compiler-rt/lib/tsan/lit_tests')
-rw-r--r-- | compiler-rt/lib/tsan/lit_tests/deep_stack0.cc | 38 | ||||
-rw-r--r-- | compiler-rt/lib/tsan/lit_tests/deep_stack1.cc | 38 | ||||
-rw-r--r-- | compiler-rt/lib/tsan/lit_tests/global_race.cc | 10 |
3 files changed, 81 insertions, 5 deletions
diff --git a/compiler-rt/lib/tsan/lit_tests/deep_stack0.cc b/compiler-rt/lib/tsan/lit_tests/deep_stack0.cc new file mode 100644 index 00000000000..7c0a8161a3f --- /dev/null +++ b/compiler-rt/lib/tsan/lit_tests/deep_stack0.cc @@ -0,0 +1,38 @@ +// RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s +#include <pthread.h> +#include <stdio.h> +#include <unistd.h> + +volatile int X; +volatile int N; +void (*volatile F)(); + +static void foo() { + if (--N == 0) + X = 42; + else + F(); +} + +void *Thread(void *p) { + sleep(1); + F(); + return 0; +} + +int main() { + N = 50000; + F = foo; + pthread_t t; + pthread_attr_t a; + pthread_attr_init(&a); + pthread_attr_setstacksize(&a, N * 256 + (1 << 20)); + pthread_create(&t, &a, Thread, 0); + X = 43; + pthread_join(t, 0); +} + +// CHECK: WARNING: ThreadSanitizer: data race +// CHECK: #100 foo +// We must output suffucuently large stack (at least 100 frames) + diff --git a/compiler-rt/lib/tsan/lit_tests/deep_stack1.cc b/compiler-rt/lib/tsan/lit_tests/deep_stack1.cc new file mode 100644 index 00000000000..929f1e6039a --- /dev/null +++ b/compiler-rt/lib/tsan/lit_tests/deep_stack1.cc @@ -0,0 +1,38 @@ +// RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s +#include <pthread.h> +#include <stdio.h> +#include <unistd.h> + +volatile int X; +volatile int N; +void (*volatile F)(); + +static void foo() { + if (--N == 0) + X = 42; + else + F(); +} + +void *Thread(void *p) { + F(); + return 0; +} + +int main() { + N = 50000; + F = foo; + pthread_t t; + pthread_attr_t a; + pthread_attr_init(&a); + pthread_attr_setstacksize(&a, N * 256 + (1 << 20)); + pthread_create(&t, &a, Thread, 0); + sleep(1); + X = 43; + pthread_join(t, 0); +} + +// CHECK: WARNING: ThreadSanitizer: data race +// CHECK: #100 foo +// We must output suffucuently large stack (at least 100 frames) + diff --git a/compiler-rt/lib/tsan/lit_tests/global_race.cc b/compiler-rt/lib/tsan/lit_tests/global_race.cc index 3e26792d8d6..cbe9f147221 100644 --- a/compiler-rt/lib/tsan/lit_tests/global_race.cc +++ b/compiler-rt/lib/tsan/lit_tests/global_race.cc @@ -4,7 +4,7 @@ #include <stddef.h> int GlobalData[10]; -int y; +int qwerty; namespace XXX { struct YYY { static int ZZZ[10]; @@ -14,19 +14,19 @@ namespace XXX { void *Thread(void *a) { GlobalData[2] = 42; - y = 1; + qwerty = 1; XXX::YYY::ZZZ[0] = 1; return 0; } int main() { fprintf(stderr, "addr=%p\n", GlobalData); - fprintf(stderr, "addr2=%p\n", &y); + fprintf(stderr, "addr2=%p\n", &qwerty); fprintf(stderr, "addr3=%p\n", XXX::YYY::ZZZ); pthread_t t; pthread_create(&t, 0, Thread, 0); GlobalData[2] = 43; - y = 0; + qwerty = 0; XXX::YYY::ZZZ[0] = 0; pthread_join(t, 0); } @@ -37,6 +37,6 @@ int main() { // CHECK: WARNING: ThreadSanitizer: data race // CHECK: Location is global 'GlobalData' of size 40 at [[ADDR]] ({{.*}}+0x{{[0-9,a-f]+}}) // CHECK: WARNING: ThreadSanitizer: data race -// CHECK: Location is global 'y' of size 4 at [[ADDR2]] ({{.*}}+0x{{[0-9,a-f]+}}) +// CHECK: Location is global 'qwerty' of size 4 at [[ADDR2]] ({{.*}}+0x{{[0-9,a-f]+}}) // CHECK: WARNING: ThreadSanitizer: data race // CHECK: Location is global 'XXX::YYY::ZZZ' of size 40 at [[ADDR3]] ({{.*}}+0x{{[0-9,a-f]+}}) |