1*ff41da50SThomas Huth======================================== 2*ff41da50SThomas HuthQTest Device Emulation Testing Framework 3*ff41da50SThomas Huth======================================== 4*ff41da50SThomas Huth 5*ff41da50SThomas Huth.. toctree:: 6*ff41da50SThomas Huth 7*ff41da50SThomas Huth qgraph 8*ff41da50SThomas Huth 9*ff41da50SThomas HuthQTest is a device emulation testing framework. It can be very useful to test 10*ff41da50SThomas Huthdevice models; it could also control certain aspects of QEMU (such as virtual 11*ff41da50SThomas Huthclock stepping), with a special purpose "qtest" protocol. Refer to 12*ff41da50SThomas Huth:ref:`qtest-protocol` for more details of the protocol. 13*ff41da50SThomas Huth 14*ff41da50SThomas HuthQTest cases can be executed with 15*ff41da50SThomas Huth 16*ff41da50SThomas Huth.. code:: 17*ff41da50SThomas Huth 18*ff41da50SThomas Huth make check-qtest 19*ff41da50SThomas Huth 20*ff41da50SThomas HuthThe QTest library is implemented by ``tests/qtest/libqtest.c`` and the API is 21*ff41da50SThomas Huthdefined in ``tests/qtest/libqtest.h``. 22*ff41da50SThomas Huth 23*ff41da50SThomas HuthConsider adding a new QTest case when you are introducing a new virtual 24*ff41da50SThomas Huthhardware, or extending one if you are adding functionalities to an existing 25*ff41da50SThomas Huthvirtual device. 26*ff41da50SThomas Huth 27*ff41da50SThomas HuthOn top of libqtest, a higher level library, ``libqos``, was created to 28*ff41da50SThomas Huthencapsulate common tasks of device drivers, such as memory management and 29*ff41da50SThomas Huthcommunicating with system buses or devices. Many virtual device tests use 30*ff41da50SThomas Huthlibqos instead of directly calling into libqtest. 31*ff41da50SThomas HuthLibqos also offers the Qgraph API to increase each test coverage and 32*ff41da50SThomas Huthautomate QEMU command line arguments and devices setup. 33*ff41da50SThomas HuthRefer to :ref:`qgraph` for Qgraph explanation and API. 34*ff41da50SThomas Huth 35*ff41da50SThomas HuthSteps to add a new QTest case are: 36*ff41da50SThomas Huth 37*ff41da50SThomas Huth1. Create a new source file for the test. (More than one file can be added as 38*ff41da50SThomas Huth necessary.) For example, ``tests/qtest/foo-test.c``. 39*ff41da50SThomas Huth 40*ff41da50SThomas Huth2. Write the test code with the glib and libqtest/libqos API. See also existing 41*ff41da50SThomas Huth tests and the library headers for reference. 42*ff41da50SThomas Huth 43*ff41da50SThomas Huth3. Register the new test in ``tests/qtest/meson.build``. Add the test 44*ff41da50SThomas Huth executable name to an appropriate ``qtests_*`` variable. There is 45*ff41da50SThomas Huth one variable per architecture, plus ``qtests_generic`` for tests 46*ff41da50SThomas Huth that can be run for all architectures. For example:: 47*ff41da50SThomas Huth 48*ff41da50SThomas Huth qtests_generic = [ 49*ff41da50SThomas Huth ... 50*ff41da50SThomas Huth 'foo-test', 51*ff41da50SThomas Huth ... 52*ff41da50SThomas Huth ] 53*ff41da50SThomas Huth 54*ff41da50SThomas Huth4. If the test has more than one source file or needs to be linked with any 55*ff41da50SThomas Huth dependency other than ``qemuutil`` and ``qos``, list them in the ``qtests`` 56*ff41da50SThomas Huth dictionary. For example a test that needs to use the ``QIO`` library 57*ff41da50SThomas Huth will have an entry like:: 58*ff41da50SThomas Huth 59*ff41da50SThomas Huth { 60*ff41da50SThomas Huth ... 61*ff41da50SThomas Huth 'foo-test': [io], 62*ff41da50SThomas Huth ... 63*ff41da50SThomas Huth } 64*ff41da50SThomas Huth 65*ff41da50SThomas HuthDebugging a QTest failure is slightly harder than the unit test because the 66*ff41da50SThomas Huthtests look up QEMU program names in the environment variables, such as 67*ff41da50SThomas Huth``QTEST_QEMU_BINARY`` and ``QTEST_QEMU_IMG``, and also because it is not easy 68*ff41da50SThomas Huthto attach gdb to the QEMU process spawned from the test. But manual invoking 69*ff41da50SThomas Huthand using gdb on the test is still simple to do: find out the actual command 70*ff41da50SThomas Huthfrom the output of 71*ff41da50SThomas Huth 72*ff41da50SThomas Huth.. code:: 73*ff41da50SThomas Huth 74*ff41da50SThomas Huth make check-qtest V=1 75*ff41da50SThomas Huth 76*ff41da50SThomas Huthwhich you can run manually. 77*ff41da50SThomas Huth 78*ff41da50SThomas Huth 79*ff41da50SThomas Huth.. _qtest-protocol: 80*ff41da50SThomas Huth 81*ff41da50SThomas HuthQTest Protocol 82*ff41da50SThomas Huth-------------- 83*ff41da50SThomas Huth 84*ff41da50SThomas Huth.. kernel-doc:: system/qtest.c 85*ff41da50SThomas Huth :doc: QTest Protocol 86*ff41da50SThomas Huth 87*ff41da50SThomas Huth 88*ff41da50SThomas Huthlibqtest API reference 89*ff41da50SThomas Huth---------------------- 90*ff41da50SThomas Huth 91*ff41da50SThomas Huth.. kernel-doc:: tests/qtest/libqtest.h 92