Skip to content

Commit df07e7d

Browse files
committed
Fixes in Sys Timer test
Do not call sleep from the test thread, but let scheduler do it. And also include the deep sleep latency in the computation of the allowed delta for deep sleep test case.
1 parent 9cc1caa commit df07e7d

File tree

1 file changed

+17
-8
lines changed
  • TESTS/mbedmicro-rtos-mbed/systimer

1 file changed

+17
-8
lines changed

TESTS/mbedmicro-rtos-mbed/systimer/main.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ extern "C" {
3131
#define TEST_TICKS 42UL
3232
#define DELAY_DELTA_US 2500ULL
3333

34+
/* Use a specific delta value for deep sleep, as entry/exit adds up extra latency.
35+
* Use deep sleep latency if defined and add 1ms extra delta */
36+
#if defined MBED_CONF_TARGET_DEEP_SLEEP_LATENCY
37+
#define DEEP_SLEEP_DELAY_DELTA_US ((MBED_CONF_TARGET_DEEP_SLEEP_LATENCY * 1000ULL) + 1000ULL)
38+
#else
39+
#define DEEP_SLEEP_DELAY_DELTA_US 2500ULL
40+
#endif
41+
3442
using namespace utest::v1;
3543

3644
const us_timestamp_t DELAY_US = 1000000ULL * TEST_TICKS / OS_TICK_FREQ;
@@ -66,6 +74,11 @@ class SysTimerTest: public rtos::internal::SysTimer {
6674
{
6775
return _sem.try_acquire_for(millisec);
6876
}
77+
78+
void sem_acquire()
79+
{
80+
_sem.acquire();
81+
}
6982
};
7083

7184
timestamp_t mock_ticker_timestamp;
@@ -275,9 +288,8 @@ void test_sleep(void)
275288
st.schedule_tick(TEST_TICKS);
276289

277290
TEST_ASSERT_FALSE_MESSAGE(sleep_manager_can_deep_sleep(), "Deep sleep should be disallowed");
278-
while (!st.sem_try_acquire(0)) {
279-
sleep();
280-
}
291+
st.sem_acquire();
292+
281293
timer.stop();
282294
sleep_manager_unlock_deep_sleep();
283295

@@ -305,20 +317,17 @@ void test_deepsleep(void)
305317
* so we'll use the wait_ms() function for now.
306318
*/
307319
wait_ms(10);
308-
309320
// Regular Timer might be disabled during deepsleep.
310321
LowPowerTimer lptimer;
311322
SysTimerTest st;
312323

313324
lptimer.start();
314325
st.schedule_tick(TEST_TICKS);
315326
TEST_ASSERT_TRUE_MESSAGE(sleep_manager_can_deep_sleep_test_check(), "Deep sleep should be allowed");
316-
while (!st.sem_try_acquire(0)) {
317-
sleep();
318-
}
327+
st.sem_acquire();
319328
lptimer.stop();
320329

321-
TEST_ASSERT_UINT64_WITHIN(DELAY_DELTA_US, DELAY_US, lptimer.read_high_resolution_us());
330+
TEST_ASSERT_UINT64_WITHIN(DEEP_SLEEP_DELAY_DELTA_US, DELAY_US, lptimer.read_high_resolution_us());
322331
}
323332
#endif
324333
#endif

0 commit comments

Comments
 (0)