[compiler-rt] r201503 - [sanitizer] add one more test for deadlock detection stuff
Kostya Serebryany
kcc at google.com
Sun Feb 16 23:39:45 PST 2014
Author: kcc
Date: Mon Feb 17 01:39:44 2014
New Revision: 201503
URL: http://llvm.org/viewvc/llvm-project?rev=201503&view=rev
Log:
[sanitizer] add one more test for deadlock detection stuff
Modified:
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cc?rev=201503&r1=201502&r2=201503&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cc Mon Feb 17 01:39:44 2014
@@ -24,6 +24,17 @@
using namespace __sanitizer;
using namespace std;
+
+template<class G>
+void PrintGraph(const G &g) {
+ for (uptr i = 0; i < g.size(); i++) {
+ for (uptr j = 0; j < g.size(); j++) {
+ fprintf(stderr, "%d", g.hasEdge(i, j));
+ }
+ fprintf(stderr, "\n");
+ }
+}
+
class SimpleGraph {
public:
bool addEdge(uptr from, uptr to) {
@@ -134,3 +145,47 @@ TEST(SanitizerCommon, BVGraph_isReachabl
Test_isReachable<TwoLevelBitVector<> >();
Test_isReachable<TwoLevelBitVector<3, BasicBitVector<u8> > >();
}
+
+template <class BV>
+void LongCycle() {
+ BVGraph<BV> g;
+ g.clear();
+ vector<uptr> path_vec(g.size());
+ uptr *path = path_vec.data();
+ uptr start = 5;
+ for (uptr i = start; i < g.size() - 1; i++) {
+ g.addEdge(i, i + 1);
+ for (uptr j = 0; j < start; j++)
+ g.addEdge(i, j);
+ }
+ // Bad graph that looks like this:
+ // 00000000000000
+ // 00000000000000
+ // 00000000000000
+ // 00000000000000
+ // 00000000000000
+ // 11111010000000
+ // 11111001000000
+ // 11111000100000
+ // 11111000010000
+ // 11111000001000
+ // 11111000000100
+ // 11111000000010
+ // 11111000000001
+ // if (g.size() <= 64) PrintGraph(g);
+ BV target;
+ for (uptr i = start + 1; i < g.size(); i += 11) {
+ // if ((i & (i - 1)) == 0) fprintf(stderr, "Path: : %zd\n", i);
+ target.clear();
+ target.setBit(i);
+ EXPECT_TRUE(g.isReachable(start, target));
+ EXPECT_EQ(g.findPath(start, target, path, g.size()), i - start + 1);
+ }
+}
+
+TEST(SanitizerCommon, BVGraph_LongCycle) {
+ LongCycle<BasicBitVector<u8> >();
+ LongCycle<BasicBitVector<> >();
+ LongCycle<TwoLevelBitVector<> >();
+ LongCycle<TwoLevelBitVector<2, BasicBitVector<u8> > >();
+}
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cc?rev=201503&r1=201502&r2=201503&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cc Mon Feb 17 01:39:44 2014
@@ -24,11 +24,18 @@
using namespace __sanitizer;
using namespace std;
+// Poor man's unique_ptr.
+template<class BV>
+struct ScopedDD {
+ ScopedDD() { dp = new DeadlockDetector<BV>; }
+ ~ScopedDD() { delete dp; }
+ DeadlockDetector<BV> *dp;
+};
+
template <class BV>
-void TestDeadlockDetector() {
- // Can't allocate on stack.
- DeadlockDetector<BV> *dp = new DeadlockDetector<BV>;
- DeadlockDetector<BV> &d = *dp;
+void BasicTest() {
+ ScopedDD<BV> sdd;
+ DeadlockDetector<BV> &d = *sdd.dp;
DeadlockDetectorTLS dtls;
d.clear();
set<uptr> s;
@@ -93,13 +100,10 @@ void TestDeadlockDetector() {
d.onUnlock(&dtls, n1);
d.onUnlock(&dtls, n3);
}
-
- delete dp;
}
-TEST(SanitizerCommon, DeadlockDetector) {
- TestDeadlockDetector<BasicBitVector<> >();
- TestDeadlockDetector<TwoLevelBitVector<2> >();
- TestDeadlockDetector<TwoLevelBitVector<3,
- BasicBitVector<unsigned short> > >();
+TEST(DeadlockDetector, BasicTest) {
+ BasicTest<BasicBitVector<> >();
+ BasicTest<TwoLevelBitVector<2> >();
+ BasicTest<TwoLevelBitVector<3, BasicBitVector<u16> > >();
}
More information about the llvm-commits
mailing list