From e951fe4eec98de20b9b843f97fec2cca84c48b9c Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Fri, 14 Feb 2014 14:35:48 +0000 Subject: Move TSan lit-tests under test/tsan git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@201414 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/tsan/fd_dup_norace.cc | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/tsan/fd_dup_norace.cc (limited to 'test/tsan/fd_dup_norace.cc') diff --git a/test/tsan/fd_dup_norace.cc b/test/tsan/fd_dup_norace.cc new file mode 100644 index 000000000..8826f90fc --- /dev/null +++ b/test/tsan/fd_dup_norace.cc @@ -0,0 +1,34 @@ +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s +#include +#include +#include +#include +#include +#include + +int fds[2]; + +void *Thread1(void *x) { + char buf; + read(fds[0], &buf, 1); + close(fds[0]); + return 0; +} + +void *Thread2(void *x) { + close(fds[1]); + return 0; +} + +int main() { + fds[0] = open("/dev/random", O_RDONLY); + fds[1] = dup2(fds[0], 100); + pthread_t t[2]; + pthread_create(&t[0], NULL, Thread1, NULL); + pthread_create(&t[1], NULL, Thread2, NULL); + pthread_join(t[0], NULL); + pthread_join(t[1], NULL); + printf("OK\n"); +} + +// CHECK-NOT: WARNING: ThreadSanitizer: data race -- cgit v1.2.3