Skip to content

Update watchdog tests -- allow shorter timeouts #6709

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
Show file tree
Hide file tree
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
32 changes: 26 additions & 6 deletions TESTS/mbed_drivers/watchdog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "unity/unity.h"
#include "drivers/Watchdog.h"
#include "Watchdog_tests.h"
#include "mbed.h"

/* This is platform specific and depends on the watchdog timer implementation,
* e.g. STM32F4 uses 32kHz internal RC oscillator to clock the IWDG, so
Expand All @@ -33,7 +34,11 @@
#define WORST_TIMEOUT_RESOLUTION_MS 8UL

#define TIMEOUT_DELTA_MS (WORST_TIMEOUT_RESOLUTION_MS)
#define WDG_TIMEOUT_MS 500UL

// 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 100UL

#define MSG_VALUE_DUMMY "0"
#define MSG_VALUE_LEN 24
Expand All @@ -50,6 +55,18 @@ using utest::v1::Case;
using utest::v1::Specification;
using utest::v1::Harness;

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()
{
Watchdog watchdog;
Expand Down Expand Up @@ -112,6 +129,8 @@ utest::v1::status_t case_setup_sync_on_reset(const Case * const source, const si
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.
Expand Down Expand Up @@ -190,6 +209,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;
}
Expand All @@ -200,11 +223,8 @@ Case cases[] = {
Case("Restart multiple times", (utest::v1::case_setup_handler_t) case_setup_sync_on_reset,
test_restart, (utest::v1::case_teardown_handler_t) case_teardown_sync_on_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("Start, 500 ms", (utest::v1::case_setup_handler_t) case_setup_sync_on_reset,
test_start<500UL>, (utest::v1::case_teardown_handler_t) case_teardown_sync_on_reset),
Case("Start, 100 ms", (utest::v1::case_setup_handler_t) case_setup_sync_on_reset,
test_start<100UL>, (utest::v1::case_teardown_handler_t) case_teardown_sync_on_reset),
Case("Start, max_timeout", (utest::v1::case_setup_handler_t) case_setup_sync_on_reset,
test_start_max_timeout, (utest::v1::case_teardown_handler_t) case_teardown_sync_on_reset),

Expand Down
4 changes: 2 additions & 2 deletions TESTS/mbed_drivers/watchdog_reset/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include "Watchdog_reset_tests.h"
#include "mbed.h"

#define TIMEOUT_MS 500UL
#define TIMEOUT_DELTA_MS 50UL
#define TIMEOUT_MS 100UL
#define TIMEOUT_DELTA_MS 10UL

#define MSG_VALUE_DUMMY "0"
#define CASE_DATA_INVALID 0xffffffffUL
Expand Down
32 changes: 26 additions & 6 deletions TESTS/mbed_hal/watchdog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "unity/unity.h"
#include "hal/watchdog_api.h"
#include "watchdog_api_tests.h"
#include "mbed.h"

/* This is platform specific and depends on the watchdog timer implementation,
* e.g. STM32F4 uses 32kHz internal RC oscillator to clock the IWDG, so
Expand All @@ -31,7 +32,11 @@
#define WORST_TIMEOUT_RESOLUTION_MS 8UL

#define TIMEOUT_DELTA_MS (WORST_TIMEOUT_RESOLUTION_MS)
#define WDG_TIMEOUT_MS 500UL

// 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 100UL

#define MSG_VALUE_DUMMY "0"
#define MSG_VALUE_LEN 24
Expand All @@ -50,6 +55,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);
Expand Down Expand Up @@ -114,6 +131,8 @@ utest::v1::status_t case_setup_sync_on_reset(const Case * const source, const si
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.
Expand Down Expand Up @@ -187,6 +206,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;
}
Expand All @@ -201,11 +224,8 @@ 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, 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),
};
Expand Down
4 changes: 2 additions & 2 deletions TESTS/mbed_hal/watchdog_reset/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include "watchdog_reset_tests.h"
#include "mbed.h"

#define TIMEOUT_MS 500UL
#define TIMEOUT_DELTA_MS 50UL
#define TIMEOUT_MS 100UL
#define TIMEOUT_DELTA_MS 10UL

#define MSG_VALUE_DUMMY "0"
#define CASE_DATA_INVALID 0xffffffffUL
Expand Down