Reputation: 8582
I'm interested in mocking functions and global variables in order to unit test a kernel module.
Initially tried with https://github.com/ThrowTheSwitch/CMock but ran into issues. Any articles links on how to do this would also be great. (for kernel modules). To give more details here: compiling as a kernel module would error because stdio wouldn't be available, compiling for user space would error because it wouldn't find stuff like printk.
Ideally I would have either a user level executable or a kernel module that would run unit test on my functions. The parts I am having trouble with is mocking global dependencies like structs that the functions rely on in order to write a decent test.
I've gone through a few questions and articles about this but haven't found an answer, or a definitive reason on why this wouldn't be possible.
Upvotes: 11
Views: 3104
Reputation: 10947
I would proceed as follows:
/dev/
(where you can define proper ioctls);/proc/
(discouraged);/sys/
Upvotes: 7