From abbd71da9b5cfd12bad4a8a7050493e53f508054 Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Wed, 7 Sep 2016 17:33:33 -0500 Subject: [PATCH] Add test case for thread self termination Test that thread self termination works. --- TESTS/mbedmicro-rtos-mbed/threads/main.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/TESTS/mbedmicro-rtos-mbed/threads/main.cpp b/TESTS/mbedmicro-rtos-mbed/threads/main.cpp index 1fb638b3cd..cebe9b2f84 100644 --- a/TESTS/mbedmicro-rtos-mbed/threads/main.cpp +++ b/TESTS/mbedmicro-rtos-mbed/threads/main.cpp @@ -59,6 +59,12 @@ void increment_with_murder(counter_t* counter) { (*counter)++; } +void self_terminate(Thread *self) { + self->terminate(); + // Code should not get here + TEST_ASSERT(0); +} + // Tests that spawn tasks in different configurations template void test_single_thread() { @@ -97,6 +103,13 @@ void test_serial_threads() { TEST_ASSERT_EQUAL(counter, N); } +void test_self_terminate() { + Thread *thread = new Thread(osPriorityNormal, STACK_SIZE); + thread->start(thread, self_terminate); + thread->join(); + delete thread; +} + utest::v1::status_t test_setup(const size_t number_of_cases) { GREENTEA_SETUP(40, "default_auto"); return verbose_test_setup_handler(number_of_cases); @@ -123,6 +136,8 @@ Case cases[] = { Case("Testing single thread with murder", test_single_thread), Case("Testing parallel threads with murder", test_parallel_threads<3, increment_with_murder>), Case("Testing serial threads with murder", test_serial_threads<10, increment_with_murder>), + + Case("Testing thread self terminate", test_self_terminate), }; Specification specification(test_setup, cases);