mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			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.pull/12942/head
							parent
							
								
									029109a2f0
								
							
						
					
					
						commit
						25fad5d2a3
					
				| 
						 | 
				
			
			@ -52,6 +52,9 @@ Case cases[] = {
 | 
			
		|||
    Case("Zero delay (attach)", test_no_wait<AttachTester<LowPowerTimeout> >),
 | 
			
		||||
    Case("Zero delay (attach_us)", test_no_wait<AttachUSTester<LowPowerTimeout> >),
 | 
			
		||||
 | 
			
		||||
    Case("Reschedule in callback (attach)",  test_reschedule<AttachTester<LowPowerTimeout> >),
 | 
			
		||||
    Case("Reschedule in callback (attach_us)", test_reschedule<AttachUSTester<LowPowerTimeout> >),
 | 
			
		||||
 | 
			
		||||
    Case("10 ms delay accuracy (attach)", test_delay_accuracy<AttachTester<LowPowerTimeout>, 10000, SHORT_DELTA_US>,
 | 
			
		||||
         greentea_failure_handler),
 | 
			
		||||
    Case("10 ms delay accuracy (attach_us)", test_delay_accuracy<AttachUSTester<LowPowerTimeout>, 10000, SHORT_DELTA_US>,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -48,6 +48,9 @@ Case cases[] = {
 | 
			
		|||
    Case("Zero delay (attach)", test_no_wait<AttachTester<Timeout> >),
 | 
			
		||||
    Case("Zero delay (attach_us)", test_no_wait<AttachUSTester<Timeout> >),
 | 
			
		||||
 | 
			
		||||
    Case("Reschedule in callback (attach)",  test_reschedule<AttachTester<Timeout> >),
 | 
			
		||||
    Case("Reschedule in callback (attach_us)", test_reschedule<AttachUSTester<Timeout> >),
 | 
			
		||||
 | 
			
		||||
    Case("10 ms delay accuracy (attach)", test_delay_accuracy<AttachTester<Timeout>, 10000, SHORT_DELTA_US>,
 | 
			
		||||
         greentea_failure_handler),
 | 
			
		||||
    Case("10 ms delay accuracy (attach_us)", test_delay_accuracy<AttachUSTester<Timeout>, 10000, SHORT_DELTA_US>,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -363,6 +363,27 @@ private:
 | 
			
		|||
    TimeoutTesterType _timeout;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/** Template for tests: rescheduling
 | 
			
		||||
 *
 | 
			
		||||
 * Given a Timeout object
 | 
			
		||||
 * When a callback is attached with that reattaches itself, with @a attach()
 | 
			
		||||
 * Then the callback is called repeatedly
 | 
			
		||||
 *
 | 
			
		||||
 * Given a Timeout object
 | 
			
		||||
 * When a callback is attached with that reattaches itself, with @a attach_us()
 | 
			
		||||
 * Then the callback is called repeatedly
 | 
			
		||||
 */
 | 
			
		||||
template<typename T>
 | 
			
		||||
void test_reschedule(void)
 | 
			
		||||
{
 | 
			
		||||
    volatile uint32_t callback_count = 0;
 | 
			
		||||
    TimeoutDriftTester<T> timeout;
 | 
			
		||||
 | 
			
		||||
    timeout.reschedule_callback();
 | 
			
		||||
    ThisThread::sleep_for(TEST_DELAY_MS * 5);
 | 
			
		||||
    TEST_ASSERT(timeout.get_callback_count() >= 3);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** Template for tests: accuracy of timeout delay scheduled repeatedly
 | 
			
		||||
 *
 | 
			
		||||
 * Test time drift -- device part
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue