Skip to content

Commit b3d45c5

Browse files
authored
Merge pull request #10777 from fkjagodzinski/fix-watchdog-missing_commits
Bring back the missing watchdog commits
2 parents e3bcf0c + c5ad70c commit b3d45c5

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

TESTS/mbed_hal/watchdog/main.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "unity/unity.h"
2525
#include "utest/utest.h"
2626
#include "watchdog_api_tests.h"
27+
#include "mbed.h"
2728

2829
#include <stdlib.h>
2930

@@ -35,7 +36,11 @@
3536
#define WORST_TIMEOUT_RESOLUTION_MS 8UL
3637

3738
#define TIMEOUT_DELTA_MS (WORST_TIMEOUT_RESOLUTION_MS)
38-
#define WDG_TIMEOUT_MS 500UL
39+
40+
// Do not set watchdog timeout shorter than 50 ms as it may cause the
41+
// host-test-runner return 'TIMEOUT' instead of 'FAIL' / 'PASS' if watchdog
42+
// performs reset during test suite teardown.
43+
#define WDG_TIMEOUT_MS 100UL
3944

4045
#define MSG_VALUE_DUMMY "0"
4146
#define MSG_VALUE_LEN 24
@@ -69,6 +74,18 @@ using utest::v1::Harness;
6974

7075
const watchdog_config_t WDG_CONFIG_DEFAULT = { .timeout_ms = WDG_TIMEOUT_MS };
7176

77+
Thread wdg_kicking_thread;
78+
Semaphore kick_wdg_during_test_teardown(0, 1);
79+
80+
void wdg_kicking_thread_fun()
81+
{
82+
kick_wdg_during_test_teardown.wait();
83+
while (true) {
84+
hal_watchdog_kick();
85+
wait_ms(20);
86+
}
87+
}
88+
7289
void test_max_timeout_is_valid()
7390
{
7491
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
133150
utest::v1::status_t case_teardown_sync_on_reset(const Case *const source, const size_t passed, const size_t failed,
134151
const utest::v1::failure_t failure)
135152
{
153+
// Unlock kicking the watchdog during teardown.
154+
kick_wdg_during_test_teardown.release();
136155
utest::v1::status_t status = utest::v1::greentea_case_teardown_handler(source, passed, failed, failure);
137156
if (failed) {
138157
/* 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)
206225
return utest::v1::STATUS_ABORT;
207226
}
208227

228+
// The thread is started here, but feeding the watchdog will start
229+
// when the semaphore is released during a test case teardown.
230+
wdg_kicking_thread.start(mbed::callback(wdg_kicking_thread_fun));
231+
209232
utest_printf("Starting with test case index %i of all %i defined test cases.\n", CASE_INDEX_START, number_of_cases);
210233
return CASE_INDEX_START;
211234
}
@@ -220,11 +243,8 @@ Case cases[] = {
220243
test_update_config,
221244
(utest::v1::case_teardown_handler_t) case_teardown_wdg_stop_or_reset),
222245

223-
// Do not set watchdog timeout shorter than 500 ms as it may cause the
224-
// host-test-runner return 'TIMEOUT' instead of 'FAIL' / 'PASS' if watchdog
225-
// performs reset during test suite teardown.
226-
Case("Init, 500 ms", (utest::v1::case_setup_handler_t) case_setup_sync_on_reset,
227-
test_init<500UL>, (utest::v1::case_teardown_handler_t) case_teardown_sync_on_reset),
246+
Case("Init, 100 ms", (utest::v1::case_setup_handler_t) case_setup_sync_on_reset,
247+
test_init<100UL>, (utest::v1::case_teardown_handler_t) case_teardown_sync_on_reset),
228248
Case("Init, max_timeout", (utest::v1::case_setup_handler_t) case_setup_sync_on_reset,
229249
test_init_max_timeout, (utest::v1::case_teardown_handler_t) case_teardown_sync_on_reset),
230250
};

TESTS/mbed_hal/watchdog_reset/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
#include "watchdog_reset_tests.h"
2626
#include "mbed.h"
2727

28-
#define TIMEOUT_MS 500UL
2928
#if TARGET_NUMAKER_PFM_NANO130
3029
/* On NUMAKER_PFM_NANO130 target, WDT's clock source is fixed to LIRC, which is more
3130
* inaccurate than other targets. Enlarge this delta define to pass this test. */
31+
#define TIMEOUT_MS 500UL
3232
#define TIMEOUT_DELTA_MS 100UL
3333
#else
34-
#define TIMEOUT_DELTA_MS 50UL
34+
#define TIMEOUT_MS 100UL
35+
#define TIMEOUT_DELTA_MS 10UL
3536
#endif
3637

3738
#define MSG_VALUE_DUMMY "0"

TESTS/mbed_hal/watchdog_timing/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ testcase_data current_case;
5050
template<uint32_t timeout_ms, uint32_t delta_ms>
5151
void test_timing()
5252
{
53+
watchdog_features_t features = hal_watchdog_get_platform_features();
54+
if (timeout_ms > features.max_timeout) {
55+
TEST_IGNORE_MESSAGE("Requested timeout value not supported for this target -- ignoring test case.");
56+
return;
57+
}
58+
5359
// Phase 2. -- verify the test results.
5460
// Verify the heartbeat time span sent by host is within given delta.
5561
if (current_case.received_data != CASE_DATA_INVALID) {

0 commit comments

Comments
 (0)