1Testing in QEMU 2=============== 3 4This document describes the testing infrastructure in QEMU. 5 6Testing with "make check" 7------------------------- 8 9The "make check" testing family includes most of the C based tests in QEMU. For 10a quick help, run ``make check-help`` from the source tree. 11 12The usual way to run these tests is: 13 14.. code:: 15 16 make check 17 18which includes QAPI schema tests, unit tests, QTests and some iotests. 19Different sub-types of "make check" tests will be explained below. 20 21Before running tests, it is best to build QEMU programs first. Some tests 22expect the executables to exist and will fail with obscure messages if they 23cannot find them. 24 25Unit tests 26~~~~~~~~~~ 27 28Unit tests, which can be invoked with ``make check-unit``, are simple C tests 29that typically link to individual QEMU object files and exercise them by 30calling exported functions. 31 32If you are writing new code in QEMU, consider adding a unit test, especially 33for utility modules that are relatively stateless or have few dependencies. To 34add a new unit test: 35 361. Create a new source file. For example, ``tests/unit/foo-test.c``. 37 382. Write the test. Normally you would include the header file which exports 39 the module API, then verify the interface behaves as expected from your 40 test. The test code should be organized with the glib testing framework. 41 Copying and modifying an existing test is usually a good idea. 42 433. Add the test to ``tests/unit/meson.build``. The unit tests are listed in a 44 dictionary called ``tests``. The values are any additional sources and 45 dependencies to be linked with the test. For a simple test whose source 46 is in ``tests/unit/foo-test.c``, it is enough to add an entry like:: 47 48 { 49 ... 50 'foo-test': [], 51 ... 52 } 53 54Since unit tests don't require environment variables, the simplest way to debug 55a unit test failure is often directly invoking it or even running it under 56``gdb``. However there can still be differences in behavior between ``make`` 57invocations and your manual run, due to ``$MALLOC_PERTURB_`` environment 58variable (which affects memory reclamation and catches invalid pointers better) 59and gtester options. If necessary, you can run 60 61.. code:: 62 63 make check-unit V=1 64 65and copy the actual command line which executes the unit test, then run 66it from the command line. 67 68QTest 69~~~~~ 70 71QTest is a device emulation testing framework. It can be very useful to test 72device models; it could also control certain aspects of QEMU (such as virtual 73clock stepping), with a special purpose "qtest" protocol. Refer to 74:doc:`qtest` for more details. 75 76QTest cases can be executed with 77 78.. code:: 79 80 make check-qtest 81 82QAPI schema tests 83~~~~~~~~~~~~~~~~~ 84 85The QAPI schema tests validate the QAPI parser used by QMP, by feeding 86predefined input to the parser and comparing the result with the reference 87output. 88 89The input/output data is managed under the ``tests/qapi-schema`` directory. 90Each test case includes four files that have a common base name: 91 92 * ``${casename}.json`` - the file contains the JSON input for feeding the 93 parser 94 * ``${casename}.out`` - the file contains the expected stdout from the parser 95 * ``${casename}.err`` - the file contains the expected stderr from the parser 96 * ``${casename}.exit`` - the expected error code 97 98Consider adding a new QAPI schema test when you are making a change on the QAPI 99parser (either fixing a bug or extending/modifying the syntax). To do this: 100 1011. Add four files for the new case as explained above. For example: 102 103 ``$EDITOR tests/qapi-schema/foo.{json,out,err,exit}``. 104 1052. Add the new test in ``tests/Makefile.include``. For example: 106 107 ``qapi-schema += foo.json`` 108 109check-block 110~~~~~~~~~~~ 111 112``make check-block`` runs a subset of the block layer iotests (the tests that 113are in the "auto" group). 114See the "QEMU iotests" section below for more information. 115 116QEMU iotests 117------------ 118 119QEMU iotests, under the directory ``tests/qemu-iotests``, is the testing 120framework widely used to test block layer related features. It is higher level 121than "make check" tests and 99% of the code is written in bash or Python 122scripts. The testing success criteria is golden output comparison, and the 123test files are named with numbers. 124 125To run iotests, make sure QEMU is built successfully, then switch to the 126``tests/qemu-iotests`` directory under the build directory, and run ``./check`` 127with desired arguments from there. 128 129By default, "raw" format and "file" protocol is used; all tests will be 130executed, except the unsupported ones. You can override the format and protocol 131with arguments: 132 133.. code:: 134 135 # test with qcow2 format 136 ./check -qcow2 137 # or test a different protocol 138 ./check -nbd 139 140It's also possible to list test numbers explicitly: 141 142.. code:: 143 144 # run selected cases with qcow2 format 145 ./check -qcow2 001 030 153 146 147Cache mode can be selected with the "-c" option, which may help reveal bugs 148that are specific to certain cache mode. 149 150More options are supported by the ``./check`` script, run ``./check -h`` for 151help. 152 153Writing a new test case 154~~~~~~~~~~~~~~~~~~~~~~~ 155 156Consider writing a tests case when you are making any changes to the block 157layer. An iotest case is usually the choice for that. There are already many 158test cases, so it is possible that extending one of them may achieve the goal 159and save the boilerplate to create one. (Unfortunately, there isn't a 100% 160reliable way to find a related one out of hundreds of tests. One approach is 161using ``git grep``.) 162 163Usually an iotest case consists of two files. One is an executable that 164produces output to stdout and stderr, the other is the expected reference 165output. They are given the same number in file names. E.g. Test script ``055`` 166and reference output ``055.out``. 167 168In rare cases, when outputs differ between cache mode ``none`` and others, a 169``.out.nocache`` file is added. In other cases, when outputs differ between 170image formats, more than one ``.out`` files are created ending with the 171respective format names, e.g. ``178.out.qcow2`` and ``178.out.raw``. 172 173There isn't a hard rule about how to write a test script, but a new test is 174usually a (copy and) modification of an existing case. There are a few 175commonly used ways to create a test: 176 177* A Bash script. It will make use of several environmental variables related 178 to the testing procedure, and could source a group of ``common.*`` libraries 179 for some common helper routines. 180 181* A Python unittest script. Import ``iotests`` and create a subclass of 182 ``iotests.QMPTestCase``, then call ``iotests.main`` method. The downside of 183 this approach is that the output is too scarce, and the script is considered 184 harder to debug. 185 186* A simple Python script without using unittest module. This could also import 187 ``iotests`` for launching QEMU and utilities etc, but it doesn't inherit 188 from ``iotests.QMPTestCase`` therefore doesn't use the Python unittest 189 execution. This is a combination of 1 and 2. 190 191Pick the language per your preference since both Bash and Python have 192comparable library support for invoking and interacting with QEMU programs. If 193you opt for Python, it is strongly recommended to write Python 3 compatible 194code. 195 196Both Python and Bash frameworks in iotests provide helpers to manage test 197images. They can be used to create and clean up images under the test 198directory. If no I/O or any protocol specific feature is needed, it is often 199more convenient to use the pseudo block driver, ``null-co://``, as the test 200image, which doesn't require image creation or cleaning up. Avoid system-wide 201devices or files whenever possible, such as ``/dev/null`` or ``/dev/zero``. 202Otherwise, image locking implications have to be considered. For example, 203another application on the host may have locked the file, possibly leading to a 204test failure. If using such devices are explicitly desired, consider adding 205``locking=off`` option to disable image locking. 206 207Debugging a test case 208~~~~~~~~~~~~~~~~~~~~~ 209 210The following options to the ``check`` script can be useful when debugging 211a failing test: 212 213* ``-gdb`` wraps every QEMU invocation in a ``gdbserver``, which waits for a 214 connection from a gdb client. The options given to ``gdbserver`` (e.g. the 215 address on which to listen for connections) are taken from the ``$GDB_OPTIONS`` 216 environment variable. By default (if ``$GDB_OPTIONS`` is empty), it listens on 217 ``localhost:12345``. 218 It is possible to connect to it for example with 219 ``gdb -iex "target remote $addr"``, where ``$addr`` is the address 220 ``gdbserver`` listens on. 221 If the ``-gdb`` option is not used, ``$GDB_OPTIONS`` is ignored, 222 regardless of whether it is set or not. 223 224* ``-valgrind`` attaches a valgrind instance to QEMU. If it detects 225 warnings, it will print and save the log in 226 ``$TEST_DIR/<valgrind_pid>.valgrind``. 227 The final command line will be ``valgrind --log-file=$TEST_DIR/ 228 <valgrind_pid>.valgrind --error-exitcode=99 $QEMU ...`` 229 230* ``-d`` (debug) just increases the logging verbosity, showing 231 for example the QMP commands and answers. 232 233* ``-p`` (print) redirects QEMU’s stdout and stderr to the test output, 234 instead of saving it into a log file in 235 ``$TEST_DIR/qemu-machine-<random_string>``. 236 237Test case groups 238~~~~~~~~~~~~~~~~ 239 240"Tests may belong to one or more test groups, which are defined in the form 241of a comment in the test source file. By convention, test groups are listed 242in the second line of the test file, after the "#!/..." line, like this: 243 244.. code:: 245 246 #!/usr/bin/env python3 247 # group: auto quick 248 # 249 ... 250 251Another way of defining groups is creating the tests/qemu-iotests/group.local 252file. This should be used only for downstream (this file should never appear 253in upstream). This file may be used for defining some downstream test groups 254or for temporarily disabling tests, like this: 255 256.. code:: 257 258 # groups for some company downstream process 259 # 260 # ci - tests to run on build 261 # down - our downstream tests, not for upstream 262 # 263 # Format of each line is: 264 # TEST_NAME TEST_GROUP [TEST_GROUP ]... 265 266 013 ci 267 210 disabled 268 215 disabled 269 our-ugly-workaround-test down ci 270 271Note that the following group names have a special meaning: 272 273- quick: Tests in this group should finish within a few seconds. 274 275- auto: Tests in this group are used during "make check" and should be 276 runnable in any case. That means they should run with every QEMU binary 277 (also non-x86), with every QEMU configuration (i.e. must not fail if 278 an optional feature is not compiled in - but reporting a "skip" is ok), 279 work at least with the qcow2 file format, work with all kind of host 280 filesystems and users (e.g. "nobody" or "root") and must not take too 281 much memory and disk space (since CI pipelines tend to fail otherwise). 282 283- disabled: Tests in this group are disabled and ignored by check. 284 285.. _container-ref: 286 287Container based tests 288--------------------- 289 290Introduction 291~~~~~~~~~~~~ 292 293The container testing framework in QEMU utilizes public images to 294build and test QEMU in predefined and widely accessible Linux 295environments. This makes it possible to expand the test coverage 296across distros, toolchain flavors and library versions. The support 297was originally written for Docker although we also support Podman as 298an alternative container runtime. Although the many of the target 299names and scripts are prefixed with "docker" the system will 300automatically run on whichever is configured. 301 302The container images are also used to augment the generation of tests 303for testing TCG. See :ref:`checktcg-ref` for more details. 304 305Docker Prerequisites 306~~~~~~~~~~~~~~~~~~~~ 307 308Install "docker" with the system package manager and start the Docker service 309on your development machine, then make sure you have the privilege to run 310Docker commands. Typically it means setting up passwordless ``sudo docker`` 311command or login as root. For example: 312 313.. code:: 314 315 $ sudo yum install docker 316 $ # or `apt-get install docker` for Ubuntu, etc. 317 $ sudo systemctl start docker 318 $ sudo docker ps 319 320The last command should print an empty table, to verify the system is ready. 321 322An alternative method to set up permissions is by adding the current user to 323"docker" group and making the docker daemon socket file (by default 324``/var/run/docker.sock``) accessible to the group: 325 326.. code:: 327 328 $ sudo groupadd docker 329 $ sudo usermod $USER -a -G docker 330 $ sudo chown :docker /var/run/docker.sock 331 332Note that any one of above configurations makes it possible for the user to 333exploit the whole host with Docker bind mounting or other privileged 334operations. So only do it on development machines. 335 336Podman Prerequisites 337~~~~~~~~~~~~~~~~~~~~ 338 339Install "podman" with the system package manager. 340 341.. code:: 342 343 $ sudo dnf install podman 344 $ podman ps 345 346The last command should print an empty table, to verify the system is ready. 347 348Quickstart 349~~~~~~~~~~ 350 351From source tree, type ``make docker-help`` to see the help. Testing 352can be started without configuring or building QEMU (``configure`` and 353``make`` are done in the container, with parameters defined by the 354make target): 355 356.. code:: 357 358 make docker-test-build@centos8 359 360This will create a container instance using the ``centos8`` image (the image 361is downloaded and initialized automatically), in which the ``test-build`` job 362is executed. 363 364Registry 365~~~~~~~~ 366 367The QEMU project has a container registry hosted by GitLab at 368``registry.gitlab.com/qemu-project/qemu`` which will automatically be 369used to pull in pre-built layers. This avoids unnecessary strain on 370the distro archives created by multiple developers running the same 371container build steps over and over again. This can be overridden 372locally by using the ``NOCACHE`` build option: 373 374.. code:: 375 376 make docker-image-debian10 NOCACHE=1 377 378Images 379~~~~~~ 380 381Along with many other images, the ``centos8`` image is defined in a Dockerfile 382in ``tests/docker/dockerfiles/``, called ``centos8.docker``. ``make docker-help`` 383command will list all the available images. 384 385A ``.pre`` script can be added beside the ``.docker`` file, which will be 386executed before building the image under the build context directory. This is 387mainly used to do necessary host side setup. One such setup is ``binfmt_misc``, 388for example, to make qemu-user powered cross build containers work. 389 390Most of the existing Dockerfiles were written by hand, simply by creating a 391a new ``.docker`` file under the ``tests/docker/dockerfiles/`` directory. 392This has led to an inconsistent set of packages being present across the 393different containers. 394 395Thus going forward, QEMU is aiming to automatically generate the Dockerfiles 396using the ``lcitool`` program provided by the ``libvirt-ci`` project: 397 398 https://gitlab.com/libvirt/libvirt-ci 399 400In that project, there is a ``mappings.yml`` file defining the distro native 401package names for a wide variety of third party projects. This is processed 402in combination with a project defined list of build pre-requisites to determine 403the list of native packages to install on each distribution. This can be used 404to generate dockerfiles, VM package lists and Cirrus CI variables needed to 405setup build environments across OS distributions with a consistent set of 406packages present. 407 408When preparing a patch series that adds a new build pre-requisite to QEMU, 409updates to various lcitool data files may be required. 410 411 412Adding new build pre-requisites 413^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 414 415In the simple case where the pre-requisite is already known to ``libvirt-ci`` 416the following steps are needed 417 418 * Edit ``tests/lcitool/projects/qemu.yml`` and add the pre-requisite 419 420 * Run ``make lcitool-refresh`` to re-generate all relevant build environment 421 manifests 422 423In some cases ``libvirt-ci`` will not know about the build pre-requisite and 424thus some extra preparation steps will be required first 425 426 * Fork the ``libvirt-ci`` project on gitlab 427 428 * Edit the ``mappings.yml`` change to add an entry for the new build 429 prerequisite, listing its native package name on as many OS distros 430 as practical. 431 432 * Commit the ``mappings.yml`` change and submit a merge request to 433 the ``libvirt-ci`` project, noting in the description that this 434 is a new build pre-requisite desired for use with QEMU 435 436 * CI pipeline will run to validate that the changes to ``mappings.yml`` 437 are correct, by attempting to install the newly listed package on 438 all OS distributions supported by ``libvirt-ci``. 439 440 * Once the merge request is accepted, go back to QEMU and update 441 the ``libvirt-ci`` submodule to point to a commit that contains 442 the ``mappings.yml`` update. 443 444 445Adding new OS distros 446^^^^^^^^^^^^^^^^^^^^^ 447 448In some cases ``libvirt-ci`` will not know about the OS distro that is 449desired to be tested. Before adding a new OS distro, discuss the proposed 450addition: 451 452 * Send a mail to qemu-devel, copying people listed in the 453 MAINTAINERS file for ``Build and test automation``. 454 455 There are limited CI compute resources available to QEMU, so the 456 cost/benefit tradeoff of adding new OS distros needs to be considered. 457 458 * File an issue at https://gitlab.com/libvirt/libvirt-ci/-/issues 459 pointing to the qemu-devel mail thread in the archives. 460 461 This alerts other people who might be interested in the work 462 to avoid duplication, as well as to get feedback from libvirt-ci 463 maintainers on any tips to ease the addition 464 465Assuming there is agreement to add a new OS distro then 466 467 * Fork the ``libvirt-ci`` project on gitlab 468 469 * Add metadata under ``guests/lcitool/lcitool/ansible/group_vars/`` 470 for the new OS distro. There might be code changes required if 471 the OS distro uses a package format not currently known. The 472 ``libvirt-ci`` maintainers can advise on this when the issue 473 is file. 474 475 * Edit the ``mappings.yml`` change to update all the existing package 476 entries, providing details of the new OS distro 477 478 * Commit the ``mappings.yml`` change and submit a merge request to 479 the ``libvirt-ci`` project, noting in the description that this 480 is a new build pre-requisite desired for use with QEMU 481 482 * CI pipeline will run to validate that the changes to ``mappings.yml`` 483 are correct, by attempting to install the newly listed package on 484 all OS distributions supported by ``libvirt-ci``. 485 486 * Once the merge request is accepted, go back to QEMU and update 487 the ``libvirt-ci`` submodule to point to a commit that contains 488 the ``mappings.yml`` update. 489 490 491Tests 492~~~~~ 493 494Different tests are added to cover various configurations to build and test 495QEMU. Docker tests are the executables under ``tests/docker`` named 496``test-*``. They are typically shell scripts and are built on top of a shell 497library, ``tests/docker/common.rc``, which provides helpers to find the QEMU 498source and build it. 499 500The full list of tests is printed in the ``make docker-help`` help. 501 502Debugging a Docker test failure 503~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 504 505When CI tasks, maintainers or yourself report a Docker test failure, follow the 506below steps to debug it: 507 5081. Locally reproduce the failure with the reported command line. E.g. run 509 ``make docker-test-mingw@fedora J=8``. 5102. Add "V=1" to the command line, try again, to see the verbose output. 5113. Further add "DEBUG=1" to the command line. This will pause in a shell prompt 512 in the container right before testing starts. You could either manually 513 build QEMU and run tests from there, or press Ctrl-D to let the Docker 514 testing continue. 5154. If you press Ctrl-D, the same building and testing procedure will begin, and 516 will hopefully run into the error again. After that, you will be dropped to 517 the prompt for debug. 518 519Options 520~~~~~~~ 521 522Various options can be used to affect how Docker tests are done. The full 523list is in the ``make docker`` help text. The frequently used ones are: 524 525* ``V=1``: the same as in top level ``make``. It will be propagated to the 526 container and enable verbose output. 527* ``J=$N``: the number of parallel tasks in make commands in the container, 528 similar to the ``-j $N`` option in top level ``make``. (The ``-j`` option in 529 top level ``make`` will not be propagated into the container.) 530* ``DEBUG=1``: enables debug. See the previous "Debugging a Docker test 531 failure" section. 532 533Thread Sanitizer 534---------------- 535 536Thread Sanitizer (TSan) is a tool which can detect data races. QEMU supports 537building and testing with this tool. 538 539For more information on TSan: 540 541https://github.com/google/sanitizers/wiki/ThreadSanitizerCppManual 542 543Thread Sanitizer in Docker 544~~~~~~~~~~~~~~~~~~~~~~~~~~ 545TSan is currently supported in the ubuntu2004 docker. 546 547The test-tsan test will build using TSan and then run make check. 548 549.. code:: 550 551 make docker-test-tsan@ubuntu2004 552 553TSan warnings under docker are placed in files located at build/tsan/. 554 555We recommend using DEBUG=1 to allow launching the test from inside the docker, 556and to allow review of the warnings generated by TSan. 557 558Building and Testing with TSan 559~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 560 561It is possible to build and test with TSan, with a few additional steps. 562These steps are normally done automatically in the docker. 563 564There is a one time patch needed in clang-9 or clang-10 at this time: 565 566.. code:: 567 568 sed -i 's/^const/static const/g' \ 569 /usr/lib/llvm-10/lib/clang/10.0.0/include/sanitizer/tsan_interface.h 570 571To configure the build for TSan: 572 573.. code:: 574 575 ../configure --enable-tsan --cc=clang-10 --cxx=clang++-10 \ 576 --disable-werror --extra-cflags="-O0" 577 578The runtime behavior of TSAN is controlled by the TSAN_OPTIONS environment 579variable. 580 581More information on the TSAN_OPTIONS can be found here: 582 583https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags 584 585For example: 586 587.. code:: 588 589 export TSAN_OPTIONS=suppressions=<path to qemu>/tests/tsan/suppressions.tsan \ 590 detect_deadlocks=false history_size=7 exitcode=0 \ 591 log_path=<build path>/tsan/tsan_warning 592 593The above exitcode=0 has TSan continue without error if any warnings are found. 594This allows for running the test and then checking the warnings afterwards. 595If you want TSan to stop and exit with error on warnings, use exitcode=66. 596 597TSan Suppressions 598~~~~~~~~~~~~~~~~~ 599Keep in mind that for any data race warning, although there might be a data race 600detected by TSan, there might be no actual bug here. TSan provides several 601different mechanisms for suppressing warnings. In general it is recommended 602to fix the code if possible to eliminate the data race rather than suppress 603the warning. 604 605A few important files for suppressing warnings are: 606 607tests/tsan/suppressions.tsan - Has TSan warnings we wish to suppress at runtime. 608The comment on each suppression will typically indicate why we are 609suppressing it. More information on the file format can be found here: 610 611https://github.com/google/sanitizers/wiki/ThreadSanitizerSuppressions 612 613tests/tsan/blacklist.tsan - Has TSan warnings we wish to disable 614at compile time for test or debug. 615Add flags to configure to enable: 616 617"--extra-cflags=-fsanitize-blacklist=<src path>/tests/tsan/blacklist.tsan" 618 619More information on the file format can be found here under "Blacklist Format": 620 621https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags 622 623TSan Annotations 624~~~~~~~~~~~~~~~~ 625include/qemu/tsan.h defines annotations. See this file for more descriptions 626of the annotations themselves. Annotations can be used to suppress 627TSan warnings or give TSan more information so that it can detect proper 628relationships between accesses of data. 629 630Annotation examples can be found here: 631 632https://github.com/llvm/llvm-project/tree/master/compiler-rt/test/tsan/ 633 634Good files to start with are: annotate_happens_before.cpp and ignore_race.cpp 635 636The full set of annotations can be found here: 637 638https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/tsan/rtl/tsan_interface_ann.cpp 639 640docker-binfmt-image-debian-% targets 641------------------------------------ 642 643It is possible to combine Debian's bootstrap scripts with a configured 644``binfmt_misc`` to bootstrap a number of Debian's distros including 645experimental ports not yet supported by a released OS. This can 646simplify setting up a rootfs by using docker to contain the foreign 647rootfs rather than manually invoking chroot. 648 649Setting up ``binfmt_misc`` 650~~~~~~~~~~~~~~~~~~~~~~~~~~ 651 652You can use the script ``qemu-binfmt-conf.sh`` to configure a QEMU 653user binary to automatically run binaries for the foreign 654architecture. While the scripts will try their best to work with 655dynamically linked QEMU's a statically linked one will present less 656potential complications when copying into the docker image. Modern 657kernels support the ``F`` (fix binary) flag which will open the QEMU 658executable on setup and avoids the need to find and re-open in the 659chroot environment. This is triggered with the ``--persistent`` flag. 660 661Example invocation 662~~~~~~~~~~~~~~~~~~ 663 664For example to setup the HPPA ports builds of Debian:: 665 666 make docker-binfmt-image-debian-sid-hppa \ 667 DEB_TYPE=sid DEB_ARCH=hppa \ 668 DEB_URL=http://ftp.ports.debian.org/debian-ports/ \ 669 DEB_KEYRING=/usr/share/keyrings/debian-ports-archive-keyring.gpg \ 670 EXECUTABLE=(pwd)/qemu-hppa V=1 671 672The ``DEB_`` variables are substitutions used by 673``debian-boostrap.pre`` which is called to do the initial debootstrap 674of the rootfs before it is copied into the container. The second stage 675is run as part of the build. The final image will be tagged as 676``qemu/debian-sid-hppa``. 677 678VM testing 679---------- 680 681This test suite contains scripts that bootstrap various guest images that have 682necessary packages to build QEMU. The basic usage is documented in ``Makefile`` 683help which is displayed with ``make vm-help``. 684 685Quickstart 686~~~~~~~~~~ 687 688Run ``make vm-help`` to list available make targets. Invoke a specific make 689command to run build test in an image. For example, ``make vm-build-freebsd`` 690will build the source tree in the FreeBSD image. The command can be executed 691from either the source tree or the build dir; if the former, ``./configure`` is 692not needed. The command will then generate the test image in ``./tests/vm/`` 693under the working directory. 694 695Note: images created by the scripts accept a well-known RSA key pair for SSH 696access, so they SHOULD NOT be exposed to external interfaces if you are 697concerned about attackers taking control of the guest and potentially 698exploiting a QEMU security bug to compromise the host. 699 700QEMU binaries 701~~~~~~~~~~~~~ 702 703By default, ``qemu-system-x86_64`` is searched in $PATH to run the guest. If 704there isn't one, or if it is older than 2.10, the test won't work. In this case, 705provide the QEMU binary in env var: ``QEMU=/path/to/qemu-2.10+``. 706 707Likewise the path to ``qemu-img`` can be set in QEMU_IMG environment variable. 708 709Make jobs 710~~~~~~~~~ 711 712The ``-j$X`` option in the make command line is not propagated into the VM, 713specify ``J=$X`` to control the make jobs in the guest. 714 715Debugging 716~~~~~~~~~ 717 718Add ``DEBUG=1`` and/or ``V=1`` to the make command to allow interactive 719debugging and verbose output. If this is not enough, see the next section. 720``V=1`` will be propagated down into the make jobs in the guest. 721 722Manual invocation 723~~~~~~~~~~~~~~~~~ 724 725Each guest script is an executable script with the same command line options. 726For example to work with the netbsd guest, use ``$QEMU_SRC/tests/vm/netbsd``: 727 728.. code:: 729 730 $ cd $QEMU_SRC/tests/vm 731 732 # To bootstrap the image 733 $ ./netbsd --build-image --image /var/tmp/netbsd.img 734 <...> 735 736 # To run an arbitrary command in guest (the output will not be echoed unless 737 # --debug is added) 738 $ ./netbsd --debug --image /var/tmp/netbsd.img uname -a 739 740 # To build QEMU in guest 741 $ ./netbsd --debug --image /var/tmp/netbsd.img --build-qemu $QEMU_SRC 742 743 # To get to an interactive shell 744 $ ./netbsd --interactive --image /var/tmp/netbsd.img sh 745 746Adding new guests 747~~~~~~~~~~~~~~~~~ 748 749Please look at existing guest scripts for how to add new guests. 750 751Most importantly, create a subclass of BaseVM and implement ``build_image()`` 752method and define ``BUILD_SCRIPT``, then finally call ``basevm.main()`` from 753the script's ``main()``. 754 755* Usually in ``build_image()``, a template image is downloaded from a 756 predefined URL. ``BaseVM._download_with_cache()`` takes care of the cache and 757 the checksum, so consider using it. 758 759* Once the image is downloaded, users, SSH server and QEMU build deps should 760 be set up: 761 762 - Root password set to ``BaseVM.ROOT_PASS`` 763 - User ``BaseVM.GUEST_USER`` is created, and password set to 764 ``BaseVM.GUEST_PASS`` 765 - SSH service is enabled and started on boot, 766 ``$QEMU_SRC/tests/keys/id_rsa.pub`` is added to ssh's ``authorized_keys`` 767 file of both root and the normal user 768 - DHCP client service is enabled and started on boot, so that it can 769 automatically configure the virtio-net-pci NIC and communicate with QEMU 770 user net (10.0.2.2) 771 - Necessary packages are installed to untar the source tarball and build 772 QEMU 773 774* Write a proper ``BUILD_SCRIPT`` template, which should be a shell script that 775 untars a raw virtio-blk block device, which is the tarball data blob of the 776 QEMU source tree, then configure/build it. Running "make check" is also 777 recommended. 778 779Image fuzzer testing 780-------------------- 781 782An image fuzzer was added to exercise format drivers. Currently only qcow2 is 783supported. To start the fuzzer, run 784 785.. code:: 786 787 tests/image-fuzzer/runner.py -c '[["qemu-img", "info", "$test_img"]]' /tmp/test qcow2 788 789Alternatively, some command different from ``qemu-img info`` can be tested, by 790changing the ``-c`` option. 791 792Integration tests using the Avocado Framework 793--------------------------------------------- 794 795The ``tests/avocado`` directory hosts integration tests. They're usually 796higher level tests, and may interact with external resources and with 797various guest operating systems. 798 799These tests are written using the Avocado Testing Framework (which must 800be installed separately) in conjunction with a the ``avocado_qemu.Test`` 801class, implemented at ``tests/avocado/avocado_qemu``. 802 803Tests based on ``avocado_qemu.Test`` can easily: 804 805 * Customize the command line arguments given to the convenience 806 ``self.vm`` attribute (a QEMUMachine instance) 807 808 * Interact with the QEMU monitor, send QMP commands and check 809 their results 810 811 * Interact with the guest OS, using the convenience console device 812 (which may be useful to assert the effectiveness and correctness of 813 command line arguments or QMP commands) 814 815 * Interact with external data files that accompany the test itself 816 (see ``self.get_data()``) 817 818 * Download (and cache) remote data files, such as firmware and kernel 819 images 820 821 * Have access to a library of guest OS images (by means of the 822 ``avocado.utils.vmimage`` library) 823 824 * Make use of various other test related utilities available at the 825 test class itself and at the utility library: 826 827 - http://avocado-framework.readthedocs.io/en/latest/api/test/avocado.html#avocado.Test 828 - http://avocado-framework.readthedocs.io/en/latest/api/utils/avocado.utils.html 829 830Running tests 831~~~~~~~~~~~~~ 832 833You can run the avocado tests simply by executing: 834 835.. code:: 836 837 make check-avocado 838 839This involves the automatic creation of Python virtual environment 840within the build tree (at ``tests/venv``) which will have all the 841right dependencies, and will save tests results also within the 842build tree (at ``tests/results``). 843 844Note: the build environment must be using a Python 3 stack, and have 845the ``venv`` and ``pip`` packages installed. If necessary, make sure 846``configure`` is called with ``--python=`` and that those modules are 847available. On Debian and Ubuntu based systems, depending on the 848specific version, they may be on packages named ``python3-venv`` and 849``python3-pip``. 850 851It is also possible to run tests based on tags using the 852``make check-avocado`` command and the ``AVOCADO_TAGS`` environment 853variable: 854 855.. code:: 856 857 make check-avocado AVOCADO_TAGS=quick 858 859Note that tags separated with commas have an AND behavior, while tags 860separated by spaces have an OR behavior. For more information on Avocado 861tags, see: 862 863 https://avocado-framework.readthedocs.io/en/latest/guides/user/chapters/tags.html 864 865To run a single test file, a couple of them, or a test within a file 866using the ``make check-avocado`` command, set the ``AVOCADO_TESTS`` 867environment variable with the test files or test names. To run all 868tests from a single file, use: 869 870 .. code:: 871 872 make check-avocado AVOCADO_TESTS=$FILEPATH 873 874The same is valid to run tests from multiple test files: 875 876 .. code:: 877 878 make check-avocado AVOCADO_TESTS='$FILEPATH1 $FILEPATH2' 879 880To run a single test within a file, use: 881 882 .. code:: 883 884 make check-avocado AVOCADO_TESTS=$FILEPATH:$TESTCLASS.$TESTNAME 885 886The same is valid to run single tests from multiple test files: 887 888 .. code:: 889 890 make check-avocado AVOCADO_TESTS='$FILEPATH1:$TESTCLASS1.$TESTNAME1 $FILEPATH2:$TESTCLASS2.$TESTNAME2' 891 892The scripts installed inside the virtual environment may be used 893without an "activation". For instance, the Avocado test runner 894may be invoked by running: 895 896 .. code:: 897 898 tests/venv/bin/avocado run $OPTION1 $OPTION2 tests/avocado/ 899 900Note that if ``make check-avocado`` was not executed before, it is 901possible to create the Python virtual environment with the dependencies 902needed running: 903 904 .. code:: 905 906 make check-venv 907 908It is also possible to run tests from a single file or a single test within 909a test file. To run tests from a single file within the build tree, use: 910 911 .. code:: 912 913 tests/venv/bin/avocado run tests/avocado/$TESTFILE 914 915To run a single test within a test file, use: 916 917 .. code:: 918 919 tests/venv/bin/avocado run tests/avocado/$TESTFILE:$TESTCLASS.$TESTNAME 920 921Valid test names are visible in the output from any previous execution 922of Avocado or ``make check-avocado``, and can also be queried using: 923 924 .. code:: 925 926 tests/venv/bin/avocado list tests/avocado 927 928Manual Installation 929~~~~~~~~~~~~~~~~~~~ 930 931To manually install Avocado and its dependencies, run: 932 933.. code:: 934 935 pip install --user avocado-framework 936 937Alternatively, follow the instructions on this link: 938 939 https://avocado-framework.readthedocs.io/en/latest/guides/user/chapters/installing.html 940 941Overview 942~~~~~~~~ 943 944The ``tests/avocado/avocado_qemu`` directory provides the 945``avocado_qemu`` Python module, containing the ``avocado_qemu.Test`` 946class. Here's a simple usage example: 947 948.. code:: 949 950 from avocado_qemu import QemuSystemTest 951 952 953 class Version(QemuSystemTest): 954 """ 955 :avocado: tags=quick 956 """ 957 def test_qmp_human_info_version(self): 958 self.vm.launch() 959 res = self.vm.command('human-monitor-command', 960 command_line='info version') 961 self.assertRegexpMatches(res, r'^(\d+\.\d+\.\d)') 962 963To execute your test, run: 964 965.. code:: 966 967 avocado run version.py 968 969Tests may be classified according to a convention by using docstring 970directives such as ``:avocado: tags=TAG1,TAG2``. To run all tests 971in the current directory, tagged as "quick", run: 972 973.. code:: 974 975 avocado run -t quick . 976 977The ``avocado_qemu.Test`` base test class 978^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 979 980The ``avocado_qemu.Test`` class has a number of characteristics that 981are worth being mentioned right away. 982 983First of all, it attempts to give each test a ready to use QEMUMachine 984instance, available at ``self.vm``. Because many tests will tweak the 985QEMU command line, launching the QEMUMachine (by using ``self.vm.launch()``) 986is left to the test writer. 987 988The base test class has also support for tests with more than one 989QEMUMachine. The way to get machines is through the ``self.get_vm()`` 990method which will return a QEMUMachine instance. The ``self.get_vm()`` 991method accepts arguments that will be passed to the QEMUMachine creation 992and also an optional ``name`` attribute so you can identify a specific 993machine and get it more than once through the tests methods. A simple 994and hypothetical example follows: 995 996.. code:: 997 998 from avocado_qemu import QemuSystemTest 999 1000 1001 class MultipleMachines(QemuSystemTest): 1002 def test_multiple_machines(self): 1003 first_machine = self.get_vm() 1004 second_machine = self.get_vm() 1005 self.get_vm(name='third_machine').launch() 1006 1007 first_machine.launch() 1008 second_machine.launch() 1009 1010 first_res = first_machine.command( 1011 'human-monitor-command', 1012 command_line='info version') 1013 1014 second_res = second_machine.command( 1015 'human-monitor-command', 1016 command_line='info version') 1017 1018 third_res = self.get_vm(name='third_machine').command( 1019 'human-monitor-command', 1020 command_line='info version') 1021 1022 self.assertEquals(first_res, second_res, third_res) 1023 1024At test "tear down", ``avocado_qemu.Test`` handles all the QEMUMachines 1025shutdown. 1026 1027The ``avocado_qemu.LinuxTest`` base test class 1028^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1029 1030The ``avocado_qemu.LinuxTest`` is further specialization of the 1031``avocado_qemu.Test`` class, so it contains all the characteristics of 1032the later plus some extra features. 1033 1034First of all, this base class is intended for tests that need to 1035interact with a fully booted and operational Linux guest. At this 1036time, it uses a Fedora 31 guest image. The most basic example looks 1037like this: 1038 1039.. code:: 1040 1041 from avocado_qemu import LinuxTest 1042 1043 1044 class SomeTest(LinuxTest): 1045 1046 def test(self): 1047 self.launch_and_wait() 1048 self.ssh_command('some_command_to_be_run_in_the_guest') 1049 1050Please refer to tests that use ``avocado_qemu.LinuxTest`` under 1051``tests/avocado`` for more examples. 1052 1053QEMUMachine 1054~~~~~~~~~~~ 1055 1056The QEMUMachine API is already widely used in the Python iotests, 1057device-crash-test and other Python scripts. It's a wrapper around the 1058execution of a QEMU binary, giving its users: 1059 1060 * the ability to set command line arguments to be given to the QEMU 1061 binary 1062 1063 * a ready to use QMP connection and interface, which can be used to 1064 send commands and inspect its results, as well as asynchronous 1065 events 1066 1067 * convenience methods to set commonly used command line arguments in 1068 a more succinct and intuitive way 1069 1070QEMU binary selection 1071^^^^^^^^^^^^^^^^^^^^^ 1072 1073The QEMU binary used for the ``self.vm`` QEMUMachine instance will 1074primarily depend on the value of the ``qemu_bin`` parameter. If it's 1075not explicitly set, its default value will be the result of a dynamic 1076probe in the same source tree. A suitable binary will be one that 1077targets the architecture matching host machine. 1078 1079Based on this description, test writers will usually rely on one of 1080the following approaches: 1081 10821) Set ``qemu_bin``, and use the given binary 1083 10842) Do not set ``qemu_bin``, and use a QEMU binary named like 1085 "qemu-system-${arch}", either in the current 1086 working directory, or in the current source tree. 1087 1088The resulting ``qemu_bin`` value will be preserved in the 1089``avocado_qemu.Test`` as an attribute with the same name. 1090 1091Attribute reference 1092~~~~~~~~~~~~~~~~~~~ 1093 1094Test 1095^^^^ 1096 1097Besides the attributes and methods that are part of the base 1098``avocado.Test`` class, the following attributes are available on any 1099``avocado_qemu.Test`` instance. 1100 1101vm 1102'' 1103 1104A QEMUMachine instance, initially configured according to the given 1105``qemu_bin`` parameter. 1106 1107arch 1108'''' 1109 1110The architecture can be used on different levels of the stack, e.g. by 1111the framework or by the test itself. At the framework level, it will 1112currently influence the selection of a QEMU binary (when one is not 1113explicitly given). 1114 1115Tests are also free to use this attribute value, for their own needs. 1116A test may, for instance, use the same value when selecting the 1117architecture of a kernel or disk image to boot a VM with. 1118 1119The ``arch`` attribute will be set to the test parameter of the same 1120name. If one is not given explicitly, it will either be set to 1121``None``, or, if the test is tagged with one (and only one) 1122``:avocado: tags=arch:VALUE`` tag, it will be set to ``VALUE``. 1123 1124cpu 1125''' 1126 1127The cpu model that will be set to all QEMUMachine instances created 1128by the test. 1129 1130The ``cpu`` attribute will be set to the test parameter of the same 1131name. If one is not given explicitly, it will either be set to 1132``None ``, or, if the test is tagged with one (and only one) 1133``:avocado: tags=cpu:VALUE`` tag, it will be set to ``VALUE``. 1134 1135machine 1136''''''' 1137 1138The machine type that will be set to all QEMUMachine instances created 1139by the test. 1140 1141The ``machine`` attribute will be set to the test parameter of the same 1142name. If one is not given explicitly, it will either be set to 1143``None``, or, if the test is tagged with one (and only one) 1144``:avocado: tags=machine:VALUE`` tag, it will be set to ``VALUE``. 1145 1146qemu_bin 1147'''''''' 1148 1149The preserved value of the ``qemu_bin`` parameter or the result of the 1150dynamic probe for a QEMU binary in the current working directory or 1151source tree. 1152 1153LinuxTest 1154^^^^^^^^^ 1155 1156Besides the attributes present on the ``avocado_qemu.Test`` base 1157class, the ``avocado_qemu.LinuxTest`` adds the following attributes: 1158 1159distro 1160'''''' 1161 1162The name of the Linux distribution used as the guest image for the 1163test. The name should match the **Provider** column on the list 1164of images supported by the avocado.utils.vmimage library: 1165 1166https://avocado-framework.readthedocs.io/en/latest/guides/writer/libs/vmimage.html#supported-images 1167 1168distro_version 1169'''''''''''''' 1170 1171The version of the Linux distribution as the guest image for the 1172test. The name should match the **Version** column on the list 1173of images supported by the avocado.utils.vmimage library: 1174 1175https://avocado-framework.readthedocs.io/en/latest/guides/writer/libs/vmimage.html#supported-images 1176 1177distro_checksum 1178''''''''''''''' 1179 1180The sha256 hash of the guest image file used for the test. 1181 1182If this value is not set in the code or by a test parameter (with the 1183same name), no validation on the integrity of the image will be 1184performed. 1185 1186Parameter reference 1187~~~~~~~~~~~~~~~~~~~ 1188 1189To understand how Avocado parameters are accessed by tests, and how 1190they can be passed to tests, please refer to:: 1191 1192 https://avocado-framework.readthedocs.io/en/latest/guides/writer/chapters/writing.html#accessing-test-parameters 1193 1194Parameter values can be easily seen in the log files, and will look 1195like the following: 1196 1197.. code:: 1198 1199 PARAMS (key=qemu_bin, path=*, default=./qemu-system-x86_64) => './qemu-system-x86_64 1200 1201Test 1202^^^^ 1203 1204arch 1205'''' 1206 1207The architecture that will influence the selection of a QEMU binary 1208(when one is not explicitly given). 1209 1210Tests are also free to use this parameter value, for their own needs. 1211A test may, for instance, use the same value when selecting the 1212architecture of a kernel or disk image to boot a VM with. 1213 1214This parameter has a direct relation with the ``arch`` attribute. If 1215not given, it will default to None. 1216 1217cpu 1218''' 1219 1220The cpu model that will be set to all QEMUMachine instances created 1221by the test. 1222 1223machine 1224''''''' 1225 1226The machine type that will be set to all QEMUMachine instances created 1227by the test. 1228 1229qemu_bin 1230'''''''' 1231 1232The exact QEMU binary to be used on QEMUMachine. 1233 1234LinuxTest 1235^^^^^^^^^ 1236 1237Besides the parameters present on the ``avocado_qemu.Test`` base 1238class, the ``avocado_qemu.LinuxTest`` adds the following parameters: 1239 1240distro 1241'''''' 1242 1243The name of the Linux distribution used as the guest image for the 1244test. The name should match the **Provider** column on the list 1245of images supported by the avocado.utils.vmimage library: 1246 1247https://avocado-framework.readthedocs.io/en/latest/guides/writer/libs/vmimage.html#supported-images 1248 1249distro_version 1250'''''''''''''' 1251 1252The version of the Linux distribution as the guest image for the 1253test. The name should match the **Version** column on the list 1254of images supported by the avocado.utils.vmimage library: 1255 1256https://avocado-framework.readthedocs.io/en/latest/guides/writer/libs/vmimage.html#supported-images 1257 1258distro_checksum 1259''''''''''''''' 1260 1261The sha256 hash of the guest image file used for the test. 1262 1263If this value is not set in the code or by this parameter no 1264validation on the integrity of the image will be performed. 1265 1266Skipping tests 1267~~~~~~~~~~~~~~ 1268 1269The Avocado framework provides Python decorators which allow for easily skip 1270tests running under certain conditions. For example, on the lack of a binary 1271on the test system or when the running environment is a CI system. For further 1272information about those decorators, please refer to:: 1273 1274 https://avocado-framework.readthedocs.io/en/latest/guides/writer/chapters/writing.html#skipping-tests 1275 1276While the conditions for skipping tests are often specifics of each one, there 1277are recurring scenarios identified by the QEMU developers and the use of 1278environment variables became a kind of standard way to enable/disable tests. 1279 1280Here is a list of the most used variables: 1281 1282AVOCADO_ALLOW_LARGE_STORAGE 1283^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1284Tests which are going to fetch or produce assets considered *large* are not 1285going to run unless that ``AVOCADO_ALLOW_LARGE_STORAGE=1`` is exported on 1286the environment. 1287 1288The definition of *large* is a bit arbitrary here, but it usually means an 1289asset which occupies at least 1GB of size on disk when uncompressed. 1290 1291AVOCADO_ALLOW_UNTRUSTED_CODE 1292^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1293There are tests which will boot a kernel image or firmware that can be 1294considered not safe to run on the developer's workstation, thus they are 1295skipped by default. The definition of *not safe* is also arbitrary but 1296usually it means a blob which either its source or build process aren't 1297public available. 1298 1299You should export ``AVOCADO_ALLOW_UNTRUSTED_CODE=1`` on the environment in 1300order to allow tests which make use of those kind of assets. 1301 1302AVOCADO_TIMEOUT_EXPECTED 1303^^^^^^^^^^^^^^^^^^^^^^^^ 1304The Avocado framework has a timeout mechanism which interrupts tests to avoid the 1305test suite of getting stuck. The timeout value can be set via test parameter or 1306property defined in the test class, for further details:: 1307 1308 https://avocado-framework.readthedocs.io/en/latest/guides/writer/chapters/writing.html#setting-a-test-timeout 1309 1310Even though the timeout can be set by the test developer, there are some tests 1311that may not have a well-defined limit of time to finish under certain 1312conditions. For example, tests that take longer to execute when QEMU is 1313compiled with debug flags. Therefore, the ``AVOCADO_TIMEOUT_EXPECTED`` variable 1314has been used to determine whether those tests should run or not. 1315 1316GITLAB_CI 1317^^^^^^^^^ 1318A number of tests are flagged to not run on the GitLab CI. Usually because 1319they proved to the flaky or there are constraints on the CI environment which 1320would make them fail. If you encounter a similar situation then use that 1321variable as shown on the code snippet below to skip the test: 1322 1323.. code:: 1324 1325 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab') 1326 def test(self): 1327 do_something() 1328 1329Uninstalling Avocado 1330~~~~~~~~~~~~~~~~~~~~ 1331 1332If you've followed the manual installation instructions above, you can 1333easily uninstall Avocado. Start by listing the packages you have 1334installed:: 1335 1336 pip list --user 1337 1338And remove any package you want with:: 1339 1340 pip uninstall <package_name> 1341 1342If you've used ``make check-avocado``, the Python virtual environment where 1343Avocado is installed will be cleaned up as part of ``make check-clean``. 1344 1345.. _checktcg-ref: 1346 1347Testing with "make check-tcg" 1348----------------------------- 1349 1350The check-tcg tests are intended for simple smoke tests of both 1351linux-user and softmmu TCG functionality. However to build test 1352programs for guest targets you need to have cross compilers available. 1353If your distribution supports cross compilers you can do something as 1354simple as:: 1355 1356 apt install gcc-aarch64-linux-gnu 1357 1358The configure script will automatically pick up their presence. 1359Sometimes compilers have slightly odd names so the availability of 1360them can be prompted by passing in the appropriate configure option 1361for the architecture in question, for example:: 1362 1363 $(configure) --cross-cc-aarch64=aarch64-cc 1364 1365There is also a ``--cross-cc-cflags-ARCH`` flag in case additional 1366compiler flags are needed to build for a given target. 1367 1368If you have the ability to run containers as the user the build system 1369will automatically use them where no system compiler is available. For 1370architectures where we also support building QEMU we will generally 1371use the same container to build tests. However there are a number of 1372additional containers defined that have a minimal cross-build 1373environment that is only suitable for building test cases. Sometimes 1374we may use a bleeding edge distribution for compiler features needed 1375for test cases that aren't yet in the LTS distros we support for QEMU 1376itself. 1377 1378See :ref:`container-ref` for more details. 1379 1380Running subset of tests 1381~~~~~~~~~~~~~~~~~~~~~~~ 1382 1383You can build the tests for one architecture:: 1384 1385 make build-tcg-tests-$TARGET 1386 1387And run with:: 1388 1389 make run-tcg-tests-$TARGET 1390 1391Adding ``V=1`` to the invocation will show the details of how to 1392invoke QEMU for the test which is useful for debugging tests. 1393 1394TCG test dependencies 1395~~~~~~~~~~~~~~~~~~~~~ 1396 1397The TCG tests are deliberately very light on dependencies and are 1398either totally bare with minimal gcc lib support (for softmmu tests) 1399or just glibc (for linux-user tests). This is because getting a cross 1400compiler to work with additional libraries can be challenging. 1401 1402Other TCG Tests 1403--------------- 1404 1405There are a number of out-of-tree test suites that are used for more 1406extensive testing of processor features. 1407 1408KVM Unit Tests 1409~~~~~~~~~~~~~~ 1410 1411The KVM unit tests are designed to run as a Guest OS under KVM but 1412there is no reason why they can't exercise the TCG as well. It 1413provides a minimal OS kernel with hooks for enabling the MMU as well 1414as reporting test results via a special device:: 1415 1416 https://git.kernel.org/pub/scm/virt/kvm/kvm-unit-tests.git 1417 1418Linux Test Project 1419~~~~~~~~~~~~~~~~~~ 1420 1421The LTP is focused on exercising the syscall interface of a Linux 1422kernel. It checks that syscalls behave as documented and strives to 1423exercise as many corner cases as possible. It is a useful test suite 1424to run to exercise QEMU's linux-user code:: 1425 1426 https://linux-test-project.github.io/ 1427 1428GCC gcov support 1429---------------- 1430 1431``gcov`` is a GCC tool to analyze the testing coverage by 1432instrumenting the tested code. To use it, configure QEMU with 1433``--enable-gcov`` option and build. Then run the tests as usual. 1434 1435If you want to gather coverage information on a single test the ``make 1436clean-gcda`` target can be used to delete any existing coverage 1437information before running a single test. 1438 1439You can generate a HTML coverage report by executing ``make 1440coverage-html`` which will create 1441``meson-logs/coveragereport/index.html``. 1442 1443Further analysis can be conducted by running the ``gcov`` command 1444directly on the various .gcda output files. Please read the ``gcov`` 1445documentation for more information. 1446