1a738a50eSEduardo Habkost======================================== 2a738a50eSEduardo HabkostQTest Device Emulation Testing Framework 3a738a50eSEduardo Habkost======================================== 4a738a50eSEduardo Habkost 5222455efSEmanuele Giuseppe Esposito.. toctree:: 6222455efSEmanuele Giuseppe Esposito 7222455efSEmanuele Giuseppe Esposito qgraph 8222455efSEmanuele Giuseppe Esposito 9a738a50eSEduardo HabkostQTest is a device emulation testing framework. It can be very useful to test 10a738a50eSEduardo Habkostdevice models; it could also control certain aspects of QEMU (such as virtual 11f59c6de7SEduardo Habkostclock stepping), with a special purpose "qtest" protocol. Refer to 12f59c6de7SEduardo Habkost:ref:`qtest-protocol` for more details of the protocol. 13a738a50eSEduardo Habkost 14a738a50eSEduardo HabkostQTest cases can be executed with 15a738a50eSEduardo Habkost 16a738a50eSEduardo Habkost.. code:: 17a738a50eSEduardo Habkost 18a738a50eSEduardo Habkost make check-qtest 19a738a50eSEduardo Habkost 20a738a50eSEduardo HabkostThe QTest library is implemented by ``tests/qtest/libqtest.c`` and the API is 21a738a50eSEduardo Habkostdefined in ``tests/qtest/libqtest.h``. 22a738a50eSEduardo Habkost 23a738a50eSEduardo HabkostConsider adding a new QTest case when you are introducing a new virtual 24a738a50eSEduardo Habkosthardware, or extending one if you are adding functionalities to an existing 25a738a50eSEduardo Habkostvirtual device. 26a738a50eSEduardo Habkost 27a738a50eSEduardo HabkostOn top of libqtest, a higher level library, ``libqos``, was created to 28a738a50eSEduardo Habkostencapsulate common tasks of device drivers, such as memory management and 29a738a50eSEduardo Habkostcommunicating with system buses or devices. Many virtual device tests use 30a738a50eSEduardo Habkostlibqos instead of directly calling into libqtest. 31222455efSEmanuele Giuseppe EspositoLibqos also offers the Qgraph API to increase each test coverage and 32222455efSEmanuele Giuseppe Espositoautomate QEMU command line arguments and devices setup. 33222455efSEmanuele Giuseppe EspositoRefer to :ref:`qgraph` for Qgraph explanation and API. 34a738a50eSEduardo Habkost 35a738a50eSEduardo HabkostSteps to add a new QTest case are: 36a738a50eSEduardo Habkost 37a738a50eSEduardo Habkost1. Create a new source file for the test. (More than one file can be added as 38a738a50eSEduardo Habkost necessary.) For example, ``tests/qtest/foo-test.c``. 39a738a50eSEduardo Habkost 40a738a50eSEduardo Habkost2. Write the test code with the glib and libqtest/libqos API. See also existing 41a738a50eSEduardo Habkost tests and the library headers for reference. 42a738a50eSEduardo Habkost 43bab88eadSPaolo Bonzini3. Register the new test in ``tests/qtest/meson.build``. Add the test 44bab88eadSPaolo Bonzini executable name to an appropriate ``qtests_*`` variable. There is 45bab88eadSPaolo Bonzini one variable per architecture, plus ``qtests_generic`` for tests 46bab88eadSPaolo Bonzini that can be run for all architectures. For example:: 47a738a50eSEduardo Habkost 48bab88eadSPaolo Bonzini qtests_generic = [ 49bab88eadSPaolo Bonzini ... 50bab88eadSPaolo Bonzini 'foo-test', 51bab88eadSPaolo Bonzini ... 52bab88eadSPaolo Bonzini ] 53a738a50eSEduardo Habkost 54bab88eadSPaolo Bonzini4. If the test has more than one source file or needs to be linked with any 55bab88eadSPaolo Bonzini dependency other than ``qemuutil`` and ``qos``, list them in the ``qtests`` 56bab88eadSPaolo Bonzini dictionary. For example a test that needs to use the ``QIO`` library 57bab88eadSPaolo Bonzini will have an entry like:: 58a738a50eSEduardo Habkost 59bab88eadSPaolo Bonzini { 60bab88eadSPaolo Bonzini ... 61bab88eadSPaolo Bonzini 'foo-test': [io], 62bab88eadSPaolo Bonzini ... 63bab88eadSPaolo Bonzini } 64a738a50eSEduardo Habkost 65a738a50eSEduardo HabkostDebugging a QTest failure is slightly harder than the unit test because the 66a738a50eSEduardo Habkosttests look up QEMU program names in the environment variables, such as 67a738a50eSEduardo Habkost``QTEST_QEMU_BINARY`` and ``QTEST_QEMU_IMG``, and also because it is not easy 68a738a50eSEduardo Habkostto attach gdb to the QEMU process spawned from the test. But manual invoking 69a738a50eSEduardo Habkostand using gdb on the test is still simple to do: find out the actual command 70a738a50eSEduardo Habkostfrom the output of 71a738a50eSEduardo Habkost 72a738a50eSEduardo Habkost.. code:: 73a738a50eSEduardo Habkost 74a738a50eSEduardo Habkost make check-qtest V=1 75a738a50eSEduardo Habkost 76a738a50eSEduardo Habkostwhich you can run manually. 77a738a50eSEduardo Habkost 78f59c6de7SEduardo Habkost 79f59c6de7SEduardo Habkost.. _qtest-protocol: 80f59c6de7SEduardo Habkost 81f59c6de7SEduardo HabkostQTest Protocol 82f59c6de7SEduardo Habkost-------------- 83f59c6de7SEduardo Habkost 84f59c6de7SEduardo Habkost.. kernel-doc:: softmmu/qtest.c 85f59c6de7SEduardo Habkost :doc: QTest Protocol 8651c778edSEduardo Habkost 8751c778edSEduardo Habkost 8851c778edSEduardo Habkostlibqtest API reference 8951c778edSEduardo Habkost---------------------- 9051c778edSEduardo Habkost 91*907b5105SMarc-André Lureau.. kernel-doc:: tests/qtest/libqtest.h 92