Skip to content

Commit 5a0fafd

Browse files
author
Filip Jagodzinski
committed
Test: Watchdog: Update the test case teardown
Replace the thread used in the test case teardown with a Ticker to allow testing with the bare metal profile. This Ticker is used to prevent the watchdog from resetting the device during the final greentea communication.
1 parent de798c4 commit 5a0fafd

File tree

4 files changed

+30
-77
lines changed

4 files changed

+30
-77
lines changed

TESTS/mbed_drivers/watchdog/main.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,6 @@ using utest::v1::Harness;
7373

7474
using namespace mbed;
7575

76-
Thread wdg_kicking_thread(osPriorityNormal, 768);
77-
Semaphore kick_wdg_during_test_teardown(0, 1);
78-
79-
void wdg_kicking_thread_fun()
80-
{
81-
kick_wdg_during_test_teardown.wait();
82-
while (true) {
83-
hal_watchdog_kick();
84-
wait_ms(20);
85-
}
86-
}
87-
8876
void test_max_timeout_is_valid()
8977
{
9078
Watchdog &watchdog = Watchdog::get_instance();
@@ -172,8 +160,10 @@ utest::v1::status_t case_teardown_sync_on_reset(const Case *const source, const
172160
if (CASE_IGNORED) {
173161
return utest::v1::greentea_case_teardown_handler(source, passed, failed, failure);
174162
}
175-
// Unlock kicking the watchdog during teardown.
176-
kick_wdg_during_test_teardown.release();
163+
// Start kicking the watchdog during teardown.
164+
hal_watchdog_kick();
165+
Ticker wdg_kicking_ticker;
166+
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000);
177167
utest::v1::status_t status = utest::v1::greentea_case_teardown_handler(source, passed, failed, failure);
178168
if (failed) {
179169
/* Return immediately and skip the device reset, if the test case failed.
@@ -260,10 +250,6 @@ int testsuite_setup_sync_on_reset(const size_t number_of_cases)
260250
return utest::v1::STATUS_ABORT;
261251
}
262252

263-
// The thread is started here, but feeding the watchdog will start
264-
// when the semaphore is released during a test case teardown.
265-
wdg_kicking_thread.start(mbed::callback(wdg_kicking_thread_fun));
266-
267253
utest_printf("Starting with test case index %i of all %i defined test cases.\n", CASE_INDEX_START, number_of_cases);
268254
return CASE_INDEX_START;
269255
}

TESTS/mbed_drivers/watchdog_reset/main.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,7 @@ struct testcase_data {
9090

9191
testcase_data current_case;
9292

93-
Thread wdg_kicking_thread(osPriorityNormal, 768);
94-
Semaphore kick_wdg_during_test_teardown(0, 1);
95-
96-
void wdg_kicking_thread_fun()
97-
{
98-
kick_wdg_during_test_teardown.acquire();
99-
Watchdog &watchdog = Watchdog::get_instance();
100-
while (true) {
101-
watchdog.kick();
102-
wait_us(20000);
103-
}
104-
}
93+
Ticker wdg_kicking_ticker;
10594

10695
bool send_reset_notification(testcase_data *tcdata, uint32_t delay_ms)
10796
{
@@ -140,7 +129,8 @@ void test_simple_reset()
140129

141130
// Watchdog reset should have occurred during a wait above.
142131

143-
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
132+
hal_watchdog_kick();
133+
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
144134
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
145135
}
146136

@@ -174,7 +164,8 @@ void test_sleep_reset()
174164

175165
// Watchdog reset should have occurred during the sleep above.
176166

177-
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
167+
hal_watchdog_kick();
168+
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
178169
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
179170
}
180171

@@ -210,7 +201,8 @@ void test_deepsleep_reset()
210201

211202
// Watchdog reset should have occurred during the deepsleep above.
212203

213-
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
204+
hal_watchdog_kick();
205+
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
214206
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
215207
}
216208
#endif
@@ -255,7 +247,8 @@ void test_restart_reset()
255247

256248
// Watchdog reset should have occurred during a wait above.
257249

258-
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
250+
hal_watchdog_kick();
251+
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
259252
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
260253
}
261254

@@ -288,7 +281,8 @@ void test_kick_reset()
288281

289282
// Watchdog reset should have occurred during a wait above.
290283

291-
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
284+
hal_watchdog_kick();
285+
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
292286
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
293287
}
294288

@@ -323,10 +317,6 @@ int testsuite_setup(const size_t number_of_cases)
323317
return utest::v1::STATUS_ABORT;
324318
}
325319

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

TESTS/mbed_hal/watchdog/main.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,6 @@ using utest::v1::Harness;
7373

7474
const watchdog_config_t WDG_CONFIG_DEFAULT = { .timeout_ms = WDG_TIMEOUT_MS };
7575

76-
Thread wdg_kicking_thread(osPriorityNormal, 768);
77-
Semaphore kick_wdg_during_test_teardown(0, 1);
78-
79-
void wdg_kicking_thread_fun()
80-
{
81-
kick_wdg_during_test_teardown.wait();
82-
while (true) {
83-
hal_watchdog_kick();
84-
wait_ms(20);
85-
}
86-
}
87-
8876
void test_max_timeout_is_valid()
8977
{
9078
TEST_ASSERT(hal_watchdog_get_platform_features().max_timeout > 1UL);
@@ -168,8 +156,10 @@ utest::v1::status_t case_teardown_sync_on_reset(const Case *const source, const
168156
if (CASE_IGNORED) {
169157
return utest::v1::greentea_case_teardown_handler(source, passed, failed, failure);
170158
}
171-
// Unlock kicking the watchdog during teardown.
172-
kick_wdg_during_test_teardown.release();
159+
// Start kicking the watchdog during teardown.
160+
hal_watchdog_kick();
161+
Ticker wdg_kicking_ticker;
162+
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000);
173163
utest::v1::status_t status = utest::v1::greentea_case_teardown_handler(source, passed, failed, failure);
174164
if (failed) {
175165
/* Return immediately and skip the device reset, if the test case failed.
@@ -256,10 +246,6 @@ int testsuite_setup_sync_on_reset(const size_t number_of_cases)
256246
return utest::v1::STATUS_ABORT;
257247
}
258248

259-
// The thread is started here, but feeding the watchdog will start
260-
// when the semaphore is released during a test case teardown.
261-
wdg_kicking_thread.start(mbed::callback(wdg_kicking_thread_fun));
262-
263249
utest_printf("Starting with test case index %i of all %i defined test cases.\n", CASE_INDEX_START, number_of_cases);
264250
return CASE_INDEX_START;
265251
}

TESTS/mbed_hal/watchdog_reset/main.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,7 @@ struct testcase_data {
8888

8989
testcase_data current_case;
9090

91-
Thread wdg_kicking_thread(osPriorityNormal, 768);
92-
Semaphore kick_wdg_during_test_teardown(0, 1);
93-
94-
void wdg_kicking_thread_fun()
95-
{
96-
kick_wdg_during_test_teardown.acquire();
97-
while (true) {
98-
hal_watchdog_kick();
99-
wait_us(20000);
100-
}
101-
}
91+
Ticker wdg_kicking_ticker;
10292

10393
bool send_reset_notification(testcase_data *tcdata, uint32_t delay_ms)
10494
{
@@ -135,7 +125,8 @@ void test_simple_reset()
135125

136126
// Watchdog reset should have occurred during a wait above.
137127

138-
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
128+
hal_watchdog_kick();
129+
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
139130
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
140131
}
141132

@@ -167,7 +158,8 @@ void test_sleep_reset()
167158

168159
// Watchdog reset should have occurred during the sleep above.
169160

170-
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
161+
hal_watchdog_kick();
162+
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
171163
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
172164
}
173165

@@ -201,7 +193,8 @@ void test_deepsleep_reset()
201193

202194
// Watchdog reset should have occurred during the deepsleep above.
203195

204-
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
196+
hal_watchdog_kick();
197+
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
205198
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
206199
}
207200
#endif
@@ -242,7 +235,8 @@ void test_restart_reset()
242235

243236
// Watchdog reset should have occurred during a wait above.
244237

245-
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
238+
hal_watchdog_kick();
239+
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
246240
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
247241
}
248242

@@ -273,7 +267,8 @@ void test_kick_reset()
273267

274268
// Watchdog reset should have occurred during a wait above.
275269

276-
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
270+
hal_watchdog_kick();
271+
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000); // For testsuite failure handling.
277272
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
278273
}
279274

@@ -308,10 +303,6 @@ int testsuite_setup(const size_t number_of_cases)
308303
return utest::v1::STATUS_ABORT;
309304
}
310305

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

0 commit comments

Comments
 (0)