Skip to content

Commit c24e461

Browse files
authored
Merge pull request #2248 from pan-/define_stack_stize_for_RTOS_threads_test
Define stack size of the threads spawned by RTOS threads test.
2 parents ec1adb2 + 2099da6 commit c24e461

File tree

1 file changed

+16
-5
lines changed
  • TESTS/mbedmicro-rtos-mbed/threads

1 file changed

+16
-5
lines changed

TESTS/mbedmicro-rtos-mbed/threads/main.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010
#error [NOT_SUPPORTED] test not supported
1111
#endif
1212

13+
/*
14+
* The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
15+
* the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
16+
* and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
17+
*/
18+
#if defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832)
19+
#define STACK_SIZE 512
20+
#else
21+
#define STACK_SIZE DEFAULT_STACK_SIZE
22+
#endif
23+
1324
using namespace utest::v1;
1425

1526
// The counter type used accross all the tests
@@ -32,7 +43,7 @@ void increment_with_wait(counter_t* counter) {
3243
}
3344

3445
void increment_with_child(counter_t* counter) {
35-
Thread child(counter, increment);
46+
Thread child(counter, increment, osPriorityNormal, STACK_SIZE);
3647
child.join();
3748
}
3849

@@ -41,7 +52,7 @@ void increment_with_murder(counter_t* counter) {
4152
// take ownership of the counter mutex so it prevent the child to
4253
// modify counter.
4354
LockGuard lock(counter->internal_mutex());
44-
Thread child(counter, increment);
55+
Thread child(counter, increment, osPriorityNormal, STACK_SIZE);
4556
child.terminate();
4657
}
4758

@@ -52,7 +63,7 @@ void increment_with_murder(counter_t* counter) {
5263
template <void (*F)(counter_t *)>
5364
void test_single_thread() {
5465
counter_t counter(0);
55-
Thread thread(&counter, F);
66+
Thread thread(&counter, F, osPriorityNormal, STACK_SIZE);
5667
thread.join();
5768
TEST_ASSERT_EQUAL(counter, 1);
5869
}
@@ -63,7 +74,7 @@ void test_parallel_threads() {
6374
Thread *threads[N];
6475

6576
for (int i = 0; i < N; i++) {
66-
threads[i] = new Thread(&counter, F);
77+
threads[i] = new Thread(&counter, F, osPriorityNormal, STACK_SIZE);
6778
}
6879

6980
for (int i = 0; i < N; i++) {
@@ -79,7 +90,7 @@ void test_serial_threads() {
7990
counter_t counter(0);
8091

8192
for (int i = 0; i < N; i++) {
82-
Thread thread(&counter, F);
93+
Thread thread(&counter, F, osPriorityNormal, STACK_SIZE);
8394
thread.join();
8495
}
8596

0 commit comments

Comments
 (0)