xref: /openbmc/qemu/docs/devel/testing.rst (revision e0c0965f)
1===============
2Testing in QEMU
3===============
4
5This document describes the testing infrastructure in QEMU.
6
7Testing with "make check"
8=========================
9
10The "make check" testing family includes most of the C based tests in QEMU. For
11a quick help, run ``make check-help`` from the source tree.
12
13The usual way to run these tests is:
14
15.. code::
16
17  make check
18
19which includes QAPI schema tests, unit tests, and QTests. Different sub-types
20of "make check" tests will be explained below.
21
22Before running tests, it is best to build QEMU programs first. Some tests
23expect the executables to exist and will fail with obscure messages if they
24cannot find them.
25
26Unit tests
27----------
28
29Unit tests, which can be invoked with ``make check-unit``, are simple C tests
30that typically link to individual QEMU object files and exercise them by
31calling exported functions.
32
33If you are writing new code in QEMU, consider adding a unit test, especially
34for utility modules that are relatively stateless or have few dependencies. To
35add a new unit test:
36
371. Create a new source file. For example, ``tests/foo-test.c``.
38
392. Write the test. Normally you would include the header file which exports
40   the module API, then verify the interface behaves as expected from your
41   test. The test code should be organized with the glib testing framework.
42   Copying and modifying an existing test is usually a good idea.
43
443. Add the test to ``tests/Makefile.include``. First, name the unit test
45   program and add it to ``$(check-unit-y)``; then add a rule to build the
46   executable.  For example:
47
48.. code::
49
50  check-unit-y += tests/foo-test$(EXESUF)
51  tests/foo-test$(EXESUF): tests/foo-test.o $(test-util-obj-y)
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 the
74documentation in ``qtest.c`` for more details of the protocol.
75
76QTest cases can be executed with
77
78.. code::
79
80   make check-qtest
81
82The QTest library is implemented by ``tests/libqtest.c`` and the API is defined
83in ``tests/libqtest.h``.
84
85Consider adding a new QTest case when you are introducing a new virtual
86hardware, or extending one if you are adding functionalities to an existing
87virtual device.
88
89On top of libqtest, a higher level library, ``libqos``, was created to
90encapsulate common tasks of device drivers, such as memory management and
91communicating with system buses or devices. Many virtual device tests use
92libqos instead of directly calling into libqtest.
93
94Steps to add a new QTest case are:
95
961. Create a new source file for the test. (More than one file can be added as
97   necessary.) For example, ``tests/test-foo-device.c``.
98
992. Write the test code with the glib and libqtest/libqos API. See also existing
100   tests and the library headers for reference.
101
1023. Register the new test in ``tests/Makefile.include``. Add the test executable
103   name to an appropriate ``check-qtest-*-y`` variable. For example:
104
105   ``check-qtest-generic-y = tests/test-foo-device$(EXESUF)``
106
1074. Add object dependencies of the executable in the Makefile, including the
108   test source file(s) and other interesting objects. For example:
109
110   ``tests/test-foo-device$(EXESUF): tests/test-foo-device.o $(libqos-obj-y)``
111
112Debugging a QTest failure is slightly harder than the unit test because the
113tests look up QEMU program names in the environment variables, such as
114``QTEST_QEMU_BINARY`` and ``QTEST_QEMU_IMG``, and also because it is not easy
115to attach gdb to the QEMU process spawned from the test. But manual invoking
116and using gdb on the test is still simple to do: find out the actual command
117from the output of
118
119.. code::
120
121  make check-qtest V=1
122
123which you can run manually.
124
125QAPI schema tests
126-----------------
127
128The QAPI schema tests validate the QAPI parser used by QMP, by feeding
129predefined input to the parser and comparing the result with the reference
130output.
131
132The input/output data is managed under the ``tests/qapi-schema`` directory.
133Each test case includes four files that have a common base name:
134
135  * ``${casename}.json`` - the file contains the JSON input for feeding the
136    parser
137  * ``${casename}.out`` - the file contains the expected stdout from the parser
138  * ``${casename}.err`` - the file contains the expected stderr from the parser
139  * ``${casename}.exit`` - the expected error code
140
141Consider adding a new QAPI schema test when you are making a change on the QAPI
142parser (either fixing a bug or extending/modifying the syntax). To do this:
143
1441. Add four files for the new case as explained above. For example:
145
146  ``$EDITOR tests/qapi-schema/foo.{json,out,err,exit}``.
147
1482. Add the new test in ``tests/Makefile.include``. For example:
149
150  ``qapi-schema += foo.json``
151
152check-block
153-----------
154
155``make check-block`` is a legacy command to invoke block layer iotests and is
156rarely used. See "QEMU iotests" section below for more information.
157
158GCC gcov support
159----------------
160
161``gcov`` is a GCC tool to analyze the testing coverage by
162instrumenting the tested code. To use it, configure QEMU with
163``--enable-gcov`` option and build. Then run ``make check`` as usual.
164
165If you want to gather coverage information on a single test the ``make
166clean-coverage`` target can be used to delete any existing coverage
167information before running a single test.
168
169You can generate a HTML coverage report by executing ``make
170coverage-report`` which will create
171./reports/coverage/coverage-report.html. If you want to create it
172elsewhere simply execute ``make /foo/bar/baz/coverage-report.html``.
173
174Further analysis can be conducted by running the ``gcov`` command
175directly on the various .gcda output files. Please read the ``gcov``
176documentation for more information.
177
178QEMU iotests
179============
180
181QEMU iotests, under the directory ``tests/qemu-iotests``, is the testing
182framework widely used to test block layer related features. It is higher level
183than "make check" tests and 99% of the code is written in bash or Python
184scripts.  The testing success criteria is golden output comparison, and the
185test files are named with numbers.
186
187To run iotests, make sure QEMU is built successfully, then switch to the
188``tests/qemu-iotests`` directory under the build directory, and run ``./check``
189with desired arguments from there.
190
191By default, "raw" format and "file" protocol is used; all tests will be
192executed, except the unsupported ones. You can override the format and protocol
193with arguments:
194
195.. code::
196
197  # test with qcow2 format
198  ./check -qcow2
199  # or test a different protocol
200  ./check -nbd
201
202It's also possible to list test numbers explicitly:
203
204.. code::
205
206  # run selected cases with qcow2 format
207  ./check -qcow2 001 030 153
208
209Cache mode can be selected with the "-c" option, which may help reveal bugs
210that are specific to certain cache mode.
211
212More options are supported by the ``./check`` script, run ``./check -h`` for
213help.
214
215Writing a new test case
216-----------------------
217
218Consider writing a tests case when you are making any changes to the block
219layer. An iotest case is usually the choice for that. There are already many
220test cases, so it is possible that extending one of them may achieve the goal
221and save the boilerplate to create one.  (Unfortunately, there isn't a 100%
222reliable way to find a related one out of hundreds of tests.  One approach is
223using ``git grep``.)
224
225Usually an iotest case consists of two files. One is an executable that
226produces output to stdout and stderr, the other is the expected reference
227output. They are given the same number in file names. E.g. Test script ``055``
228and reference output ``055.out``.
229
230In rare cases, when outputs differ between cache mode ``none`` and others, a
231``.out.nocache`` file is added. In other cases, when outputs differ between
232image formats, more than one ``.out`` files are created ending with the
233respective format names, e.g. ``178.out.qcow2`` and ``178.out.raw``.
234
235There isn't a hard rule about how to write a test script, but a new test is
236usually a (copy and) modification of an existing case.  There are a few
237commonly used ways to create a test:
238
239* A Bash script. It will make use of several environmental variables related
240  to the testing procedure, and could source a group of ``common.*`` libraries
241  for some common helper routines.
242
243* A Python unittest script. Import ``iotests`` and create a subclass of
244  ``iotests.QMPTestCase``, then call ``iotests.main`` method. The downside of
245  this approach is that the output is too scarce, and the script is considered
246  harder to debug.
247
248* A simple Python script without using unittest module. This could also import
249  ``iotests`` for launching QEMU and utilities etc, but it doesn't inherit
250  from ``iotests.QMPTestCase`` therefore doesn't use the Python unittest
251  execution. This is a combination of 1 and 2.
252
253Pick the language per your preference since both Bash and Python have
254comparable library support for invoking and interacting with QEMU programs. If
255you opt for Python, it is strongly recommended to write Python 3 compatible
256code.
257
258Both Python and Bash frameworks in iotests provide helpers to manage test
259images. They can be used to create and clean up images under the test
260directory. If no I/O or any protocol specific feature is needed, it is often
261more convenient to use the pseudo block driver, ``null-co://``, as the test
262image, which doesn't require image creation or cleaning up. Avoid system-wide
263devices or files whenever possible, such as ``/dev/null`` or ``/dev/zero``.
264Otherwise, image locking implications have to be considered.  For example,
265another application on the host may have locked the file, possibly leading to a
266test failure.  If using such devices are explicitly desired, consider adding
267``locking=off`` option to disable image locking.
268
269.. _docker-ref:
270
271Docker based tests
272==================
273
274Introduction
275------------
276
277The Docker testing framework in QEMU utilizes public Docker images to build and
278test QEMU in predefined and widely accessible Linux environments.  This makes
279it possible to expand the test coverage across distros, toolchain flavors and
280library versions.
281
282Prerequisites
283-------------
284
285Install "docker" with the system package manager and start the Docker service
286on your development machine, then make sure you have the privilege to run
287Docker commands. Typically it means setting up passwordless ``sudo docker``
288command or login as root. For example:
289
290.. code::
291
292  $ sudo yum install docker
293  $ # or `apt-get install docker` for Ubuntu, etc.
294  $ sudo systemctl start docker
295  $ sudo docker ps
296
297The last command should print an empty table, to verify the system is ready.
298
299An alternative method to set up permissions is by adding the current user to
300"docker" group and making the docker daemon socket file (by default
301``/var/run/docker.sock``) accessible to the group:
302
303.. code::
304
305  $ sudo groupadd docker
306  $ sudo usermod $USER -a -G docker
307  $ sudo chown :docker /var/run/docker.sock
308
309Note that any one of above configurations makes it possible for the user to
310exploit the whole host with Docker bind mounting or other privileged
311operations.  So only do it on development machines.
312
313Quickstart
314----------
315
316From source tree, type ``make docker`` to see the help. Testing can be started
317without configuring or building QEMU (``configure`` and ``make`` are done in
318the container, with parameters defined by the make target):
319
320.. code::
321
322  make docker-test-build@min-glib
323
324This will create a container instance using the ``min-glib`` image (the image
325is downloaded and initialized automatically), in which the ``test-build`` job
326is executed.
327
328Images
329------
330
331Along with many other images, the ``min-glib`` image is defined in a Dockerfile
332in ``tests/docker/dockerfiles/``, called ``min-glib.docker``. ``make docker``
333command will list all the available images.
334
335To add a new image, simply create a new ``.docker`` file under the
336``tests/docker/dockerfiles/`` directory.
337
338A ``.pre`` script can be added beside the ``.docker`` file, which will be
339executed before building the image under the build context directory. This is
340mainly used to do necessary host side setup. One such setup is ``binfmt_misc``,
341for example, to make qemu-user powered cross build containers work.
342
343Tests
344-----
345
346Different tests are added to cover various configurations to build and test
347QEMU.  Docker tests are the executables under ``tests/docker`` named
348``test-*``. They are typically shell scripts and are built on top of a shell
349library, ``tests/docker/common.rc``, which provides helpers to find the QEMU
350source and build it.
351
352The full list of tests is printed in the ``make docker`` help.
353
354Tools
355-----
356
357There are executables that are created to run in a specific Docker environment.
358This makes it easy to write scripts that have heavy or special dependencies,
359but are still very easy to use.
360
361Currently the only tool is ``travis``, which mimics the Travis-CI tests in a
362container. It runs in the ``travis`` image:
363
364.. code::
365
366  make docker-travis@travis
367
368Debugging a Docker test failure
369-------------------------------
370
371When CI tasks, maintainers or yourself report a Docker test failure, follow the
372below steps to debug it:
373
3741. Locally reproduce the failure with the reported command line. E.g. run
375   ``make docker-test-mingw@fedora J=8``.
3762. Add "V=1" to the command line, try again, to see the verbose output.
3773. Further add "DEBUG=1" to the command line. This will pause in a shell prompt
378   in the container right before testing starts. You could either manually
379   build QEMU and run tests from there, or press Ctrl-D to let the Docker
380   testing continue.
3814. If you press Ctrl-D, the same building and testing procedure will begin, and
382   will hopefully run into the error again. After that, you will be dropped to
383   the prompt for debug.
384
385Options
386-------
387
388Various options can be used to affect how Docker tests are done. The full
389list is in the ``make docker`` help text. The frequently used ones are:
390
391* ``V=1``: the same as in top level ``make``. It will be propagated to the
392  container and enable verbose output.
393* ``J=$N``: the number of parallel tasks in make commands in the container,
394  similar to the ``-j $N`` option in top level ``make``. (The ``-j`` option in
395  top level ``make`` will not be propagated into the container.)
396* ``DEBUG=1``: enables debug. See the previous "Debugging a Docker test
397  failure" section.
398
399VM testing
400==========
401
402This test suite contains scripts that bootstrap various guest images that have
403necessary packages to build QEMU. The basic usage is documented in ``Makefile``
404help which is displayed with ``make vm-help``.
405
406Quickstart
407----------
408
409Run ``make vm-help`` to list available make targets. Invoke a specific make
410command to run build test in an image. For example, ``make vm-build-freebsd``
411will build the source tree in the FreeBSD image. The command can be executed
412from either the source tree or the build dir; if the former, ``./configure`` is
413not needed. The command will then generate the test image in ``./tests/vm/``
414under the working directory.
415
416Note: images created by the scripts accept a well-known RSA key pair for SSH
417access, so they SHOULD NOT be exposed to external interfaces if you are
418concerned about attackers taking control of the guest and potentially
419exploiting a QEMU security bug to compromise the host.
420
421QEMU binary
422-----------
423
424By default, qemu-system-x86_64 is searched in $PATH to run the guest. If there
425isn't one, or if it is older than 2.10, the test won't work. In this case,
426provide the QEMU binary in env var: ``QEMU=/path/to/qemu-2.10+``.
427
428Make jobs
429---------
430
431The ``-j$X`` option in the make command line is not propagated into the VM,
432specify ``J=$X`` to control the make jobs in the guest.
433
434Debugging
435---------
436
437Add ``DEBUG=1`` and/or ``V=1`` to the make command to allow interactive
438debugging and verbose output. If this is not enough, see the next section.
439``V=1`` will be propagated down into the make jobs in the guest.
440
441Manual invocation
442-----------------
443
444Each guest script is an executable script with the same command line options.
445For example to work with the netbsd guest, use ``$QEMU_SRC/tests/vm/netbsd``:
446
447.. code::
448
449    $ cd $QEMU_SRC/tests/vm
450
451    # To bootstrap the image
452    $ ./netbsd --build-image --image /var/tmp/netbsd.img
453    <...>
454
455    # To run an arbitrary command in guest (the output will not be echoed unless
456    # --debug is added)
457    $ ./netbsd --debug --image /var/tmp/netbsd.img uname -a
458
459    # To build QEMU in guest
460    $ ./netbsd --debug --image /var/tmp/netbsd.img --build-qemu $QEMU_SRC
461
462    # To get to an interactive shell
463    $ ./netbsd --interactive --image /var/tmp/netbsd.img sh
464
465Adding new guests
466-----------------
467
468Please look at existing guest scripts for how to add new guests.
469
470Most importantly, create a subclass of BaseVM and implement ``build_image()``
471method and define ``BUILD_SCRIPT``, then finally call ``basevm.main()`` from
472the script's ``main()``.
473
474* Usually in ``build_image()``, a template image is downloaded from a
475  predefined URL. ``BaseVM._download_with_cache()`` takes care of the cache and
476  the checksum, so consider using it.
477
478* Once the image is downloaded, users, SSH server and QEMU build deps should
479  be set up:
480
481  - Root password set to ``BaseVM.ROOT_PASS``
482  - User ``BaseVM.GUEST_USER`` is created, and password set to
483    ``BaseVM.GUEST_PASS``
484  - SSH service is enabled and started on boot,
485    ``$QEMU_SRC/tests/keys/id_rsa.pub`` is added to ssh's ``authorized_keys``
486    file of both root and the normal user
487  - DHCP client service is enabled and started on boot, so that it can
488    automatically configure the virtio-net-pci NIC and communicate with QEMU
489    user net (10.0.2.2)
490  - Necessary packages are installed to untar the source tarball and build
491    QEMU
492
493* Write a proper ``BUILD_SCRIPT`` template, which should be a shell script that
494  untars a raw virtio-blk block device, which is the tarball data blob of the
495  QEMU source tree, then configure/build it. Running "make check" is also
496  recommended.
497
498Image fuzzer testing
499====================
500
501An image fuzzer was added to exercise format drivers. Currently only qcow2 is
502supported. To start the fuzzer, run
503
504.. code::
505
506  tests/image-fuzzer/runner.py -c '[["qemu-img", "info", "$test_img"]]' /tmp/test qcow2
507
508Alternatively, some command different from "qemu-img info" can be tested, by
509changing the ``-c`` option.
510
511Acceptance tests using the Avocado Framework
512============================================
513
514The ``tests/acceptance`` directory hosts functional tests, also known
515as acceptance level tests.  They're usually higher level tests, and
516may interact with external resources and with various guest operating
517systems.
518
519These tests are written using the Avocado Testing Framework (which must
520be installed separately) in conjunction with a the ``avocado_qemu.Test``
521class, implemented at ``tests/acceptance/avocado_qemu``.
522
523Tests based on ``avocado_qemu.Test`` can easily:
524
525 * Customize the command line arguments given to the convenience
526   ``self.vm`` attribute (a QEMUMachine instance)
527
528 * Interact with the QEMU monitor, send QMP commands and check
529   their results
530
531 * Interact with the guest OS, using the convenience console device
532   (which may be useful to assert the effectiveness and correctness of
533   command line arguments or QMP commands)
534
535 * Interact with external data files that accompany the test itself
536   (see ``self.get_data()``)
537
538 * Download (and cache) remote data files, such as firmware and kernel
539   images
540
541 * Have access to a library of guest OS images (by means of the
542   ``avocado.utils.vmimage`` library)
543
544 * Make use of various other test related utilities available at the
545   test class itself and at the utility library:
546
547   - http://avocado-framework.readthedocs.io/en/latest/api/test/avocado.html#avocado.Test
548   - http://avocado-framework.readthedocs.io/en/latest/api/utils/avocado.utils.html
549
550Running tests
551-------------
552
553You can run the acceptance tests simply by executing:
554
555.. code::
556
557  make check-acceptance
558
559This involves the automatic creation of Python virtual environment
560within the build tree (at ``tests/venv``) which will have all the
561right dependencies, and will save tests results also within the
562build tree (at ``tests/results``).
563
564Note: the build environment must be using a Python 3 stack, and have
565the ``venv`` and ``pip`` packages installed.  If necessary, make sure
566``configure`` is called with ``--python=`` and that those modules are
567available.  On Debian and Ubuntu based systems, depending on the
568specific version, they may be on packages named ``python3-venv`` and
569``python3-pip``.
570
571The scripts installed inside the virtual environment may be used
572without an "activation".  For instance, the Avocado test runner
573may be invoked by running:
574
575 .. code::
576
577  tests/venv/bin/avocado run $OPTION1 $OPTION2 tests/acceptance/
578
579Manual Installation
580-------------------
581
582To manually install Avocado and its dependencies, run:
583
584.. code::
585
586  pip install --user avocado-framework
587
588Alternatively, follow the instructions on this link:
589
590  http://avocado-framework.readthedocs.io/en/latest/GetStartedGuide.html#installing-avocado
591
592Overview
593--------
594
595The ``tests/acceptance/avocado_qemu`` directory provides the
596``avocado_qemu`` Python module, containing the ``avocado_qemu.Test``
597class.  Here's a simple usage example:
598
599.. code::
600
601  from avocado_qemu import Test
602
603
604  class Version(Test):
605      """
606      :avocado: tags=quick
607      """
608      def test_qmp_human_info_version(self):
609          self.vm.launch()
610          res = self.vm.command('human-monitor-command',
611                                command_line='info version')
612          self.assertRegexpMatches(res, r'^(\d+\.\d+\.\d)')
613
614To execute your test, run:
615
616.. code::
617
618  avocado run version.py
619
620Tests may be classified according to a convention by using docstring
621directives such as ``:avocado: tags=TAG1,TAG2``.  To run all tests
622in the current directory, tagged as "quick", run:
623
624.. code::
625
626  avocado run -t quick .
627
628The ``avocado_qemu.Test`` base test class
629-----------------------------------------
630
631The ``avocado_qemu.Test`` class has a number of characteristics that
632are worth being mentioned right away.
633
634First of all, it attempts to give each test a ready to use QEMUMachine
635instance, available at ``self.vm``.  Because many tests will tweak the
636QEMU command line, launching the QEMUMachine (by using ``self.vm.launch()``)
637is left to the test writer.
638
639The base test class has also support for tests with more than one
640QEMUMachine. The way to get machines is through the ``self.get_vm()``
641method which will return a QEMUMachine instance. The ``self.get_vm()``
642method accepts arguments that will be passed to the QEMUMachine creation
643and also an optional `name` attribute so you can identify a specific
644machine and get it more than once through the tests methods. A simple
645and hypothetical example follows:
646
647.. code::
648
649  from avocado_qemu import Test
650
651
652  class MultipleMachines(Test):
653      """
654      :avocado: enable
655      """
656      def test_multiple_machines(self):
657          first_machine = self.get_vm()
658          second_machine = self.get_vm()
659          self.get_vm(name='third_machine').launch()
660
661          first_machine.launch()
662          second_machine.launch()
663
664          first_res = first_machine.command(
665              'human-monitor-command',
666              command_line='info version')
667
668          second_res = second_machine.command(
669              'human-monitor-command',
670              command_line='info version')
671
672          third_res = self.get_vm(name='third_machine').command(
673              'human-monitor-command',
674              command_line='info version')
675
676          self.assertEquals(first_res, second_res, third_res)
677
678At test "tear down", ``avocado_qemu.Test`` handles all the QEMUMachines
679shutdown.
680
681QEMUMachine
682~~~~~~~~~~~
683
684The QEMUMachine API is already widely used in the Python iotests,
685device-crash-test and other Python scripts.  It's a wrapper around the
686execution of a QEMU binary, giving its users:
687
688 * the ability to set command line arguments to be given to the QEMU
689   binary
690
691 * a ready to use QMP connection and interface, which can be used to
692   send commands and inspect its results, as well as asynchronous
693   events
694
695 * convenience methods to set commonly used command line arguments in
696   a more succinct and intuitive way
697
698QEMU binary selection
699~~~~~~~~~~~~~~~~~~~~~
700
701The QEMU binary used for the ``self.vm`` QEMUMachine instance will
702primarily depend on the value of the ``qemu_bin`` parameter.  If it's
703not explicitly set, its default value will be the result of a dynamic
704probe in the same source tree.  A suitable binary will be one that
705targets the architecture matching host machine.
706
707Based on this description, test writers will usually rely on one of
708the following approaches:
709
7101) Set ``qemu_bin``, and use the given binary
711
7122) Do not set ``qemu_bin``, and use a QEMU binary named like
713   "${arch}-softmmu/qemu-system-${arch}", either in the current
714   working directory, or in the current source tree.
715
716The resulting ``qemu_bin`` value will be preserved in the
717``avocado_qemu.Test`` as an attribute with the same name.
718
719Attribute reference
720-------------------
721
722Besides the attributes and methods that are part of the base
723``avocado.Test`` class, the following attributes are available on any
724``avocado_qemu.Test`` instance.
725
726vm
727~~
728
729A QEMUMachine instance, initially configured according to the given
730``qemu_bin`` parameter.
731
732arch
733~~~~
734
735The architecture can be used on different levels of the stack, e.g. by
736the framework or by the test itself.  At the framework level, it will
737currently influence the selection of a QEMU binary (when one is not
738explicitly given).
739
740Tests are also free to use this attribute value, for their own needs.
741A test may, for instance, use the same value when selecting the
742architecture of a kernel or disk image to boot a VM with.
743
744The ``arch`` attribute will be set to the test parameter of the same
745name.  If one is not given explicitly, it will either be set to
746``None``, or, if the test is tagged with one (and only one)
747``:avocado: tags=arch:VALUE`` tag, it will be set to ``VALUE``.
748
749machine
750~~~~~~~
751
752The machine type that will be set to all QEMUMachine instances created
753by the test.
754
755The ``machine`` attribute will be set to the test parameter of the same
756name.  If one is not given explicitly, it will either be set to
757``None``, or, if the test is tagged with one (and only one)
758``:avocado: tags=machine:VALUE`` tag, it will be set to ``VALUE``.
759
760qemu_bin
761~~~~~~~~
762
763The preserved value of the ``qemu_bin`` parameter or the result of the
764dynamic probe for a QEMU binary in the current working directory or
765source tree.
766
767Parameter reference
768-------------------
769
770To understand how Avocado parameters are accessed by tests, and how
771they can be passed to tests, please refer to::
772
773  http://avocado-framework.readthedocs.io/en/latest/WritingTests.html#accessing-test-parameters
774
775Parameter values can be easily seen in the log files, and will look
776like the following:
777
778.. code::
779
780  PARAMS (key=qemu_bin, path=*, default=x86_64-softmmu/qemu-system-x86_64) => 'x86_64-softmmu/qemu-system-x86_64
781
782arch
783~~~~
784
785The architecture that will influence the selection of a QEMU binary
786(when one is not explicitly given).
787
788Tests are also free to use this parameter value, for their own needs.
789A test may, for instance, use the same value when selecting the
790architecture of a kernel or disk image to boot a VM with.
791
792This parameter has a direct relation with the ``arch`` attribute.  If
793not given, it will default to None.
794
795machine
796~~~~~~~
797
798The machine type that will be set to all QEMUMachine instances created
799by the test.
800
801
802qemu_bin
803~~~~~~~~
804
805The exact QEMU binary to be used on QEMUMachine.
806
807Uninstalling Avocado
808--------------------
809
810If you've followed the manual installation instructions above, you can
811easily uninstall Avocado.  Start by listing the packages you have
812installed::
813
814  pip list --user
815
816And remove any package you want with::
817
818  pip uninstall <package_name>
819
820If you've used ``make check-acceptance``, the Python virtual environment where
821Avocado is installed will be cleaned up as part of ``make check-clean``.
822
823Testing with "make check-tcg"
824=============================
825
826The check-tcg tests are intended for simple smoke tests of both
827linux-user and softmmu TCG functionality. However to build test
828programs for guest targets you need to have cross compilers available.
829If your distribution supports cross compilers you can do something as
830simple as::
831
832  apt install gcc-aarch64-linux-gnu
833
834The configure script will automatically pick up their presence.
835Sometimes compilers have slightly odd names so the availability of
836them can be prompted by passing in the appropriate configure option
837for the architecture in question, for example::
838
839  $(configure) --cross-cc-aarch64=aarch64-cc
840
841There is also a ``--cross-cc-flags-ARCH`` flag in case additional
842compiler flags are needed to build for a given target.
843
844If you have the ability to run containers as the user you can also
845take advantage of the build systems "Docker" support. It will then use
846containers to build any test case for an enabled guest where there is
847no system compiler available. See :ref: `_docker-ref` for details.
848
849Running subset of tests
850-----------------------
851
852You can build the tests for one architecture::
853
854  make build-tcg-tests-$TARGET
855
856And run with::
857
858  make run-tcg-tests-$TARGET
859
860Adding ``V=1`` to the invocation will show the details of how to
861invoke QEMU for the test which is useful for debugging tests.
862
863TCG test dependencies
864---------------------
865
866The TCG tests are deliberately very light on dependencies and are
867either totally bare with minimal gcc lib support (for softmmu tests)
868or just glibc (for linux-user tests). This is because getting a cross
869compiler to work with additional libraries can be challenging.
870
871Other TCG Tests
872---------------
873
874There are a number of out-of-tree test suites that are used for more
875extensive testing of processor features.
876
877KVM Unit Tests
878~~~~~~~~~~~~~~
879
880The KVM unit tests are designed to run as a Guest OS under KVM but
881there is no reason why they can't exercise the TCG as well. It
882provides a minimal OS kernel with hooks for enabling the MMU as well
883as reporting test results via a special device::
884
885  https://git.kernel.org/pub/scm/virt/kvm/kvm-unit-tests.git
886
887Linux Test Project
888~~~~~~~~~~~~~~~~~~
889
890The LTP is focused on exercising the syscall interface of a Linux
891kernel. It checks that syscalls behave as documented and strives to
892exercise as many corner cases as possible. It is a useful test suite
893to run to exercise QEMU's linux-user code::
894
895  https://linux-test-project.github.io/
896