summaryrefslogtreecommitdiff
path: root/test/tsan/deadlock_detector_stress_test.cc
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2014-02-26 17:06:58 +0000
committerDmitry Vyukov <dvyukov@google.com>2014-02-26 17:06:58 +0000
commite9286077544e83fa0a15002e162a038fab289ead (patch)
treeaa29e2fd70e462dfc64c5f6faa4a7244dc50a0d8 /test/tsan/deadlock_detector_stress_test.cc
parent50da249d327db4e710812e1d8ae9e0003af554db (diff)
tsan: fix deadlock detector test so that it does not force contention in runtime
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@202278 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tsan/deadlock_detector_stress_test.cc')
-rw-r--r--test/tsan/deadlock_detector_stress_test.cc33
1 files changed, 21 insertions, 12 deletions
diff --git a/test/tsan/deadlock_detector_stress_test.cc b/test/tsan/deadlock_detector_stress_test.cc
index 57a633e33..a8adc56d3 100644
--- a/test/tsan/deadlock_detector_stress_test.cc
+++ b/test/tsan/deadlock_detector_stress_test.cc
@@ -88,36 +88,44 @@ class PthreadRWLock {
class LockTest {
public:
- explicit LockTest(size_t n) : n_(n), locks_(new LockType[n]) { }
- ~LockTest() { delete [] locks_; }
+ explicit LockTest(size_t n)
+ : n_(n), locks_(new LockType*[n]) {
+ for (size_t i = 0; i < n_; i++)
+ locks_[i] = new LockType;
+ }
+ ~LockTest() {
+ for (size_t i = 0; i < n_; i++)
+ delete locks_[i];
+ delete [] locks_;
+ }
void L(size_t i) {
assert(i < n_);
- locks_[i].lock();
+ locks_[i]->lock();
}
void U(size_t i) {
assert(i < n_);
- locks_[i].unlock();
+ locks_[i]->unlock();
}
void RL(size_t i) {
assert(i < n_);
- locks_[i].rdlock();
+ locks_[i]->rdlock();
}
void RU(size_t i) {
assert(i < n_);
- locks_[i].rdunlock();
+ locks_[i]->rdunlock();
}
void *A(size_t i) {
assert(i < n_);
- return &locks_[i];
+ return locks_[i];
}
bool T(size_t i) {
assert(i < n_);
- return locks_[i].try_lock();
+ return locks_[i]->try_lock();
}
// Simple lock order onversion.
@@ -263,12 +271,13 @@ class LockTest {
// fprintf(stderr, "\n");
}
void Lock1_Loop_0() { Lock1_Loop(0, 100000); }
- void Lock1_Loop_1() { Lock1_Loop(1, 100000); }
- void Lock1_Loop_2() { Lock1_Loop(2, 100000); }
+ void Lock1_Loop_1() { Lock1_Loop(10, 100000); }
+ void Lock1_Loop_2() { Lock1_Loop(20, 100000); }
void CreateAndDestroyManyLocks() {
LockType create_many_locks_but_never_acquire[kDeadlockGraphSize];
(void)create_many_locks_but_never_acquire;
+ (void)create_many_locks_but_never_acquire;
}
void CreateLockUnlockAndDestroyManyLocks() {
@@ -305,7 +314,7 @@ class LockTest {
static const size_t kDeadlockGraphSize = 4096;
size_t n_;
- LockType *locks_;
+ LockType **locks_;
};
int main() {
@@ -314,7 +323,7 @@ int main() {
{ LockTest t(5); t.Test3(); }
{ LockTest t(5); t.Test4(); }
{ LockTest t(5); t.Test5(); }
- { LockTest t(5); t.Test6(); }
+ { LockTest t(100); t.Test6(); }
{ LockTest t(10); t.Test7(); }
{ LockTest t(5); t.Test8(); }
{ LockTest t(5); t.Test9(); }