4 ms·
Maybe not "typical" unit tests, but Linux does have test cases for stuff like the generic library code (data compression, encryption, ECC, ...) in the shape of
by st_goliath 4y ago
Maybe not "typical" unit tests, but Linux does have test cases for stuff like the generic library code (data compression, encryption, ECC, ...) in the shape of special modules that, when built, run through their test cases during boot up.
It gets harder to test low-level driver code, but some subsystems have similar sets of tests, e.g. MTD has a set of tests for drivers & flash chips that they interact with. In 2016 I ported those tests to userspace as part of mtd-utils. The tests for the kernel crypto stuff I mentioned would also test hardware accelerators, if enabled.
Filesystems have the fstests project (formerly xfstests, as it was originally written when porting XFS to Linux), testing filesystem semantics and known bugs. There is something similar for the block layer (blktests). The downside being that those test suits take rather long to do a full run.
Those are just things that I can think of on top of my head, given the subsystems that I have interacted with in the past. Static analysis on the kernel code is also being done[1][2], there are also CI test farms[3][4], fuzzing farms[5], etc. As others have pointed out, there is a unit testing framework in the kernel[6], IIRC replacing an older framework and ad-hoc test code.
[1] https://www.kernel.org/doc/html/v4.15/dev-tools/coccinelle.html https://www.kernel.org/doc/html/v4.15/dev-tools/coccinelle.h...
[2] https://scan.coverity.com/projects/linux https://scan.coverity.com/projects/linux
[3] https://cki-project.org/ https://cki-project.org/
[4] https://bottest.wiki.kernel.org/ https://bottest.wiki.kernel.org/
[5] https://syzkaller.appspot.com/upstream https://syzkaller.appspot.com/upstream
[6] https://kernel.org/doc/html/latest/dev-tools/kunit https://kernel.org/doc/html/latest/dev-tools/kunit
- dshacker 4y agoI recently took a class on linux kernel development, and this is indeed correct, you can always expect when developing for the linux kernel to get your bugs from external sources. If your code has a bug or breaks something, you get a nice email from them telling you what errors you have.