Skip to content

Commit 25fad5d

Browse files
committed
Add Timeout rescheduling test
The `Timeout` drift test uses rescheduling inside a callback, but it is currently disabled due to lack of stability. Rescheduling using relative timeouts inside the callback is a bad technique as it leads to drift, so I understand the test being disabled. It is better to use `Ticker` for a periodic callback or to use `Timeout::attach_absolute`. Add a simpler test that just ensures the callback is called repeatedly - this test would detect issue #12940, and should not have stability problems.
1 parent 029109a commit 25fad5d

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

TESTS/mbed_drivers/lp_timeout/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ Case cases[] = {
5252
Case("Zero delay (attach)", test_no_wait<AttachTester<LowPowerTimeout> >),
5353
Case("Zero delay (attach_us)", test_no_wait<AttachUSTester<LowPowerTimeout> >),
5454

55+
Case("Reschedule in callback (attach)", test_reschedule<AttachTester<LowPowerTimeout> >),
56+
Case("Reschedule in callback (attach_us)", test_reschedule<AttachUSTester<LowPowerTimeout> >),
57+
5558
Case("10 ms delay accuracy (attach)", test_delay_accuracy<AttachTester<LowPowerTimeout>, 10000, SHORT_DELTA_US>,
5659
greentea_failure_handler),
5760
Case("10 ms delay accuracy (attach_us)", test_delay_accuracy<AttachUSTester<LowPowerTimeout>, 10000, SHORT_DELTA_US>,

TESTS/mbed_drivers/timeout/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ Case cases[] = {
4848
Case("Zero delay (attach)", test_no_wait<AttachTester<Timeout> >),
4949
Case("Zero delay (attach_us)", test_no_wait<AttachUSTester<Timeout> >),
5050

51+
Case("Reschedule in callback (attach)", test_reschedule<AttachTester<Timeout> >),
52+
Case("Reschedule in callback (attach_us)", test_reschedule<AttachUSTester<Timeout> >),
53+
5154
Case("10 ms delay accuracy (attach)", test_delay_accuracy<AttachTester<Timeout>, 10000, SHORT_DELTA_US>,
5255
greentea_failure_handler),
5356
Case("10 ms delay accuracy (attach_us)", test_delay_accuracy<AttachUSTester<Timeout>, 10000, SHORT_DELTA_US>,

TESTS/mbed_drivers/timeout/timeout_tests.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,27 @@ class TimeoutDriftTester {
363363
TimeoutTesterType _timeout;
364364
};
365365

366+
/** Template for tests: rescheduling
367+
*
368+
* Given a Timeout object
369+
* When a callback is attached with that reattaches itself, with @a attach()
370+
* Then the callback is called repeatedly
371+
*
372+
* Given a Timeout object
373+
* When a callback is attached with that reattaches itself, with @a attach_us()
374+
* Then the callback is called repeatedly
375+
*/
376+
template<typename T>
377+
void test_reschedule(void)
378+
{
379+
volatile uint32_t callback_count = 0;
380+
TimeoutDriftTester<T> timeout;
381+
382+
timeout.reschedule_callback();
383+
ThisThread::sleep_for(TEST_DELAY_MS * 5);
384+
TEST_ASSERT(timeout.get_callback_count() >= 3);
385+
}
386+
366387
/** Template for tests: accuracy of timeout delay scheduled repeatedly
367388
*
368389
* Test time drift -- device part

0 commit comments

Comments
 (0)