A kernel unit-testing framework
A kernel unit-testing framework
Posted Mar 2, 2019 8:26 UTC (Sat) by gps (subscriber, #45638)Parent article: A kernel unit-testing framework
I preached the need for user space unittesting without booting a system to kernel teams last decade. Too much community fear. No takers. I moved on.
Accept this concept. Get it in. Reject all future proposed kernel patches without small test coverage for their logic. Build meaningful frameworks within it for mock devices, mock and fuzzy event sequences, galore. Bug fixes could come with regression tests! *Gasp*
Leave the basement. Become a real world software project. Be proud of your work instead of lying to everybody that you just don't write bugs despite repeated evidence to the contrary as documented in CVEs. Write tests, you'll earn respect!
Posted Mar 4, 2019 1:12 UTC (Mon)
by shemminger (subscriber, #5739)
[Link] (18 responses)
Posted Mar 4, 2019 2:51 UTC (Mon)
by Cyberax (✭ supporter ✭, #52523)
[Link] (14 responses)
This is admittedly less useful than testing with physical devices, but it still is useful.
Posted Mar 4, 2019 4:51 UTC (Mon)
by Cyberax (✭ supporter ✭, #52523)
[Link] (7 responses)
Posted Mar 4, 2019 12:46 UTC (Mon)
by geert (subscriber, #98403)
[Link] (1 responses)
Perhaps we need a kernel commandline option to enable that at the generic dmaengine level?
Posted Mar 4, 2019 20:11 UTC (Mon)
by dezgeg (subscriber, #92243)
[Link]
I once had a similar idea for injecting failures into USB transmissions (inspired a kernel crash in the USB hub code which would occur if he device was unplugged at a precise moment) but sadly, didn't implement it.
Posted Mar 4, 2019 17:04 UTC (Mon)
by gps (subscriber, #45638)
[Link]
Posted Mar 4, 2019 19:48 UTC (Mon)
by roc (subscriber, #30627)
[Link] (3 responses)
Posted Mar 5, 2019 14:14 UTC (Tue)
by pm215 (subscriber, #98099)
[Link] (2 responses)
Posted Mar 5, 2019 19:08 UTC (Tue)
by roc (subscriber, #30627)
[Link] (1 responses)
The "right conditions" include the software living long enough for tests written today to pay off in the future, and bugs in deployed releases being costly because you have a lot of users or your software does important things or bugs found in the field are difficult to debug remotely.
Ironically the work I'm doing on improving debugging makes writing good tests slightly less important!
Tests are never perfect. I can see that device models diverging from hardware would be a problem. But it also seems to me that you could engineer around some of the problems, e.g. have a testing framework that *by default* tests for multiple instances of each hardware element, hotplugging of each hardware element, randomization of interrupt delays, etc.
Posted Mar 9, 2019 1:14 UTC (Sat)
by nix (subscriber, #2304)
[Link]
Linux would probably have terrible threading despite NPTL if Uli hadn't written a massive heap of tests for NPTL at the same time to make sure that the damn thing actually worked and did not regress. More than one bug I've looked at in the past which came down to one missed assembler instruction that triggered problems only in ludicrously obscure slowpath cases was tickled by one or more of those tests...
Posted Mar 4, 2019 19:23 UTC (Mon)
by pbonzini (subscriber, #60935)
[Link] (4 responses)
Posted Mar 4, 2019 19:32 UTC (Mon)
by Cyberax (✭ supporter ✭, #52523)
[Link] (3 responses)
However lots of other devices most definitely can be simulated.
Simulation also doesn't have to be perfect to be useful. Just something good enough will suffice.
Posted Mar 4, 2019 21:13 UTC (Mon)
by pizza (subscriber, #46)
[Link]
"All models are wrong. Some are useful."
But the "useful" threshold varies widely depending on what you're trying to accomplish.
The majority of my headaches with respect to device drivers was due to the hardware not working the way it was documented. Spurious interrupts, clock phasing, interactions/collisions with shared resources, subtle sleep/wake sequencing issues, sensitivity to environmental conditions (eg clocks drifting between -40C -> 85C), dma peripheral quirks, workarounds for things fixed in later revisions.. and so forth.
Granted, I also had plenty of headaches due to the upper stacks not behaving as specified either. Or perhaps I should say significantly underspecified -- While it was actually well-tested (unit and system-level) the tests were written from the same incorrect/incomplete set of spherical-cow specifications/assumptions.
Posted Mar 4, 2019 22:51 UTC (Mon)
by pbonzini (subscriber, #60935)
[Link] (1 responses)
USB would only be practical if you also emulated all the broken devices around to ensure they don't regress. Same for the "generic" drivers like AHCI or SDHCI.
Some mock devices are there, for example scsi_debug, the tests are in user space rather than kernel.
Posted Mar 14, 2019 3:22 UTC (Thu)
by Cyberax (✭ supporter ✭, #52523)
[Link]
Posted Mar 5, 2019 15:49 UTC (Tue)
by shemminger (subscriber, #5739)
[Link]
Posted Mar 5, 2019 8:58 UTC (Tue)
by knuto (subscriber, #96401)
[Link]
We're in the process of making patch set of KTF suitable for inclusion in the kernel, while keeping the features we have in place to have one test code base applied to multiple kernel versions, an important need for anyone trying to maintain stable kernels for production use in addition to bleeding edge.
Posted Mar 8, 2019 22:17 UTC (Fri)
by flussence (guest, #85566)
[Link] (1 responses)
Filesystems don't need specific hardware either. Wouldn't it be nice if Btrfs had RAID5/6 regression tests?
Posted Mar 8, 2019 23:25 UTC (Fri)
by dezgeg (subscriber, #92243)
[Link]
A kernel unit-testing framework
A kernel unit-testing framework
A kernel unit-testing framework
A kernel unit-testing framework
A kernel unit-testing framework
A kernel unit-testing framework
A kernel unit-testing framework
A kernel unit-testing framework
A kernel unit-testing framework
A kernel unit-testing framework
Spending double the development effort to have reasonable (not perfect) automated tests isn't outrageous. It's in the right ballpark for projects I've worked on like Firefox and rr. Under the right conditions that spend pays for itself pretty easily.
In glibc, which is very much following the 'everything should have tests dammit' policy (and long has), the tradeoff is sometimes much higher: it can easily take five times longer to write a decent test for some bugfixes than to fix the bug, even (sometimes especially!) when the bug is a real monster to find.
A kernel unit-testing framework
A kernel unit-testing framework
A kernel unit-testing framework
A kernel unit-testing framework
A kernel unit-testing framework
A kernel unit-testing framework
A kernel unit-testing framework
A kernel unit-testing framework
A kernel unit-testing framework
