From 7af11fa4b5de59af0dff95a3a9b373bf5fdde75a Mon Sep 17 00:00:00 2001 From: Filip Jagodzinski Date: Fri, 25 Oct 2019 18:07:12 +0200 Subject: [PATCH 1/7] Test: Watchdog: Fix error handling Add a watchdog-kicking thread running in the background when the test suite is handling a failed assertion. A single watchdog kick did not provide enough time for the greentea communication if the watchdog reset happened later than expected. --- TESTS/mbed_drivers/watchdog_reset/main.cpp | 27 ++++++++++++++++++---- TESTS/mbed_hal/watchdog_reset/main.cpp | 26 +++++++++++++++++---- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/TESTS/mbed_drivers/watchdog_reset/main.cpp b/TESTS/mbed_drivers/watchdog_reset/main.cpp index 0732d98fa4..530afba7fc 100644 --- a/TESTS/mbed_drivers/watchdog_reset/main.cpp +++ b/TESTS/mbed_drivers/watchdog_reset/main.cpp @@ -87,6 +87,19 @@ void release_sem(Semaphore *sem) testcase_data current_case; +Thread wdg_kicking_thread(osPriorityNormal, 768); +Semaphore kick_wdg_during_test_teardown(0, 1); + +void wdg_kicking_thread_fun() +{ + kick_wdg_during_test_teardown.acquire(); + Watchdog &watchdog = Watchdog::get_instance(); + while (true) { + watchdog.kick(); + wait_us(20000); + } +} + bool send_reset_notification(testcase_data *tcdata, uint32_t delay_ms) { char msg_value[12]; @@ -124,7 +137,7 @@ void test_simple_reset() // Watchdog reset should have occurred during wait_ms() above; - watchdog.kick(); // Just to buy some time for testsuite failure handling. + kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); } @@ -161,7 +174,7 @@ void test_sleep_reset() // Watchdog reset should have occurred during sem.wait() (sleep) above; - watchdog.kick(); // Just to buy some time for testsuite failure handling. + kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); } @@ -196,7 +209,7 @@ void test_deepsleep_reset() // Watchdog reset should have occurred during sem.wait() (deepsleep) above; - watchdog.kick(); // Just to buy some time for testsuite failure handling. + kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); } #endif @@ -241,7 +254,7 @@ void test_restart_reset() // Watchdog reset should have occurred during that wait() above; - watchdog.kick(); // Just to buy some time for testsuite failure handling. + kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); } @@ -274,7 +287,7 @@ void test_kick_reset() // Watchdog reset should have occurred during that wait() above; - watchdog.kick(); // Just to buy some time for testsuite failure handling. + kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); } @@ -309,6 +322,10 @@ int testsuite_setup(const size_t number_of_cases) return utest::v1::STATUS_ABORT; } + // The thread is started here, but feeding the watchdog will start + // when the semaphore is released during a test case teardown. + wdg_kicking_thread.start(mbed::callback(wdg_kicking_thread_fun)); + utest_printf("This test suite is composed of %i test cases. Starting at index %i.\n", number_of_cases, current_case.start_index); return current_case.start_index; diff --git a/TESTS/mbed_hal/watchdog_reset/main.cpp b/TESTS/mbed_hal/watchdog_reset/main.cpp index 7300392ddc..0d273b70ad 100644 --- a/TESTS/mbed_hal/watchdog_reset/main.cpp +++ b/TESTS/mbed_hal/watchdog_reset/main.cpp @@ -85,6 +85,18 @@ void release_sem(Semaphore *sem) testcase_data current_case; +Thread wdg_kicking_thread(osPriorityNormal, 768); +Semaphore kick_wdg_during_test_teardown(0, 1); + +void wdg_kicking_thread_fun() +{ + kick_wdg_during_test_teardown.acquire(); + while (true) { + hal_watchdog_kick(); + wait_us(20000); + } +} + bool send_reset_notification(testcase_data *tcdata, uint32_t delay_ms) { char msg_value[12]; @@ -120,7 +132,7 @@ void test_simple_reset() // Watchdog reset should have occurred during wait_ms() above; - hal_watchdog_kick(); // Just to buy some time for testsuite failure handling. + kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); } @@ -155,7 +167,7 @@ void test_sleep_reset() // Watchdog reset should have occurred during sem.wait() (sleep) above; - hal_watchdog_kick(); // Just to buy some time for testsuite failure handling. + kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); } @@ -188,7 +200,7 @@ void test_deepsleep_reset() // Watchdog reset should have occurred during sem.wait() (deepsleep) above; - hal_watchdog_kick(); // Just to buy some time for testsuite failure handling. + kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); } #endif @@ -229,7 +241,7 @@ void test_restart_reset() // Watchdog reset should have occurred during that wait() above; - hal_watchdog_kick(); // Just to buy some time for testsuite failure handling. + kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); } @@ -260,7 +272,7 @@ void test_kick_reset() // Watchdog reset should have occurred during that wait() above; - hal_watchdog_kick(); // Just to buy some time for testsuite failure handling. + kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); } @@ -295,6 +307,10 @@ int testsuite_setup(const size_t number_of_cases) return utest::v1::STATUS_ABORT; } + // The thread is started here, but feeding the watchdog will start + // when the semaphore is released during a test case teardown. + wdg_kicking_thread.start(mbed::callback(wdg_kicking_thread_fun)); + utest_printf("This test suite is composed of %i test cases. Starting at index %i.\n", number_of_cases, current_case.start_index); return current_case.start_index; From 2410257551ec7d4d752b41149f0d093af5d1a7f2 Mon Sep 17 00:00:00 2001 From: Filip Jagodzinski Date: Mon, 28 Oct 2019 12:33:10 +0100 Subject: [PATCH 2/7] Test: Watchdog: Fix LP ticker preproc condition --- TESTS/mbed_drivers/watchdog_reset/main.cpp | 4 ++-- TESTS/mbed_hal/watchdog_reset/main.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/TESTS/mbed_drivers/watchdog_reset/main.cpp b/TESTS/mbed_drivers/watchdog_reset/main.cpp index 530afba7fc..b02e458cf0 100644 --- a/TESTS/mbed_drivers/watchdog_reset/main.cpp +++ b/TESTS/mbed_drivers/watchdog_reset/main.cpp @@ -178,7 +178,7 @@ void test_sleep_reset() TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); } -#if DEVICE_LOWPOWERTIMER +#if DEVICE_LPTICKER void test_deepsleep_reset() { // Phase 2. -- verify the test results. @@ -335,7 +335,7 @@ Case cases[] = { Case("Watchdog reset", case_setup, test_simple_reset), #if DEVICE_SLEEP Case("Watchdog reset in sleep mode", case_setup, test_sleep_reset), -#if DEVICE_LOWPOWERTIMER +#if DEVICE_LPTICKER Case("Watchdog reset in deepsleep mode", case_setup, test_deepsleep_reset), #endif #endif diff --git a/TESTS/mbed_hal/watchdog_reset/main.cpp b/TESTS/mbed_hal/watchdog_reset/main.cpp index 0d273b70ad..2ac592a3be 100644 --- a/TESTS/mbed_hal/watchdog_reset/main.cpp +++ b/TESTS/mbed_hal/watchdog_reset/main.cpp @@ -171,7 +171,7 @@ void test_sleep_reset() TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); } -#if DEVICE_LOWPOWERTIMER +#if DEVICE_LPTICKER void test_deepsleep_reset() { // Phase 2. -- verify the test results. @@ -320,7 +320,7 @@ Case cases[] = { Case("Watchdog reset", case_setup, test_simple_reset), #if DEVICE_SLEEP Case("Watchdog reset in sleep mode", case_setup, test_sleep_reset), -#if DEVICE_LOWPOWERTIMER +#if DEVICE_LPTICKER Case("Watchdog reset in deepsleep mode", case_setup, test_deepsleep_reset), #endif #endif From e3f871181819b73c6b599664da1e6814824d1f6c Mon Sep 17 00:00:00 2001 From: Filip Jagodzinski Date: Tue, 29 Oct 2019 14:41:34 +0100 Subject: [PATCH 3/7] Test: Watchdog: Update the deprecated calls Replace the wait_ms() with wait_us(). Replace the Semaphore::wait() with Semaphore::acquire(). --- TESTS/mbed_drivers/watchdog_reset/main.cpp | 32 +++++++++++--------- TESTS/mbed_hal/watchdog_reset/main.cpp | 34 ++++++++++++---------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/TESTS/mbed_drivers/watchdog_reset/main.cpp b/TESTS/mbed_drivers/watchdog_reset/main.cpp index b02e458cf0..ddb98f9b6d 100644 --- a/TESTS/mbed_drivers/watchdog_reset/main.cpp +++ b/TESTS/mbed_drivers/watchdog_reset/main.cpp @@ -68,6 +68,10 @@ */ #define SERIAL_FLUSH_TIME_MS 20 +#define TIMEOUT_US (1000 * (TIMEOUT_MS)) +#define KICK_ADVANCE_US (1000 * (KICK_ADVANCE_MS)) +#define SERIAL_FLUSH_TIME_US (1000 * (SERIAL_FLUSH_TIME_MS)) + using utest::v1::Case; using utest::v1::Specification; using utest::v1::Harness; @@ -133,9 +137,9 @@ void test_simple_reset() TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS)); TEST_ASSERT_TRUE(watchdog.is_running()); // Watchdog should fire before twice the timeout value. - wait_ms(2 * TIMEOUT_MS); // Device reset expected. + wait_us(2 * TIMEOUT_US); // Device reset expected. - // Watchdog reset should have occurred during wait_ms() above; + // Watchdog reset should have occurred during a wait above. kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); @@ -169,10 +173,10 @@ void test_sleep_reset() TEST_ASSERT_MESSAGE(0, "Deepsleep should be disallowed."); return; } - sem.wait(); // Device reset expected. + sem.acquire(); // Device reset expected. sleep_manager_unlock_deep_sleep(); - // Watchdog reset should have occurred during sem.wait() (sleep) above; + // Watchdog reset should have occurred during sem.acquire() (sleep) above. kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); @@ -201,13 +205,13 @@ void test_deepsleep_reset() 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)); - wait_ms(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. + wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush. if (!sleep_manager_can_deep_sleep()) { TEST_ASSERT_MESSAGE(0, "Deepsleep should be allowed."); } - sem.wait(); // Device reset expected. + sem.acquire(); // Device reset expected. - // Watchdog reset should have occurred during sem.wait() (deepsleep) above; + // Watchdog reset should have occurred during sem.acquire() (deepsleep) above. kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); @@ -235,13 +239,13 @@ void test_restart_reset() TEST_ASSERT_FALSE(watchdog.is_running()); TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS)); TEST_ASSERT_TRUE(watchdog.is_running()); - wait_ms(TIMEOUT_MS / 2UL); + wait_us(TIMEOUT_US / 2); TEST_ASSERT_TRUE(watchdog.stop()); TEST_ASSERT_FALSE(watchdog.is_running()); // Check that stopping the Watchdog prevents a device reset. // The watchdog should trigger at, or after the timeout value. // The watchdog should trigger before twice the timeout value. - wait_ms(TIMEOUT_MS / 2UL + TIMEOUT_MS); + wait_us(TIMEOUT_US / 2 + TIMEOUT_US); if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS) == false) { TEST_ASSERT_MESSAGE(0, "Dev-host communication error."); @@ -250,9 +254,9 @@ void test_restart_reset() TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS)); TEST_ASSERT_TRUE(watchdog.is_running()); // Watchdog should fire before twice the timeout value. - wait_ms(2 * TIMEOUT_MS); // Device reset expected. + wait_us(2 * TIMEOUT_US); // Device reset expected. - // Watchdog reset should have occurred during that wait() above; + // Watchdog reset should have occurred during a wait above. kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); @@ -275,7 +279,7 @@ void test_kick_reset() for (int i = 3; i; i--) { // The reset is prevented as long as the watchdog is kicked // anytime before the timeout. - wait_ms(TIMEOUT_MS - KICK_ADVANCE_MS); + wait_us(TIMEOUT_US - KICK_ADVANCE_US); watchdog.kick(); } if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS) == false) { @@ -283,9 +287,9 @@ void test_kick_reset() return; } // Watchdog should fire before twice the timeout value. - wait_ms(2 * TIMEOUT_MS); // Device reset expected. + wait_us(2 * TIMEOUT_US); // Device reset expected. - // Watchdog reset should have occurred during that wait() above; + // Watchdog reset should have occurred during a wait above. kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); diff --git a/TESTS/mbed_hal/watchdog_reset/main.cpp b/TESTS/mbed_hal/watchdog_reset/main.cpp index 2ac592a3be..9a4ea7f4c8 100644 --- a/TESTS/mbed_hal/watchdog_reset/main.cpp +++ b/TESTS/mbed_hal/watchdog_reset/main.cpp @@ -66,7 +66,11 @@ * flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms. * To be on the safe side, set the wait time to 20 ms. */ -#define SERIAL_FLUSH_TIME_MS 20 +#define SERIAL_FLUSH_TIME_MS 20 + +#define TIMEOUT_US (1000 * (TIMEOUT_MS)) +#define KICK_ADVANCE_US (1000 * (KICK_ADVANCE_MS)) +#define SERIAL_FLUSH_TIME_US (1000 * (SERIAL_FLUSH_TIME_MS)) using utest::v1::Case; using utest::v1::Specification; @@ -128,9 +132,9 @@ void test_simple_reset() } TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config)); // Watchdog should fire before twice the timeout value. - wait_ms(2 * TIMEOUT_MS); // Device reset expected. + wait_us(2 * TIMEOUT_US); // Device reset expected. - // Watchdog reset should have occurred during wait_ms() above; + // Watchdog reset should have occurred during a wait above. kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); @@ -162,10 +166,10 @@ void test_sleep_reset() TEST_ASSERT_MESSAGE(0, "Deepsleep should be disallowed."); return; } - sem.wait(); // Device reset expected. + sem.acquire(); // Device reset expected. sleep_manager_unlock_deep_sleep(); - // Watchdog reset should have occurred during sem.wait() (sleep) above; + // Watchdog reset should have occurred during sem.acquire() (sleep) above. kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); @@ -192,13 +196,13 @@ void test_deepsleep_reset() 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)); - wait_ms(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. + wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush. if (!sleep_manager_can_deep_sleep()) { TEST_ASSERT_MESSAGE(0, "Deepsleep should be allowed."); } - sem.wait(); // Device reset expected. + sem.acquire(); // Device reset expected. - // Watchdog reset should have occurred during sem.wait() (deepsleep) above; + // Watchdog reset should have occurred during sem.acquire() (deepsleep) above. kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); @@ -224,12 +228,12 @@ void test_restart_reset() // Phase 1. -- run the test code. watchdog_config_t config = { TIMEOUT_MS }; TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config)); - wait_ms(TIMEOUT_MS / 2UL); + wait_us(TIMEOUT_US / 2); TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_stop()); // Check that stopping the Watchdog prevents a device reset. // The watchdog should trigger at, or after the timeout value. // The watchdog should trigger before twice the timeout value. - wait_ms(TIMEOUT_MS / 2UL + TIMEOUT_MS); + wait_us(TIMEOUT_US / 2 + TIMEOUT_US); if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS) == false) { TEST_ASSERT_MESSAGE(0, "Dev-host communication error."); @@ -237,9 +241,9 @@ void test_restart_reset() } TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config)); // Watchdog should fire before twice the timeout value. - wait_ms(2 * TIMEOUT_MS); // Device reset expected. + wait_us(2 * TIMEOUT_US); // Device reset expected. - // Watchdog reset should have occurred during that wait() above; + // Watchdog reset should have occurred during a wait above. kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); @@ -260,7 +264,7 @@ void test_kick_reset() for (int i = 3; i; i--) { // The reset is prevented as long as the watchdog is kicked // anytime before the timeout. - wait_ms(TIMEOUT_MS - KICK_ADVANCE_MS); + wait_us(TIMEOUT_US - KICK_ADVANCE_US); hal_watchdog_kick(); } if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS) == false) { @@ -268,9 +272,9 @@ void test_kick_reset() return; } // Watchdog should fire before twice the timeout value. - wait_ms(2 * TIMEOUT_MS); // Device reset expected. + wait_us(2 * TIMEOUT_US); // Device reset expected. - // Watchdog reset should have occurred during that wait() above; + // Watchdog reset should have occurred during a wait above. kick_wdg_during_test_teardown.release(); // For testsuite failure handling. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); From 361804b91d6c40327e6c8755fd1b93de7bf40496 Mon Sep 17 00:00:00 2001 From: Filip Jagodzinski Date: Wed, 30 Oct 2019 11:35:55 +0100 Subject: [PATCH 4/7] Test: Watchdog: Fix deepsleep wait Wait for the serial buffers flush before starting the watchdog. --- TESTS/mbed_drivers/watchdog_reset/main.cpp | 4 ++-- TESTS/mbed_hal/watchdog_reset/main.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/TESTS/mbed_drivers/watchdog_reset/main.cpp b/TESTS/mbed_drivers/watchdog_reset/main.cpp index ddb98f9b6d..e17fe4a4df 100644 --- a/TESTS/mbed_drivers/watchdog_reset/main.cpp +++ b/TESTS/mbed_drivers/watchdog_reset/main.cpp @@ -195,17 +195,17 @@ void test_deepsleep_reset() // Phase 1. -- run the test code. Semaphore sem(0, 1); LowPowerTimeout lp_timeout; - if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS) == false) { + if (send_reset_notification(¤t_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. Watchdog &watchdog = Watchdog::get_instance(); 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)); - wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush. if (!sleep_manager_can_deep_sleep()) { TEST_ASSERT_MESSAGE(0, "Deepsleep should be allowed."); } diff --git a/TESTS/mbed_hal/watchdog_reset/main.cpp b/TESTS/mbed_hal/watchdog_reset/main.cpp index 9a4ea7f4c8..2a71471365 100644 --- a/TESTS/mbed_hal/watchdog_reset/main.cpp +++ b/TESTS/mbed_hal/watchdog_reset/main.cpp @@ -189,14 +189,14 @@ void test_deepsleep_reset() watchdog_config_t config = { TIMEOUT_MS }; Semaphore sem(0, 1); LowPowerTimeout lp_timeout; - if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS) == false) { + if (send_reset_notification(¤t_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)); - wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush. if (!sleep_manager_can_deep_sleep()) { TEST_ASSERT_MESSAGE(0, "Deepsleep should be allowed."); } From 8640da4f9d514776651993027ddcb48e7e26c917 Mon Sep 17 00:00:00 2001 From: Filip Jagodzinski Date: Wed, 30 Oct 2019 11:42:22 +0100 Subject: [PATCH 5/7] Test: Watchdog: Update the sleep & deepsleep cases Use ThisThread::sleep_for() for sleeping instead of the calls to Semaphore::acquire(). --- TESTS/mbed_drivers/watchdog_reset/main.cpp | 23 ++++++---------------- TESTS/mbed_hal/watchdog_reset/main.cpp | 23 ++++++---------------- 2 files changed, 12 insertions(+), 34 deletions(-) diff --git a/TESTS/mbed_drivers/watchdog_reset/main.cpp b/TESTS/mbed_drivers/watchdog_reset/main.cpp index e17fe4a4df..6711f37ae5 100644 --- a/TESTS/mbed_drivers/watchdog_reset/main.cpp +++ b/TESTS/mbed_drivers/watchdog_reset/main.cpp @@ -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(¤t_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(¤t_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."); diff --git a/TESTS/mbed_hal/watchdog_reset/main.cpp b/TESTS/mbed_hal/watchdog_reset/main.cpp index 2a71471365..27b269b4bf 100644 --- a/TESTS/mbed_hal/watchdog_reset/main.cpp +++ b/TESTS/mbed_hal/watchdog_reset/main.cpp @@ -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(¤t_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(¤t_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."); From 945a9b3ad5e063a63f823b356b3ae997fe1f46fc Mon Sep 17 00:00:00 2001 From: Filip Jagodzinski Date: Mon, 4 Nov 2019 10:58:56 +0100 Subject: [PATCH 6/7] K64F: Fix the watchdog mode settings Enable the Watchdog Timer for the low-power stop modes of operation, including the VLPS used in deepsleep. Enable the Watchdog Timer for the Debug mode. --- .../TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/watchdog_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/watchdog_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/watchdog_api.c index 1b2f72feb4..7e3961dd94 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/watchdog_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/watchdog_api.c @@ -75,8 +75,8 @@ watchdog_status_t hal_watchdog_init(const watchdog_config_t *config) cfg.enableInterrupt = false; cfg.enableWindowMode = false; cfg.workMode.enableWait = true; - cfg.workMode.enableStop = false; - cfg.workMode.enableDebug = false; + cfg.workMode.enableStop = true; + cfg.workMode.enableDebug = true; const uint32_t prescaler = calculate_prescaler_value(config->timeout_ms); From 55e1a760cb8f19022659a1cd197b9167cf7d3b9c Mon Sep 17 00:00:00 2001 From: Filip Jagodzinski Date: Mon, 4 Nov 2019 20:27:41 +0100 Subject: [PATCH 7/7] Test: Watchdog: Update the deepsleep wait Extend the deepsleep wait up to 220% of the Watchdog timeout. One of the current Watchdog timing requirements is to fire BEFORE twice the timeout value, but at least one target (K64F) is expected to fire EXACTLY at a doubled timeout value in deepsleep mode. This patch updates the test to cope with a new deepsleep timing requirement. --- TESTS/mbed_drivers/watchdog_reset/main.cpp | 8 ++++++-- TESTS/mbed_hal/watchdog_reset/main.cpp | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/TESTS/mbed_drivers/watchdog_reset/main.cpp b/TESTS/mbed_drivers/watchdog_reset/main.cpp index 6711f37ae5..97914ab1f5 100644 --- a/TESTS/mbed_drivers/watchdog_reset/main.cpp +++ b/TESTS/mbed_drivers/watchdog_reset/main.cpp @@ -197,8 +197,12 @@ void test_deepsleep_reset() if (!sleep_manager_can_deep_sleep()) { TEST_ASSERT_MESSAGE(0, "Deepsleep should be allowed."); } - // Watchdog should fire before twice the timeout value. - ThisThread::sleep_for(2 * TIMEOUT_MS); // Device reset expected. + + // The Watchdog reset is allowed to be delayed up to twice the timeout + // value when the deepsleep mode is active. + // To make the test less sensitive to clock/wait accuracy, add 20% extra + // (making tha whole deepsleep wait equal to 2.2 * timeout). + ThisThread::sleep_for(220 * TIMEOUT_MS / 100); // Device reset expected. // Watchdog reset should have occurred during the deepsleep above. diff --git a/TESTS/mbed_hal/watchdog_reset/main.cpp b/TESTS/mbed_hal/watchdog_reset/main.cpp index 27b269b4bf..284a5bb3c0 100644 --- a/TESTS/mbed_hal/watchdog_reset/main.cpp +++ b/TESTS/mbed_hal/watchdog_reset/main.cpp @@ -188,8 +188,12 @@ void test_deepsleep_reset() if (!sleep_manager_can_deep_sleep()) { TEST_ASSERT_MESSAGE(0, "Deepsleep should be allowed."); } - // Watchdog should fire before twice the timeout value. - ThisThread::sleep_for(2 * TIMEOUT_MS); // Device reset expected. + + // The Watchdog reset is allowed to be delayed up to twice the timeout + // value when the deepsleep mode is active. + // To make the test less sensitive to clock/wait accuracy, add 20% extra + // (making tha whole deepsleep wait equal to 2.2 * timeout). + ThisThread::sleep_for(220 * TIMEOUT_MS / 100); // Device reset expected. // Watchdog reset should have occurred during the deepsleep above.