Skip to content

Commit

Permalink
Fixing issue in timing host test and wait_us case
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bridadan committed Sep 7, 2016
1 parent 4f4112b commit 1473240
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion TESTS/host_tests/timing_drift_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def result(self, print_stats=True):
self.average_drift_max))


if self.total_drift > self.total_drift_max:
if abs(self.total_drift) > self.total_drift_max:
if print_stats:
self.log("FAIL: Total drift exceeded max total drift")
self.__result = False
Expand Down
26 changes: 10 additions & 16 deletions TESTS/mbed_drivers/wait_us/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,25 @@
#include "greentea-client/test_env.h"
#include "utest/utest.h"

/**
NOTE: This test will have a bit of inherent drift due to it being
single-threaded, so having a drift that is non-zero should be ok. However,
it should still be well under the limit.
**/


using namespace utest::v1;

DigitalOut led(LED1);
Timer timer;
volatile bool print_tick = false;
const int ONE_SECOND_US = 1000000;
const int total_ticks = 10;

void test_case_ticker() {
int start_time;
int after_print_us;
int wait_time_us = ONE_SECOND_US;

timer.start();
start_time = timer.read();
int i = 0;
while (i <= total_ticks) {
wait_us(wait_time_us);
void test_case_ticker() {
for (int i = 0; i <= total_ticks; i++) {
wait_us(ONE_SECOND_US);
greentea_send_kv("tick", i);
after_print_us = timer.read();

// This won't be 100% exact, but it should be very close
wait_time_us = after_print_us - start_time - ((++i) * ONE_SECOND_US);
}
timer.stop();
}

// Test cases
Expand Down

0 comments on commit 1473240

Please sign in to comment.