Petr Šabata f5bf49
=====================
Petr Šabata f5bf49
Kexec Kdump Self-test
Petr Šabata f5bf49
=====================
Petr Šabata f5bf49
Petr Šabata f5bf49
Petr Šabata f5bf49
Introduction
Petr Šabata f5bf49
============
Petr Šabata f5bf49
The self-tests here are useful for quick sanity tests for new patches, and also helpful for debugging issues.
Petr Šabata f5bf49
Petr Šabata f5bf49
Petr Šabata f5bf49
How it works
Petr Šabata f5bf49
============
Petr Šabata f5bf49
All tests are run within VMs using qemu. By default, VM images are based on Fedora Cloud image, and the image for each test run is a layered qcow2 snapshot on top of the base image.
Petr Šabata f5bf49
Test images are managed by Makefile, so if there are any code change in the kexec-tools repository, `make` command will detect that and only rebuild the top image layer. This makes the test runs boot fast and each test run is clean.
Petr Šabata f5bf49
Petr Šabata f5bf49
Petr Šabata f5bf49
Basic usage
Petr Šabata f5bf49
===========
Petr Šabata f5bf49
Before you start, you can make the self-tests use your own base image by running following command:
Petr Šabata f5bf49
Petr Šabata f5bf49
`make clean && make BASE_IMAGE=<path/to/your/image>`
Petr Šabata f5bf49
Petr Šabata f5bf49
This is helpful if you have a slow network, else self-test will try to download the cloud image from Fedora's official website using `wget`.
Petr Šabata f5bf49
Petr Šabata f5bf49
- Use the following command to run all tests:
Petr Šabata f5bf49
  $ make test-run
Petr Šabata f5bf49
Petr Šabata f5bf49
  All available tests will be executed.
Petr Šabata f5bf49
Petr Šabata f5bf49
  Test artifacts are stored in output/<testcase>
Petr Šabata f5bf49
Petr Šabata f5bf49
- For easier debugging, you can run only on test with the following command:
Petr Šabata f5bf49
  $ make TEST_CASE=<testcase> test-run
Petr Šabata f5bf49
Petr Šabata f5bf49
  This way, VM's console is directly connected to stdin/out so debugging will be easier.
Petr Šabata f5bf49
  If there are multiple VMs used in a test case, the VM performing actual kdump/kexec operation will be connected to stdin/out.
Petr Šabata f5bf49
Petr Šabata f5bf49
Test Cases
Petr Šabata f5bf49
==========
Petr Šabata f5bf49
Each test case is a folder under scripts/testcases/, a test case folder will contain at least one executable shell script, and each script should contain two functions: "on_build" and "on_test".
Petr Šabata f5bf49
Petr Šabata f5bf49
"on_build" is called when building the test image, which can instruct the self-test framework to install packages or create files, etc.
Petr Šabata f5bf49
"on_test" is called when VM finished booting, which can get the boot count by calling "get_test_boot_count" and determine what to do. It should call "test_passed" on success, and call "test_failed" on failure. "test_aborted" is called when unexpected behavior occurs.
Petr Šabata f5bf49
Petr Šabata f5bf49
When there are multiple scripts in a single test case folder, they will spawn VMs in lexical order, and the last VM is considered the VM performing the actual test. Other VMs could be hosting test required service. This is useful for the network dump test. However, "test_passed" or "test_failed" or "test_aborted" could be called in any of these VMs, so during network kdump test, the dump target can also terminate the test and mark it passed when a valid vmcore is detected.
Petr Šabata f5bf49
Petr Šabata f5bf49
Petr Šabata f5bf49
Debugging
Petr Šabata f5bf49
=========
Petr Šabata f5bf49
Petr Šabata f5bf49
- When the test VM boots, you can append "no_test" to kernel args in grub, which tells the test services to quit early.
Petr Šabata f5bf49
Petr Šabata f5bf49
- You can launch the VMs manually or inspect the image after ran a test.
Petr Šabata f5bf49
Petr Šabata f5bf49
  Test images are located as:
Petr Šabata f5bf49
Petr Šabata f5bf49
    output/<testcase>/<vm-name>.img
Petr Šabata f5bf49
Petr Šabata f5bf49
  Test images' corresponding qemu command are located as:
Petr Šabata f5bf49
Petr Šabata f5bf49
    output/<testcase>/<vm-name>.qemu_cmd
Petr Šabata f5bf49
Petr Šabata f5bf49
  To repeat/debug a test manually, you should launch all VMs in output/<testcase> menu in lexical order, and append 'no_test' in the last VM's grub cmdline, then VM will hang on login prompt, login with root/fedora. Test script is located as /kexec-kdump-test/test.sh
Petr Šabata f5bf49
Petr Šabata f5bf49
- If you just want to inspect the images file content, you can also use scripts/spawn-image-shell.sh <test-image> to spawn a shell in the image quickly.