Commit e89fe33a authored by Enjia Mai's avatar Enjia Mai Committed by Anas Nashif
Browse files

tests: thread: refine the thread abort test case



Refine the thread abort test case and add one extra condition.

Signed-off-by: default avatarEnjia Mai <enjiax.mai@intel.com>
parent 30bf585e
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ extern void test_threads_cpu_mask(void);
extern void test_threads_suspend_timeout(void);
extern void test_threads_suspend(void);
extern void test_abort_from_isr(void);
extern void test_abort_from_isr_not_self(void);
extern void test_essential_thread_abort(void);

struct k_thread tdata;
@@ -516,7 +517,8 @@ void test_main(void)
			 ztest_user_unit_test(test_thread_join),
			 ztest_unit_test(test_thread_join_isr),
			 ztest_user_unit_test(test_thread_join_deadlock),
			 ztest_unit_test(test_abort_from_isr)
			 ztest_unit_test(test_abort_from_isr),
			 ztest_unit_test(test_abort_from_isr_not_self)
			 );

	ztest_run_test_suite(threads_lifecycle);
+57 −1
Original line number Diff line number Diff line
@@ -218,9 +218,15 @@ static void entry_abort_isr(void *p1, void *p2, void *p3)
	ztest_test_fail();
}

extern struct k_sem offload_sem;

/**
 * @ingroup kernel_thread_tests
 * @brief Show that threads can be aborted from interrupt context
 *
 * @brief Show that threads can be aborted from interrupt context by itself
 *
 * @details Spwan a thread, then enter ISR context in child thread and abort
 * the child thread. Check if ISR completed and target thread was aborted.
 *
 * @see k_thread_abort()
 */
@@ -231,6 +237,56 @@ void test_abort_from_isr(void)
			NULL, NULL, NULL, 0, 0, K_NO_WAIT);


	k_thread_join(&tdata, K_FOREVER);
	zassert_true(isr_finished, "ISR did not complete");

	/* Notice: Recover back the offload_sem: This is use for releasing
	 * offload_sem which might be held when thread aborts itself in ISR
	 * context, it will cause irq_offload cannot be used again.
	 */
	k_sem_give(&offload_sem);
}

/* use for sync thread start */
static struct k_sem sem_abort;

static void entry_aborted_thread(void *p1, void *p2, void *p3)
{
	k_sem_give(&sem_abort);

	/* wait for being aborted */
	while (1) {
		k_sleep(K_MSEC(1));
	}
	zassert_unreachable("should not reach here");
}

/**
 * @ingroup kernel_thread_tests
 *
 * @brief Show that threads can be aborted from interrupt context
 *
 * @details Spwan a thread, then enter ISR context in main thread and abort
 * the child thread. Check if ISR completed and target thread was aborted.
 *
 * @see k_thread_abort()
 */
void test_abort_from_isr_not_self(void)
{
	k_tid_t tid;

	isr_finished = false;
	k_sem_init(&sem_abort, 0, 1);

	tid = k_thread_create(&tdata, tstack, STACK_SIZE, entry_aborted_thread,
			NULL, NULL, NULL, 0, 0, K_NO_WAIT);

	/* wait for thread started */
	k_sem_take(&sem_abort, K_FOREVER);

	/* Simulate taking an interrupt which kills spwan thread */
	irq_offload(offload_func, (void *)tid);

	k_thread_join(&tdata, K_FOREVER);
	zassert_true(isr_finished, "ISR did not complete");
}