|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | - | - |
| arm/ | H | 02-May-2025 | - | 7,582 | 5,525 |
| ci/ | H | 02-May-2025 | - | 167 | 161 |
| common/ | H | 02-May-2025 | - | 168 | 121 |
| docs/ | H | 02-May-2025 | - | 102 | 77 |
| lib/ | H | 02-May-2025 | - | 42,138 | 28,823 |
| powerpc/ | H | 02-May-2025 | - | 4,576 | 3,383 |
| riscv/ | H | 02-May-2025 | - | 4,770 | 3,670 |
| s390x/ | H | 02-May-2025 | - | 13,269 | 9,276 |
| scripts/ | H | 04-May-2025 | - | 14,293 | 11,050 |
| x86/ | H | 02-May-2025 | - | 36,598 | 27,422 |
| .editorconfig | H A D | 02-May-2025 | 438 | 19 | 15 |
| .gitignore | H A D | 02-May-2025 | 373 | 36 | 35 |
| .gitlab-ci.yml | H A D | 02-May-2025 | 14.2 KiB | 571 | 529 |
| .shellcheckrc | H A D | 02-May-2025 | 1.2 KiB | 31 | 26 |
| .travis.yml | H A D | 02-May-2025 | 1.2 KiB | 46 | 40 |
| COPYRIGHT | H A D | 02-May-2025 | 529 | 11 | 8 |
| LICENSE | H A D | 02-May-2025 | 17.7 KiB | 340 | 281 |
| MAINTAINERS | H A D | 02-May-2025 | 3.8 KiB | 123 | 108 |
| Makefile | H A D | 02-May-2025 | 4.7 KiB | 159 | 110 |
| README | H A D | 02-May-2025 | 6.8 KiB | 221 | 147 |
| README.macOS.md | H A D | 02-May-2025 | 2.1 KiB | 81 | 65 |
| README.md | H A D | 02-May-2025 | 6.8 KiB | 221 | 147 |
| configure | H A D | 02-May-2025 | 14.7 KiB | 557 | 500 |
| errata.txt | H A D | 02-May-2025 | 826 | 10 | 9 |
| run_tests.sh | H A D | 02-May-2025 | 4.9 KiB | 203 | 170 |
README
1# Welcome to kvm-unit-tests
2
3See http://www.linux-kvm.org/page/KVM-unit-tests for a high-level
4description of this project, as well as running tests and adding
5tests HOWTOs.
6
7# Building the tests
8
9This directory contains sources for a KVM test suite.
10
11To create the test images do:
12
13 ./configure
14 make
15
16in this directory. Test images are created in ./ARCH/\*.flat
17
18NOTE: GCC cross-compiler is required for [build on macOS](README.macOS.md).
19
20## Cross-compiling
21
22A cross compiler may be configured by specifying a cross prefix. For example,
23for arm64
24
25 ./configure --arch=arm64 --cross-prefix=aarch64-linux-gnu-
26 make
27
28## clang
29
30clang may be used as an alternative to gcc.
31
32 ./configure --cc=clang
33 make
34
35clang may also be used with cross binutils when cross-compiling. For example,
36for riscv64
37
38 ./configure --arch=riscv64 --cc=clang --cflags='--target=riscv64' \
39 --cross-prefix=riscv64-linux-gnu-
40 make
41
42## Standalone tests
43
44The tests can be built as standalone. To create and use standalone tests do:
45
46 ./configure
47 make standalone
48 (send tests/some-test somewhere)
49 (go to somewhere)
50 ./some-test
51
52`make install` will install all tests in PREFIX/share/kvm-unit-tests/tests,
53each as a standalone test.
54
55
56# Running the tests
57
58Then use the runner script to detect the correct invocation and
59invoke the test:
60
61 ./x86-run ./x86/msr.flat
62or:
63
64 ./run_tests.sh
65
66to run them all.
67
68By default the runner script searches for a suitable QEMU binary in the system.
69To select a specific QEMU binary though, specify the QEMU=path/to/binary
70environment variable:
71
72 QEMU=/tmp/qemu/x86_64-softmmu/qemu-system-x86_64 ./x86-run ./x86/msr.flat
73
74To select an accelerator, for example "kvm", "hvf" or "tcg", specify the
75ACCEL=name environment variable:
76
77 ACCEL=kvm ./x86-run ./x86/msr.flat
78
79For running tests that involve migration from one QEMU instance to another
80you also need to have the "ncat" binary (from the nmap.org project) installed,
81otherwise the related tests will be skipped.
82
83## Running the tests with UEFI
84
85Check [x86/efi/README.md](./x86/efi/README.md).
86
87# Tests configuration file
88
89The test case may need specific runtime configurations, for
90example, extra QEMU parameters and time to execute limited, the
91runner script reads those information from a configuration file found
92at ./ARCH/unittests.cfg.
93
94The configuration file also contain the groups (if any) each test belong
95to. So that a given group can be executed by specifying its name in the
96runner's -g option.
97
98# Unit test inputs
99
100Unit tests use QEMU's '-append args...' parameter for command line
101inputs, i.e. all args will be available as argv strings in main().
102Additionally a file of the form
103
104 KEY=VAL
105 KEY2=VAL
106 ...
107
108may be passed with '-initrd file' to become the unit test's environ,
109which can then be accessed in the usual ways, e.g. VAL = getenv("KEY").
110Any key=val strings can be passed, but some have reserved meanings in
111the framework. The list of reserved environment variables is below
112
113 QEMU_ACCEL either kvm, hvf or tcg
114 QEMU_VERSION_STRING string of the form `qemu -h | head -1`
115 KERNEL_VERSION_STRING string of the form `uname -r`
116
117Additionally these self-explanatory variables are reserved
118
119 QEMU_MAJOR, QEMU_MINOR, QEMU_MICRO, KERNEL_VERSION, KERNEL_PATCHLEVEL,
120 KERNEL_SUBLEVEL, KERNEL_EXTRAVERSION
121
122# Guarding unsafe tests
123
124Some tests are not safe to run by default, as they may crash the
125host. kvm-unit-tests provides two ways to handle tests like those.
126
127 1) Adding 'nodefault' to the groups field for the unit test in the
128 unittests.cfg file. When a unit test is in the nodefault group
129 it is only run when invoked
130
131 a) independently, `ARCH-run ARCH/test`
132
133 b) by specifying any other non-nodefault group it is in,
134 groups = nodefault mygroup : `./run_tests.sh -g mygroup`
135
136 c) by specifying all tests should be run, `./run_tests.sh -a`
137
138 2) Making the test conditional on errata in the code,
139 ```
140 if (ERRATA(abcdef012345)) {
141 do_unsafe_test();
142 }
143 ```
144
145 With the errata condition the unsafe unit test is only run
146 when
147
148 a) the ERRATA_abcdef012345 environment variable is provided and 'y'
149
150 b) the ERRATA_FORCE environment variable is provided and 'y'
151
152 c) by specifying all tests should be run, `./run_tests.sh -a`
153 (The -a switch ensures the ERRATA_FORCE is provided and set
154 to 'y'.)
155
156The ./errata.txt file provides a mapping of the commits needed by errata
157conditionals to their respective minimum kernel versions. By default,
158when the user does not provide an environ, then an environ generated
159from the ./errata.txt file and the host's kernel version is provided to
160all unit tests.
161
162# Contributing
163
164## Directory structure
165
166 .: configure script, top-level Makefile, and run_tests.sh
167 ./scripts: general architecture neutral helper scripts for building and running tests
168 ./scripts/<ARCH>: architecture dependent helper scripts for building and running tests
169 ./lib: general architecture neutral services for the tests
170 ./lib/<ARCH>: architecture dependent services for the tests
171 ./<ARCH>: the sources of the tests and the created objects/images
172
173See ./ARCH/README for architecture specific documentation.
174
175## Style
176
177Currently there is a mix of indentation styles so any changes to
178existing files should be consistent with the existing style. For new
179files:
180
181 - C: please use standard linux-with-tabs, see Linux kernel
182 doc Documentation/process/coding-style.rst
183 - Shell: use TABs for indentation
184
185Exceptions:
186
187 - While the kernel standard requires 80 columns, we allow up to 120.
188
189Header guards:
190
191Please try to adhere to the following patterns when adding
192"#ifndef <...> #define <...>" header guards:
193 ./lib: _HEADER_H_
194 ./lib/<ARCH>: _ARCH_HEADER_H_
195 ./lib/<ARCH>/asm: _ASMARCH_HEADER_H_
196 ./<ARCH>: ARCH_HEADER_H
197
198## Patches
199
200Patches are welcome at the KVM mailing list <kvm@vger.kernel.org>.
201
202Please prefix messages with: [kvm-unit-tests PATCH]
203
204You can add the following to .git/config to do this automatically for you:
205
206 [format]
207 subjectprefix = kvm-unit-tests PATCH
208
209Additionally it's helpful to have a common order of file types in patches.
210Our chosen order attempts to place the more declarative files before
211the code files. We also start with common code and finish with unit test
212code. git-diff's orderFile feature allows us to specify the order in a
213file. The orderFile we use is `scripts/git.difforder`; adding the config
214with `git config diff.orderFile scripts/git.difforder` enables it.
215
216We strive to follow the Linux kernels coding style so it's recommended
217to run the kernel's ./scripts/checkpatch.pl on new patches.
218
219Also run `make shellcheck` before submitting a patch which touches bash
220scripts.
221
README.macOS.md
1# kvm-unit-tests on macOS
2
3The tests can be used to validate TCG or HVF accel on macOS.
4
5## Prerequisites
6
7GNU getopt and coreutils should be installed prior to building and running the
8tests. They're available in [homebrew](https://brew.sh):
9```
10$ brew install coreutils
11$ brew install gnu-getopt
12```
13
14A cross-compiler with ELF support is required to build kvm-unit-tests on macOS.
15
16### Pre-built cross-compiler
17
18Binary packages of ELF cross-compilers for i386 and x86_64 target can be
19installed from homebrew:
20```
21$ brew install i686-elf-gcc
22$ brew install x86_64-elf-gcc
23```
24
25Make enhanced getopt available in the current shell session:
26```
27export PATH="/usr/local/opt/gnu-getopt/bin:$PATH"
28```
29
30Then, 32-bit x86 tests can be built like that:
31```
32$ ./configure \
33 --arch=i386 \
34 --cross-prefix=i686-elf-
35$ make -j $(nproc)
36```
37
3864-bit x86 tests can be built likewise:
39```
40$ ./configure \
41 --arch=x86_64 \
42 --cross-prefix=x86_64-elf-
43$ make -j $(nproc)
44```
45
46Out-of-tree build can be used to make tests for both architectures
47simultaneously in separate build directories.
48
49### Building cross-compiler from source
50
51An alternative is to build cross-compiler toolchain from source using
52crosstool-ng. The latest released version of
53[crosstool-ng](https://github.com/crosstool-ng/crosstool-ng) can be installed
54using homebrew:
55```
56$ brew install crosstool-ng
57```
58
59A case-sensitive APFS/HFS+ volume has to be created using Disk Utility as a
60build and installation directory for the cross-compiler. Please [see Apple
61documentation](https://support.apple.com/guide/disk-utility/dsku19ed921c/mac)
62for details.
63
64Assuming the case-sensitive volume is named /Volumes/BuildTools, the
65cross-compiler can be built and installed there:
66```
67$ X_BUILD_DIR=/Volumes/BuildTools/ct-ng-build
68$ X_INSTALL_DIR=/Volumes/BuildTools/x-tools
69$ mkdir $X_BUILD_DIR
70$ ct-ng -C $X_BUILD_DIR x86_64-unknown-linux-gnu
71$ ct-ng -C $X_BUILD_DIR build CT_PREFIX=$X_INSTALL_DIR
72```
73
74Once compiled, the cross-compiler can be used to build the tests:
75```
76$ ./configure \
77 --arch=x86_64 \
78 --cross-prefix=$X_INSTALL_DIR/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-
79$ make -j $(nproc)
80```
81
README.md
1# Welcome to kvm-unit-tests
2
3See http://www.linux-kvm.org/page/KVM-unit-tests for a high-level
4description of this project, as well as running tests and adding
5tests HOWTOs.
6
7# Building the tests
8
9This directory contains sources for a KVM test suite.
10
11To create the test images do:
12
13 ./configure
14 make
15
16in this directory. Test images are created in ./ARCH/\*.flat
17
18NOTE: GCC cross-compiler is required for [build on macOS](README.macOS.md).
19
20## Cross-compiling
21
22A cross compiler may be configured by specifying a cross prefix. For example,
23for arm64
24
25 ./configure --arch=arm64 --cross-prefix=aarch64-linux-gnu-
26 make
27
28## clang
29
30clang may be used as an alternative to gcc.
31
32 ./configure --cc=clang
33 make
34
35clang may also be used with cross binutils when cross-compiling. For example,
36for riscv64
37
38 ./configure --arch=riscv64 --cc=clang --cflags='--target=riscv64' \
39 --cross-prefix=riscv64-linux-gnu-
40 make
41
42## Standalone tests
43
44The tests can be built as standalone. To create and use standalone tests do:
45
46 ./configure
47 make standalone
48 (send tests/some-test somewhere)
49 (go to somewhere)
50 ./some-test
51
52`make install` will install all tests in PREFIX/share/kvm-unit-tests/tests,
53each as a standalone test.
54
55
56# Running the tests
57
58Then use the runner script to detect the correct invocation and
59invoke the test:
60
61 ./x86-run ./x86/msr.flat
62or:
63
64 ./run_tests.sh
65
66to run them all.
67
68By default the runner script searches for a suitable QEMU binary in the system.
69To select a specific QEMU binary though, specify the QEMU=path/to/binary
70environment variable:
71
72 QEMU=/tmp/qemu/x86_64-softmmu/qemu-system-x86_64 ./x86-run ./x86/msr.flat
73
74To select an accelerator, for example "kvm", "hvf" or "tcg", specify the
75ACCEL=name environment variable:
76
77 ACCEL=kvm ./x86-run ./x86/msr.flat
78
79For running tests that involve migration from one QEMU instance to another
80you also need to have the "ncat" binary (from the nmap.org project) installed,
81otherwise the related tests will be skipped.
82
83## Running the tests with UEFI
84
85Check [x86/efi/README.md](./x86/efi/README.md).
86
87# Tests configuration file
88
89The test case may need specific runtime configurations, for
90example, extra QEMU parameters and time to execute limited, the
91runner script reads those information from a configuration file found
92at ./ARCH/unittests.cfg.
93
94The configuration file also contain the groups (if any) each test belong
95to. So that a given group can be executed by specifying its name in the
96runner's -g option.
97
98# Unit test inputs
99
100Unit tests use QEMU's '-append args...' parameter for command line
101inputs, i.e. all args will be available as argv strings in main().
102Additionally a file of the form
103
104 KEY=VAL
105 KEY2=VAL
106 ...
107
108may be passed with '-initrd file' to become the unit test's environ,
109which can then be accessed in the usual ways, e.g. VAL = getenv("KEY").
110Any key=val strings can be passed, but some have reserved meanings in
111the framework. The list of reserved environment variables is below
112
113 QEMU_ACCEL either kvm, hvf or tcg
114 QEMU_VERSION_STRING string of the form `qemu -h | head -1`
115 KERNEL_VERSION_STRING string of the form `uname -r`
116
117Additionally these self-explanatory variables are reserved
118
119 QEMU_MAJOR, QEMU_MINOR, QEMU_MICRO, KERNEL_VERSION, KERNEL_PATCHLEVEL,
120 KERNEL_SUBLEVEL, KERNEL_EXTRAVERSION
121
122# Guarding unsafe tests
123
124Some tests are not safe to run by default, as they may crash the
125host. kvm-unit-tests provides two ways to handle tests like those.
126
127 1) Adding 'nodefault' to the groups field for the unit test in the
128 unittests.cfg file. When a unit test is in the nodefault group
129 it is only run when invoked
130
131 a) independently, `ARCH-run ARCH/test`
132
133 b) by specifying any other non-nodefault group it is in,
134 groups = nodefault mygroup : `./run_tests.sh -g mygroup`
135
136 c) by specifying all tests should be run, `./run_tests.sh -a`
137
138 2) Making the test conditional on errata in the code,
139 ```
140 if (ERRATA(abcdef012345)) {
141 do_unsafe_test();
142 }
143 ```
144
145 With the errata condition the unsafe unit test is only run
146 when
147
148 a) the ERRATA_abcdef012345 environment variable is provided and 'y'
149
150 b) the ERRATA_FORCE environment variable is provided and 'y'
151
152 c) by specifying all tests should be run, `./run_tests.sh -a`
153 (The -a switch ensures the ERRATA_FORCE is provided and set
154 to 'y'.)
155
156The ./errata.txt file provides a mapping of the commits needed by errata
157conditionals to their respective minimum kernel versions. By default,
158when the user does not provide an environ, then an environ generated
159from the ./errata.txt file and the host's kernel version is provided to
160all unit tests.
161
162# Contributing
163
164## Directory structure
165
166 .: configure script, top-level Makefile, and run_tests.sh
167 ./scripts: general architecture neutral helper scripts for building and running tests
168 ./scripts/<ARCH>: architecture dependent helper scripts for building and running tests
169 ./lib: general architecture neutral services for the tests
170 ./lib/<ARCH>: architecture dependent services for the tests
171 ./<ARCH>: the sources of the tests and the created objects/images
172
173See ./ARCH/README for architecture specific documentation.
174
175## Style
176
177Currently there is a mix of indentation styles so any changes to
178existing files should be consistent with the existing style. For new
179files:
180
181 - C: please use standard linux-with-tabs, see Linux kernel
182 doc Documentation/process/coding-style.rst
183 - Shell: use TABs for indentation
184
185Exceptions:
186
187 - While the kernel standard requires 80 columns, we allow up to 120.
188
189Header guards:
190
191Please try to adhere to the following patterns when adding
192"#ifndef <...> #define <...>" header guards:
193 ./lib: _HEADER_H_
194 ./lib/<ARCH>: _ARCH_HEADER_H_
195 ./lib/<ARCH>/asm: _ASMARCH_HEADER_H_
196 ./<ARCH>: ARCH_HEADER_H
197
198## Patches
199
200Patches are welcome at the KVM mailing list <kvm@vger.kernel.org>.
201
202Please prefix messages with: [kvm-unit-tests PATCH]
203
204You can add the following to .git/config to do this automatically for you:
205
206 [format]
207 subjectprefix = kvm-unit-tests PATCH
208
209Additionally it's helpful to have a common order of file types in patches.
210Our chosen order attempts to place the more declarative files before
211the code files. We also start with common code and finish with unit test
212code. git-diff's orderFile feature allows us to specify the order in a
213file. The orderFile we use is `scripts/git.difforder`; adding the config
214with `git config diff.orderFile scripts/git.difforder` enables it.
215
216We strive to follow the Linux kernels coding style so it's recommended
217to run the kernel's ./scripts/checkpatch.pl on new patches.
218
219Also run `make shellcheck` before submitting a patch which touches bash
220scripts.
221