Hi all,
For a while now, we’ve been unit testing individual pieces of our kernel extension by cross-compiling them as a standard user-space application and performing our tests there. Over time, as we have increased our code coverage of the unit tests, we’re noticing a pretty strong upward trend of the number of compiler conditionals required to support cross-compiling between a kext and a user-space app. For example:
#include <stdio.h> // for snprintf #include <libkern/libkern.h> // for snprintf
and
str = (char*) malloc(sz); str = (char*) OSMalloc(sz, gOSMallocTag);
(There are some more ugly examples, but I’m betting you can imagine how bad it can get at times)
Suffice it to say, we’re wondering if there’s a better way. Ideally, we would like to unit test the code that’s actually running in production. These compiler-level conditionals force us to essentially maintain two versions of our code. Worse than that, the unit tested version is not the production version.
Off the top of my head, I wonder if it would be sane to build the unit tests as a kext and run them as such, which would allow us to have only one version of our code. However, that sounds a bit like a sledgehammer. Before I go down that road myself, I figured I’d ask around.
How do various people here unit test their kexts?
Thanks, - Andrew Keller
|