Skip to content

Fixes in Sys Timer test #10744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions TESTS/mbedmicro-rtos-mbed/systimer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ extern "C" {
#define TEST_TICKS 42UL
#define DELAY_DELTA_US 2500ULL

/* Use a specific delta value for deep sleep, as entry/exit adds up extra latency.
* Use deep sleep latency if defined and add 1ms extra delta */
#if defined MBED_CONF_TARGET_DEEP_SLEEP_LATENCY
#define DEEP_SLEEP_DELAY_DELTA_US ((MBED_CONF_TARGET_DEEP_SLEEP_LATENCY * 1000ULL) + 1000ULL)
#else
#define DEEP_SLEEP_DELAY_DELTA_US 2500ULL
#endif

using namespace utest::v1;

const us_timestamp_t DELAY_US = 1000000ULL * TEST_TICKS / OS_TICK_FREQ;
Expand Down Expand Up @@ -66,6 +74,11 @@ class SysTimerTest: public rtos::internal::SysTimer {
{
return _sem.try_acquire_for(millisec);
}

void sem_acquire()
{
_sem.acquire();
}
};

timestamp_t mock_ticker_timestamp;
Expand Down Expand Up @@ -275,9 +288,8 @@ void test_sleep(void)
st.schedule_tick(TEST_TICKS);

TEST_ASSERT_FALSE_MESSAGE(sleep_manager_can_deep_sleep(), "Deep sleep should be disallowed");
while (!st.sem_try_acquire(0)) {
sleep();
}
st.sem_acquire();

timer.stop();
sleep_manager_unlock_deep_sleep();

Expand Down Expand Up @@ -305,20 +317,17 @@ void test_deepsleep(void)
* so we'll use the wait_ms() function for now.
*/
wait_ms(10);

// Regular Timer might be disabled during deepsleep.
LowPowerTimer lptimer;
SysTimerTest st;

lptimer.start();
st.schedule_tick(TEST_TICKS);
TEST_ASSERT_TRUE_MESSAGE(sleep_manager_can_deep_sleep_test_check(), "Deep sleep should be allowed");
while (!st.sem_try_acquire(0)) {
sleep();
}
st.sem_acquire();
lptimer.stop();

TEST_ASSERT_UINT64_WITHIN(DELAY_DELTA_US, DELAY_US, lptimer.read_high_resolution_us());
TEST_ASSERT_UINT64_WITHIN(DEEP_SLEEP_DELAY_DELTA_US, DELAY_US, lptimer.read_high_resolution_us());
}
#endif
#endif
Expand Down