summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/tsan/lit_tests
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2013-11-15 16:58:12 +0000
committerDmitry Vyukov <dvyukov@google.com>2013-11-15 16:58:12 +0000
commit4bbe6dc8a923089cdacd3363996fc00a64f96cfa (patch)
tree5b1c056a200924dd795b5e53a2a3ea1711f6587a /compiler-rt/lib/tsan/lit_tests
parent4fe1301bea7882e0ee38a8eb97e3b199eab80e8e (diff)
downloadbcm5719-llvm-4bbe6dc8a923089cdacd3363996fc00a64f96cfa.tar.gz
bcm5719-llvm-4bbe6dc8a923089cdacd3363996fc00a64f96cfa.zip
tsan: add support for robust mutexes
llvm-svn: 194823
Diffstat (limited to 'compiler-rt/lib/tsan/lit_tests')
-rw-r--r--compiler-rt/lib/tsan/lit_tests/mutex_robust.cc36
-rw-r--r--compiler-rt/lib/tsan/lit_tests/mutex_robust2.cc41
2 files changed, 77 insertions, 0 deletions
diff --git a/compiler-rt/lib/tsan/lit_tests/mutex_robust.cc b/compiler-rt/lib/tsan/lit_tests/mutex_robust.cc
new file mode 100644
index 00000000000..b826616076a
--- /dev/null
+++ b/compiler-rt/lib/tsan/lit_tests/mutex_robust.cc
@@ -0,0 +1,36 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+
+pthread_mutex_t m;
+
+void *thr(void *p) {
+ pthread_mutex_lock(&m);
+ return 0;
+}
+
+int main() {
+ pthread_mutexattr_t a;
+ pthread_mutexattr_init(&a);
+ pthread_mutexattr_setrobust(&a, PTHREAD_MUTEX_ROBUST);
+ pthread_mutex_init(&m, &a);
+ pthread_t th;
+ pthread_create(&th, 0, thr, 0);
+ sleep(1);
+ if (pthread_mutex_lock(&m) != EOWNERDEAD) {
+ fprintf(stderr, "not EOWNERDEAD\n");
+ exit(1);
+ }
+ pthread_join(th, 0);
+ fprintf(stderr, "DONE\n");
+}
+
+// This is a correct code, and tsan must not bark.
+// CHECK-NOT: WARNING: ThreadSanitizer
+// CHECK-NOT: EOWNERDEAD
+// CHECK: DONE
+// CHECK-NOT: WARNING: ThreadSanitizer
+
diff --git a/compiler-rt/lib/tsan/lit_tests/mutex_robust2.cc b/compiler-rt/lib/tsan/lit_tests/mutex_robust2.cc
new file mode 100644
index 00000000000..5bd7ff682d1
--- /dev/null
+++ b/compiler-rt/lib/tsan/lit_tests/mutex_robust2.cc
@@ -0,0 +1,41 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+
+pthread_mutex_t m;
+int x;
+
+void *thr(void *p) {
+ pthread_mutex_lock(&m);
+ x = 42;
+ return 0;
+}
+
+int main() {
+ pthread_mutexattr_t a;
+ pthread_mutexattr_init(&a);
+ pthread_mutexattr_setrobust(&a, PTHREAD_MUTEX_ROBUST);
+ pthread_mutex_init(&m, &a);
+ pthread_t th;
+ pthread_create(&th, 0, thr, 0);
+ sleep(1);
+ if (pthread_mutex_trylock(&m) != EOWNERDEAD) {
+ fprintf(stderr, "not EOWNERDEAD\n");
+ exit(1);
+ }
+ x = 43;
+ pthread_join(th, 0);
+ fprintf(stderr, "DONE\n");
+}
+
+// This is a false positive, tsan must not bark at the data race.
+// But currently it does.
+// CHECK-NOT: WARNING: ThreadSanitizer WARNING: double lock of mutex
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK-NOT: EOWNERDEAD
+// CHECK: DONE
+// CHECK-NOT: WARNING: ThreadSanitizer
+
OpenPOWER on IntegriCloud