Skip to content

Commit e3f8711

Browse files
author
Filip Jagodzinski
committed
Test: Watchdog: Update the deprecated calls
Replace the wait_ms() with wait_us(). Replace the Semaphore::wait() with Semaphore::acquire().
1 parent 2410257 commit e3f8711

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

TESTS/mbed_drivers/watchdog_reset/main.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
*/
6969
#define SERIAL_FLUSH_TIME_MS 20
7070

71+
#define TIMEOUT_US (1000 * (TIMEOUT_MS))
72+
#define KICK_ADVANCE_US (1000 * (KICK_ADVANCE_MS))
73+
#define SERIAL_FLUSH_TIME_US (1000 * (SERIAL_FLUSH_TIME_MS))
74+
7175
using utest::v1::Case;
7276
using utest::v1::Specification;
7377
using utest::v1::Harness;
@@ -133,9 +137,9 @@ void test_simple_reset()
133137
TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS));
134138
TEST_ASSERT_TRUE(watchdog.is_running());
135139
// Watchdog should fire before twice the timeout value.
136-
wait_ms(2 * TIMEOUT_MS); // Device reset expected.
140+
wait_us(2 * TIMEOUT_US); // Device reset expected.
137141

138-
// Watchdog reset should have occurred during wait_ms() above;
142+
// Watchdog reset should have occurred during a wait above.
139143

140144
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
141145
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
@@ -169,10 +173,10 @@ void test_sleep_reset()
169173
TEST_ASSERT_MESSAGE(0, "Deepsleep should be disallowed.");
170174
return;
171175
}
172-
sem.wait(); // Device reset expected.
176+
sem.acquire(); // Device reset expected.
173177
sleep_manager_unlock_deep_sleep();
174178

175-
// Watchdog reset should have occurred during sem.wait() (sleep) above;
179+
// Watchdog reset should have occurred during sem.acquire() (sleep) above.
176180

177181
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
178182
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
@@ -201,13 +205,13 @@ void test_deepsleep_reset()
201205
TEST_ASSERT_TRUE(watchdog.is_running());
202206
// Watchdog should fire before twice the timeout value.
203207
lp_timeout.attach_us(mbed::callback(release_sem, &sem), 1000ULL * (2 * TIMEOUT_MS));
204-
wait_ms(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush.
208+
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
205209
if (!sleep_manager_can_deep_sleep()) {
206210
TEST_ASSERT_MESSAGE(0, "Deepsleep should be allowed.");
207211
}
208-
sem.wait(); // Device reset expected.
212+
sem.acquire(); // Device reset expected.
209213

210-
// Watchdog reset should have occurred during sem.wait() (deepsleep) above;
214+
// Watchdog reset should have occurred during sem.acquire() (deepsleep) above.
211215

212216
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
213217
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
@@ -235,13 +239,13 @@ void test_restart_reset()
235239
TEST_ASSERT_FALSE(watchdog.is_running());
236240
TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS));
237241
TEST_ASSERT_TRUE(watchdog.is_running());
238-
wait_ms(TIMEOUT_MS / 2UL);
242+
wait_us(TIMEOUT_US / 2);
239243
TEST_ASSERT_TRUE(watchdog.stop());
240244
TEST_ASSERT_FALSE(watchdog.is_running());
241245
// Check that stopping the Watchdog prevents a device reset.
242246
// The watchdog should trigger at, or after the timeout value.
243247
// The watchdog should trigger before twice the timeout value.
244-
wait_ms(TIMEOUT_MS / 2UL + TIMEOUT_MS);
248+
wait_us(TIMEOUT_US / 2 + TIMEOUT_US);
245249

246250
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
247251
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
@@ -250,9 +254,9 @@ void test_restart_reset()
250254
TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS));
251255
TEST_ASSERT_TRUE(watchdog.is_running());
252256
// Watchdog should fire before twice the timeout value.
253-
wait_ms(2 * TIMEOUT_MS); // Device reset expected.
257+
wait_us(2 * TIMEOUT_US); // Device reset expected.
254258

255-
// Watchdog reset should have occurred during that wait() above;
259+
// Watchdog reset should have occurred during a wait above.
256260

257261
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
258262
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
@@ -275,17 +279,17 @@ void test_kick_reset()
275279
for (int i = 3; i; i--) {
276280
// The reset is prevented as long as the watchdog is kicked
277281
// anytime before the timeout.
278-
wait_ms(TIMEOUT_MS - KICK_ADVANCE_MS);
282+
wait_us(TIMEOUT_US - KICK_ADVANCE_US);
279283
watchdog.kick();
280284
}
281285
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
282286
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
283287
return;
284288
}
285289
// Watchdog should fire before twice the timeout value.
286-
wait_ms(2 * TIMEOUT_MS); // Device reset expected.
290+
wait_us(2 * TIMEOUT_US); // Device reset expected.
287291

