21
21
#include " utest/utest.h"
22
22
23
23
using utest::v1::Case;
24
+ using namespace std ::chrono;
24
25
25
26
#if !DEVICE_USTICKER
26
27
#error [NOT_SUPPORTED] UsTicker need to be enabled for this test.
@@ -44,14 +45,14 @@ using utest::v1::Case;
44
45
#define PROHIBITED_FLAG 0x80000000 /* 10000000000000000000000000000000 */
45
46
#define NO_FLAGS 0x0
46
47
47
- void send_thread (EventFlags *ef, uint32_t flags, uint32_t wait_ms )
48
+ void send_thread (EventFlags *ef, uint32_t flags, milliseconds wait )
48
49
{
49
50
for (uint32_t i = 0 ; i <= MAX_FLAG_POS; i++) {
50
51
const uint32_t flag = flags & (1 << i);
51
52
if (flag) {
52
53
ef->set (flag);
53
- if (wait_ms != 0 ) {
54
- ThisThread::sleep_for (wait_ms );
54
+ if (wait != 0ms ) {
55
+ ThisThread::sleep_for (wait );
55
56
}
56
57
}
57
58
}
@@ -60,21 +61,19 @@ void send_thread(EventFlags *ef, uint32_t flags, uint32_t wait_ms)
60
61
#if defined(MBED_CONF_RTOS_PRESENT)
61
62
Semaphore sync_sem (0 , 1 );
62
63
63
- template <uint32_t flags, uint32_t wait_ms>
64
- void send_thread_sync (EventFlags *ef)
64
+ void send_thread_sync (EventFlags *ef, uint32_t flags, milliseconds wait)
65
65
{
66
66
for (uint32_t i = 0 ; i <= MAX_FLAG_POS; i++) {
67
67
const uint32_t flag = flags & (1 << i);
68
68
if (flag) {
69
69
sync_sem.acquire ();
70
70
ef->set (flag);
71
- ThisThread::sleep_for (wait_ms );
71
+ ThisThread::sleep_for (wait );
72
72
}
73
73
}
74
74
}
75
75
76
- template <uint32_t flags>
77
- void wait_thread_all (EventFlags *ef)
76
+ void wait_thread_all (EventFlags *ef, uint32_t flags)
78
77
{
79
78
uint32_t ret, flags_after_clear;
80
79
ret = ef->wait_all (flags);
@@ -218,9 +217,9 @@ void test_multi_thread_all(void)
218
217
Thread thread1 (osPriorityNormal, THREAD_STACK_SIZE);
219
218
Thread thread2 (osPriorityNormal, THREAD_STACK_SIZE);
220
219
Thread thread3 (osPriorityNormal, THREAD_STACK_SIZE);
221
- thread1.start ([&] { send_thread (&ef, FLAG01, 1 ); });
222
- thread2.start ([&] { send_thread (&ef, FLAG02, 2 ); });
223
- thread3.start ([&] { send_thread (&ef, FLAG03, 3 ); });
220
+ thread1.start ([&] { send_thread (&ef, FLAG01, 1ms ); });
221
+ thread2.start ([&] { send_thread (&ef, FLAG02, 2ms ); });
222
+ thread3.start ([&] { send_thread (&ef, FLAG03, 3ms ); });
224
223
225
224
uint32_t ret = ef.wait_all (FLAG01 | FLAG02 | FLAG03);
226
225
TEST_ASSERT_EQUAL (FLAG01 | FLAG02 | FLAG03, ret);
@@ -239,9 +238,9 @@ void test_multi_thread_any(void)
239
238
Thread thread1 (osPriorityNormal, THREAD_STACK_SIZE);
240
239
Thread thread2 (osPriorityNormal, THREAD_STACK_SIZE);
241
240
Thread thread3 (osPriorityNormal, THREAD_STACK_SIZE);
242
- thread1.start ([&] { send_thread (&ef, FLAG01, 1 ); });
243
- thread2.start ([&] { send_thread (&ef, FLAG02, 1 ); });
244
- thread3.start ([&] { send_thread (&ef, FLAG03, 1 ); });
241
+ thread1.start ([&] { send_thread (&ef, FLAG01, 1ms ); });
242
+ thread2.start ([&] { send_thread (&ef, FLAG02, 1ms ); });
243
+ thread3.start ([&] { send_thread (&ef, FLAG03, 1ms ); });
245
244
246
245
for (int i = 0 ; i <= MAX_FLAG_POS; i++) {
247
246
uint32_t flag = 1 << i;
@@ -265,16 +264,16 @@ void test_multi_thread_any_timeout(void)
265
264
EventFlags ef;
266
265
uint32_t ret;
267
266
Thread thread (osPriorityNormal, THREAD_STACK_SIZE);
268
- thread.start (callback (send_thread_sync < FLAG01 | FLAG02 | FLAG03, 1 >, &ef) );
267
+ thread.start ([&] { send_thread_sync (&ef, FLAG01 | FLAG02 | FLAG03, 1ms); } );
269
268
270
269
for (int i = 0 ; i <= MAX_FLAG_POS; i++) {
271
270
uint32_t flag = 1 << i;
272
271
273
- ret = ef.wait_any (flag, 10 );
272
+ ret = ef.wait_any_for (flag, 10ms );
274
273
TEST_ASSERT_EQUAL (osFlagsErrorTimeout, ret);
275
274
276
275
sync_sem.release ();
277
- ret = ef.wait_any (flag, 10 );
276
+ ret = ef.wait_any_for (flag, 10ms );
278
277
TEST_ASSERT_EQUAL (flag, ret);
279
278
}
280
279
ret = ef.get ();
@@ -294,13 +293,13 @@ void test_multi_thread_any_no_clear(void)
294
293
Thread thread1 (osPriorityNormal, THREAD_STACK_SIZE);
295
294
Thread thread2 (osPriorityNormal, THREAD_STACK_SIZE);
296
295
Thread thread3 (osPriorityNormal, THREAD_STACK_SIZE);
297
- thread1.start ([&] { send_thread (&ef, FLAG01, 1 ); });
298
- thread2.start ([&] { send_thread (&ef, FLAG02, 1 ); });
299
- thread3.start ([&] { send_thread (&ef, FLAG03, 1 ); });
296
+ thread1.start ([&] { send_thread (&ef, FLAG01, 1ms ); });
297
+ thread2.start ([&] { send_thread (&ef, FLAG02, 1ms ); });
298
+ thread3.start ([&] { send_thread (&ef, FLAG03, 1ms ); });
300
299
301
300
for (int i = 0 ; i <= MAX_FLAG_POS; i++) {
302
301
uint32_t flag = 1 << i;
303
- ret = ef.wait_any (flag, osWaitForever , false );
302
+ ret = ef.wait_any_for (flag, Kernel::wait_for_u32_forever , false );
304
303
TEST_ASSERT (flag | ret);
305
304
ret = ef.clear (flag);
306
305
TEST_ASSERT (ret < osFlagsError);
@@ -322,9 +321,9 @@ void test_multi_thread_all_many_wait(void)
322
321
Thread thread1 (osPriorityNormal, THREAD_STACK_SIZE);
323
322
Thread thread2 (osPriorityNormal, THREAD_STACK_SIZE);
324
323
Thread thread3 (osPriorityNormal, THREAD_STACK_SIZE);
325
- thread1.start (callback (wait_thread_all<FLAG01>, &ef) );
326
- thread2.start (callback (wait_thread_all<FLAG02>, &ef) );
327
- thread3.start (callback (wait_thread_all<FLAG03>, &ef) );
324
+ thread1.start ([&] { wait_thread_all ( &ef, FLAG01); } );
325
+ thread2.start ([&] { wait_thread_all ( &ef, FLAG02); } );
326
+ thread3.start ([&] { wait_thread_all ( &ef, FLAG03); } );
328
327
329
328
ef.set (FLAG01 | FLAG02 | FLAG03);
330
329
thread1.join ();
@@ -337,9 +336,9 @@ void test_multi_thread_all_many_wait(void)
337
336
Thread thread1 (osPriorityNormal, THREAD_STACK_SIZE);
338
337
Thread thread2 (osPriorityNormal, THREAD_STACK_SIZE);
339
338
Thread thread3 (osPriorityNormal, THREAD_STACK_SIZE);
340
- thread1.start (callback (wait_thread_all<FLAG01>, &ef) );
341
- thread2.start (callback (wait_thread_all<FLAG02>, &ef) );
342
- thread3.start (callback (wait_thread_all<FLAG03>, &ef) );
339
+ thread1.start ([&] { wait_thread_all ( &ef, FLAG01); } );
340
+ thread2.start ([&] { wait_thread_all ( &ef, FLAG02); } );
341
+ thread3.start ([&] { wait_thread_all ( &ef, FLAG03); } );
343
342
344
343
ef.set (FLAG01);
345
344
thread1.join ();
@@ -362,10 +361,10 @@ void test_multi_eventflags_all(void)
362
361
{
363
362
EventFlags ef;
364
363
Ticker t1, t2, t3;
365
- t1.attach_us ([&] { send_thread (&ef, FLAG01, 0 ); }, 3000 );
366
- t2.attach_us ([&] { send_thread (&ef, FLAG02, 0 ); }, 4000 );
367
- t3.attach_us ([&] { send_thread (&ef, FLAG03, 0 ); }, 5000 );
368
- uint32_t ret = ef.wait_all (FLAG01 | FLAG02 | FLAG03, 20 , false );
364
+ t1.attach ([&] { send_thread (&ef, FLAG01, 0ms ); }, 3ms );
365
+ t2.attach ([&] { send_thread (&ef, FLAG02, 0ms ); }, 4ms );
366
+ t3.attach ([&] { send_thread (&ef, FLAG03, 0ms ); }, 5ms );
367
+ uint32_t ret = ef.wait_all_for (FLAG01 | FLAG02 | FLAG03, 20ms , false );
369
368
TEST_ASSERT_EQUAL (FLAG01 | FLAG02 | FLAG03, ret);
370
369
}
371
370
@@ -380,9 +379,9 @@ void test_multi_eventflags_any(void)
380
379
EventFlags ef;
381
380
uint32_t ret;
382
381
Ticker t1, t2, t3;
383
- t1.attach_us ([&] { send_thread (&ef, FLAG01, 0 ); }, 3000 );
384
- t2.attach_us ([&] { send_thread (&ef, FLAG02, 0 ); }, 4000 );
385
- t3.attach_us ([&] { send_thread (&ef, FLAG03, 0 ); }, 5000 );
382
+ t1.attach ([&] { send_thread (&ef, FLAG01, 0ms ); }, 3ms );
383
+ t2.attach ([&] { send_thread (&ef, FLAG02, 0ms ); }, 4ms );
384
+ t3.attach ([&] { send_thread (&ef, FLAG03, 0ms ); }, 5ms );
386
385
387
386
for (int i = 0 ; i <= MAX_FLAG_POS; i++) {
388
387
uint32_t flag = 1 << i;
@@ -404,9 +403,9 @@ void test_multi_eventflags_any_no_clear(void)
404
403
EventFlags ef;
405
404
uint32_t ret;
406
405
Ticker t1, t2, t3;
407
- t1.attach_us ([&] { send_thread (&ef, FLAG01, 0 ); }, 3000 );
408
- t2.attach_us ([&] { send_thread (&ef, FLAG02, 0 ); }, 4000 );
409
- t3.attach_us ([&] { send_thread (&ef, FLAG03, 0 ); }, 5000 );
406
+ t1.attach ([&] { send_thread (&ef, FLAG01, 0ms ); }, 3ms );
407
+ t2.attach ([&] { send_thread (&ef, FLAG02, 0ms ); }, 4ms );
408
+ t3.attach ([&] { send_thread (&ef, FLAG03, 0ms ); }, 5ms );
410
409
411
410
for (int i = 0 ; i <= MAX_FLAG_POS; i++) {
412
411
uint32_t flag = 1 << i;
0 commit comments