xref: /openbmc/qemu/docs/devel/testing/avocado.rst (revision 2133c2ab)
1*2133c2abSThomas Huth.. _checkavocado-ref:
2*2133c2abSThomas Huth
3*2133c2abSThomas Huth
4*2133c2abSThomas HuthIntegration testing with Avocado
5*2133c2abSThomas Huth================================
6*2133c2abSThomas Huth
7*2133c2abSThomas HuthThe ``tests/avocado`` directory hosts integration tests. They're usually
8*2133c2abSThomas Huthhigher level tests, and may interact with external resources and with
9*2133c2abSThomas Huthvarious guest operating systems.
10*2133c2abSThomas Huth
11*2133c2abSThomas HuthThese tests are written using the Avocado Testing Framework (which must
12*2133c2abSThomas Huthbe installed separately) in conjunction with a the ``avocado_qemu.Test``
13*2133c2abSThomas Huthclass, implemented at ``tests/avocado/avocado_qemu``.
14*2133c2abSThomas Huth
15*2133c2abSThomas HuthTests based on ``avocado_qemu.Test`` can easily:
16*2133c2abSThomas Huth
17*2133c2abSThomas Huth * Customize the command line arguments given to the convenience
18*2133c2abSThomas Huth   ``self.vm`` attribute (a QEMUMachine instance)
19*2133c2abSThomas Huth
20*2133c2abSThomas Huth * Interact with the QEMU monitor, send QMP commands and check
21*2133c2abSThomas Huth   their results
22*2133c2abSThomas Huth
23*2133c2abSThomas Huth * Interact with the guest OS, using the convenience console device
24*2133c2abSThomas Huth   (which may be useful to assert the effectiveness and correctness of
25*2133c2abSThomas Huth   command line arguments or QMP commands)
26*2133c2abSThomas Huth
27*2133c2abSThomas Huth * Interact with external data files that accompany the test itself
28*2133c2abSThomas Huth   (see ``self.get_data()``)
29*2133c2abSThomas Huth
30*2133c2abSThomas Huth * Download (and cache) remote data files, such as firmware and kernel
31*2133c2abSThomas Huth   images
32*2133c2abSThomas Huth
33*2133c2abSThomas Huth * Have access to a library of guest OS images (by means of the
34*2133c2abSThomas Huth   ``avocado.utils.vmimage`` library)
35*2133c2abSThomas Huth
36*2133c2abSThomas Huth * Make use of various other test related utilities available at the
37*2133c2abSThomas Huth   test class itself and at the utility library:
38*2133c2abSThomas Huth
39*2133c2abSThomas Huth   - http://avocado-framework.readthedocs.io/en/latest/api/test/avocado.html#avocado.Test
40*2133c2abSThomas Huth   - http://avocado-framework.readthedocs.io/en/latest/api/utils/avocado.utils.html
41*2133c2abSThomas Huth
42*2133c2abSThomas HuthRunning tests
43*2133c2abSThomas Huth-------------
44*2133c2abSThomas Huth
45*2133c2abSThomas HuthYou can run the avocado tests simply by executing:
46*2133c2abSThomas Huth
47*2133c2abSThomas Huth.. code::
48*2133c2abSThomas Huth
49*2133c2abSThomas Huth  make check-avocado
50*2133c2abSThomas Huth
51*2133c2abSThomas HuthThis involves the automatic installation, from PyPI, of all the
52*2133c2abSThomas Huthnecessary avocado-framework dependencies into the QEMU venv within the
53*2133c2abSThomas Huthbuild tree (at ``./pyvenv``). Test results are also saved within the
54*2133c2abSThomas Huthbuild tree (at ``tests/results``).
55*2133c2abSThomas Huth
56*2133c2abSThomas HuthNote: the build environment must be using a Python 3 stack, and have
57*2133c2abSThomas Huththe ``venv`` and ``pip`` packages installed.  If necessary, make sure
58*2133c2abSThomas Huth``configure`` is called with ``--python=`` and that those modules are
59*2133c2abSThomas Huthavailable.  On Debian and Ubuntu based systems, depending on the
60*2133c2abSThomas Huthspecific version, they may be on packages named ``python3-venv`` and
61*2133c2abSThomas Huth``python3-pip``.
62*2133c2abSThomas Huth
63*2133c2abSThomas HuthIt is also possible to run tests based on tags using the
64*2133c2abSThomas Huth``make check-avocado`` command and the ``AVOCADO_TAGS`` environment
65*2133c2abSThomas Huthvariable:
66*2133c2abSThomas Huth
67*2133c2abSThomas Huth.. code::
68*2133c2abSThomas Huth
69*2133c2abSThomas Huth   make check-avocado AVOCADO_TAGS=quick
70*2133c2abSThomas Huth
71*2133c2abSThomas HuthNote that tags separated with commas have an AND behavior, while tags
72*2133c2abSThomas Huthseparated by spaces have an OR behavior. For more information on Avocado
73*2133c2abSThomas Huthtags, see:
74*2133c2abSThomas Huth
75*2133c2abSThomas Huth https://avocado-framework.readthedocs.io/en/latest/guides/user/chapters/tags.html
76*2133c2abSThomas Huth
77*2133c2abSThomas HuthTo run a single test file, a couple of them, or a test within a file
78*2133c2abSThomas Huthusing the ``make check-avocado`` command, set the ``AVOCADO_TESTS``
79*2133c2abSThomas Huthenvironment variable with the test files or test names. To run all
80*2133c2abSThomas Huthtests from a single file, use:
81*2133c2abSThomas Huth
82*2133c2abSThomas Huth .. code::
83*2133c2abSThomas Huth
84*2133c2abSThomas Huth  make check-avocado AVOCADO_TESTS=$FILEPATH
85*2133c2abSThomas Huth
86*2133c2abSThomas HuthThe same is valid to run tests from multiple test files:
87*2133c2abSThomas Huth
88*2133c2abSThomas Huth .. code::
89*2133c2abSThomas Huth
90*2133c2abSThomas Huth  make check-avocado AVOCADO_TESTS='$FILEPATH1 $FILEPATH2'
91*2133c2abSThomas Huth
92*2133c2abSThomas HuthTo run a single test within a file, use:
93*2133c2abSThomas Huth
94*2133c2abSThomas Huth .. code::
95*2133c2abSThomas Huth
96*2133c2abSThomas Huth  make check-avocado AVOCADO_TESTS=$FILEPATH:$TESTCLASS.$TESTNAME
97*2133c2abSThomas Huth
98*2133c2abSThomas HuthThe same is valid to run single tests from multiple test files:
99*2133c2abSThomas Huth
100*2133c2abSThomas Huth .. code::
101*2133c2abSThomas Huth
102*2133c2abSThomas Huth  make check-avocado AVOCADO_TESTS='$FILEPATH1:$TESTCLASS1.$TESTNAME1 $FILEPATH2:$TESTCLASS2.$TESTNAME2'
103*2133c2abSThomas Huth
104*2133c2abSThomas HuthThe scripts installed inside the virtual environment may be used
105*2133c2abSThomas Huthwithout an "activation".  For instance, the Avocado test runner
106*2133c2abSThomas Huthmay be invoked by running:
107*2133c2abSThomas Huth
108*2133c2abSThomas Huth .. code::
109*2133c2abSThomas Huth
110*2133c2abSThomas Huth  pyvenv/bin/avocado run $OPTION1 $OPTION2 tests/avocado/
111*2133c2abSThomas Huth
112*2133c2abSThomas HuthNote that if ``make check-avocado`` was not executed before, it is
113*2133c2abSThomas Huthpossible to create the Python virtual environment with the dependencies
114*2133c2abSThomas Huthneeded running:
115*2133c2abSThomas Huth
116*2133c2abSThomas Huth .. code::
117*2133c2abSThomas Huth
118*2133c2abSThomas Huth  make check-venv
119*2133c2abSThomas Huth
120*2133c2abSThomas HuthIt is also possible to run tests from a single file or a single test within
121*2133c2abSThomas Hutha test file. To run tests from a single file within the build tree, use:
122*2133c2abSThomas Huth
123*2133c2abSThomas Huth .. code::
124*2133c2abSThomas Huth
125*2133c2abSThomas Huth  pyvenv/bin/avocado run tests/avocado/$TESTFILE
126*2133c2abSThomas Huth
127*2133c2abSThomas HuthTo run a single test within a test file, use:
128*2133c2abSThomas Huth
129*2133c2abSThomas Huth .. code::
130*2133c2abSThomas Huth
131*2133c2abSThomas Huth  pyvenv/bin/avocado run tests/avocado/$TESTFILE:$TESTCLASS.$TESTNAME
132*2133c2abSThomas Huth
133*2133c2abSThomas HuthValid test names are visible in the output from any previous execution
134*2133c2abSThomas Huthof Avocado or ``make check-avocado``, and can also be queried using:
135*2133c2abSThomas Huth
136*2133c2abSThomas Huth .. code::
137*2133c2abSThomas Huth
138*2133c2abSThomas Huth  pyvenv/bin/avocado list tests/avocado
139*2133c2abSThomas Huth
140*2133c2abSThomas HuthManual Installation
141*2133c2abSThomas Huth-------------------
142*2133c2abSThomas Huth
143*2133c2abSThomas HuthTo manually install Avocado and its dependencies, run:
144*2133c2abSThomas Huth
145*2133c2abSThomas Huth.. code::
146*2133c2abSThomas Huth
147*2133c2abSThomas Huth  pip install --user avocado-framework
148*2133c2abSThomas Huth
149*2133c2abSThomas HuthAlternatively, follow the instructions on this link:
150*2133c2abSThomas Huth
151*2133c2abSThomas Huth  https://avocado-framework.readthedocs.io/en/latest/guides/user/chapters/installing.html
152*2133c2abSThomas Huth
153*2133c2abSThomas HuthOverview
154*2133c2abSThomas Huth--------
155*2133c2abSThomas Huth
156*2133c2abSThomas HuthThe ``tests/avocado/avocado_qemu`` directory provides the
157*2133c2abSThomas Huth``avocado_qemu`` Python module, containing the ``avocado_qemu.Test``
158*2133c2abSThomas Huthclass.  Here's a simple usage example:
159*2133c2abSThomas Huth
160*2133c2abSThomas Huth.. code::
161*2133c2abSThomas Huth
162*2133c2abSThomas Huth  from avocado_qemu import QemuSystemTest
163*2133c2abSThomas Huth
164*2133c2abSThomas Huth
165*2133c2abSThomas Huth  class Version(QemuSystemTest):
166*2133c2abSThomas Huth      """
167*2133c2abSThomas Huth      :avocado: tags=quick
168*2133c2abSThomas Huth      """
169*2133c2abSThomas Huth      def test_qmp_human_info_version(self):
170*2133c2abSThomas Huth          self.vm.launch()
171*2133c2abSThomas Huth          res = self.vm.cmd('human-monitor-command',
172*2133c2abSThomas Huth                            command_line='info version')
173*2133c2abSThomas Huth          self.assertRegex(res, r'^(\d+\.\d+\.\d)')
174*2133c2abSThomas Huth
175*2133c2abSThomas HuthTo execute your test, run:
176*2133c2abSThomas Huth
177*2133c2abSThomas Huth.. code::
178*2133c2abSThomas Huth
179*2133c2abSThomas Huth  avocado run version.py
180*2133c2abSThomas Huth
181*2133c2abSThomas HuthTests may be classified according to a convention by using docstring
182*2133c2abSThomas Huthdirectives such as ``:avocado: tags=TAG1,TAG2``.  To run all tests
183*2133c2abSThomas Huthin the current directory, tagged as "quick", run:
184*2133c2abSThomas Huth
185*2133c2abSThomas Huth.. code::
186*2133c2abSThomas Huth
187*2133c2abSThomas Huth  avocado run -t quick .
188*2133c2abSThomas Huth
189*2133c2abSThomas HuthThe ``avocado_qemu.Test`` base test class
190*2133c2abSThomas Huth^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
191*2133c2abSThomas Huth
192*2133c2abSThomas HuthThe ``avocado_qemu.Test`` class has a number of characteristics that
193*2133c2abSThomas Huthare worth being mentioned right away.
194*2133c2abSThomas Huth
195*2133c2abSThomas HuthFirst of all, it attempts to give each test a ready to use QEMUMachine
196*2133c2abSThomas Huthinstance, available at ``self.vm``.  Because many tests will tweak the
197*2133c2abSThomas HuthQEMU command line, launching the QEMUMachine (by using ``self.vm.launch()``)
198*2133c2abSThomas Huthis left to the test writer.
199*2133c2abSThomas Huth
200*2133c2abSThomas HuthThe base test class has also support for tests with more than one
201*2133c2abSThomas HuthQEMUMachine. The way to get machines is through the ``self.get_vm()``
202*2133c2abSThomas Huthmethod which will return a QEMUMachine instance. The ``self.get_vm()``
203*2133c2abSThomas Huthmethod accepts arguments that will be passed to the QEMUMachine creation
204*2133c2abSThomas Huthand also an optional ``name`` attribute so you can identify a specific
205*2133c2abSThomas Huthmachine and get it more than once through the tests methods. A simple
206*2133c2abSThomas Huthand hypothetical example follows:
207*2133c2abSThomas Huth
208*2133c2abSThomas Huth.. code::
209*2133c2abSThomas Huth
210*2133c2abSThomas Huth  from avocado_qemu import QemuSystemTest
211*2133c2abSThomas Huth
212*2133c2abSThomas Huth
213*2133c2abSThomas Huth  class MultipleMachines(QemuSystemTest):
214*2133c2abSThomas Huth      def test_multiple_machines(self):
215*2133c2abSThomas Huth          first_machine = self.get_vm()
216*2133c2abSThomas Huth          second_machine = self.get_vm()
217*2133c2abSThomas Huth          self.get_vm(name='third_machine').launch()
218*2133c2abSThomas Huth
219*2133c2abSThomas Huth          first_machine.launch()
220*2133c2abSThomas Huth          second_machine.launch()
221*2133c2abSThomas Huth
222*2133c2abSThomas Huth          first_res = first_machine.cmd(
223*2133c2abSThomas Huth              'human-monitor-command',
224*2133c2abSThomas Huth              command_line='info version')
225*2133c2abSThomas Huth
226*2133c2abSThomas Huth          second_res = second_machine.cmd(
227*2133c2abSThomas Huth              'human-monitor-command',
228*2133c2abSThomas Huth              command_line='info version')
229*2133c2abSThomas Huth
230*2133c2abSThomas Huth          third_res = self.get_vm(name='third_machine').cmd(
231*2133c2abSThomas Huth              'human-monitor-command',
232*2133c2abSThomas Huth              command_line='info version')
233*2133c2abSThomas Huth
234*2133c2abSThomas Huth          self.assertEqual(first_res, second_res, third_res)
235*2133c2abSThomas Huth
236*2133c2abSThomas HuthAt test "tear down", ``avocado_qemu.Test`` handles all the QEMUMachines
237*2133c2abSThomas Huthshutdown.
238*2133c2abSThomas Huth
239*2133c2abSThomas HuthThe ``avocado_qemu.LinuxTest`` base test class
240*2133c2abSThomas Huth^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
241*2133c2abSThomas Huth
242*2133c2abSThomas HuthThe ``avocado_qemu.LinuxTest`` is further specialization of the
243*2133c2abSThomas Huth``avocado_qemu.Test`` class, so it contains all the characteristics of
244*2133c2abSThomas Huththe later plus some extra features.
245*2133c2abSThomas Huth
246*2133c2abSThomas HuthFirst of all, this base class is intended for tests that need to
247*2133c2abSThomas Huthinteract with a fully booted and operational Linux guest.  At this
248*2133c2abSThomas Huthtime, it uses a Fedora 31 guest image.  The most basic example looks
249*2133c2abSThomas Huthlike this:
250*2133c2abSThomas Huth
251*2133c2abSThomas Huth.. code::
252*2133c2abSThomas Huth
253*2133c2abSThomas Huth  from avocado_qemu import LinuxTest
254*2133c2abSThomas Huth
255*2133c2abSThomas Huth
256*2133c2abSThomas Huth  class SomeTest(LinuxTest):
257*2133c2abSThomas Huth
258*2133c2abSThomas Huth      def test(self):
259*2133c2abSThomas Huth          self.launch_and_wait()
260*2133c2abSThomas Huth          self.ssh_command('some_command_to_be_run_in_the_guest')
261*2133c2abSThomas Huth
262*2133c2abSThomas HuthPlease refer to tests that use ``avocado_qemu.LinuxTest`` under
263*2133c2abSThomas Huth``tests/avocado`` for more examples.
264*2133c2abSThomas Huth
265*2133c2abSThomas HuthQEMUMachine
266*2133c2abSThomas Huth-----------
267*2133c2abSThomas Huth
268*2133c2abSThomas HuthThe QEMUMachine API is already widely used in the Python iotests,
269*2133c2abSThomas Huthdevice-crash-test and other Python scripts.  It's a wrapper around the
270*2133c2abSThomas Huthexecution of a QEMU binary, giving its users:
271*2133c2abSThomas Huth
272*2133c2abSThomas Huth * the ability to set command line arguments to be given to the QEMU
273*2133c2abSThomas Huth   binary
274*2133c2abSThomas Huth
275*2133c2abSThomas Huth * a ready to use QMP connection and interface, which can be used to
276*2133c2abSThomas Huth   send commands and inspect its results, as well as asynchronous
277*2133c2abSThomas Huth   events
278*2133c2abSThomas Huth
279*2133c2abSThomas Huth * convenience methods to set commonly used command line arguments in
280*2133c2abSThomas Huth   a more succinct and intuitive way
281*2133c2abSThomas Huth
282*2133c2abSThomas HuthQEMU binary selection
283*2133c2abSThomas Huth^^^^^^^^^^^^^^^^^^^^^
284*2133c2abSThomas Huth
285*2133c2abSThomas HuthThe QEMU binary used for the ``self.vm`` QEMUMachine instance will
286*2133c2abSThomas Huthprimarily depend on the value of the ``qemu_bin`` parameter.  If it's
287*2133c2abSThomas Huthnot explicitly set, its default value will be the result of a dynamic
288*2133c2abSThomas Huthprobe in the same source tree.  A suitable binary will be one that
289*2133c2abSThomas Huthtargets the architecture matching host machine.
290*2133c2abSThomas Huth
291*2133c2abSThomas HuthBased on this description, test writers will usually rely on one of
292*2133c2abSThomas Huththe following approaches:
293*2133c2abSThomas Huth
294*2133c2abSThomas Huth1) Set ``qemu_bin``, and use the given binary
295*2133c2abSThomas Huth
296*2133c2abSThomas Huth2) Do not set ``qemu_bin``, and use a QEMU binary named like
297*2133c2abSThomas Huth   "qemu-system-${arch}", either in the current
298*2133c2abSThomas Huth   working directory, or in the current source tree.
299*2133c2abSThomas Huth
300*2133c2abSThomas HuthThe resulting ``qemu_bin`` value will be preserved in the
301*2133c2abSThomas Huth``avocado_qemu.Test`` as an attribute with the same name.
302*2133c2abSThomas Huth
303*2133c2abSThomas HuthAttribute reference
304*2133c2abSThomas Huth-------------------
305*2133c2abSThomas Huth
306*2133c2abSThomas HuthTest
307*2133c2abSThomas Huth^^^^
308*2133c2abSThomas Huth
309*2133c2abSThomas HuthBesides the attributes and methods that are part of the base
310*2133c2abSThomas Huth``avocado.Test`` class, the following attributes are available on any
311*2133c2abSThomas Huth``avocado_qemu.Test`` instance.
312*2133c2abSThomas Huth
313*2133c2abSThomas Huthvm
314*2133c2abSThomas Huth""
315*2133c2abSThomas Huth
316*2133c2abSThomas HuthA QEMUMachine instance, initially configured according to the given
317*2133c2abSThomas Huth``qemu_bin`` parameter.
318*2133c2abSThomas Huth
319*2133c2abSThomas Hutharch
320*2133c2abSThomas Huth""""
321*2133c2abSThomas Huth
322*2133c2abSThomas HuthThe architecture can be used on different levels of the stack, e.g. by
323*2133c2abSThomas Huththe framework or by the test itself.  At the framework level, it will
324*2133c2abSThomas Huthcurrently influence the selection of a QEMU binary (when one is not
325*2133c2abSThomas Huthexplicitly given).
326*2133c2abSThomas Huth
327*2133c2abSThomas HuthTests are also free to use this attribute value, for their own needs.
328*2133c2abSThomas HuthA test may, for instance, use the same value when selecting the
329*2133c2abSThomas Hutharchitecture of a kernel or disk image to boot a VM with.
330*2133c2abSThomas Huth
331*2133c2abSThomas HuthThe ``arch`` attribute will be set to the test parameter of the same
332*2133c2abSThomas Huthname.  If one is not given explicitly, it will either be set to
333*2133c2abSThomas Huth``None``, or, if the test is tagged with one (and only one)
334*2133c2abSThomas Huth``:avocado: tags=arch:VALUE`` tag, it will be set to ``VALUE``.
335*2133c2abSThomas Huth
336*2133c2abSThomas Huthcpu
337*2133c2abSThomas Huth"""
338*2133c2abSThomas Huth
339*2133c2abSThomas HuthThe cpu model that will be set to all QEMUMachine instances created
340*2133c2abSThomas Huthby the test.
341*2133c2abSThomas Huth
342*2133c2abSThomas HuthThe ``cpu`` attribute will be set to the test parameter of the same
343*2133c2abSThomas Huthname. If one is not given explicitly, it will either be set to
344*2133c2abSThomas Huth``None ``, or, if the test is tagged with one (and only one)
345*2133c2abSThomas Huth``:avocado: tags=cpu:VALUE`` tag, it will be set to ``VALUE``.
346*2133c2abSThomas Huth
347*2133c2abSThomas Huthmachine
348*2133c2abSThomas Huth"""""""
349*2133c2abSThomas Huth
350*2133c2abSThomas HuthThe machine type that will be set to all QEMUMachine instances created
351*2133c2abSThomas Huthby the test.
352*2133c2abSThomas Huth
353*2133c2abSThomas HuthThe ``machine`` attribute will be set to the test parameter of the same
354*2133c2abSThomas Huthname.  If one is not given explicitly, it will either be set to
355*2133c2abSThomas Huth``None``, or, if the test is tagged with one (and only one)
356*2133c2abSThomas Huth``:avocado: tags=machine:VALUE`` tag, it will be set to ``VALUE``.
357*2133c2abSThomas Huth
358*2133c2abSThomas Huthqemu_bin
359*2133c2abSThomas Huth""""""""
360*2133c2abSThomas Huth
361*2133c2abSThomas HuthThe preserved value of the ``qemu_bin`` parameter or the result of the
362*2133c2abSThomas Huthdynamic probe for a QEMU binary in the current working directory or
363*2133c2abSThomas Huthsource tree.
364*2133c2abSThomas Huth
365*2133c2abSThomas HuthLinuxTest
366*2133c2abSThomas Huth^^^^^^^^^
367*2133c2abSThomas Huth
368*2133c2abSThomas HuthBesides the attributes present on the ``avocado_qemu.Test`` base
369*2133c2abSThomas Huthclass, the ``avocado_qemu.LinuxTest`` adds the following attributes:
370*2133c2abSThomas Huth
371*2133c2abSThomas Huthdistro
372*2133c2abSThomas Huth""""""
373*2133c2abSThomas Huth
374*2133c2abSThomas HuthThe name of the Linux distribution used as the guest image for the
375*2133c2abSThomas Huthtest.  The name should match the **Provider** column on the list
376*2133c2abSThomas Huthof images supported by the avocado.utils.vmimage library:
377*2133c2abSThomas Huth
378*2133c2abSThomas Huthhttps://avocado-framework.readthedocs.io/en/latest/guides/writer/libs/vmimage.html#supported-images
379*2133c2abSThomas Huth
380*2133c2abSThomas Huthdistro_version
381*2133c2abSThomas Huth""""""""""""""
382*2133c2abSThomas Huth
383*2133c2abSThomas HuthThe version of the Linux distribution as the guest image for the
384*2133c2abSThomas Huthtest.  The name should match the **Version** column on the list
385*2133c2abSThomas Huthof images supported by the avocado.utils.vmimage library:
386*2133c2abSThomas Huth
387*2133c2abSThomas Huthhttps://avocado-framework.readthedocs.io/en/latest/guides/writer/libs/vmimage.html#supported-images
388*2133c2abSThomas Huth
389*2133c2abSThomas Huthdistro_checksum
390*2133c2abSThomas Huth"""""""""""""""
391*2133c2abSThomas Huth
392*2133c2abSThomas HuthThe sha256 hash of the guest image file used for the test.
393*2133c2abSThomas Huth
394*2133c2abSThomas HuthIf this value is not set in the code or by a test parameter (with the
395*2133c2abSThomas Huthsame name), no validation on the integrity of the image will be
396*2133c2abSThomas Huthperformed.
397*2133c2abSThomas Huth
398*2133c2abSThomas HuthParameter reference
399*2133c2abSThomas Huth-------------------
400*2133c2abSThomas Huth
401*2133c2abSThomas HuthTo understand how Avocado parameters are accessed by tests, and how
402*2133c2abSThomas Huththey can be passed to tests, please refer to::
403*2133c2abSThomas Huth
404*2133c2abSThomas Huth  https://avocado-framework.readthedocs.io/en/latest/guides/writer/chapters/writing.html#accessing-test-parameters
405*2133c2abSThomas Huth
406*2133c2abSThomas HuthParameter values can be easily seen in the log files, and will look
407*2133c2abSThomas Huthlike the following:
408*2133c2abSThomas Huth
409*2133c2abSThomas Huth.. code::
410*2133c2abSThomas Huth
411*2133c2abSThomas Huth  PARAMS (key=qemu_bin, path=*, default=./qemu-system-x86_64) => './qemu-system-x86_64
412*2133c2abSThomas Huth
413*2133c2abSThomas HuthTest
414*2133c2abSThomas Huth^^^^
415*2133c2abSThomas Huth
416*2133c2abSThomas Hutharch
417*2133c2abSThomas Huth""""
418*2133c2abSThomas Huth
419*2133c2abSThomas HuthThe architecture that will influence the selection of a QEMU binary
420*2133c2abSThomas Huth(when one is not explicitly given).
421*2133c2abSThomas Huth
422*2133c2abSThomas HuthTests are also free to use this parameter value, for their own needs.
423*2133c2abSThomas HuthA test may, for instance, use the same value when selecting the
424*2133c2abSThomas Hutharchitecture of a kernel or disk image to boot a VM with.
425*2133c2abSThomas Huth
426*2133c2abSThomas HuthThis parameter has a direct relation with the ``arch`` attribute.  If
427*2133c2abSThomas Huthnot given, it will default to None.
428*2133c2abSThomas Huth
429*2133c2abSThomas Huthcpu
430*2133c2abSThomas Huth"""
431*2133c2abSThomas Huth
432*2133c2abSThomas HuthThe cpu model that will be set to all QEMUMachine instances created
433*2133c2abSThomas Huthby the test.
434*2133c2abSThomas Huth
435*2133c2abSThomas Huthmachine
436*2133c2abSThomas Huth"""""""
437*2133c2abSThomas Huth
438*2133c2abSThomas HuthThe machine type that will be set to all QEMUMachine instances created
439*2133c2abSThomas Huthby the test.
440*2133c2abSThomas Huth
441*2133c2abSThomas Huthqemu_bin
442*2133c2abSThomas Huth""""""""
443*2133c2abSThomas Huth
444*2133c2abSThomas HuthThe exact QEMU binary to be used on QEMUMachine.
445*2133c2abSThomas Huth
446*2133c2abSThomas HuthLinuxTest
447*2133c2abSThomas Huth^^^^^^^^^
448*2133c2abSThomas Huth
449*2133c2abSThomas HuthBesides the parameters present on the ``avocado_qemu.Test`` base
450*2133c2abSThomas Huthclass, the ``avocado_qemu.LinuxTest`` adds the following parameters:
451*2133c2abSThomas Huth
452*2133c2abSThomas Huthdistro
453*2133c2abSThomas Huth""""""
454*2133c2abSThomas Huth
455*2133c2abSThomas HuthThe name of the Linux distribution used as the guest image for the
456*2133c2abSThomas Huthtest.  The name should match the **Provider** column on the list
457*2133c2abSThomas Huthof images supported by the avocado.utils.vmimage library:
458*2133c2abSThomas Huth
459*2133c2abSThomas Huthhttps://avocado-framework.readthedocs.io/en/latest/guides/writer/libs/vmimage.html#supported-images
460*2133c2abSThomas Huth
461*2133c2abSThomas Huthdistro_version
462*2133c2abSThomas Huth""""""""""""""
463*2133c2abSThomas Huth
464*2133c2abSThomas HuthThe version of the Linux distribution as the guest image for the
465*2133c2abSThomas Huthtest.  The name should match the **Version** column on the list
466*2133c2abSThomas Huthof images supported by the avocado.utils.vmimage library:
467*2133c2abSThomas Huth
468*2133c2abSThomas Huthhttps://avocado-framework.readthedocs.io/en/latest/guides/writer/libs/vmimage.html#supported-images
469*2133c2abSThomas Huth
470*2133c2abSThomas Huthdistro_checksum
471*2133c2abSThomas Huth"""""""""""""""
472*2133c2abSThomas Huth
473*2133c2abSThomas HuthThe sha256 hash of the guest image file used for the test.
474*2133c2abSThomas Huth
475*2133c2abSThomas HuthIf this value is not set in the code or by this parameter no
476*2133c2abSThomas Huthvalidation on the integrity of the image will be performed.
477*2133c2abSThomas Huth
478*2133c2abSThomas HuthSkipping tests
479*2133c2abSThomas Huth--------------
480*2133c2abSThomas Huth
481*2133c2abSThomas HuthThe Avocado framework provides Python decorators which allow for easily skip
482*2133c2abSThomas Huthtests running under certain conditions. For example, on the lack of a binary
483*2133c2abSThomas Huthon the test system or when the running environment is a CI system. For further
484*2133c2abSThomas Huthinformation about those decorators, please refer to::
485*2133c2abSThomas Huth
486*2133c2abSThomas Huth  https://avocado-framework.readthedocs.io/en/latest/guides/writer/chapters/writing.html#skipping-tests
487*2133c2abSThomas Huth
488*2133c2abSThomas HuthWhile the conditions for skipping tests are often specifics of each one, there
489*2133c2abSThomas Huthare recurring scenarios identified by the QEMU developers and the use of
490*2133c2abSThomas Huthenvironment variables became a kind of standard way to enable/disable tests.
491*2133c2abSThomas Huth
492*2133c2abSThomas HuthHere is a list of the most used variables:
493*2133c2abSThomas Huth
494*2133c2abSThomas HuthAVOCADO_ALLOW_LARGE_STORAGE
495*2133c2abSThomas Huth^^^^^^^^^^^^^^^^^^^^^^^^^^^
496*2133c2abSThomas HuthTests which are going to fetch or produce assets considered *large* are not
497*2133c2abSThomas Huthgoing to run unless that ``AVOCADO_ALLOW_LARGE_STORAGE=1`` is exported on
498*2133c2abSThomas Huththe environment.
499*2133c2abSThomas Huth
500*2133c2abSThomas HuthThe definition of *large* is a bit arbitrary here, but it usually means an
501*2133c2abSThomas Huthasset which occupies at least 1GB of size on disk when uncompressed.
502*2133c2abSThomas Huth
503*2133c2abSThomas HuthSPEED
504*2133c2abSThomas Huth^^^^^
505*2133c2abSThomas HuthTests which have a long runtime will not be run unless ``SPEED=slow`` is
506*2133c2abSThomas Huthexported on the environment.
507*2133c2abSThomas Huth
508*2133c2abSThomas HuthThe definition of *long* is a bit arbitrary here, and it depends on the
509*2133c2abSThomas Huthusefulness of the test too. A unique test is worth spending more time on,
510*2133c2abSThomas Huthsmall variations on existing tests perhaps less so. As a rough guide,
511*2133c2abSThomas Hutha test or set of similar tests which take more than 100 seconds to
512*2133c2abSThomas Huthcomplete.
513*2133c2abSThomas Huth
514*2133c2abSThomas HuthAVOCADO_ALLOW_UNTRUSTED_CODE
515*2133c2abSThomas Huth^^^^^^^^^^^^^^^^^^^^^^^^^^^^
516*2133c2abSThomas HuthThere are tests which will boot a kernel image or firmware that can be
517*2133c2abSThomas Huthconsidered not safe to run on the developer's workstation, thus they are
518*2133c2abSThomas Huthskipped by default. The definition of *not safe* is also arbitrary but
519*2133c2abSThomas Huthusually it means a blob which either its source or build process aren't
520*2133c2abSThomas Huthpublic available.
521*2133c2abSThomas Huth
522*2133c2abSThomas HuthYou should export ``AVOCADO_ALLOW_UNTRUSTED_CODE=1`` on the environment in
523*2133c2abSThomas Huthorder to allow tests which make use of those kind of assets.
524*2133c2abSThomas Huth
525*2133c2abSThomas HuthAVOCADO_TIMEOUT_EXPECTED
526*2133c2abSThomas Huth^^^^^^^^^^^^^^^^^^^^^^^^
527*2133c2abSThomas HuthThe Avocado framework has a timeout mechanism which interrupts tests to avoid the
528*2133c2abSThomas Huthtest suite of getting stuck. The timeout value can be set via test parameter or
529*2133c2abSThomas Huthproperty defined in the test class, for further details::
530*2133c2abSThomas Huth
531*2133c2abSThomas Huth  https://avocado-framework.readthedocs.io/en/latest/guides/writer/chapters/writing.html#setting-a-test-timeout
532*2133c2abSThomas Huth
533*2133c2abSThomas HuthEven though the timeout can be set by the test developer, there are some tests
534*2133c2abSThomas Huththat may not have a well-defined limit of time to finish under certain
535*2133c2abSThomas Huthconditions. For example, tests that take longer to execute when QEMU is
536*2133c2abSThomas Huthcompiled with debug flags. Therefore, the ``AVOCADO_TIMEOUT_EXPECTED`` variable
537*2133c2abSThomas Huthhas been used to determine whether those tests should run or not.
538*2133c2abSThomas Huth
539*2133c2abSThomas HuthQEMU_TEST_FLAKY_TESTS
540*2133c2abSThomas Huth^^^^^^^^^^^^^^^^^^^^^
541*2133c2abSThomas HuthSome tests are not working reliably and thus are disabled by default.
542*2133c2abSThomas HuthThis includes tests that don't run reliably on GitLab's CI which
543*2133c2abSThomas Huthusually expose real issues that are rarely seen on developer machines
544*2133c2abSThomas Huthdue to the constraints of the CI environment. If you encounter a
545*2133c2abSThomas Huthsimilar situation then raise a bug and then mark the test as shown on
546*2133c2abSThomas Huththe code snippet below:
547*2133c2abSThomas Huth
548*2133c2abSThomas Huth.. code::
549*2133c2abSThomas Huth
550*2133c2abSThomas Huth  # See https://gitlab.com/qemu-project/qemu/-/issues/nnnn
551*2133c2abSThomas Huth  @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab')
552*2133c2abSThomas Huth  def test(self):
553*2133c2abSThomas Huth      do_something()
554*2133c2abSThomas Huth
555*2133c2abSThomas HuthYou can also add ``:avocado: tags=flaky`` to the test meta-data so
556*2133c2abSThomas Huthonly the flaky tests can be run as a group:
557*2133c2abSThomas Huth
558*2133c2abSThomas Huth.. code::
559*2133c2abSThomas Huth
560*2133c2abSThomas Huth   env QEMU_TEST_FLAKY_TESTS=1 ./pyvenv/bin/avocado \
561*2133c2abSThomas Huth      run tests/avocado -filter-by-tags=flaky
562*2133c2abSThomas Huth
563*2133c2abSThomas HuthTests should not live in this state forever and should either be fixed
564*2133c2abSThomas Huthor eventually removed.
565*2133c2abSThomas Huth
566*2133c2abSThomas Huth
567*2133c2abSThomas HuthUninstalling Avocado
568*2133c2abSThomas Huth--------------------
569*2133c2abSThomas Huth
570*2133c2abSThomas HuthIf you've followed the manual installation instructions above, you can
571*2133c2abSThomas Hutheasily uninstall Avocado.  Start by listing the packages you have
572*2133c2abSThomas Huthinstalled::
573*2133c2abSThomas Huth
574*2133c2abSThomas Huth  pip list --user
575*2133c2abSThomas Huth
576*2133c2abSThomas HuthAnd remove any package you want with::
577*2133c2abSThomas Huth
578*2133c2abSThomas Huth  pip uninstall <package_name>
579*2133c2abSThomas Huth
580*2133c2abSThomas HuthIf you've used ``make check-avocado``, the Python virtual environment where
581*2133c2abSThomas HuthAvocado is installed will be cleaned up as part of ``make check-clean``.
582