Make the core libqtest library independe from global_qtest
v2 cover Make the core libqtest library independe from global_qtest
global_qtest and the related wrapper functions often caused trouble in the past - if they are used somewhere in the libqtest or libqos library code, it's hard to write tests that properly track multiple test states (like migration tests).
This patch series finally gets rid of the remaining global_qtest dependencies in the core libqtest code. The first patches are used to clean up some files that should not use global_qtest anymore, then the wrapper functions and the global_qtest definition get moved to a separate header file called libqtest-single.h - which then should only be used in tests that track only a single test state.
v2:
- Do not add parameter to qvirtio_wait_config_isr(), but push the logic into virtio-mmio.c and virtio-pci.c instead since we have access to the test state here (as suggested by Laurent).
Thomas Huth (6):
tests/migration: Do not use functions anymore that rely on
global_qtest
tests/libqos/e1000e: Make e1000e libqos functions independent from
global_qtest
tests/libqos: Replace clock_step with qtest_clock_step in virtio code
tests: Remove unnecessary global_qtest references tests/libqtest: Move global_test wrapper function into a separate
header
tests/libqtest: Use libqtest-single.h in tests that require
global_qtest
MAINTAINERS | 2 +- tests/ahci-test.c | 1 - tests/bios-tables-test.c | 1 - tests/cpu-plug-test.c | 2 +- tests/display-vga-test.c | 2 +- tests/e1000e-test.c | 2 +- tests/fdc-test.c | 2 +- tests/i440fx-test.c | 2 +- tests/i82801b11-test.c | 2 +- tests/intel-hda-test.c | 2 +- tests/ioh3420-test.c | 2 +- tests/ipmi-kcs-test.c | 3 +- tests/ivshmem-test.c | 3 - tests/libqos/e1000e.c | 16 +- tests/libqos/virtio-mmio.c | 14 +- tests/libqos/virtio-pci.c | 14 +- tests/libqos/virtio.c | 20 +-- tests/libqos/virtio.h | 6 +- tests/libqtest-single.h | 315 ++++++++++++++++++++++++++++++++++ tests/libqtest.c | 13 -- tests/libqtest.h | 289 ------------------------------- tests/m25p80-test.c | 2 +- tests/migration-test.c | 6 +- tests/qos-test.c | 2 +- tests/rtas-test.c | 1 - tests/rtc-test.c | 2 +- tests/rtl8139-test.c | 2 +- tests/test-arm-mptimer.c | 2 +- tests/test-netfilter.c | 2 +- tests/test-x86-cpuid-compat.c | 2 +- tests/tmp105-test.c | 2 +- tests/tpm-crb-test.c | 2 +- tests/tpm-tests.c | 2 +- tests/tpm-tis-test.c | 2 +- tests/usb-hcd-ohci-test.c | 2 +- tests/usb-hcd-uhci-test.c | 2 +- tests/usb-hcd-xhci-test.c | 2 +- tests/vhost-user-test.c | 2 +- tests/virtio-blk-test.c | 5 +- tests/virtio-ccw-test.c | 2 +- tests/virtio-net-test.c | 2 +- tests/virtio-scsi-test.c | 2 +- tests/virtio-serial-test.c | 2 +- 43 files changed, 396 insertions(+), 367 deletions(-) create mode 100644 tests/libqtest-single.h
Signature · 1 line
2.18.1
PATCH v2 1/6 tests/migration: Do not use functions anymore that rely on global_qtest
The migration tests deal with multiple test states, so we really should not use functions here that rely on the single global_qtest variable. Switch from qtest_start() to qtest_init() to make sure that global_qtest is not set anymore. This also revealed a regression in the migrate()
function: It has once been converted to use the qtest_qmp() function, but commit b5bbd3f315d686bd511 ("Clean up string interpolation into QMP, part 2") accidentally reverted it back to qmp().
--- tests/migration-test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tests/migration-test.c +3 -3
@@ -490,7 +490,7 @@ static void migrate(QTestState *who, const char *uri, const char *fmt, ...)g_assert (!qdict_haskey (args,"uri" ));qdict_put_str (args,"uri" , uri); - rsp =qmp ("{ 'execute': 'migrate', 'arguments': %p}" , args); + rsp =qtest_qmp (who,"{ 'execute': 'migrate', 'arguments': %p}" , args);g_assert (qdict_haskey (rsp,"return" ));qobject_unref (rsp);
@@ -625,7 +625,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, cmd_dst = tmp; } - *from =qtest_start (cmd_src); + *from =qtest_init (cmd_src);g_free (cmd_src); *to =qtest_init (cmd_dst);
@@ -715,7 +715,7 @@ static void test_deprecated(void) {QTestState *from; - from =qtest_start ("-machine none" ); + from =qtest_init ("-machine none" );deprecated_set_downtime (from,0.12345 );deprecated_set_speed (from,12345 );
Signature · 1 line
2.18.1
Re: [Qemu-devel] [PATCH v2 1/6] tests/migration: Do not use functions anymore that rely on global_qtest
Quoted 8 lines · Thomas Huth
The migration tests deal with multiple test states, so we really should not use functions here that rely on the single
global_qtestvariable. Switch fromqtest_start()toqtest_init()to make sure thatglobal_qtestis not set anymore. This also revealed a regression in themigrate()
function: It has once been converted to use theqtest_qmp()function, but commitb5bbd3f315d686bd511("Clean up string interpolation into QMP, part 2") accidentally reverted it back toqmp().
Quoted 6 lines
Reviewed-by Dr. David Alan Gilbert <[email protected]>Reviewed-by Laurent Vivier <[email protected]>Signed-off-by Thomas Huth <[email protected]>--- tests/migration-test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
PATCH v2 2/6 tests/libqos/e1000e: Make e1000e libqos functions independent from global_qtest
In reply to Thomas Huthlibqos library functions should never depend on functions (like memread(), memwrite() or clock_step()) that require global_qtest to be set, since library functions might get used in qtests that track multiple states, too. Thus let's replace the global_qtest-related functions with their independent counterparts.
--- tests/libqos/e1000e.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
tests/libqos/e1000e.c +11 -5
@@ -85,26 +85,32 @@ static uint32_t e1000e_macreg_read(QE1000E *d, uint32_t reg)void e1000e_tx_ring_push (QE1000E *d,void *descr) { +QE1000E_PCI *d_pci =container_of (d,QE1000E_PCI , e1000e);uint32_t tail =e1000e_macreg_read (d,E1000E_TDT );uint32_t len =e1000e_macreg_read (d,E1000E_TDLEN ) /E1000E_TXD_LEN ; -memwrite (d->tx_ring + tail *E1000E_TXD_LEN , descr,E1000E_TXD_LEN ); +qtest_memwrite (d_pci->pci_dev.bus->qts, d->tx_ring + tail *E1000E_TXD_LEN , + descr,E1000E_TXD_LEN );e1000e_macreg_write (d,E1000E_TDT , (tail +1 ) % len);/* Read WB data for the packet transmitted */ -memread (d->tx_ring + tail *E1000E_TXD_LEN , descr,E1000E_TXD_LEN ); +qtest_memread (d_pci->pci_dev.bus->qts, d->tx_ring + tail *E1000E_TXD_LEN , + descr,E1000E_TXD_LEN ); }void e1000e_rx_ring_push (QE1000E *d,void *descr) { +QE1000E_PCI *d_pci =container_of (d,QE1000E_PCI , e1000e);uint32_t tail =e1000e_macreg_read (d,E1000E_RDT );uint32_t len =e1000e_macreg_read (d,E1000E_RDLEN ) /E1000E_RXD_LEN ; -memwrite (d->rx_ring + tail *E1000E_RXD_LEN , descr,E1000E_RXD_LEN ); +qtest_memwrite (d_pci->pci_dev.bus->qts, d->rx_ring + tail *E1000E_RXD_LEN , + descr,E1000E_RXD_LEN );e1000e_macreg_write (d,E1000E_RDT , (tail +1 ) % len);/* Read WB data for the packet received */ -memread (d->rx_ring + tail *E1000E_RXD_LEN , descr,E1000E_RXD_LEN ); +qtest_memread (d_pci->pci_dev.bus->qts, d->rx_ring + tail *E1000E_RXD_LEN , + descr,E1000E_RXD_LEN ); }static void e1000e_foreach_callback (QPCIDevice *dev,int devfn,void *data)
@@ -123,7 +129,7 @@ void e1000e_wait_isr(QE1000E *d, uint16_t msg_id)if (qpci_msix_pending (&d_pci->pci_dev, msg_id)) {return ; } -clock_step (10000 ); +qtest_clock_step (d_pci->pci_dev.bus->qts,10000 ); }while (g_get_monotonic_time () < end_time);g_error ("Timeout expired" );
Signature · 1 line
2.18.1
Re: [Qemu-devel] [PATCH v2 2/6] tests/libqos/e1000e: Make e1000e libqos functions independent from global_qtest
Quoted 11 lines · Thomas Huth
libqos library functions should never depend on functions (like
memread(),memwrite()orclock_step()) that requireglobal_qtestto be set, since library functions might get used in qtests that track multiple states, too. Thus let's replace the global_qtest-related functions with their independent counterparts.Reviewed-by Laurent Vivier <[email protected]>Signed-off-by Thomas Huth <[email protected]>--- tests/libqos/e1000e.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
PATCH v2 3/6 tests/libqos: Replace clock_step with qtest_clock_step in virtio code
In reply to Thomas HuthLibrary functions should not rely on functions that require global_qtest (since they might get used in tests that deal with multiple states). Commit 1999a70a05ad603d ("Make generic virtio code independent from global_qtest") already tried to clean the libqos virtio code, but I missed to replace the clock_step() function. Thus change it now to qtest_clock_step() instead.
The logic of the qvirtio_wait_config_isr() function is now pushed to the virtio-mmio.c and virtio-pci.c files instead, since we can get the QTestState here easily.
--- tests/libqos/virtio-mmio.c | 14 +++++++++++++- tests/libqos/virtio-pci.c | 14 +++++++++++++- tests/libqos/virtio.c | 20 ++++++-------------- tests/libqos/virtio.h | 6 +++--- tests/virtio-blk-test.c | 3 ++- 5 files changed, 37 insertions(+), 20 deletions(-)
tests/libqos/virtio-mmio.c +13 -1
@@ -101,6 +101,18 @@ static bool qvirtio_mmio_get_config_isr_status(QVirtioDevice *d)return false; } +static void qvirtio_mmio_wait_config_isr_status (QVirtioDevice *d, +gint64 timeout_us) +{ +QVirtioMMIODevice *dev =container_of (d, QVirtioMMIODevice, vdev); +gint64 start_time =g_get_monotonic_time (); + +do { +g_assert (g_get_monotonic_time () - start_time <= timeout_us); +qtest_clock_step (dev->qts,100 ); + }while (!qvirtio_mmio_get_config_isr_status (d)); +} +static void qvirtio_mmio_queue_select (QVirtioDevice *d,uint16_t index) {QVirtioMMIODevice *dev =container_of (d, QVirtioMMIODevice, vdev);
@@ -179,7 +191,7 @@ const QVirtioBus qvirtio_mmio = { .get_status = qvirtio_mmio_get_status, .set_status = qvirtio_mmio_set_status, .get_queue_isr_status = qvirtio_mmio_get_queue_isr_status, - .get_config_isr_status = qvirtio_mmio_get_config_isr_status, + .wait_config_isr_status = qvirtio_mmio_wait_config_isr_status, .queue_select = qvirtio_mmio_queue_select, .get_queue_size = qvirtio_mmio_get_queue_size, .set_queue_address = qvirtio_mmio_set_queue_address,
tests/libqos/virtio-pci.c +13 -1
@@ -175,6 +175,18 @@ static bool qvirtio_pci_get_config_isr_status(QVirtioDevice *d) } } +static void qvirtio_pci_wait_config_isr_status (QVirtioDevice *d, +gint64 timeout_us) +{ +QVirtioPCIDevice *dev =container_of (d, QVirtioPCIDevice, vdev); +gint64 start_time =g_get_monotonic_time (); + +do { +g_assert (g_get_monotonic_time () - start_time <= timeout_us); +qtest_clock_step (dev->pdev->bus->qts,100 ); + }while (!qvirtio_pci_get_config_isr_status (d)); +} +static void qvirtio_pci_queue_select (QVirtioDevice *d,uint16_t index) {QVirtioPCIDevice *dev =container_of (d, QVirtioPCIDevice, vdev);
@@ -257,7 +269,7 @@ const QVirtioBus qvirtio_pci = { .get_status = qvirtio_pci_get_status, .set_status = qvirtio_pci_set_status, .get_queue_isr_status = qvirtio_pci_get_queue_isr_status, - .get_config_isr_status = qvirtio_pci_get_config_isr_status, + .wait_config_isr_status = qvirtio_pci_wait_config_isr_status, .queue_select = qvirtio_pci_queue_select, .get_queue_size = qvirtio_pci_get_queue_size, .set_queue_address = qvirtio_pci_set_queue_address,
tests/libqos/virtio.c +6 -14
@@ -82,13 +82,13 @@ void qvirtio_set_driver_ok(QVirtioDevice *d) VIRTIO_CONFIG_S_DRIVER | VIRTIO_CONFIG_S_ACKNOWLEDGE); } -void qvirtio_wait_queue_isr (QVirtioDevice *d, +void qvirtio_wait_queue_isr (QTestState *qts,QVirtioDevice *d,QVirtQueue *vq,gint64 timeout_us) {gint64 start_time =g_get_monotonic_time ();for (;;) { -clock_step (100 ); +qtest_clock_step (qts,100 );if (d->bus->get_queue_isr_status (d, vq)) {return ; }
@@ -109,8 +109,8 @@ uint8_t qvirtio_wait_status_byte_no_isr(QTestState *qts, QVirtioDevice *d,gint64 start_time =g_get_monotonic_time ();uint8_t val; -while ((val =readb (addr)) ==0xff ) { -clock_step (100 ); +while ((val =qtest_readb (qts, addr)) ==0xff ) { +qtest_clock_step (qts,100 );g_assert (!d->bus->get_queue_isr_status (d, vq));g_assert (g_get_monotonic_time () - start_time <= timeout_us); }
@@ -137,7 +137,7 @@ void qvirtio_wait_used_elem(QTestState *qts, QVirtioDevice *d,for (;;) {uint32_t got_desc_idx; -clock_step (100 ); +qtest_clock_step (qts,100 );if (d->bus->get_queue_isr_status (d, vq) &&qvirtqueue_get_buf (qts, vq, &got_desc_idx, len)) {
@@ -151,15 +151,7 @@ void qvirtio_wait_used_elem(QTestState *qts, QVirtioDevice *d,void qvirtio_wait_config_isr (QVirtioDevice *d,gint64 timeout_us) { -gint64 start_time =g_get_monotonic_time (); - -for (;;) { -clock_step (100 ); -if (d->bus->get_config_isr_status (d)) { -return ; - } -g_assert (g_get_monotonic_time () - start_time <= timeout_us); - } + d->bus->wait_config_isr_status (d, timeout_us); } void qvring_init(QTestState *qts, const QGuestAllocator *alloc, QVirtQueue *vq,
tests/libqos/virtio.h +3 -3
@@ -69,8 +69,8 @@ struct QVirtioBus {/* Get the queue ISR status of the device */ bool (*get_queue_isr_status)(QVirtioDevice *d,QVirtQueue *vq); -/* Get the configuration ISR status of the device */ -bool (*get_config_isr_status)(QVirtioDevice *d); +/* Wait for the configuration ISR status of the device */ +void (*wait_config_isr_status)(QVirtioDevice *d,gint64 timeout_us);/* Select a queue to work on */ void (*queue_select)(QVirtioDevice *d,uint16_t index);
@@ -112,7 +112,7 @@ void qvirtio_set_acknowledge(QVirtioDevice *d);void qvirtio_set_driver (QVirtioDevice *d);void qvirtio_set_driver_ok (QVirtioDevice *d); -void qvirtio_wait_queue_isr (QVirtioDevice *d, +void qvirtio_wait_queue_isr (QTestState *qts,QVirtioDevice *d,QVirtQueue *vq,gint64 timeout_us); uint8_t qvirtio_wait_status_byte_no_isr(QTestState *qts, QVirtioDevice *d, QVirtQueue *vq,
tests/virtio-blk-test.c +2 -1
@@ -737,6 +737,7 @@ static void resize(void *obj, void *data, QGuestAllocator *t_alloc)int n_size =TEST_IMAGE_SIZE /2 ;uint64_t capacity;QVirtQueue *vq; +QTestState *qts = global_qtest; vq =qvirtqueue_setup (dev, t_alloc,0 );
@@ -746,7 +747,7 @@ static void resize(void *obj, void *data, QGuestAllocator *t_alloc)" 'arguments': { 'device': 'drive0', " " 'size': %d } }", n_size); -qvirtio_wait_queue_isr (dev, vq,QVIRTIO_BLK_TIMEOUT_US ); +qvirtio_wait_queue_isr (qts, dev, vq,QVIRTIO_BLK_TIMEOUT_US ); capacity =qvirtio_config_readq (dev,0 ); g_assert_cmpint(capacity, ==, n_size / 512);
Signature · 1 line
2.18.1
Re: [Qemu-devel] [PATCH v2 3/6] tests/libqos: Replace clock_step with qtest_clock_step in virtio code
Quoted 10 lines · Thomas Huth
Library functions should not rely on functions that require
global_qtest(since they might get used in tests that deal with multiple states). Commit1999a70a05ad603d("Make generic virtio code independent fromglobal_qtest") already tried to clean the libqos virtio code, but I missed to replace theclock_step()function. Thus change it now toqtest_clock_step()instead.
The logic of theqvirtio_wait_config_isr()function is now pushed to thevirtio-mmio.candvirtio-pci.cfiles instead, since we can get the QTestState here easily.
Quoted 2 lines
Signed-off-by Thomas Huth <[email protected]>---
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v2 3/6] tests/libqos: Replace clock_step with qtest_clock_step in virtio code
In reply to Thomas HuthQuoted 10 lines · Thomas Huth
Library functions should not rely on functions that require
global_qtest(since they might get used in tests that deal with multiple states). Commit1999a70a05ad603d("Make generic virtio code independent fromglobal_qtest") already tried to clean the libqos virtio code, but I missed to replace theclock_step()function. Thus change it now toqtest_clock_step()instead.
The logic of theqvirtio_wait_config_isr()function is now pushed to thevirtio-mmio.candvirtio-pci.cfiles instead, since we can get the QTestState here easily.
Quoted 8 lines
Signed-off-by Thomas Huth <[email protected]>--- tests/libqos/virtio-mmio.c | 14 +++++++++++++- tests/libqos/virtio-pci.c | 14 +++++++++++++- tests/libqos/virtio.c | 20 ++++++-------------- tests/libqos/virtio.h | 6 +++--- tests/virtio-blk-test.c | 3 ++- 5 files changed, 37 insertions(+), 20 deletions(-)
PATCH v2 4/6 tests: Remove unnecessary global_qtest references
In reply to Thomas HuthWe are going to remove global_qtest from the main libqtest library soon, so tests that do not urgently need global_qtest anymore should be cleaned from the unnecessary references.
--- tests/ahci-test.c | 1 - tests/bios-tables-test.c | 1 - tests/ivshmem-test.c | 3 --- tests/rtas-test.c | 1 - 4 files changed, 6 deletions(-)
tests/ahci-test.c +0 -1
@@ -200,7 +200,6 @@ static void ahci_shutdown(AHCIQState *ahci) {QOSState *qs = ahci->parent; -assert (!global_qtest);ahci_clean_mem (ahci);free_ahci_device (ahci->dev);g_free (ahci);
tests/bios-tables-test.c +0 -1
@@ -626,7 +626,6 @@ static void test_acpi_one(const char *params, test_data *data)test_smbios_structs (data); } -assert (!global_qtest);qtest_quit (data->qts);g_free (args); }
tests/ivshmem-test.c +0 -3
@@ -100,7 +100,6 @@ static inline void write_mem(IVState *s, uint64_t off,static void cleanup_vm (IVState *s) { -assert (!global_qtest);g_free (s->dev);qtest_shutdown (s->qs); }
@@ -388,7 +387,6 @@ static void test_ivshmem_hotplug(void) qts =qtest_init ("-object memory-backend-ram,size=1M,id=mb1" ); - global_qtest = qts;/* TODO: Get rid of global_qtest here */ qtest_qmp_device_add (qts,"ivshmem-plain" ,"iv1" ,"{'addr': %s, 'memdev': 'mb1'}" ,stringify (PCI_SLOT_HP ));
@@ -397,7 +395,6 @@ static void test_ivshmem_hotplug(void) }qtest_quit (qts); - global_qtest =NULL ; }static void test_ivshmem_memdev (void )
tests/rtas-test.c +0 -1
@@ -14,7 +14,6 @@ static void test_rtas_get_time_of_day(void)time_t t1, t2; qs =qtest_spapr_boot ("-machine pseries" ); - global_qtest = qs->qts; t1 =time (NULL ); ret =qrtas_get_time_of_day (qs->qts, &qs->alloc, &tm, &ns);
Signature · 1 line
2.18.1
Re: [Qemu-devel] [PATCH v2 4/6] tests: Remove unnecessary global_qtest references
Quoted 11 lines · Thomas Huth
We are going to remove
global_qtestfrom the main libqtest library soon, so tests that do not urgently needglobal_qtestanymore should be cleaned from the unnecessary references.Signed-off-by Thomas Huth <[email protected]>--- tests/ahci-test.c | 1 - tests/bios-tables-test.c | 1 - tests/ivshmem-test.c | 3 --- tests/rtas-test.c | 1 - 4 files changed, 6 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v2 4/6] tests: Remove unnecessary global_qtest references
In reply to Thomas HuthQuoted 11 lines · Thomas Huth
We are going to remove
global_qtestfrom the main libqtest library soon, so tests that do not urgently needglobal_qtestanymore should be cleaned from the unnecessary references.Signed-off-by Thomas Huth <[email protected]>--- tests/ahci-test.c | 1 - tests/bios-tables-test.c | 1 - tests/ivshmem-test.c | 3 --- tests/rtas-test.c | 1 - 4 files changed, 6 deletions(-)
PATCH v2 5/6 tests/libqtest: Move global_test wrapper function into a separate header
In reply to Thomas HuthWe want libqtest.h to become completely independen from global_qtest (so that the wrapper functions are not used by accident anymore). As a first step, move the wrapper functions into a separate header file.
--- MAINTAINERS | 2 +- tests/libqtest-single.h | 311 ++++++++++++++++++++++++++++++++++++++++ tests/libqtest.c | 11 -- tests/libqtest.h | 287 +----------------------------------- 4 files changed, 313 insertions(+), 298 deletions(-) create mode 100644 tests/libqtest-single.h
MAINTAINERS +1 -1
@@ -2078,7 +2078,7 @@ R: Paolo Bonzini <[email protected]> S: Maintained F: qtest.c F: accel/qtest.c -F: tests/libqtest.* +F: tests/libqtest* F: tests/libqos/ F: tests/*-test.c
tests/libqtest-single.h new file +311 -0
311 lines not on this page · raw message
tests/libqtest.c +0 -11
@@ -1106,17 +1106,6 @@ void qtest_memset(QTestState *s, uint64_t addr, uint8_t pattern, size_t size)qtest_rsp (s,0 ); } -QDict *qmp (const char *fmt, ...) -{ -va_list ap; -QDict *response; - -va_start (ap, fmt); - response =qtest_vqmp (global_qtest, fmt, ap); -va_end (ap); -return response; -} -void qtest_qmp_assert_success (QTestState *qts,const char *fmt, ...) {va_list ap;
tests/libqtest.h +1 -286
299 lines not on this page · raw message
Signature · 1 line
2.18.1
Re: [Qemu-devel] [PATCH v2 5/6] tests/libqtest: Move global_test wrapper function into a separate header
Quoted 1 line · Thomas Huth
We want
libqtest.hto become completely independen fromglobal_qtest
independent
Quoted 14 lines
(so that the wrapper functions are not used by accident anymore). As a first step, move the wrapper functions into a separate header file.
Signed-off-by Thomas Huth <[email protected]>--- MAINTAINERS | 2 +- tests/libqtest-single.h | 311 ++++++++++++++++++++++++++++++++++++++++ tests/libqtest.c | 11 -- tests/libqtest.h | 287 +----------------------------------- 4 files changed, 313 insertions(+), 298 deletions(-) create mode 100644 tests/libqtest-single.htests/libqtest-single.h new file +1
-0+/**
tests/libqtest-single.h line 53
Quoted 10 lines
tests/libqtest-single.h new file +10
-0+* qmp: +* @fmt...: QMP message to send to qemu, formatted like +* qobject_from_jsonf_nofail(). See parse_escape() for what's +* supported after '%'. +* +* Sends a QMP message to QEMU and returns the response. +*/ +GCC_FMT_ATTR(1, 2) +static inline QDict *qmp (const char *fmt, ...) +{
I'm a bit surprised gcc doesn't complain about inlining a va_arg function, but since it works, I'm fine with the approach.
Quoted 6 lines
+++
b/tests/libqtest.ctests/libqtest.c +0
-1@@ -1106,17 +1106,6 @@ void qtest_memset(QTestState *s, uint64_t addr, uint8_t pattern, size_t size)qtest_rsp (s,0 ); } -QDict *qmp (const char *fmt, ...)
tests/libqtest.c void qtest_memset(QTestState *s, uint64_t addr, uint8_t pattern, size_t size) · line 1119
Quoted 10 lines
tests/libqtest.c +0
-10-{ -va_list ap; -QDict *response; - -va_start (ap, fmt); - response =qtest_vqmp (global_qtest, fmt, ap); -va_end (ap); -return response; -} -
Nice - we've reduced the use of global_qtest to just a single optional header!
Quoted 5 lines
tests/libqtest.h +1
-3+++ b/tests/libqtest.h -/** -* clock_step: -* @step: Number of nanoseconds to advance the clock by.
tests/libqtest.h QDict *qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2); · line 644
Quoted 10 lines
tests/libqtest.h +1
-9-* -* Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds. -* -* Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. -*/ -static inline int64_t clock_step (int64_t step) -{ -return qtest_clock_step (global_qtest, step); -} +#include "libqtest-single.h"
Well, almost. I guess this commit is the code motion, and the next one actually fixes clients to track the rename, so this #include is temporary (I hope). It's just churn to put a TODO comment in this commit that would get removed in the next. So,
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v2 5/6] tests/libqtest: Move global_test wrapper function into a separate header
In reply to Thomas HuthQuoted 21 lines · Thomas Huth
tests/libqtest-single.h new file +15
-0@@ -0,0 +1,311 @@ +/* +* QTest - wrappers for test with single QEMU instances +* +* Copyright IBM, Corp. 2012 +* Copyright Red Hat, Inc. 2012 +* Copyright SUSE LINUX Products GmbH 2013 +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +#ifndef LIBQTEST_SINGLE_H +#define LIBQTEST_SINGLE_H + +/** +* qtest_start:
tests/libqtest-single.h line 25
Quoted 10 lines
tests/libqtest-single.h new file +10
-0+* @args: other arguments to pass to QEMU +* +* Start QEMU and assign the resulting #QTestState to a global variable. +* The global variable is used by "shortcut" functions documented below. +* +* Returns: #QTestState instance. +*/ +static inline QTestState *qtest_start (const char *args) +{ + global_qtest =qtest_init (args);
Where are global_qtest and qtest_init() declared? I would expect compilation to fail if a .c file included just "libqtest-single.h". Missing #include?
If this header is not supposed to be included by .c files, please include at least a comment or use a magic #define + #ifdef to prevent inclusion.
Re: [Qemu-devel] [PATCH v2 5/6] tests/libqtest: Move global_test wrapper function into a separate header
Quoted 7 lines · Stefan Hajnoczi
Quoted 5 lines · Thomas Huth
tests/libqtest-single.h new file +0
-0
Quoted 6 lines
tests/libqtest-single.h line 25
Quoted 3 lines
tests/libqtest-single.h new file +3
-0+static inline QTestState *qtest_start (const char *args) +{ + global_qtest =qtest_init (args);Where are
global_qtestandqtest_init()declared? I would expect compilation to fail if a .c file included just "libqtest-single.h".
In patch 5, "libqtest.h" declares global_qtest, then includes "libqtest-single.h"; no file includes it standalone. Then in patch 6, the roles are swapped; "libqtest-single.h" declares global_qtest and includes "libqtest.h". But yes, the commit message could do better in explaining this.
Quoted 5 lines
Missing #include?
If this header is not supposed to be included by .c files, please include at least a comment or use a magic #define + #ifdef to prevent inclusion.
The condition is transient for one patch; but calling it out better in the commit message and/or as a comment (especially since the #include "libqtest-single.h" is not in the normal #includes up front) would help.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v2 5/6] tests/libqtest: Move global_test wrapper function into a separate header
Quoted 15 lines · Eric Blake
Quoted 7 lines · Stefan Hajnoczi
Quoted 5 lines · Thomas Huth
tests/libqtest-single.h new file +0
-0Quoted 6 lines
tests/libqtest-single.h line 25
Quoted 3 lines
tests/libqtest-single.h new file +3
-0+static inline QTestState *qtest_start (const char *args) +{ + global_qtest =qtest_init (args);Where are
global_qtestandqtest_init()declared? I would expect compilation to fail if a .c file included just "libqtest-single.h".
Quoted 5 lines
In patch 5, "
libqtest.h" declaresglobal_qtest, then includes "libqtest-single.h"; no file includes it standalone. Then in patch 6, the roles are swapped; "libqtest-single.h" declaresglobal_qtestand includes "libqtest.h". But yes, the commit message could do better in explaining this.
Right. Let me add something like this to the patch description here:
"The new header is only included from libqtest.h for now, so that there is no difference to the users of libqtest.h yet. In the next patch, we will switch this, so that the users of the global_qtest-related functions will be using libqtest-single.h directly and libqtest.h becomes completely independent of this."
Thomas
PATCH v2 6/6 tests/libqtest: Use libqtest-single.h in tests that require global_qtest
In reply to Thomas HuthTests that require global_qtest or the related wrapper functions now use the libqtest-single.h header that is dedicated for everything related to global_qtest. The core libqtest.c and libqtest.h files are now completely indepedent from global_qtest, so that the core library is now not depending on a global state anymore.
--- tests/cpu-plug-test.c | 2 +- tests/display-vga-test.c | 2 +- tests/e1000e-test.c | 2 +- tests/fdc-test.c | 2 +- tests/i440fx-test.c | 2 +- tests/i82801b11-test.c | 2 +- tests/intel-hda-test.c | 2 +- tests/ioh3420-test.c | 2 +- tests/ipmi-kcs-test.c | 3 +-- tests/libqtest-single.h | 4 ++++ tests/libqtest.c | 2 -- tests/libqtest.h | 4 ---- tests/m25p80-test.c | 2 +- tests/qos-test.c | 2 +- tests/rtc-test.c | 2 +- tests/rtl8139-test.c | 2 +- tests/test-arm-mptimer.c | 2 +- tests/test-netfilter.c | 2 +- tests/test-x86-cpuid-compat.c | 2 +- tests/tmp105-test.c | 2 +- tests/tpm-crb-test.c | 2 +- tests/tpm-tests.c | 2 +- tests/tpm-tis-test.c | 2 +- tests/usb-hcd-ohci-test.c | 2 +- tests/usb-hcd-uhci-test.c | 2 +- tests/usb-hcd-xhci-test.c | 2 +- tests/vhost-user-test.c | 2 +- tests/virtio-blk-test.c | 2 +- tests/virtio-ccw-test.c | 2 +- tests/virtio-net-test.c | 2 +- tests/virtio-scsi-test.c | 2 +- tests/virtio-serial-test.c | 2 +- 32 files changed, 33 insertions(+), 36 deletions(-)
tests/cpu-plug-test.c +1 -1
@@ -10,7 +10,7 @@#include "qemu/osdep.h" #include "qemu-common.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "qapi/qmp/qdict.h" struct PlugTestData {
tests/display-vga-test.c +1 -1
@@ -8,7 +8,7 @@*/ #include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" static void pci_cirrus (void ) {
tests/e1000e-test.c +1 -1
@@ -26,7 +26,7 @@#include "qemu/osdep.h" #include "qemu-common.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "qemu-common.h" #include "libqos/pci-pc.h" #include "qemu/sockets.h"
tests/fdc-test.c +1 -1
@@ -25,7 +25,7 @@#include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "qapi/qmp/qdict.h" #include "qemu-common.h"
tests/i440fx-test.c +1 -1
@@ -14,7 +14,7 @@#include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "libqos/pci.h" #include "libqos/pci-pc.h" #include "hw/pci/pci_regs.h"
tests/i82801b11-test.c +1 -1
@@ -8,7 +8,7 @@*/ #include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" /* Tests only initialization so far. TODO: Replace with functional tests */ static void nop (void )
tests/intel-hda-test.c +1 -1
@@ -8,7 +8,7 @@*/ #include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" #define HDA_ID "hda0"#define CODEC_DEVICES " -device hda-output,bus=" HDA_ID ".0" \
tests/ioh3420-test.c +1 -1
@@ -8,7 +8,7 @@*/ #include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" /* Tests only initialization so far. TODO: Replace with functional tests */ static void nop (void )
tests/ipmi-kcs-test.c +1 -2
@@ -24,8 +24,7 @@#include "qemu/osdep.h" - -#include "libqtest.h" +#include "libqtest-single.h" #define IPMI_IRQ 5
tests/libqtest-single.h +4 -0
@@ -11,6 +11,10 @@#ifndef LIBQTEST_SINGLE_H #define LIBQTEST_SINGLE_H +#include "libqtest.h" + +QTestState *global_qtest __attribute__((common, weak)); +/** * qtest_start: * @args: other arguments to pass to QEMU
tests/libqtest.c +0 -2
@@ -35,8 +35,6 @@#define SOCKET_TIMEOUT 50#define SOCKET_MAX_FDS 16 -QTestState *global_qtest; -struct QTestState {int fd;
tests/libqtest.h +0 -4
@@ -22,8 +22,6 @@typedef struct QTestState QTestState ; -extern QTestState *global_qtest; -/** * qtest_initf: * @fmt...: Format for creating other arguments to pass to QEMU, formatted
@@ -641,8 +639,6 @@ void qtest_add_abrt_handler(GHookFunc fn, const void *data); void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...) GCC_FMT_ATTR(2, 3); -#include "libqtest-single.h" -QDict *qmp_fd_receive (int fd); void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, const char *fmt, va_list ap) GCC_FMT_ATTR(4, 0);
tests/m25p80-test.c +1 -1
@@ -25,7 +25,7 @@#include "qemu/osdep.h" #include "qemu/bswap.h" -#include "libqtest.h" +#include "libqtest-single.h" /* * ASPEED SPI Controller registers
tests/qos-test.c +1 -1
@@ -18,7 +18,7 @@#include "qemu/osdep.h" #include <getopt.h> -#include "libqtest.h" +#include "libqtest-single.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qbool.h" #include "qapi/qmp/qstring.h"
tests/rtc-test.c +1 -1
@@ -13,7 +13,7 @@#include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "qemu/timer.h" #include "hw/timer/mc146818rtc_regs.h"
tests/rtl8139-test.c +1 -1
@@ -8,7 +8,7 @@*/ #include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "libqos/pci-pc.h" #include "qemu/timer.h" #include "qemu-common.h"
tests/test-arm-mptimer.c +1 -1
@@ -9,7 +9,7 @@#include "qemu/osdep.h" #include "qemu/timer.h" -#include "libqtest.h" +#include "libqtest-single.h" #define TIMER_BLOCK_SCALE (s) ((((s) & 0xff) + 1) * 10)
tests/test-netfilter.c +1 -1
@@ -9,7 +9,7 @@*/ #include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "qapi/qmp/qdict.h" /* add a netfilter to a netdev and then remove it */
tests/test-x86-cpuid-compat.c +1 -1
@@ -4,7 +4,7 @@#include "qapi/qmp/qlist.h" #include "qapi/qmp/qnum.h" #include "qapi/qmp/qbool.h" -#include "libqtest.h" +#include "libqtest-single.h" static char *get_cpu0_qom_path (void ) {
tests/tmp105-test.c +1 -1
@@ -9,7 +9,7 @@#include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "libqos/qgraph.h" #include "libqos/i2c.h" #include "qapi/qmp/qdict.h"
tests/tpm-crb-test.c +1 -1
@@ -15,7 +15,7 @@#include "hw/acpi/tpm.h" #include "io/channel-socket.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "qemu/module.h" #include "tpm-emu.h"
tests/tpm-tests.c +1 -1
@@ -15,7 +15,7 @@#include "qemu/osdep.h" #include <glib/gstdio.h> -#include "libqtest.h" +#include "libqtest-single.h" #include "tpm-tests.h" static bool
tests/tpm-tis-test.c +1 -1
@@ -17,7 +17,7 @@#include "hw/acpi/tpm.h" #include "io/channel-socket.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "qemu/module.h" #include "tpm-emu.h"
tests/usb-hcd-ohci-test.c +1 -1
@@ -8,7 +8,7 @@*/ #include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "qemu/module.h" #include "libqos/usb.h" #include "libqos/qgraph.h"
tests/usb-hcd-uhci-test.c +1 -1
@@ -8,7 +8,7 @@*/ #include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "libqos/libqos.h" #include "libqos/usb.h" #include "libqos/libqos-pc.h"
tests/usb-hcd-xhci-test.c +1 -1
@@ -8,7 +8,7 @@*/ #include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "libqos/usb.h"
tests/vhost-user-test.c +1 -1
@@ -10,7 +10,7 @@#include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" #include "qemu/config-file.h"
tests/virtio-blk-test.c +1 -1
@@ -9,7 +9,7 @@*/ #include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "qemu/bswap.h" #include "qemu/module.h" #include "standard-headers/linux/virtio_blk.h"
tests/virtio-ccw-test.c +1 -1
@@ -14,7 +14,7 @@*/ #include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "libqos/virtio.h" static void virtio_balloon_nop (void )
tests/virtio-net-test.c +1 -1
@@ -9,7 +9,7 @@#include "qemu/osdep.h" #include "qemu-common.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "qemu/iov.h" #include "qemu/module.h" #include "qapi/qmp/qdict.h"
tests/virtio-scsi-test.c +1 -1
@@ -9,7 +9,7 @@*/ #include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "qemu/module.h" #include "scsi/constants.h" #include "libqos/libqos-pc.h"
tests/virtio-serial-test.c +1 -1
@@ -8,7 +8,7 @@*/ #include "qemu/osdep.h" -#include "libqtest.h" +#include "libqtest-single.h" #include "qemu/module.h" #include "libqos/virtio-serial.h"
Signature · 1 line
2.18.1
Re: [Qemu-devel] [PATCH v2 6/6] tests/libqtest: Use libqtest-single.h in tests that require global_qtest
Quoted 10 lines · Thomas Huth
Tests that require
global_qtestor the related wrapper functions now use thelibqtest-single.hheader that is dedicated for everything related toglobal_qtest. The corelibqtest.candlibqtest.hfiles are now completely indepedent fromglobal_qtest, so that the core library is now not depending on a global state anymore.Signed-off-by Thomas Huth <[email protected]>---
32 files changed, 33 insertions(+), 36 deletions(-)
Big list, but looks reasonable and mechanical.
Thanks again for seeing this through to conclusion (my RFC patches that kicked off the idea are now a few years old...).
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v2 6/6] tests/libqtest: Use libqtest-single.h in tests that require global_qtest
In reply to Thomas HuthQuoted 33 lines · Thomas Huth
Tests that require
global_qtestor the related wrapper functions now use thelibqtest-single.hheader that is dedicated for everything related toglobal_qtest. The corelibqtest.candlibqtest.hfiles are now completely indepedent fromglobal_qtest, so that the core library is now not depending on a global state anymore.Signed-off-by Thomas Huth <[email protected]>--- tests/cpu-plug-test.c | 2 +- tests/display-vga-test.c | 2 +- tests/e1000e-test.c | 2 +- tests/fdc-test.c | 2 +- tests/i440fx-test.c | 2 +- tests/i82801b11-test.c | 2 +- tests/intel-hda-test.c | 2 +- tests/ioh3420-test.c | 2 +- tests/ipmi-kcs-test.c | 3 +-- tests/libqtest-single.h | 4 ++++ tests/libqtest.c | 2 -- tests/libqtest.h | 4 ---- tests/m25p80-test.c | 2 +- tests/qos-test.c | 2 +- tests/rtc-test.c | 2 +- tests/rtl8139-test.c | 2 +- tests/test-arm-mptimer.c | 2 +- tests/test-netfilter.c | 2 +- tests/test-x86-cpuid-compat.c | 2 +- tests/tmp105-test.c | 2 +- tests/tpm-crb-test.c | 2 +- tests/tpm-tests.c | 2 +- tests/tpm-tis-test.c | 2 +- tests/usb-hcd-ohci-test.c | 2 +- tests/usb-hcd-uhci-test.c | 2 +-
Quoted 8 lines
tests/usb-hcd-xhci-test.c | 2 +- tests/vhost-user-test.c | 2 +- tests/virtio-blk-test.c | 2 +- tests/virtio-ccw-test.c | 2 +- tests/virtio-net-test.c | 2 +- tests/virtio-scsi-test.c | 2 +- tests/virtio-serial-test.c | 2 +- 32 files changed, 33 insertions(+), 36 deletions(-)
Quoted 12 lines · Thomas Huth
global_qtestand the related wrapper functions often caused trouble in the past - if they are used somewhere in the libqtest or libqos library code, it's hard to write tests that properly track multiple test states (like migration tests).This patch series finally gets rid of the remaining
global_qtestdependencies in the core libqtest code. The first patches are used to clean up some files that should not useglobal_qtestanymore, then the wrapper functions and theglobal_qtestdefinition get moved to a separate header file calledlibqtest-single.h- which then should only be used in tests that track only a single test state.
Quoted 4 lines
v2:
- Do not add parameter toqvirtio_wait_config_isr(), but push the logic intovirtio-mmio.candvirtio-pci.cinstead since we have access to the test state here (as suggested by Laurent).
Looks good overall. I posted one comment on a patch.
Stefan