KVM-unit-tests: Difference between revisions
Line 16: | Line 16: | ||
<br>Here are a few examples of building and running tests | <br>Here are a few examples of building and running tests | ||
:: Run all tests on the current host | :: Run all tests on the current host | ||
<pre> | |||
$ git clone git://git.kernel.org/pub/scm/virt/kvm/kvm-unit-tests.git | $ git clone git://git.kernel.org/pub/scm/virt/kvm/kvm-unit-tests.git | ||
$ cd kvm-unit-tests/ | $ cd kvm-unit-tests/ | ||
Line 22: | Line 22: | ||
$ make | $ make | ||
$ ./run_tests.sh | $ ./run_tests.sh | ||
</pre | </pre> | ||
:: Cross-compile and run with a specific QEMU | :: Cross-compile and run with a specific QEMU | ||
<pre> | |||
$ ./configure --arch=arm64 --cross-prefix=aarch64-linux-gnu- | $ ./configure --arch=arm64 --cross-prefix=aarch64-linux-gnu- | ||
$ make | $ make | ||
$ export QEMU=/path/to/qemu-system-aarch64 | $ export QEMU=/path/to/qemu-system-aarch64 | ||
$ ./run_tests.sh | $ ./run_tests.sh | ||
</pre | </pre> | ||
:: Run a single test, passing additional QEMU command line options | :: Run a single test, passing additional QEMU command line options | ||
<pre> | |||
$ ./arm-run arm/selftest.flat -smp 4 -append smp | $ ./arm-run arm/selftest.flat -smp 4 -append smp | ||
</pre | </pre> | ||
Note: run_tests.sh runs each test in $TEST_DIR/unittests.cfg<br> | Note: run_tests.sh runs each test in $TEST_DIR/unittests.cfg<br> |
Revision as of 11:16, 11 September 2015
kvm-unit-tests
git://git.kernel.org/pub/scm/virt/kvm/kvm-unit-tests.git
Introduction
kvm-unit-tests is a project as old as KVM. As its name suggests, it's purpose is to provide unit tests for KVM. The unit tests are tiny guest operating systems that generally execute only tens of lines of C and assembler test code in order to obtain its PASS/FAIL result. Unit tests provide KVM and virt hardware functional testing by targeting the features through minimal implementations of their use per the hardware specification. The simplicity of unit tests make them easy to verify they are correct, easy to maintain, and easy to use in timing measurements. Unit tests are also often used for quick and dirty bug reproducers. The reproducers may then be kept as regression tests. It's strongly encouraged that patches implementing new KVM features are submitted with accompanying unit tests.
While a single unit test is focused on a single feature, all unit tests share the minimal system initialization and setup code. There are also several functions shared across all unit tests, comprising a unit test API. The setup code and API implementation make up the kvm-unit-tests framework, which is briefly described in the next section. We then describe testdevs, which are extensions to KVM's userspace that provide special support for unit tests, in the "Testdevs" section. Section "API" lists the subsystems, e.g. MMU, SMP, that the API covers, along with a few descriptions of what the API supports. It specifically avoids listing any actual function declarations though, as those may change (use the source Luke!). The section "Running the tests" gives all the details necessary to build and run tests, and the final section "Adding a test" provides an example of adding a test.
Framework
Testdevs
API
Running the tests
Here are a few examples of building and running tests
- Run all tests on the current host
$ git clone git://git.kernel.org/pub/scm/virt/kvm/kvm-unit-tests.git $ cd kvm-unit-tests/ $ ./configure $ make $ ./run_tests.sh
- Cross-compile and run with a specific QEMU
$ ./configure --arch=arm64 --cross-prefix=aarch64-linux-gnu- $ make $ export QEMU=/path/to/qemu-system-aarch64 $ ./run_tests.sh
- Run a single test, passing additional QEMU command line options
$ ./arm-run arm/selftest.flat -smp 4 -append smp
Note: run_tests.sh runs each test in $TEST_DIR/unittests.cfg
TEST_DIR, along with some other variables, is defined in config.mak after running configure