xref: /openbmc/qemu/docs/devel/testing/avocado.rst (revision 0abdd970)
12133c2abSThomas Huth.. _checkavocado-ref:
22133c2abSThomas Huth
32133c2abSThomas Huth
42133c2abSThomas HuthIntegration testing with Avocado
52133c2abSThomas Huth================================
62133c2abSThomas Huth
72133c2abSThomas HuthThe ``tests/avocado`` directory hosts integration tests. They're usually
82133c2abSThomas Huthhigher level tests, and may interact with external resources and with
92133c2abSThomas Huthvarious guest operating systems.
102133c2abSThomas Huth
11*0abdd970SThomas HuthThese tests are written using the Avocado Testing Framework (which must be
12*0abdd970SThomas Huthinstalled separately) in conjunction with a the ``avocado_qemu.QemuSystemTest``
132133c2abSThomas Huthclass, implemented at ``tests/avocado/avocado_qemu``.
142133c2abSThomas Huth
15*0abdd970SThomas HuthTests based on ``avocado_qemu.QemuSystemTest`` can easily:
162133c2abSThomas Huth
172133c2abSThomas Huth * Customize the command line arguments given to the convenience
182133c2abSThomas Huth   ``self.vm`` attribute (a QEMUMachine instance)
192133c2abSThomas Huth
202133c2abSThomas Huth * Interact with the QEMU monitor, send QMP commands and check
212133c2abSThomas Huth   their results
222133c2abSThomas Huth
232133c2abSThomas Huth * Interact with the guest OS, using the convenience console device
242133c2abSThomas Huth   (which may be useful to assert the effectiveness and correctness of
252133c2abSThomas Huth   command line arguments or QMP commands)
262133c2abSThomas Huth
272133c2abSThomas Huth * Interact with external data files that accompany the test itself
282133c2abSThomas Huth   (see ``self.get_data()``)
292133c2abSThomas Huth
302133c2abSThomas Huth * Download (and cache) remote data files, such as firmware and kernel
312133c2abSThomas Huth   images
322133c2abSThomas Huth
332133c2abSThomas Huth * Have access to a library of guest OS images (by means of the
342133c2abSThomas Huth   ``avocado.utils.vmimage`` library)
352133c2abSThomas Huth
362133c2abSThomas Huth * Make use of various other test related utilities available at the
372133c2abSThomas Huth   test class itself and at the utility library:
382133c2abSThomas Huth
392133c2abSThomas Huth   - http://avocado-framework.readthedocs.io/en/latest/api/test/avocado.html#avocado.Test
402133c2abSThomas Huth   - http://avocado-framework.readthedocs.io/en/latest/api/utils/avocado.utils.html
412133c2abSThomas Huth
422133c2abSThomas HuthRunning tests
432133c2abSThomas Huth-------------
442133c2abSThomas Huth
452133c2abSThomas HuthYou can run the avocado tests simply by executing:
462133c2abSThomas Huth
472133c2abSThomas Huth.. code::
482133c2abSThomas Huth
492133c2abSThomas Huth  make check-avocado
502133c2abSThomas Huth
512133c2abSThomas HuthThis involves the automatic installation, from PyPI, of all the
522133c2abSThomas Huthnecessary avocado-framework dependencies into the QEMU venv within the
532133c2abSThomas Huthbuild tree (at ``./pyvenv``). Test results are also saved within the
542133c2abSThomas Huthbuild tree (at ``tests/results``).
552133c2abSThomas Huth
562133c2abSThomas HuthNote: the build environment must be using a Python 3 stack, and have
572133c2abSThomas Huththe ``venv`` and ``pip`` packages installed.  If necessary, make sure
582133c2abSThomas Huth``configure`` is called with ``--python=`` and that those modules are
592133c2abSThomas Huthavailable.  On Debian and Ubuntu based systems, depending on the
602133c2abSThomas Huthspecific version, they may be on packages named ``python3-venv`` and
612133c2abSThomas Huth``python3-pip``.
622133c2abSThomas Huth
632133c2abSThomas HuthIt is also possible to run tests based on tags using the
642133c2abSThomas Huth``make check-avocado`` command and the ``AVOCADO_TAGS`` environment
652133c2abSThomas Huthvariable:
662133c2abSThomas Huth
672133c2abSThomas Huth.. code::
682133c2abSThomas Huth
692133c2abSThomas Huth   make check-avocado AVOCADO_TAGS=quick
702133c2abSThomas Huth
712133c2abSThomas HuthNote that tags separated with commas have an AND behavior, while tags
722133c2abSThomas Huthseparated by spaces have an OR behavior. For more information on Avocado
732133c2abSThomas Huthtags, see:
742133c2abSThomas Huth
752133c2abSThomas Huth https://avocado-framework.readthedocs.io/en/latest/guides/user/chapters/tags.html
762133c2abSThomas Huth
772133c2abSThomas HuthTo run a single test file, a couple of them, or a test within a file
782133c2abSThomas Huthusing the ``make check-avocado`` command, set the ``AVOCADO_TESTS``
792133c2abSThomas Huthenvironment variable with the test files or test names. To run all
802133c2abSThomas Huthtests from a single file, use:
812133c2abSThomas Huth
822133c2abSThomas Huth .. code::
832133c2abSThomas Huth
842133c2abSThomas Huth  make check-avocado AVOCADO_TESTS=$FILEPATH
852133c2abSThomas Huth
862133c2abSThomas HuthThe same is valid to run tests from multiple test files:
872133c2abSThomas Huth
882133c2abSThomas Huth .. code::
892133c2abSThomas Huth
902133c2abSThomas Huth  make check-avocado AVOCADO_TESTS='$FILEPATH1 $FILEPATH2'
912133c2abSThomas Huth
922133c2abSThomas HuthTo run a single test within a file, use:
932133c2abSThomas Huth
942133c2abSThomas Huth .. code::
952133c2abSThomas Huth
962133c2abSThomas Huth  make check-avocado AVOCADO_TESTS=$FILEPATH:$TESTCLASS.$TESTNAME
972133c2abSThomas Huth
982133c2abSThomas HuthThe same is valid to run single tests from multiple test files:
992133c2abSThomas Huth
1002133c2abSThomas Huth .. code::
1012133c2abSThomas Huth
1022133c2abSThomas Huth  make check-avocado AVOCADO_TESTS='$FILEPATH1:$TESTCLASS1.$TESTNAME1 $FILEPATH2:$TESTCLASS2.$TESTNAME2'
1032133c2abSThomas Huth
1042133c2abSThomas HuthThe scripts installed inside the virtual environment may be used
1052133c2abSThomas Huthwithout an "activation".  For instance, the Avocado test runner
1062133c2abSThomas Huthmay be invoked by running:
1072133c2abSThomas Huth
1082133c2abSThomas Huth .. code::
1092133c2abSThomas Huth
1102133c2abSThomas Huth  pyvenv/bin/avocado run $OPTION1 $OPTION2 tests/avocado/
1112133c2abSThomas Huth
1122133c2abSThomas HuthNote that if ``make check-avocado`` was not executed before, it is
1132133c2abSThomas Huthpossible to create the Python virtual environment with the dependencies
1142133c2abSThomas Huthneeded running:
1152133c2abSThomas Huth
1162133c2abSThomas Huth .. code::
1172133c2abSThomas Huth
1182133c2abSThomas Huth  make check-venv
1192133c2abSThomas Huth
1202133c2abSThomas HuthIt is also possible to run tests from a single file or a single test within
1212133c2abSThomas Hutha test file. To run tests from a single file within the build tree, use:
1222133c2abSThomas Huth
1232133c2abSThomas Huth .. code::
1242133c2abSThomas Huth
1252133c2abSThomas Huth  pyvenv/bin/avocado run tests/avocado/$TESTFILE
1262133c2abSThomas Huth
1272133c2abSThomas HuthTo run a single test within a test file, use:
1282133c2abSThomas Huth
1292133c2abSThomas Huth .. code::
1302133c2abSThomas Huth
1312133c2abSThomas Huth  pyvenv/bin/avocado run tests/avocado/$TESTFILE:$TESTCLASS.$TESTNAME
1322133c2abSThomas Huth
1332133c2abSThomas HuthValid test names are visible in the output from any previous execution
1342133c2abSThomas Huthof Avocado or ``make check-avocado``, and can also be queried using:
1352133c2abSThomas Huth
1362133c2abSThomas Huth .. code::
1372133c2abSThomas Huth
1382133c2abSThomas Huth  pyvenv/bin/avocado list tests/avocado
1392133c2abSThomas Huth
1402133c2abSThomas HuthManual Installation
1412133c2abSThomas Huth-------------------
1422133c2abSThomas Huth
1432133c2abSThomas HuthTo manually install Avocado and its dependencies, run:
1442133c2abSThomas Huth
1452133c2abSThomas Huth.. code::
1462133c2abSThomas Huth
1472133c2abSThomas Huth  pip install --user avocado-framework
1482133c2abSThomas Huth
1492133c2abSThomas HuthAlternatively, follow the instructions on this link:
1502133c2abSThomas Huth
1512133c2abSThomas Huth  https://avocado-framework.readthedocs.io/en/latest/guides/user/chapters/installing.html
1522133c2abSThomas Huth
1532133c2abSThomas HuthOverview
1542133c2abSThomas Huth--------
1552133c2abSThomas Huth
1562133c2abSThomas HuthThe ``tests/avocado/avocado_qemu`` directory provides the
157*0abdd970SThomas Huth``avocado_qemu`` Python module, containing the ``avocado_qemu.QemuSystemTest``
1582133c2abSThomas Huthclass.  Here's a simple usage example:
1592133c2abSThomas Huth
1602133c2abSThomas Huth.. code::
1612133c2abSThomas Huth
1622133c2abSThomas Huth  from avocado_qemu import QemuSystemTest
1632133c2abSThomas Huth
1642133c2abSThomas Huth
1652133c2abSThomas Huth  class Version(QemuSystemTest):
1662133c2abSThomas Huth      """
1672133c2abSThomas Huth      :avocado: tags=quick
1682133c2abSThomas Huth      """
1692133c2abSThomas Huth      def test_qmp_human_info_version(self):
1702133c2abSThomas Huth          self.vm.launch()
1712133c2abSThomas Huth          res = self.vm.cmd('human-monitor-command',
1722133c2abSThomas Huth                            command_line='info version')
1732133c2abSThomas Huth          self.assertRegex(res, r'^(\d+\.\d+\.\d)')
1742133c2abSThomas Huth
1752133c2abSThomas HuthTo execute your test, run:
1762133c2abSThomas Huth
1772133c2abSThomas Huth.. code::
1782133c2abSThomas Huth
1792133c2abSThomas Huth  avocado run version.py
1802133c2abSThomas Huth
1812133c2abSThomas HuthTests may be classified according to a convention by using docstring
1822133c2abSThomas Huthdirectives such as ``:avocado: tags=TAG1,TAG2``.  To run all tests
1832133c2abSThomas Huthin the current directory, tagged as "quick", run:
1842133c2abSThomas Huth
1852133c2abSThomas Huth.. code::
1862133c2abSThomas Huth
1872133c2abSThomas Huth  avocado run -t quick .
1882133c2abSThomas Huth
189*0abdd970SThomas HuthThe ``avocado_qemu.QemuSystemTest`` base test class
190*0abdd970SThomas Huth^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1912133c2abSThomas Huth
192*0abdd970SThomas HuthThe ``avocado_qemu.QemuSystemTest`` class has a number of characteristics
193*0abdd970SThomas Huththat are worth being mentioned right away.
1942133c2abSThomas Huth
1952133c2abSThomas HuthFirst of all, it attempts to give each test a ready to use QEMUMachine
1962133c2abSThomas Huthinstance, available at ``self.vm``.  Because many tests will tweak the
1972133c2abSThomas HuthQEMU command line, launching the QEMUMachine (by using ``self.vm.launch()``)
1982133c2abSThomas Huthis left to the test writer.
1992133c2abSThomas Huth
2002133c2abSThomas HuthThe base test class has also support for tests with more than one
2012133c2abSThomas HuthQEMUMachine. The way to get machines is through the ``self.get_vm()``
2022133c2abSThomas Huthmethod which will return a QEMUMachine instance. The ``self.get_vm()``
2032133c2abSThomas Huthmethod accepts arguments that will be passed to the QEMUMachine creation
2042133c2abSThomas Huthand also an optional ``name`` attribute so you can identify a specific
2052133c2abSThomas Huthmachine and get it more than once through the tests methods. A simple
2062133c2abSThomas Huthand hypothetical example follows:
2072133c2abSThomas Huth
2082133c2abSThomas Huth.. code::
2092133c2abSThomas Huth
2102133c2abSThomas Huth  from avocado_qemu import QemuSystemTest
2112133c2abSThomas Huth
2122133c2abSThomas Huth
2132133c2abSThomas Huth  class MultipleMachines(QemuSystemTest):
2142133c2abSThomas Huth      def test_multiple_machines(self):
2152133c2abSThomas Huth          first_machine = self.get_vm()
2162133c2abSThomas Huth          second_machine = self.get_vm()
2172133c2abSThomas Huth          self.get_vm(name='third_machine').launch()
2182133c2abSThomas Huth
2192133c2abSThomas Huth          first_machine.launch()
2202133c2abSThomas Huth          second_machine.launch()
2212133c2abSThomas Huth
2222133c2abSThomas Huth          first_res = first_machine.cmd(
2232133c2abSThomas Huth              'human-monitor-command',
2242133c2abSThomas Huth              command_line='info version')
2252133c2abSThomas Huth
2262133c2abSThomas Huth          second_res = second_machine.cmd(
2272133c2abSThomas Huth              'human-monitor-command',
2282133c2abSThomas Huth              command_line='info version')
2292133c2abSThomas Huth
2302133c2abSThomas Huth          third_res = self.get_vm(name='third_machine').cmd(
2312133c2abSThomas Huth              'human-monitor-command',
2322133c2abSThomas Huth              command_line='info version')
2332133c2abSThomas Huth
2342133c2abSThomas Huth          self.assertEqual(first_res, second_res, third_res)
2352133c2abSThomas Huth
236*0abdd970SThomas HuthAt test "tear down", ``avocado_qemu.QemuSystemTest`` handles all the
237*0abdd970SThomas HuthQEMUMachines shutdown.
2382133c2abSThomas Huth
2392133c2abSThomas HuthThe ``avocado_qemu.LinuxTest`` base test class
2402133c2abSThomas Huth^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2412133c2abSThomas Huth
2422133c2abSThomas HuthThe ``avocado_qemu.LinuxTest`` is further specialization of the
243*0abdd970SThomas Huth``avocado_qemu.QemuSystemTest`` class, so it contains all the characteristics
244*0abdd970SThomas Huthof the later plus some extra features.
2452133c2abSThomas Huth
2462133c2abSThomas HuthFirst of all, this base class is intended for tests that need to
2472133c2abSThomas Huthinteract with a fully booted and operational Linux guest.  At this
2482133c2abSThomas Huthtime, it uses a Fedora 31 guest image.  The most basic example looks
2492133c2abSThomas Huthlike this:
2502133c2abSThomas Huth
2512133c2abSThomas Huth.. code::
2522133c2abSThomas Huth
2532133c2abSThomas Huth  from avocado_qemu import LinuxTest
2542133c2abSThomas Huth
2552133c2abSThomas Huth
2562133c2abSThomas Huth  class SomeTest(LinuxTest):
2572133c2abSThomas Huth
2582133c2abSThomas Huth      def test(self):
2592133c2abSThomas Huth          self.launch_and_wait()
2602133c2abSThomas Huth          self.ssh_command('some_command_to_be_run_in_the_guest')
2612133c2abSThomas Huth
2622133c2abSThomas HuthPlease refer to tests that use ``avocado_qemu.LinuxTest`` under
2632133c2abSThomas Huth``tests/avocado`` for more examples.
2642133c2abSThomas Huth
2652133c2abSThomas HuthQEMUMachine
2662133c2abSThomas Huth-----------
2672133c2abSThomas Huth
2682133c2abSThomas HuthThe QEMUMachine API is already widely used in the Python iotests,
2692133c2abSThomas Huthdevice-crash-test and other Python scripts.  It's a wrapper around the
2702133c2abSThomas Huthexecution of a QEMU binary, giving its users:
2712133c2abSThomas Huth
2722133c2abSThomas Huth * the ability to set command line arguments to be given to the QEMU
2732133c2abSThomas Huth   binary
2742133c2abSThomas Huth
2752133c2abSThomas Huth * a ready to use QMP connection and interface, which can be used to
2762133c2abSThomas Huth   send commands and inspect its results, as well as asynchronous
2772133c2abSThomas Huth   events
2782133c2abSThomas Huth
2792133c2abSThomas Huth * convenience methods to set commonly used command line arguments in
2802133c2abSThomas Huth   a more succinct and intuitive way
2812133c2abSThomas Huth
2822133c2abSThomas HuthQEMU binary selection
2832133c2abSThomas Huth^^^^^^^^^^^^^^^^^^^^^
2842133c2abSThomas Huth
2852133c2abSThomas HuthThe QEMU binary used for the ``self.vm`` QEMUMachine instance will
2862133c2abSThomas Huthprimarily depend on the value of the ``qemu_bin`` parameter.  If it's
2872133c2abSThomas Huthnot explicitly set, its default value will be the result of a dynamic
2882133c2abSThomas Huthprobe in the same source tree.  A suitable binary will be one that
2892133c2abSThomas Huthtargets the architecture matching host machine.
2902133c2abSThomas Huth
2912133c2abSThomas HuthBased on this description, test writers will usually rely on one of
2922133c2abSThomas Huththe following approaches:
2932133c2abSThomas Huth
2942133c2abSThomas Huth1) Set ``qemu_bin``, and use the given binary
2952133c2abSThomas Huth
2962133c2abSThomas Huth2) Do not set ``qemu_bin``, and use a QEMU binary named like
2972133c2abSThomas Huth   "qemu-system-${arch}", either in the current
2982133c2abSThomas Huth   working directory, or in the current source tree.
2992133c2abSThomas Huth
3002133c2abSThomas HuthThe resulting ``qemu_bin`` value will be preserved in the
301*0abdd970SThomas Huth``avocado_qemu.QemuSystemTest`` as an attribute with the same name.
3022133c2abSThomas Huth
3032133c2abSThomas HuthAttribute reference
3042133c2abSThomas Huth-------------------
3052133c2abSThomas Huth
3062133c2abSThomas HuthTest
3072133c2abSThomas Huth^^^^
3082133c2abSThomas Huth
3092133c2abSThomas HuthBesides the attributes and methods that are part of the base
3102133c2abSThomas Huth``avocado.Test`` class, the following attributes are available on any
311*0abdd970SThomas Huth``avocado_qemu.QemuSystemTest`` instance.
3122133c2abSThomas Huth
3132133c2abSThomas Huthvm
3142133c2abSThomas Huth""
3152133c2abSThomas Huth
3162133c2abSThomas HuthA QEMUMachine instance, initially configured according to the given
3172133c2abSThomas Huth``qemu_bin`` parameter.
3182133c2abSThomas Huth
3192133c2abSThomas Hutharch
3202133c2abSThomas Huth""""
3212133c2abSThomas Huth
3222133c2abSThomas HuthThe architecture can be used on different levels of the stack, e.g. by
3232133c2abSThomas Huththe framework or by the test itself.  At the framework level, it will
3242133c2abSThomas Huthcurrently influence the selection of a QEMU binary (when one is not
3252133c2abSThomas Huthexplicitly given).
3262133c2abSThomas Huth
3272133c2abSThomas HuthTests are also free to use this attribute value, for their own needs.
3282133c2abSThomas HuthA test may, for instance, use the same value when selecting the
3292133c2abSThomas Hutharchitecture of a kernel or disk image to boot a VM with.
3302133c2abSThomas Huth
3312133c2abSThomas HuthThe ``arch`` attribute will be set to the test parameter of the same
3322133c2abSThomas Huthname.  If one is not given explicitly, it will either be set to
3332133c2abSThomas Huth``None``, or, if the test is tagged with one (and only one)
3342133c2abSThomas Huth``:avocado: tags=arch:VALUE`` tag, it will be set to ``VALUE``.
3352133c2abSThomas Huth
3362133c2abSThomas Huthcpu
3372133c2abSThomas Huth"""
3382133c2abSThomas Huth
3392133c2abSThomas HuthThe cpu model that will be set to all QEMUMachine instances created
3402133c2abSThomas Huthby the test.
3412133c2abSThomas Huth
3422133c2abSThomas HuthThe ``cpu`` attribute will be set to the test parameter of the same
3432133c2abSThomas Huthname. If one is not given explicitly, it will either be set to
3442133c2abSThomas Huth``None ``, or, if the test is tagged with one (and only one)
3452133c2abSThomas Huth``:avocado: tags=cpu:VALUE`` tag, it will be set to ``VALUE``.
3462133c2abSThomas Huth
3472133c2abSThomas Huthmachine
3482133c2abSThomas Huth"""""""
3492133c2abSThomas Huth
3502133c2abSThomas HuthThe machine type that will be set to all QEMUMachine instances created
3512133c2abSThomas Huthby the test.
3522133c2abSThomas Huth
3532133c2abSThomas HuthThe ``machine`` attribute will be set to the test parameter of the same
3542133c2abSThomas Huthname.  If one is not given explicitly, it will either be set to
3552133c2abSThomas Huth``None``, or, if the test is tagged with one (and only one)
3562133c2abSThomas Huth``:avocado: tags=machine:VALUE`` tag, it will be set to ``VALUE``.
3572133c2abSThomas Huth
3582133c2abSThomas Huthqemu_bin
3592133c2abSThomas Huth""""""""
3602133c2abSThomas Huth
3612133c2abSThomas HuthThe preserved value of the ``qemu_bin`` parameter or the result of the
3622133c2abSThomas Huthdynamic probe for a QEMU binary in the current working directory or
3632133c2abSThomas Huthsource tree.
3642133c2abSThomas Huth
3652133c2abSThomas HuthLinuxTest
3662133c2abSThomas Huth^^^^^^^^^
3672133c2abSThomas Huth
368*0abdd970SThomas HuthBesides the attributes present on the ``avocado_qemu.QemuSystemTest`` base
3692133c2abSThomas Huthclass, the ``avocado_qemu.LinuxTest`` adds the following attributes:
3702133c2abSThomas Huth
3712133c2abSThomas Huthdistro
3722133c2abSThomas Huth""""""
3732133c2abSThomas Huth
3742133c2abSThomas HuthThe name of the Linux distribution used as the guest image for the
3752133c2abSThomas Huthtest.  The name should match the **Provider** column on the list
3762133c2abSThomas Huthof images supported by the avocado.utils.vmimage library:
3772133c2abSThomas Huth
3782133c2abSThomas Huthhttps://avocado-framework.readthedocs.io/en/latest/guides/writer/libs/vmimage.html#supported-images
3792133c2abSThomas Huth
3802133c2abSThomas Huthdistro_version
3812133c2abSThomas Huth""""""""""""""
3822133c2abSThomas Huth
3832133c2abSThomas HuthThe version of the Linux distribution as the guest image for the
3842133c2abSThomas Huthtest.  The name should match the **Version** column on the list
3852133c2abSThomas Huthof images supported by the avocado.utils.vmimage library:
3862133c2abSThomas Huth
3872133c2abSThomas Huthhttps://avocado-framework.readthedocs.io/en/latest/guides/writer/libs/vmimage.html#supported-images
3882133c2abSThomas Huth
3892133c2abSThomas Huthdistro_checksum
3902133c2abSThomas Huth"""""""""""""""
3912133c2abSThomas Huth
3922133c2abSThomas HuthThe sha256 hash of the guest image file used for the test.
3932133c2abSThomas Huth
3942133c2abSThomas HuthIf this value is not set in the code or by a test parameter (with the
3952133c2abSThomas Huthsame name), no validation on the integrity of the image will be
3962133c2abSThomas Huthperformed.
3972133c2abSThomas Huth
3982133c2abSThomas HuthParameter reference
3992133c2abSThomas Huth-------------------
4002133c2abSThomas Huth
4012133c2abSThomas HuthTo understand how Avocado parameters are accessed by tests, and how
4022133c2abSThomas Huththey can be passed to tests, please refer to::
4032133c2abSThomas Huth
4042133c2abSThomas Huth  https://avocado-framework.readthedocs.io/en/latest/guides/writer/chapters/writing.html#accessing-test-parameters
4052133c2abSThomas Huth
4062133c2abSThomas HuthParameter values can be easily seen in the log files, and will look
4072133c2abSThomas Huthlike the following:
4082133c2abSThomas Huth
4092133c2abSThomas Huth.. code::
4102133c2abSThomas Huth
4112133c2abSThomas Huth  PARAMS (key=qemu_bin, path=*, default=./qemu-system-x86_64) => './qemu-system-x86_64
4122133c2abSThomas Huth
4132133c2abSThomas HuthTest
4142133c2abSThomas Huth^^^^
4152133c2abSThomas Huth
4162133c2abSThomas Hutharch
4172133c2abSThomas Huth""""
4182133c2abSThomas Huth
4192133c2abSThomas HuthThe architecture that will influence the selection of a QEMU binary
4202133c2abSThomas Huth(when one is not explicitly given).
4212133c2abSThomas Huth
4222133c2abSThomas HuthTests are also free to use this parameter value, for their own needs.
4232133c2abSThomas HuthA test may, for instance, use the same value when selecting the
4242133c2abSThomas Hutharchitecture of a kernel or disk image to boot a VM with.
4252133c2abSThomas Huth
4262133c2abSThomas HuthThis parameter has a direct relation with the ``arch`` attribute.  If
4272133c2abSThomas Huthnot given, it will default to None.
4282133c2abSThomas Huth
4292133c2abSThomas Huthcpu
4302133c2abSThomas Huth"""
4312133c2abSThomas Huth
4322133c2abSThomas HuthThe cpu model that will be set to all QEMUMachine instances created
4332133c2abSThomas Huthby the test.
4342133c2abSThomas Huth
4352133c2abSThomas Huthmachine
4362133c2abSThomas Huth"""""""
4372133c2abSThomas Huth
4382133c2abSThomas HuthThe machine type that will be set to all QEMUMachine instances created
4392133c2abSThomas Huthby the test.
4402133c2abSThomas Huth
4412133c2abSThomas Huthqemu_bin
4422133c2abSThomas Huth""""""""
4432133c2abSThomas Huth
4442133c2abSThomas HuthThe exact QEMU binary to be used on QEMUMachine.
4452133c2abSThomas Huth
4462133c2abSThomas HuthLinuxTest
4472133c2abSThomas Huth^^^^^^^^^
4482133c2abSThomas Huth
449*0abdd970SThomas HuthBesides the parameters present on the ``avocado_qemu.QemuSystemTest`` base
4502133c2abSThomas Huthclass, the ``avocado_qemu.LinuxTest`` adds the following parameters:
4512133c2abSThomas Huth
4522133c2abSThomas Huthdistro
4532133c2abSThomas Huth""""""
4542133c2abSThomas Huth
4552133c2abSThomas HuthThe name of the Linux distribution used as the guest image for the
4562133c2abSThomas Huthtest.  The name should match the **Provider** column on the list
4572133c2abSThomas Huthof images supported by the avocado.utils.vmimage library:
4582133c2abSThomas Huth
4592133c2abSThomas Huthhttps://avocado-framework.readthedocs.io/en/latest/guides/writer/libs/vmimage.html#supported-images
4602133c2abSThomas Huth
4612133c2abSThomas Huthdistro_version
4622133c2abSThomas Huth""""""""""""""
4632133c2abSThomas Huth
4642133c2abSThomas HuthThe version of the Linux distribution as the guest image for the
4652133c2abSThomas Huthtest.  The name should match the **Version** column on the list
4662133c2abSThomas Huthof images supported by the avocado.utils.vmimage library:
4672133c2abSThomas Huth
4682133c2abSThomas Huthhttps://avocado-framework.readthedocs.io/en/latest/guides/writer/libs/vmimage.html#supported-images
4692133c2abSThomas Huth
4702133c2abSThomas Huthdistro_checksum
4712133c2abSThomas Huth"""""""""""""""
4722133c2abSThomas Huth
4732133c2abSThomas HuthThe sha256 hash of the guest image file used for the test.
4742133c2abSThomas Huth
4752133c2abSThomas HuthIf this value is not set in the code or by this parameter no
4762133c2abSThomas Huthvalidation on the integrity of the image will be performed.
4772133c2abSThomas Huth
4782133c2abSThomas HuthSkipping tests
4792133c2abSThomas Huth--------------
4802133c2abSThomas Huth
4812133c2abSThomas HuthThe Avocado framework provides Python decorators which allow for easily skip
4822133c2abSThomas Huthtests running under certain conditions. For example, on the lack of a binary
4832133c2abSThomas Huthon the test system or when the running environment is a CI system. For further
4842133c2abSThomas Huthinformation about those decorators, please refer to::
4852133c2abSThomas Huth
4862133c2abSThomas Huth  https://avocado-framework.readthedocs.io/en/latest/guides/writer/chapters/writing.html#skipping-tests
4872133c2abSThomas Huth
4882133c2abSThomas HuthWhile the conditions for skipping tests are often specifics of each one, there
4892133c2abSThomas Huthare recurring scenarios identified by the QEMU developers and the use of
4902133c2abSThomas Huthenvironment variables became a kind of standard way to enable/disable tests.
4912133c2abSThomas Huth
4922133c2abSThomas HuthHere is a list of the most used variables:
4932133c2abSThomas Huth
4942133c2abSThomas HuthAVOCADO_ALLOW_LARGE_STORAGE
4952133c2abSThomas Huth^^^^^^^^^^^^^^^^^^^^^^^^^^^
4962133c2abSThomas HuthTests which are going to fetch or produce assets considered *large* are not
4972133c2abSThomas Huthgoing to run unless that ``AVOCADO_ALLOW_LARGE_STORAGE=1`` is exported on
4982133c2abSThomas Huththe environment.
4992133c2abSThomas Huth
5002133c2abSThomas HuthThe definition of *large* is a bit arbitrary here, but it usually means an
5012133c2abSThomas Huthasset which occupies at least 1GB of size on disk when uncompressed.
5022133c2abSThomas Huth
5032133c2abSThomas HuthSPEED
5042133c2abSThomas Huth^^^^^
5052133c2abSThomas HuthTests which have a long runtime will not be run unless ``SPEED=slow`` is
5062133c2abSThomas Huthexported on the environment.
5072133c2abSThomas Huth
5082133c2abSThomas HuthThe definition of *long* is a bit arbitrary here, and it depends on the
5092133c2abSThomas Huthusefulness of the test too. A unique test is worth spending more time on,
5102133c2abSThomas Huthsmall variations on existing tests perhaps less so. As a rough guide,
5112133c2abSThomas Hutha test or set of similar tests which take more than 100 seconds to
5122133c2abSThomas Huthcomplete.
5132133c2abSThomas Huth
5142133c2abSThomas HuthAVOCADO_ALLOW_UNTRUSTED_CODE
5152133c2abSThomas Huth^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5162133c2abSThomas HuthThere are tests which will boot a kernel image or firmware that can be
5172133c2abSThomas Huthconsidered not safe to run on the developer's workstation, thus they are
5182133c2abSThomas Huthskipped by default. The definition of *not safe* is also arbitrary but
5192133c2abSThomas Huthusually it means a blob which either its source or build process aren't
5202133c2abSThomas Huthpublic available.
5212133c2abSThomas Huth
5222133c2abSThomas HuthYou should export ``AVOCADO_ALLOW_UNTRUSTED_CODE=1`` on the environment in
5232133c2abSThomas Huthorder to allow tests which make use of those kind of assets.
5242133c2abSThomas Huth
5252133c2abSThomas HuthAVOCADO_TIMEOUT_EXPECTED
5262133c2abSThomas Huth^^^^^^^^^^^^^^^^^^^^^^^^
5272133c2abSThomas HuthThe Avocado framework has a timeout mechanism which interrupts tests to avoid the
5282133c2abSThomas Huthtest suite of getting stuck. The timeout value can be set via test parameter or
5292133c2abSThomas Huthproperty defined in the test class, for further details::
5302133c2abSThomas Huth
5312133c2abSThomas Huth  https://avocado-framework.readthedocs.io/en/latest/guides/writer/chapters/writing.html#setting-a-test-timeout
5322133c2abSThomas Huth
5332133c2abSThomas HuthEven though the timeout can be set by the test developer, there are some tests
5342133c2abSThomas Huththat may not have a well-defined limit of time to finish under certain
5352133c2abSThomas Huthconditions. For example, tests that take longer to execute when QEMU is
5362133c2abSThomas Huthcompiled with debug flags. Therefore, the ``AVOCADO_TIMEOUT_EXPECTED`` variable
5372133c2abSThomas Huthhas been used to determine whether those tests should run or not.
5382133c2abSThomas Huth
5392133c2abSThomas HuthQEMU_TEST_FLAKY_TESTS
5402133c2abSThomas Huth^^^^^^^^^^^^^^^^^^^^^
5412133c2abSThomas HuthSome tests are not working reliably and thus are disabled by default.
5422133c2abSThomas HuthThis includes tests that don't run reliably on GitLab's CI which
5432133c2abSThomas Huthusually expose real issues that are rarely seen on developer machines
5442133c2abSThomas Huthdue to the constraints of the CI environment. If you encounter a
5452133c2abSThomas Huthsimilar situation then raise a bug and then mark the test as shown on
5462133c2abSThomas Huththe code snippet below:
5472133c2abSThomas Huth
5482133c2abSThomas Huth.. code::
5492133c2abSThomas Huth
5502133c2abSThomas Huth  # See https://gitlab.com/qemu-project/qemu/-/issues/nnnn
5512133c2abSThomas Huth  @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab')
5522133c2abSThomas Huth  def test(self):
5532133c2abSThomas Huth      do_something()
5542133c2abSThomas Huth
5552133c2abSThomas HuthYou can also add ``:avocado: tags=flaky`` to the test meta-data so
5562133c2abSThomas Huthonly the flaky tests can be run as a group:
5572133c2abSThomas Huth
5582133c2abSThomas Huth.. code::
5592133c2abSThomas Huth
5602133c2abSThomas Huth   env QEMU_TEST_FLAKY_TESTS=1 ./pyvenv/bin/avocado \
5612133c2abSThomas Huth      run tests/avocado -filter-by-tags=flaky
5622133c2abSThomas Huth
5632133c2abSThomas HuthTests should not live in this state forever and should either be fixed
5642133c2abSThomas Huthor eventually removed.
5652133c2abSThomas Huth
5662133c2abSThomas Huth
5672133c2abSThomas HuthUninstalling Avocado
5682133c2abSThomas Huth--------------------
5692133c2abSThomas Huth
5702133c2abSThomas HuthIf you've followed the manual installation instructions above, you can
5712133c2abSThomas Hutheasily uninstall Avocado.  Start by listing the packages you have
5722133c2abSThomas Huthinstalled::
5732133c2abSThomas Huth
5742133c2abSThomas Huth  pip list --user
5752133c2abSThomas Huth
5762133c2abSThomas HuthAnd remove any package you want with::
5772133c2abSThomas Huth
5782133c2abSThomas Huth  pip uninstall <package_name>
5792133c2abSThomas Huth
5802133c2abSThomas HuthIf you've used ``make check-avocado``, the Python virtual environment where
5812133c2abSThomas HuthAvocado is installed will be cleaned up as part of ``make check-clean``.
582