Files
clang-p2996/compiler-rt/test/tsan/deep_stack1.cc
Dmitry Vyukov 233f401c2b tsan: make positive tests more robust
Add a script that is used to deflake inherently flaky tsan tests.
It is invoked from lit tests as:
%deflake %run %t
The script runs the target program up to 10 times,
until it produces a tsan warning.

llvm-svn: 209898
2014-05-30 14:08:51 +00:00

45 lines
810 B
C++

// RUN: %clangxx_tsan -O1 %s -o %t -DORDER1 && %deflake %run %t | FileCheck %s
// RUN: %clangxx_tsan -O1 %s -o %t -DORDER2 && %deflake %run %t | 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) {
#ifdef ORDER1
sleep(1);
#endif
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);
#ifdef ORDER2
sleep(1);
#endif
X = 43;
pthread_join(t, 0);
}
// CHECK: WARNING: ThreadSanitizer: data race
// CHECK: #100 foo
// We must output suffucuently large stack (at least 100 frames)