Skip to content

Commit ad0b115

Browse files
committed
Prevent use of deleted ticker in Ticker test
In test_case_2x_callbacks two tickers are setup to repeatedly reschedule each other. When these tickers are deleted this rescheduling is still occurring and can lead to a deleted ticker being scheduled. When this happens the following error message is displayed: Thread 0x0 error -6: Not allowed in ISR context Note - this problem was not detected by CI since the test reported the correct results back to the host test and only experienced this error on tear down. This problem can be reproduced on an nrf51 by first building the ticker test with: "mbed test -t GCC_ARM -m NRF51_DK -n tests-mbed_drivers-ticker --compile -DMBED_TRAP_ERRORS_ENABLED=1 -DMBED_HEAP_STATS_ENABLED=1 -DMBED_STACK_STATS_ENABLED=1" And then running testing with: "mbed test -t GCC_ARM -m NRF51_DK -n tests-mbed_drivers-ticker --run"
1 parent 373e6ab commit ad0b115

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

TESTS/mbed_drivers/ticker/main.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ static const int total_ticks = 10;
4444
DigitalOut led1(LED1);
4545
DigitalOut led2(LED2);
4646

47-
Ticker *ticker1;
48-
Ticker *ticker2;
47+
Ticker *volatile ticker1;
48+
Ticker *volatile ticker2;
4949

5050
volatile int ticker_count = 0;
5151
volatile bool print_tick = false;
@@ -67,15 +67,21 @@ void ticker_callback_2_led(void) {
6767

6868
void ticker_callback_1_switch_to_2(void) {
6969
++callback_trigger_count;
70-
ticker1->detach();
71-
ticker1->attach_us(ticker_callback_2_switch_to_1, ONE_MILLI_SEC);
70+
// If ticker is NULL then it is being or has been deleted
71+
if (ticker1) {
72+
ticker1->detach();
73+
ticker1->attach_us(ticker_callback_2_switch_to_1, ONE_MILLI_SEC);
74+
}
7275
ticker_callback_1_led();
7376
}
7477

7578
void ticker_callback_2_switch_to_1(void) {
7679
++callback_trigger_count;
77-
ticker2->detach();
78-
ticker2->attach_us(ticker_callback_1_switch_to_2, ONE_MILLI_SEC);
80+
// If ticker is NULL then it is being or has been deleted
81+
if (ticker2) {
82+
ticker2->detach();
83+
ticker2->attach_us(ticker_callback_1_switch_to_2, ONE_MILLI_SEC);
84+
}
7985
ticker_callback_2_led();
8086
}
8187

@@ -159,13 +165,19 @@ utest::v1::status_t two_ticker_case_setup_handler_t(const Case *const source, co
159165
}
160166

161167
utest::v1::status_t one_ticker_case_teardown_handler_t(const Case *const source, const size_t passed, const size_t failed, const failure_t reason) {
162-
delete ticker1;
168+
Ticker *temp1 = ticker1;
169+
ticker1 = NULL;
170+
delete temp1;
163171
return greentea_case_teardown_handler(source, passed, failed, reason);
164172
}
165173

166174
utest::v1::status_t two_ticker_case_teardown_handler_t(const Case *const source, const size_t passed, const size_t failed, const failure_t reason) {
167-
delete ticker1;
168-
delete ticker2;
175+
Ticker *temp1 = ticker1;
176+
Ticker *temp2 = ticker2;
177+
ticker1 = NULL;
178+
ticker2 = NULL;
179+
delete temp1;
180+
delete temp2;
169181
return greentea_case_teardown_handler(source, passed, failed, reason);
170182
}
171183

0 commit comments

Comments
 (0)