Skip to content

Commit eeab68d

Browse files
committed
tests-mbed_hal-common_tickers: Fix increment test case implementation
In case when base tick count is different than next tick count check first if the difference is equal to 1 tick (this is what we are looking for) if not then decrease the tick count. Repeat counting process few times before incrementing the number of cycles in case when base tick count is equal to next tick count.
1 parent 4ae6491 commit eeab68d

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

TESTS/mbed_hal/common_tickers/main.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,20 +344,34 @@ void ticker_increment_test(void)
344344
} else { // high frequency tickers
345345

346346
uint32_t num_of_cycles = NUM_OF_CYCLES;
347+
const uint32_t repeat_count = 20;
348+
const uint32_t max_inc_val = 100;
347349

348350
uint32_t base_tick_count = count_ticks(num_of_cycles, 1);
349351
uint32_t next_tick_count = base_tick_count;
350352
uint32_t inc_val = 0;
353+
uint32_t repeat_cnt = 0;
351354

352-
while (inc_val < 100) {
353-
355+
while (inc_val < max_inc_val) {
354356
next_tick_count = count_ticks(num_of_cycles + inc_val, 1);
355357

356358
if (next_tick_count == base_tick_count) {
357359

358-
/* Same tick count, so increase num of cycles. */
359-
inc_val++;
360+
/* Same tick count, so repeat 20 times and than
361+
* increase num of cycles by 1.
362+
*/
363+
if (repeat_cnt == repeat_count) {
364+
inc_val++;
365+
repeat_cnt = 0;
366+
}
367+
368+
repeat_cnt++;
360369
} else {
370+
/* Check if we got 1 tick diff. */
371+
if (next_tick_count - base_tick_count == 1 ||
372+
base_tick_count - next_tick_count == 1) {
373+
break;
374+
}
361375

362376
/* It is possible that the difference between base and next
363377
* tick count on some platforms is greater that 1, in this case we need
@@ -366,12 +380,8 @@ void ticker_increment_test(void)
366380
*/
367381
num_of_cycles /= 2;
368382
inc_val = 0;
383+
repeat_cnt = 0;
369384
base_tick_count = count_ticks(num_of_cycles, 1);
370-
371-
if (next_tick_count - base_tick_count == 1 ||
372-
base_tick_count - next_tick_count == 1) {
373-
break;
374-
}
375385
}
376386
}
377387

0 commit comments

Comments
 (0)