llvm-project/compiler-rt/test/tsan/signal_write.cc
Dmitry Vyukov 3ab6b2347e tsan: remove sleeps from tests
Even sleep(1) lead to episodical flakes on some machines.
Use an invisible by tsan barrier to enforce required execution order instead.
This makes the tests deterministic and faster.

llvm-svn: 226659
2015-01-21 13:50:02 +00:00

28 lines
644 B
C++

// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
static void handler(int, siginfo_t*, void*) {
const char *str = "HELLO FROM SIGNAL\n";
write(2, str, strlen(str));
}
int main() {
struct sigaction act = {};
act.sa_sigaction = &handler;
sigaction(SIGPROF, &act, 0);
kill(getpid(), SIGPROF);
sleep(1); // let the signal handler run, can't use barrier in sig handler
fprintf(stderr, "DONE\n");
return 0;
}
// CHECK-NOT: WARNING: ThreadSanitizer
// CHECK: HELLO FROM SIGNAL
// CHECK: DONE