Convert witness_assert_lockless() to witness_assert_lock_depth().
This makes it possible to make lock state assertions about precisely which locks are held.
This commit is contained in:
@@ -3,12 +3,12 @@
|
||||
static witness_lock_error_t *witness_lock_error_orig;
|
||||
static witness_owner_error_t *witness_owner_error_orig;
|
||||
static witness_not_owner_error_t *witness_not_owner_error_orig;
|
||||
static witness_lockless_error_t *witness_lockless_error_orig;
|
||||
static witness_lock_depth_error_t *witness_lock_depth_error_orig;
|
||||
|
||||
static bool saw_lock_error;
|
||||
static bool saw_owner_error;
|
||||
static bool saw_not_owner_error;
|
||||
static bool saw_lockless_error;
|
||||
static bool saw_lock_depth_error;
|
||||
|
||||
static void
|
||||
witness_lock_error_intercept(const witness_list_t *witnesses,
|
||||
@@ -33,10 +33,11 @@ witness_not_owner_error_intercept(const witness_t *witness)
|
||||
}
|
||||
|
||||
static void
|
||||
witness_lockless_error_intercept(const witness_list_t *witnesses)
|
||||
witness_lock_depth_error_intercept(const witness_list_t *witnesses,
|
||||
unsigned depth)
|
||||
{
|
||||
|
||||
saw_lockless_error = true;
|
||||
saw_lock_depth_error = true;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -66,22 +67,25 @@ TEST_BEGIN(test_witness)
|
||||
|
||||
tsdn = tsdn_fetch();
|
||||
|
||||
witness_assert_lockless(tsdn);
|
||||
witness_assert_lock_depth(tsdn, 0);
|
||||
|
||||
witness_init(&a, "a", 1, NULL);
|
||||
witness_assert_not_owner(tsdn, &a);
|
||||
witness_lock(tsdn, &a);
|
||||
witness_assert_owner(tsdn, &a);
|
||||
witness_assert_lock_depth(tsdn, 1);
|
||||
|
||||
witness_init(&b, "b", 2, NULL);
|
||||
witness_assert_not_owner(tsdn, &b);
|
||||
witness_lock(tsdn, &b);
|
||||
witness_assert_owner(tsdn, &b);
|
||||
witness_assert_lock_depth(tsdn, 2);
|
||||
|
||||
witness_unlock(tsdn, &a);
|
||||
witness_assert_lock_depth(tsdn, 1);
|
||||
witness_unlock(tsdn, &b);
|
||||
|
||||
witness_assert_lockless(tsdn);
|
||||
witness_assert_lock_depth(tsdn, 0);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
@@ -94,18 +98,21 @@ TEST_BEGIN(test_witness_comp)
|
||||
|
||||
tsdn = tsdn_fetch();
|
||||
|
||||
witness_assert_lockless(tsdn);
|
||||
witness_assert_lock_depth(tsdn, 0);
|
||||
|
||||
witness_init(&a, "a", 1, witness_comp);
|
||||
witness_assert_not_owner(tsdn, &a);
|
||||
witness_lock(tsdn, &a);
|
||||
witness_assert_owner(tsdn, &a);
|
||||
witness_assert_lock_depth(tsdn, 1);
|
||||
|
||||
witness_init(&b, "b", 1, witness_comp);
|
||||
witness_assert_not_owner(tsdn, &b);
|
||||
witness_lock(tsdn, &b);
|
||||
witness_assert_owner(tsdn, &b);
|
||||
witness_assert_lock_depth(tsdn, 2);
|
||||
witness_unlock(tsdn, &b);
|
||||
witness_assert_lock_depth(tsdn, 1);
|
||||
|
||||
witness_lock_error_orig = witness_lock_error;
|
||||
witness_lock_error = witness_lock_error_intercept;
|
||||
@@ -117,6 +124,7 @@ TEST_BEGIN(test_witness_comp)
|
||||
witness_lock(tsdn, &c);
|
||||
assert_true(saw_lock_error, "Expected witness lock error");
|
||||
witness_unlock(tsdn, &c);
|
||||
witness_assert_lock_depth(tsdn, 1);
|
||||
|
||||
saw_lock_error = false;
|
||||
|
||||
@@ -126,10 +134,11 @@ TEST_BEGIN(test_witness_comp)
|
||||
witness_lock(tsdn, &d);
|
||||
assert_true(saw_lock_error, "Expected witness lock error");
|
||||
witness_unlock(tsdn, &d);
|
||||
witness_assert_lock_depth(tsdn, 1);
|
||||
|
||||
witness_unlock(tsdn, &a);
|
||||
|
||||
witness_assert_lockless(tsdn);
|
||||
witness_assert_lock_depth(tsdn, 0);
|
||||
|
||||
witness_lock_error = witness_lock_error_orig;
|
||||
}
|
||||
@@ -148,20 +157,22 @@ TEST_BEGIN(test_witness_reversal)
|
||||
|
||||
tsdn = tsdn_fetch();
|
||||
|
||||
witness_assert_lockless(tsdn);
|
||||
witness_assert_lock_depth(tsdn, 0);
|
||||
|
||||
witness_init(&a, "a", 1, NULL);
|
||||
witness_init(&b, "b", 2, NULL);
|
||||
|
||||
witness_lock(tsdn, &b);
|
||||
witness_assert_lock_depth(tsdn, 1);
|
||||
assert_false(saw_lock_error, "Unexpected witness lock error");
|
||||
witness_lock(tsdn, &a);
|
||||
assert_true(saw_lock_error, "Expected witness lock error");
|
||||
|
||||
witness_unlock(tsdn, &a);
|
||||
witness_assert_lock_depth(tsdn, 1);
|
||||
witness_unlock(tsdn, &b);
|
||||
|
||||
witness_assert_lockless(tsdn);
|
||||
witness_assert_lock_depth(tsdn, 0);
|
||||
|
||||
witness_lock_error = witness_lock_error_orig;
|
||||
}
|
||||
@@ -184,7 +195,7 @@ TEST_BEGIN(test_witness_recursive)
|
||||
|
||||
tsdn = tsdn_fetch();
|
||||
|
||||
witness_assert_lockless(tsdn);
|
||||
witness_assert_lock_depth(tsdn, 0);
|
||||
|
||||
witness_init(&a, "a", 1, NULL);
|
||||
|
||||
@@ -197,7 +208,7 @@ TEST_BEGIN(test_witness_recursive)
|
||||
|
||||
witness_unlock(tsdn, &a);
|
||||
|
||||
witness_assert_lockless(tsdn);
|
||||
witness_assert_lock_depth(tsdn, 0);
|
||||
|
||||
witness_owner_error = witness_owner_error_orig;
|
||||
witness_lock_error = witness_lock_error_orig;
|
||||
@@ -218,7 +229,7 @@ TEST_BEGIN(test_witness_unlock_not_owned)
|
||||
|
||||
tsdn = tsdn_fetch();
|
||||
|
||||
witness_assert_lockless(tsdn);
|
||||
witness_assert_lock_depth(tsdn, 0);
|
||||
|
||||
witness_init(&a, "a", 1, NULL);
|
||||
|
||||
@@ -226,41 +237,41 @@ TEST_BEGIN(test_witness_unlock_not_owned)
|
||||
witness_unlock(tsdn, &a);
|
||||
assert_true(saw_owner_error, "Expected owner error");
|
||||
|
||||
witness_assert_lockless(tsdn);
|
||||
witness_assert_lock_depth(tsdn, 0);
|
||||
|
||||
witness_owner_error = witness_owner_error_orig;
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_witness_lockful)
|
||||
TEST_BEGIN(test_witness_lock_depth)
|
||||
{
|
||||
witness_t a;
|
||||
tsdn_t *tsdn;
|
||||
|
||||
test_skip_if(!config_debug);
|
||||
|
||||
witness_lockless_error_orig = witness_lockless_error;
|
||||
witness_lockless_error = witness_lockless_error_intercept;
|
||||
saw_lockless_error = false;
|
||||
witness_lock_depth_error_orig = witness_lock_depth_error;
|
||||
witness_lock_depth_error = witness_lock_depth_error_intercept;
|
||||
saw_lock_depth_error = false;
|
||||
|
||||
tsdn = tsdn_fetch();
|
||||
|
||||
witness_assert_lockless(tsdn);
|
||||
witness_assert_lock_depth(tsdn, 0);
|
||||
|
||||
witness_init(&a, "a", 1, NULL);
|
||||
|
||||
assert_false(saw_lockless_error, "Unexpected lockless error");
|
||||
witness_assert_lockless(tsdn);
|
||||
assert_false(saw_lock_depth_error, "Unexpected lock_depth error");
|
||||
witness_assert_lock_depth(tsdn, 0);
|
||||
|
||||
witness_lock(tsdn, &a);
|
||||
witness_assert_lockless(tsdn);
|
||||
assert_true(saw_lockless_error, "Expected lockless error");
|
||||
witness_assert_lock_depth(tsdn, 0);
|
||||
assert_true(saw_lock_depth_error, "Expected lock_depth error");
|
||||
|
||||
witness_unlock(tsdn, &a);
|
||||
|
||||
witness_assert_lockless(tsdn);
|
||||
witness_assert_lock_depth(tsdn, 0);
|
||||
|
||||
witness_lockless_error = witness_lockless_error_orig;
|
||||
witness_lock_depth_error = witness_lock_depth_error_orig;
|
||||
}
|
||||
TEST_END
|
||||
|
||||
@@ -274,5 +285,5 @@ main(void)
|
||||
test_witness_reversal,
|
||||
test_witness_recursive,
|
||||
test_witness_unlock_not_owned,
|
||||
test_witness_lockful));
|
||||
test_witness_lock_depth));
|
||||
}
|
||||
|
Reference in New Issue
Block a user