Kernel Testing Skill
This skill allows you to run unit and integration tests for the kernel, verifying functionality on QEMU.
1. Running Tests
To run the kernel test suite:
bash
chmod +x run-test.sh ./run-test.sh
2. How it Works
- •Compilation: The kernel is compiled in
testmode, which includes thecustom_test_frameworksharness and atest_mainentry point. - •UEFI Boot: The test kernel is packaged into a UEFI bootable image, similar to the main OS.
- •QEMU Execution: The scripts launches QEMU with a special
isa-debug-exitdevice. - •Reporting:
- •Tests results are printed to the Serial Port.
- •Pass: QEMU exits with status
33((0x10 << 1) | 1). - •Fail/Panic: QEMU exits with status
35((0x11 << 1) | 1). - •The
run-test.shscript captures this exit code and reportsPASSorFAIL.
3. Adding New Tests
Add #[test_case] to any function in the kernel to register it as a test.
rust
#[cfg(test)]
#[test_case]
fn trivial_assertion() {
assert_eq!(1, 1);
}
4. Troubleshooting
- •If QEMU hangs, check if the
isa-debug-exitdevice is correctly configured inrun-test.sh. - •Ensure
test_main()is conditionally called in_startinsidekernel/src/main.rs.