Skip to content

Commit ce21d1d

Browse files
mprse0xc0170
authored andcommitted
tests-mbed_drivers-lp_ticker: Adapt tolerance for new Ticker driver
Since this change concerns new ticker driver for NRF51_DK it goas on ticker feature branch. On master NRF51_DK Ticker driver uses 32kHz RTC for lp and us ticker. Test uses us ticker to measure lp ticker interrupt scheduling (LowPowerTicker.attach), but since the same hardware is used for both tickers the measurement error is constant. On this branch us ticker uses 1 MHz higher precision clock and the results are different - measurement error grows linearly and shows inaccuracy of the RTC. Test implements constant delta for measured time equal to 2000 us. Change delta so it depends on lp ticker tested timeout value: 500us for measurement inaccuracy + 5% tolerance for LowPowerTicker
1 parent 73351a0 commit ce21d1d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

TESTS/mbed_drivers/lp_ticker/main.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ static const int test_timeout = 10;
3333
/* Due to poor accuracy of LowPowerTicker on many platforms
3434
there is no sense to tune tolerance value as it was in Ticker tests.
3535
36-
Tolerance value is set to 2000us to cover this diversity */
37-
#define TOLERANCE_US 2000
36+
Tolerance value is set to 500us for measurement inaccuracy + 5% tolerance
37+
for LowPowerTicker. */
38+
#define TOLERANCE_US(DELAY) (500 + DELAY / 20)
3839

3940

4041
volatile uint32_t ticker_callback_flag;
@@ -117,7 +118,7 @@ void test_multi_call_time(void)
117118
while(!ticker_callback_flag);
118119
time_diff = gtimer.read_us();
119120

120-
TEST_ASSERT_UINT32_WITHIN(TOLERANCE_US, MULTI_TICKER_TIME_MS * 1000, time_diff);
121+
TEST_ASSERT_UINT32_WITHIN(TOLERANCE_US(MULTI_TICKER_TIME_MS * 1000), MULTI_TICKER_TIME_MS * 1000, time_diff);
121122
}
122123
}
123124

@@ -167,7 +168,7 @@ void test_attach_time(void)
167168
ticker.detach();
168169
const int time_diff = gtimer.read_us();
169170

170-
TEST_ASSERT_UINT64_WITHIN(TOLERANCE_US, DELAY_US, time_diff);
171+
TEST_ASSERT_UINT64_WITHIN(TOLERANCE_US(DELAY_US), DELAY_US, time_diff);
171172
}
172173

173174
/** Test single callback time via attach_us
@@ -189,7 +190,7 @@ void test_attach_us_time(void)
189190
ticker.detach();
190191
const int time_diff = gtimer.read_us();
191192

192-
TEST_ASSERT_UINT64_WITHIN(TOLERANCE_US, DELAY_US, time_diff);
193+
TEST_ASSERT_UINT64_WITHIN(TOLERANCE_US(DELAY_US), DELAY_US, time_diff);
193194
}
194195

195196
// Test cases

0 commit comments

Comments
 (0)