Skip to content

Commit 7af11fa

Browse files
author
Filip Jagodzinski
committed
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.
1 parent 419556b commit 7af11fa

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

TESTS/mbed_drivers/watchdog_reset/main.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ void release_sem(Semaphore *sem)
8787

8888
testcase_data current_case;
8989

90+
Thread wdg_kicking_thread(osPriorityNormal, 768);
91+
Semaphore kick_wdg_during_test_teardown(0, 1);
92+
93+
void wdg_kicking_thread_fun()
94+
{
95+
kick_wdg_during_test_teardown.acquire();
96+
Watchdog &watchdog = Watchdog::get_instance();
97+
while (true) {
98+
watchdog.kick();
99+
wait_us(20000);
100+
}
101+
}
102+
90103
bool send_reset_notification(testcase_data *tcdata, uint32_t delay_ms)
91104
{
92105
char msg_value[12];
@@ -124,7 +137,7 @@ void test_simple_reset()
124137

125138
// Watchdog reset should have occurred during wait_ms() above;
126139

127-
watchdog.kick(); // Just to buy some time for testsuite failure handling.
140+
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
128141
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
129142
}
130143

@@ -161,7 +174,7 @@ void test_sleep_reset()
161174

162175
// Watchdog reset should have occurred during sem.wait() (sleep) above;
163176

164-
watchdog.kick(); // Just to buy some time for testsuite failure handling.
177+
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
165178
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
166179
}
167180

@@ -196,7 +209,7 @@ void test_deepsleep_reset()
196209

197210
// Watchdog reset should have occurred during sem.wait() (deepsleep) above;
198211

199-
watchdog.kick(); // Just to buy some time for testsuite failure handling.
212+
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
200213
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
201214
}
202215
#endif
@@ -241,7 +254,7 @@ void test_restart_reset()
241254

242255
// Watchdog reset should have occurred during that wait() above;
243256

244-
watchdog.kick(); // Just to buy some time for testsuite failure handling.
257+
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
245258
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
246259
}
247260

@@ -274,7 +287,7 @@ void test_kick_reset()
274287

275288
// Watchdog reset should have occurred during that wait() above;
276289

277-
watchdog.kick(); // Just to buy some time for testsuite failure handling.
290+
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
278291
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
279292
}
280293

@@ -309,6 +322,10 @@ int testsuite_setup(const size_t number_of_cases)
309322
return utest::v1::STATUS_ABORT;
310323
}
311324

325+
// The thread is started here, but feeding the watchdog will start
326+
// when the semaphore is released during a test case teardown.
327+
wdg_kicking_thread.start(mbed::callback(wdg_kicking_thread_fun));
328+
312329
utest_printf("This test suite is composed of %i test cases. Starting at index %i.\n", number_of_cases,
313330
current_case.start_index);
314331
return current_case.start_index;

TESTS/mbed_hal/watchdog_reset/main.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ void release_sem(Semaphore *sem)
8585

8686
testcase_data current_case;
8787

88+
Thread wdg_kicking_thread(osPriorityNormal, 768);
89+
Semaphore kick_wdg_during_test_teardown(0, 1);
90+
91+
void wdg_kicking_thread_fun()
92+
{
93+
kick_wdg_during_test_teardown.acquire();
94+
while (true) {
95+
hal_watchdog_kick();
96+
wait_us(20000);
97+
}
98+
}
99+
88100
bool send_reset_notification(testcase_data *tcdata, uint32_t delay_ms)
89101
{
90102
char msg_value[12];
@@ -120,7 +132,7 @@ void test_simple_reset()
120132

121133
// Watchdog reset should have occurred during wait_ms() above;
122134

123-
hal_watchdog_kick(); // Just to buy some time for testsuite failure handling.
135+
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
124136
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
125137
}
126138

@@ -155,7 +167,7 @@ void test_sleep_reset()
155167

156168
// Watchdog reset should have occurred during sem.wait() (sleep) above;
157169

158-
hal_watchdog_kick(); // Just to buy some time for testsuite failure handling.
170+
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
159171
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
160172
}
161173

@@ -188,7 +200,7 @@ void test_deepsleep_reset()
188200

189201
// Watchdog reset should have occurred during sem.wait() (deepsleep) above;
190202

191-
hal_watchdog_kick(); // Just to buy some time for testsuite failure handling.
203+
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
192204
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
193205
}
194206
#endif
@@ -229,7 +241,7 @@ void test_restart_reset()
229241

230242
// Watchdog reset should have occurred during that wait() above;
231243

232-
hal_watchdog_kick(); // Just to buy some time for testsuite failure handling.
244+
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
233245
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
234246
}
235247

@@ -260,7 +272,7 @@ void test_kick_reset()
260272

261273
// Watchdog reset should have occurred during that wait() above;
262274

263-
hal_watchdog_kick(); // Just to buy some time for testsuite failure handling.
275+
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
264276
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
265277
}
266278

@@ -295,6 +307,10 @@ int testsuite_setup(const size_t number_of_cases)
295307
return utest::v1::STATUS_ABORT;
296308
}
297309

310+
// The thread is started here, but feeding the watchdog will start
311+
// when the semaphore is released during a test case teardown.
312+
wdg_kicking_thread.start(mbed::callback(wdg_kicking_thread_fun));
313+
298314
utest_printf("This test suite is composed of %i test cases. Starting at index %i.\n", number_of_cases,
299315
current_case.start_index);
300316
return current_case.start_index;

0 commit comments

Comments
 (0)