tests: Fix spinlock time limit test
Set the time limit to be long enough not to trigger too early. Do not unlock after assert when doing the time limit test. Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
This commit is contained in:
parent
305e198e45
commit
1644cc69d7
2 changed files with 33 additions and 13 deletions
|
@ -1,4 +1,4 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_SPIN_VALIDATE=y
|
||||
CONFIG_SPIN_LOCK_TIME_LIMIT=1000
|
||||
CONFIG_SPIN_LOCK_TIME_LIMIT=100000
|
||||
CONFIG_ZTEST_NEW_API=y
|
||||
|
|
|
@ -15,15 +15,20 @@ static struct k_spinlock mylock;
|
|||
static k_spinlock_key_t key;
|
||||
|
||||
static ZTEST_DMEM volatile bool valid_assert;
|
||||
static ZTEST_DMEM volatile bool unlock_after_assert;
|
||||
|
||||
static inline void set_assert_valid(bool valid)
|
||||
|
||||
static inline void set_assert_valid(bool valid, bool unlock)
|
||||
{
|
||||
valid_assert = valid;
|
||||
unlock_after_assert = unlock;
|
||||
}
|
||||
|
||||
static void action_after_assert_fail(void)
|
||||
{
|
||||
k_spin_unlock(&lock, key);
|
||||
if (unlock_after_assert) {
|
||||
k_spin_unlock(&lock, key);
|
||||
}
|
||||
|
||||
ztest_test_pass();
|
||||
}
|
||||
|
@ -77,7 +82,7 @@ ZTEST(spinlock, test_spinlock_no_recursive)
|
|||
|
||||
key = k_spin_lock(&lock);
|
||||
|
||||
set_assert_valid(true);
|
||||
set_assert_valid(true, true);
|
||||
re = k_spin_lock(&lock);
|
||||
|
||||
ztest_test_fail();
|
||||
|
@ -96,7 +101,7 @@ ZTEST(spinlock, test_spinlock_unlock_error)
|
|||
{
|
||||
key = k_spin_lock(&lock);
|
||||
|
||||
set_assert_valid(true);
|
||||
set_assert_valid(true, true);
|
||||
k_spin_unlock(&mylock, key);
|
||||
|
||||
ztest_test_fail();
|
||||
|
@ -115,7 +120,7 @@ ZTEST(spinlock, test_spinlock_release_error)
|
|||
{
|
||||
key = k_spin_lock(&lock);
|
||||
|
||||
set_assert_valid(true);
|
||||
set_assert_valid(true, true);
|
||||
k_spin_release(&mylock);
|
||||
|
||||
ztest_test_fail();
|
||||
|
@ -133,15 +138,30 @@ ZTEST(spinlock, test_spinlock_release_error)
|
|||
*/
|
||||
ZTEST(spinlock, test_spinlock_lock_time_limit)
|
||||
{
|
||||
Z_TEST_SKIP_IFNDEF(CONFIG_SPIN_LOCK_TIME_LIMIT);
|
||||
|
||||
key = k_spin_lock(&lock);
|
||||
|
||||
for (volatile int i = 0; i < 100000; i++) {
|
||||
#ifndef CONFIG_SPIN_LOCK_TIME_LIMIT
|
||||
ztest_test_skip();
|
||||
return;
|
||||
#else
|
||||
if (CONFIG_SPIN_LOCK_TIME_LIMIT == 0) {
|
||||
ztest_test_skip();
|
||||
return;
|
||||
}
|
||||
|
||||
set_assert_valid(true);
|
||||
k_spin_unlock(&lock, key);
|
||||
|
||||
struct k_spinlock timeout_lock;
|
||||
|
||||
TC_PRINT("testing lock time limit, limit is %d!\n", CONFIG_SPIN_LOCK_TIME_LIMIT);
|
||||
|
||||
|
||||
key = k_spin_lock(&timeout_lock);
|
||||
|
||||
/* spin here for at least 2x the cycle limit */
|
||||
for (volatile int i = 0; i < CONFIG_SPIN_LOCK_TIME_LIMIT*2; i++) {
|
||||
}
|
||||
|
||||
set_assert_valid(true, false);
|
||||
k_spin_unlock(&timeout_lock, key);
|
||||
|
||||
ztest_test_fail();
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue