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