Skip to content

Commit 6a0fcd3

Browse files
bulislawc1728p9
authored andcommitted
Reduce test overhead in preparation for CMSIS 5
Reduce RAM consumption so all tests can still be built when using CMSIS/RTX5. Also reduce clutter by removing the per target stack size defines in the tests.
1 parent 5ebe295 commit 6a0fcd3

File tree

16 files changed

+65
-255
lines changed

16 files changed

+65
-255
lines changed

TESTS/events/queue/main.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using namespace utest::v1;
99

10+
#define TEST_EQUEUE_SIZE 1024
1011

1112
// flag for called
1213
volatile bool touched = false;
@@ -43,7 +44,7 @@ void func0() {
4344

4445
#define SIMPLE_POSTS_TEST(i, ...) \
4546
void simple_posts_test##i() { \
46-
EventQueue queue; \
47+
EventQueue queue(TEST_EQUEUE_SIZE); \
4748
\
4849
touched = false; \
4950
queue.call(func##i,##__VA_ARGS__); \
@@ -78,7 +79,7 @@ template <int N>
7879
void call_in_test() {
7980
Timer tickers[N];
8081

81-
EventQueue queue;
82+
EventQueue queue(TEST_EQUEUE_SIZE);
8283

8384
for (int i = 0; i < N; i++) {
8485
tickers[i].start();
@@ -92,7 +93,7 @@ template <int N>
9293
void call_every_test() {
9394
Timer tickers[N];
9495

95-
EventQueue queue;
96+
EventQueue queue(TEST_EQUEUE_SIZE);
9697

9798
for (int i = 0; i < N; i++) {
9899
tickers[i].start();
@@ -103,7 +104,7 @@ void call_every_test() {
103104
}
104105

105106
void allocate_failure_test() {
106-
EventQueue queue;
107+
EventQueue queue(TEST_EQUEUE_SIZE);
107108
int id;
108109

109110
for (int i = 0; i < 100; i++) {
@@ -119,7 +120,7 @@ void no() {
119120

120121
template <int N>
121122
void cancel_test1() {
122-
EventQueue queue;
123+
EventQueue queue(TEST_EQUEUE_SIZE);
123124

124125
int ids[N];
125126

@@ -164,7 +165,7 @@ void count0() {
164165

165166
void event_class_test() {
166167
counter = 0;
167-
EventQueue queue(2048);
168+
EventQueue queue(TEST_EQUEUE_SIZE);
168169

169170
Event<void(int, int, int, int, int)> e5(&queue, count5);
170171
Event<void(int, int, int, int)> e4(&queue, count5, 1);
@@ -187,7 +188,7 @@ void event_class_test() {
187188

188189
void event_class_helper_test() {
189190
counter = 0;
190-
EventQueue queue(2048);
191+
EventQueue queue(TEST_EQUEUE_SIZE);
191192

192193
Event<void()> e5 = queue.event(count5, 1, 1, 1, 1, 1);
193194
Event<void()> e4 = queue.event(count4, 1, 1, 1, 1);
@@ -210,7 +211,7 @@ void event_class_helper_test() {
210211

211212
void event_inference_test() {
212213
counter = 0;
213-
EventQueue queue(2048);
214+
EventQueue queue(TEST_EQUEUE_SIZE);
214215

215216
queue.event(count5, 1, 1, 1, 1, 1).post();
216217
queue.event(count5, 1, 1, 1, 1).post(1);

TESTS/mbed_drivers/race_test/main.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,18 @@
2828

2929
using namespace utest::v1;
3030

31-
#define TEST_STACK_SIZE 1024
31+
#define TEST_STACK_SIZE 512
3232
static uint32_t instance_count = 0;
3333

3434
class TestClass {
3535
public:
3636
TestClass() {
37-
printf("TestClass ctor start\r\n");
3837
Thread::wait(500);
3938
instance_count++;
40-
printf("TestClass ctor end\r\n");
4139
}
4240

4341
void do_something() {
44-
printf("Do something called\r\n");
42+
Thread::wait(100);
4543
}
4644

4745
~TestClass() {
@@ -69,7 +67,6 @@ static void main_class_race()
6967

7068
void test_case_func_race()
7169
{
72-
printf("Running function race test\r\n");
7370
Callback<void()> cb(main_func_race);
7471
Thread *t1 = new Thread(osPriorityNormal, TEST_STACK_SIZE);
7572
Thread *t2 = new Thread(osPriorityNormal, TEST_STACK_SIZE);
@@ -95,7 +92,6 @@ void test_case_func_race()
9592

9693
void test_case_class_race()
9794
{
98-
printf("Running class race test\r\n");
9995
Callback<void()> cb(main_class_race);
10096
Thread *t1 = new Thread(osPriorityNormal, TEST_STACK_SIZE);
10197
Thread *t2 = new Thread(osPriorityNormal, TEST_STACK_SIZE);

TESTS/mbed_drivers/stats/main.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using namespace utest::v1;
3030

3131
#define ALLOCATION_SIZE_DEFAULT 564
3232
#define ALLOCATION_SIZE_SMALL 124
33-
#define ALLOCATION_SIZE_LARGE 790
33+
#define ALLOCATION_SIZE_LARGE 700
3434
#define ALLOCATION_SIZE_FAIL (1024 * 1024 *1024)
3535

3636
typedef void* (*malloc_cb_t) (uint32_t size);
@@ -49,7 +49,6 @@ malloc_cb_t malloc_thunk_array[] = {
4949

5050
void test_case_malloc_free_size()
5151
{
52-
printf("Initial print to setup stdio buffers\n");
5352
mbed_stats_heap_t stats_start;
5453
mbed_stats_heap_t stats_current;
5554
void *data;
@@ -127,26 +126,22 @@ void test_case_allocate_fail()
127126

128127
static void* thunk_malloc(uint32_t size)
129128
{
130-
printf("Malloc thunk\n");
131129
return malloc(size);
132130
}
133131

134132
static void* thunk_calloc_1(uint32_t size)
135133
{
136-
printf("Calloc thunk 1 byte\n");
137134
return calloc(size / 1, 1);
138135
}
139136

140137
static void* thunk_calloc_4(uint32_t size)
141138
{
142-
printf("Calloc thunk 4 bytes\n");
143139
return calloc(size / 4, 4);
144140
}
145141

146142

147143
static void* thunk_realloc(uint32_t size)
148144
{
149-
printf("Realloc thunk\n");
150145
return realloc(NULL, size);
151146
}
152147

TESTS/mbed_drivers/stl_features/main.cpp

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,10 @@ using namespace utest::v1;
3232
#define TABLE_SIZE(TAB) (sizeof(TAB) / sizeof(TAB[0]))
3333

3434
#define NEGATIVE_INTEGERS -32768,-3214,-999,-100,-1,0,1,4231,999,4123,32760,99999
35-
#define POSITIVE_INTEGERS 32768,3214,999,100,1,0,1,4231,999,4123,32760,99999
3635
#define FLOATS 0.002,0.92430,15.91320,791.77368,6208.2,25719.4952,426815.982588,6429271.046,42468024.93,212006462.910
3736
#define FLOATS_STR "0.002","0.92430","15.91320","791.77368","6208.2","25719.4952","426815.982588","6429271.046","42468024.93","212006462.910"
3837

39-
4038
namespace {
41-
int p_integers[] = {POSITIVE_INTEGERS};
42-
int n_integers[] = {NEGATIVE_INTEGERS};
43-
float floats[] = {FLOATS};
4439

4540
template <class T, class F>
4641
void BubbleSort(T& _array, size_t array_size, F functor) {
@@ -59,62 +54,49 @@ void BubbleSort(T& _array, size_t array_size, F functor) {
5954
}
6055
}
6156

62-
struct printInt {
63-
void operator()(int i) { printf("%d ", i); }
64-
};
65-
66-
struct printFloat {
67-
void operator()(float f) { printf("%f ", f); }
68-
};
69-
70-
struct printString {
71-
void operator()(const char* s) { printf("%s ", s); }
72-
};
73-
7457
struct greaterAbs {
7558
bool operator()(int a, int b) { return abs(a) > abs(b); }
7659
};
7760

7861
} // namespace
7962

8063
void test_case_stl_equal() {
81-
std::vector<int> v_pints(p_integers, p_integers + TABLE_SIZE(p_integers));
82-
TEST_ASSERT_TRUE(std::equal(v_pints.begin(), v_pints.end(), p_integers));
64+
const int n_integers[] = {NEGATIVE_INTEGERS};
65+
std::vector<int> v_pints(n_integers, n_integers + TABLE_SIZE(n_integers));
66+
TEST_ASSERT_TRUE(std::equal(v_pints.begin(), v_pints.end(), n_integers));
8367
}
8468

8569
void test_case_stl_transform() {
70+
const float floats[] = {FLOATS};
8671
const char* floats_str[] = {FLOATS_STR};
8772
float floats_transform[TABLE_SIZE(floats_str)] = {0.0};
8873
std::transform(floats_str, floats_str + TABLE_SIZE(floats_str), floats_transform, atof);
89-
//printf("stl_transform::floats_str: ");
90-
//std::for_each(floats_str, floats_str + TABLE_SIZE(floats_str), printString());
91-
//printf("stl_transform::floats_transform: ");
92-
//std::for_each(floats_transform, floats_transform + TABLE_SIZE(floats_transform), printFloat());
93-
//printf("\n");
9474

9575
TEST_ASSERT_TRUE(std::equal(floats_transform, floats_transform + TABLE_SIZE(floats_transform), floats));
9676
}
9777

9878
void test_case_stl_sort_greater() {
99-
std::vector<int> v_nints_1(n_integers, n_integers + TABLE_SIZE(n_integers));
100-
std::vector<int> v_nints_2(n_integers, n_integers + TABLE_SIZE(n_integers));
79+
int n_integers[] = {NEGATIVE_INTEGERS};
80+
int n_integers2[] = {NEGATIVE_INTEGERS};
10181

102-
BubbleSort(v_nints_1, v_nints_1.size(), std::greater<int>());
103-
std::sort(v_nints_2.begin(), v_nints_2.end(), std::greater<int>());
82+
BubbleSort(n_integers, TABLE_SIZE(n_integers), std::greater<int>());
83+
std::sort(n_integers2, n_integers2 + TABLE_SIZE(n_integers2), std::greater<int>());
10484

105-
TEST_ASSERT_TRUE(std::equal(v_nints_1.begin(), v_nints_1.end(), v_nints_2.begin()));
85+
TEST_ASSERT_TRUE(std::equal(n_integers2, n_integers2 + TABLE_SIZE(n_integers2), n_integers));
10686
}
10787

88+
10889
void test_case_stl_sort_abs() {
109-
std::vector<int> v_nints_1(n_integers, n_integers + TABLE_SIZE(n_integers));
110-
std::vector<int> v_nints_2(n_integers, n_integers + TABLE_SIZE(n_integers));
90+
int n_integers[] = {NEGATIVE_INTEGERS};
91+
int n_integers2[] = {NEGATIVE_INTEGERS};
11192

112-
BubbleSort(v_nints_1, v_nints_1.size(), greaterAbs());
113-
std::sort(v_nints_2.begin(), v_nints_2.end(), greaterAbs());
93+
BubbleSort(n_integers, TABLE_SIZE(n_integers), greaterAbs());
94+
std::sort(n_integers2, n_integers2 + TABLE_SIZE(n_integers2), greaterAbs());
11495

115-
TEST_ASSERT_TRUE(std::equal(v_nints_1.begin(), v_nints_1.end(), v_nints_2.begin()));
96+
TEST_ASSERT_TRUE(std::equal(n_integers2, n_integers2 + TABLE_SIZE(n_integers2), n_integers));
11697
}
11798

99+
118100
utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) {
119101
greentea_case_failure_abort_handler(source, reason);
120102
return STATUS_CONTINUE;

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

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,7 @@
66
#error [NOT_SUPPORTED] test not supported
77
#endif
88

9-
/*
10-
* The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
11-
* the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
12-
* and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
13-
*/
14-
#if defined(TARGET_STM32F070RB) && defined(TOOLCHAIN_GCC)
15-
#define STACK_SIZE DEFAULT_STACK_SIZE/2
16-
#elif (defined(TARGET_EFM32HG_STK3400)) && !defined(TOOLCHAIN_ARM_MICRO)
17-
#define STACK_SIZE 512
18-
#elif (defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32PG_STK3401)) && !defined(TOOLCHAIN_ARM_MICRO)
19-
#define STACK_SIZE 768
20-
#elif (defined(TARGET_EFM32GG_STK3700)) && !defined(TOOLCHAIN_ARM_MICRO)
21-
#define STACK_SIZE 1536
22-
#elif defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832)
23-
#define STACK_SIZE 768
24-
#elif defined(TARGET_XDOT_L151CC)
25-
#define STACK_SIZE 1024
26-
#else
27-
#define STACK_SIZE DEFAULT_STACK_SIZE
28-
#endif
9+
#define TEST_STACK_SIZE 768
2910

3011
#define SIGNAL_PRINT_TICK 0x01
3112

@@ -43,15 +24,15 @@ void print_tick_thread() {
4324

4425
int main() {
4526
GREENTEA_SETUP(total_ticks + 5, "timing_drift_auto");
46-
47-
Thread tick_thread(osPriorityNormal, STACK_SIZE);
27+
28+
Thread tick_thread(osPriorityNormal, TEST_STACK_SIZE);
4829
tick_thread.start(print_tick_thread);
49-
30+
5031
for (int i = 0; i <= total_ticks; i++) {
5132
Thread::wait(1000);
5233
tick_thread.signal_set(SIGNAL_PRINT_TICK);
5334
}
54-
35+
5536
tick_thread.join();
5637
GREENTEA_TESTSUITE_RESULT(1);
5738
}

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

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,7 @@
1111
#define QUEUE_PUT_ISR_VALUE 128
1212
#define QUEUE_PUT_THREAD_VALUE 127
1313

14-
/*
15-
* The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
16-
* the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
17-
* and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
18-
*/
19-
#if (defined(TARGET_EFM32HG_STK3400)) && !defined(TOOLCHAIN_ARM_MICRO)
20-
#define STACK_SIZE 512
21-
#elif (defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32PG_STK3401)) && !defined(TOOLCHAIN_ARM_MICRO)
22-
#define STACK_SIZE 768
23-
#elif (defined(TARGET_EFM32GG_STK3700)) && !defined(TOOLCHAIN_ARM_MICRO)
24-
#define STACK_SIZE 1536
25-
#elif defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832)
26-
#define STACK_SIZE 768
27-
#elif defined(TARGET_XDOT_L151CC)
28-
#define STACK_SIZE 1024
29-
#else
30-
#define STACK_SIZE DEFAULT_STACK_SIZE
31-
#endif
14+
#define TEST_STACK_SIZE 512
3215

3316
Queue<uint32_t, QUEUE_SIZE> queue;
3417

@@ -50,7 +33,7 @@ void queue_thread() {
5033
int main (void) {
5134
GREENTEA_SETUP(20, "default_auto");
5235

53-
Thread thread(osPriorityNormal, STACK_SIZE);
36+
Thread thread(osPriorityNormal, TEST_STACK_SIZE);
5437
thread.start(queue_thread);
5538
Ticker ticker;
5639
ticker.attach(queue_isr, 1.0);
@@ -60,7 +43,7 @@ int main (void) {
6043
while (true) {
6144
osEvent evt = queue.get();
6245
if (evt.status != osEventMessage) {
63-
printf("QUEUE_GET: Status(0x%02X) ... [FAIL]\r\n", evt.status);
46+
printf("QUEUE_GET: FAIL\r\n");
6447
result = false;
6548
break;
6649
} else {

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

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,11 @@ typedef struct {
1717
#define QUEUE_SIZE 16
1818
#define QUEUE_PUT_DELAY 100
1919

20-
/*
21-
* The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
22-
* the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
23-
* and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
24-
*/
25-
#if (defined(TARGET_EFM32HG_STK3400)) && !defined(TOOLCHAIN_ARM_MICRO)
26-
#define STACK_SIZE 512
27-
#elif (defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32PG_STK3401)) && !defined(TOOLCHAIN_ARM_MICRO)
28-
#define STACK_SIZE 768
29-
#elif (defined(TARGET_EFM32GG_STK3700)) && !defined(TOOLCHAIN_ARM_MICRO)
30-
#define STACK_SIZE 1536
31-
#elif defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832)
32-
#define STACK_SIZE 768
33-
#elif defined(TARGET_XDOT_L151CC)
34-
#define STACK_SIZE 1024
35-
#else
36-
#define STACK_SIZE DEFAULT_STACK_SIZE
37-
#endif
20+
#define STACK_SIZE 1024
3821

3922
Mail<mail_t, QUEUE_SIZE> mail_box;
4023

41-
void send_thread () {
24+
void send_thread (void const *argument) {
4225
static uint32_t i = 10;
4326
while (true) {
4427
i++; // fake data update
@@ -54,8 +37,7 @@ void send_thread () {
5437
int main (void) {
5538
GREENTEA_SETUP(20, "default_auto");
5639

57-
Thread thread(osPriorityNormal, STACK_SIZE);
58-
thread.start(send_thread);
40+
Thread thread(send_thread, NULL, osPriorityNormal, STACK_SIZE);
5941
bool result = true;
6042
int result_counter = 0;
6143

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#endif
88

99
#define NUM_THREADS 5
10+
1011
#if defined(__CORTEX_A9)
1112
#define THREAD_STACK_SIZE DEFAULT_STACK_SIZE
1213
#else

0 commit comments

Comments
 (0)