Skip to content

Commit 176c599

Browse files
committed
Incorported the review comment
1 parent d598d81 commit 176c599

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ using utest::v1::Case;
3636

3737
#define MAX_FLAG_POS 30
3838
#define PROHIBITED_FLAG_POS 31
39+
static bool is_ticker_used = false; /* This flag protects avoid calling ThisThread::sleep_for as it is not safe to call in IRQ mode. */
3940

4041
/* flags */
4142
#define FLAG01 0x1FFF /* 00000000000000000001111111111111 */
@@ -51,7 +52,9 @@ void send_thread(EventFlags *ef)
5152
const uint32_t flag = flags & (1 << i);
5253
if (flag) {
5354
ef->set(flag);
54-
ThisThread::sleep_for(wait_ms);
55+
if (!is_ticker_used) {
56+
ThisThread::sleep_for(wait_ms);
57+
}
5558
}
5659
}
5760
}
@@ -349,7 +352,7 @@ void test_multi_thread_all_many_wait(void)
349352
TEST_ASSERT_EQUAL(NO_FLAGS, ef.get());
350353
}
351354
}
352-
#else
355+
#endif
353356

354357
/** Test if multi-event flag set cause wait_all to return
355358
@@ -361,11 +364,13 @@ void test_multi_eventflags_all(void)
361364
{
362365
EventFlags ef;
363366
Ticker t1, t2, t3;
367+
is_ticker_used = true;
364368
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);
369+
t2.attach_us(callback(send_thread<FLAG02, 0>, &ef), 4000);
370+
t3.attach_us(callback(send_thread<FLAG03, 0>, &ef), 5000);
371+
uint32_t ret = ef.wait_all(FLAG01 | FLAG02 | FLAG03, 20, false);
368372
TEST_ASSERT_EQUAL(FLAG01 | FLAG02 | FLAG03, ret);
373+
is_ticker_used = false;
369374
}
370375

371376
/** Test if multi-event flag set cause wait_any to return
@@ -374,12 +379,12 @@ void test_multi_eventflags_all(void)
374379
When callbacks set specified flags
375380
Then main thread waits until receive all of them
376381
*/
377-
378382
void test_multi_eventflags_any(void)
379383
{
380384
EventFlags ef;
381385
uint32_t ret;
382386
Ticker t1, t2, t3;
387+
is_ticker_used = true;
383388
t1.attach_us(callback(send_thread<FLAG01, 0>, &ef), 3000);
384389
t2.attach_us(callback(send_thread<FLAG02, 0>, &ef), 4000);
385390
t3.attach_us(callback(send_thread<FLAG03, 0>, &ef), 5000);
@@ -391,6 +396,7 @@ void test_multi_eventflags_any(void)
391396
}
392397
ret = ef.get();
393398
TEST_ASSERT_EQUAL(NO_FLAGS, ret);
399+
is_ticker_used = false;
394400
}
395401

396402
/** Test if multi-event flag set cause wait_any(without clear) to return
@@ -404,6 +410,7 @@ void test_multi_eventflags_any_no_clear(void)
404410
EventFlags ef;
405411
uint32_t ret;
406412
Ticker t1, t2, t3;
413+
is_ticker_used = true;
407414
t1.attach_us(callback(send_thread<FLAG01, 0>, &ef), 3000);
408415
t2.attach_us(callback(send_thread<FLAG02, 0>, &ef), 4000);
409416
t3.attach_us(callback(send_thread<FLAG03, 0>, &ef), 5000);
@@ -417,8 +424,9 @@ void test_multi_eventflags_any_no_clear(void)
417424
}
418425
ret = ef.get();
419426
TEST_ASSERT_EQUAL(NO_FLAGS, ret);
427+
is_ticker_used = false;
420428
}
421-
#endif
429+
422430
utest::v1::status_t test_setup(const size_t number_of_cases)
423431
{
424432
GREENTEA_SETUP(10, "default_auto");
@@ -436,12 +444,11 @@ Case cases[] = {
436444
Case("Test multi-threaded wait_any", test_multi_thread_any),
437445
Case("Test multi-threaded wait_all many wait", test_multi_thread_all_many_wait),
438446
Case("Test multi-threaded wait_any timeout", test_multi_thread_any_timeout),
439-
Case("Test multi-threaded wait_any no clear", test_multi_thread_any_no_clear)
440-
#else
447+
Case("Test multi-threaded wait_any no clear", test_multi_thread_any_no_clear),
448+
#endif
441449
Case("Test multi-eventflags wait_all", test_multi_eventflags_all),
442450
Case("Test multi-eventflags wait_any", test_multi_eventflags_any),
443451
Case("Test multi-eventflags wait_any no clear", test_multi_eventflags_any_no_clear)
444-
#endif
445452
};
446453

447454
utest::v1::Specification specification(test_setup, cases);

text.txt

204 KB
Binary file not shown.

0 commit comments

Comments
 (0)