25
25
#error [NOT_SUPPORTED] test not supported
26
26
#endif
27
27
28
- #define THREAD_STACK_SIZE 768
28
+ #define THREAD_STACK_SIZE 512
29
+ #define PARALLEL_THREAD_STACK_SIZE 384
30
+ #define CHILD_THREAD_STACK_SIZE 384
29
31
30
32
using namespace utest ::v1;
31
33
32
34
// The counter type used accross all the tests
33
35
// It is internall ysynchronized so read
34
36
typedef SynchronizedIntegral<int > counter_t ;
35
37
38
+ template <osPriority P, uint32_t S>
39
+ class ParallelThread : public Thread {
40
+ public:
41
+ ParallelThread () : Thread(P, S) { }
42
+ };
43
+
36
44
// Tasks with different functions to test on threads
37
45
void increment (counter_t * counter) {
38
46
(*counter)++;
@@ -49,19 +57,21 @@ void increment_with_wait(counter_t* counter) {
49
57
}
50
58
51
59
void increment_with_child (counter_t * counter) {
52
- Thread child (osPriorityNormal, THREAD_STACK_SIZE/2 );
53
- child.start (callback (increment, counter));
54
- child.join ();
60
+ Thread *child = new Thread (osPriorityNormal, CHILD_THREAD_STACK_SIZE);
61
+ child->start (callback (increment, counter));
62
+ child->join ();
63
+ delete child;
55
64
}
56
65
57
66
void increment_with_murder (counter_t * counter) {
58
67
{
59
68
// take ownership of the counter mutex so it prevent the child to
60
69
// modify counter.
61
70
LockGuard lock (counter->internal_mutex ());
62
- Thread child (osPriorityNormal, THREAD_STACK_SIZE);
63
- child.start (callback (increment, counter));
64
- child.terminate ();
71
+ Thread *child = new Thread (osPriorityNormal, CHILD_THREAD_STACK_SIZE);
72
+ child->start (callback (increment, counter));
73
+ child->terminate ();
74
+ delete child;
65
75
}
66
76
67
77
(*counter)++;
@@ -147,16 +157,14 @@ void test_single_thread() {
147
157
template <int N, void (*F)(counter_t *)>
148
158
void test_parallel_threads () {
149
159
counter_t counter (0 );
150
- Thread * threads[N];
160
+ ParallelThread<osPriorityNormal, PARALLEL_THREAD_STACK_SIZE> threads[N];
151
161
152
162
for (int i = 0 ; i < N; i++) {
153
- threads[i] = new Thread (osPriorityNormal, THREAD_STACK_SIZE);
154
- threads[i]->start (callback (F, &counter));
163
+ threads[i].start (callback (F, &counter));
155
164
}
156
165
157
166
for (int i = 0 ; i < N; i++) {
158
- threads[i]->join ();
159
- delete threads[i];
167
+ threads[i].join ();
160
168
}
161
169
162
170
TEST_ASSERT_EQUAL (counter, N);
@@ -272,7 +280,7 @@ void signal_wait_multibit_tout()
272
280
template <int S, void (*F)()>
273
281
void test_thread_signal ()
274
282
{
275
- Thread t_wait;
283
+ Thread t_wait (osPriorityNormal, THREAD_STACK_SIZE) ;
276
284
277
285
t_wait.start (callback (F));
278
286
@@ -308,7 +316,7 @@ void signal_clr()
308
316
*/
309
317
void test_thread_signal_clr ()
310
318
{
311
- Thread t_wait;
319
+ Thread t_wait (osPriorityNormal, THREAD_STACK_SIZE) ;
312
320
313
321
t_wait.start (callback (signal_clr));
314
322
@@ -413,7 +421,7 @@ void test_deleted_thread()
413
421
*/
414
422
void test_deleted ()
415
423
{
416
- Thread t;
424
+ Thread t (osPriorityNormal, THREAD_STACK_SIZE) ;
417
425
418
426
TEST_ASSERT_EQUAL (Thread::Deleted, t.get_state ());
419
427
@@ -436,7 +444,7 @@ void test_delay_thread()
436
444
*/
437
445
void test_delay ()
438
446
{
439
- Thread t;
447
+ Thread t (osPriorityNormal, THREAD_STACK_SIZE) ;
440
448
441
449
t.start (callback (test_delay_thread));
442
450
@@ -461,7 +469,7 @@ void test_signal_thread()
461
469
*/
462
470
void test_signal ()
463
471
{
464
- Thread t;
472
+ Thread t (osPriorityNormal, THREAD_STACK_SIZE) ;
465
473
466
474
t.start (callback (test_signal_thread));
467
475
@@ -485,7 +493,7 @@ void test_evt_flag_thread(osEventFlagsId_t evtflg)
485
493
*/
486
494
void test_evt_flag ()
487
495
{
488
- Thread t;
496
+ Thread t (osPriorityNormal, THREAD_STACK_SIZE) ;
489
497
mbed_rtos_storage_event_flags_t evtflg_mem;
490
498
osEventFlagsAttr_t evtflg_attr;
491
499
osEventFlagsId_t evtflg;
@@ -517,7 +525,7 @@ void test_mutex_thread(Mutex *mutex)
517
525
*/
518
526
void test_mutex ()
519
527
{
520
- Thread t;
528
+ Thread t (osPriorityNormal, THREAD_STACK_SIZE) ;
521
529
Mutex mutex;
522
530
523
531
mutex.lock ();
@@ -544,7 +552,7 @@ void test_semaphore_thread(Semaphore *sem)
544
552
*/
545
553
void test_semaphore ()
546
554
{
547
- Thread t;
555
+ Thread t (osPriorityNormal, THREAD_STACK_SIZE) ;
548
556
Semaphore sem;
549
557
550
558
t.start (callback (test_semaphore_thread, &sem));
@@ -569,7 +577,7 @@ void test_msg_get_thread(Queue<int32_t, 1> *queue)
569
577
*/
570
578
void test_msg_get ()
571
579
{
572
- Thread t;
580
+ Thread t (osPriorityNormal, THREAD_STACK_SIZE) ;
573
581
Queue<int32_t , 1 > queue;
574
582
575
583
t.start (callback (test_msg_get_thread, &queue));
@@ -595,7 +603,7 @@ void test_msg_put_thread(Queue<int32_t, 1> *queue)
595
603
*/
596
604
void test_msg_put ()
597
605
{
598
- Thread t;
606
+ Thread t (osPriorityNormal, THREAD_STACK_SIZE) ;
599
607
Queue<int32_t , 1 > queue;
600
608
601
609
queue.put ((int32_t *)0xE1EE7 );
@@ -643,7 +651,7 @@ void test_thread_ext_stack() {
643
651
then priority is changed and can be retrieved using @a get_priority
644
652
*/
645
653
void test_thread_prio () {
646
- Thread t (osPriorityNormal);
654
+ Thread t (osPriorityNormal, THREAD_STACK_SIZE );
647
655
t.start (callback (thread_wait_signal));
648
656
649
657
TEST_ASSERT_EQUAL (osPriorityNormal, t.get_priority ());
@@ -679,11 +687,11 @@ static const case_t cases[] = {
679
687
{" Testing serial threads with wait" , test_serial_threads<10 , increment_with_wait>, DEFAULT_HANDLERS},
680
688
681
689
{" Testing single thread with child" , test_single_thread<increment_with_child>, DEFAULT_HANDLERS},
682
- {" Testing parallel threads with child" , test_parallel_threads<3 , increment_with_child>, DEFAULT_HANDLERS},
690
+ {" Testing parallel threads with child" , test_parallel_threads<2 , increment_with_child>, DEFAULT_HANDLERS},
683
691
{" Testing serial threads with child" , test_serial_threads<10 , increment_with_child>, DEFAULT_HANDLERS},
684
692
685
693
{" Testing single thread with murder" , test_single_thread<increment_with_murder>, DEFAULT_HANDLERS},
686
- {" Testing parallel threads with murder" , test_parallel_threads<3 , increment_with_murder>, DEFAULT_HANDLERS},
694
+ {" Testing parallel threads with murder" , test_parallel_threads<2 , increment_with_murder>, DEFAULT_HANDLERS},
687
695
{" Testing serial threads with murder" , test_serial_threads<10 , increment_with_murder>, DEFAULT_HANDLERS},
688
696
689
697
{" Testing thread self terminate" , test_self_terminate, DEFAULT_HANDLERS},
@@ -710,6 +718,7 @@ static const case_t cases[] = {
710
718
711
719
{" Testing thread with external stack memory" , test_thread_ext_stack, DEFAULT_HANDLERS},
712
720
{" Testing thread priority ops" , test_thread_prio, DEFAULT_HANDLERS}
721
+
713
722
};
714
723
715
724
Specification specification (test_setup, cases);
0 commit comments