288-
// Watchdog reset should have occurred during that wait() above;
292+
// Watchdog reset should have occurred during a wait above.
289293

290294
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
291295
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");

TESTS/mbed_hal/watchdog_reset/main.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@
6666
* flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms.
6767
* To be on the safe side, set the wait time to 20 ms.
6868
*/
69-
#define SERIAL_FLUSH_TIME_MS 20
69+
#define SERIAL_FLUSH_TIME_MS 20
70+
71+
#define TIMEOUT_US (1000 * (TIMEOUT_MS))
72+
#define KICK_ADVANCE_US (1000 * (KICK_ADVANCE_MS))
73+
#define SERIAL_FLUSH_TIME_US (1000 * (SERIAL_FLUSH_TIME_MS))
7074

7175
using utest::v1::Case;
7276
using utest::v1::Specification;
@@ -128,9 +132,9 @@ void test_simple_reset()
128132
}
129133
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
130134
// Watchdog should fire before twice the timeout value.
131-
wait_ms(2 * TIMEOUT_MS); // Device reset expected.
135+
wait_us(2 * TIMEOUT_US); // Device reset expected.
132136

133-
// Watchdog reset should have occurred during wait_ms() above;
137+
// Watchdog reset should have occurred during a wait above.
134138

135139
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
136140
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
@@ -162,10 +166,10 @@ void test_sleep_reset()
162166
TEST_ASSERT_MESSAGE(0, "Deepsleep should be disallowed.");
163167
return;
164168
}
165-
sem.wait(); // Device reset expected.
169+
sem.acquire(); // Device reset expected.
166170
sleep_manager_unlock_deep_sleep();
167171

168-
// Watchdog reset should have occurred during sem.wait() (sleep) above;
172+
// Watchdog reset should have occurred during sem.acquire() (sleep) above.
169173

170174
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
171175
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
@@ -192,13 +196,13 @@ void test_deepsleep_reset()
192196
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
193197
// Watchdog should fire before twice the timeout value.
194198
lp_timeout.attach_us(mbed::callback(release_sem, &sem), 1000ULL * (2 * TIMEOUT_MS));
195-
wait_ms(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush.
199+
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
196200
if (!sleep_manager_can_deep_sleep()) {
197201
TEST_ASSERT_MESSAGE(0, "Deepsleep should be allowed.");
198202
}
199-
sem.wait(); // Device reset expected.
203+
sem.acquire(); // Device reset expected.
200204

201-
// Watchdog reset should have occurred during sem.wait() (deepsleep) above;
205+
// Watchdog reset should have occurred during sem.acquire() (deepsleep) above.
202206

203207
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
204208
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
@@ -224,22 +228,22 @@ void test_restart_reset()
224228
// Phase 1. -- run the test code.
225229
watchdog_config_t config = { TIMEOUT_MS };
226230
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
227-
wait_ms(TIMEOUT_MS / 2UL);
231+
wait_us(TIMEOUT_US / 2);
228232
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_stop());
229233
// Check that stopping the Watchdog prevents a device reset.
230234
// The watchdog should trigger at, or after the timeout value.
231235
// The watchdog should trigger before twice the timeout value.
232-
wait_ms(TIMEOUT_MS / 2UL + TIMEOUT_MS);
236+
wait_us(TIMEOUT_US / 2 + TIMEOUT_US);
233237

234238
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
235239
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
236240
return;
237241
}
238242
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
239243
// Watchdog should fire before twice the timeout value.
240-
wait_ms(2 * TIMEOUT_MS); // Device reset expected.
244+
wait_us(2 * TIMEOUT_US); // Device reset expected.
241245

242-
// Watchdog reset should have occurred during that wait() above;
246+
// Watchdog reset should have occurred during a wait above.
243247

244248
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
245249
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
@@ -260,17 +264,17 @@ void test_kick_reset()
260264
for (int i = 3; i; i--) {
261265
// The reset is prevented as long as the watchdog is kicked
262266
// anytime before the timeout.
263-
wait_ms(TIMEOUT_MS - KICK_ADVANCE_MS);
267+
wait_us(TIMEOUT_US - KICK_ADVANCE_US);
264268
hal_watchdog_kick();
265269
}
266270
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
267271
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
268272
return;
269273
}
270274
// Watchdog should fire before twice the timeout value.
271-
wait_ms(2 * TIMEOUT_MS); // Device reset expected.
275+
wait_us(2 * TIMEOUT_US); // Device reset expected.
272276

273-
// Watchdog reset should have occurred during that wait() above;
277+
// Watchdog reset should have occurred during a wait above.
274278

275279
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
276280
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");

0 commit comments

Comments
 (0)