nixos-uki/tests
2025-12-25 15:09:12 +00:00
..
README.md Automated testing (not working yet) 2025-12-25 15:09:12 +00:00

UEFI Rescue System Test Suite

Overview

The test suite verifies that UEFI rescue system images build correctly and boot successfully in QEMU.

Running Tests

From the repository root:

./run-tests.sh

This will:

  1. Build the minimal UKI image
  2. Boot it in QEMU
  3. Monitor the serial console for successful autologin
  4. Stop QEMU once the test passes
  5. Timeout after 120 seconds if boot fails

How It Works

The test script (run-tests.sh) is a simple bash script that:

  1. Builds the minimal image with nix build .#minimal
  2. Starts test-boot.sh in the background with output redirected to a log file
  3. Loops every second, grepping the log file for the success pattern ^\[root@
  4. If found: kills QEMU and reports success
  5. If timeout (120s) reached: shows the last 50 lines and exits with failure
  6. If QEMU crashes: shows the full log and exits with failure

This approach is simple, provides immediate output, and doesn't require complex Nix builds for testing.

Current Tests

minimal-boot

Verifies that the minimal rescue image:

  • Builds successfully
  • Boots in QEMU
  • Auto-login works (checks for [root@nixos-rescue:~]# prompt)

Adding New Tests

To add a new test, edit run-tests.sh and add a new test section:

# Test 2: Your new test
echo "Test: your-test-name"
echo "  Building your image..."
nix build .#your-image --no-link

# ... test logic similar to minimal-boot ...

Future Test Ideas

  • fat-boot: Test the KDE fat image boots
  • ssh-service: Verify SSH service starts (check for "Started OpenSSH" in logs)
  • network-dhcp: Check that network configuration works
  • disk-tools: Verify rescue tools are available in the booted system
  • nix-commands: Test that Nix commands work (nix-env, nix-shell)

Debugging Failed Tests

  1. Check the output: The test script shows output in real-time
  2. Boot manually: ./test-boot.sh ./result to see what's happening interactively
  3. Use graphical mode: ./test-boot.sh --graphical ./result to see VGA output
  4. Increase timeout: Edit TIMEOUT=120 in run-tests.sh if the system is slow
  5. Check the pattern: Make sure the grep pattern matches what you expect

Tips

  • The script runs in the repository directory, so paths are relative
  • QEMU process is automatically killed on script exit (via trap)
  • Serial console output is captured to a temporary file
  • Use grep -E syntax for the success pattern (extended regex)