Add test case for thread self termination

Test that thread self termination works.
pull/2643/head
Russ Butler 2016-09-07 17:33:33 -05:00
parent b49d7e4fb4
commit abbd71da9b
1 changed files with 15 additions and 0 deletions

View File

@ -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 (*F)(counter_t *)>
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<increment_with_murder>),
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);