From 50a5e2c1f45c5afb2a05ffd2b3360161ef8f480e Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 21 May 2018 09:07:35 +0200 Subject: [PATCH] tests-mbed_hal-common_tickers: fix bug in ticker increment test case It is possible that the difference between base and next tick count on some platforms is greater than 1, in this case we need to repeat counting with the reduced number of cycles (for slower boards). If number of cycles has been reduced than base tick count needs to be redefined. This operation is missing and is added by this patch. --- TESTS/mbed_hal/common_tickers/main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/TESTS/mbed_hal/common_tickers/main.cpp b/TESTS/mbed_hal/common_tickers/main.cpp index ad8b758d21..2e8de40063 100644 --- a/TESTS/mbed_hal/common_tickers/main.cpp +++ b/TESTS/mbed_hal/common_tickers/main.cpp @@ -345,23 +345,28 @@ void ticker_increment_test(void) uint32_t num_of_cycles = NUM_OF_CYCLES; - const uint32_t base_tick_count = count_ticks(num_of_cycles, 1); + uint32_t base_tick_count = count_ticks(num_of_cycles, 1); uint32_t next_tick_count = base_tick_count; uint32_t inc_val = 0; while (inc_val < 100) { + next_tick_count = count_ticks(num_of_cycles + inc_val, 1); if (next_tick_count == base_tick_count) { + /* Same tick count, so increase num of cycles. */ inc_val++; } else { + /* It is possible that the difference between base and next * tick count on some platforms is greater that 1, in this case we need * to repeat counting with the reduced number of cycles (for slower boards). * In cases if difference is exactly 1 we can exit the loop. */ num_of_cycles /= 2; + inc_val = 0; + base_tick_count = count_ticks(num_of_cycles, 1); if (next_tick_count - base_tick_count == 1 || base_tick_count - next_tick_count == 1) {