title: Testing a kernel module
body: <p>I'm interested in mocking functions and global variables in order to unit test a kernel module.</p>
  
  <p>Initially tried with <a href="https://github.com/ThrowTheSwitch/CMock" rel="nofollow noreferrer">https://github.com/ThrowTheSwitch/CMock</a> 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.</p>
  
  <p>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.</p>
  
  <p>I've gone through a few <a href="http://comments.gmane.org/gmane.linux.kernel.kernelnewbies/49915" rel="nofollow noreferrer">questions</a> and <a href="https://meekrosoft.wordpress.com/2009/11/09/unit-testing-c-code-with-the-googletest-framework/" rel="nofollow noreferrer">articles</a> <a href="https://stackoverflow.com/questions/3177338/how-is-linux-kernel-tested/30367968">about</a> <a href="https://stackoverflow.com/questions/33551498/is-it-feasible-to-unit-test-kernel-module-code">this</a> but haven't found an answer, or a definitive reason on why this wouldn't be possible.</p>