24
24
#include " unity/unity.h"
25
25
#include " utest/utest.h"
26
26
#include " watchdog_api_tests.h"
27
+ #include " mbed.h"
27
28
28
29
#include < stdlib.h>
29
30
35
36
#define WORST_TIMEOUT_RESOLUTION_MS 8UL
36
37
37
38
#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
39
44
40
45
#define MSG_VALUE_DUMMY " 0"
41
46
#define MSG_VALUE_LEN 24
@@ -69,6 +74,18 @@ using utest::v1::Harness;
69
74
70
75
const watchdog_config_t WDG_CONFIG_DEFAULT = { .timeout_ms = WDG_TIMEOUT_MS };
71
76
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
+
72
89
void test_max_timeout_is_valid ()
73
90
{
74
91
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
133
150
utest::v1::status_t case_teardown_sync_on_reset (const Case *const source, const size_t passed, const size_t failed,
134
151
const utest::v1::failure_t failure)
135
152
{
153
+ // Unlock kicking the watchdog during teardown.
154
+ kick_wdg_during_test_teardown.release ();
136
155
utest::v1::status_t status = utest::v1::greentea_case_teardown_handler (source, passed, failed, failure);
137
156
if (failed) {
138
157
/* 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)
206
225
return utest::v1::STATUS_ABORT;
207
226
}
208
227
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
+
209
232
utest_printf (" Starting with test case index %i of all %i defined test cases.\n " , CASE_INDEX_START, number_of_cases);
210
233
return CASE_INDEX_START;
211
234
}
@@ -220,11 +243,8 @@ Case cases[] = {
220
243
test_update_config,
221
244
(utest::v1::case_teardown_handler_t ) case_teardown_wdg_stop_or_reset),
222
245
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),
228
248
Case (" Init, max_timeout" , (utest::v1::case_setup_handler_t ) case_setup_sync_on_reset,
229
249
test_init_max_timeout, (utest::v1::case_teardown_handler_t ) case_teardown_sync_on_reset),
230
250
};
0 commit comments