summaryrefslogtreecommitdiff
path: root/test/tsan
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2014-02-25 09:33:10 +0000
committerKostya Serebryany <kcc@google.com>2014-02-25 09:33:10 +0000
commit2f0bd16650f6f0fe3d4966b30346869742d4ceb9 (patch)
tree8e319ea635b1360811c5f65368eea90707a90cf0 /test/tsan
parenta55886ca5c82e2e40e8c27ed75671cd799093a84 (diff)
downloadcompiler-rt-2f0bd16650f6f0fe3d4966b30346869742d4ceb9.tar.gz
[sanitizer] partially support pthread_rwlock_* (no rd* form yet)
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@202128 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tsan')
-rw-r--r--test/tsan/deadlock_detector_stress_test.cc44
1 files changed, 29 insertions, 15 deletions
diff --git a/test/tsan/deadlock_detector_stress_test.cc b/test/tsan/deadlock_detector_stress_test.cc
index da9451f21..a4d4505a6 100644
--- a/test/tsan/deadlock_detector_stress_test.cc
+++ b/test/tsan/deadlock_detector_stress_test.cc
@@ -1,4 +1,8 @@
-// RUN: %clangxx_tsan %s -o %t
+// RUN: %clangxx_tsan %s -o %t -DLockType=PthreadMutex
+// RUN: TSAN_OPTIONS=detect_deadlocks=1 not %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan %s -o %t -DLockType=PthreadSpinLock
+// RUN: TSAN_OPTIONS=detect_deadlocks=1 not %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan %s -o %t -DLockType=PthreadRWLock
// RUN: TSAN_OPTIONS=detect_deadlocks=1 not %t 2>&1 | FileCheck %s
#include <pthread.h>
#undef NDEBUG
@@ -37,8 +41,22 @@ class PthreadSpinLock {
char padding_[64 - sizeof(pthread_spinlock_t)];
};
+class PthreadRWLock {
+ public:
+ PthreadRWLock() { assert(0 == pthread_rwlock_init(&mu_, 0)); }
+ ~PthreadRWLock() {
+ assert(0 == pthread_rwlock_destroy(&mu_));
+ (void)padding_;
+ }
+ void lock() { assert(0 == pthread_rwlock_wrlock(&mu_)); }
+ void unlock() { assert(0 == pthread_rwlock_unlock(&mu_)); }
+ bool try_lock() { return 0 == pthread_rwlock_trywrlock(&mu_); }
+
+ private:
+ pthread_rwlock_t mu_;
+ char padding_[64 - sizeof(pthread_rwlock_t)];
+};
-template <class LockType>
class LockTest {
public:
LockTest(size_t n) : n_(n), locks_(new LockType[n]) { }
@@ -184,7 +202,9 @@ class LockTest {
void CreateAndDestroyManyLocks() {
LockType create_many_locks_but_never_acquire[kDeadlockGraphSize];
+ (void)create_many_locks_but_never_acquire;
}
+
void CreateLockUnlockAndDestroyManyLocks() {
LockType many_locks[kDeadlockGraphSize];
for (size_t i = 0; i < kDeadlockGraphSize; i++) {
@@ -222,20 +242,14 @@ class LockTest {
LockType *locks_;
};
-template <class LockType>
-void RunAllTests() {
- { LockTest<LockType> t(5); t.Test1(); }
- { LockTest<LockType> t(5); t.Test2(); }
- { LockTest<LockType> t(5); t.Test3(); }
- { LockTest<LockType> t(5); t.Test4(); }
- { LockTest<LockType> t(5); t.Test5(); }
- { LockTest<LockType> t(5); t.Test6(); }
- { LockTest<LockType> t(10); t.Test7(); }
-}
-
int main () {
- RunAllTests<PthreadMutex>();
- RunAllTests<PthreadSpinLock>();
+ { LockTest t(5); t.Test1(); }
+ { LockTest t(5); t.Test2(); }
+ { LockTest t(5); t.Test3(); }
+ { LockTest t(5); t.Test4(); }
+ { LockTest t(5); t.Test5(); }
+ { LockTest t(5); t.Test6(); }
+ { LockTest t(10); t.Test7(); }
fprintf(stderr, "DONE\n");
// CHECK: DONE
}