Commit 1644cc69 authored by Tom Burdick's avatar Tom Burdick Committed by Stephanos Ioannidis
Browse files

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: default avatarTom Burdick <thomas.burdick@intel.com>
parent 305e198e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
CONFIG_ZTEST=y
CONFIG_SPIN_VALIDATE=y
CONFIG_SPIN_LOCK_TIME_LIMIT=1000
CONFIG_SPIN_LOCK_TIME_LIMIT=100000
CONFIG_ZTEST_NEW_API=y
+30 −10
Original line number Diff line number Diff line
@@ -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)
{
	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);
#ifndef CONFIG_SPIN_LOCK_TIME_LIMIT
	ztest_test_skip();
	return;
#else
	if (CONFIG_SPIN_LOCK_TIME_LIMIT == 0) {
		ztest_test_skip();
		return;
	}

	key = k_spin_lock(&lock);

	for (volatile int i = 0; i < 100000; i++) {
	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);
	k_spin_unlock(&lock, key);
	set_assert_valid(true, false);
	k_spin_unlock(&timeout_lock, key);

	ztest_test_fail();
#endif
}