Limiting the thread stack for parallel threads test

Previously, the RTOS threads test was conditionally change the thread
stack size for all test cases based on the target. Now, it uses the
default stack size for all targets when threads are created serially,
and uses a 512 byte stack for the threads that are created in parallel.
pull/3510/head
Brian Daniels 2016-12-20 17:14:04 -06:00 committed by Anna Bridge
parent 7333c5ae6d
commit 480ec66b75
1 changed files with 7 additions and 23 deletions

View File

@ -15,23 +15,7 @@
* the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
* and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize. * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
*/ */
#if defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832) #define PARALLEL_STACK_SIZE 512
#define STACK_SIZE 512
#elif defined(TARGET_STM32F070RB) || defined(TARGET_STM32F072RB) || defined(TARGET_STM32F103RB) || defined(TARGET_STM32F091RC)
#define STACK_SIZE 512
#elif defined(TARGET_STM32F410RB)
#define STACK_SIZE 512
#elif defined(TARGET_STM32L073RZ)
#define STACK_SIZE 512
#elif defined(TARGET_XDOT_L151CC)
#define STACK_SIZE 1024
#elif defined(TARGET_HI2110)
#define STACK_SIZE 512
#elif defined(TARGET_EFR32)
#define STACK_SIZE 512
#else
#define STACK_SIZE DEFAULT_STACK_SIZE
#endif
using namespace utest::v1; using namespace utest::v1;
@ -55,7 +39,7 @@ void increment_with_wait(counter_t* counter) {
} }
void increment_with_child(counter_t* counter) { void increment_with_child(counter_t* counter) {
Thread child(counter, increment, osPriorityNormal, STACK_SIZE); Thread child(counter, increment);
child.join(); child.join();
} }
@ -64,7 +48,7 @@ void increment_with_murder(counter_t* counter) {
// take ownership of the counter mutex so it prevent the child to // take ownership of the counter mutex so it prevent the child to
// modify counter. // modify counter.
LockGuard lock(counter->internal_mutex()); LockGuard lock(counter->internal_mutex());
Thread child(counter, increment, osPriorityNormal, STACK_SIZE); Thread child(counter, increment);
child.terminate(); child.terminate();
} }
@ -81,7 +65,7 @@ void self_terminate(Thread *self) {
template <void (*F)(counter_t *)> template <void (*F)(counter_t *)>
void test_single_thread() { void test_single_thread() {
counter_t counter(0); counter_t counter(0);
Thread thread(&counter, F, osPriorityNormal, STACK_SIZE); Thread thread(&counter, F);
thread.join(); thread.join();
TEST_ASSERT_EQUAL(counter, 1); TEST_ASSERT_EQUAL(counter, 1);
} }
@ -92,7 +76,7 @@ void test_parallel_threads() {
Thread *threads[N]; Thread *threads[N];
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
threads[i] = new Thread(&counter, F, osPriorityNormal, STACK_SIZE); threads[i] = new Thread(&counter, F, osPriorityNormal, PARALLEL_STACK_SIZE);
} }
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
@ -108,7 +92,7 @@ void test_serial_threads() {
counter_t counter(0); counter_t counter(0);
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
Thread thread(&counter, F, osPriorityNormal, STACK_SIZE); Thread thread(&counter, F);
thread.join(); thread.join();
} }
@ -116,7 +100,7 @@ void test_serial_threads() {
} }
void test_self_terminate() { void test_self_terminate() {
Thread *thread = new Thread(osPriorityNormal, STACK_SIZE); Thread *thread = new Thread(osPriorityNormal);
thread->start(thread, self_terminate); thread->start(thread, self_terminate);
thread->join(); thread->join();
delete thread; delete thread;