@@ -71,7 +71,16 @@ void increment_with_wait(counter_t *counter)
71
71
72
72
void increment_with_child (counter_t *counter)
73
73
{
74
- Thread *child = new Thread (osPriorityNormal, CHILD_THREAD_STACK_SIZE);
74
+ Thread *child = new (std::nothrow) Thread (osPriorityNormal, CHILD_THREAD_STACK_SIZE);
75
+ char *dummy = new (std::nothrow) char [CHILD_THREAD_STACK_SIZE];
76
+ delete[] dummy;
77
+
78
+ // Don't fail test due to lack of memory. Call function directly instead
79
+ if (!child || !dummy) {
80
+ increment (counter);
81
+ delete child;
82
+ return ;
83
+ }
75
84
child->start (callback (increment, counter));
76
85
child->join ();
77
86
delete child;
@@ -83,12 +92,21 @@ void increment_with_murder(counter_t *counter)
83
92
// take ownership of the counter mutex so it prevent the child to
84
93
// modify counter.
85
94
LockGuard lock (counter->internal_mutex ());
86
- Thread *child = new Thread (osPriorityNormal, CHILD_THREAD_STACK_SIZE);
95
+ Thread *child = new (std::nothrow) Thread (osPriorityNormal, CHILD_THREAD_STACK_SIZE);
96
+ char *dummy = new (std::nothrow) char [CHILD_THREAD_STACK_SIZE];
97
+ delete[] dummy;
98
+
99
+ // Don't fail test due to lack of memory.
100
+ if (!child || !dummy) {
101
+ delete child;
102
+ goto end;
103
+ }
87
104
child->start (callback (increment, counter));
88
105
child->terminate ();
89
106
delete child;
90
107
}
91
108
109
+ end:
92
110
(*counter)++;
93
111
}
94
112
@@ -134,6 +152,10 @@ void self_terminate(Thread *self)
134
152
template <void (*F)(counter_t *)>
135
153
void test_single_thread ()
136
154
{
155
+ char *dummy = new (std::nothrow) char [THREAD_STACK_SIZE];
156
+ delete[] dummy;
157
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory to run test" );
158
+
137
159
counter_t counter (0 );
138
160
Thread thread (osPriorityNormal, THREAD_STACK_SIZE);
139
161
thread.start (callback (F, &counter));
@@ -174,6 +196,10 @@ void test_single_thread()
174
196
template <int N, void (*F)(counter_t *)>
175
197
void test_parallel_threads ()
176
198
{
199
+ char *dummy = new (std::nothrow) char [PARALLEL_THREAD_STACK_SIZE * N];
200
+ delete[] dummy;
201
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory to run test" );
202
+
177
203
counter_t counter (0 );
178
204
ParallelThread<osPriorityNormal, PARALLEL_THREAD_STACK_SIZE> threads[N];
179
205
@@ -222,6 +248,9 @@ template <int N, void (*F)(counter_t *)>
222
248
void test_serial_threads ()
223
249
{
224
250
counter_t counter (0 );
251
+ char *dummy = new (std::nothrow) char [THREAD_STACK_SIZE];
252
+ delete[] dummy;
253
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory to run test" );
225
254
226
255
for (int i = 0 ; i < N; i++) {
227
256
Thread thread (osPriorityNormal, THREAD_STACK_SIZE);
@@ -240,9 +269,18 @@ void test_serial_threads()
240
269
*/
241
270
void test_self_terminate ()
242
271
{
243
- Thread *thread = new Thread (osPriorityNormal, THREAD_STACK_SIZE);
272
+ Thread *thread = new (std::nothrow) Thread (osPriorityNormal, THREAD_STACK_SIZE);
273
+ char *dummy = new (std::nothrow) char [THREAD_STACK_SIZE];
274
+ delete[] dummy;
275
+
276
+ // Don't fail test due to lack of memory.
277
+ if (!thread || !dummy) {
278
+ goto end;
279
+ }
244
280
thread->start (callback (self_terminate, thread));
245
281
thread->join ();
282
+
283
+ end:
246
284
delete thread;
247
285
}
248
286
@@ -300,6 +338,10 @@ void signal_wait_multibit_tout()
300
338
template <int S, void (*F)()>
301
339
void test_thread_signal ()
302
340
{
341
+ char *dummy = new (std::nothrow) char [THREAD_STACK_SIZE];
342
+ delete[] dummy;
343
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory to run test" );
344
+
303
345
Thread t_wait (osPriorityNormal, THREAD_STACK_SIZE);
304
346
305
347
t_wait.start (callback (F));
@@ -336,6 +378,10 @@ void signal_clr()
336
378
*/
337
379
void test_thread_signal_clr ()
338
380
{
381
+ char *dummy = new (std::nothrow) char [THREAD_STACK_SIZE];
382
+ delete[] dummy;
383
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory to run test" );
384
+
339
385
Thread t_wait (osPriorityNormal, THREAD_STACK_SIZE);
340
386
341
387
t_wait.start (callback (signal_clr));
@@ -374,6 +420,10 @@ void stack_info()
374
420
*/
375
421
void test_thread_stack_info ()
376
422
{
423
+ char *dummy = new (std::nothrow) char [THREAD_STACK_SIZE];
424
+ delete[] dummy;
425
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory to run test" );
426
+
377
427
Thread t (osPriorityNormal, THREAD_STACK_SIZE);
378
428
t.start (callback (stack_info));
379
429
@@ -425,6 +475,10 @@ void test_thread_wait()
425
475
*/
426
476
void test_thread_name ()
427
477
{
478
+ char *dummy = new (std::nothrow) char [THREAD_STACK_SIZE];
479
+ delete[] dummy;
480
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory to run test" );
481
+
428
482
const char tname[] = " Amazing thread" ;
429
483
Thread t (osPriorityNormal, THREAD_STACK_SIZE, NULL , tname);
430
484
t.start (callback (thread_wait_signal));
@@ -446,6 +500,10 @@ void test_deleted_thread()
446
500
*/
447
501
void test_deleted ()
448
502
{
503
+ char *dummy = new (std::nothrow) char [THREAD_STACK_SIZE];
504
+ delete[] dummy;
505
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory to run test" );
506
+
449
507
Thread t (osPriorityNormal, THREAD_STACK_SIZE);
450
508
451
509
TEST_ASSERT_EQUAL (Thread::Deleted, t.get_state ());
@@ -469,6 +527,10 @@ void test_delay_thread()
469
527
*/
470
528
void test_delay ()
471
529
{
530
+ char *dummy = new (std::nothrow) char [THREAD_STACK_SIZE];
531
+ delete[] dummy;
532
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory to run test" );
533
+
472
534
Thread t (osPriorityNormal, THREAD_STACK_SIZE);
473
535
474
536
t.start (callback (test_delay_thread));
@@ -494,6 +556,10 @@ void test_signal_thread()
494
556
*/
495
557
void test_signal ()
496
558
{
559
+ char *dummy = new (std::nothrow) char [THREAD_STACK_SIZE];
560
+ delete[] dummy;
561
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory to run test" );
562
+
497
563
Thread t (osPriorityNormal, THREAD_STACK_SIZE);
498
564
499
565
t.start (callback (test_signal_thread));
@@ -518,6 +584,10 @@ void test_evt_flag_thread(osEventFlagsId_t evtflg)
518
584
*/
519
585
void test_evt_flag ()
520
586
{
587
+ char *dummy = new (std::nothrow) char [THREAD_STACK_SIZE];
588
+ delete[] dummy;
589
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory to run test" );
590
+
521
591
Thread t (osPriorityNormal, THREAD_STACK_SIZE);
522
592
mbed_rtos_storage_event_flags_t evtflg_mem;
523
593
osEventFlagsAttr_t evtflg_attr;
@@ -550,6 +620,10 @@ void test_mutex_thread(Mutex *mutex)
550
620
*/
551
621
void test_mutex ()
552
622
{
623
+ char *dummy = new (std::nothrow) char [THREAD_STACK_SIZE];
624
+ delete[] dummy;
625
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory to run test" );
626
+
553
627
Thread t (osPriorityNormal, THREAD_STACK_SIZE);
554
628
Mutex mutex;
555
629
@@ -577,6 +651,10 @@ void test_semaphore_thread(Semaphore *sem)
577
651
*/
578
652
void test_semaphore ()
579
653
{
654
+ char *dummy = new (std::nothrow) char [THREAD_STACK_SIZE];
655
+ delete[] dummy;
656
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory to run test" );
657
+
580
658
Thread t (osPriorityNormal, THREAD_STACK_SIZE);
581
659
Semaphore sem;
582
660
@@ -602,6 +680,10 @@ void test_msg_get_thread(Queue<int32_t, 1> *queue)
602
680
*/
603
681
void test_msg_get ()
604
682
{
683
+ char *dummy = new (std::nothrow) char [THREAD_STACK_SIZE];
684
+ delete[] dummy;
685
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory to run test" );
686
+
605
687
Thread t (osPriorityNormal, THREAD_STACK_SIZE);
606
688
Queue<int32_t , 1 > queue;
607
689
@@ -628,6 +710,10 @@ void test_msg_put_thread(Queue<int32_t, 1> *queue)
628
710
*/
629
711
void test_msg_put ()
630
712
{
713
+ char *dummy = new (std::nothrow) char [THREAD_STACK_SIZE];
714
+ delete[] dummy;
715
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory to run test" );
716
+
631
717
Thread t (osPriorityNormal, THREAD_STACK_SIZE);
632
718
Queue<int32_t , 1 > queue;
633
719
@@ -680,6 +766,10 @@ void test_thread_ext_stack()
680
766
*/
681
767
void test_thread_prio ()
682
768
{
769
+ char *dummy = new (std::nothrow) char [THREAD_STACK_SIZE];
770
+ delete[] dummy;
771
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory to run test" );
772
+
683
773
Thread t (osPriorityNormal, THREAD_STACK_SIZE);
684
774
t.start (callback (thread_wait_signal));
685
775
0 commit comments