tests: add ending logic for the preempt test

Old tests/kernel/sched/preempt cannot be run repeatedly.
If you register the test_preempt() method twice, the
second run will fail. It is because the participating
threads don't exit properly when the main thread exits.

The new ztest fx implies that a unit test should be able
to run repeatedly. This commit enables that for the preempt
test by adding explicit epilogue.

Signed-off-by: Ming Shao <ming.shao@intel.com>
This commit is contained in:
Ming Shao 2022-08-16 08:53:50 +08:00 committed by Carles Cufí
parent 392cabe070
commit 80f8540f9b

View file

@ -346,6 +346,21 @@ void test_preempt(void)
* test is done
*/
k_sem_take(&main_sem, K_FOREVER);
/* unit test clean up */
/* k_thread_abort() also works here.
* But join should be more graceful.
*/
k_thread_join(&manager_thread, K_FOREVER);
/* worker threads have to be aborted.
* It is difficult to make them stop gracefully.
*/
for (int i = 0; i < NUM_THREADS; i++) {
k_thread_abort(&worker_threads[i]);
}
}
void test_main(void)