libqos/qgraph: format qgraph comments for sphinx documentation
[qemu/ar7.git] / docs / devel / qtest.rst
blobc3dceb6c8a1d88ec8969307209027549424eeee2
1 ========================================
2 QTest Device Emulation Testing Framework
3 ========================================
5 .. toctree::
6    :hidden:
8    qgraph
10 QTest is a device emulation testing framework.  It can be very useful to test
11 device models; it could also control certain aspects of QEMU (such as virtual
12 clock stepping), with a special purpose "qtest" protocol.  Refer to
13 :ref:`qtest-protocol` for more details of the protocol.
15 QTest cases can be executed with
17 .. code::
19    make check-qtest
21 The QTest library is implemented by ``tests/qtest/libqtest.c`` and the API is
22 defined in ``tests/qtest/libqtest.h``.
24 Consider adding a new QTest case when you are introducing a new virtual
25 hardware, or extending one if you are adding functionalities to an existing
26 virtual device.
28 On top of libqtest, a higher level library, ``libqos``, was created to
29 encapsulate common tasks of device drivers, such as memory management and
30 communicating with system buses or devices. Many virtual device tests use
31 libqos instead of directly calling into libqtest.
32 Libqos also offers the Qgraph API to increase each test coverage and
33 automate QEMU command line arguments and devices setup.
34 Refer to :ref:`qgraph` for Qgraph explanation and API.
36 Steps to add a new QTest case are:
38 1. Create a new source file for the test. (More than one file can be added as
39    necessary.) For example, ``tests/qtest/foo-test.c``.
41 2. Write the test code with the glib and libqtest/libqos API. See also existing
42    tests and the library headers for reference.
44 3. Register the new test in ``tests/qtest/meson.build``. Add the test
45    executable name to an appropriate ``qtests_*`` variable. There is
46    one variable per architecture, plus ``qtests_generic`` for tests
47    that can be run for all architectures.  For example::
49      qtests_generic = [
50        ...
51        'foo-test',
52        ...
53      ]
55 4. If the test has more than one source file or needs to be linked with any
56    dependency other than ``qemuutil`` and ``qos``, list them in the ``qtests``
57    dictionary.  For example a test that needs to use the ``QIO`` library
58    will have an entry like::
60      {
61        ...
62        'foo-test': [io],
63        ...
64      }
66 Debugging a QTest failure is slightly harder than the unit test because the
67 tests look up QEMU program names in the environment variables, such as
68 ``QTEST_QEMU_BINARY`` and ``QTEST_QEMU_IMG``, and also because it is not easy
69 to attach gdb to the QEMU process spawned from the test. But manual invoking
70 and using gdb on the test is still simple to do: find out the actual command
71 from the output of
73 .. code::
75   make check-qtest V=1
77 which you can run manually.
80 .. _qtest-protocol:
82 QTest Protocol
83 --------------
85 .. kernel-doc:: softmmu/qtest.c
86    :doc: QTest Protocol
89 libqtest API reference
90 ----------------------
92 .. kernel-doc:: tests/qtest/libqos/libqtest.h