The general layout of the tests:
The unittest itself generally follows the conventions:
#include "test_skel.h". For new system headers, try to add them here rather than copying to exact unittest (if possible). It might slow compilation down slightly, but makes the code easier to manage. Make sure it is included first.
assert()on everything to check return values.
sys_xxx()to access the syscall via LSS (compared to
xxx()which tends to come from the C library).
tempfile.XXXXXXfor templates with helpers like
mkstemp. Try to clean them up when you‘re done with them. These will be created in the cwd, but that’s fine.
Feel free to extend test_skel.h with more helpers if they're useful to more than one test.
If you're looking for a simple example, start with unlink.c. You should be able to copy this over and replace the content of
make. This will compile & execute all the tests on your local system. A standard
make clean will clean up all the objects.
If you need to debug something, then the programs are simply named
xxx_test and can easily be thrown into
We have rudimentary cross-compile testing via gcc and clang. Try running
make cross -- for any toolchains you don't have available, it should skip things automatically. This only verifies the compilation & linking stages though.
The cross-compilers can be created using http://crosstool-ng.github.io/.