Test: Watchdog: Update the sleep & deepsleep cases

Use ThisThread::sleep_for() for sleeping instead of the calls to
Semaphore::acquire().
pull/11773/head
Filip Jagodzinski 2019-10-30 11:42:22 +01:00
parent 361804b91d
commit 8640da4f9d
2 changed files with 12 additions and 34 deletions

View File

@ -84,11 +84,6 @@ struct testcase_data {
uint32_t received_data;
};
void release_sem(Semaphore *sem)
{
sem->release();
}
testcase_data current_case;
Thread wdg_kicking_thread(osPriorityNormal, 768);
@ -156,8 +151,6 @@ void test_sleep_reset()
}
// Phase 1. -- run the test code.
Semaphore sem(0, 1);
Timeout timeout;
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
return;
@ -167,16 +160,15 @@ void test_sleep_reset()
TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS));
TEST_ASSERT_TRUE(watchdog.is_running());
sleep_manager_lock_deep_sleep();
// Watchdog should fire before twice the timeout value.
timeout.attach_us(mbed::callback(release_sem, &sem), 1000ULL * (2 * TIMEOUT_MS));
if (sleep_manager_can_deep_sleep()) {
TEST_ASSERT_MESSAGE(0, "Deepsleep should be disallowed.");
return;
}
sem.acquire(); // Device reset expected.
// Watchdog should fire before twice the timeout value.
ThisThread::sleep_for(2 * TIMEOUT_MS); // Device reset expected.
sleep_manager_unlock_deep_sleep();
// Watchdog reset should have occurred during sem.acquire() (sleep) above.
// Watchdog reset should have occurred during the sleep above.
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
@ -193,8 +185,6 @@ void test_deepsleep_reset()
}
// Phase 1. -- run the test code.
Semaphore sem(0, 1);
LowPowerTimeout lp_timeout;
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
return;
@ -204,14 +194,13 @@ void test_deepsleep_reset()
TEST_ASSERT_FALSE(watchdog.is_running());
TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS));
TEST_ASSERT_TRUE(watchdog.is_running());
// Watchdog should fire before twice the timeout value.
lp_timeout.attach_us(mbed::callback(release_sem, &sem), 1000ULL * (2 * TIMEOUT_MS));
if (!sleep_manager_can_deep_sleep()) {
TEST_ASSERT_MESSAGE(0, "Deepsleep should be allowed.");
}
sem.acquire(); // Device reset expected.
// Watchdog should fire before twice the timeout value.
ThisThread::sleep_for(2 * TIMEOUT_MS); // Device reset expected.
// Watchdog reset should have occurred during sem.acquire() (deepsleep) above.
// Watchdog reset should have occurred during the deepsleep above.
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");

View File

@ -82,11 +82,6 @@ struct testcase_data {
uint32_t received_data;
};
void release_sem(Semaphore *sem)
{
sem->release();
}
testcase_data current_case;
Thread wdg_kicking_thread(osPriorityNormal, 768);
@ -152,24 +147,21 @@ void test_sleep_reset()
// Phase 1. -- run the test code.
watchdog_config_t config = { TIMEOUT_MS };
Semaphore sem(0, 1);
Timeout timeout;
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
return;
}
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
sleep_manager_lock_deep_sleep();
// Watchdog should fire before twice the timeout value.
timeout.attach_us(mbed::callback(release_sem, &sem), 1000ULL * (2 * TIMEOUT_MS));
if (sleep_manager_can_deep_sleep()) {
TEST_ASSERT_MESSAGE(0, "Deepsleep should be disallowed.");
return;
}
sem.acquire(); // Device reset expected.
// Watchdog should fire before twice the timeout value.
ThisThread::sleep_for(2 * TIMEOUT_MS); // Device reset expected.
sleep_manager_unlock_deep_sleep();
// Watchdog reset should have occurred during sem.acquire() (sleep) above.
// Watchdog reset should have occurred during the sleep above.
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
@ -187,22 +179,19 @@ void test_deepsleep_reset()
// Phase 1. -- run the test code.
watchdog_config_t config = { TIMEOUT_MS };
Semaphore sem(0, 1);
LowPowerTimeout lp_timeout;
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
return;
}
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
// Watchdog should fire before twice the timeout value.
lp_timeout.attach_us(mbed::callback(release_sem, &sem), 1000ULL * (2 * TIMEOUT_MS));
if (!sleep_manager_can_deep_sleep()) {
TEST_ASSERT_MESSAGE(0, "Deepsleep should be allowed.");
}
sem.acquire(); // Device reset expected.
// Watchdog should fire before twice the timeout value.
ThisThread::sleep_for(2 * TIMEOUT_MS); // Device reset expected.
// Watchdog reset should have occurred during sem.acquire() (deepsleep) above.
// Watchdog reset should have occurred during the deepsleep above.
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");