Controlling time for integration testing?

For specific integration testing, I’d like to be able to control the functions that FreeRTOS uses for timing. For example, I’d like to be able to speed time up by 10x (or any arbitrary number) so that tests can run faster than real time.

I’m running on an ARM Cortex-M0+ (an ATSAML22). I’ve not tried it, but I think upping the frequency on SYSTICK (for main system ticks) and TC0 (for wake timer in tickless mode) would maybe do the right thing, but I’m fuzzy on the relationship between the two.

Update: As I read through tasks.c and the port-specific read_wake_timer() function, it looks like I can get away with only changing TC0’s rate, since that will bump xTickCount whenever the system comes back from a sleep.

Is there a preferred FreeRTOS idiom for doing this sort of thing?

The tickless parameters are configurable. But yes, you can speed up things by not really sleeping, or sleeping 1/10th of what is required.

It occurred to me that I can modify the sleep code so it doesn’t actually sleep at all, but simply advances the tick counter by the amount that it was told to sleep, in other words, to run as fast as possible while maintaining virtual time. I’ll give that a try and see what happens…

That’s a great strategy. Please note there is a minor issue with stepping the tick by the expected idle time, as noted in PR #73 in the kernel.

1 Like