test: kernel: sched: Add a test for nested scheduler lock
Add a new test for unlocking nested scheduler lock. Make sure that k_sched_unlock() isn't unconditionally a preemption point. Signed-off-by: Yasushi SHOJI <y-shoji@ispace-inc.com>
This commit is contained in:
parent
20d072465d
commit
1fe8269399
3 changed files with 51 additions and 0 deletions
|
@ -65,6 +65,7 @@ void test_main(void)
|
||||||
ztest_unit_test(test_time_slicing_disable_preemptible),
|
ztest_unit_test(test_time_slicing_disable_preemptible),
|
||||||
ztest_unit_test(test_lock_preemptible),
|
ztest_unit_test(test_lock_preemptible),
|
||||||
ztest_unit_test(test_unlock_preemptible),
|
ztest_unit_test(test_unlock_preemptible),
|
||||||
|
ztest_unit_test(test_unlock_nested_sched_lock),
|
||||||
ztest_unit_test(test_sched_is_preempt_thread),
|
ztest_unit_test(test_sched_is_preempt_thread),
|
||||||
ztest_unit_test(test_slice_reset),
|
ztest_unit_test(test_slice_reset),
|
||||||
ztest_unit_test(test_slice_scheduling),
|
ztest_unit_test(test_slice_scheduling),
|
||||||
|
|
|
@ -37,6 +37,7 @@ void test_time_slicing_preemptible(void);
|
||||||
void test_time_slicing_disable_preemptible(void);
|
void test_time_slicing_disable_preemptible(void);
|
||||||
void test_lock_preemptible(void);
|
void test_lock_preemptible(void);
|
||||||
void test_unlock_preemptible(void);
|
void test_unlock_preemptible(void);
|
||||||
|
void test_unlock_nested_sched_lock(void);
|
||||||
void test_sched_is_preempt_thread(void);
|
void test_sched_is_preempt_thread(void);
|
||||||
void test_slice_reset(void);
|
void test_slice_reset(void);
|
||||||
void test_slice_scheduling(void);
|
void test_slice_scheduling(void);
|
||||||
|
|
|
@ -365,6 +365,55 @@ void test_unlock_preemptible(void)
|
||||||
teardown_threads();
|
teardown_threads();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Validate nested k_sched_lock() and k_sched_unlock()
|
||||||
|
*
|
||||||
|
* @details In a preemptive thread, lock the scheduler twice and
|
||||||
|
* create a cooperative thread. Call k_sched_unlock() and check the
|
||||||
|
* cooperative thread haven't executed. Unlock it again to see the
|
||||||
|
* thread have executed this time.
|
||||||
|
*
|
||||||
|
* @see k_sched_lock(), k_sched_unlock()
|
||||||
|
*
|
||||||
|
* @ingroup kernel_sched_tests
|
||||||
|
*/
|
||||||
|
void test_unlock_nested_sched_lock(void)
|
||||||
|
{
|
||||||
|
/* set current thread to a preemptible priority */
|
||||||
|
init_prio = 0;
|
||||||
|
setup_threads();
|
||||||
|
|
||||||
|
/* take the scheduler lock twice */
|
||||||
|
k_sched_lock();
|
||||||
|
k_sched_lock();
|
||||||
|
|
||||||
|
/* spawn threads without wait */
|
||||||
|
spawn_threads(0);
|
||||||
|
|
||||||
|
/* do critical thing */
|
||||||
|
k_busy_wait(100000);
|
||||||
|
|
||||||
|
/* unlock once; this shouldn't let other threads to run */
|
||||||
|
k_sched_unlock();
|
||||||
|
|
||||||
|
/* checkpoint: no threads get executed */
|
||||||
|
for (int i = 0; i < THREADS_NUM; i++) {
|
||||||
|
zassert_true(tdata[i].executed == 0, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* unlock another; this let the higher thread to run */
|
||||||
|
k_sched_unlock();
|
||||||
|
|
||||||
|
/* checkpoint: higher threads NOT get executed */
|
||||||
|
zassert_true(tdata[0].executed == 1, NULL);
|
||||||
|
for (int i = 1; i < THREADS_NUM; i++) {
|
||||||
|
zassert_true(tdata[i].executed == 0, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* restore environment */
|
||||||
|
teardown_threads();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief validate k_wakeup() in some corner scenario
|
* @brief validate k_wakeup() in some corner scenario
|
||||||
* @details trigger a timer and after expiration of timer
|
* @details trigger a timer and after expiration of timer
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue