@@ -44,14 +44,17 @@ extern uint32_t SystemCoreClock;
44
44
* For NRF51_DK DELTA = (15000 / 16000000) * 1000000 = 937[us]
45
45
*/
46
46
#define US_PER_SEC 1000000
47
+ #define US_PER_MSEC 1000
47
48
#define TOLERANCE_FACTOR 15000 .0f
48
49
#define US_FACTOR 1000000 .0f
49
50
50
51
static const int delta_sys_clk_us = ((int ) (TOLERANCE_FACTOR / (float )SystemCoreClock * US_FACTOR));
51
52
52
- #define DELTA_US delta_sys_clk_us
53
- #define DELTA_S ((float )delta_sys_clk_us/US_PER_SEC)
54
- #define DELTA_MS 1
53
+ /* When test performs time measurement using Timer in sequence, then measurement error accumulates
54
+ * in the successive attempts. */
55
+ #define DELTA_US (i ) (delta_sys_clk_us * i)
56
+ #define DELTA_S (i ) ((float )delta_sys_clk_us * i / US_PER_SEC)
57
+ #define DELTA_MS (i ) (1 + ( (i * delta_sys_clk_us) / US_PER_MSEC))
55
58
56
59
#define TICKER_FREQ_1MHZ 1000000
57
60
#define TICKER_BITS 32
@@ -410,10 +413,10 @@ void test_timer_time_accumulation_os_ticker()
410
413
p_timer->stop ();
411
414
412
415
/* Check results - totally 10 ms have elapsed. */
413
- TEST_ASSERT_FLOAT_WITHIN (DELTA_S, 0 .010f , p_timer->read ());
414
- TEST_ASSERT_INT32_WITHIN (DELTA_MS, 10 , p_timer->read_ms ());
415
- TEST_ASSERT_INT32_WITHIN (DELTA_US, 10000 , p_timer->read_us ());
416
- TEST_ASSERT_UINT64_WITHIN (DELTA_US, 10000 , p_timer->read_high_resolution_us ());
416
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 1 ) , 0 .010f , p_timer->read ());
417
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 1 ) , 10 , p_timer->read_ms ());
418
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 1 ) , 10000 , p_timer->read_us ());
419
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 1 ) , 10000 , p_timer->read_high_resolution_us ());
417
420
418
421
/* Wait 50 ms - this is done to show that time elapsed when
419
422
* the timer is stopped does not have influence on the
@@ -432,10 +435,10 @@ void test_timer_time_accumulation_os_ticker()
432
435
p_timer->stop ();
433
436
434
437
/* Check results - totally 30 ms have elapsed. */
435
- TEST_ASSERT_FLOAT_WITHIN (2 * DELTA_S, 0 .030f , p_timer->read ());
436
- TEST_ASSERT_INT32_WITHIN (2 * DELTA_MS, 30 , p_timer->read_ms ());
437
- TEST_ASSERT_INT32_WITHIN (2 * DELTA_US, 30000 , p_timer->read_us ());
438
- TEST_ASSERT_UINT64_WITHIN (2 * DELTA_US, 30000 , p_timer->read_high_resolution_us ());
438
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 2 ) , 0 .030f , p_timer->read ());
439
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 2 ) , 30 , p_timer->read_ms ());
440
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 2 ) , 30000 , p_timer->read_us ());
441
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 2 ) , 30000 , p_timer->read_high_resolution_us ());
439
442
440
443
/* Wait 50 ms - this is done to show that time elapsed when
441
444
* the timer is stopped does not have influence on the
@@ -453,10 +456,10 @@ void test_timer_time_accumulation_os_ticker()
453
456
p_timer->stop ();
454
457
455
458
/* Check results - totally 60 ms have elapsed. */
456
- TEST_ASSERT_FLOAT_WITHIN (3 * DELTA_S, 0 .060f , p_timer->read ());
457
- TEST_ASSERT_INT32_WITHIN (3 * DELTA_MS, 60 , p_timer->read_ms ());
458
- TEST_ASSERT_INT32_WITHIN (3 * DELTA_US, 60000 , p_timer->read_us ());
459
- TEST_ASSERT_UINT64_WITHIN (3 * DELTA_US, 60000 , p_timer->read_high_resolution_us ());
459
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 3 ) , 0 .060f , p_timer->read ());
460
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 3 ) , 60 , p_timer->read_ms ());
461
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 3 ) , 60000 , p_timer->read_us ());
462
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 3 ) , 60000 , p_timer->read_high_resolution_us ());
460
463
461
464
/* Wait 50 ms - this is done to show that time elapsed when
462
465
* the timer is stopped does not have influence on the
@@ -475,10 +478,10 @@ void test_timer_time_accumulation_os_ticker()
475
478
p_timer->stop ();
476
479
477
480
/* Check results - totally 1060 ms have elapsed. */
478
- TEST_ASSERT_FLOAT_WITHIN (4 * DELTA_S, 1 .060f , p_timer->read ());
479
- TEST_ASSERT_INT32_WITHIN (4 * DELTA_MS, 1060 , p_timer->read_ms ());
480
- TEST_ASSERT_INT32_WITHIN (4 * DELTA_US, 1060000 , p_timer->read_us ());
481
- TEST_ASSERT_UINT64_WITHIN (4 * DELTA_US, 1060000 , p_timer->read_high_resolution_us ());
481
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 4 ) , 1 .060f , p_timer->read ());
482
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 4 ) , 1060 , p_timer->read_ms ());
483
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 4 ) , 1060000 , p_timer->read_us ());
484
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 4 ) , 1060000 , p_timer->read_high_resolution_us ());
482
485
}
483
486
484
487
/* This test verifies if reset() function resets the timer
@@ -504,10 +507,10 @@ void test_timer_reset_os_ticker()
504
507
p_timer->stop ();
505
508
506
509
/* Check results - totally 10 ms elapsed. */
507
- TEST_ASSERT_FLOAT_WITHIN (DELTA_S, 0 .010f , p_timer->read ());
508
- TEST_ASSERT_INT32_WITHIN (DELTA_MS, 10 , p_timer->read_ms ());
509
- TEST_ASSERT_INT32_WITHIN (DELTA_US, 10000 , p_timer->read_us ());
510
- TEST_ASSERT_UINT64_WITHIN (DELTA_US, 10000 , p_timer->read_high_resolution_us ());
510
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 1 ) , 0 .010f , p_timer->read ());
511
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 1 ) , 10 , p_timer->read_ms ());
512
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 1 ) , 10000 , p_timer->read_us ());
513
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 1 ) , 10000 , p_timer->read_high_resolution_us ());
511
514
512
515
/* Reset the timer - previous measured time should be lost now. */
513
516
p_timer->reset ();
@@ -522,10 +525,10 @@ void test_timer_reset_os_ticker()
522
525
p_timer->stop ();
523
526
524
527
/* Check results - 20 ms elapsed since the reset. */
525
- TEST_ASSERT_FLOAT_WITHIN (DELTA_S, 0 .020f , p_timer->read ());
526
- TEST_ASSERT_INT32_WITHIN (DELTA_MS, 20 , p_timer->read_ms ());
527
- TEST_ASSERT_INT32_WITHIN (DELTA_US, 20000 , p_timer->read_us ());
528
- TEST_ASSERT_UINT64_WITHIN (DELTA_US, 20000 , p_timer->read_high_resolution_us ());
528
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 1 ) , 0 .020f , p_timer->read ());
529
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 1 ) , 20 , p_timer->read_ms ());
530
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 1 ) , 20000 , p_timer->read_us ());
531
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 1 ) , 20000 , p_timer->read_high_resolution_us ());
529
532
}
530
533
531
534
/* This test verifies if reset() function resets the timer
@@ -555,10 +558,10 @@ void test_timer_reset_user_ticker()
555
558
p_timer->stop ();
556
559
557
560
/* Check results - totally 10 ms elapsed. */
558
- TEST_ASSERT_FLOAT_WITHIN (DELTA_S, 0 .010f , p_timer->read ());
559
- TEST_ASSERT_INT32_WITHIN (DELTA_MS, 10 , p_timer->read_ms ());
560
- TEST_ASSERT_INT32_WITHIN (DELTA_US, 10000 , p_timer->read_us ());
561
- TEST_ASSERT_UINT64_WITHIN (DELTA_US, 10000 , p_timer->read_high_resolution_us ());
561
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 1 ) , 0 .010f , p_timer->read ());
562
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 1 ) , 10 , p_timer->read_ms ());
563
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 1 ) , 10000 , p_timer->read_us ());
564
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 1 ) , 10000 , p_timer->read_high_resolution_us ());
562
565
563
566
/* Reset the timer - previous measured time should be lost now. */
564
567
p_timer->reset ();
@@ -573,10 +576,10 @@ void test_timer_reset_user_ticker()
573
576
p_timer->stop ();
574
577
575
578
/* Check results - 20 ms elapsed since the reset. */
576
- TEST_ASSERT_FLOAT_WITHIN (DELTA_S, 0 .020f , p_timer->read ());
577
- TEST_ASSERT_INT32_WITHIN (DELTA_MS, 20 , p_timer->read_ms ());
578
- TEST_ASSERT_INT32_WITHIN (DELTA_US, 20000 , p_timer->read_us ());
579
- TEST_ASSERT_UINT64_WITHIN (DELTA_US, 20000 , p_timer->read_high_resolution_us ());
579
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 1 ) , 0 .020f , p_timer->read ());
580
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 1 ) , 20 , p_timer->read_ms ());
581
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 1 ) , 20000 , p_timer->read_us ());
582
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 1 ) , 20000 , p_timer->read_high_resolution_us ());
580
583
}
581
584
582
585
/* This test verifies if calling start() for already
@@ -606,10 +609,10 @@ void test_timer_start_started_timer_os_ticker()
606
609
p_timer->stop ();
607
610
608
611
/* Check results - 30 ms have elapsed since the first start. */
609
- TEST_ASSERT_FLOAT_WITHIN (2 * DELTA_S, 0 .030f , p_timer->read ());
610
- TEST_ASSERT_INT32_WITHIN (2 * DELTA_MS, 30 , p_timer->read_ms ());
611
- TEST_ASSERT_INT32_WITHIN (2 * DELTA_US, 30000 , p_timer->read_us ());
612
- TEST_ASSERT_UINT64_WITHIN (2 * DELTA_US, 30000 , p_timer->read_high_resolution_us ());
612
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 2 ) , 0 .030f , p_timer->read ());
613
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 2 ) , 30 , p_timer->read_ms ());
614
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 2 ) , 30000 , p_timer->read_us ());
615
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 2 ) , 30000 , p_timer->read_high_resolution_us ());
613
616
}
614
617
615
618
/* This test verifies if calling start() for already
@@ -643,10 +646,10 @@ void test_timer_start_started_timer_user_ticker()
643
646
p_timer->stop ();
644
647
645
648
/* Check results - 30 ms have elapsed since the first start. */
646
- TEST_ASSERT_FLOAT_WITHIN (2 * DELTA_S, 0 .030f , p_timer->read ());
647
- TEST_ASSERT_INT32_WITHIN (2 * DELTA_MS, 30 , p_timer->read_ms ());
648
- TEST_ASSERT_INT32_WITHIN (2 * DELTA_US, 30000 , p_timer->read_us ());
649
- TEST_ASSERT_UINT64_WITHIN (2 * DELTA_US, 30000 , p_timer->read_high_resolution_us ());
649
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 2 ) , 0 .030f , p_timer->read ());
650
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 2 ) , 30 , p_timer->read_ms ());
651
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 2 ) , 30000 , p_timer->read_us ());
652
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 2 ) , 30000 , p_timer->read_high_resolution_us ());
650
653
}
651
654
652
655
/* This test verifies Timer float operator.
@@ -670,7 +673,7 @@ void test_timer_float_operator_os_ticker()
670
673
p_timer->stop ();
671
674
672
675
/* Check result - 10 ms elapsed. */
673
- TEST_ASSERT_FLOAT_WITHIN (DELTA_S, 0 .010f , (float )(*p_timer));
676
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 1 ) , 0 .010f , (float )(*p_timer));
674
677
}
675
678
676
679
/* This test verifies Timer float operator.
@@ -698,7 +701,7 @@ void test_timer_float_operator_user_ticker()
698
701
p_timer->stop ();
699
702
700
703
/* Check result - 10 ms elapsed. */
701
- TEST_ASSERT_FLOAT_WITHIN (DELTA_S, 0 .010f , (float )(*p_timer));
704
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 1 ) , 0 .010f , (float )(*p_timer));
702
705
}
703
706
704
707
/* This test verifies if time counted by the timer is
@@ -725,10 +728,10 @@ void test_timer_time_measurement()
725
728
p_timer->stop ();
726
729
727
730
/* Check results. */
728
- TEST_ASSERT_FLOAT_WITHIN (DELTA_S, (float )wait_val_us / 1000000 , p_timer->read ());
729
- TEST_ASSERT_INT32_WITHIN (DELTA_MS, wait_val_us / 1000 , p_timer->read_ms ());
730
- TEST_ASSERT_INT32_WITHIN (DELTA_US, wait_val_us, p_timer->read_us ());
731
- TEST_ASSERT_UINT64_WITHIN (DELTA_US, wait_val_us, p_timer->read_high_resolution_us ());
731
+ TEST_ASSERT_FLOAT_WITHIN (DELTA_S ( 1 ) , (float )wait_val_us / 1000000 , p_timer->read ());
732
+ TEST_ASSERT_INT32_WITHIN (DELTA_MS ( 1 ) , wait_val_us / 1000 , p_timer->read_ms ());
733
+ TEST_ASSERT_INT32_WITHIN (DELTA_US ( 1 ) , wait_val_us, p_timer->read_us ());
734
+ TEST_ASSERT_UINT64_WITHIN (DELTA_US ( 1 ) , wait_val_us, p_timer->read_high_resolution_us ());
732
735
}
733
736
734
737
utest::v1::status_t test_setup (const size_t number_of_cases) {
0 commit comments