14
14
* See the License for the specific language governing permissions and
15
15
* limitations under the License.
16
16
*/
17
- #if defined(MBED_RTOS_SINGLE_THREAD) || !defined(MBED_CONF_RTOS_PRESENT)
18
- #error [NOT_SUPPORTED] Event flags test cases require RTOS with multithread to run
19
- #else
20
17
21
18
#include " mbed.h"
22
19
#include " greentea-client/test_env.h"
@@ -29,11 +26,13 @@ using utest::v1::Case;
29
26
#error [NOT_SUPPORTED] UsTicker need to be enabled for this test.
30
27
#else
31
28
29
+ #if defined(MBED_CONF_RTOS_PRESENT)
32
30
#if defined(__CORTEX_M23) || defined(__CORTEX_M33)
33
31
#define THREAD_STACK_SIZE 512
34
32
#else
35
33
#define THREAD_STACK_SIZE 320 /* 512B stack on GCC_ARM compiler cause out of memory on some 16kB RAM boards e.g. NUCLEO_F070RB */
36
34
#endif
35
+ #endif
37
36
38
37
#define MAX_FLAG_POS 30
39
38
#define PROHIBITED_FLAG_POS 31
@@ -45,8 +44,6 @@ using utest::v1::Case;
45
44
#define PROHIBITED_FLAG 0x80000000 /* 10000000000000000000000000000000 */
46
45
#define NO_FLAGS 0x0
47
46
48
- Semaphore sync_sem (0 , 1 );
49
-
50
47
template <uint32_t flags, uint32_t wait_ms>
51
48
void send_thread (EventFlags *ef)
52
49
{
@@ -59,6 +56,9 @@ void send_thread(EventFlags *ef)
59
56
}
60
57
}
61
58
59
+ #if defined(MBED_CONF_RTOS_PRESENT)
60
+ Semaphore sync_sem (0 , 1 );
61
+
62
62
template <uint32_t flags, uint32_t wait_ms>
63
63
void send_thread_sync (EventFlags *ef)
64
64
{
@@ -81,6 +81,7 @@ void wait_thread_all(EventFlags *ef)
81
81
TEST_ASSERT (flags | ret);
82
82
TEST_ASSERT (flags | ~flags_after_clear);
83
83
}
84
+ #endif
84
85
85
86
86
87
/* * Test if get on empty EventFlags object return NO_FLAGS
@@ -203,6 +204,7 @@ void test_set_get_clear_full_flag_range(void)
203
204
}
204
205
}
205
206
207
+ #if defined(MBED_CONF_RTOS_PRESENT)
206
208
/* * Test if multi-threaded flag set cause wait_all to return
207
209
208
210
Given a EventFlags object and three threads are started in parallel
@@ -347,7 +349,76 @@ void test_multi_thread_all_many_wait(void)
347
349
TEST_ASSERT_EQUAL (NO_FLAGS, ef.get ());
348
350
}
349
351
}
352
+ #else
353
+
354
+ /* * Test if multi-event flag set cause wait_all to return
355
+
356
+ Given a EventFlags object and three ticker instance with the callback registered
357
+ When callbacks set specified flags
358
+ Then main thread waits until receive all of them
359
+ */
360
+ void test_multi_eventflags_all (void )
361
+ {
362
+ EventFlags ef;
363
+ Ticker t1, t2, t3;
364
+ t1.attach_us (callback (send_thread<FLAG01, 0 >, &ef), 3000 );
365
+ t2.attach_us (callback (send_thread<FLAG02, 0 >, &ef), 5000 );
366
+ t3.attach_us (callback (send_thread<FLAG03, 0 >, &ef), 6000 );
367
+ uint32_t ret = ef.wait_all (FLAG01 | FLAG02 | FLAG03);
368
+ TEST_ASSERT_EQUAL (FLAG01 | FLAG02 | FLAG03, ret);
369
+ }
370
+
371
+ /* * Test if multi-event flag set cause wait_any to return
372
+
373
+ Given a EventFlags object and three ticker instance with the callback registered
374
+ When callbacks set specified flags
375
+ Then main thread waits until receive all of them
376
+ */
377
+
378
+ void test_multi_eventflags_any (void )
379
+ {
380
+ EventFlags ef;
381
+ uint32_t ret;
382
+ Ticker t1, t2, t3;
383
+ t1.attach_us (callback (send_thread<FLAG01, 0 >, &ef), 3000 );
384
+ t2.attach_us (callback (send_thread<FLAG02, 0 >, &ef), 4000 );
385
+ t3.attach_us (callback (send_thread<FLAG03, 0 >, &ef), 5000 );
386
+
387
+ for (int i = 0 ; i <= MAX_FLAG_POS; i++) {
388
+ uint32_t flag = 1 << i;
389
+ ret = ef.wait_any (flag);
390
+ TEST_ASSERT (flag | ret);
391
+ }
392
+ ret = ef.get ();
393
+ TEST_ASSERT_EQUAL (NO_FLAGS, ret);
394
+ }
395
+
396
+ /* * Test if multi-event flag set cause wait_any(without clear) to return
397
+
398
+ Given a EventFlags object and three ticker instance with the callback registered
399
+ When callbacks set specified flags
400
+ Then main thread waits until receive all of them
401
+ */
402
+ void test_multi_eventflags_any_no_clear (void )
403
+ {
404
+ EventFlags ef;
405
+ uint32_t ret;
406
+ Ticker t1, t2, t3;
407
+ t1.attach_us (callback (send_thread<FLAG01, 0 >, &ef), 3000 );
408
+ t2.attach_us (callback (send_thread<FLAG02, 0 >, &ef), 4000 );
409
+ t3.attach_us (callback (send_thread<FLAG03, 0 >, &ef), 5000 );
350
410
411
+ for (int i = 0 ; i <= MAX_FLAG_POS; i++) {
412
+ uint32_t flag = 1 << i;
413
+ ret = ef.wait_any (flag, osWaitForever, false );
414
+ TEST_ASSERT (flag | ret);
415
+ ret = ef.clear (flag);
416
+ TEST_ASSERT (ret < osFlagsError);
417
+ }
418
+ ret = ef.get ();
419
+ TEST_ASSERT_EQUAL (NO_FLAGS, ret);
420
+ }
421
+ #endif
351
422
utest::v1::status_t test_setup (const size_t number_of_cases)
352
423
{
353
424
GREENTEA_SETUP (10 , " default_auto" );
@@ -360,11 +431,17 @@ Case cases[] = {
360
431
Case (" Test empty set" , test_empty_set),
361
432
Case (" Test clear/set with prohibited flag" , test_prohibited),
362
433
Case (" Test set/get/clear for full flag range" , test_set_get_clear_full_flag_range),
434
+ #if defined(MBED_CONF_RTOS_PRESENT)
363
435
Case (" Test multi-threaded wait_all" , test_multi_thread_all),
364
436
Case (" Test multi-threaded wait_any" , test_multi_thread_any),
365
437
Case (" Test multi-threaded wait_all many wait" , test_multi_thread_all_many_wait),
366
438
Case (" Test multi-threaded wait_any timeout" , test_multi_thread_any_timeout),
367
439
Case (" Test multi-threaded wait_any no clear" , test_multi_thread_any_no_clear)
440
+ #else
441
+ Case (" Test multi-eventflags wait_all" , test_multi_eventflags_all),
442
+ Case (" Test multi-eventflags wait_any" , test_multi_eventflags_any),
443
+ Case (" Test multi-eventflags wait_any no clear" , test_multi_eventflags_any_no_clear)
444
+ #endif
368
445
};
369
446
370
447
utest::v1::Specification specification (test_setup, cases);
@@ -375,4 +452,3 @@ int main()
375
452
}
376
453
377
454
#endif // !DEVICE_USTICKER
378
- #endif // defined(MBED_RTOS_SINGLE_THREAD) || !defined(MBED_CONF_RTOS_PRESENT)
0 commit comments