From c29cdab0796e1a44d5d24723daceaf9d46e305ef Mon Sep 17 00:00:00 2001 From: Filip Jagodzinski Date: Mon, 23 Apr 2018 16:40:30 +0200 Subject: [PATCH 1/3] Tests: Watchdog: Update test case teardown Added a mechanism which will prevent an initialised watchdog from resetting the device during final greentea communication. This allows testing watchdog timeouts as short as 50 ms. --- TESTS/mbed_hal/watchdog/main.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/TESTS/mbed_hal/watchdog/main.cpp b/TESTS/mbed_hal/watchdog/main.cpp index 04c5b0d5186..60ba65bc3c9 100644 --- a/TESTS/mbed_hal/watchdog/main.cpp +++ b/TESTS/mbed_hal/watchdog/main.cpp @@ -24,6 +24,7 @@ #include "unity/unity.h" #include "utest/utest.h" #include "watchdog_api_tests.h" +#include "mbed.h" #include @@ -35,6 +36,10 @@ #define WORST_TIMEOUT_RESOLUTION_MS 8UL #define TIMEOUT_DELTA_MS (WORST_TIMEOUT_RESOLUTION_MS) + +// Do not set watchdog timeout shorter than 50 ms as it may cause the +// host-test-runner return 'TIMEOUT' instead of 'FAIL' / 'PASS' if watchdog +// performs reset during test suite teardown. #define WDG_TIMEOUT_MS 500UL #define MSG_VALUE_DUMMY "0" @@ -69,6 +74,18 @@ using utest::v1::Harness; const watchdog_config_t WDG_CONFIG_DEFAULT = { .timeout_ms = WDG_TIMEOUT_MS }; +Thread wdg_kicking_thread; +Semaphore kick_wdg_during_test_teardown(0, 1); + +void wdg_kicking_thread_fun() +{ + kick_wdg_during_test_teardown.wait(); + while (true) { + hal_watchdog_kick(); + wait_ms(20); + } +} + void test_max_timeout_is_valid() { TEST_ASSERT(hal_watchdog_get_platform_features().max_timeout > 1UL); @@ -133,6 +150,8 @@ utest::v1::status_t case_setup_sync_on_reset(const Case *const source, const siz utest::v1::status_t case_teardown_sync_on_reset(const Case *const source, const size_t passed, const size_t failed, const utest::v1::failure_t failure) { + // Unlock kicking the watchdog during teardown. + kick_wdg_during_test_teardown.release(); utest::v1::status_t status = utest::v1::greentea_case_teardown_handler(source, passed, failed, failure); if (failed) { /* Return immediately and skip the device reset, if the test case failed. @@ -206,6 +225,10 @@ int testsuite_setup_sync_on_reset(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("Starting with test case index %i of all %i defined test cases.\n", CASE_INDEX_START, number_of_cases); return CASE_INDEX_START; } @@ -220,9 +243,6 @@ Case cases[] = { test_update_config, (utest::v1::case_teardown_handler_t) case_teardown_wdg_stop_or_reset), - // Do not set watchdog timeout shorter than 500 ms as it may cause the - // host-test-runner return 'TIMEOUT' instead of 'FAIL' / 'PASS' if watchdog - // performs reset during test suite teardown. Case("Init, 500 ms", (utest::v1::case_setup_handler_t) case_setup_sync_on_reset, test_init<500UL>, (utest::v1::case_teardown_handler_t) case_teardown_sync_on_reset), Case("Init, max_timeout", (utest::v1::case_setup_handler_t) case_setup_sync_on_reset, From d634862a09a33437703b5fc6996dbac6d58b1353 Mon Sep 17 00:00:00 2001 From: Filip Jagodzinski Date: Tue, 15 May 2018 15:11:48 +0200 Subject: [PATCH 2/3] Tests: Watchdog: Decrease default timeout to 100 ms --- TESTS/mbed_hal/watchdog/main.cpp | 6 +++--- TESTS/mbed_hal/watchdog_reset/main.cpp | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/TESTS/mbed_hal/watchdog/main.cpp b/TESTS/mbed_hal/watchdog/main.cpp index 60ba65bc3c9..c22d1e9623a 100644 --- a/TESTS/mbed_hal/watchdog/main.cpp +++ b/TESTS/mbed_hal/watchdog/main.cpp @@ -40,7 +40,7 @@ // Do not set watchdog timeout shorter than 50 ms as it may cause the // host-test-runner return 'TIMEOUT' instead of 'FAIL' / 'PASS' if watchdog // performs reset during test suite teardown. -#define WDG_TIMEOUT_MS 500UL +#define WDG_TIMEOUT_MS 100UL #define MSG_VALUE_DUMMY "0" #define MSG_VALUE_LEN 24 @@ -243,8 +243,8 @@ Case cases[] = { test_update_config, (utest::v1::case_teardown_handler_t) case_teardown_wdg_stop_or_reset), - Case("Init, 500 ms", (utest::v1::case_setup_handler_t) case_setup_sync_on_reset, - test_init<500UL>, (utest::v1::case_teardown_handler_t) case_teardown_sync_on_reset), + Case("Init, 100 ms", (utest::v1::case_setup_handler_t) case_setup_sync_on_reset, + test_init<100UL>, (utest::v1::case_teardown_handler_t) case_teardown_sync_on_reset), Case("Init, max_timeout", (utest::v1::case_setup_handler_t) case_setup_sync_on_reset, test_init_max_timeout, (utest::v1::case_teardown_handler_t) case_teardown_sync_on_reset), }; diff --git a/TESTS/mbed_hal/watchdog_reset/main.cpp b/TESTS/mbed_hal/watchdog_reset/main.cpp index 9421f222cf6..2fbf4d304e6 100644 --- a/TESTS/mbed_hal/watchdog_reset/main.cpp +++ b/TESTS/mbed_hal/watchdog_reset/main.cpp @@ -25,13 +25,14 @@ #include "watchdog_reset_tests.h" #include "mbed.h" -#define TIMEOUT_MS 500UL #if TARGET_NUMAKER_PFM_NANO130 /* On NUMAKER_PFM_NANO130 target, WDT's clock source is fixed to LIRC, which is more * inaccurate than other targets. Enlarge this delta define to pass this test. */ +#define TIMEOUT_MS 500UL #define TIMEOUT_DELTA_MS 100UL #else -#define TIMEOUT_DELTA_MS 50UL +#define TIMEOUT_MS 100UL +#define TIMEOUT_DELTA_MS 10UL #endif #define MSG_VALUE_DUMMY "0" From c5ad70c1e5ce060216419375c50350650b33488a Mon Sep 17 00:00:00 2001 From: Filip Jagodzinski Date: Fri, 25 May 2018 14:26:12 +0200 Subject: [PATCH 3/3] Tests: Watchdog: Update timing test Skip test cases with unsupported timeout values. --- TESTS/mbed_hal/watchdog_timing/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/TESTS/mbed_hal/watchdog_timing/main.cpp b/TESTS/mbed_hal/watchdog_timing/main.cpp index 8e9d3940c35..19eab7d58f9 100644 --- a/TESTS/mbed_hal/watchdog_timing/main.cpp +++ b/TESTS/mbed_hal/watchdog_timing/main.cpp @@ -50,6 +50,12 @@ testcase_data current_case; template void test_timing() { + watchdog_features_t features = hal_watchdog_get_platform_features(); + if (timeout_ms > features.max_timeout) { + TEST_IGNORE_MESSAGE("Requested timeout value not supported for this target -- ignoring test case."); + return; + } + // Phase 2. -- verify the test results. // Verify the heartbeat time span sent by host is within given delta. if (current_case.received_data != CASE_DATA_INVALID) {