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