Re: Mocking with ztest


Jan Van Winkel <jan.van_winkel@...>
 

Hi Kim,

I bumped into the similar issue and the solution was to use ztest together with the native_posix target to implement my unit tests.

Also see following issue on github:

Best Regards,
Jan

On Thu, Apr 11, 2019 at 1:23 PM Kim Bøndergaard <kim.bondergaard@...> wrote:
Hi Zephyr developers

I'm looking at ztest as a means to test our application code.
I've managed to command sanytycheck to run at our 'out of tree' projects. That's all fine.

Next issue is mocking. Fx. to make some accelerated tests or to test some special corner case scenarios I need to force timers to expire.
I have successfully added a 'timer wrapper' which by default (for target app builds) calls the k_timer_xxx functions while in ztest builds I implement special mock functions so I can e.g. catch the struct k_timer object or the expiry callback. They are typically static within the MUT (Module Under Test).
I don't like though that application developers have to call none-zephyr functions.
I furthermore fear we will end up mocking also lots of other interfaces - even though it might be as simple as 'unconfig'ing them. But that seems not possible with the kernel.

I'm also looking a bit into the K_SYSCALL_DECLARE* macros? Can they somehow solve my problem? But e.g k_timer_init() is not defined by such macro?

Anyone having any input to this problem?

Join {devel@lists.zephyrproject.org to automatically receive all group messages.