@@ -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,79 +508,90 @@ void static_events_queue_test()
508
508
TEST_ASSERT_EQUAL (15 , test4.counter );
509
509
}
510
510
511
- static EventTest event_period;
511
+ static EventQueue period_tests_queue;
512
+ static long update_counter = 0 ;
513
+
514
+ void handler ()
515
+ {
516
+ update_counter ++;
517
+ }
512
518
513
519
void event_period_tests ()
514
520
{
515
- EventQueue queue;
521
+ // Test a non periodic event ie dispatched only once
516
522
517
- // Test a non periodic event ie dispatched only once
523
+ Event< void ()> event1 (&period_tests_queue, handler);
518
524
519
- Event<void (int )> event1 (&queue, &event_period::f0);
520
- event1.delay (100ms);
521
- event1.period (Event::non_periodic);
522
- event1.post ()
525
+ event1.delay (10ms);
526
+ event1.period (events::non_periodic);
527
+ event1.post ();
523
528
524
- queue .dispatch (800 );
529
+ period_tests_queue .dispatch (80 );
525
530
526
- // Wait 1000ms and check the event execution status
527
- wait_us (1000 * 1000 )
531
+ // Wait 100ms and check the event execution status
532
+ wait_us (100 * 1000 );
528
533
529
534
// Event should only have been dispatched once and thus counter
530
535
// should be 1
531
- TEST_ASSERT_EQUAL (1 , event_period. counter );
536
+ TEST_ASSERT_EQUAL (1 , update_counter );
532
537
533
- // Test an event with an invalid -ve period.
538
+ // Test an event with an invalid negative period value.
539
+
540
+ update_counter = 0 ;
541
+
542
+ Event<void ()> event2 (&period_tests_queue, handler);
534
543
535
- event_period.counter = 0 ;
536
- Event<void (int )> event2 (&queue, &event_period::f0);
537
- event2.delay (100ms);
544
+ event2.delay (10ms);
538
545
event2.period (-10ms);
539
- event2.post ()
546
+ event2.post ();
540
547
541
- queue .dispatch (800 );
548
+ period_tests_queue .dispatch (80 );
542
549
543
- // Wait 1000ms and check the event execution status
544
- wait_us (1000 * 1000 )
550
+ // Wait 100ms and check the event execution status
551
+ wait_us (100 * 1000 );
545
552
546
553
// Event should default to non_periodic and thus only have been
547
554
// dispatched once. Counter should be 1.
548
- TEST_ASSERT_EQUAL (1 , event_period. counter );
555
+ TEST_ASSERT_EQUAL (1 , update_counter );
549
556
550
557
// Test an event with a zero period.
551
558
552
- event_period.counter = 0 ;
553
- Event<void (int )> event3 (&queue, &event_period::f0);
554
- event3.delay (100ms);
559
+ update_counter = 0 ;
560
+
561
+ Event<void ()> event3 (&period_tests_queue, handler);
562
+
563
+ event3.delay (10ms);
555
564
event3.period (0ms);
556
- event3.post ()
565
+ event3.post ();
557
566
558
- queue .dispatch (800 );
567
+ period_tests_queue .dispatch (80 );
559
568
560
- // Wait 1000ms and check the event execution status
561
- wait_us (1000 * 1000 )
569
+ // Wait 100ms and check the event execution status
570
+ wait_us (100 * 1000 );
562
571
563
572
// Event should default to non_periodic and thus only have been
564
573
// dispatched once. Counter should be 1.
565
- TEST_ASSERT_EQUAL (1 , event_period. counter );
574
+ TEST_ASSERT_EQUAL (1 , update_counter );
566
575
567
576
// Test a periodic event ie dispatched a number of times
568
- event_period.counter = 0 ;
569
- Event<void (int )> event4 (&queue, &event_period::f0);
570
- event4.delay (100ms);
571
- event4.period (200ms);
572
- event4.post ()
577
+ update_counter = 0 ;
578
+
579
+ Event<void ()> event4 (&period_tests_queue, handler);
580
+
581
+ event4.delay (10ms);
582
+ event4.period (20ms);
583
+ event4.post ();
573
584
574
- queue .dispatch (800 );
585
+ period_tests_queue .dispatch (80 );
575
586
576
- // Wait 1000ms and check the event execution status
577
- wait_us (1000 * 1000 )
587
+ // Wait 100ms and check the event execution status
588
+ wait_us (100 * 1000 );
578
589
579
- // The event should be first dispatched after 100ms and then
580
- // every subsequent 200ms until the dispatcher has completed.
590
+ // The event should be first dispatched after 10ms and then
591
+ // every subsequent 20ms until the dispatcher has completed.
581
592
// Thus the counter should be incremented after :
582
- // 100ms, 300ms, 500ms and 700ms
583
- TEST_ASSERT_EQUAL (4 , event_period. counter );
593
+ // 10ms, 30ms, 50ms and 70ms
594
+ TEST_ASSERT_EQUAL (4 , update_counter );
584
595
585
596
}
586
597
@@ -611,7 +622,7 @@ const Case cases[] = {
611
622
612
623
Case (" Testing time_left" , time_left_test),
613
624
Case (" Testing mixed dynamic & static events queue" , mixed_dynamic_static_events_queue_test),
614
- Case (" Testing static events queue" , static_events_queue_test)
625
+ Case (" Testing static events queue" , static_events_queue_test),
615
626
Case (" Testing event period values" , event_period_tests)
616
627
};
617
628
0 commit comments