mirror of https://github.com/ARMmbed/mbed-os.git
Add test case for thread self termination
Test that thread self termination works.pull/2643/head
parent
b49d7e4fb4
commit
abbd71da9b
|
@ -59,6 +59,12 @@ void increment_with_murder(counter_t* counter) {
|
||||||
(*counter)++;
|
(*counter)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void self_terminate(Thread *self) {
|
||||||
|
self->terminate();
|
||||||
|
// Code should not get here
|
||||||
|
TEST_ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
// Tests that spawn tasks in different configurations
|
// Tests that spawn tasks in different configurations
|
||||||
template <void (*F)(counter_t *)>
|
template <void (*F)(counter_t *)>
|
||||||
void test_single_thread() {
|
void test_single_thread() {
|
||||||
|
@ -97,6 +103,13 @@ void test_serial_threads() {
|
||||||
TEST_ASSERT_EQUAL(counter, N);
|
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) {
|
utest::v1::status_t test_setup(const size_t number_of_cases) {
|
||||||
GREENTEA_SETUP(40, "default_auto");
|
GREENTEA_SETUP(40, "default_auto");
|
||||||
return verbose_test_setup_handler(number_of_cases);
|
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 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 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 serial threads with murder", test_serial_threads<10, increment_with_murder>),
|
||||||
|
|
||||||
|
Case("Testing thread self terminate", test_self_terminate),
|
||||||
};
|
};
|
||||||
|
|
||||||
Specification specification(test_setup, cases);
|
Specification specification(test_setup, cases);
|
||||||
|
|
Loading…
Reference in New Issue