Commit 61b7757d authored by Adithya Baglody's avatar Adithya Baglody Committed by Anas Nashif
Browse files

tests: abort: Testcase for repeated thread abort



Test case to showcase the repeated abort of a thread.

Signed-off-by: default avatarAdithya Baglody <adithya.nagaraj.baglody@intel.com>
parent 10db82bf
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
CONFIG_ZTEST=y
CONFIG_THREAD_MONITOR=y
+3 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ extern void test_threads_cancel_delayed(void);
extern void test_threads_cancel_started(void);
extern void test_threads_abort_self(void);
extern void test_threads_abort_others(void);
extern void test_threads_abort_repeat(void);

__kernel struct k_thread tdata;
#define STACK_SIZE (256 + CONFIG_TEST_EXTRA_STACKSIZE)
@@ -45,7 +46,8 @@ void test_main(void)
			 ztest_user_unit_test(test_threads_cancel_delayed),
			 ztest_user_unit_test(test_threads_cancel_started),
			 ztest_user_unit_test(test_threads_abort_self),
			 ztest_user_unit_test(test_threads_abort_others)
			 ztest_user_unit_test(test_threads_abort_others),
			 ztest_unit_test(test_threads_abort_repeat)
			 );
	ztest_run_test_suite(test_threads_lifecycle);
}
+17 −0
Original line number Diff line number Diff line
@@ -123,3 +123,20 @@ void test_threads_abort_others(void)
	k_sleep(1000);
	zassert_true(execute_flag == 1, NULL);
}

/* Test should not crash if repeated aborts are called on a dead thread. */
void test_threads_abort_repeat(void)
{
	execute_flag = 0;
	k_tid_t tid = k_thread_create(&tdata, tstack, STACK_SIZE,
				      thread_entry, NULL, NULL, NULL,
				      0, K_USER, 0);

	k_thread_abort(tid);
	k_sleep(100);
	k_thread_abort(tid);
	k_sleep(100);
	k_thread_abort(tid);
	/* If no fault occured till now. The test case passed. */
	ztest_test_pass();
}