Skip to content

Commit 8640da4

Browse files
author
Filip Jagodzinski
committed
Test: Watchdog: Update the sleep & deepsleep cases
Use ThisThread::sleep_for() for sleeping instead of the calls to Semaphore::acquire().
1 parent 361804b commit 8640da4

File tree

2 files changed

+12
-34
lines changed

2 files changed

+12
-34
lines changed

TESTS/mbed_drivers/watchdog_reset/main.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ struct testcase_data {
8484
uint32_t received_data;
8585
};
8686

87-
void release_sem(Semaphore *sem)
88-
{
89-
sem->release();
90-
}
91-
9287
testcase_data current_case;
9388

9489
Thread wdg_kicking_thread(osPriorityNormal, 768);
@@ -156,8 +151,6 @@ void test_sleep_reset()
156151
}
157152

158153
// Phase 1. -- run the test code.
159-
Semaphore sem(0, 1);
160-
Timeout timeout;
161154
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
162155
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
163156
return;
@@ -167,16 +160,15 @@ void test_sleep_reset()
167160
TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS));
168161
TEST_ASSERT_TRUE(watchdog.is_running());
169162
sleep_manager_lock_deep_sleep();
170-
// Watchdog should fire before twice the timeout value.
171-
timeout.attach_us(mbed::callback(release_sem, &sem), 1000ULL * (2 * TIMEOUT_MS));
172163
if (sleep_manager_can_deep_sleep()) {
173164
TEST_ASSERT_MESSAGE(0, "Deepsleep should be disallowed.");
174165
return;
175166
}
176-
sem.acquire(); // Device reset expected.
167+
// Watchdog should fire before twice the timeout value.
168+
ThisThread::sleep_for(2 * TIMEOUT_MS); // Device reset expected.
177169
sleep_manager_unlock_deep_sleep();
178170

179-
// Watchdog reset should have occurred during sem.acquire() (sleep) above.
171+
// Watchdog reset should have occurred during the sleep above.
180172

181173
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
182174
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
@@ -193,8 +185,6 @@ void test_deepsleep_reset()
193185
}
194186

195187
// Phase 1. -- run the test code.
196-
Semaphore sem(0, 1);
197-
LowPowerTimeout lp_timeout;
198188
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
199189
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
200190
return;
@@ -204,14 +194,13 @@ void test_deepsleep_reset()
204194
TEST_ASSERT_FALSE(watchdog.is_running());
205195
TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS));
206196
TEST_ASSERT_TRUE(watchdog.is_running());
207-
// Watchdog should fire before twice the timeout value.
208-
lp_timeout.attach_us(mbed::callback(release_sem, &sem), 1000ULL * (2 * TIMEOUT_MS));
209197
if (!sleep_manager_can_deep_sleep()) {
210198
TEST_ASSERT_MESSAGE(0, "Deepsleep should be allowed.");
211199
}
212-
sem.acquire(); // Device reset expected.
200+
// Watchdog should fire before twice the timeout value.
201+
ThisThread::sleep_for(2 * TIMEOUT_MS); // Device reset expected.
213202

214-
// Watchdog reset should have occurred during sem.acquire() (deepsleep) above.
203+
// Watchdog reset should have occurred during the deepsleep above.
215204

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

TESTS/mbed_hal/watchdog_reset/main.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ struct testcase_data {
8282
uint32_t received_data;
8383
};
8484

85-
void release_sem(Semaphore *sem)
86-
{
87-
sem->release();
88-
}
89-
9085
testcase_data current_case;
9186

9287
Thread wdg_kicking_thread(osPriorityNormal, 768);
@@ -152,24 +147,21 @@ void test_sleep_reset()
152147

153148
// Phase 1. -- run the test code.
154149
watchdog_config_t config = { TIMEOUT_MS };
155-
Semaphore sem(0, 1);
156-
Timeout timeout;
157150
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
158151
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
159152
return;
160153
}
161154
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
162155
sleep_manager_lock_deep_sleep();
163-
// Watchdog should fire before twice the timeout value.
164-
timeout.attach_us(mbed::callback(release_sem, &sem), 1000ULL * (2 * TIMEOUT_MS));
165156
if (sleep_manager_can_deep_sleep()) {
166157
TEST_ASSERT_MESSAGE(0, "Deepsleep should be disallowed.");
167158
return;
168159
}
169-
sem.acquire(); // Device reset expected.
160+
// Watchdog should fire before twice the timeout value.
161+
ThisThread::sleep_for(2 * TIMEOUT_MS); // Device reset expected.
170162
sleep_manager_unlock_deep_sleep();
171163

172-
// Watchdog reset should have occurred during sem.acquire() (sleep) above.
164+
// Watchdog reset should have occurred during the sleep above.
173165

174166
kick_wdg_during_test_teardown.release(); // For testsuite failure handling.
175167
TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected.");
@@ -187,22 +179,19 @@ void test_deepsleep_reset()
187179

188180
// Phase 1. -- run the test code.
189181
watchdog_config_t config = { TIMEOUT_MS };
190-
Semaphore sem(0, 1);
191-
LowPowerTimeout lp_timeout;
192182
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
193183
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
194184
return;
195185
}
196186
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
197187
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
198-
// Watchdog should fire before twice the timeout value.
199-
lp_timeout.attach_us(mbed::callback(release_sem, &sem), 1000ULL * (2 * TIMEOUT_MS));
200188
if (!sleep_manager_can_deep_sleep()) {
201189
TEST_ASSERT_MESSAGE(0, "Deepsleep should be allowed.");
202190
}
203-
sem.acquire(); // Device reset expected.
191+
// Watchdog should fire before twice the timeout value.
192+
ThisThread::sleep_for(2 * TIMEOUT_MS); // Device reset expected.
204193

205-
// Watchdog reset should have occurred during sem.acquire() (deepsleep) above.
194+
// Watchdog reset should have occurred during the deepsleep above.
206195

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

0 commit comments

Comments
 (0)