@@ -93,12 +93,12 @@ void simple_posts_test##i() { \
93
93
TEST_ASSERT (touched); \
94
94
\
95
95
touched = false ; \
96
- queue.call_in (1 , func##i,##__VA_ARGS__); \
96
+ queue.call_in (1ms , func##i,##__VA_ARGS__); \
97
97
queue.dispatch (2 ); \
98
98
TEST_ASSERT (touched); \
99
99
\
100
100
touched = false ; \
101
- queue.call_every (1 , func##i,##__VA_ARGS__); \
101
+ queue.call_every (1ms , func##i,##__VA_ARGS__); \
102
102
queue.dispatch (2 ); \
103
103
TEST_ASSERT (touched); \
104
104
}
@@ -126,7 +126,7 @@ void call_in_test()
126
126
127
127
for (int i = 0 ; i < N; i++) {
128
128
tickers[i].start ();
129
- queue.call_in ((i + 1 ) * 100 , time_func, &tickers[i], (i + 1 ) * 100 );
129
+ queue.call_in ((i + 1 ) * 100ms , time_func, &tickers[i], (i + 1 ) * 100 );
130
130
}
131
131
132
132
queue.dispatch (N * 100 );
@@ -141,7 +141,7 @@ void call_every_test()
141
141
142
142
for (int i = 0 ; i < N; i++) {
143
143
tickers[i].start ();
144
- queue.call_every ((i + 1 ) * 100 , time_func, &tickers[i], (i + 1 ) * 100 );
144
+ queue.call_every ((i + 1 ) * 100ms , time_func, &tickers[i], (i + 1 ) * 100 );
145
145
}
146
146
147
147
queue.dispatch (N * 100 );
@@ -172,7 +172,7 @@ void cancel_test1()
172
172
int ids[N];
173
173
174
174
for (int i = 0 ; i < N; i++) {
175
- ids[i] = queue.call_in (1000 , no);
175
+ ids[i] = queue.call_in (1000ms , no);
176
176
}
177
177
178
178
for (int i = N - 1 ; i >= 0 ; i--) {
@@ -308,12 +308,12 @@ void time_left_test()
308
308
EventQueue queue (TEST_EQUEUE_SIZE);
309
309
310
310
// Enque check events
311
- TEST_ASSERT (queue.call_in (50 , check_time_left, &queue, 0 , 100 - 50 ));
312
- TEST_ASSERT (queue.call_in (200 , check_time_left, &queue, 1 , 200 - 200 ));
311
+ TEST_ASSERT (queue.call_in (50ms , check_time_left, &queue, 0 , 100 - 50 ));
312
+ TEST_ASSERT (queue.call_in (200ms , check_time_left, &queue, 1 , 200 - 200 ));
313
313
314
314
// Enque events to be checked
315
- timeleft_events[0 ] = queue.call_in (100 , time_left, &queue, 0 );
316
- timeleft_events[1 ] = queue.call_in (200 , time_left, &queue, 1 );
315
+ timeleft_events[0 ] = queue.call_in (100ms , time_left, &queue, 0 );
316
+ timeleft_events[1 ] = queue.call_in (200ms , time_left, &queue, 1 );
317
317
TEST_ASSERT (timeleft_events[0 ]);
318
318
TEST_ASSERT (timeleft_events[1 ]);
319
319
@@ -373,18 +373,18 @@ void mixed_dynamic_static_events_queue_test()
373
373
374
374
EventTest e1_test;
375
375
Event<void ()> e1 = queue.event (&e1_test, &EventTest::f0);
376
- e1 .delay (10 );
377
- e1 .period (10 );
376
+ e1 .delay (10ms );
377
+ e1 .period (10ms );
378
378
int id1 = e1 .post ();
379
379
TEST_ASSERT_NOT_EQUAL (0 , id1);
380
380
EventTest e2_test;
381
381
Event<void ()> e2 = queue.event (&e2_test, &EventTest::f1, 3 );
382
- e2 .period (10 );
382
+ e2 .period (10ms );
383
383
int id2 = e2 .post ();
384
384
TEST_ASSERT_NOT_EQUAL (0 , id2);
385
385
EventTest e3_test;
386
386
Event<void ()> e3 = queue.event (&e3_test, &EventTest::f5, 1 , 2 , 3 , 4 , 5 );
387
- e3 .period (10 );
387
+ e3 .period (10ms );
388
388
int id3 = e3 .post ();
389
389
TEST_ASSERT_NOT_EQUAL (0 , id3);
390
390
@@ -508,6 +508,89 @@ void static_events_queue_test()
508
508
TEST_ASSERT_EQUAL (15 , test4.counter );
509
509
}
510
510
511
+ static EventQueue period_tests_queue;
512
+ static long update_counter = 0 ;
513
+
514
+ void handler ()
515
+ {
516
+ update_counter ++;
517
+ }
518
+
519
+ void event_period_tests ()
520
+ {
521
+ // Test a non periodic event ie dispatched only once
522
+
523
+ Event<void ()> event1 (&period_tests_queue, handler);
524
+
525
+ event1.delay (10ms);
526
+ event1.period (events::non_periodic);
527
+ event1.post ();
528
+ period_tests_queue.dispatch (80 );
529
+
530
+ // Wait 100ms and check the event execution status
531
+ wait_us (100 * 1000 );
532
+
533
+ // Event should only have been dispatched once and thus counter
534
+ // should be 1
535
+ TEST_ASSERT_EQUAL (1 , update_counter);
536
+
537
+ // Test an event with an invalid negative period value.
538
+
539
+ update_counter = 0 ;
540
+
541
+ Event<void ()> event2 (&period_tests_queue, handler);
542
+
543
+ event2.delay (10ms);
544
+ event2.period (-10ms);
545
+ event2.post ();
546
+ period_tests_queue.dispatch (80 );
547
+
548
+ // Wait 100ms and check the event execution status
549
+ wait_us (100 * 1000 );
550
+
551
+ // Event should default to non_periodic and thus only have been
552
+ // dispatched once. Counter should be 1.
553
+ TEST_ASSERT_EQUAL (1 , update_counter);
554
+
555
+ // Test an event with a zero period.
556
+
557
+ update_counter = 0 ;
558
+
559
+ Event<void ()> event3 (&period_tests_queue, handler);
560
+
561
+ event3.delay (10ms);
562
+ event3.period (0ms);
563
+ event3.post ();
564
+ period_tests_queue.dispatch (80 );
565
+
566
+ // Wait 100ms and check the event execution status
567
+ wait_us (100 * 1000 );
568
+
569
+ // Event should default to non_periodic and thus only have been
570
+ // dispatched once. Counter should be 1.
571
+ TEST_ASSERT_EQUAL (1 , update_counter);
572
+
573
+ // Test a periodic event ie dispatched a number of times
574
+ update_counter = 0 ;
575
+
576
+ Event<void ()> event4 (&period_tests_queue, handler);
577
+
578
+ event4.delay (10ms);
579
+ event4.period (20ms);
580
+ event4.post ();
581
+ period_tests_queue.dispatch (80 );
582
+
583
+ // Wait 100ms and check the event execution status
584
+ wait_us (100 * 1000 );
585
+
586
+ // The event should be first dispatched after 10ms and then
587
+ // every subsequent 20ms until the dispatcher has completed.
588
+ // Thus the counter should be incremented after :
589
+ // 10ms, 30ms, 50ms and 70ms
590
+ TEST_ASSERT_EQUAL (4 , update_counter);
591
+
592
+ }
593
+
511
594
// Test setup
512
595
utest::v1::status_t test_setup (const size_t number_of_cases)
513
596
{
@@ -535,8 +618,8 @@ const Case cases[] = {
535
618
536
619
Case (" Testing time_left" , time_left_test),
537
620
Case (" Testing mixed dynamic & static events queue" , mixed_dynamic_static_events_queue_test),
538
- Case (" Testing static events queue" , static_events_queue_test)
539
-
621
+ Case (" Testing static events queue" , static_events_queue_test),
622
+ Case ( " Testing event period values " , event_period_tests)
540
623
};
541
624
542
625
Specification specification (test_setup, cases);
0 commit comments