Skip to content

Commit 1473240

Browse files
committed
Fixing issue in timing host test and wait_us case
The timing host tests reported success even if the total drift was negative. This adds a check for this now. The wait_us test now does not use a timer and just waits for 100000 us between prints. This adds inherent drift, but it should still be well under the limit.
1 parent 4f4112b commit 1473240

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

TESTS/host_tests/timing_drift_auto.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def result(self, print_stats=True):
8888
self.average_drift_max))
8989

9090

91-
if self.total_drift > self.total_drift_max:
91+
if abs(self.total_drift) > self.total_drift_max:
9292
if print_stats:
9393
self.log("FAIL: Total drift exceeded max total drift")
9494
self.__result = False

TESTS/mbed_drivers/wait_us/main.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,25 @@
1818
#include "greentea-client/test_env.h"
1919
#include "utest/utest.h"
2020

21+
/**
22+
NOTE: This test will have a bit of inherent drift due to it being
23+
single-threaded, so having a drift that is non-zero should be ok. However,
24+
it should still be well under the limit.
25+
**/
26+
27+
2128
using namespace utest::v1;
2229

2330
DigitalOut led(LED1);
24-
Timer timer;
2531
volatile bool print_tick = false;
2632
const int ONE_SECOND_US = 1000000;
2733
const int total_ticks = 10;
2834

29-
void test_case_ticker() {
30-
int start_time;
31-
int after_print_us;
32-
int wait_time_us = ONE_SECOND_US;
33-
34-
timer.start();
35-
start_time = timer.read();
36-
int i = 0;
37-
while (i <= total_ticks) {
38-
wait_us(wait_time_us);
35+
void test_case_ticker() {
36+
for (int i = 0; i <= total_ticks; i++) {
37+
wait_us(ONE_SECOND_US);
3938
greentea_send_kv("tick", i);
40-
after_print_us = timer.read();
41-
42-
// This won't be 100% exact, but it should be very close
43-
wait_time_us = after_print_us - start_time - ((++i) * ONE_SECOND_US);
4439
}
45-
timer.stop();
4640
}
4741

4842
// Test cases

0 commit comments

Comments
 (0)