Skip to contentSkip to conversation

Preliminary libqtest cleanups

PATCH Superseded Eric Blake 9 participants 99 messages Sep 1, 2017 – Sep 8, 2017 Page 1 of 2

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Eric Blake

author
#0 lore raw

v6 cover Preliminary libqtest cleanups

Markus gave some good advice on my 'v4: Clean up around qmp() and hmp()' series [1], but Paolo made the suggestion on v5 [2] that we are probably better off avoiding dependence on a magic global variable, rather than making such dependence even more prominent. So, this round of patches starts to head in the direction of more explicit use of a QTestState object - particularly in all tests that have more than one test state active at a given time. There is still more work to do (patch 28 shows how many tests still depend on global_qtest), and I'd still like to do even more renaming (for example, rather than having qtest_inb(s, addr) and inb(addr), I'd rather have a single inb(s, addr) once I get rid of all dependence on global_qtest, but this series was getting long enough that I want to get review started on the earlier parts that might as well go in the tree now rather than waiting for the whole conversion series to be complete. (Or, by posting this alternative that goes the opposite direction from v5, we may decide that depending on global_qtest is not so bad after all, and just go with v5 instead of this version.)

There's still more libqtest cleanups in my queue, in particular all the work around making qmp("...") friendlier to use and compatible with gcc -Wformat checking, but we'll take it one step at a time.

[1] https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg00595.html
[2] https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg03589.html

Since v5:
001/29:[down] 'tests: Improve .gitignore for tests/multiboot' 002/29:[down] 'tests: Sort .gitignore'
003/29:[----] [--] 'test-qga: Kill broken and dead QGA_TEST_SIDE_EFFECTING code' 004/29:[----] [--] 'qtest: Don't perform side effects inside assertion' 005/29:[----] [--] 'numa-test: Use hmp()'
006/29:[----] [-C] 'tests: Clean up wait for event'
007/29:[----] [--] 'libqtest: Remove dead qtest_instances variable' 008/29:[----] [--] 'libqtest: Let socket_send() compute length' 009/29:[----] [--] 'libqtest: Use qemu_strtoul()'
010/29:[----] [--] 'libqtest: Topologically sort functions' 011/29:[----] [--] 'libqtest: Inline qtest_query_target_endianness()' 012/29:[down] 'libqos: Track QTestState with QPCIBus'
013/29:[down] 'libqos: Use explicit QTestState for pci operations' 014/29:[down] 'libqos: Use explicit QTestState for fw_cfg operations' 015/29:[down] 'libqos: Use explicit QTestState for rtas operations' 016/29:[down] 'libqos: Use explicit QTestState for virtio operations' 017/29:[down] 'ahci-test: Drop dependence on global_qtest' 018/29:[down] 'ivshmem-test: Drop dependence on global_qtest' 019/29:[down] 'postcopy-test: Drop dependence on global_qtest' 020/29:[down] 'vhost-user-test: Drop dependence on global_qtest' 021/29:[down] 'qmp-test: Drop dependence on global_qtest' 022/29:[down] 'tests/boot-sector: Drop dependence on global_qtest' 023/29:[down] 'tests/acpi-utils: Drop dependence on global_qtest' 024/29:[down] 'bios-tables-test: Drop dependence on global_qtest' 025/29:[down] 'wdt_ib700-test: Drop dependence on global_qtest' 026/29:[down] 'fw_cfg-test: Drop dependence on global_qtest' 027/29:[down] 'libqtest: Make qtest_init() accept format string' 028/29:[down] 'libqtest: Remove qtest_start() and qtest_end() shortcuts' 029/29:[down] 'libqtest: Rename qtest_init() to qtest_start()'

Eric Blake (28):
tests: Improve .gitignore for tests/multiboot
tests: Sort .gitignore
test-qga: Kill broken and dead QGA_TEST_SIDE_EFFECTING code
qtest: Don't perform side effects inside assertion
numa-test: Use hmp()
libqtest: Remove dead qtest_instances variable
libqtest: Let socket_send() compute length
libqtest: Use qemu_strtoul()
libqtest: Topologically sort functions
libqtest: Inline qtest_query_target_endianness()
libqos: Track QTestState with QPCIBus
libqos: Use explicit QTestState for pci operations
libqos: Use explicit QTestState for fw_cfg operations
libqos: Use explicit QTestState for rtas operations
libqos: Use explicit QTestState for virtio operations
ahci-test: Drop dependence on global_qtest
ivshmem-test: Drop dependence on global_qtest
postcopy-test: Drop dependence on global_qtest
vhost-user-test: Drop dependence on global_qtest
qmp-test: Drop dependence on global_qtest tests/boot-sector: Drop dependence on global_qtest tests/acpi-utils: Drop dependence on global_qtest
bios-tables-test: Drop dependence on global_qtest
wdt_ib700-test: Drop dependence on global_qtest
fw_cfg-test: Drop dependence on global_qtest
libqtest: Make qtest_init() accept format string
libqtest: Remove qtest_start() and qtest_end() shortcuts
libqtest: Rename qtest_init() to qtest_start()

Markus Armbruster (1):
tests: Clean up wait for event

 tests/libqtest.h               |  37 +-----
 tests/acpi-utils.h             |  65 ++++-----
 tests/boot-sector.h            |   6 +-
 tests/libqos/ahci.h            |   2 +-
 tests/libqos/fw_cfg.h          |  10 +-
 tests/libqos/libqos.h          |   5 +-
 tests/libqos/malloc-pc.h       |   4 +-
 tests/libqos/malloc-spapr.h    |   2 +-
 tests/libqos/malloc.h          |   1 +
 tests/libqos/pci-pc.h          |   2 +-
 tests/libqos/pci-spapr.h       |   2 +-
 tests/libqos/pci.h             |   1 +
 tests/libqos/rtas.h            |   9 +-
 tests/libqos/virtio-mmio.h     |   3 +-
 tests/libqos/virtio.h          |   5 +-
 tests/libqtest.c               | 293 +++++++++++++++++++++--------------------
 qtest.c                        |  80 +++++++----
 tests/ac97-test.c              |   4 +-
 tests/acpi-utils.c             |  19 +--
 tests/ahci-test.c              |  85 ++++++------
 tests/bios-tables-test.c       | 198 ++++++++++++++--------------
 tests/boot-order-test.c        |  19 ++-
 tests/boot-sector.c            |   8 +-
 tests/boot-serial-test.c       |  12 +-
 tests/device-introspect-test.c |  24 ++--
 tests/display-vga-test.c       |  18 +--
 tests/drive_del-test.c         |  17 +--
 tests/ds1338-test.c            |   2 +-
 tests/e1000-test.c             |  10 +-
 tests/e1000e-test.c            |  24 ++--
 tests/eepro100-test.c          |  11 +-
 tests/endianness-test.c        |  33 ++---
 tests/es1370-test.c            |   4 +-
 tests/fdc-test.c               |   4 +-
 tests/fw_cfg-test.c            |  13 +-
 tests/hd-geo-test.c            |  16 +--
 tests/i440fx-test.c            |  16 +--
 tests/i82801b11-test.c         |   5 +-
 tests/ide-test.c               |   8 +-
 tests/intel-hda-test.c         |  11 +-
 tests/ioh3420-test.c           |   7 +-
 tests/ipmi-bt-test.c           |  11 +-
 tests/ipmi-kcs-test.c          |   7 +-
 tests/ipoctal232-test.c        |   5 +-
 tests/ivshmem-test.c           |  22 +---
 tests/libqos/ahci.c            |  49 +++----
 tests/libqos/fw_cfg.c          |  14 +-
 tests/libqos/libqos-pc.c       |   2 +-
 tests/libqos/libqos.c          |  45 ++-----
 tests/libqos/malloc-pc.c       |   8 +-
 tests/libqos/malloc-spapr.c    |   4 +-
 tests/libqos/pci-pc.c          |  58 ++++----
 tests/libqos/pci-spapr.c       |  44 ++++---
 tests/libqos/rtas.c            |  21 +--
 tests/libqos/virtio-mmio.c     |  54 ++++----
 tests/libqos/virtio-pci.c      |   3 +
 tests/libqos/virtio.c          |  77 ++++++-----
 tests/m25p80-test.c            |   9 +-
 tests/m48t59-test.c            |   2 +-
 tests/ne2000-test.c            |   4 +-
 tests/numa-test.c              |  49 +++----
 tests/nvme-test.c              |   7 +-
 tests/pc-cpu-test.c            |  26 ++--
 tests/pcnet-test.c             |   4 +-
 tests/pnv-xscom-test.c         |  14 +-
 tests/postcopy-test.c          |  86 ++++++------
 tests/prom-env-test.c          |  13 +-
 tests/pvpanic-test.c           |   4 +-
 tests/pxe-test.c               |  16 +--
 tests/q35-test.c               |  12 +-
 tests/qmp-test.c               |  35 ++---
 tests/qom-test.c               |   7 +-
 tests/rtas-test.c              |   2 +-
 tests/rtc-test.c               |   2 +-
 tests/rtl8139-test.c           |   7 +-
 tests/spapr-phb-test.c         |   5 +-
 tests/tco-test.c               |  17 +--
 tests/test-arm-mptimer.c       |   4 +-
 tests/test-filter-mirror.c     |  16 +--
 tests/test-filter-redirector.c |  60 ++++-----
 tests/test-hmp.c               |   7 +-
 tests/test-netfilter.c         |   9 +-
 tests/test-qga.c               |  90 -------------
 tests/test-x86-cpuid-compat.c  |  13 +-
 tests/tmp105-test.c            |   7 +-
 tests/tpci200-test.c           |   4 +-
 tests/usb-hcd-ehci-test.c      |  27 ++--
 tests/usb-hcd-ohci-test.c      |   4 +-
 tests/usb-hcd-uhci-test.c      |   6 +-
 tests/usb-hcd-xhci-test.c      |  19 +--
 tests/vhost-user-test.c        | 105 ++++++---------
 tests/virtio-balloon-test.c    |   4 +-
 tests/virtio-blk-test.c        |  16 +--
 tests/virtio-console-test.c    |  12 +-
 tests/virtio-net-test.c        |   4 +-
 tests/virtio-rng-test.c        |   4 +-
 tests/virtio-serial-test.c     |   4 +-
 tests/vmgenid-test.c           |  49 +++----
 tests/vmxnet3-test.c           |   4 +-
 tests/wdt_ib700-test.c         |  84 ++++++------
 tests/.gitignore               |  30 +++--
 101 files changed, 1092 insertions(+), 1330 deletions(-)
Signature · 1 line
2.13.5
author
#1 lore raw

PATCH v6 1/29 tests: Improve .gitignore for tests/multiboot

Right now, tests/multiboot is not run by default during 'make check'; but when it is run in-tree, it was leaving some junk behind that could accidentally get checked in with a careless 'git add tests'.

---
 tests/.gitignore | 2 ++
 1 file changed, 2 insertions(+)
tests/.gitignore +2 -0
index fed0189a5a..64ecd6683b 100644
@@ -10,6 +10,8 @@ check-qnull
 check-qstring
 check-qom-interface
 check-qom-proplist
+multiboot/test.out
+multiboot/*.elf
 qht-bench
 rcutorture
 test-aio
Signature · 1 line
2.13.5
#2 lore raw

Re: [Qemu-devel] [PATCH v6 01/29] tests: Improve .gitignore for tests/multiboot

Quoted 14 lines · Eric Blake

Right now, tests/multiboot is not run by default during 'make check'; but when it is run in-tree, it was leaving some junk behind that could accidentally get checked in with a careless 'git add tests'.

---
 tests/.gitignore | 2 ++
 1 file changed, 2 insertions(+)
tests/.gitignore +0 -0
index fed0189a5a..64ecd6683b 100644

tests/.gitignore check-qnull · line 13

Quoted 4 lines
tests/.gitignore +1 -0
@@ -10,6 +10,8 @@ check-qnull
 check-qstring
 check-qom-interface
 check-qom-proplist
+multiboot/test.out

Your patch is of course a good idea ... but that test.out smells quite bad ... I guess it should (a) use mktemp for a better file name instead so that we can run this in parallel and (b) clean up the temporary file once the test has been done?

tests/.gitignore check-qnull · line 17

Quoted 5 lines
tests/.gitignore +1 -0
+multiboot/*.elf
 qht-bench
 rcutorture
 test-aio

Thomas

author
#3 lore raw

Re: [Qemu-devel] [PATCH v6 01/29] tests: Improve .gitignore for tests/multiboot

Quoted 10 lines · Thomas Huth
Quoted 9 lines · Eric Blake

Right now, tests/multiboot is not run by default during 'make check'; but when it is run in-tree, it was leaving some junk behind that could accidentally get checked in with a careless 'git add tests'.

---
 tests/.gitignore | 2 ++
 1 file changed, 2 insertions(+)
Quoted 14 lines

tests/.gitignore check-qnull · line 13

Quoted 9 lines
tests/.gitignore +1 -0
index fed0189a5a..64ecd6683b 100644
@@ -10,6 +10,8 @@ check-qnull
 check-qstring
 check-qom-interface
 check-qom-proplist
+multiboot/test.out

Your patch is of course a good idea ... but that test.out smells quite bad ... I guess it should (a) use mktemp for a better file name instead so that we can run this in parallel and (b) clean up the temporary file once the test has been done?

Indeed, making multiboot better, and run by default under 'make check', is a better task than just tweaking .gitignore, but one orthogonal enough to my libqtest changes that I will save this patch (and 2/29) for another series (or if someone else wants to tackle it first).

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
author
#4 lore raw

PATCH v6 2/29 tests: Sort .gitignore

In reply to Eric Blake

It doesn't matter if things are unsorted, but finding stuff in a list is easier when it is sorted. (Sorted under LC_ALL=C rules, rather than en_US.UTF-8).

---
 tests/.gitignore | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
tests/.gitignore +15 -15
index 64ecd6683b..8d35a58751 100644
@@ -1,25 +1,27 @@
+*-test
 atomic_add-bench
 benchmark-crypto-cipher
 benchmark-crypto-hash
 benchmark-crypto-hmac
 check-qdict
-check-qnum
 check-qjson
 check-qlist
 check-qnull
-check-qstring
+check-qnum
 check-qom-interface
 check-qom-proplist
-multiboot/test.out
+check-qstring
 multiboot/*.elf
+multiboot/test.out
+qapi-schema/*.test.*
 qht-bench
 rcutorture
 test-aio
 test-aio-multithread
 test-arm-mptimer
 test-base64
-test-bitops
 test-bitcnt
+test-bitops
 test-blockjob
 test-blockjob-txn
 test-bufferiszero
@@ -35,18 +37,19 @@ test-crypto-ivgen
 test-crypto-pbkdf
 test-crypto-secret
 test-crypto-tlscredsx509
-test-crypto-tlscredsx509-work/
 test-crypto-tlscredsx509-certs/
+test-crypto-tlscredsx509-work/
 test-crypto-tlssession
-test-crypto-tlssession-work/
 test-crypto-tlssession-client/
 test-crypto-tlssession-server/
+test-crypto-tlssession-work/
 test-crypto-xts
 test-cutils
+test-filter-mirror
+test-filter-redirector
 test-hbitmap
 test-hmp
 test-int128
-test-iov
 test-io-channel-buffer
 test-io-channel-command
 test-io-channel-command.fifo
@@ -55,27 +58,29 @@ test-io-channel-file.txt
 test-io-channel-socket
 test-io-channel-tls
 test-io-task
+test-iov
 test-keyval
 test-logging
 test-mul64
+test-netfilter
 test-opts-visitor
 test-qapi-event.[ch]
 test-qapi-types.[ch]
 test-qapi-util
 test-qapi-visit.[ch]
 test-qdev-global-props
-test-qemu-opts
 test-qdist
+test-qemu-opts
 test-qga
 test-qht
 test-qht-par
 test-qmp-commands
 test-qmp-commands.h
 test-qmp-event
-test-qobject-input-strict
-test-qobject-input-visitor
 test-qmp-introspect.[ch]
 test-qmp-marshal.c
+test-qobject-input-strict
+test-qobject-input-visitor
 test-qobject-output-visitor
 test-rcu-list
 test-replication
@@ -92,8 +97,3 @@ test-write-threshold
 test-x86-cpuid
 test-x86-cpuid-compat
 test-xbzrle
-test-netfilter
-test-filter-mirror
-test-filter-redirector
-*-test
-qapi-schema/*.test.*
Signature · 1 line
2.13.5
Reviewed-by on v6 2/29
#5 lore raw

Re: [Qemu-devel] [PATCH v6 02/29] tests: Sort .gitignore

Quoted 8 lines · Eric Blake

It doesn't matter if things are unsorted, but finding stuff in a list is easier when it is sorted. (Sorted under LC_ALL=C rules, rather than en_US.UTF-8).

---
 tests/.gitignore | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

BTW, did you note the patch "build-sys: generate tests/.gitignore" from Marc-André ? Maybe the list can be generated automatically, too...

tests/.gitignore line 1

Quoted 6 lines
tests/.gitignore +1 -0
index 64ecd6683b..8d35a58751 100644
@@ -1,25 +1,27 @@
+*-test

... but looking at this wildcard, I wonder if we just named most of our tests in a bad way. If we name the files something-test instead of test-something, we maybe do not need the automatic generation from Marc-André (which is kind of ugly because it writes to the source directory - and this should not happen when doing out of tree builds).

So what do you think about renaming our tests, so that the above wildcard applies instead?

Thomas

Quoted 96 lines
tests/.gitignore +14 -15
 atomic_add-bench
 benchmark-crypto-cipher
 benchmark-crypto-hash
 benchmark-crypto-hmac
 check-qdict
-check-qnum
 check-qjson
 check-qlist
 check-qnull
-check-qstring
+check-qnum
 check-qom-interface
 check-qom-proplist
-multiboot/test.out
+check-qstring
 multiboot/*.elf
+multiboot/test.out
+qapi-schema/*.test.*
 qht-bench
 rcutorture
 test-aio
 test-aio-multithread
 test-arm-mptimer
 test-base64
-test-bitops
 test-bitcnt
+test-bitops
 test-blockjob
 test-blockjob-txn
 test-bufferiszero
@@ -35,18 +37,19 @@ test-crypto-ivgen
 test-crypto-pbkdf
 test-crypto-secret
 test-crypto-tlscredsx509
-test-crypto-tlscredsx509-work/
 test-crypto-tlscredsx509-certs/
+test-crypto-tlscredsx509-work/
 test-crypto-tlssession
-test-crypto-tlssession-work/
 test-crypto-tlssession-client/
 test-crypto-tlssession-server/
+test-crypto-tlssession-work/
 test-crypto-xts
 test-cutils
+test-filter-mirror
+test-filter-redirector
 test-hbitmap
 test-hmp
 test-int128
-test-iov
 test-io-channel-buffer
 test-io-channel-command
 test-io-channel-command.fifo
@@ -55,27 +58,29 @@ test-io-channel-file.txt
 test-io-channel-socket
 test-io-channel-tls
 test-io-task
+test-iov
 test-keyval
 test-logging
 test-mul64
+test-netfilter
 test-opts-visitor
 test-qapi-event.[ch]
 test-qapi-types.[ch]
 test-qapi-util
 test-qapi-visit.[ch]
 test-qdev-global-props
-test-qemu-opts
 test-qdist
+test-qemu-opts
 test-qga
 test-qht
 test-qht-par
 test-qmp-commands
 test-qmp-commands.h
 test-qmp-event
-test-qobject-input-strict
-test-qobject-input-visitor
 test-qmp-introspect.[ch]
 test-qmp-marshal.c
+test-qobject-input-strict
+test-qobject-input-visitor
 test-qobject-output-visitor
 test-rcu-list
 test-replication
@@ -92,8 +97,3 @@ test-write-threshold
 test-x86-cpuid
 test-x86-cpuid-compat
 test-xbzrle
-test-netfilter
-test-filter-mirror
-test-filter-redirector
-*-test
-qapi-schema/*.test.*
#6 lore raw

Re: [Qemu-devel] [PATCH v6 02/29] tests: Sort .gitignore

Quoted 28 lines · Thomas Huth
Quoted 8 lines · Eric Blake

It doesn't matter if things are unsorted, but finding stuff in a list is easier when it is sorted. (Sorted under LC_ALL=C rules, rather than en_US.UTF-8).

---
 tests/.gitignore | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

BTW, did you note the patch "build-sys: generate tests/.gitignore" from Marc-André ? Maybe the list can be generated automatically, too...

tests/.gitignore line 1

Quoted 6 lines
tests/.gitignore +1 -0
index 64ecd6683b..8d35a58751 100644
@@ -1,25 +1,27 @@
+*-test

... but looking at this wildcard, I wonder if we just named most of our tests in a bad way. If we name the files something-test instead of test-something, we maybe do not need the automatic generation from Marc-André (which is kind of ugly because it writes to the source directory - and this should not happen when doing out of tree builds).

Quoted 2 lines

So what do you think about renaming our tests, so that the above wildcard applies instead?

Apropos naming tests: there's an (unspoken) convention to name unit tests check-FOO or test-FOO and tests using libqtest FOO-test, but it's not really honored anymore, probably because people creating tests didn't know about it.

#7 lore raw

Re: [Qemu-devel] [PATCH v6 02/29] tests: Sort .gitignore

Quoted 30 lines · Markus Armbruster
Quoted 28 lines · Thomas Huth
Quoted 8 lines · Eric Blake

It doesn't matter if things are unsorted, but finding stuff in a list is easier when it is sorted. (Sorted under LC_ALL=C rules, rather than en_US.UTF-8).

---
 tests/.gitignore | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

BTW, did you note the patch "build-sys: generate tests/.gitignore" from Marc-André ? Maybe the list can be generated automatically, too...

tests/.gitignore line 1

Quoted 6 lines
tests/.gitignore +1 -0
index 64ecd6683b..8d35a58751 100644
@@ -1,25 +1,27 @@
+*-test

... but looking at this wildcard, I wonder if we just named most of our tests in a bad way. If we name the files something-test instead of test-something, we maybe do not need the automatic generation from Marc-André (which is kind of ugly because it writes to the source directory - and this should not happen when doing out of tree builds).

Quoted 7 lines
Quoted 2 lines

So what do you think about renaming our tests, so that the above wildcard applies instead?

Apropos naming tests: there's an (unspoken) convention to name unit tests check-FOO or test-FOO and tests using libqtest FOO-test, but it's not really honored anymore, probably because people creating tests didn't know about it.

Maybe it would help to have an entry for libqtest in MAINTAINERS with a wildcard for tests/*-test.c ? Then we would have at least some kind of documentation for this... (BTW: Any volunteers here for such a maintainer job? ;-))

Thomas

#8 lore raw

Re: [Qemu-devel] [PATCH v6 02/29] tests: Sort .gitignore

In reply to Markus Armbruster
Quoted 30 lines · Markus Armbruster
Quoted 28 lines · Thomas Huth
Quoted 8 lines · Eric Blake

It doesn't matter if things are unsorted, but finding stuff in a list is easier when it is sorted. (Sorted under LC_ALL=C rules, rather than en_US.UTF-8).

---
 tests/.gitignore | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

BTW, did you note the patch "build-sys: generate tests/.gitignore" from Marc-André ? Maybe the list can be generated automatically, too...

tests/.gitignore line 1

Quoted 6 lines
tests/.gitignore +1 -0
index 64ecd6683b..8d35a58751 100644
@@ -1,25 +1,27 @@
+*-test

... but looking at this wildcard, I wonder if we just named most of our tests in a bad way. If we name the files something-test instead of test-something, we maybe do not need the automatic generation from Marc-André (which is kind of ugly because it writes to the source directory - and this should not happen when doing out of tree builds).

Quoted 7 lines
Quoted 2 lines

So what do you think about renaming our tests, so that the above wildcard applies instead?

Apropos naming tests: there's an (unspoken) convention to name unit tests check-FOO or test-FOO and tests using libqtest FOO-test, but it's not really honored anymore, probably because people creating tests didn't know about it.

$ ls *test.c | wc -l
67
$ ls test*.c | wc -l
73
$ ls check*.c | wc -l
8

Fairly even split between 'test' as a prefix vs suffix. 'check' as a prefix should clearly be killed as a minority pattern. Any appetite for standardizing naming of everything else ?

A further idea might be to actually have separate sub-directories for unit tests vs qtests. eg go for

tests

    +- unit
    +- qtest
    +- iotests

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#9 lore raw

Re: [Qemu-devel] [PATCH v6 02/29] tests: Sort .gitignore

Quoted 50 lines · Daniel P. Berrange
Quoted 30 lines · Markus Armbruster
Quoted 28 lines · Thomas Huth
Quoted 8 lines · Eric Blake

It doesn't matter if things are unsorted, but finding stuff in a list is easier when it is sorted. (Sorted under LC_ALL=C rules, rather than en_US.UTF-8).

---
 tests/.gitignore | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

BTW, did you note the patch "build-sys: generate tests/.gitignore" from Marc-André ? Maybe the list can be generated automatically, too...

tests/.gitignore line 1

Quoted 6 lines
tests/.gitignore +1 -0
index 64ecd6683b..8d35a58751 100644
@@ -1,25 +1,27 @@
+*-test

... but looking at this wildcard, I wonder if we just named most of our tests in a bad way. If we name the files something-test instead of test-something, we maybe do not need the automatic generation from Marc-André (which is kind of ugly because it writes to the source directory - and this should not happen when doing out of tree builds).

Quoted 7 lines
Quoted 2 lines

So what do you think about renaming our tests, so that the above wildcard applies instead?

Apropos naming tests: there's an (unspoken) convention to name unit tests check-FOO or test-FOO and tests using libqtest FOO-test, but it's not really honored anymore, probably because people creating tests didn't know about it.

$ ls *test.c | wc -l
67
$ ls test*.c | wc -l
73
$ ls check*.c | wc -l
8

Fairly even split between 'test' as a prefix vs suffix. 'check' as a prefix should clearly be killed as a minority pattern. Any appetite for standardizing naming of everything else ?

Quoted 7 lines

A further idea might be to actually have separate sub-directories for unit tests vs qtests. eg go for

tests

    +- unit
    +- qtest
    +- iotests

That sounds like a good idea to me, too.

Thomas

author
#10 lore raw

Re: [Qemu-devel] [PATCH v6 02/29] tests: Sort .gitignore

In reply to Daniel P. Berrange
Quoted 11 lines · Daniel P. Berrange

Fairly even split between 'test' as a prefix vs suffix. 'check' as a prefix should clearly be killed as a minority pattern. Any appetite for standardizing naming of everything else ?

A further idea might be to actually have separate sub-directories for unit tests vs qtests. eg go for

tests

    +- unit
    +- qtest
    +- iotests

I like the idea, but don't know if I want to be the one tackling it...

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
author
#11 lore raw

PATCH v6 3/29 test-qga: Kill broken and dead QGA_TEST_SIDE_EFFECTING code

In reply to Eric Blake

Back when the test was introduced, in commit 62c39b307, the test was set up to run qemu-ga directly on the host performing the test, and defaults to limiting itself to safe commands. At the time, it was envisioned that setting QGA_TEST_SIDE_EFFECTING in the environment could cover a few more commands, while noting the potential danger of those side effects running in the host.

But this has NEVER been tested: if you enable the environment variable, the test WILL fail. One obvious reason: if you are not running as root, you'll probably get a permission failure when trying to freeze the file systems, or when changing system time. Less obvious: if you run the test as root (wow, you're brave), you could end up hanging if the test tries to log things to a temporarily frozen filesystem. But the cutest reason of all: if you get past the above hurdles, the test uses invalid JSON in test_qga_fstrim() (missing '' around the dictionary key 'minimum'), and will thus fail an assertion in qmp_fd().

Rather than leave this untested time-bomb in place, rip it out. Hopefully, as originally envisioned, we can find an opportunity to test an actual sandboxed guest where the guest-agent has full permissions and will not unduly affect the host running the test - if so, 'git revert' can be used if desired, for salvaging any useful parts of this attempt.

---
 tests/test-qga.c | 90 --------------------------------------------------------
 1 file changed, 90 deletions(-)
tests/test-qga.c +0 -90
index 06783e7585..fd6bc7690f 100644
@@ -642,65 +642,6 @@ static void test_qga_get_time(gconstpointer fix)
     QDECREF(ret);
 }
 
-static void test_qga_set_time(gconstpointer fix)
-{
-    const TestFixture *fixture = fix;
-    QDict *ret;
-    int64_t current, time;
-    gchar *cmd;
-
-    /* get current time */
-    ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-time'}");
-    g_assert_nonnull(ret);
-    qmp_assert_no_error(ret);
-    current = qdict_get_int(ret, "return");
-    g_assert_cmpint(current, >, 0);
-    QDECREF(ret);
-
-    /* set some old time */
-    ret = qmp_fd(fixture->fd, "{'execute': 'guest-set-time',"
-                 " 'arguments': { 'time': 1000 } }");
-    g_assert_nonnull(ret);
-    qmp_assert_no_error(ret);
-    QDECREF(ret);
-
-    /* check old time */
-    ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-time'}");
-    g_assert_nonnull(ret);
-    qmp_assert_no_error(ret);
-    time = qdict_get_int(ret, "return");
-    g_assert_cmpint(time / 1000, <, G_USEC_PER_SEC * 10);
-    QDECREF(ret);
-
-    /* set back current time */
-    cmd = g_strdup_printf("{'execute': 'guest-set-time',"
-                          " 'arguments': { 'time': %" PRId64 " } }",
-                          current + time * 1000);
-    ret = qmp_fd(fixture->fd, cmd);
-    g_free(cmd);
-    g_assert_nonnull(ret);
-    qmp_assert_no_error(ret);
-    QDECREF(ret);
-}
-
-static void test_qga_fstrim(gconstpointer fix)
-{
-    const TestFixture *fixture = fix;
-    QDict *ret;
-    QList *list;
-    const QListEntry *entry;
-
-    ret = qmp_fd(fixture->fd, "{'execute': 'guest-fstrim',"
-                 " arguments: { minimum: 4194304 } }");
-    g_assert_nonnull(ret);
-    qmp_assert_no_error(ret);
-    list = qdict_get_qlist(ret, "return");
-    entry = qlist_first(list);
-    g_assert(qdict_haskey(qobject_to_qdict(entry->value), "paths"));
-
-    QDECREF(ret);
-}
-
 static void test_qga_blacklist(gconstpointer data)
 {
     TestFixture fix;
@@ -831,30 +772,6 @@ static void test_qga_fsfreeze_status(gconstpointer fix)
     QDECREF(ret);
 }
 
-static void test_qga_fsfreeze_and_thaw(gconstpointer fix)
-{
-    const TestFixture *fixture = fix;
-    QDict *ret;
-    const gchar *status;
-
-    ret = qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-freeze'}");
-    g_assert_nonnull(ret);
-    qmp_assert_no_error(ret);
-    QDECREF(ret);
-
-    ret = qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-status'}");
-    g_assert_nonnull(ret);
-    qmp_assert_no_error(ret);
-    status = qdict_get_try_str(ret, "return");
-    g_assert_cmpstr(status, ==, "frozen");
-    QDECREF(ret);
-
-    ret = qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-thaw'}");
-    g_assert_nonnull(ret);
-    qmp_assert_no_error(ret);
-    QDECREF(ret);
-}
-
 static void test_qga_guest_exec(gconstpointer fix)
 {
     const TestFixture *fixture = fix;
@@ -1029,13 +946,6 @@ int main(int argc, char **argv)
     g_test_add_data_func("/qga/guest-get-osinfo", &fix,
                          test_qga_guest_get_osinfo);
 
-    if (g_getenv("QGA_TEST_SIDE_EFFECTING")) {
-        g_test_add_data_func("/qga/fsfreeze-and-thaw", &fix,
-                             test_qga_fsfreeze_and_thaw);
-        g_test_add_data_func("/qga/set-time", &fix, test_qga_set_time);
-        g_test_add_data_func("/qga/fstrim", &fix, test_qga_fstrim);
-    }
-
     ret = g_test_run();
 
     fixture_tear_down(&fix, NULL);
Signature · 1 line
2.13.5
Reviewed-by on v6 3/29
#12 lore raw

Re: [Qemu-devel] [PATCH v6 03/29] test-qga: Kill broken and dead QGA_TEST_SIDE_EFFECTING code

Quoted 25 lines · Eric Blake

Back when the test was introduced, in commit 62c39b307, the test was set up to run qemu-ga directly on the host performing the test, and defaults to limiting itself to safe commands. At the time, it was envisioned that setting QGA_TEST_SIDE_EFFECTING in the environment could cover a few more commands, while noting the potential danger of those side effects running in the host.

But this has NEVER been tested: if you enable the environment variable, the test WILL fail. One obvious reason: if you are not running as root, you'll probably get a permission failure when trying to freeze the file systems, or when changing system time. Less obvious: if you run the test as root (wow, you're brave), you could end up hanging if the test tries to log things to a temporarily frozen filesystem. But the cutest reason of all: if you get past the above hurdles, the test uses invalid JSON in test_qga_fstrim() (missing '' around the dictionary key 'minimum'), and will thus fail an assertion in qmp_fd().

Rather than leave this untested time-bomb in place, rip it out. Hopefully, as originally envisioned, we can find an opportunity to test an actual sandboxed guest where the guest-agent has full permissions and will not unduly affect the host running the test - if so, 'git revert' can be used if desired, for salvaging any useful parts of this attempt.

Quoted 5 lines
---
 tests/test-qga.c | 90 --------------------------------------------------------
 1 file changed, 90 deletions(-)
author
#13 lore raw

PATCH v6 4/29 qtest: Don't perform side effects inside assertion

In reply to Eric Blake

Assertions should be separate from the side effects, since in theory, g_assert() can be disabled (in practice, we can't really ever do that).

---
 qtest.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 57 insertions(+), 23 deletions(-)
qtest.c +57 -23
index 88a09e9afc..cbbfb71114 100644
@@ -332,10 +332,13 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
                strcmp(words[0], "outl") == 0) {
         unsigned long addr;
         unsigned long value;
+        int ret;
 
         g_assert(words[1] && words[2]);
-        g_assert(qemu_strtoul(words[1], NULL, 0, &addr) == 0);
-        g_assert(qemu_strtoul(words[2], NULL, 0, &value) == 0);
+        ret = qemu_strtoul(words[1], NULL, 0, &addr);
+        g_assert(ret == 0);
+        ret = qemu_strtoul(words[2], NULL, 0, &value);
+        g_assert(ret == 0);
         g_assert(addr <= 0xffff);
 
         if (words[0][3] == 'b') {
@@ -352,9 +355,11 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
         strcmp(words[0], "inl") == 0) {
         unsigned long addr;
         uint32_t value = -1U;
+        int ret;
 
         g_assert(words[1]);
-        g_assert(qemu_strtoul(words[1], NULL, 0, &addr) == 0);
+        ret = qemu_strtoul(words[1], NULL, 0, &addr);
+        g_assert(ret == 0);
         g_assert(addr <= 0xffff);
 
         if (words[0][2] == 'b') {
@@ -372,10 +377,13 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
                strcmp(words[0], "writeq") == 0) {
         uint64_t addr;
         uint64_t value;
+        int ret;
 
         g_assert(words[1] && words[2]);
-        g_assert(qemu_strtou64(words[1], NULL, 0, &addr) == 0);
-        g_assert(qemu_strtou64(words[2], NULL, 0, &value) == 0);
+        ret = qemu_strtou64(words[1], NULL, 0, &addr);
+        g_assert(ret == 0);
+        ret = qemu_strtou64(words[2], NULL, 0, &value);
+        g_assert(ret == 0);
 
         if (words[0][5] == 'b') {
             uint8_t data = value;
@@ -401,9 +409,11 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
                strcmp(words[0], "readq") == 0) {
         uint64_t addr;
         uint64_t value = UINT64_C(-1);
+        int ret;
 
         g_assert(words[1]);
-        g_assert(qemu_strtou64(words[1], NULL, 0, &addr) == 0);
+        ret = qemu_strtou64(words[1], NULL, 0, &addr);
+        g_assert(ret == 0);
 
         if (words[0][4] == 'b') {
             uint8_t data;
@@ -427,10 +437,13 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
         uint64_t addr, len, i;
         uint8_t *data;
         char *enc;
+        int ret;
 
         g_assert(words[1] && words[2]);
-        g_assert(qemu_strtou64(words[1], NULL, 0, &addr) == 0);
-        g_assert(qemu_strtou64(words[2], NULL, 0, &len) == 0);
+        ret = qemu_strtou64(words[1], NULL, 0, &addr);
+        g_assert(ret == 0);
+        ret = qemu_strtou64(words[2], NULL, 0, &len);
+        g_assert(ret == 0);
         /* We'd send garbage to libqtest if len is 0 */
         g_assert(len);
 
@@ -451,10 +464,13 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
         uint64_t addr, len;
         uint8_t *data;
         gchar *b64_data;
+        int ret;
 
         g_assert(words[1] && words[2]);
-        g_assert(qemu_strtou64(words[1], NULL, 0, &addr) == 0);
-        g_assert(qemu_strtou64(words[2], NULL, 0, &len) == 0);
+        ret = qemu_strtou64(words[1], NULL, 0, &addr);
+        g_assert(ret == 0);
+        ret = qemu_strtou64(words[2], NULL, 0, &len);
+        g_assert(ret == 0);
 
         data = g_malloc(len);
         cpu_physical_memory_read(addr, data, len);
@@ -468,10 +484,13 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
         uint64_t addr, len, i;
         uint8_t *data;
         size_t data_len;
+        int ret;
 
         g_assert(words[1] && words[2] && words[3]);
-        g_assert(qemu_strtou64(words[1], NULL, 0, &addr) == 0);
-        g_assert(qemu_strtou64(words[2], NULL, 0, &len) == 0);
+        ret = qemu_strtou64(words[1], NULL, 0, &addr);
+        g_assert(ret == 0);
+        ret = qemu_strtou64(words[2], NULL, 0, &len);
+        g_assert(ret == 0);
 
         data_len = strlen(words[3]);
         if (data_len < 3) {
@@ -497,11 +516,15 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
         uint64_t addr, len;
         uint8_t *data;
         unsigned long pattern;
+        int ret;
 
         g_assert(words[1] && words[2] && words[3]);
-        g_assert(qemu_strtou64(words[1], NULL, 0, &addr) == 0);
-        g_assert(qemu_strtou64(words[2], NULL, 0, &len) == 0);
-        g_assert(qemu_strtoul(words[3], NULL, 0, &pattern) == 0);
+        ret = qemu_strtou64(words[1], NULL, 0, &addr);
+        g_assert(ret == 0);
+        ret = qemu_strtou64(words[2], NULL, 0, &len);
+        g_assert(ret == 0);
+        ret = qemu_strtoul(words[3], NULL, 0, &pattern);
+        g_assert(ret == 0);
 
         if (len) {
             data = g_malloc(len);
@@ -517,10 +540,13 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
         uint8_t *data;
         size_t data_len;
         gsize out_len;
+        int ret;
 
         g_assert(words[1] && words[2] && words[3]);
-        g_assert(qemu_strtou64(words[1], NULL, 0, &addr) == 0);
-        g_assert(qemu_strtou64(words[2], NULL, 0, &len) == 0);
+        ret = qemu_strtou64(words[1], NULL, 0, &addr);
+        g_assert(ret == 0);
+        ret = qemu_strtou64(words[2], NULL, 0, &len);
+        g_assert(ret == 0);
 
         data_len = strlen(words[3]);
         if (data_len < 3) {
@@ -551,11 +577,16 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
     } else if (strcmp(words[0], "rtas") == 0) {
         uint64_t res, args, ret;
         unsigned long nargs, nret;
+        int rc;
 
-        g_assert(qemu_strtoul(words[2], NULL, 0, &nargs) == 0);
-        g_assert(qemu_strtou64(words[3], NULL, 0, &args) == 0);
-        g_assert(qemu_strtoul(words[4], NULL, 0, &nret) == 0);
-        g_assert(qemu_strtou64(words[5], NULL, 0, &ret) == 0);
+        rc = qemu_strtoul(words[2], NULL, 0, &nargs);
+        g_assert(rc == 0);
+        rc = qemu_strtou64(words[3], NULL, 0, &args);
+        g_assert(rc == 0);
+        rc = qemu_strtoul(words[4], NULL, 0, &nret);
+        g_assert(rc == 0);
+        rc = qemu_strtou64(words[5], NULL, 0, &ret);
+        g_assert(rc == 0);
         res = qtest_rtas_call(words[1], nargs, args, nret, ret);
 
         qtest_send_prefix(chr);
@@ -565,7 +596,8 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
         int64_t ns;
 
         if (words[1]) {
-            g_assert(qemu_strtoi64(words[1], NULL, 0, &ns) == 0);
+            int ret = qemu_strtoi64(words[1], NULL, 0, &ns);
+            g_assert(ret == 0);
         } else {
             ns = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
         }
@@ -575,9 +607,11 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
                     (int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
     } else if (qtest_enabled() && strcmp(words[0], "clock_set") == 0) {
         int64_t ns;
+        int ret;
 
         g_assert(words[1]);
-        g_assert(qemu_strtoi64(words[1], NULL, 0, &ns) == 0);
+        ret = qemu_strtoi64(words[1], NULL, 0, &ns);
+        g_assert(ret == 0);
         qtest_clock_warp(ns);
         qtest_send_prefix(chr);
         qtest_sendf(chr, "OK %"PRIi64"\n",
Signature · 1 line
2.13.5
Reviewed-by on v6 4/29
#14 lore raw

Re: [Qemu-devel] [PATCH v6 04/29] qtest: Don't perform side effects inside assertion

Quoted 8 lines · Eric Blake

Assertions should be separate from the side effects, since in theory, g_assert() can be disabled (in practice, we can't really ever do that).

---
 qtest.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 57 insertions(+), 23 deletions(-)

Right, we should get rid of this bad coding style in the QEMU sources.

author
#15 lore raw

PATCH v6 5/29 numa-test: Use hmp()

In reply to Eric Blake

Don't open-code something that has a convenient helper available.

---
 tests/numa-test.c | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)
tests/numa-test.c +3 -18
index 3f636840b1..e1b6152244 100644
@@ -17,21 +17,6 @@ static char *make_cli(const char *generic_cli, const char *test_cli)
     return g_strdup_printf("%s %s", generic_cli ? generic_cli : "", test_cli);
 }
 
-static char *hmp_info_numa(void)
-{
-    QDict *resp;
-    char *s;
-
-    resp = qmp("{ 'execute': 'human-monitor-command', 'arguments': "
-                      "{ 'command-line': 'info numa '} }");
-    g_assert(resp);
-    g_assert(qdict_haskey(resp, "return"));
-    s = g_strdup(qdict_get_str(resp, "return"));
-    g_assert(s);
-    QDECREF(resp);
-    return s;
-}
-
 static void test_mon_explicit(const void *data)
 {
     char *s;
@@ -42,7 +27,7 @@ static void test_mon_explicit(const void *data)
                    "-numa node,nodeid=1,cpus=4-7 ");
     qtest_start(cli);
 
-    s = hmp_info_numa();
+    s = hmp("info numa");
     g_assert(strstr(s, "node 0 cpus: 0 1 2 3"));
     g_assert(strstr(s, "node 1 cpus: 4 5 6 7"));
     g_free(s);
@@ -59,7 +44,7 @@ static void test_mon_default(const void *data)
     cli = make_cli(data, "-smp 8 -numa node -numa node");
     qtest_start(cli);
 
-    s = hmp_info_numa();
+    s = hmp("info numa");
     g_assert(strstr(s, "node 0 cpus: 0 2 4 6"));
     g_assert(strstr(s, "node 1 cpus: 1 3 5 7"));
     g_free(s);
@@ -78,7 +63,7 @@ static void test_mon_partial(const void *data)
                    "-numa node,nodeid=1,cpus=4-5 ");
     qtest_start(cli);
 
-    s = hmp_info_numa();
+    s = hmp("info numa");
     g_assert(strstr(s, "node 0 cpus: 0 1 2 3 6 7"));
     g_assert(strstr(s, "node 1 cpus: 4 5"));
     g_free(s);
Signature · 1 line
2.13.5
Reviewed-by on v6 5/29
#16 lore raw

Re: [Qemu-devel] [PATCH v6 05/29] numa-test: Use hmp()

Quoted 8 lines · Eric Blake

Don't open-code something that has a convenient helper available.

---
 tests/numa-test.c | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)
author
#17 lore raw

PATCH v6 6/29 tests: Clean up wait for event

In reply to Eric Blake

From: Markus Armbruster <[email protected]>

We still use hacks like qmp("") to wait for an event, even though we have qmp_eventwait() since commit 8fe941f, and qmp_eventwait_ref() since commit 7ffe312. Both commits neglected to convert all the existing hacks. Make up what they missed.

Bonus: gets rid of empty format strings. A step towards compile-time format string checking without triggering -Wformat-zero-length.

Message-Id: <[email protected]>

---
v4: hoist earlier in series

---
 tests/boot-order-test.c   |  2 +-
 tests/libqos/pci-pc.c     |  6 +-----
 tests/tco-test.c          |  3 +--
 tests/usb-hcd-uhci-test.c |  6 +-----
 tests/usb-hcd-xhci-test.c | 12 ++----------
 tests/wdt_ib700-test.c    | 35 ++++++++++-------------------------
 6 files changed, 16 insertions(+), 48 deletions(-)
tests/boot-order-test.c +1 -1
index fc1e7941f7..9d516830dd 100644
@@ -43,7 +43,7 @@ static void test_a_boot_order(const char *machine,
      * system_reset only requests reset.  We get a RESET event after
      * the actual reset completes.  Need to wait for that.
      */
-    qmp_discard_response("");   /* HACK: wait for event */
+    qmp_eventwait("RESET");
     actual = read_boot_order();
     g_assert_cmphex(actual, ==, expected_reboot);
     qtest_quit(global_qtest);
tests/libqos/pci-pc.c +1 -5
index ded1c54c06..02ce49927a 100644
@@ -173,9 +173,5 @@ void qpci_unplug_acpi_device_test(const char *id, uint8_t slot)
 
     outb(ACPI_PCIHP_ADDR + PCI_EJ_BASE, 1 << slot);
 
-    response = qmp("");
-    g_assert(response);
-    g_assert(qdict_haskey(response, "event"));
-    g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED"));
-    QDECREF(response);
+    qmp_eventwait("DEVICE_DELETED");
 }
tests/tco-test.c +1 -2
index c4c264eb3d..f2ed6ed91c 100644
@@ -237,9 +237,8 @@ static void test_tco_max_timeout(void)
 
 static QDict *get_watchdog_action(void)
 {
-    QDict *ev = qmp("");
+    QDict *ev = qmp_eventwait_ref("WATCHDOG");
     QDict *data;
-    g_assert(!strcmp(qdict_get_str(ev, "event"), "WATCHDOG"));
 
     data = qdict_get_qdict(ev, "data");
     QINCREF(data);
tests/usb-hcd-uhci-test.c +1 -5
index 5b500fedb0..0fb7f8d223 100644
@@ -68,11 +68,7 @@ static void test_usb_storage_hotplug(void)
     g_assert(!qdict_haskey(response, "error"));
     QDECREF(response);
 
-    response = qmp("");
-    g_assert(response);
-    g_assert(qdict_haskey(response, "event"));
-    g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED"));
-    QDECREF(response);
+    qmp_eventwait("DEVICE_DELETED");
 }
 
 int main(int argc, char **argv)
tests/usb-hcd-xhci-test.c +2 -10
index 031764da6d..c05a339894 100644
@@ -57,11 +57,7 @@ static void test_usb_uas_hotplug(void)
     g_assert(!qdict_haskey(response, "error"));
     QDECREF(response);
 
-    response = qmp("");
-    g_assert(qdict_haskey(response, "event"));
-    g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED"));
-    QDECREF(response);
-
+    qmp_eventwait("DEVICE_DELETED");
 
     response = qmp("{'execute': 'device_del',"
                            " 'arguments': {"
@@ -71,11 +67,7 @@ static void test_usb_uas_hotplug(void)
     g_assert(!qdict_haskey(response, "error"));
     QDECREF(response);
 
-    response = qmp("");
-    g_assert(response);
-    g_assert(qdict_haskey(response, "event"));
-    g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED"));
-    QDECREF(response);
+    qmp_eventwait("DEVICE_DELETED");
 }
 
 int main(int argc, char **argv)
tests/wdt_ib700-test.c +10 -25
index 49f4f0c221..4fc8eeae86 100644
@@ -18,26 +18,10 @@ static void qmp_check_no_event(void)
     QDECREF(resp);
 }
 
-static QDict *qmp_get_event(const char *name)
-{
-    QDict *event = qmp("");
-    QDict *data;
-    g_assert(qdict_haskey(event, "event"));
-    g_assert(!strcmp(qdict_get_str(event, "event"), name));
-
-    if (qdict_haskey(event, "data")) {
-        data = qdict_get_qdict(event, "data");
-        QINCREF(data);
-    } else {
-        data = NULL;
-    }
-
-    QDECREF(event);
-    return data;
-}
-
 static QDict *ib700_program_and_wait(QTestState *s)
 {
+    QDict *event, *data;
+
     clock_step(NANOSECONDS_PER_SECOND * 40);
     qmp_check_no_event();
 
@@ -61,7 +45,11 @@ static QDict *ib700_program_and_wait(QTestState *s)
     clock_step(3 * NANOSECONDS_PER_SECOND);
     qmp_check_no_event();
     clock_step(2 * NANOSECONDS_PER_SECOND);
-    return qmp_get_event("WATCHDOG");
+    event = qmp_eventwait_ref("WATCHDOG");
+    data = qdict_get_qdict(event, "data");
+    QINCREF(data);
+    QDECREF(event);
+    return data;
 }
 
 
@@ -73,8 +61,7 @@ static void ib700_pause(void)
     d = ib700_program_and_wait(s);
     g_assert(!strcmp(qdict_get_str(d, "action"), "pause"));
     QDECREF(d);
-    d = qmp_get_event("STOP");
-    QDECREF(d);
+    qmp_eventwait("STOP");
     qtest_end();
 }
 
@@ -86,8 +73,7 @@ static void ib700_reset(void)
     d = ib700_program_and_wait(s);
     g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
     QDECREF(d);
-    d = qmp_get_event("RESET");
-    QDECREF(d);
+    qmp_eventwait("RESET");
     qtest_end();
 }
 
@@ -99,8 +85,7 @@ static void ib700_shutdown(void)
     d = ib700_program_and_wait(s);
     g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
     QDECREF(d);
-    d = qmp_get_event("SHUTDOWN");
-    QDECREF(d);
+    qmp_eventwait("SHUTDOWN");
     qtest_end();
 }
 
Signature · 1 line
2.13.5
author
#18 lore raw

PATCH v6 7/29 libqtest: Remove dead qtest_instances variable

In reply to Eric Blake

Prior to commit 063c23d9, we were tracking a list of parallel qtest objects, in order to safely clean up a SIGABRT handler only after the last connection quits. But when we switched to more of glib's infrastructure, the list became dead code that is never assigned to.

---
 tests/libqtest.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
tests/libqtest.c +1 -5
index b9a1f180e1..3f956f09fc 100644
@@ -42,7 +42,6 @@ struct QTestState
 };
 
 static GHookList abrt_hooks;
-static GList *qtest_instances;
 static struct sigaction sigact_old;
 
 #define g_assert_no_errno(ret) do { \
@@ -240,13 +239,10 @@ QTestState *qtest_init(const char *extra_args)
 
 void qtest_quit(QTestState *s)
 {
-    qtest_instances = g_list_remove(qtest_instances, s);
     g_hook_destroy_link(&abrt_hooks, g_hook_find_data(&abrt_hooks, TRUE, s));
 
     /* Uninstall SIGABRT handler on last instance */
-    if (!qtest_instances) {
-        cleanup_sigabrt_handler();
-    }
+    cleanup_sigabrt_handler();
 
     kill_qemu(s);
     close(s->fd);
Signature · 1 line
2.13.5
Reviewed-by on v6 7/29
#19 lore raw

Re: [Qemu-devel] [PATCH v6 07/29] libqtest: Remove dead qtest_instances variable

Quoted 11 lines · Eric Blake

Prior to commit 063c23d9, we were tracking a list of parallel qtest objects, in order to safely clean up a SIGABRT handler only after the last connection quits. But when we switched to more of glib's infrastructure, the list became dead code that is never assigned to.

---
 tests/libqtest.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
author
#20 lore raw

PATCH v6 8/29 libqtest: Let socket_send() compute length

In reply to Eric Blake

Rather than make multiple callers call strlen(), it's easier if socket_send() itself can compute a length via strlen() if none was provided (caller passes -1). Callers that can get at the length more efficiently are left that way.

---
 tests/libqtest.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
tests/libqtest.c +6 -4
index 3f956f09fc..a6ce21d7f9 100644
@@ -251,10 +251,13 @@ void qtest_quit(QTestState *s)
     g_free(s);
 }
 
-static void socket_send(int fd, const char *buf, size_t size)
+static void socket_send(int fd, const char *buf, ssize_t size)
 {
     size_t offset;
 
+    if (size < 0) {
+        size = strlen(buf);
+    }
     offset = 0;
     while (offset < size) {
         ssize_t len;
@@ -274,9 +277,8 @@ static void socket_send(int fd, const char *buf, size_t size)
 static void socket_sendf(int fd, const char *fmt, va_list ap)
 {
     gchar *str = g_strdup_vprintf(fmt, ap);
-    size_t size = strlen(str);
 
-    socket_send(fd, str, size);
+    socket_send(fd, str, -1);
     g_free(str);
 }
 
@@ -858,7 +860,7 @@ void qtest_bufwrite(QTestState *s, uint64_t addr, const void *data, size_t size)
 
     bdata = g_base64_encode(data, size);
     qtest_sendf(s, "b64write 0x%" PRIx64 " 0x%zx ", addr, size);
-    socket_send(s->fd, bdata, strlen(bdata));
+    socket_send(s->fd, bdata, -1);
     socket_send(s->fd, "\n", 1);
     qtest_rsp(s, 0);
     g_free(bdata);
Signature · 1 line
2.13.5
#21 lore raw

Re: [Qemu-devel] [PATCH v6 08/29] libqtest: Let socket_send() compute length

Quoted 9 lines · Eric Blake

Rather than make multiple callers call strlen(), it's easier if socket_send() itself can compute a length via strlen() if none was provided (caller passes -1). Callers that can get at the length more efficiently are left that way.

---
 tests/libqtest.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

I have to say that I don't like this idea very much. socket_send() should IMHO not know about the type of the data that should be sent, i.e. it should not assume that the content is a zero-terminated string. This also could lead to some hard to detect bugs later in case somebody is calling the function like this:

  size = someotherfunction();
  socket_send(fd, buf, size);

... and the someotherfunction() returned a negative error code instead of a correct size.

So I'd like to suggest to simply drop this patch.

Thomas

#22 lore raw

Re: [Qemu-devel] [PATCH v6 08/29] libqtest: Let socket_send() compute length

Quoted 6 lines · Thomas Huth
Quoted 5 lines · Eric Blake

Rather than make multiple callers call strlen(), it's easier if socket_send() itself can compute a length via strlen() if none was provided (caller passes -1). Callers that can get at the length more efficiently are left that way.

Quoted 8 lines
Quoted 4 lines
---
 tests/libqtest.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

I have to say that I don't like this idea very much. socket_send() should IMHO not know about the type of the data that should be sent, i.e. it should not assume that the content is a zero-terminated string.

I agree.

Quoted 10 lines

This also could lead to some hard to detect bugs later in case somebody is calling the function like this:

  size = someotherfunction();
  socket_send(fd, buf, size);

... and the someotherfunction() returned a negative error code instead of a correct size.

So I'd like to suggest to simply drop this patch.

A separate wrapper function for sending zero-terminated strings would be fine with me.

author
#23 lore raw

Re: [Qemu-devel] [PATCH v6 08/29] libqtest: Let socket_send() compute length

Quoted 13 lines · Markus Armbruster
Quoted 11 lines · Thomas Huth
Quoted 9 lines · Eric Blake

Rather than make multiple callers call strlen(), it's easier if socket_send() itself can compute a length via strlen() if none was provided (caller passes -1). Callers that can get at the length more efficiently are left that way.

---
 tests/libqtest.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Quoted 5 lines
Quoted 3 lines

I have to say that I don't like this idea very much. socket_send() should IMHO not know about the type of the data that should be sent, i.e. it should not assume that the content is a zero-terminated string.

I agree.

It doesn't assume that the content is zero-terminated unless you pass a negative length.

Quoted 7 lines
Quoted 7 lines

This also could lead to some hard to detect bugs later in case somebody is calling the function like this:

  size = someotherfunction();
  socket_send(fd, buf, size);
Quoted 7 lines
Quoted 4 lines

... and the someotherfunction() returned a negative error code instead of a correct size.

So I'd like to suggest to simply drop this patch.

A separate wrapper function for sending zero-terminated strings would be fine with me.

I'm fine dropping the patch; computing the length in the callers is not that much more onerous (there aren't that many), so I don't think another wrapper is needed.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
author
#24 lore raw

PATCH v6 9/29 libqtest: Use qemu_strtoul()

In reply to Eric Blake

This will keep checkpatch happy when the next patch does code motion. Fix the include order to match HACKING when adding the needed header.

---
 tests/libqtest.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
tests/libqtest.c +13 -6
index a6ce21d7f9..438a22678d 100644
@@ -15,12 +15,13 @@
  *
  */
 #include "qemu/osdep.h"
-#include "libqtest.h"
 
 #include <sys/socket.h>
 #include <sys/wait.h>
 #include <sys/un.h>
 
+#include "libqtest.h"
+#include "qemu/cutils.h"
 #include "qapi/error.h"
 #include "qapi/qmp/json-parser.h"
 #include "qapi/qmp/json-streamer.h"
@@ -333,12 +334,14 @@ redo:
     g_string_free(line, TRUE);
 
     if (strcmp(words[0], "IRQ") == 0) {
-        int irq;
+        long irq;
+        int ret;
 
         g_assert(words[1] != NULL);
         g_assert(words[2] != NULL);
 
-        irq = strtoul(words[2], NULL, 0);
+        ret = qemu_strtol(words[2], NULL, 0, &irq);
+        g_assert(!ret);
         g_assert_cmpint(irq, >=, 0);
         g_assert_cmpint(irq, <, MAX_IRQ);
 
@@ -701,11 +704,13 @@ void qtest_outl(QTestState *s, uint16_t addr, uint32_t value)
 static uint32_t qtest_in(QTestState *s, const char *cmd, uint16_t addr)
 {
     gchar **args;
-    uint32_t value;
+    int ret;
+    unsigned long value;
 
     qtest_sendf(s, "%s 0x%x\n", cmd, addr);
     args = qtest_rsp(s, 2);
-    value = strtoul(args[1], NULL, 0);
+    ret = qemu_strtoul(args[1], NULL, 0, &value);
+    g_assert(!ret && value <= UINT32_MAX);
     g_strfreev(args);
 
     return value;
@@ -756,11 +761,13 @@ void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value)
 static uint64_t qtest_read(QTestState *s, const char *cmd, uint64_t addr)
 {
     gchar **args;
+    int ret;
     uint64_t value;
 
     qtest_sendf(s, "%s 0x%" PRIx64 "\n", cmd, addr);
     args = qtest_rsp(s, 2);
-    value = strtoull(args[1], NULL, 0);
+    ret = qemu_strtou64(args[1], NULL, 0, &value);
+    g_assert(!ret);
     g_strfreev(args);
 
     return value;
Signature · 1 line
2.13.5
Reviewed-by on v6 9/29
#25 lore raw

Re: [Qemu-devel] [PATCH v6 09/29] libqtest: Use qemu_strtoul()

Quoted 8 lines · Eric Blake

This will keep checkpatch happy when the next patch does code motion. Fix the include order to match HACKING when adding the needed header.

---
 tests/libqtest.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
author
#26 lore raw

PATCH v6 10/29 libqtest: Topologically sort functions

In reply to Eric Blake

Put static functions prior to public ones, in part so that improvements to qtest_start() can benefit from the static helpers without needing forward references. Code motion, with no semantic change.

---
 tests/libqtest.c | 263 +++++++++++++++++++++++++++----------------------------
 1 file changed, 131 insertions(+), 132 deletions(-)
tests/libqtest.c +131 -132
index 438a22678d..5d16351e24 100644
@@ -49,7 +49,6 @@ static struct sigaction sigact_old;
     g_assert_cmpint(ret, !=, -1); \
 } while (0)
 
-static int qtest_query_target_endianness(QTestState *s);
 
 static int init_socket(const char *socket_path)
 {
@@ -128,6 +127,137 @@ static void setup_sigabrt_handler(void)
     sigaction(SIGABRT, &sigact, &sigact_old);
 }
 
+static void socket_send(int fd, const char *buf, ssize_t size)
+{
+    size_t offset;
+
+    if (size < 0) {
+        size = strlen(buf);
+    }
+    offset = 0;
+    while (offset < size) {
+        ssize_t len;
+
+        len = write(fd, buf + offset, size - offset);
+        if (len == -1 && errno == EINTR) {
+            continue;
+        }
+
+        g_assert_no_errno(len);
+        g_assert_cmpint(len, >, 0);
+
+        offset += len;
+    }
+}
+
+static void socket_sendf(int fd, const char *fmt, va_list ap)
+{
+    gchar *str = g_strdup_vprintf(fmt, ap);
+
+    socket_send(fd, str, -1);
+    g_free(str);
+}
+
+static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    socket_sendf(s->fd, fmt, ap);
+    va_end(ap);
+}
+
+static GString *qtest_recv_line(QTestState *s)
+{
+    GString *line;
+    size_t offset;
+    char *eol;
+
+    while ((eol = strchr(s->rx->str, '\n')) == NULL) {
+        ssize_t len;
+        char buffer[1024];
+
+        len = read(s->fd, buffer, sizeof(buffer));
+        if (len == -1 && errno == EINTR) {
+            continue;
+        }
+
+        if (len == -1 || len == 0) {
+            fprintf(stderr, "Broken pipe\n");
+            exit(1);
+        }
+
+        g_string_append_len(s->rx, buffer, len);
+    }
+
+    offset = eol - s->rx->str;
+    line = g_string_new_len(s->rx->str, offset);
+    g_string_erase(s->rx, 0, offset + 1);
+
+    return line;
+}
+
+static gchar **qtest_rsp(QTestState *s, int expected_args)
+{
+    GString *line;
+    gchar **words;
+    int i;
+
+redo:
+    line = qtest_recv_line(s);
+    words = g_strsplit(line->str, " ", 0);
+    g_string_free(line, TRUE);
+
+    if (strcmp(words[0], "IRQ") == 0) {
+        long irq;
+        int ret;
+
+        g_assert(words[1] != NULL);
+        g_assert(words[2] != NULL);
+
+        ret = qemu_strtol(words[2], NULL, 0, &irq);
+        g_assert(!ret);
+        g_assert_cmpint(irq, >=, 0);
+        g_assert_cmpint(irq, <, MAX_IRQ);
+
+        if (strcmp(words[1], "raise") == 0) {
+            s->irq_level[irq] = true;
+        } else {
+            s->irq_level[irq] = false;
+        }
+
+        g_strfreev(words);
+        goto redo;
+    }
+
+    g_assert(words[0] != NULL);
+    g_assert_cmpstr(words[0], ==, "OK");
+
+    if (expected_args) {
+        for (i = 0; i < expected_args; i++) {
+            g_assert(words[i] != NULL);
+        }
+    } else {
+        g_strfreev(words);
+    }
+
+    return words;
+}
+
+static int qtest_query_target_endianness(QTestState *s)
+{
+    gchar **args;
+    int big_endian;
+
+    qtest_sendf(s, "endianness\n");
+    args = qtest_rsp(s, 1);
+    g_assert(strcmp(args[1], "big") == 0 || strcmp(args[1], "little") == 0);
+    big_endian = strcmp(args[1], "big") == 0;
+    g_strfreev(args);
+
+    return big_endian;
+}
+
 static void cleanup_sigabrt_handler(void)
 {
     sigaction(SIGABRT, &sigact_old, NULL);
@@ -252,137 +382,6 @@ void qtest_quit(QTestState *s)
     g_free(s);
 }
 
-static void socket_send(int fd, const char *buf, ssize_t size)
-{
-    size_t offset;
-
-    if (size < 0) {
-        size = strlen(buf);
-    }
-    offset = 0;
-    while (offset < size) {
-        ssize_t len;
-
-        len = write(fd, buf + offset, size - offset);
-        if (len == -1 && errno == EINTR) {
-            continue;
-        }
-
-        g_assert_no_errno(len);
-        g_assert_cmpint(len, >, 0);
-
-        offset += len;
-    }
-}
-
-static void socket_sendf(int fd, const char *fmt, va_list ap)
-{
-    gchar *str = g_strdup_vprintf(fmt, ap);
-
-    socket_send(fd, str, -1);
-    g_free(str);
-}
-
-static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...)
-{
-    va_list ap;
-
-    va_start(ap, fmt);
-    socket_sendf(s->fd, fmt, ap);
-    va_end(ap);
-}
-
-static GString *qtest_recv_line(QTestState *s)
-{
-    GString *line;
-    size_t offset;
-    char *eol;
-
-    while ((eol = strchr(s->rx->str, '\n')) == NULL) {
-        ssize_t len;
-        char buffer[1024];
-
-        len = read(s->fd, buffer, sizeof(buffer));
-        if (len == -1 && errno == EINTR) {
-            continue;
-        }
-
-        if (len == -1 || len == 0) {
-            fprintf(stderr, "Broken pipe\n");
-            exit(1);
-        }
-
-        g_string_append_len(s->rx, buffer, len);
-    }
-
-    offset = eol - s->rx->str;
-    line = g_string_new_len(s->rx->str, offset);
-    g_string_erase(s->rx, 0, offset + 1);
-
-    return line;
-}
-
-static gchar **qtest_rsp(QTestState *s, int expected_args)
-{
-    GString *line;
-    gchar **words;
-    int i;
-
-redo:
-    line = qtest_recv_line(s);
-    words = g_strsplit(line->str, " ", 0);
-    g_string_free(line, TRUE);
-
-    if (strcmp(words[0], "IRQ") == 0) {
-        long irq;
-        int ret;
-
-        g_assert(words[1] != NULL);
-        g_assert(words[2] != NULL);
-
-        ret = qemu_strtol(words[2], NULL, 0, &irq);
-        g_assert(!ret);
-        g_assert_cmpint(irq, >=, 0);
-        g_assert_cmpint(irq, <, MAX_IRQ);
-
-        if (strcmp(words[1], "raise") == 0) {
-            s->irq_level[irq] = true;
-        } else {
-            s->irq_level[irq] = false;
-        }
-
-        g_strfreev(words);
-        goto redo;
-    }
-
-    g_assert(words[0] != NULL);
-    g_assert_cmpstr(words[0], ==, "OK");
-
-    if (expected_args) {
-        for (i = 0; i < expected_args; i++) {
-            g_assert(words[i] != NULL);
-        }
-    } else {
-        g_strfreev(words);
-    }
-
-    return words;
-}
-
-static int qtest_query_target_endianness(QTestState *s)
-{
-    gchar **args;
-    int big_endian;
-
-    qtest_sendf(s, "endianness\n");
-    args = qtest_rsp(s, 1);
-    g_assert(strcmp(args[1], "big") == 0 || strcmp(args[1], "little") == 0);
-    big_endian = strcmp(args[1], "big") == 0;
-    g_strfreev(args);
-
-    return big_endian;
-}
-
 typedef struct {
     JSONMessageParser parser;
     QDict *response;
Signature · 1 line
2.13.5
#27 lore raw

Re: [Qemu-devel] [PATCH v6 10/29] libqtest: Topologically sort functions

Quoted 289 lines · Eric Blake

Put static functions prior to public ones, in part so that improvements to qtest_start() can benefit from the static helpers without needing forward references. Code motion, with no semantic change.

---
 tests/libqtest.c | 263 +++++++++++++++++++++++++++----------------------------
 1 file changed, 131 insertions(+), 132 deletions(-)
tests/libqtest.c +131 -125
index 438a22678d..5d16351e24 100644
@@ -49,7 +49,6 @@ static struct sigaction sigact_old;
     g_assert_cmpint(ret, !=, -1); \
 } while (0)
 
-static int qtest_query_target_endianness(QTestState *s);
 
 static int init_socket(const char *socket_path)
 {
@@ -128,6 +127,137 @@ static void setup_sigabrt_handler(void)
     sigaction(SIGABRT, &sigact, &sigact_old);
 }
 
+static void socket_send(int fd, const char *buf, ssize_t size)
+{
+    size_t offset;
+
+    if (size < 0) {
+        size = strlen(buf);
+    }
+    offset = 0;
+    while (offset < size) {
+        ssize_t len;
+
+        len = write(fd, buf + offset, size - offset);
+        if (len == -1 && errno == EINTR) {
+            continue;
+        }
+
+        g_assert_no_errno(len);
+        g_assert_cmpint(len, >, 0);
+
+        offset += len;
+    }
+}
+
+static void socket_sendf(int fd, const char *fmt, va_list ap)
+{
+    gchar *str = g_strdup_vprintf(fmt, ap);
+
+    socket_send(fd, str, -1);
+    g_free(str);
+}
+
+static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    socket_sendf(s->fd, fmt, ap);
+    va_end(ap);
+}
+
+static GString *qtest_recv_line(QTestState *s)
+{
+    GString *line;
+    size_t offset;
+    char *eol;
+
+    while ((eol = strchr(s->rx->str, '\n')) == NULL) {
+        ssize_t len;
+        char buffer[1024];
+
+        len = read(s->fd, buffer, sizeof(buffer));
+        if (len == -1 && errno == EINTR) {
+            continue;
+        }
+
+        if (len == -1 || len == 0) {
+            fprintf(stderr, "Broken pipe\n");
+            exit(1);
+        }
+
+        g_string_append_len(s->rx, buffer, len);
+    }
+
+    offset = eol - s->rx->str;
+    line = g_string_new_len(s->rx->str, offset);
+    g_string_erase(s->rx, 0, offset + 1);
+
+    return line;
+}
+
+static gchar **qtest_rsp(QTestState *s, int expected_args)
+{
+    GString *line;
+    gchar **words;
+    int i;
+
+redo:
+    line = qtest_recv_line(s);
+    words = g_strsplit(line->str, " ", 0);
+    g_string_free(line, TRUE);
+
+    if (strcmp(words[0], "IRQ") == 0) {
+        long irq;
+        int ret;
+
+        g_assert(words[1] != NULL);
+        g_assert(words[2] != NULL);
+
+        ret = qemu_strtol(words[2], NULL, 0, &irq);
+        g_assert(!ret);
+        g_assert_cmpint(irq, >=, 0);
+        g_assert_cmpint(irq, <, MAX_IRQ);
+
+        if (strcmp(words[1], "raise") == 0) {
+            s->irq_level[irq] = true;
+        } else {
+            s->irq_level[irq] = false;
+        }
+
+        g_strfreev(words);
+        goto redo;
+    }
+
+    g_assert(words[0] != NULL);
+    g_assert_cmpstr(words[0], ==, "OK");
+
+    if (expected_args) {
+        for (i = 0; i < expected_args; i++) {
+            g_assert(words[i] != NULL);
+        }
+    } else {
+        g_strfreev(words);
+    }
+
+    return words;
+}
+
+static int qtest_query_target_endianness(QTestState *s)
+{
+    gchar **args;
+    int big_endian;
+
+    qtest_sendf(s, "endianness\n");
+    args = qtest_rsp(s, 1);
+    g_assert(strcmp(args[1], "big") == 0 || strcmp(args[1], "little") == 0);
+    big_endian = strcmp(args[1], "big") == 0;
+    g_strfreev(args);
+
+    return big_endian;
+}
+
 static void cleanup_sigabrt_handler(void)
 {
     sigaction(SIGABRT, &sigact_old, NULL);
@@ -252,137 +382,6 @@ void qtest_quit(QTestState *s)
     g_free(s);
 }
 
-static void socket_send(int fd, const char *buf, ssize_t size)
-{
-    size_t offset;
-
-    if (size < 0) {
-        size = strlen(buf);
-    }
-    offset = 0;
-    while (offset < size) {
-        ssize_t len;
-
-        len = write(fd, buf + offset, size - offset);
-        if (len == -1 && errno == EINTR) {
-            continue;
-        }
-
-        g_assert_no_errno(len);
-        g_assert_cmpint(len, >, 0);
-
-        offset += len;
-    }
-}
-
-static void socket_sendf(int fd, const char *fmt, va_list ap)
-{
-    gchar *str = g_strdup_vprintf(fmt, ap);
-
-    socket_send(fd, str, -1);
-    g_free(str);
-}
-
-static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...)
-{
-    va_list ap;
-
-    va_start(ap, fmt);
-    socket_sendf(s->fd, fmt, ap);
-    va_end(ap);
-}
-
-static GString *qtest_recv_line(QTestState *s)
-{
-    GString *line;
-    size_t offset;
-    char *eol;
-
-    while ((eol = strchr(s->rx->str, '\n')) == NULL) {
-        ssize_t len;
-        char buffer[1024];
-
-        len = read(s->fd, buffer, sizeof(buffer));
-        if (len == -1 && errno == EINTR) {
-            continue;
-        }
-
-        if (len == -1 || len == 0) {
-            fprintf(stderr, "Broken pipe\n");
-            exit(1);
-        }
-
-        g_string_append_len(s->rx, buffer, len);
-    }
-
-    offset = eol - s->rx->str;
-    line = g_string_new_len(s->rx->str, offset);
-    g_string_erase(s->rx, 0, offset + 1);
-
-    return line;
-}
-
-static gchar **qtest_rsp(QTestState *s, int expected_args)
-{
-    GString *line;
-    gchar **words;
-    int i;
-
-redo:
-    line = qtest_recv_line(s);
-    words = g_strsplit(line->str, " ", 0);
-    g_string_free(line, TRUE);
-
-    if (strcmp(words[0], "IRQ") == 0) {
-        long irq;
-        int ret;
-
-        g_assert(words[1] != NULL);
-        g_assert(words[2] != NULL);
-
-        ret = qemu_strtol(words[2], NULL, 0, &irq);
-        g_assert(!ret);
-        g_assert_cmpint(irq, >=, 0);
-        g_assert_cmpint(irq, <, MAX_IRQ);
-
-        if (strcmp(words[1], "raise") == 0) {
-            s->irq_level[irq] = true;
-        } else {
-            s->irq_level[irq] = false;
-        }
-
-        g_strfreev(words);
-        goto redo;
-    }
-
-    g_assert(words[0] != NULL);
-    g_assert_cmpstr(words[0], ==, "OK");
-
-    if (expected_args) {
-        for (i = 0; i < expected_args; i++) {
-            g_assert(words[i] != NULL);
-        }
-    } else {
-        g_strfreev(words);
-    }
-
-    return words;
-}
-
-static int qtest_query_target_endianness(QTestState *s)
-{
-    gchar **args;
-    int big_endian;
-
-    qtest_sendf(s, "endianness\n");
-    args = qtest_rsp(s, 1);

tests/libqtest.c void qtest_quit(QTestState *s) · line 387

Quoted 10 lines
tests/libqtest.c +0 -7
-    g_assert(strcmp(args[1], "big") == 0 || strcmp(args[1], "little") == 0);
-    big_endian = strcmp(args[1], "big") == 0;
-    g_strfreev(args);
-
-    return big_endian;
-}
-
 typedef struct {
     JSONMessageParser parser;
     QDict *response;

That's a *lot* of code motion - just to get rid of one forward declaration. IMHO getting rid of just one forward declaration does not justify this code churn. But if we really, really want to get rid of the forward declaration here, it's maybe better to move the qtest_init_without_qmp_handshake() and qtest_init() function to the end of the file instead?

Thomas

#28 lore raw

Re: [Qemu-devel] [PATCH v6 10/29] libqtest: Topologically sort functions

Quoted 10 lines · Thomas Huth
Quoted 9 lines · Eric Blake

Put static functions prior to public ones, in part so that improvements to qtest_start() can benefit from the static helpers without needing forward references. Code motion, with no semantic change.

---
 tests/libqtest.c | 263 +++++++++++++++++++++++++++----------------------------
 1 file changed, 131 insertions(+), 132 deletions(-)

[...]

Quoted 6 lines

That's a *lot* of code motion - just to get rid of one forward declaration. IMHO getting rid of just one forward declaration does not justify this code churn. But if we really, really want to get rid of the forward declaration here, it's maybe better to move the qtest_init_without_qmp_handshake() and qtest_init() function to the end of the file instead?

I've never understood why people hate forward declarations so much. Just because the compiler needs to see a declaration before any use doesn't mean a human reader profits from seeing the definition before any use. Sometimes the code is easier to understand in top-down order.

For code I maintain, I evaluate code motion proposals strictly on readability merits, with complete disregard for the number of forward declarations added or deleted.

I'm very much not maintaining this code, though :)

author
#29 lore raw

PATCH v6 11/29 libqtest: Inline qtest_query_target_endianness()

In reply to Eric Blake

There was only one caller; it's easier to inline things.

---
 tests/libqtest.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)
tests/libqtest.c +6 -16
index 5d16351e24..b6dd26e54a 100644
@@ -244,20 +244,6 @@ redo:
     return words;
 }
 
-static int qtest_query_target_endianness(QTestState *s)
-{
-    gchar **args;
-    int big_endian;
-
-    qtest_sendf(s, "endianness\n");
-    args = qtest_rsp(s, 1);
-    g_assert(strcmp(args[1], "big") == 0 || strcmp(args[1], "little") == 0);
-    big_endian = strcmp(args[1], "big") == 0;
-    g_strfreev(args);
-
-    return big_endian;
-}
-
 static void cleanup_sigabrt_handler(void)
 {
     sigaction(SIGABRT, &sigact_old, NULL);
@@ -288,6 +274,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     gchar *qmp_socket_path;
     gchar *command;
     const char *qemu_binary;
+    gchar **args;
 
     qemu_binary = getenv("QTEST_QEMU_BINARY");
     if (!qemu_binary) {
@@ -351,8 +338,11 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     }
 
     /* ask endianness of the target */
-
-    s->big_endian = qtest_query_target_endianness(s);
+    qtest_sendf(s, "endianness\n");
+    args = qtest_rsp(s, 1);
+    g_assert(strcmp(args[1], "big") == 0 || strcmp(args[1], "little") == 0);
+    s->big_endian = strcmp(args[1], "big") == 0;
+    g_strfreev(args);
 
     return s;
 }
Signature · 1 line
2.13.5
Acked-by on v6 11/29
#30 lore raw

Re: [Qemu-devel] [PATCH v6 11/29] libqtest: Inline qtest_query_target_endianness()

Quoted 3 lines · Eric Blake

There was only one caller; it's easier to inline things.

Quoted 52 lines
---
  tests/libqtest.c | 22 ++++++----------------
  1 file changed, 6 insertions(+), 16 deletions(-)
tests/libqtest.c +6 -16
index 5d16351e24..b6dd26e54a 100644
@@ -244,20 +244,6 @@ redo:
      return words;
  }
 
-static int qtest_query_target_endianness(QTestState *s)
-{
-    gchar **args;
-    int big_endian;
-
-    qtest_sendf(s, "endianness\n");
-    args = qtest_rsp(s, 1);
-    g_assert(strcmp(args[1], "big") == 0 || strcmp(args[1], "little") == 0);
-    big_endian = strcmp(args[1], "big") == 0;
-    g_strfreev(args);
-
-    return big_endian;
-}
-
  static void cleanup_sigabrt_handler(void)
  {
      sigaction(SIGABRT, &sigact_old, NULL);
@@ -288,6 +274,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
      gchar *qmp_socket_path;
      gchar *command;
      const char *qemu_binary;
+    gchar **args;
 
      qemu_binary = getenv("QTEST_QEMU_BINARY");
      if (!qemu_binary) {
@@ -351,8 +338,11 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
      }
 
      /* ask endianness of the target */
-
-    s->big_endian = qtest_query_target_endianness(s);
+    qtest_sendf(s, "endianness\n");
+    args = qtest_rsp(s, 1);
+    g_assert(strcmp(args[1], "big") == 0 || strcmp(args[1], "little") == 0);
+    s->big_endian = strcmp(args[1], "big") == 0;
+    g_strfreev(args);
 
      return s;
  }
#31 lore raw

Re: [Qemu-devel] [PATCH v6 11/29] libqtest: Inline qtest_query_target_endianness()

In reply to Eric Blake
Quoted 44 lines · Eric Blake

There was only one caller; it's easier to inline things.

---
 tests/libqtest.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)
tests/libqtest.c +1 -14
index 5d16351e24..b6dd26e54a 100644
@@ -244,20 +244,6 @@ redo:
     return words;
 }
 
-static int qtest_query_target_endianness(QTestState *s)
-{
-    gchar **args;
-    int big_endian;
-
-    qtest_sendf(s, "endianness\n");
-    args = qtest_rsp(s, 1);
-    g_assert(strcmp(args[1], "big") == 0 || strcmp(args[1], "little") == 0);
-    big_endian = strcmp(args[1], "big") == 0;
-    g_strfreev(args);
-
-    return big_endian;
-}
-
 static void cleanup_sigabrt_handler(void)
 {
     sigaction(SIGABRT, &sigact_old, NULL);
@@ -288,6 +274,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     gchar *qmp_socket_path;
     gchar *command;
     const char *qemu_binary;
+    gchar **args;
 
     qemu_binary = getenv("QTEST_QEMU_BINARY");
     if (!qemu_binary) {
@@ -351,8 +338,11 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     }
 
     /* ask endianness of the target */

tests/libqtest.c QTestState *qtest_init_without_qmp_handshake(const char *extra_args) · line 348

Quoted 10 lines
tests/libqtest.c +5 -2
-
-    s->big_endian = qtest_query_target_endianness(s);
+    qtest_sendf(s, "endianness\n");
+    args = qtest_rsp(s, 1);
+    g_assert(strcmp(args[1], "big") == 0 || strcmp(args[1], "little") == 0);
+    s->big_endian = strcmp(args[1], "big") == 0;
+    g_strfreev(args);
 
     return s;
 }

Ah, well, now that's another way of getting rid of the forward declaration in the previous patch - so may I suggest to drop the previous patch, and simply do the code inlining here instead?

Thomas

author
#32 lore raw

Re: [Qemu-devel] [PATCH v6 11/29] libqtest: Inline qtest_query_target_endianness()

Quoted 10 lines · Thomas Huth
Quoted 7 lines · Eric Blake

There was only one caller; it's easier to inline things.

---
 tests/libqtest.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)
Quoted 3 lines

Ah, well, now that's another way of getting rid of the forward declaration in the previous patch - so may I suggest to drop the previous patch, and simply do the code inlining here instead?

Will do.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
author
#33 lore raw

PATCH v6 12/29 libqos: Track QTestState with QPCIBus

In reply to Eric Blake

When initializing a QPCIBus, track which QTestState the bus is associated with (so that a later patch can then explicitly use that test state for all communication on the bus, rather than blindly relying on global_qtest). Update the initialization functions to take another parameter, and update all callers to pass in state (for now, most callers get away with passing the current global_qtest as the current state, although this required fixing the order of initialization to ensure qtest_start() is called before qpci_init*() in rtl8139-test, and provided an opportunity to pass in the allocator in e1000e-test).

---
 tests/libqos/ahci.h       | 2 +-
 tests/libqos/libqos.h     | 2 +-
 tests/libqos/pci-pc.h     | 2 +-
 tests/libqos/pci-spapr.h  | 2 +-
 tests/libqos/pci.h        | 1 +
 tests/ahci-test.c         | 2 +-
 tests/e1000e-test.c       | 6 +++---
 tests/i440fx-test.c       | 2 +-
 tests/ide-test.c          | 2 +-
 tests/libqos/ahci.c       | 4 ++--
 tests/libqos/libqos.c     | 4 ++--
 tests/libqos/pci-pc.c     | 5 ++++-
 tests/libqos/pci-spapr.c  | 6 +++++-
 tests/q35-test.c          | 4 ++--
 tests/rtl8139-test.c      | 5 +++--
 tests/tco-test.c          | 2 +-
 tests/usb-hcd-ehci-test.c | 2 +-
 tests/vhost-user-test.c   | 4 ++--
 18 files changed, 33 insertions(+), 24 deletions(-)
tests/libqos/ahci.h +1 -1
index 5f9627bb0f..715ca1e226 100644
@@ -571,7 +571,7 @@ void ahci_free(AHCIQState *ahci, uint64_t addr);
 void ahci_clean_mem(AHCIQState *ahci);
 
 /* Device management */
-QPCIDevice *get_ahci_device(uint32_t *fingerprint);
+QPCIDevice *get_ahci_device(QTestState *qts, uint32_t *fingerprint);
 void free_ahci_device(QPCIDevice *dev);
 void ahci_pci_enable(AHCIQState *ahci);
 void start_ahci_device(AHCIQState *ahci);
tests/libqos/libqos.h +1 -1
index 231969766f..78e5c044a0 100644
@@ -10,7 +10,7 @@ typedef struct QOSState QOSState;
 typedef struct QOSOps {
     QGuestAllocator *(*init_allocator)(QAllocOpts);
     void (*uninit_allocator)(QGuestAllocator *);
-    QPCIBus *(*qpci_init)(QGuestAllocator *alloc);
+    QPCIBus *(*qpci_init)(QTestState *qts, QGuestAllocator *alloc);
     void (*qpci_free)(QPCIBus *bus);
     void (*shutdown)(QOSState *);
 } QOSOps;
tests/libqos/pci-pc.h +1 -1
index 9479b51642..491eeac756 100644
@@ -16,7 +16,7 @@
 #include "libqos/pci.h"
 #include "libqos/malloc.h"
 
-QPCIBus *qpci_init_pc(QGuestAllocator *alloc);
+QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc);
 void     qpci_free_pc(QPCIBus *bus);
 
 #endif
tests/libqos/pci-spapr.h +1 -1
index 4192126d86..387686dfc8 100644
@@ -11,7 +11,7 @@
 #include "libqos/malloc.h"
 #include "libqos/pci.h"
 
-QPCIBus *qpci_init_spapr(QGuestAllocator *alloc);
+QPCIBus *qpci_init_spapr(QTestState *qts, QGuestAllocator *alloc);
 void     qpci_free_spapr(QPCIBus *bus);
 
 #endif
tests/libqos/pci.h +1 -0
index ed480614ff..429c382282 100644
@@ -48,6 +48,7 @@ struct QPCIBus {
     void (*config_writel)(QPCIBus *bus, int devfn,
                           uint8_t offset, uint32_t value);
 
+    QTestState *qts;
     uint16_t pio_alloc_ptr;
     uint64_t mmio_alloc_ptr, mmio_limit;
 };
tests/ahci-test.c +1 -1
index 999121bb7c..c94d1bd712 100644
@@ -160,7 +160,7 @@ static AHCIQState *ahci_vboot(const char *cli, va_list ap)
     alloc_set_flags(s->parent->alloc, ALLOC_LEAK_ASSERT);
 
     /* Verify that we have an AHCI device present. */
-    s->dev = get_ahci_device(&s->fingerprint);
+    s->dev = get_ahci_device(s->parent->qts, &s->fingerprint);
 
     return s;
 }
tests/e1000e-test.c +3 -3
index c612dc64ec..d8085d944e 100644
@@ -392,12 +392,12 @@ static void data_test_init(e1000e_device *d)
     qtest_start(cmdline);
     g_free(cmdline);
 
-    test_bus = qpci_init_pc(NULL);
-    g_assert_nonnull(test_bus);
-
     test_alloc = pc_alloc_init();
     g_assert_nonnull(test_alloc);
 
+    test_bus = qpci_init_pc(global_qtest, test_alloc);
+    g_assert_nonnull(test_bus);
+
     e1000e_device_init(test_bus, d);
 }
 
tests/i440fx-test.c +1 -1
index e9d05c87d1..4390e5591e 100644
@@ -38,7 +38,7 @@ static QPCIBus *test_start_get_bus(const TestData *s)
     cmdline = g_strdup_printf("-smp %d", s->num_cpus);
     qtest_start(cmdline);
     g_free(cmdline);
-    return qpci_init_pc(NULL);
+    return qpci_init_pc(global_qtest, NULL);
 }
 
 static void test_i440fx_defaults(gconstpointer opaque)
tests/ide-test.c +1 -1
index aa9de065fc..b2237b6158 100644
@@ -143,7 +143,7 @@ static QPCIDevice *get_pci_device(QPCIBar *bmdma_bar, QPCIBar *ide_bar)
     uint16_t vendor_id, device_id;
 
     if (!pcibus) {
-        pcibus = qpci_init_pc(NULL);
+        pcibus = qpci_init_pc(global_qtest, NULL);
     }
 
     /* Find PCI device and verify it's the right one */
tests/libqos/ahci.c +2 -2
index 1ca7f456b5..790ef991b3 100644
@@ -123,13 +123,13 @@ bool is_atapi(AHCIQState *ahci, uint8_t port)
 /**
  * Locate, verify, and return a handle to the AHCI device.
  */
-QPCIDevice *get_ahci_device(uint32_t *fingerprint)
+QPCIDevice *get_ahci_device(QTestState *qts, uint32_t *fingerprint)
 {
     QPCIDevice *ahci;
     uint32_t ahci_fingerprint;
     QPCIBus *pcibus;
 
-    pcibus = qpci_init_pc(NULL);
+    pcibus = qpci_init_pc(qts, NULL);
 
     /* Find the AHCI PCI device and verify it's the right one. */
     ahci = qpci_device_find(pcibus, QPCI_DEVFN(0x1F, 0x02));
tests/libqos/libqos.c +2 -2
index 6226546c28..c95428e1cb 100644
@@ -26,8 +26,8 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
         if (ops->init_allocator) {
             qs->alloc = ops->init_allocator(ALLOC_NO_FLAGS);
         }
-        if (ops->qpci_init && qs->alloc) {
-            qs->pcibus = ops->qpci_init(qs->alloc);
+        if (ops->qpci_init) {
+            qs->pcibus = ops->qpci_init(qs->qts, qs->alloc);
         }
     }
 
tests/libqos/pci-pc.c +4 -1
index 02ce49927a..85b34c6d13 100644
@@ -115,11 +115,14 @@ static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3
     outl(0xcfc, value);
 }
 
-QPCIBus *qpci_init_pc(QGuestAllocator *alloc)
+QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc)
 {
     QPCIBusPC *ret;
 
+    assert(qts);
+
     ret = g_malloc(sizeof(*ret));
+    ret->bus.qts = qts;
 
     ret->bus.pio_readb = qpci_pc_pio_readb;
     ret->bus.pio_readw = qpci_pc_pio_readw;
tests/libqos/pci-spapr.c +5 -1
index 2043f1e123..cd9b8f52d2 100644
@@ -154,11 +154,14 @@ static void qpci_spapr_config_writel(QPCIBus *bus, int devfn, uint8_t offset,
 #define SPAPR_PCI_MMIO32_WIN_SIZE    0x80000000 /* 2 GiB */
 #define SPAPR_PCI_IO_WIN_SIZE        0x10000
 
-QPCIBus *qpci_init_spapr(QGuestAllocator *alloc)
+QPCIBus *qpci_init_spapr(QTestState *qts, QGuestAllocator *alloc)
 {
     QPCIBusSPAPR *ret;
 
+    assert(qts);
+
     ret = g_malloc(sizeof(*ret));
+    ret->bus.qts = qts;
 
     ret->alloc = alloc;
 
@@ -201,6 +204,7 @@ QPCIBus *qpci_init_spapr(QGuestAllocator *alloc)
     ret->bus.mmio_alloc_ptr = ret->mmio32.pci_base;
     ret->bus.mmio_limit = ret->mmio32.pci_base + ret->mmio32.size;
 
+
     return &ret->bus;
 }
 
tests/q35-test.c +2 -2
index f98bed7a2d..e149c4c51d 100644
@@ -86,7 +86,7 @@ static void test_smram_lock(void)
 
     qtest_start("-M q35");
 
-    pcibus = qpci_init_pc(NULL);
+    pcibus = qpci_init_pc(global_qtest, NULL);
     g_assert(pcibus != NULL);
 
     pcidev = qpci_device_find(pcibus, 0);
@@ -145,7 +145,7 @@ static void test_tseg_size(const void *data)
     g_free(cmdline);
 
     /* locate the DRAM controller */
-    pcibus = qpci_init_pc(NULL);
+    pcibus = qpci_init_pc(global_qtest, NULL);
     g_assert(pcibus != NULL);
     pcidev = qpci_device_find(pcibus, 0);
     g_assert(pcidev != NULL);
tests/rtl8139-test.c +3 -2
index 7de7dc45ae..68bfc42178 100644
@@ -35,7 +35,7 @@ static QPCIDevice *get_device(void)
 {
     QPCIDevice *dev;
 
-    pcibus = qpci_init_pc(NULL);
+    pcibus = qpci_init_pc(global_qtest, NULL);
     qpci_device_foreach(pcibus, 0x10ec, 0x8139, save_fn, &dev);
     g_assert(dev != NULL);
 
@@ -197,11 +197,12 @@ int main(int argc, char **argv)
 {
     int ret;
 
+    qtest_start("-device rtl8139");
+
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/rtl8139/nop", nop);
     qtest_add_func("/rtl8139/timer", test_init);
 
-    qtest_start("-device rtl8139");
     ret = g_test_run();
 
     qtest_end();
tests/tco-test.c +1 -1
index f2ed6ed91c..0387971953 100644
@@ -64,7 +64,7 @@ static void test_init(TestData *d)
     qtest_irq_intercept_in(qs, "ioapic");
     g_free(s);
 
-    d->bus = qpci_init_pc(NULL);
+    d->bus = qpci_init_pc(qs, NULL);
     d->dev = qpci_device_find(d->bus, QPCI_DEVFN(0x1f, 0x00));
     g_assert(d->dev != NULL);
 
tests/usb-hcd-ehci-test.c +1 -1
index 944eb1c088..55d4743a2a 100644
@@ -52,7 +52,7 @@ static void ehci_port_test(struct qhc *hc, int port, uint32_t expect)
 
 static void test_init(void)
 {
-    pcibus = qpci_init_pc(NULL);
+    pcibus = qpci_init_pc(global_qtest, NULL);
     g_assert(pcibus != NULL);
 
     qusb_pci_init_one(pcibus, &uhci1, QPCI_DEVFN(0x1d, 0), 4);
tests/vhost-user-test.c +2 -2
index d4da09f147..ea7d38ea44 100644
@@ -164,7 +164,7 @@ static void init_virtio_dev(TestServer *s)
     QVirtioPCIDevice *dev;
     uint32_t features;
 
-    s->bus = qpci_init_pc(NULL);
+    s->bus = qpci_init_pc(global_qtest, NULL);
     g_assert_nonnull(s->bus);
 
     dev = qvirtio_pci_device_find(s->bus, VIRTIO_ID_NET);
@@ -891,7 +891,7 @@ static void test_multiqueue(void)
     qtest_start(cmd);
     g_free(cmd);
 
-    bus = qpci_init_pc(NULL);
+    bus = qpci_init_pc(global_qtest, NULL);
     dev = virtio_net_pci_init(bus, PCI_SLOT);
 
     alloc = pc_alloc_init();
Signature · 1 line
2.13.5
Reviewed-by on v6 12/29
#34 lore raw

Re: [Qemu-devel] [PATCH v6 12/29] libqos: Track QTestState with QPCIBus

Hi Eric,

Quoted 197 lines · Eric Blake

When initializing a QPCIBus, track which QTestState the bus is associated with (so that a later patch can then explicitly use that test state for all communication on the bus, rather than blindly relying on global_qtest). Update the initialization functions to take another parameter, and update all callers to pass in state (for now, most callers get away with passing the current global_qtest as the current state, although this required fixing the order of initialization to ensure qtest_start() is called before qpci_init*() in rtl8139-test, and provided an opportunity to pass in the allocator in e1000e-test).

---
  tests/libqos/ahci.h       | 2 +-
  tests/libqos/libqos.h     | 2 +-
  tests/libqos/pci-pc.h     | 2 +-
  tests/libqos/pci-spapr.h  | 2 +-
  tests/libqos/pci.h        | 1 +
  tests/ahci-test.c         | 2 +-
  tests/e1000e-test.c       | 6 +++---
  tests/i440fx-test.c       | 2 +-
  tests/ide-test.c          | 2 +-
  tests/libqos/ahci.c       | 4 ++--
  tests/libqos/libqos.c     | 4 ++--
  tests/libqos/pci-pc.c     | 5 ++++-
  tests/libqos/pci-spapr.c  | 6 +++++-
  tests/q35-test.c          | 4 ++--
  tests/rtl8139-test.c      | 5 +++--
  tests/tco-test.c          | 2 +-
  tests/usb-hcd-ehci-test.c | 2 +-
  tests/vhost-user-test.c   | 4 ++--
  18 files changed, 33 insertions(+), 24 deletions(-)
tests/libqos/ahci.h +1 -1
index 5f9627bb0f..715ca1e226 100644
@@ -571,7 +571,7 @@ void ahci_free(AHCIQState *ahci, uint64_t addr);
  void ahci_clean_mem(AHCIQState *ahci);
 
  /* Device management */
-QPCIDevice *get_ahci_device(uint32_t *fingerprint);
+QPCIDevice *get_ahci_device(QTestState *qts, uint32_t *fingerprint);
  void free_ahci_device(QPCIDevice *dev);
  void ahci_pci_enable(AHCIQState *ahci);
  void start_ahci_device(AHCIQState *ahci);
tests/libqos/libqos.h +1 -1
index 231969766f..78e5c044a0 100644
@@ -10,7 +10,7 @@ typedef struct QOSState QOSState;
  typedef struct QOSOps {
      QGuestAllocator *(*init_allocator)(QAllocOpts);
      void (*uninit_allocator)(QGuestAllocator *);
-    QPCIBus *(*qpci_init)(QGuestAllocator *alloc);
+    QPCIBus *(*qpci_init)(QTestState *qts, QGuestAllocator *alloc);
      void (*qpci_free)(QPCIBus *bus);
      void (*shutdown)(QOSState *);
  } QOSOps;
tests/libqos/pci-pc.h +1 -1
index 9479b51642..491eeac756 100644
@@ -16,7 +16,7 @@
  #include "libqos/pci.h"
  #include "libqos/malloc.h"
 
-QPCIBus *qpci_init_pc(QGuestAllocator *alloc);
+QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc);
  void     qpci_free_pc(QPCIBus *bus);
 
  #endif
tests/libqos/pci-spapr.h +1 -1
index 4192126d86..387686dfc8 100644
@@ -11,7 +11,7 @@
  #include "libqos/malloc.h"
  #include "libqos/pci.h"
 
-QPCIBus *qpci_init_spapr(QGuestAllocator *alloc);
+QPCIBus *qpci_init_spapr(QTestState *qts, QGuestAllocator *alloc);
  void     qpci_free_spapr(QPCIBus *bus);
 
  #endif
tests/libqos/pci.h +1 -0
index ed480614ff..429c382282 100644
@@ -48,6 +48,7 @@ struct QPCIBus {
      void (*config_writel)(QPCIBus *bus, int devfn,
                            uint8_t offset, uint32_t value);
 
+    QTestState *qts;
      uint16_t pio_alloc_ptr;
      uint64_t mmio_alloc_ptr, mmio_limit;
  };
tests/ahci-test.c +1 -1
index 999121bb7c..c94d1bd712 100644
@@ -160,7 +160,7 @@ static AHCIQState *ahci_vboot(const char *cli, va_list ap)
      alloc_set_flags(s->parent->alloc, ALLOC_LEAK_ASSERT);
 
      /* Verify that we have an AHCI device present. */
-    s->dev = get_ahci_device(&s->fingerprint);
+    s->dev = get_ahci_device(s->parent->qts, &s->fingerprint);
 
      return s;
  }
tests/e1000e-test.c +3 -3
index c612dc64ec..d8085d944e 100644
@@ -392,12 +392,12 @@ static void data_test_init(e1000e_device *d)
      qtest_start(cmdline);
      g_free(cmdline);
 
-    test_bus = qpci_init_pc(NULL);
-    g_assert_nonnull(test_bus);
-
      test_alloc = pc_alloc_init();
      g_assert_nonnull(test_alloc);
 
+    test_bus = qpci_init_pc(global_qtest, test_alloc);
+    g_assert_nonnull(test_bus);
+
      e1000e_device_init(test_bus, d);
  }
 
tests/i440fx-test.c +1 -1
index e9d05c87d1..4390e5591e 100644
@@ -38,7 +38,7 @@ static QPCIBus *test_start_get_bus(const TestData *s)
      cmdline = g_strdup_printf("-smp %d", s->num_cpus);
      qtest_start(cmdline);
      g_free(cmdline);
-    return qpci_init_pc(NULL);
+    return qpci_init_pc(global_qtest, NULL);
  }
 
  static void test_i440fx_defaults(gconstpointer opaque)
tests/ide-test.c +1 -1
index aa9de065fc..b2237b6158 100644
@@ -143,7 +143,7 @@ static QPCIDevice *get_pci_device(QPCIBar *bmdma_bar, QPCIBar *ide_bar)
      uint16_t vendor_id, device_id;
 
      if (!pcibus) {
-        pcibus = qpci_init_pc(NULL);
+        pcibus = qpci_init_pc(global_qtest, NULL);
      }
 
      /* Find PCI device and verify it's the right one */
tests/libqos/ahci.c +2 -2
index 1ca7f456b5..790ef991b3 100644
@@ -123,13 +123,13 @@ bool is_atapi(AHCIQState *ahci, uint8_t port)
  /**
   * Locate, verify, and return a handle to the AHCI device.
   */
-QPCIDevice *get_ahci_device(uint32_t *fingerprint)
+QPCIDevice *get_ahci_device(QTestState *qts, uint32_t *fingerprint)
  {
      QPCIDevice *ahci;
      uint32_t ahci_fingerprint;
      QPCIBus *pcibus;
 
-    pcibus = qpci_init_pc(NULL);
+    pcibus = qpci_init_pc(qts, NULL);
 
      /* Find the AHCI PCI device and verify it's the right one. */
      ahci = qpci_device_find(pcibus, QPCI_DEVFN(0x1F, 0x02));
tests/libqos/libqos.c +2 -2
index 6226546c28..c95428e1cb 100644
@@ -26,8 +26,8 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
          if (ops->init_allocator) {
              qs->alloc = ops->init_allocator(ALLOC_NO_FLAGS);
          }
-        if (ops->qpci_init && qs->alloc) {
-            qs->pcibus = ops->qpci_init(qs->alloc);
+        if (ops->qpci_init) {
+            qs->pcibus = ops->qpci_init(qs->qts, qs->alloc);
          }
      }
 
tests/libqos/pci-pc.c +0 -0
index 02ce49927a..85b34c6d13 100644
@@ -115,11 +115,14 @@ static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3
      outl(0xcfc, value);

tests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 124

Quoted 10 lines
tests/libqos/pci-pc.c +3 -1
  }
 
-QPCIBus *qpci_init_pc(QGuestAllocator *alloc)
+QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc)
  {
      QPCIBusPC *ret;
 
+    assert(qts);
+
      ret = g_malloc(sizeof(*ret));

I'd rather use g_malloc0() here (safer!)

tests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 128

Quoted 4 lines
tests/libqos/pci-pc.c +1 -0
+    ret->bus.qts = qts;
 
      ret->bus.pio_readb = qpci_pc_pio_readb;
      ret->bus.pio_readw = qpci_pc_pio_readw;

or init qts field in same order than struct:

...

        ret->bus.config_writel = qpci_pc_config_writel;

+ ret->bus.qts = qts;

        ret->bus.pio_alloc_ptr = 0xc000;

...

Quoted 7 lines
tests/libqos/pci-spapr.c +0 -0
index 2043f1e123..cd9b8f52d2 100644
@@ -154,11 +154,14 @@ static void qpci_spapr_config_writel(QPCIBus *bus, int devfn, uint8_t offset,
  #define SPAPR_PCI_MMIO32_WIN_SIZE    0x80000000 /* 2 GiB */
  #define SPAPR_PCI_IO_WIN_SIZE        0x10000

tests/libqos/pci-spapr.c static void qpci_spapr_config_writel(QPCIBus *bus, int devfn, uint8_t offset, · line 164

Quoted 10 lines
tests/libqos/pci-spapr.c +4 -1
 
-QPCIBus *qpci_init_spapr(QGuestAllocator *alloc)
+QPCIBus *qpci_init_spapr(QTestState *qts, QGuestAllocator *alloc)
  {
      QPCIBusSPAPR *ret;
 
+    assert(qts);
+
      ret = g_malloc(sizeof(*ret));
+    ret->bus.qts = qts;

same

Either ways:

Quoted 109 lines
tests/libqos/pci-spapr.c +1 -0
      ret->alloc = alloc;
 
@@ -201,6 +204,7 @@ QPCIBus *qpci_init_spapr(QGuestAllocator *alloc)
      ret->bus.mmio_alloc_ptr = ret->mmio32.pci_base;
      ret->bus.mmio_limit = ret->mmio32.pci_base + ret->mmio32.size;
 
+
      return &ret->bus;
  }
 
tests/q35-test.c +2 -2
index f98bed7a2d..e149c4c51d 100644
@@ -86,7 +86,7 @@ static void test_smram_lock(void)
 
      qtest_start("-M q35");
 
-    pcibus = qpci_init_pc(NULL);
+    pcibus = qpci_init_pc(global_qtest, NULL);
      g_assert(pcibus != NULL);
 
      pcidev = qpci_device_find(pcibus, 0);
@@ -145,7 +145,7 @@ static void test_tseg_size(const void *data)
      g_free(cmdline);
 
      /* locate the DRAM controller */
-    pcibus = qpci_init_pc(NULL);
+    pcibus = qpci_init_pc(global_qtest, NULL);
      g_assert(pcibus != NULL);
      pcidev = qpci_device_find(pcibus, 0);
      g_assert(pcidev != NULL);
tests/rtl8139-test.c +3 -2
index 7de7dc45ae..68bfc42178 100644
@@ -35,7 +35,7 @@ static QPCIDevice *get_device(void)
  {
      QPCIDevice *dev;
 
-    pcibus = qpci_init_pc(NULL);
+    pcibus = qpci_init_pc(global_qtest, NULL);
      qpci_device_foreach(pcibus, 0x10ec, 0x8139, save_fn, &dev);
      g_assert(dev != NULL);
 
@@ -197,11 +197,12 @@ int main(int argc, char **argv)
  {
      int ret;
 
+    qtest_start("-device rtl8139");
+
      g_test_init(&argc, &argv, NULL);
      qtest_add_func("/rtl8139/nop", nop);
      qtest_add_func("/rtl8139/timer", test_init);
 
-    qtest_start("-device rtl8139");
      ret = g_test_run();
 
      qtest_end();
tests/tco-test.c +1 -1
index f2ed6ed91c..0387971953 100644
@@ -64,7 +64,7 @@ static void test_init(TestData *d)
      qtest_irq_intercept_in(qs, "ioapic");
      g_free(s);
 
-    d->bus = qpci_init_pc(NULL);
+    d->bus = qpci_init_pc(qs, NULL);
      d->dev = qpci_device_find(d->bus, QPCI_DEVFN(0x1f, 0x00));
      g_assert(d->dev != NULL);
 
tests/usb-hcd-ehci-test.c +1 -1
index 944eb1c088..55d4743a2a 100644
@@ -52,7 +52,7 @@ static void ehci_port_test(struct qhc *hc, int port, uint32_t expect)
 
  static void test_init(void)
  {
-    pcibus = qpci_init_pc(NULL);
+    pcibus = qpci_init_pc(global_qtest, NULL);
      g_assert(pcibus != NULL);
 
      qusb_pci_init_one(pcibus, &uhci1, QPCI_DEVFN(0x1d, 0), 4);
tests/vhost-user-test.c +2 -2
index d4da09f147..ea7d38ea44 100644
@@ -164,7 +164,7 @@ static void init_virtio_dev(TestServer *s)
      QVirtioPCIDevice *dev;
      uint32_t features;
 
-    s->bus = qpci_init_pc(NULL);
+    s->bus = qpci_init_pc(global_qtest, NULL);
      g_assert_nonnull(s->bus);
 
      dev = qvirtio_pci_device_find(s->bus, VIRTIO_ID_NET);
@@ -891,7 +891,7 @@ static void test_multiqueue(void)
      qtest_start(cmd);
      g_free(cmd);
 
-    bus = qpci_init_pc(NULL);
+    bus = qpci_init_pc(global_qtest, NULL);
      dev = virtio_net_pci_init(bus, PCI_SLOT);
 
      alloc = pc_alloc_init();
author
#35 lore raw

Re: [Qemu-devel] [PATCH v6 12/29] libqos: Track QTestState with QPCIBus

Quoted 26 lines · Philippe Mathieu-Daudé

Hi Eric,

Quoted 23 lines · Eric Blake

When initializing a QPCIBus, track which QTestState the bus is associated with (so that a later patch can then explicitly use that test state for all communication on the bus, rather than blindly relying on global_qtest).  Update the initialization functions to take another parameter, and update all callers to pass in state (for now, most callers get away with passing the current global_qtest as the current state, although this required fixing the order of initialization to ensure qtest_start() is called before qpci_init*() in rtl8139-test, and provided an opportunity to pass in the allocator in e1000e-test).

+++ b/tests/libqos/pci-pc.c

(quoted diff) +0 -0
@@ -115,11 +115,14 @@ static void qpci_pc_config_writel(QPCIBus *bus,

int devfn, uint8_t offset, uint3
      outl(0xcfc, value);
  }

tests/libqos/pci-pc.c +1 -1
-QPCIBus *qpci_init_pc(QGuestAllocator *alloc)
+QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc)

  {
      QPCIBusPC *ret;

Quoted 5 lines
Quoted 3 lines

+    assert(qts);
+
      ret = g_malloc(sizeof(*ret));

I'd rather use g_malloc0() here (safer!)

Pre-existing, but yes, I can touch it while in the area.

Quoted 7 lines
Quoted 5 lines

+    ret->bus.qts = qts;

      ret->bus.pio_readb = qpci_pc_pio_readb;
      ret->bus.pio_readw = qpci_pc_pio_readw;

or init qts field in same order than struct:

Okay.

Quoted 4 lines

Either ways:

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v6 12/29
#36 lore raw

Re: [Qemu-devel] [PATCH v6 12/29] libqos: Track QTestState with QPCIBus

In reply to Eric Blake
Quoted 11 lines · Eric Blake

When initializing a QPCIBus, track which QTestState the bus is associated with (so that a later patch can then explicitly use that test state for all communication on the bus, rather than blindly relying on global_qtest). Update the initialization functions to take another parameter, and update all callers to pass in state (for now, most callers get away with passing the current global_qtest as the current state, although this required fixing the order of initialization to ensure qtest_start() is called before qpci_init*() in rtl8139-test, and provided an opportunity to pass in the allocator in e1000e-test).

Quoted 1 line
#37 lore raw

Re: [Qemu-devel] [PATCH v6 12/29] libqos: Track QTestState with QPCIBus

In reply to Eric Blake
Quoted 13 lines · Eric Blake

When initializing a QPCIBus, track which QTestState the bus is associated with (so that a later patch can then explicitly use that test state for all communication on the bus, rather than blindly relying on global_qtest). Update the initialization functions to take another parameter, and update all callers to pass in state (for now, most callers get away with passing the current global_qtest as the current state, although this required fixing the order of initialization to ensure qtest_start() is called before qpci_init*() in rtl8139-test, and provided an opportunity to pass in the allocator in e1000e-test).

---

[...]

tests/libqos/libqos.c QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap) · line 29

Quoted 11 lines
tests/libqos/libqos.c +1 -2
index 6226546c28..c95428e1cb 100644
@@ -26,8 +26,8 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
         if (ops->init_allocator) {
             qs->alloc = ops->init_allocator(ALLOC_NO_FLAGS);
         }
-        if (ops->qpci_init && qs->alloc) {
-            qs->pcibus = ops->qpci_init(qs->alloc);
+        if (ops->qpci_init) {

Why did you remove the check for qs->alloc?

Quoted 30 lines
tests/libqos/libqos.c +1 -0
+            qs->pcibus = ops->qpci_init(qs->qts, qs->alloc);
         }
     }
 
tests/libqos/pci-pc.c +4 -1
index 02ce49927a..85b34c6d13 100644
@@ -115,11 +115,14 @@ static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3
     outl(0xcfc, value);
 }
 
-QPCIBus *qpci_init_pc(QGuestAllocator *alloc)
+QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc)
 {
     QPCIBusPC *ret;
 
+    assert(qts);
+
     ret = g_malloc(sizeof(*ret));
+    ret->bus.qts = qts;
 
     ret->bus.pio_readb = qpci_pc_pio_readb;
     ret->bus.pio_readw = qpci_pc_pio_readw;
tests/libqos/pci-spapr.c +0 -0
index 2043f1e123..cd9b8f52d2 100644
@@ -154,11 +154,14 @@ static void qpci_spapr_config_writel(QPCIBus *bus, int devfn, uint8_t offset,
 #define SPAPR_PCI_MMIO32_WIN_SIZE    0x80000000 /* 2 GiB */

tests/libqos/pci-spapr.c static void qpci_spapr_config_writel(QPCIBus *bus, int devfn, uint8_t offset, · line 163

Quoted 10 lines
tests/libqos/pci-spapr.c +3 -1
 #define SPAPR_PCI_IO_WIN_SIZE        0x10000
 
-QPCIBus *qpci_init_spapr(QGuestAllocator *alloc)
+QPCIBus *qpci_init_spapr(QTestState *qts, QGuestAllocator *alloc)
 {
     QPCIBusSPAPR *ret;
 
+    assert(qts);
+
     ret = g_malloc(sizeof(*ret));

+1 for using g_malloc0 here instead.

tests/libqos/pci-spapr.c QPCIBus *qpci_init_spapr(QGuestAllocator *alloc) · line 207

Quoted 9 lines
tests/libqos/pci-spapr.c +2 -0
+    ret->bus.qts = qts;
 
     ret->alloc = alloc;
 
@@ -201,6 +204,7 @@ QPCIBus *qpci_init_spapr(QGuestAllocator *alloc)
     ret->bus.mmio_alloc_ptr = ret->mmio32.pci_base;
     ret->bus.mmio_limit = ret->mmio32.pci_base + ret->mmio32.size;
 
+

Superfluous white space change.

tests/libqos/pci-spapr.c QPCIBus *qpci_init_spapr(QGuestAllocator *alloc) · line 209

Quoted 2 lines
tests/libqos/pci-spapr.c +0 -0
     return &ret->bus;
 }

Thomas

author
#38 lore raw

Re: [Qemu-devel] [PATCH v6 12/29] libqos: Track QTestState with QPCIBus

Quoted 15 lines · Thomas Huth
Quoted 13 lines · Eric Blake

When initializing a QPCIBus, track which QTestState the bus is associated with (so that a later patch can then explicitly use that test state for all communication on the bus, rather than blindly relying on global_qtest). Update the initialization functions to take another parameter, and update all callers to pass in state (for now, most callers get away with passing the current global_qtest as the current state, although this required fixing the order of initialization to ensure qtest_start() is called before qpci_init*() in rtl8139-test, and provided an opportunity to pass in the allocator in e1000e-test).

---

[...]

Quoted 15 lines

tests/libqos/libqos.c QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap) · line 29

Quoted 11 lines
tests/libqos/libqos.c +1 -2
index 6226546c28..c95428e1cb 100644
@@ -26,8 +26,8 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
         if (ops->init_allocator) {
             qs->alloc = ops->init_allocator(ALLOC_NO_FLAGS);
         }
-        if (ops->qpci_init && qs->alloc) {
-            qs->pcibus = ops->qpci_init(qs->alloc);
+        if (ops->qpci_init) {

Why did you remove the check for qs->alloc?

Quoted 1 line
tests/libqos/libqos.c +1 -0
+            qs->pcibus = ops->qpci_init(qs->qts, qs->alloc);

Because we want to ensure qpci_init() is called to set qs->qts (presumably, whether or not qs->alloc is set). Furthermore, only two files declare a 'static QOSOps' structure in the first place (libqos-pc.c and libqos-spapr.c); where both files set both the .init_allocator and .qpci_init callbacks; a little bit of auditing shows that the .init_allocator() never returns NULL (although that requires browsing yet more files for malloc-{pc,spapr}.c).

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#39 lore raw

Re: [Qemu-devel] [PATCH v6 12/29] libqos: Track QTestState with QPCIBus

Quoted 32 lines · Eric Blake
Quoted 15 lines · Thomas Huth
Quoted 13 lines · Eric Blake

When initializing a QPCIBus, track which QTestState the bus is associated with (so that a later patch can then explicitly use that test state for all communication on the bus, rather than blindly relying on global_qtest). Update the initialization functions to take another parameter, and update all callers to pass in state (for now, most callers get away with passing the current global_qtest as the current state, although this required fixing the order of initialization to ensure qtest_start() is called before qpci_init*() in rtl8139-test, and provided an opportunity to pass in the allocator in e1000e-test).

---

[...]

Quoted 15 lines

tests/libqos/libqos.c QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap) · line 29

Quoted 11 lines
tests/libqos/libqos.c +1 -2
index 6226546c28..c95428e1cb 100644
@@ -26,8 +26,8 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
         if (ops->init_allocator) {
             qs->alloc = ops->init_allocator(ALLOC_NO_FLAGS);
         }
-        if (ops->qpci_init && qs->alloc) {
-            qs->pcibus = ops->qpci_init(qs->alloc);
+        if (ops->qpci_init) {

Why did you remove the check for qs->alloc?

Quoted 1 line
tests/libqos/libqos.c +1 -0
+            qs->pcibus = ops->qpci_init(qs->qts, qs->alloc);
Quoted 7 lines

Because we want to ensure qpci_init() is called to set qs->qts (presumably, whether or not qs->alloc is set). Furthermore, only two files declare a 'static QOSOps' structure in the first place (libqos-pc.c and libqos-spapr.c); where both files set both the .init_allocator and .qpci_init callbacks; a little bit of auditing shows that the .init_allocator() never returns NULL (although that requires browsing yet more files for malloc-{pc,spapr}.c).

OK, thanks for the explanation! ... but maybe we should g_assert(gs->alloc) somewhere instead? ... just an idea, I'm also fine if you leave it away.

Thomas

author
#40 lore raw

Re: [Qemu-devel] [PATCH v6 12/29] libqos: Track QTestState with QPCIBus

Quoted 28 lines · Thomas Huth
Quoted 19 lines · Eric Blake
Quoted 14 lines · Thomas Huth
Quoted 11 lines · Eric Blake

When initializing a QPCIBus, track which QTestState the bus is associated with (so that a later patch can then explicitly use that test state for all communication on the bus, rather than blindly relying on global_qtest). Update the initialization functions to take another parameter, and update all callers to pass in state (for now, most callers get away with passing the current global_qtest as the current state, although this required fixing the order of initialization to ensure qtest_start() is called before qpci_init*() in rtl8139-test, and provided an opportunity to pass in the allocator in e1000e-test).

Quoted 3 lines

Why did you remove the check for qs->alloc?

Quoted 1 line

+ qs->pcibus = ops->qpci_init(qs->qts, qs->alloc);

Quoted 7 lines

Because we want to ensure qpci_init() is called to set qs->qts (presumably, whether or not qs->alloc is set). Furthermore, only two files declare a 'static QOSOps' structure in the first place (libqos-pc.c and libqos-spapr.c); where both files set both the .init_allocator and .qpci_init callbacks; a little bit of auditing shows that the .init_allocator() never returns NULL (although that requires browsing yet more files for malloc-{pc,spapr}.c).

Quoted 3 lines

OK, thanks for the explanation! ... but maybe we should g_assert(gs->alloc) somewhere instead? ... just an idea, I'm also fine if you leave it away.

Users of QOSOps always supply qs->alloc, but there are tests that successfully use NULL for qs->alloc (because they did not go through QOSOps). At any rate, I can certainly update the commit message.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
author
#41 lore raw

PATCH v6 13/29 libqos: Use explicit QTestState for pci operations

In reply to Eric Blake

Now that the QPCIBus tracks QTestState, use that state instead of an implicit reliance on global_qtest.

---
 tests/libqos/pci-pc.c    | 47 ++++++++++++++++++++++++-----------------------
 tests/libqos/pci-spapr.c | 20 ++++++++++----------
 2 files changed, 34 insertions(+), 33 deletions(-)
tests/libqos/pci-pc.c +24 -23
index 85b34c6d13..9545f881ee 100644
@@ -29,90 +29,91 @@ typedef struct QPCIBusPC
 
 static uint8_t qpci_pc_pio_readb(QPCIBus *bus, uint32_t addr)
 {
-    return inb(addr);
+    return qtest_inb(bus->qts, addr);
 }
 
 static void qpci_pc_pio_writeb(QPCIBus *bus, uint32_t addr, uint8_t val)
 {
-    outb(addr, val);
+    qtest_outb(bus->qts, addr, val);
 }
 
 static uint16_t qpci_pc_pio_readw(QPCIBus *bus, uint32_t addr)
 {
-    return inw(addr);
+    return qtest_inw(bus->qts, addr);
 }
 
 static void qpci_pc_pio_writew(QPCIBus *bus, uint32_t addr, uint16_t val)
 {
-    outw(addr, val);
+    qtest_outw(bus->qts, addr, val);
 }
 
 static uint32_t qpci_pc_pio_readl(QPCIBus *bus, uint32_t addr)
 {
-    return inl(addr);
+    return qtest_inl(bus->qts, addr);
 }
 
 static void qpci_pc_pio_writel(QPCIBus *bus, uint32_t addr, uint32_t val)
 {
-    outl(addr, val);
+    qtest_outl(bus->qts, addr, val);
 }
 
 static uint64_t qpci_pc_pio_readq(QPCIBus *bus, uint32_t addr)
 {
-    return (uint64_t)inl(addr) + ((uint64_t)inl(addr + 4) << 32);
+    return (uint64_t)qtest_inl(bus->qts, addr) +
+        ((uint64_t)qtest_inl(bus->qts, addr + 4) << 32);
 }
 
 static void qpci_pc_pio_writeq(QPCIBus *bus, uint32_t addr, uint64_t val)
 {
-    outl(addr, val & 0xffffffff);
-    outl(addr + 4, val >> 32);
+    qtest_outl(bus->qts, addr, val & 0xffffffff);
+    qtest_outl(bus->qts, addr + 4, val >> 32);
 }
 
 static void qpci_pc_memread(QPCIBus *bus, uint32_t addr, void *buf, size_t len)
 {
-    memread(addr, buf, len);
+    qtest_memread(bus->qts, addr, buf, len);
 }
 
 static void qpci_pc_memwrite(QPCIBus *bus, uint32_t addr,
                              const void *buf, size_t len)
 {
-    memwrite(addr, buf, len);
+    qtest_memwrite(bus->qts, addr, buf, len);
 }
 
 static uint8_t qpci_pc_config_readb(QPCIBus *bus, int devfn, uint8_t offset)
 {
-    outl(0xcf8, (1U << 31) | (devfn << 8) | offset);
-    return inb(0xcfc);
+    qtest_outl(bus->qts, 0xcf8, (1U << 31) | (devfn << 8) | offset);
+    return qtest_inb(bus->qts, 0xcfc);
 }
 
 static uint16_t qpci_pc_config_readw(QPCIBus *bus, int devfn, uint8_t offset)
 {
-    outl(0xcf8, (1U << 31) | (devfn << 8) | offset);
-    return inw(0xcfc);
+    qtest_outl(bus->qts, 0xcf8, (1U << 31) | (devfn << 8) | offset);
+    return qtest_inw(bus->qts, 0xcfc);
 }
 
 static uint32_t qpci_pc_config_readl(QPCIBus *bus, int devfn, uint8_t offset)
 {
-    outl(0xcf8, (1U << 31) | (devfn << 8) | offset);
-    return inl(0xcfc);
+    qtest_outl(bus->qts, 0xcf8, (1U << 31) | (devfn << 8) | offset);
+    return qtest_inl(bus->qts, 0xcfc);
 }
 
 static void qpci_pc_config_writeb(QPCIBus *bus, int devfn, uint8_t offset, uint8_t value)
 {
-    outl(0xcf8, (1U << 31) | (devfn << 8) | offset);
-    outb(0xcfc, value);
+    qtest_outl(bus->qts, 0xcf8, (1U << 31) | (devfn << 8) | offset);
+    qtest_outb(bus->qts, 0xcfc, value);
 }
 
 static void qpci_pc_config_writew(QPCIBus *bus, int devfn, uint8_t offset, uint16_t value)
 {
-    outl(0xcf8, (1U << 31) | (devfn << 8) | offset);
-    outw(0xcfc, value);
+    qtest_outl(bus->qts, 0xcf8, (1U << 31) | (devfn << 8) | offset);
+    qtest_outw(bus->qts, 0xcfc, value);
 }
 
 static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint32_t value)
 {
-    outl(0xcf8, (1U << 31) | (devfn << 8) | offset);
-    outl(0xcfc, value);
+    qtest_outl(bus->qts, 0xcf8, (1U << 31) | (devfn << 8) | offset);
+    qtest_outl(bus->qts, 0xcfc, value);
 }
 
 QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc)
tests/libqos/pci-spapr.c +10 -10
index cd9b8f52d2..d7b2aa75e6 100644
@@ -45,63 +45,63 @@ typedef struct QPCIBusSPAPR {
 static uint8_t qpci_spapr_pio_readb(QPCIBus *bus, uint32_t addr)
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    return readb(s->pio_cpu_base + addr);
+    return qtest_readb(bus->qts, s->pio_cpu_base + addr);
 }
 
 static void qpci_spapr_pio_writeb(QPCIBus *bus, uint32_t addr, uint8_t val)
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    writeb(s->pio_cpu_base + addr, val);
+    qtest_writeb(bus->qts, s->pio_cpu_base + addr, val);
 }
 
 static uint16_t qpci_spapr_pio_readw(QPCIBus *bus, uint32_t addr)
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    return bswap16(readw(s->pio_cpu_base + addr));
+    return bswap16(qtest_readw(bus->qts, s->pio_cpu_base + addr));
 }
 
 static void qpci_spapr_pio_writew(QPCIBus *bus, uint32_t addr, uint16_t val)
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    writew(s->pio_cpu_base + addr, bswap16(val));
+    qtest_writew(bus->qts, s->pio_cpu_base + addr, bswap16(val));
 }
 
 static uint32_t qpci_spapr_pio_readl(QPCIBus *bus, uint32_t addr)
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    return bswap32(readl(s->pio_cpu_base + addr));
+    return bswap32(qtest_readl(bus->qts, s->pio_cpu_base + addr));
 }
 
 static void qpci_spapr_pio_writel(QPCIBus *bus, uint32_t addr, uint32_t val)
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    writel(s->pio_cpu_base + addr, bswap32(val));
+    qtest_writel(bus->qts, s->pio_cpu_base + addr, bswap32(val));
 }
 
 static uint64_t qpci_spapr_pio_readq(QPCIBus *bus, uint32_t addr)
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    return bswap64(readq(s->pio_cpu_base + addr));
+    return bswap64(qtest_readq(bus->qts, s->pio_cpu_base + addr));
 }
 
 static void qpci_spapr_pio_writeq(QPCIBus *bus, uint32_t addr, uint64_t val)
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    writeq(s->pio_cpu_base + addr, bswap64(val));
+    qtest_writeq(bus->qts, s->pio_cpu_base + addr, bswap64(val));
 }
 
 static void qpci_spapr_memread(QPCIBus *bus, uint32_t addr,
                                void *buf, size_t len)
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    memread(s->mmio32_cpu_base + addr, buf, len);
+    qtest_memread(bus->qts, s->mmio32_cpu_base + addr, buf, len);
 }
 
 static void qpci_spapr_memwrite(QPCIBus *bus, uint32_t addr,
                                 const void *buf, size_t len)
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    memwrite(s->mmio32_cpu_base + addr, buf, len);
+    qtest_memwrite(bus->qts, s->mmio32_cpu_base + addr, buf, len);
 }
 
 static uint8_t qpci_spapr_config_readb(QPCIBus *bus, int devfn, uint8_t offset)
Signature · 1 line
2.13.5
Reviewed-by on v6 13/29
#42 lore raw

Re: [Qemu-devel] [PATCH v6 13/29] libqos: Use explicit QTestState for pci operations

Quoted 4 lines · Eric Blake

Now that the QPCIBus tracks QTestState, use that state instead of an implicit reliance on global_qtest.

Quoted 203 lines
---
  tests/libqos/pci-pc.c    | 47 ++++++++++++++++++++++++-----------------------
  tests/libqos/pci-spapr.c | 20 ++++++++++----------
  2 files changed, 34 insertions(+), 33 deletions(-)
tests/libqos/pci-pc.c +24 -23
index 85b34c6d13..9545f881ee 100644
@@ -29,90 +29,91 @@ typedef struct QPCIBusPC
 
  static uint8_t qpci_pc_pio_readb(QPCIBus *bus, uint32_t addr)
  {
-    return inb(addr);
+    return qtest_inb(bus->qts, addr);
  }
 
  static void qpci_pc_pio_writeb(QPCIBus *bus, uint32_t addr, uint8_t val)
  {
-    outb(addr, val);
+    qtest_outb(bus->qts, addr, val);
  }
 
  static uint16_t qpci_pc_pio_readw(QPCIBus *bus, uint32_t addr)
  {
-    return inw(addr);
+    return qtest_inw(bus->qts, addr);
  }
 
  static void qpci_pc_pio_writew(QPCIBus *bus, uint32_t addr, uint16_t val)
  {
-    outw(addr, val);
+    qtest_outw(bus->qts, addr, val);
  }
 
  static uint32_t qpci_pc_pio_readl(QPCIBus *bus, uint32_t addr)
  {
-    return inl(addr);
+    return qtest_inl(bus->qts, addr);
  }
 
  static void qpci_pc_pio_writel(QPCIBus *bus, uint32_t addr, uint32_t val)
  {
-    outl(addr, val);
+    qtest_outl(bus->qts, addr, val);
  }
 
  static uint64_t qpci_pc_pio_readq(QPCIBus *bus, uint32_t addr)
  {
-    return (uint64_t)inl(addr) + ((uint64_t)inl(addr + 4) << 32);
+    return (uint64_t)qtest_inl(bus->qts, addr) +
+        ((uint64_t)qtest_inl(bus->qts, addr + 4) << 32);
  }
 
  static void qpci_pc_pio_writeq(QPCIBus *bus, uint32_t addr, uint64_t val)
  {
-    outl(addr, val & 0xffffffff);
-    outl(addr + 4, val >> 32);
+    qtest_outl(bus->qts, addr, val & 0xffffffff);
+    qtest_outl(bus->qts, addr + 4, val >> 32);
  }
 
  static void qpci_pc_memread(QPCIBus *bus, uint32_t addr, void *buf, size_t len)
  {
-    memread(addr, buf, len);
+    qtest_memread(bus->qts, addr, buf, len);
  }
 
  static void qpci_pc_memwrite(QPCIBus *bus, uint32_t addr,
                               const void *buf, size_t len)
  {
-    memwrite(addr, buf, len);
+    qtest_memwrite(bus->qts, addr, buf, len);
  }
 
  static uint8_t qpci_pc_config_readb(QPCIBus *bus, int devfn, uint8_t offset)
  {
-    outl(0xcf8, (1U << 31) | (devfn << 8) | offset);
-    return inb(0xcfc);
+    qtest_outl(bus->qts, 0xcf8, (1U << 31) | (devfn << 8) | offset);
+    return qtest_inb(bus->qts, 0xcfc);
  }
 
  static uint16_t qpci_pc_config_readw(QPCIBus *bus, int devfn, uint8_t offset)
  {
-    outl(0xcf8, (1U << 31) | (devfn << 8) | offset);
-    return inw(0xcfc);
+    qtest_outl(bus->qts, 0xcf8, (1U << 31) | (devfn << 8) | offset);
+    return qtest_inw(bus->qts, 0xcfc);
  }
 
  static uint32_t qpci_pc_config_readl(QPCIBus *bus, int devfn, uint8_t offset)
  {
-    outl(0xcf8, (1U << 31) | (devfn << 8) | offset);
-    return inl(0xcfc);
+    qtest_outl(bus->qts, 0xcf8, (1U << 31) | (devfn << 8) | offset);
+    return qtest_inl(bus->qts, 0xcfc);
  }
 
  static void qpci_pc_config_writeb(QPCIBus *bus, int devfn, uint8_t offset, uint8_t value)
  {
-    outl(0xcf8, (1U << 31) | (devfn << 8) | offset);
-    outb(0xcfc, value);
+    qtest_outl(bus->qts, 0xcf8, (1U << 31) | (devfn << 8) | offset);
+    qtest_outb(bus->qts, 0xcfc, value);
  }
 
  static void qpci_pc_config_writew(QPCIBus *bus, int devfn, uint8_t offset, uint16_t value)
  {
-    outl(0xcf8, (1U << 31) | (devfn << 8) | offset);
-    outw(0xcfc, value);
+    qtest_outl(bus->qts, 0xcf8, (1U << 31) | (devfn << 8) | offset);
+    qtest_outw(bus->qts, 0xcfc, value);
  }
 
  static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint32_t value)
  {
-    outl(0xcf8, (1U << 31) | (devfn << 8) | offset);
-    outl(0xcfc, value);
+    qtest_outl(bus->qts, 0xcf8, (1U << 31) | (devfn << 8) | offset);
+    qtest_outl(bus->qts, 0xcfc, value);
  }
 
  QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc)
tests/libqos/pci-spapr.c +10 -10
index cd9b8f52d2..d7b2aa75e6 100644
@@ -45,63 +45,63 @@ typedef struct QPCIBusSPAPR {
  static uint8_t qpci_spapr_pio_readb(QPCIBus *bus, uint32_t addr)
  {
      QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    return readb(s->pio_cpu_base + addr);
+    return qtest_readb(bus->qts, s->pio_cpu_base + addr);
  }
 
  static void qpci_spapr_pio_writeb(QPCIBus *bus, uint32_t addr, uint8_t val)
  {
      QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    writeb(s->pio_cpu_base + addr, val);
+    qtest_writeb(bus->qts, s->pio_cpu_base + addr, val);
  }
 
  static uint16_t qpci_spapr_pio_readw(QPCIBus *bus, uint32_t addr)
  {
      QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    return bswap16(readw(s->pio_cpu_base + addr));
+    return bswap16(qtest_readw(bus->qts, s->pio_cpu_base + addr));
  }
 
  static void qpci_spapr_pio_writew(QPCIBus *bus, uint32_t addr, uint16_t val)
  {
      QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    writew(s->pio_cpu_base + addr, bswap16(val));
+    qtest_writew(bus->qts, s->pio_cpu_base + addr, bswap16(val));
  }
 
  static uint32_t qpci_spapr_pio_readl(QPCIBus *bus, uint32_t addr)
  {
      QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    return bswap32(readl(s->pio_cpu_base + addr));
+    return bswap32(qtest_readl(bus->qts, s->pio_cpu_base + addr));
  }
 
  static void qpci_spapr_pio_writel(QPCIBus *bus, uint32_t addr, uint32_t val)
  {
      QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    writel(s->pio_cpu_base + addr, bswap32(val));
+    qtest_writel(bus->qts, s->pio_cpu_base + addr, bswap32(val));
  }
 
  static uint64_t qpci_spapr_pio_readq(QPCIBus *bus, uint32_t addr)
  {
      QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    return bswap64(readq(s->pio_cpu_base + addr));
+    return bswap64(qtest_readq(bus->qts, s->pio_cpu_base + addr));
  }
 
  static void qpci_spapr_pio_writeq(QPCIBus *bus, uint32_t addr, uint64_t val)
  {
      QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    writeq(s->pio_cpu_base + addr, bswap64(val));
+    qtest_writeq(bus->qts, s->pio_cpu_base + addr, bswap64(val));
  }
 
  static void qpci_spapr_memread(QPCIBus *bus, uint32_t addr,
                                 void *buf, size_t len)
  {
      QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    memread(s->mmio32_cpu_base + addr, buf, len);
+    qtest_memread(bus->qts, s->mmio32_cpu_base + addr, buf, len);
  }
 
  static void qpci_spapr_memwrite(QPCIBus *bus, uint32_t addr,
                                  const void *buf, size_t len)
  {
      QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
-    memwrite(s->mmio32_cpu_base + addr, buf, len);
+    qtest_memwrite(bus->qts, s->mmio32_cpu_base + addr, buf, len);
  }
 
  static uint8_t qpci_spapr_config_readb(QPCIBus *bus, int devfn, uint8_t offset)
Reviewed-by on v6 13/29
#43 lore raw

Re: [Qemu-devel] [PATCH v6 13/29] libqos: Use explicit QTestState for pci operations

In reply to Eric Blake
Quoted 8 lines · Eric Blake

Now that the QPCIBus tracks QTestState, use that state instead of an implicit reliance on global_qtest.

---
 tests/libqos/pci-pc.c    | 47 ++++++++++++++++++++++++-----------------------
 tests/libqos/pci-spapr.c | 20 ++++++++++----------
 2 files changed, 34 insertions(+), 33 deletions(-)
author
#44 lore raw

PATCH v6 14/29 libqos: Use explicit QTestState for fw_cfg operations

In reply to Eric Blake

Drop one more client of global_qtest by teaching all fw_cfg test functionality (invoked through alloc-pc) to pass in an explicit QTestState, adjusting all callers. In particular, fw_cfg-test had to reorder things to create the test state prior to creating the fw_cfg.

---
 tests/libqos/fw_cfg.h       | 10 ++++++----
 tests/libqos/libqos.h       |  2 +-
 tests/libqos/malloc-pc.h    |  4 ++--
 tests/libqos/malloc-spapr.h |  2 +-
 tests/libqos/malloc.h       |  1 +
 tests/boot-order-test.c     |  6 +++---
 tests/e1000e-test.c         |  2 +-
 tests/fw_cfg-test.c         | 14 ++++++--------
 tests/ide-test.c            |  2 +-
 tests/libqos/fw_cfg.c       | 14 ++++++++------
 tests/libqos/libqos.c       |  2 +-
 tests/libqos/malloc-pc.c    |  8 ++++----
 tests/libqos/malloc-spapr.c |  4 ++--
 tests/vhost-user-test.c     |  2 +-
 14 files changed, 38 insertions(+), 35 deletions(-)
tests/libqos/fw_cfg.h +6 -4
index e8371b2317..396dd4ee1e 100644
@@ -15,10 +15,12 @@
 
 
 typedef struct QFWCFG QFWCFG;
+typedef struct QTestState QTestState;
 
 struct QFWCFG
 {
     uint64_t base;
+    QTestState *qts;
     void (*select)(QFWCFG *fw_cfg, uint16_t key);
     void (*read)(QFWCFG *fw_cfg, void *data, size_t len);
 };
@@ -30,12 +32,12 @@ uint16_t qfw_cfg_get_u16(QFWCFG *fw_cfg, uint16_t key);
 uint32_t qfw_cfg_get_u32(QFWCFG *fw_cfg, uint16_t key);
 uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key);
 
-QFWCFG *mm_fw_cfg_init(uint64_t base);
-QFWCFG *io_fw_cfg_init(uint16_t base);
+QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base);
+QFWCFG *io_fw_cfg_init(QTestState *qts, uint16_t base);
 
-static inline QFWCFG *pc_fw_cfg_init(void)
+static inline QFWCFG *pc_fw_cfg_init(QTestState *qts)
 {
-    return io_fw_cfg_init(0x510);
+    return io_fw_cfg_init(qts, 0x510);
 }
 
 #endif
tests/libqos/libqos.h +1 -1
index 78e5c044a0..07d4b93d1d 100644
@@ -8,7 +8,7 @@
 typedef struct QOSState QOSState;
 
 typedef struct QOSOps {
-    QGuestAllocator *(*init_allocator)(QAllocOpts);
+    QGuestAllocator *(*init_allocator)(QTestState *qts, QAllocOpts);
     void (*uninit_allocator)(QGuestAllocator *);
     QPCIBus *(*qpci_init)(QTestState *qts, QGuestAllocator *alloc);
     void (*qpci_free)(QPCIBus *bus);
tests/libqos/malloc-pc.h +2 -2
index 86ab9f0429..10f3da6cf2 100644
@@ -15,8 +15,8 @@
 
 #include "libqos/malloc.h"
 
-QGuestAllocator *pc_alloc_init(void);
-QGuestAllocator *pc_alloc_init_flags(QAllocOpts flags);
+QGuestAllocator *pc_alloc_init(QTestState *qts);
+QGuestAllocator *pc_alloc_init_flags(QTestState *qts, QAllocOpts flags);
 void pc_alloc_uninit(QGuestAllocator *allocator);
 
 #endif
tests/libqos/malloc-spapr.h +1 -1
index 64d0e770d1..52a9346a26 100644
@@ -11,7 +11,7 @@
 #include "libqos/malloc.h"
 
 QGuestAllocator *spapr_alloc_init(void);
-QGuestAllocator *spapr_alloc_init_flags(QAllocOpts flags);
+QGuestAllocator *spapr_alloc_init_flags(QTestState *qts, QAllocOpts flags);
 void spapr_alloc_uninit(QGuestAllocator *allocator);
 
 #endif
tests/libqos/malloc.h +1 -0
index ae9dac8f61..828fddabdb 100644
@@ -14,6 +14,7 @@
 #define LIBQOS_MALLOC_H
 
 #include "qemu/queue.h"
+#include "libqtest.h"
 
 typedef enum {
     ALLOC_NO_FLAGS    = 0x00,
tests/boot-order-test.c +3 -3
index 9d516830dd..5fc2ca8e9e 100644
@@ -135,7 +135,7 @@ static void test_prep_boot_order(void)
 
 static uint64_t read_boot_order_pmac(void)
 {
-    QFWCFG *fw_cfg = mm_fw_cfg_init(0xf0000510);
+    QFWCFG *fw_cfg = mm_fw_cfg_init(global_qtest, 0xf0000510);
 
     return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
 }
@@ -160,7 +160,7 @@ static void test_pmac_newworld_boot_order(void)
 
 static uint64_t read_boot_order_sun4m(void)
 {
-    QFWCFG *fw_cfg = mm_fw_cfg_init(0xd00000510ULL);
+    QFWCFG *fw_cfg = mm_fw_cfg_init(global_qtest, 0xd00000510ULL);
 
     return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
 }
@@ -172,7 +172,7 @@ static void test_sun4m_boot_order(void)
 
 static uint64_t read_boot_order_sun4u(void)
 {
-    QFWCFG *fw_cfg = io_fw_cfg_init(0x510);
+    QFWCFG *fw_cfg = io_fw_cfg_init(global_qtest, 0x510);
 
     return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
 }
tests/e1000e-test.c +1 -1
index d8085d944e..32aa738b72 100644
@@ -392,7 +392,7 @@ static void data_test_init(e1000e_device *d)
     qtest_start(cmdline);
     g_free(cmdline);
 
-    test_alloc = pc_alloc_init();
+    test_alloc = pc_alloc_init(global_qtest);
     g_assert_nonnull(test_alloc);
 
     test_bus = qpci_init_pc(global_qtest, test_alloc);
tests/fw_cfg-test.c +6 -8
index 688342bed5..47596c57a1 100644
@@ -107,7 +107,11 @@ int main(int argc, char **argv)
 
     g_test_init(&argc, &argv, NULL);
 
-    fw_cfg = pc_fw_cfg_init();
+    cmdline = g_strdup_printf("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8 ");
+    s = qtest_start(cmdline);
+    g_free(cmdline);
+
+    fw_cfg = pc_fw_cfg_init(s);
 
     qtest_add_func("fw_cfg/signature", test_fw_cfg_signature);
     qtest_add_func("fw_cfg/id", test_fw_cfg_id);
@@ -125,15 +129,9 @@ int main(int argc, char **argv)
     qtest_add_func("fw_cfg/numa", test_fw_cfg_numa);
     qtest_add_func("fw_cfg/boot_menu", test_fw_cfg_boot_menu);
 
-    cmdline = g_strdup_printf("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8 ");
-    s = qtest_start(cmdline);
-    g_free(cmdline);
-
     ret = g_test_run();
 
-    if (s) {
-        qtest_quit(s);
-    }
+    qtest_quit(s);
 
     return ret;
 }
tests/ide-test.c +1 -1
index b2237b6158..084f6a5f96 100644
@@ -125,7 +125,7 @@ static void ide_test_start(const char *cmdline_fmt, ...)
     va_end(ap);
 
     qtest_start(cmdline);
-    guest_malloc = pc_alloc_init();
+    guest_malloc = pc_alloc_init(global_qtest);
 
     g_free(cmdline);
 }
tests/libqos/fw_cfg.c +8 -6
index 4d9dc3fd0b..d0889d1e22 100644
@@ -56,7 +56,7 @@ uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key)
 
 static void mm_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
 {
-    writew(fw_cfg->base, key);
+    qtest_writew(fw_cfg->qts, fw_cfg->base, key);
 }
 
 static void mm_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
@@ -65,15 +65,16 @@ static void mm_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
     int i;
 
     for (i = 0; i < len; i++) {
-        ptr[i] = readb(fw_cfg->base + 2);
+        ptr[i] = qtest_readb(fw_cfg->qts, fw_cfg->base + 2);
     }
 }
 
-QFWCFG *mm_fw_cfg_init(uint64_t base)
+QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base)
 {
     QFWCFG *fw_cfg = g_malloc0(sizeof(*fw_cfg));
 
     fw_cfg->base = base;
+    fw_cfg->qts = qts;
     fw_cfg->select = mm_fw_cfg_select;
     fw_cfg->read = mm_fw_cfg_read;
 
@@ -82,7 +83,7 @@ QFWCFG *mm_fw_cfg_init(uint64_t base)
 
 static void io_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
 {
-    outw(fw_cfg->base, key);
+    qtest_outw(fw_cfg->qts, fw_cfg->base, key);
 }
 
 static void io_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
@@ -91,15 +92,16 @@ static void io_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
     int i;
 
     for (i = 0; i < len; i++) {
-        ptr[i] = inb(fw_cfg->base + 1);
+        ptr[i] = qtest_inb(fw_cfg->qts, fw_cfg->base + 1);
     }
 }
 
-QFWCFG *io_fw_cfg_init(uint16_t base)
+QFWCFG *io_fw_cfg_init(QTestState *qts, uint16_t base)
 {
     QFWCFG *fw_cfg = g_malloc0(sizeof(*fw_cfg));
 
     fw_cfg->base = base;
+    fw_cfg->qts = qts;
     fw_cfg->select = io_fw_cfg_select;
     fw_cfg->read = io_fw_cfg_read;
 
tests/libqos/libqos.c +1 -1
index c95428e1cb..62d2f39b93 100644
@@ -24,7 +24,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
     qs->ops = ops;
     if (ops) {
         if (ops->init_allocator) {
-            qs->alloc = ops->init_allocator(ALLOC_NO_FLAGS);
+            qs->alloc = ops->init_allocator(qs->qts, ALLOC_NO_FLAGS);
         }
         if (ops->qpci_init) {
             qs->pcibus = ops->qpci_init(qs->qts, qs->alloc);
tests/libqos/malloc-pc.c +4 -4
index dd2b900c5f..634b9c288a 100644
@@ -29,11 +29,11 @@ void pc_alloc_uninit(QGuestAllocator *allocator)
     alloc_uninit(allocator);
 }
 
-QGuestAllocator *pc_alloc_init_flags(QAllocOpts flags)
+QGuestAllocator *pc_alloc_init_flags(QTestState *qts, QAllocOpts flags)
 {
     QGuestAllocator *s;
     uint64_t ram_size;
-    QFWCFG *fw_cfg = pc_fw_cfg_init();
+    QFWCFG *fw_cfg = pc_fw_cfg_init(qts);
 
     ram_size = qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE);
     s = alloc_init_flags(flags, 1 << 20, MIN(ram_size, 0xE0000000));
@@ -45,7 +45,7 @@ QGuestAllocator *pc_alloc_init_flags(QAllocOpts flags)
     return s;
 }
 
-inline QGuestAllocator *pc_alloc_init(void)
+inline QGuestAllocator *pc_alloc_init(QTestState *qts)
 {
-    return pc_alloc_init_flags(ALLOC_NO_FLAGS);
+    return pc_alloc_init_flags(qts, ALLOC_NO_FLAGS);
 }
tests/libqos/malloc-spapr.c +2 -2
index 006404af33..1c359cea6c 100644
@@ -22,7 +22,7 @@ void spapr_alloc_uninit(QGuestAllocator *allocator)
     alloc_uninit(allocator);
 }
 
-QGuestAllocator *spapr_alloc_init_flags(QAllocOpts flags)
+QGuestAllocator *spapr_alloc_init_flags(QTestState *qts, QAllocOpts flags)
 {
     QGuestAllocator *s;
 
@@ -34,5 +34,5 @@ QGuestAllocator *spapr_alloc_init_flags(QAllocOpts flags)
 
 QGuestAllocator *spapr_alloc_init(void)
 {
-    return spapr_alloc_init_flags(ALLOC_NO_FLAGS);
+    return spapr_alloc_init_flags(NULL, ALLOC_NO_FLAGS);
 }
tests/vhost-user-test.c +1 -1
index ea7d38ea44..562bfaefd2 100644
@@ -894,7 +894,7 @@ static void test_multiqueue(void)
     bus = qpci_init_pc(global_qtest, NULL);
     dev = virtio_net_pci_init(bus, PCI_SLOT);
 
-    alloc = pc_alloc_init();
+    alloc = pc_alloc_init(global_qtest);
     for (i = 0; i < queues * 2; i++) {
         vq[i] = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, alloc, i);
     }
Signature · 1 line
2.13.5
author
#45 lore raw

PATCH v6 1/1 fixup! libqos: Use explicit QTestState for fw_cfg operations

---
Fix older gcc duplicate typedef warning [patchew]

---
 tests/libqos/fw_cfg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/libqos/fw_cfg.h +1 -1
index 396dd4ee1e..0353416af0 100644
@@ -13,9 +13,9 @@
 #ifndef LIBQOS_FW_CFG_H
 #define LIBQOS_FW_CFG_H
 
+#include "libqtest.h"
 
 typedef struct QFWCFG QFWCFG;
-typedef struct QTestState QTestState;
 
 struct QFWCFG
 {
Signature · 1 line
2.13.5
Reviewed-by on v6 14/29
#46 lore raw

Re: [Qemu-devel] [PATCH v6 14/29] libqos: Use explicit QTestState for fw_cfg operations

In reply to Eric Blake
Quoted 7 lines · Eric Blake

Drop one more client of global_qtest by teaching all fw_cfg test functionality (invoked through alloc-pc) to pass in an explicit QTestState, adjusting all callers. In particular, fw_cfg-test had to reorder things to create the test state prior to creating the fw_cfg.

Quoted 330 lines
---
  tests/libqos/fw_cfg.h       | 10 ++++++----
  tests/libqos/libqos.h       |  2 +-
  tests/libqos/malloc-pc.h    |  4 ++--
  tests/libqos/malloc-spapr.h |  2 +-
  tests/libqos/malloc.h       |  1 +
  tests/boot-order-test.c     |  6 +++---
  tests/e1000e-test.c         |  2 +-
  tests/fw_cfg-test.c         | 14 ++++++--------
  tests/ide-test.c            |  2 +-
  tests/libqos/fw_cfg.c       | 14 ++++++++------
  tests/libqos/libqos.c       |  2 +-
  tests/libqos/malloc-pc.c    |  8 ++++----
  tests/libqos/malloc-spapr.c |  4 ++--
  tests/vhost-user-test.c     |  2 +-
  14 files changed, 38 insertions(+), 35 deletions(-)
tests/libqos/fw_cfg.h +6 -4
index e8371b2317..396dd4ee1e 100644
@@ -15,10 +15,12 @@
 
 
  typedef struct QFWCFG QFWCFG;
+typedef struct QTestState QTestState;
 
  struct QFWCFG
  {
      uint64_t base;
+    QTestState *qts;
      void (*select)(QFWCFG *fw_cfg, uint16_t key);
      void (*read)(QFWCFG *fw_cfg, void *data, size_t len);
  };
@@ -30,12 +32,12 @@ uint16_t qfw_cfg_get_u16(QFWCFG *fw_cfg, uint16_t key);
  uint32_t qfw_cfg_get_u32(QFWCFG *fw_cfg, uint16_t key);
  uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key);
 
-QFWCFG *mm_fw_cfg_init(uint64_t base);
-QFWCFG *io_fw_cfg_init(uint16_t base);
+QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base);
+QFWCFG *io_fw_cfg_init(QTestState *qts, uint16_t base);
 
-static inline QFWCFG *pc_fw_cfg_init(void)
+static inline QFWCFG *pc_fw_cfg_init(QTestState *qts)
  {
-    return io_fw_cfg_init(0x510);
+    return io_fw_cfg_init(qts, 0x510);
  }
 
  #endif
tests/libqos/libqos.h +1 -1
index 78e5c044a0..07d4b93d1d 100644
@@ -8,7 +8,7 @@
  typedef struct QOSState QOSState;
 
  typedef struct QOSOps {
-    QGuestAllocator *(*init_allocator)(QAllocOpts);
+    QGuestAllocator *(*init_allocator)(QTestState *qts, QAllocOpts);
      void (*uninit_allocator)(QGuestAllocator *);
      QPCIBus *(*qpci_init)(QTestState *qts, QGuestAllocator *alloc);
      void (*qpci_free)(QPCIBus *bus);
tests/libqos/malloc-pc.h +2 -2
index 86ab9f0429..10f3da6cf2 100644
@@ -15,8 +15,8 @@
 
  #include "libqos/malloc.h"
 
-QGuestAllocator *pc_alloc_init(void);
-QGuestAllocator *pc_alloc_init_flags(QAllocOpts flags);
+QGuestAllocator *pc_alloc_init(QTestState *qts);
+QGuestAllocator *pc_alloc_init_flags(QTestState *qts, QAllocOpts flags);
  void pc_alloc_uninit(QGuestAllocator *allocator);
 
  #endif
tests/libqos/malloc-spapr.h +1 -1
index 64d0e770d1..52a9346a26 100644
@@ -11,7 +11,7 @@
  #include "libqos/malloc.h"
 
  QGuestAllocator *spapr_alloc_init(void);
-QGuestAllocator *spapr_alloc_init_flags(QAllocOpts flags);
+QGuestAllocator *spapr_alloc_init_flags(QTestState *qts, QAllocOpts flags);
  void spapr_alloc_uninit(QGuestAllocator *allocator);
 
  #endif
tests/libqos/malloc.h +1 -0
index ae9dac8f61..828fddabdb 100644
@@ -14,6 +14,7 @@
  #define LIBQOS_MALLOC_H
 
  #include "qemu/queue.h"
+#include "libqtest.h"
 
  typedef enum {
      ALLOC_NO_FLAGS    = 0x00,
tests/boot-order-test.c +3 -3
index 9d516830dd..5fc2ca8e9e 100644
@@ -135,7 +135,7 @@ static void test_prep_boot_order(void)
 
  static uint64_t read_boot_order_pmac(void)
  {
-    QFWCFG *fw_cfg = mm_fw_cfg_init(0xf0000510);
+    QFWCFG *fw_cfg = mm_fw_cfg_init(global_qtest, 0xf0000510);
 
      return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
  }
@@ -160,7 +160,7 @@ static void test_pmac_newworld_boot_order(void)
 
  static uint64_t read_boot_order_sun4m(void)
  {
-    QFWCFG *fw_cfg = mm_fw_cfg_init(0xd00000510ULL);
+    QFWCFG *fw_cfg = mm_fw_cfg_init(global_qtest, 0xd00000510ULL);
 
      return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
  }
@@ -172,7 +172,7 @@ static void test_sun4m_boot_order(void)
 
  static uint64_t read_boot_order_sun4u(void)
  {
-    QFWCFG *fw_cfg = io_fw_cfg_init(0x510);
+    QFWCFG *fw_cfg = io_fw_cfg_init(global_qtest, 0x510);
 
      return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
  }
tests/e1000e-test.c +1 -1
index d8085d944e..32aa738b72 100644
@@ -392,7 +392,7 @@ static void data_test_init(e1000e_device *d)
      qtest_start(cmdline);
      g_free(cmdline);
 
-    test_alloc = pc_alloc_init();
+    test_alloc = pc_alloc_init(global_qtest);
      g_assert_nonnull(test_alloc);
 
      test_bus = qpci_init_pc(global_qtest, test_alloc);
tests/fw_cfg-test.c +6 -8
index 688342bed5..47596c57a1 100644
@@ -107,7 +107,11 @@ int main(int argc, char **argv)
 
      g_test_init(&argc, &argv, NULL);
 
-    fw_cfg = pc_fw_cfg_init();
+    cmdline = g_strdup_printf("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8 ");
+    s = qtest_start(cmdline);
+    g_free(cmdline);
+
+    fw_cfg = pc_fw_cfg_init(s);
 
      qtest_add_func("fw_cfg/signature", test_fw_cfg_signature);
      qtest_add_func("fw_cfg/id", test_fw_cfg_id);
@@ -125,15 +129,9 @@ int main(int argc, char **argv)
      qtest_add_func("fw_cfg/numa", test_fw_cfg_numa);
      qtest_add_func("fw_cfg/boot_menu", test_fw_cfg_boot_menu);
 
-    cmdline = g_strdup_printf("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8 ");
-    s = qtest_start(cmdline);
-    g_free(cmdline);
-
      ret = g_test_run();
 
-    if (s) {
-        qtest_quit(s);
-    }
+    qtest_quit(s);
 
      return ret;
  }
tests/ide-test.c +1 -1
index b2237b6158..084f6a5f96 100644
@@ -125,7 +125,7 @@ static void ide_test_start(const char *cmdline_fmt, ...)
      va_end(ap);
 
      qtest_start(cmdline);
-    guest_malloc = pc_alloc_init();
+    guest_malloc = pc_alloc_init(global_qtest);
 
      g_free(cmdline);
  }
tests/libqos/fw_cfg.c +8 -6
index 4d9dc3fd0b..d0889d1e22 100644
@@ -56,7 +56,7 @@ uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key)
 
  static void mm_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
  {
-    writew(fw_cfg->base, key);
+    qtest_writew(fw_cfg->qts, fw_cfg->base, key);
  }
 
  static void mm_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
@@ -65,15 +65,16 @@ static void mm_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
      int i;
 
      for (i = 0; i < len; i++) {
-        ptr[i] = readb(fw_cfg->base + 2);
+        ptr[i] = qtest_readb(fw_cfg->qts, fw_cfg->base + 2);
      }
  }
 
-QFWCFG *mm_fw_cfg_init(uint64_t base)
+QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base)
  {
      QFWCFG *fw_cfg = g_malloc0(sizeof(*fw_cfg));
 
      fw_cfg->base = base;
+    fw_cfg->qts = qts;
      fw_cfg->select = mm_fw_cfg_select;
      fw_cfg->read = mm_fw_cfg_read;
 
@@ -82,7 +83,7 @@ QFWCFG *mm_fw_cfg_init(uint64_t base)
 
  static void io_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
  {
-    outw(fw_cfg->base, key);
+    qtest_outw(fw_cfg->qts, fw_cfg->base, key);
  }
 
  static void io_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
@@ -91,15 +92,16 @@ static void io_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
      int i;
 
      for (i = 0; i < len; i++) {
-        ptr[i] = inb(fw_cfg->base + 1);
+        ptr[i] = qtest_inb(fw_cfg->qts, fw_cfg->base + 1);
      }
  }
 
-QFWCFG *io_fw_cfg_init(uint16_t base)
+QFWCFG *io_fw_cfg_init(QTestState *qts, uint16_t base)
  {
      QFWCFG *fw_cfg = g_malloc0(sizeof(*fw_cfg));
 
      fw_cfg->base = base;
+    fw_cfg->qts = qts;
      fw_cfg->select = io_fw_cfg_select;
      fw_cfg->read = io_fw_cfg_read;
 
tests/libqos/libqos.c +1 -1
index c95428e1cb..62d2f39b93 100644
@@ -24,7 +24,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
      qs->ops = ops;
      if (ops) {
          if (ops->init_allocator) {
-            qs->alloc = ops->init_allocator(ALLOC_NO_FLAGS);
+            qs->alloc = ops->init_allocator(qs->qts, ALLOC_NO_FLAGS);
          }
          if (ops->qpci_init) {
              qs->pcibus = ops->qpci_init(qs->qts, qs->alloc);
tests/libqos/malloc-pc.c +4 -4
index dd2b900c5f..634b9c288a 100644
@@ -29,11 +29,11 @@ void pc_alloc_uninit(QGuestAllocator *allocator)
      alloc_uninit(allocator);
  }
 
-QGuestAllocator *pc_alloc_init_flags(QAllocOpts flags)
+QGuestAllocator *pc_alloc_init_flags(QTestState *qts, QAllocOpts flags)
  {
      QGuestAllocator *s;
      uint64_t ram_size;
-    QFWCFG *fw_cfg = pc_fw_cfg_init();
+    QFWCFG *fw_cfg = pc_fw_cfg_init(qts);
 
      ram_size = qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE);
      s = alloc_init_flags(flags, 1 << 20, MIN(ram_size, 0xE0000000));
@@ -45,7 +45,7 @@ QGuestAllocator *pc_alloc_init_flags(QAllocOpts flags)
      return s;
  }
 
-inline QGuestAllocator *pc_alloc_init(void)
+inline QGuestAllocator *pc_alloc_init(QTestState *qts)
  {
-    return pc_alloc_init_flags(ALLOC_NO_FLAGS);
+    return pc_alloc_init_flags(qts, ALLOC_NO_FLAGS);
  }
tests/libqos/malloc-spapr.c +2 -2
index 006404af33..1c359cea6c 100644
@@ -22,7 +22,7 @@ void spapr_alloc_uninit(QGuestAllocator *allocator)
      alloc_uninit(allocator);
  }
 
-QGuestAllocator *spapr_alloc_init_flags(QAllocOpts flags)
+QGuestAllocator *spapr_alloc_init_flags(QTestState *qts, QAllocOpts flags)
  {
      QGuestAllocator *s;
 
@@ -34,5 +34,5 @@ QGuestAllocator *spapr_alloc_init_flags(QAllocOpts flags)
 
  QGuestAllocator *spapr_alloc_init(void)
  {
-    return spapr_alloc_init_flags(ALLOC_NO_FLAGS);
+    return spapr_alloc_init_flags(NULL, ALLOC_NO_FLAGS);
  }
tests/vhost-user-test.c +1 -1
index ea7d38ea44..562bfaefd2 100644
@@ -894,7 +894,7 @@ static void test_multiqueue(void)
      bus = qpci_init_pc(global_qtest, NULL);
      dev = virtio_net_pci_init(bus, PCI_SLOT);
 
-    alloc = pc_alloc_init();
+    alloc = pc_alloc_init(global_qtest);
      for (i = 0; i < queues * 2; i++) {
          vq[i] = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, alloc, i);
      }
Reviewed-by on v6 14/29
#47 lore raw

Re: [Qemu-devel] [PATCH v6 14/29] libqos: Use explicit QTestState for fw_cfg operations

In reply to Eric Blake
Quoted 7 lines · Eric Blake

Drop one more client of global_qtest by teaching all fw_cfg test functionality (invoked through alloc-pc) to pass in an explicit QTestState, adjusting all callers. In particular, fw_cfg-test had to reorder things to create the test state prior to creating the fw_cfg.

#48 lore raw

Re: [Qemu-devel] [PATCH v6 14/29] libqos: Use explicit QTestState for fw_cfg operations

In reply to Eric Blake
Quoted 29 lines · Eric Blake

Drop one more client of global_qtest by teaching all fw_cfg test functionality (invoked through alloc-pc) to pass in an explicit QTestState, adjusting all callers. In particular, fw_cfg-test had to reorder things to create the test state prior to creating the fw_cfg.

---
 tests/libqos/fw_cfg.h       | 10 ++++++----
 tests/libqos/libqos.h       |  2 +-
 tests/libqos/malloc-pc.h    |  4 ++--
 tests/libqos/malloc-spapr.h |  2 +-
 tests/libqos/malloc.h       |  1 +
 tests/boot-order-test.c     |  6 +++---
 tests/e1000e-test.c         |  2 +-
 tests/fw_cfg-test.c         | 14 ++++++--------
 tests/ide-test.c            |  2 +-
 tests/libqos/fw_cfg.c       | 14 ++++++++------
 tests/libqos/libqos.c       |  2 +-
 tests/libqos/malloc-pc.c    |  8 ++++----
 tests/libqos/malloc-spapr.c |  4 ++--
 tests/vhost-user-test.c     |  2 +-
 14 files changed, 38 insertions(+), 35 deletions(-)
tests/libqos/fw_cfg.h +0 -0
index e8371b2317..396dd4ee1e 100644

tests/libqos/fw_cfg.h line 18

Quoted 4 lines
tests/libqos/fw_cfg.h +1 -0
@@ -15,10 +15,12 @@
 
 
 typedef struct QFWCFG QFWCFG;
+typedef struct QTestState QTestState;

Not sure, but I slightly remember that typedeffing a struct like this in multiple places can cause compiler warnings or errors with certain versions of GCC or clang? So a file that includes both, fw_cfg.h and libqtest.h will then fail to compile?

I think it would be better to change the include order in the .c files instead, so that libqtest.h is always included before fw_cfg.h.

Thomas

#49 lore raw

Re: [Qemu-devel] [PATCH v6 14/29] libqos: Use explicit QTestState for fw_cfg operations

Quoted 40 lines · Thomas Huth
Quoted 29 lines · Eric Blake

Drop one more client of global_qtest by teaching all fw_cfg test functionality (invoked through alloc-pc) to pass in an explicit QTestState, adjusting all callers. In particular, fw_cfg-test had to reorder things to create the test state prior to creating the fw_cfg.

---
 tests/libqos/fw_cfg.h       | 10 ++++++----
 tests/libqos/libqos.h       |  2 +-
 tests/libqos/malloc-pc.h    |  4 ++--
 tests/libqos/malloc-spapr.h |  2 +-
 tests/libqos/malloc.h       |  1 +
 tests/boot-order-test.c     |  6 +++---
 tests/e1000e-test.c         |  2 +-
 tests/fw_cfg-test.c         | 14 ++++++--------
 tests/ide-test.c            |  2 +-
 tests/libqos/fw_cfg.c       | 14 ++++++++------
 tests/libqos/libqos.c       |  2 +-
 tests/libqos/malloc-pc.c    |  8 ++++----
 tests/libqos/malloc-spapr.c |  4 ++--
 tests/vhost-user-test.c     |  2 +-
 14 files changed, 38 insertions(+), 35 deletions(-)
tests/libqos/fw_cfg.h +0 -0
index e8371b2317..396dd4ee1e 100644

tests/libqos/fw_cfg.h line 18

Quoted 4 lines
tests/libqos/fw_cfg.h +1 -0
@@ -15,10 +15,12 @@
 
 
 typedef struct QFWCFG QFWCFG;
+typedef struct QTestState QTestState;

Not sure, but I slightly remember that typedeffing a struct like this in multiple places can cause compiler warnings or errors with certain versions of GCC or clang? So a file that includes both, fw_cfg.h and libqtest.h will then fail to compile?

Quoted 2 lines

I think it would be better to change the include order in the .c files instead, so that libqtest.h is always included before fw_cfg.h.

Ah, well, I just saw that you also sent a fixup patch for this. Anyway, I'm not a fan of including header files from other header files, so changing the include order in the .c files sounds like the better solution to me.

Thomas

author
#50 lore raw

Re: [Qemu-devel] [PATCH v6 14/29] libqos: Use explicit QTestState for fw_cfg operations

Quoted 13 lines · Thomas Huth
Quoted 12 lines · Thomas Huth
Quoted 11 lines · Eric Blake

Drop one more client of global_qtest by teaching all fw_cfg test functionality (invoked through alloc-pc) to pass in an explicit QTestState, adjusting all callers. In particular, fw_cfg-test had to reorder things to create the test state prior to creating the fw_cfg.

+++ b/tests/libqos/fw_cfg.h

(quoted diff) +0 -0
@@ -15,10 +15,12 @@
 
 
Quoted 7 lines
Quoted 7 lines

tests/libqos/fw_cfg.h line 18

Quoted 2 lines
tests/libqos/fw_cfg.h +1 -0
 typedef struct QFWCFG QFWCFG;
+typedef struct QTestState QTestState;

Not sure, but I slightly remember that typedeffing a struct like this in multiple places can cause compiler warnings or errors with certain versions of GCC or clang? So a file that includes both, fw_cfg.h and libqtest.h will then fail to compile?

Yes, older gcc fails to compile (my off-hand recollection is that it was a bug in the older gcc, and not a standards-compliance issue to encounter the same typedef twice, but I could be wrong), ergo the fixup that you later noticed.

Quoted 8 lines
Quoted 3 lines

I think it would be better to change the include order in the .c files instead, so that libqtest.h is always included before fw_cfg.h.

Ah, well, I just saw that you also sent a fixup patch for this. Anyway, I'm not a fan of including header files from other header files, so changing the include order in the .c files sounds like the better solution to me.

Eww. I like headers to be self-contained. Other than stuff we get from osdep.h (which we know is included by EVERY .c file), I prefer that if a header uses another type, then it guarantees that an idempotent inclusion of a header that declares that type is also present in the header file, rather than forcing .c files to know which order to include things in.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
author
#51 lore raw

Re: [Qemu-devel] [PATCH v6 14/29] libqos: Use explicit QTestState for fw_cfg operations

Quoted 10 lines · Eric Blake
Quoted 3 lines

I'm not a fan of including header files from other header files, so changing the include order in the .c files sounds like the better solution to me.

Eww. I like headers to be self-contained. Other than stuff we get from osdep.h (which we know is included by EVERY .c file), I prefer that if a header uses another type, then it guarantees that an idempotent inclusion of a header that declares that type is also present in the header file, rather than forcing .c files to know which order to include things in.

The qemu tree-wide policy appears to be that a header should be self-contained (order of inclusion in .c files shouldn't matter). Also, if header A only uses 'SomeType *', it can either get the definition of SomeType from header B, or we can add the typedef to typedef.h at which point both header A and B get the typedef from there (that is, typedef.h is great for breaking what would otherwise be cyclic inclusion of mutually-recursive types across different headers, as well as a way to speed up compilation when a typedef is sufficient rather than a full definition).

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
author
#52 lore raw

PATCH v6 15/29 libqos: Use explicit QTestState for rtas operations

In reply to Eric Blake

Drop one more client of global_qtest by teaching all rtas test functionality to pass in an explicit QTestState, adjusting all callers.

---
 tests/libqos/rtas.h      |  9 ++++++---
 tests/libqos/pci-spapr.c | 18 ++++++++++++------
 tests/libqos/rtas.c      | 21 ++++++++++++---------
 tests/rtas-test.c        |  2 +-
 4 files changed, 31 insertions(+), 19 deletions(-)
tests/libqos/rtas.h +6 -3
index 498eb19230..e3d0f850a7 100644
@@ -7,9 +7,12 @@
 #define LIBQOS_RTAS_H
 #include "libqos/malloc.h"
 
-int qrtas_get_time_of_day(QGuestAllocator *alloc, struct tm *tm, uint32_t *ns);
-uint32_t qrtas_ibm_read_pci_config(QGuestAllocator *alloc, uint64_t buid,
+int qrtas_get_time_of_day(QTestState *qts, QGuestAllocator *alloc,
+                          struct tm *tm, uint32_t *ns);
+uint32_t qrtas_ibm_read_pci_config(QTestState *qts, QGuestAllocator *alloc,
+                                   uint64_t buid,
                                    uint32_t addr, uint32_t size);
-int qrtas_ibm_write_pci_config(QGuestAllocator *alloc, uint64_t buid,
+int qrtas_ibm_write_pci_config(QTestState *qts, QGuestAllocator *alloc,
+                               uint64_t buid,
                                uint32_t addr, uint32_t size, uint32_t val);
 #endif /* LIBQOS_RTAS_H */
tests/libqos/pci-spapr.c +12 -6
index d7b2aa75e6..b7199501b4 100644
@@ -108,21 +108,24 @@ static uint8_t qpci_spapr_config_readb(QPCIBus *bus, int devfn, uint8_t offset)
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
     uint32_t config_addr = (devfn << 8) | offset;
-    return qrtas_ibm_read_pci_config(s->alloc, s->buid, config_addr, 1);
+    return qrtas_ibm_read_pci_config(bus->qts, s->alloc, s->buid,
+                                     config_addr, 1);
 }
 
 static uint16_t qpci_spapr_config_readw(QPCIBus *bus, int devfn, uint8_t offset)
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
     uint32_t config_addr = (devfn << 8) | offset;
-    return qrtas_ibm_read_pci_config(s->alloc, s->buid, config_addr, 2);
+    return qrtas_ibm_read_pci_config(bus->qts, s->alloc, s->buid,
+                                     config_addr, 2);
 }
 
 static uint32_t qpci_spapr_config_readl(QPCIBus *bus, int devfn, uint8_t offset)
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
     uint32_t config_addr = (devfn << 8) | offset;
-    return qrtas_ibm_read_pci_config(s->alloc, s->buid, config_addr, 4);
+    return qrtas_ibm_read_pci_config(bus->qts, s->alloc, s->buid,
+                                     config_addr, 4);
 }
 
 static void qpci_spapr_config_writeb(QPCIBus *bus, int devfn, uint8_t offset,
@@ -130,7 +133,8 @@ static void qpci_spapr_config_writeb(QPCIBus *bus, int devfn, uint8_t offset,
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
     uint32_t config_addr = (devfn << 8) | offset;
-    qrtas_ibm_write_pci_config(s->alloc, s->buid, config_addr, 1, value);
+    qrtas_ibm_write_pci_config(bus->qts, s->alloc, s->buid,
+                               config_addr, 1, value);
 }
 
 static void qpci_spapr_config_writew(QPCIBus *bus, int devfn, uint8_t offset,
@@ -138,7 +142,8 @@ static void qpci_spapr_config_writew(QPCIBus *bus, int devfn, uint8_t offset,
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
     uint32_t config_addr = (devfn << 8) | offset;
-    qrtas_ibm_write_pci_config(s->alloc, s->buid, config_addr, 2, value);
+    qrtas_ibm_write_pci_config(bus->qts, s->alloc, s->buid,
+                               config_addr, 2, value);
 }
 
 static void qpci_spapr_config_writel(QPCIBus *bus, int devfn, uint8_t offset,
@@ -146,7 +151,8 @@ static void qpci_spapr_config_writel(QPCIBus *bus, int devfn, uint8_t offset,
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
     uint32_t config_addr = (devfn << 8) | offset;
-    qrtas_ibm_write_pci_config(s->alloc, s->buid, config_addr, 4, value);
+    qrtas_ibm_write_pci_config(bus->qts, s->alloc, s->buid,
+                               config_addr, 4, value);
 }
 
 #define SPAPR_PCI_BASE               (1ULL << 45)
tests/libqos/rtas.c +12 -9
index 0269803ce0..fb25f91723 100644
@@ -26,7 +26,8 @@ static void qrtas_copy_ret(uint64_t target_ret, uint32_t nret, uint32_t *ret)
     }
 }
 
-static uint64_t qrtas_call(QGuestAllocator *alloc, const char *name,
+static uint64_t qrtas_call(QTestState *qts, QGuestAllocator *alloc,
+                           const char *name,
                            uint32_t nargs, uint32_t *args,
                            uint32_t nret, uint32_t *ret)
 {
@@ -37,8 +38,7 @@ static uint64_t qrtas_call(QGuestAllocator *alloc, const char *name,
     target_ret = guest_alloc(alloc, nret * sizeof(uint32_t));
 
     qrtas_copy_args(target_args, nargs, args);
-    res = qtest_rtas_call(global_qtest, name,
-                          nargs, target_args, nret, target_ret);
+    res = qtest_rtas_call(qts, name, nargs, target_args, nret, target_ret);
     qrtas_copy_ret(target_ret, nret, ret);
 
     guest_free(alloc, target_ret);
@@ -47,12 +47,13 @@ static uint64_t qrtas_call(QGuestAllocator *alloc, const char *name,
     return res;
 }
 
-int qrtas_get_time_of_day(QGuestAllocator *alloc, struct tm *tm, uint32_t *ns)
+int qrtas_get_time_of_day(QTestState *qts, QGuestAllocator *alloc,
+                          struct tm *tm, uint32_t *ns)
 {
     int res;
     uint32_t ret[8];
 
-    res = qrtas_call(alloc, "get-time-of-day", 0, NULL, 8, ret);
+    res = qrtas_call(qts, alloc, "get-time-of-day", 0, NULL, 8, ret);
     if (res != 0) {
         return res;
     }
@@ -70,7 +71,8 @@ int qrtas_get_time_of_day(QGuestAllocator *alloc, struct tm *tm, uint32_t *ns)
     return res;
 }
 
-uint32_t qrtas_ibm_read_pci_config(QGuestAllocator *alloc, uint64_t buid,
+uint32_t qrtas_ibm_read_pci_config(QTestState *qts, QGuestAllocator *alloc,
+                                   uint64_t buid,
                                    uint32_t addr, uint32_t size)
 {
     int res;
@@ -80,7 +82,7 @@ uint32_t qrtas_ibm_read_pci_config(QGuestAllocator *alloc, uint64_t buid,
     args[1] = buid >> 32;
     args[2] = buid & 0xffffffff;
     args[3] = size;
-    res = qrtas_call(alloc, "ibm,read-pci-config", 4, args, 2, ret);
+    res = qrtas_call(qts, alloc, "ibm,read-pci-config", 4, args, 2, ret);
     if (res != 0) {
         return -1;
     }
@@ -92,7 +94,8 @@ uint32_t qrtas_ibm_read_pci_config(QGuestAllocator *alloc, uint64_t buid,
     return ret[1];
 }
 
-int qrtas_ibm_write_pci_config(QGuestAllocator *alloc, uint64_t buid,
+int qrtas_ibm_write_pci_config(QTestState *qts, QGuestAllocator *alloc,
+                               uint64_t buid,
                                uint32_t addr, uint32_t size, uint32_t val)
 {
     int res;
@@ -103,7 +106,7 @@ int qrtas_ibm_write_pci_config(QGuestAllocator *alloc, uint64_t buid,
     args[2] = buid & 0xffffffff;
     args[3] = size;
     args[4] = val;
-    res = qrtas_call(alloc, "ibm,write-pci-config", 5, args, 1, ret);
+    res = qrtas_call(qts, alloc, "ibm,write-pci-config", 5, args, 1, ret);
     if (res != 0) {
         return -1;
     }
tests/rtas-test.c +1 -1
index 276c87ef84..34a692163f 100644
@@ -16,7 +16,7 @@ static void test_rtas_get_time_of_day(void)
     qs = qtest_spapr_boot("-machine pseries");
 
     t1 = time(NULL);
-    ret = qrtas_get_time_of_day(qs->alloc, &tm, &ns);
+    ret = qrtas_get_time_of_day(qs->qts, qs->alloc, &tm, &ns);
     g_assert_cmpint(ret, ==, 0);
     t2 = mktimegm(&tm);
     g_assert(t2 - t1 < 5); /* 5 sec max to run the test */
Signature · 1 line
2.13.5
Reviewed-by on v6 15/29
#53 lore raw

Re: [Qemu-devel] [PATCH v6 15/29] libqos: Use explicit QTestState for rtas operations

Quoted 178 lines · Eric Blake

Drop one more client of global_qtest by teaching all rtas test functionality to pass in an explicit QTestState, adjusting all callers.

---
 tests/libqos/rtas.h      |  9 ++++++---
 tests/libqos/pci-spapr.c | 18 ++++++++++++------
 tests/libqos/rtas.c      | 21 ++++++++++++---------
 tests/rtas-test.c        |  2 +-
 4 files changed, 31 insertions(+), 19 deletions(-)
tests/libqos/rtas.h +6 -3
index 498eb19230..e3d0f850a7 100644
@@ -7,9 +7,12 @@
 #define LIBQOS_RTAS_H
 #include "libqos/malloc.h"
 
-int qrtas_get_time_of_day(QGuestAllocator *alloc, struct tm *tm, uint32_t *ns);
-uint32_t qrtas_ibm_read_pci_config(QGuestAllocator *alloc, uint64_t buid,
+int qrtas_get_time_of_day(QTestState *qts, QGuestAllocator *alloc,
+                          struct tm *tm, uint32_t *ns);
+uint32_t qrtas_ibm_read_pci_config(QTestState *qts, QGuestAllocator *alloc,
+                                   uint64_t buid,
                                    uint32_t addr, uint32_t size);
-int qrtas_ibm_write_pci_config(QGuestAllocator *alloc, uint64_t buid,
+int qrtas_ibm_write_pci_config(QTestState *qts, QGuestAllocator *alloc,
+                               uint64_t buid,
                                uint32_t addr, uint32_t size, uint32_t val);
 #endif /* LIBQOS_RTAS_H */
tests/libqos/pci-spapr.c +12 -6
index d7b2aa75e6..b7199501b4 100644
@@ -108,21 +108,24 @@ static uint8_t qpci_spapr_config_readb(QPCIBus *bus, int devfn, uint8_t offset)
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
     uint32_t config_addr = (devfn << 8) | offset;
-    return qrtas_ibm_read_pci_config(s->alloc, s->buid, config_addr, 1);
+    return qrtas_ibm_read_pci_config(bus->qts, s->alloc, s->buid,
+                                     config_addr, 1);
 }
 
 static uint16_t qpci_spapr_config_readw(QPCIBus *bus, int devfn, uint8_t offset)
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
     uint32_t config_addr = (devfn << 8) | offset;
-    return qrtas_ibm_read_pci_config(s->alloc, s->buid, config_addr, 2);
+    return qrtas_ibm_read_pci_config(bus->qts, s->alloc, s->buid,
+                                     config_addr, 2);
 }
 
 static uint32_t qpci_spapr_config_readl(QPCIBus *bus, int devfn, uint8_t offset)
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
     uint32_t config_addr = (devfn << 8) | offset;
-    return qrtas_ibm_read_pci_config(s->alloc, s->buid, config_addr, 4);
+    return qrtas_ibm_read_pci_config(bus->qts, s->alloc, s->buid,
+                                     config_addr, 4);
 }
 
 static void qpci_spapr_config_writeb(QPCIBus *bus, int devfn, uint8_t offset,
@@ -130,7 +133,8 @@ static void qpci_spapr_config_writeb(QPCIBus *bus, int devfn, uint8_t offset,
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
     uint32_t config_addr = (devfn << 8) | offset;
-    qrtas_ibm_write_pci_config(s->alloc, s->buid, config_addr, 1, value);
+    qrtas_ibm_write_pci_config(bus->qts, s->alloc, s->buid,
+                               config_addr, 1, value);
 }
 
 static void qpci_spapr_config_writew(QPCIBus *bus, int devfn, uint8_t offset,
@@ -138,7 +142,8 @@ static void qpci_spapr_config_writew(QPCIBus *bus, int devfn, uint8_t offset,
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
     uint32_t config_addr = (devfn << 8) | offset;
-    qrtas_ibm_write_pci_config(s->alloc, s->buid, config_addr, 2, value);
+    qrtas_ibm_write_pci_config(bus->qts, s->alloc, s->buid,
+                               config_addr, 2, value);
 }
 
 static void qpci_spapr_config_writel(QPCIBus *bus, int devfn, uint8_t offset,
@@ -146,7 +151,8 @@ static void qpci_spapr_config_writel(QPCIBus *bus, int devfn, uint8_t offset,
 {
     QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
     uint32_t config_addr = (devfn << 8) | offset;
-    qrtas_ibm_write_pci_config(s->alloc, s->buid, config_addr, 4, value);
+    qrtas_ibm_write_pci_config(bus->qts, s->alloc, s->buid,
+                               config_addr, 4, value);
 }
 
 #define SPAPR_PCI_BASE               (1ULL << 45)
tests/libqos/rtas.c +12 -9
index 0269803ce0..fb25f91723 100644
@@ -26,7 +26,8 @@ static void qrtas_copy_ret(uint64_t target_ret, uint32_t nret, uint32_t *ret)
     }
 }
 
-static uint64_t qrtas_call(QGuestAllocator *alloc, const char *name,
+static uint64_t qrtas_call(QTestState *qts, QGuestAllocator *alloc,
+                           const char *name,
                            uint32_t nargs, uint32_t *args,
                            uint32_t nret, uint32_t *ret)
 {
@@ -37,8 +38,7 @@ static uint64_t qrtas_call(QGuestAllocator *alloc, const char *name,
     target_ret = guest_alloc(alloc, nret * sizeof(uint32_t));
 
     qrtas_copy_args(target_args, nargs, args);
-    res = qtest_rtas_call(global_qtest, name,
-                          nargs, target_args, nret, target_ret);
+    res = qtest_rtas_call(qts, name, nargs, target_args, nret, target_ret);
     qrtas_copy_ret(target_ret, nret, ret);
 
     guest_free(alloc, target_ret);
@@ -47,12 +47,13 @@ static uint64_t qrtas_call(QGuestAllocator *alloc, const char *name,
     return res;
 }
 
-int qrtas_get_time_of_day(QGuestAllocator *alloc, struct tm *tm, uint32_t *ns)
+int qrtas_get_time_of_day(QTestState *qts, QGuestAllocator *alloc,
+                          struct tm *tm, uint32_t *ns)
 {
     int res;
     uint32_t ret[8];
 
-    res = qrtas_call(alloc, "get-time-of-day", 0, NULL, 8, ret);
+    res = qrtas_call(qts, alloc, "get-time-of-day", 0, NULL, 8, ret);
     if (res != 0) {
         return res;
     }
@@ -70,7 +71,8 @@ int qrtas_get_time_of_day(QGuestAllocator *alloc, struct tm *tm, uint32_t *ns)
     return res;
 }
 
-uint32_t qrtas_ibm_read_pci_config(QGuestAllocator *alloc, uint64_t buid,
+uint32_t qrtas_ibm_read_pci_config(QTestState *qts, QGuestAllocator *alloc,
+                                   uint64_t buid,
                                    uint32_t addr, uint32_t size)
 {
     int res;
@@ -80,7 +82,7 @@ uint32_t qrtas_ibm_read_pci_config(QGuestAllocator *alloc, uint64_t buid,
     args[1] = buid >> 32;
     args[2] = buid & 0xffffffff;
     args[3] = size;
-    res = qrtas_call(alloc, "ibm,read-pci-config", 4, args, 2, ret);
+    res = qrtas_call(qts, alloc, "ibm,read-pci-config", 4, args, 2, ret);
     if (res != 0) {
         return -1;
     }
@@ -92,7 +94,8 @@ uint32_t qrtas_ibm_read_pci_config(QGuestAllocator *alloc, uint64_t buid,
     return ret[1];
 }
 
-int qrtas_ibm_write_pci_config(QGuestAllocator *alloc, uint64_t buid,
+int qrtas_ibm_write_pci_config(QTestState *qts, QGuestAllocator *alloc,
+                               uint64_t buid,
                                uint32_t addr, uint32_t size, uint32_t val)
 {
     int res;
@@ -103,7 +106,7 @@ int qrtas_ibm_write_pci_config(QGuestAllocator *alloc, uint64_t buid,
     args[2] = buid & 0xffffffff;
     args[3] = size;
     args[4] = val;
-    res = qrtas_call(alloc, "ibm,write-pci-config", 5, args, 1, ret);
+    res = qrtas_call(qts, alloc, "ibm,write-pci-config", 5, args, 1, ret);
     if (res != 0) {
         return -1;
     }
tests/rtas-test.c +0 -0
index 276c87ef84..34a692163f 100644

tests/rtas-test.c static void test_rtas_get_time_of_day(void) · line 22

Quoted 8 lines
tests/rtas-test.c +1 -1
@@ -16,7 +16,7 @@ static void test_rtas_get_time_of_day(void)
     qs = qtest_spapr_boot("-machine pseries");
 
     t1 = time(NULL);
-    ret = qrtas_get_time_of_day(qs->alloc, &tm, &ns);
+    ret = qrtas_get_time_of_day(qs->qts, qs->alloc, &tm, &ns);
     g_assert_cmpint(ret, ==, 0);
     t2 = mktimegm(&tm);
     g_assert(t2 - t1 < 5); /* 5 sec max to run the test */
author
#54 lore raw

PATCH v6 16/29 libqos: Use explicit QTestState for virtio operations

In reply to Eric Blake

Drop one more client of global_qtest by teaching all virtio test functionality to pass in an explicit QTestState in constructors, where it is then reused for later access. Adjust all callers. This gets us one step closer to eliminating implicit use of global_qtest.

---
 tests/libqos/virtio-mmio.h |  3 +-
 tests/libqos/virtio.h      |  5 ++-
 tests/libqos/virtio-mmio.c | 54 +++++++++++++++++---------------
 tests/libqos/virtio-pci.c  |  3 ++
 tests/libqos/virtio.c      | 77 ++++++++++++++++++++++++++--------------------
 tests/virtio-blk-test.c    |  3 +-
 6 files changed, 84 insertions(+), 61 deletions(-)
tests/libqos/virtio-mmio.h +2 -1
index e3e52b9ce1..bd01386054 100644
@@ -41,6 +41,7 @@ typedef struct QVirtioMMIODevice {
 
 extern const QVirtioBus qvirtio_mmio;
 
-QVirtioMMIODevice *qvirtio_mmio_init_device(uint64_t addr, uint32_t page_size);
+QVirtioMMIODevice *qvirtio_mmio_init_device(QTestState *qts, uint64_t addr,
+                                            uint32_t page_size);
 
 #endif
tests/libqos/virtio.h +4 -1
index 8fbcd1869c..d180d54fc4 100644
@@ -19,6 +19,7 @@ typedef struct QVirtioBus QVirtioBus;
 
 typedef struct QVirtioDevice {
     const QVirtioBus *bus;
+    QTestState *qts;
     /* Device type */
     uint16_t device_type;
 } QVirtioDevice;
@@ -35,12 +36,14 @@ typedef struct QVirtQueue {
     uint16_t last_used_idx;
     bool indirect;
     bool event;
+    QTestState *qts;
 } QVirtQueue;
 
 typedef struct QVRingIndirectDesc {
     uint64_t desc; /* This points to an array fo struct vring_desc */
     uint16_t index;
     uint16_t elem;
+    QTestState *qts;
 } QVRingIndirectDesc;
 
 struct QVirtioBus {
@@ -93,7 +96,7 @@ struct QVirtioBus {
 static inline bool qvirtio_is_big_endian(QVirtioDevice *d)
 {
     /* FIXME: virtio 1.0 is always little-endian */
-    return qtest_big_endian(global_qtest);
+    return qtest_big_endian(d->qts);
 }
 
 static inline uint32_t qvring_size(uint32_t num, uint32_t align)
tests/libqos/virtio-mmio.c +30 -24

165 lines not on this page · raw message

tests/libqos/virtio-pci.c +3 -0
index 7ac15c04e1..f15971220c 100644
@@ -240,6 +240,7 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d,
     vqpci->vq.align = VIRTIO_PCI_VRING_ALIGN;
     vqpci->vq.indirect = (feat & (1u << VIRTIO_RING_F_INDIRECT_DESC)) != 0;
     vqpci->vq.event = (feat & (1u << VIRTIO_RING_F_EVENT_IDX)) != 0;
+    vqpci->vq.qts = d->qts;
 
     vqpci->msix_entry = -1;
     vqpci->msix_addr = 0;
@@ -316,6 +317,7 @@ QVirtioPCIDevice *qvirtio_pci_device_find(QPCIBus *bus, uint16_t device_type)
                         qvirtio_pci_assign_device, &dev);
 
     dev->vdev.bus = &qvirtio_pci;
+    dev->vdev.qts = bus->qts;
 
     return dev;
 }
@@ -329,6 +331,7 @@ QVirtioPCIDevice *qvirtio_pci_device_find_slot(QPCIBus *bus,
                         qvirtio_pci_assign_device, &dev);
 
     dev->vdev.bus = &qvirtio_pci;
+    dev->vdev.qts = bus->qts;
 
     return dev;
 }
tests/libqos/virtio.c +43 -34

188 lines not on this page · raw message

tests/virtio-blk-test.c +2 -1
index 0576cb16ba..26d0a7e9af 100644
@@ -687,7 +687,8 @@ static void mmio_basic(void)
 
     arm_test_start();
 
-    dev = qvirtio_mmio_init_device(MMIO_DEV_BASE_ADDR, MMIO_PAGE_SIZE);
+    dev = qvirtio_mmio_init_device(global_qtest, MMIO_DEV_BASE_ADDR,
+                                   MMIO_PAGE_SIZE);
     g_assert(dev != NULL);
     g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK);
 
Signature · 1 line
2.13.5
#55 lore raw

Re: [Qemu-devel] [PATCH v6 16/29] libqos: Use explicit QTestState for virtio operations

Quoted 44 lines · Eric Blake

Drop one more client of global_qtest by teaching all virtio test functionality to pass in an explicit QTestState in constructors, where it is then reused for later access. Adjust all callers. This gets us one step closer to eliminating implicit use of global_qtest.

---
 tests/libqos/virtio-mmio.h |  3 +-
 tests/libqos/virtio.h      |  5 ++-
 tests/libqos/virtio-mmio.c | 54 +++++++++++++++++---------------
 tests/libqos/virtio-pci.c  |  3 ++
 tests/libqos/virtio.c      | 77 ++++++++++++++++++++++++++--------------------
 tests/virtio-blk-test.c    |  3 +-
 6 files changed, 84 insertions(+), 61 deletions(-)
tests/libqos/virtio-mmio.h +2 -1
index e3e52b9ce1..bd01386054 100644
@@ -41,6 +41,7 @@ typedef struct QVirtioMMIODevice {
 
 extern const QVirtioBus qvirtio_mmio;
 
-QVirtioMMIODevice *qvirtio_mmio_init_device(uint64_t addr, uint32_t page_size);
+QVirtioMMIODevice *qvirtio_mmio_init_device(QTestState *qts, uint64_t addr,
+                                            uint32_t page_size);
 
 #endif
tests/libqos/virtio.h +1 -0
index 8fbcd1869c..d180d54fc4 100644
@@ -19,6 +19,7 @@ typedef struct QVirtioBus QVirtioBus;
 
 typedef struct QVirtioDevice {
     const QVirtioBus *bus;
+    QTestState *qts;
     /* Device type */
     uint16_t device_type;
 } QVirtioDevice;
@@ -35,12 +36,14 @@ typedef struct QVirtQueue {
     uint16_t last_used_idx;
     bool indirect;

tests/libqos/virtio.h typedef struct QVirtQueue { · line 47

Quoted 10 lines
tests/libqos/virtio.h +2 -0
     bool event;
+    QTestState *qts;
 } QVirtQueue;
 
 typedef struct QVRingIndirectDesc {
     uint64_t desc; /* This points to an array fo struct vring_desc */
     uint16_t index;
     uint16_t elem;
+    QTestState *qts;
 } QVRingIndirectDesc;

Adding QTestState to QVRingIndirectDesc and QVirtQueue sounds somewhat ugly to me. I think they should either rather have a pointer to the associated QVirtioDevice, or the functions where this is needed (qvring_init() for example) should get a "QTestState *" parameter instead.

Just my 0.02 €.

Thomas

#56 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH v6 16/29] libqos: Use explicit QTestState for virtio operations

Quoted 9 lines
 typedef struct QVirtioDevice {
     const QVirtioBus *bus;
tests/libqos/virtio.h +1 -0
+    QTestState *qts;
     /* Device type */
     uint16_t device_type;
 } QVirtioDevice;
@@ -35,12 +36,14 @@ typedef struct QVirtQueue {
     uint16_t last_used_idx;
     bool indirect;

tests/libqos/virtio.h typedef struct QVirtQueue { · line 47

Quoted 10 lines
tests/libqos/virtio.h +2 -0
     bool event;
+    QTestState *qts;
 } QVirtQueue;
 
 typedef struct QVRingIndirectDesc {
     uint64_t desc; /* This points to an array fo struct vring_desc */
     uint16_t index;
     uint16_t elem;
+    QTestState *qts;
 } QVRingIndirectDesc;

Adding QTestState to QVRingIndirectDesc and QVirtQueue sounds somewhat ugly to me. I think they should either rather have a pointer to the associated QVirtioDevice, or the functions where this is needed (qvring_init() for example) should get a "QTestState *" parameter instead.

I agree with Thomas and even extend it to QVirtioDevice. If there is a has-a hierarchy between libqos objects, only the topmost one (such as the virtio mmio bus device, and the PCI host bridge---or possibly even the machine object exclusively) should have a QTestState. Everyone else can access it implicitly through operations on its bus.

Test code on the other hand can use global_qtest implicitly when they prepare/read buffers that the devices do DMA from/to.

Paolo

Just my 0.02 €.

Thomas

author
#57 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH v6 16/29] libqos: Use explicit QTestState for virtio operations

Quoted 26 lines · Paolo Bonzini
Quoted 9 lines
 typedef struct QVirtioDevice {
     const QVirtioBus *bus;
tests/libqos/virtio.h +1 -0
+    QTestState *qts;
     /* Device type */
     uint16_t device_type;
 } QVirtioDevice;
@@ -35,12 +36,14 @@ typedef struct QVirtQueue {
     uint16_t last_used_idx;
     bool indirect;

tests/libqos/virtio.h typedef struct QVirtQueue { · line 47

Quoted 10 lines
tests/libqos/virtio.h +2 -0
     bool event;
+    QTestState *qts;
 } QVirtQueue;
 
 typedef struct QVRingIndirectDesc {
     uint64_t desc; /* This points to an array fo struct vring_desc */
     uint16_t index;
     uint16_t elem;
+    QTestState *qts;
 } QVRingIndirectDesc;

Adding QTestState to QVRingIndirectDesc and QVirtQueue sounds somewhat ugly to me. I think they should either rather have a pointer to the associated QVirtioDevice, or the functions where this is needed (qvring_init() for example) should get a "QTestState *" parameter instead.

Quoted 5 lines

I agree with Thomas and even extend it to QVirtioDevice. If there is a has-a hierarchy between libqos objects, only the topmost one (such as the virtio mmio bus device, and the PCI host bridge---or possibly even the machine object exclusively) should have a QTestState. Everyone else can access it implicitly through operations on its bus.

[Paolo, gmail is really messing up with your quoting style ;( ]

Okay, so if I understand correctly, at most a QVRingIndirectDesc can have a pointer back to the QVirtioDevice that owns it, and in turn the QVirtioDevice has a pointer back to the QPCIBus that the device is on, and anywhere that needs a QTestState follows the chain back to the QPCIBus to get it. I'll play with the idea, as it may still allow for more compact code than passing an explicit QTestState parameter through every call.

Quoted 3 lines

Test code on the other hand can use global_qtest implicitly when they prepare/read buffers that the devices do DMA from/to.

Not when I'm done - my next series gets rid of implicit global_qtest everywhere.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
author
#58 lore raw

PATCH v6 17/29 ahci-test: Drop dependence on global_qtest

In reply to Eric Blake

Managing parallel connections to two different monitors via the implicit global_qtest makes it hard to copy-and-paste code to tests that are not aware of the implicit state; the management of global_qtest is even harder to follow because it was masked behind set_context().

Instead, explicitly pass QTestState* around (generally, by reusing the member already present in ahci->parent QOSState), and call explicit qtest_* functions on all places that interact with a monitor.

We can assert that the conversion is correct by checking that global_qtest remains NULL throughout the test (a later patch that changes global_qtest to not be a public global variable will drop the assertions).

Bonus: there were several spots that were constructing a JSON string, then passing that through qmp() as the format, rather than directly using qmp() to construct the JSON. Fixing that gets us one step closer to enabling -Wformat checking on constructed JSON.

---
 tests/libqos/libqos.h    |  1 -
 tests/ahci-test.c        | 83 +++++++++++++++++++++++-------------------------
 tests/libqos/ahci.c      | 45 +++++++++++++-------------
 tests/libqos/libqos-pc.c |  2 +-
 tests/libqos/libqos.c    | 37 ++++++---------------
 5 files changed, 73 insertions(+), 95 deletions(-)
tests/libqos/libqos.h +0 -1
index 07d4b93d1d..9e020efb10 100644
@@ -29,7 +29,6 @@ void qtest_shutdown(QOSState *qs);
 bool have_qemu_img(void);
 void mkimg(const char *file, const char *fmt, unsigned size_mb);
 void mkqcow2(const char *file, unsigned size_mb);
-void set_context(QOSState *s);
 void migrate(QOSState *from, QOSState *to, const char *uri);
 void prepare_blkdebug_script(const char *debug_fn, const char *event);
 void generate_pattern(void *buffer, size_t len, size_t cycle_len);
tests/ahci-test.c +40 -43

218 lines not on this page · raw message

tests/libqos/ahci.c +23 -22

154 lines not on this page · raw message

tests/libqos/libqos-pc.c +1 -1
index b554758802..a9c1aceaa7 100644
@@ -25,7 +25,7 @@ QOSState *qtest_pc_boot(const char *cmdline_fmt, ...)
     qs = qtest_vboot(&qos_ops, cmdline_fmt, ap);
     va_end(ap);
 
-    qtest_irq_intercept_in(global_qtest, "ioapic");
+    qtest_irq_intercept_in(qs->qts, "ioapic");
 
     return qs;
 }
tests/libqos/libqos.c +9 -28
index 62d2f39b93..24e8156fe2 100644
@@ -79,34 +79,19 @@ void qtest_shutdown(QOSState *qs)
     }
 }
 
-void set_context(QOSState *s)
+static QDict *qmp_execute(QTestState *qts, const char *command)
 {
-    global_qtest = s->qts;
-}
-
-static QDict *qmp_execute(const char *command)
-{
-    char *fmt;
-    QDict *rsp;
-
-    fmt = g_strdup_printf("{ 'execute': '%s' }", command);
-    rsp = qmp(fmt);
-    g_free(fmt);
-
-    return rsp;
+    return qtest_qmp(qts, "{ 'execute': %s }", command);
 }
 
 void migrate(QOSState *from, QOSState *to, const char *uri)
 {
     const char *st;
-    char *s;
     QDict *rsp, *sub;
     bool running;
 
-    set_context(from);
-
     /* Is the machine currently running? */
-    rsp = qmp_execute("query-status");
+    rsp = qmp_execute(from->qts, "query-status");
     g_assert(qdict_haskey(rsp, "return"));
     sub = qdict_get_qdict(rsp, "return");
     g_assert(qdict_haskey(sub, "running"));
@@ -114,30 +99,27 @@ void migrate(QOSState *from, QOSState *to, const char *uri)
     QDECREF(rsp);
 
     /* Issue the migrate command. */
-    s = g_strdup_printf("{ 'execute': 'migrate',"
-                        "'arguments': { 'uri': '%s' } }",
-                        uri);
-    rsp = qmp(s);
-    g_free(s);
+    rsp = qtest_qmp(from->qts,
+                    "{ 'execute': 'migrate', 'arguments': { 'uri': %s }}",
+                    uri);
     g_assert(qdict_haskey(rsp, "return"));
     QDECREF(rsp);
 
     /* Wait for STOP event, but only if we were running: */
     if (running) {
-        qmp_eventwait("STOP");
+        qtest_qmp_eventwait(from->qts, "STOP");
     }
 
     /* If we were running, we can wait for an event. */
     if (running) {
         migrate_allocator(from->alloc, to->alloc);
-        set_context(to);
-        qmp_eventwait("RESUME");
+        qtest_qmp_eventwait(to->qts, "RESUME");
         return;
     }
 
     /* Otherwise, we need to wait: poll until migration is completed. */
     while (1) {
-        rsp = qmp_execute("query-migrate");
+        rsp = qmp_execute(from->qts, "query-migrate");
         g_assert(qdict_haskey(rsp, "return"));
         sub = qdict_get_qdict(rsp, "return");
         g_assert(qdict_haskey(sub, "status"));
@@ -160,7 +142,6 @@ void migrate(QOSState *from, QOSState *to, const char *uri)
     }
 
     migrate_allocator(from->alloc, to->alloc);
-    set_context(to);
 }
 
 bool have_qemu_img(void)
Signature · 1 line
2.13.5
Reviewed-by on v6 17/29
#59 lore raw

Re: [Qemu-devel] [PATCH v6 17/29] ahci-test: Drop dependence on global_qtest

Quoted 16 lines · Eric Blake

Managing parallel connections to two different monitors via the implicit global_qtest makes it hard to copy-and-paste code to tests that are not aware of the implicit state; the management of global_qtest is even harder to follow because it was masked behind set_context().

Instead, explicitly pass QTestState* around (generally, by reusing the member already present in ahci->parent QOSState), and call explicit qtest_* functions on all places that interact with a monitor.

We can assert that the conversion is correct by checking that global_qtest remains NULL throughout the test (a later patch that changes global_qtest to not be a public global variable will drop the assertions).

Quoted 7 lines

Bonus: there were several spots that were constructing a JSON string, then passing that through qmp() as the format, rather than directly using qmp() to construct the JSON. Fixing that gets us one step closer to enabling -Wformat checking on constructed JSON.

I think you've stumbled across why I was not a big fan of the implicit context versions of these functions.

Reviewed-by on v6 17/29
#60 lore raw

Re: [Qemu-devel] [PATCH v6 17/29] ahci-test: Drop dependence on global_qtest

In reply to Eric Blake
Quoted 22 lines · Eric Blake

Managing parallel connections to two different monitors via the implicit global_qtest makes it hard to copy-and-paste code to tests that are not aware of the implicit state; the management of global_qtest is even harder to follow because it was masked behind set_context().

Instead, explicitly pass QTestState* around (generally, by reusing the member already present in ahci->parent QOSState), and call explicit qtest_* functions on all places that interact with a monitor.

We can assert that the conversion is correct by checking that global_qtest remains NULL throughout the test (a later patch that changes global_qtest to not be a public global variable will drop the assertions).

Bonus: there were several spots that were constructing a JSON string, then passing that through qmp() as the format, rather than directly using qmp() to construct the JSON. Fixing that gets us one step closer to enabling -Wformat checking on constructed JSON.

Quoted 8 lines
---
 tests/libqos/libqos.h    |  1 -
 tests/ahci-test.c        | 83 +++++++++++++++++++++++-------------------------
 tests/libqos/ahci.c      | 45 +++++++++++++-------------
 tests/libqos/libqos-pc.c |  2 +-
 tests/libqos/libqos.c    | 37 ++++++---------------
 5 files changed, 73 insertions(+), 95 deletions(-)

Might be easier to review if you'd split the changes to libqos.c into a separate patch. But anyway:

author
#61 lore raw

Re: [Qemu-devel] [PATCH v6 17/29] ahci-test: Drop dependence on global_qtest

Quoted 16 lines · Thomas Huth
Quoted 7 lines · Eric Blake

Managing parallel connections to two different monitors via the implicit global_qtest makes it hard to copy-and-paste code to tests that are not aware of the implicit state; the management of global_qtest is even harder to follow because it was masked behind set_context().

Quoted 7 lines
---
 tests/libqos/libqos.h    |  1 -
 tests/ahci-test.c        | 83 +++++++++++++++++++++++-------------------------
 tests/libqos/ahci.c      | 45 +++++++++++++-------------
 tests/libqos/libqos-pc.c |  2 +-
 tests/libqos/libqos.c    | 37 ++++++---------------
 5 files changed, 73 insertions(+), 95 deletions(-)
Quoted 4 lines

Might be easier to review if you'd split the changes to libqos.c into a separate patch. But anyway:

I'll split it, even though it means dropping R-b on both halves of the split (so you can make sure the pieces still look sane).

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
author
#62 lore raw

PATCH v6 18/29 ivshmem-test: Drop dependence on global_qtest

In reply to Eric Blake

Managing parallel connections to two different monitors via the implicit global_qtest makes it hard to copy-and-paste code to tests that are not aware of the implicit state. Since we have already fixed qpci to avoid global_qtest, we can now simplify by not using global_qtest anywhere in ivshmem-test.

We can assert that the conversion is correct by checking that global_qtest remains NULL throughout the test (a later patch that changes global_qtest to not be a public global variable will drop the assertions).

---
 tests/ivshmem-test.c | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)
tests/ivshmem-test.c +2 -16
index 37763425ee..b9e0f573f6 100644
@@ -71,13 +71,10 @@ static const char* reg2str(enum Reg reg) {
 static inline unsigned in_reg(IVState *s, enum Reg reg)
 {
     const char *name = reg2str(reg);
-    QTestState *qtest = global_qtest;
     unsigned res;
 
-    global_qtest = s->qs->qts;
     res = qpci_io_readl(s->dev, s->reg_bar, reg);
     g_test_message("*%s -> %x\n", name, res);
-    global_qtest = qtest;
 
     return res;
 }
@@ -85,35 +82,25 @@ static inline unsigned in_reg(IVState *s, enum Reg reg)
 static inline void out_reg(IVState *s, enum Reg reg, unsigned v)
 {
     const char *name = reg2str(reg);
-    QTestState *qtest = global_qtest;
 
-    global_qtest = s->qs->qts;
     g_test_message("%x -> *%s\n", v, name);
     qpci_io_writel(s->dev, s->reg_bar, reg, v);
-    global_qtest = qtest;
 }
 
 static inline void read_mem(IVState *s, uint64_t off, void *buf, size_t len)
 {
-    QTestState *qtest = global_qtest;
-
-    global_qtest = s->qs->qts;
     qpci_memread(s->dev, s->mem_bar, off, buf, len);
-    global_qtest = qtest;
 }
 
 static inline void write_mem(IVState *s, uint64_t off,
                              const void *buf, size_t len)
 {
-    QTestState *qtest = global_qtest;
-
-    global_qtest = s->qs->qts;
     qpci_memwrite(s->dev, s->mem_bar, off, buf, len);
-    global_qtest = qtest;
 }
 
 static void cleanup_vm(IVState *s)
 {
+    assert(!global_qtest);
     g_free(s->dev);
     qtest_shutdown(s->qs);
 }
@@ -131,6 +118,7 @@ static void setup_vm_cmd(IVState *s, const char *cmd, bool msix)
         g_printerr("ivshmem-test tests are only available on x86 or ppc64\n");
         exit(EXIT_FAILURE);
     }
+    global_qtest = NULL;
     s->dev = get_device(s->qs->pcibus);
 
     s->reg_bar = qpci_iomap(s->dev, 0, &barsize);
@@ -353,7 +341,6 @@ static void test_ivshmem_server(bool msi)
     g_assert_cmpint(vm1, !=, vm2);
 
     /* check number of MSI-X vectors */
-    global_qtest = s1->qs->qts;
     if (msi) {
         ret = qpci_msix_table_size(s1->dev);
         g_assert_cmpuint(ret, ==, nvectors);
@@ -376,7 +363,6 @@ static void test_ivshmem_server(bool msi)
     g_assert_cmpuint(ret, !=, 0);
 
     /* ping vm1 -> vm2 on vector 1 */
-    global_qtest = s2->qs->qts;
     if (msi) {
         ret = qpci_msix_pending(s2->dev, 1);
         g_assert_cmpuint(ret, ==, 0);
Signature · 1 line
2.13.5
Reviewed-by on v6 18/29
#63 lore raw

Re: [Qemu-devel] [PATCH v6 18/29] ivshmem-test: Drop dependence on global_qtest

Quoted 89 lines · Eric Blake

Managing parallel connections to two different monitors via the implicit global_qtest makes it hard to copy-and-paste code to tests that are not aware of the implicit state. Since we have already fixed qpci to avoid global_qtest, we can now simplify by not using global_qtest anywhere in ivshmem-test.

We can assert that the conversion is correct by checking that global_qtest remains NULL throughout the test (a later patch that changes global_qtest to not be a public global variable will drop the assertions).

---
 tests/ivshmem-test.c | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)
tests/ivshmem-test.c +2 -15
index 37763425ee..b9e0f573f6 100644
@@ -71,13 +71,10 @@ static const char* reg2str(enum Reg reg) {
 static inline unsigned in_reg(IVState *s, enum Reg reg)
 {
     const char *name = reg2str(reg);
-    QTestState *qtest = global_qtest;
     unsigned res;
 
-    global_qtest = s->qs->qts;
     res = qpci_io_readl(s->dev, s->reg_bar, reg);
     g_test_message("*%s -> %x\n", name, res);
-    global_qtest = qtest;
 
     return res;
 }
@@ -85,35 +82,25 @@ static inline unsigned in_reg(IVState *s, enum Reg reg)
 static inline void out_reg(IVState *s, enum Reg reg, unsigned v)
 {
     const char *name = reg2str(reg);
-    QTestState *qtest = global_qtest;
 
-    global_qtest = s->qs->qts;
     g_test_message("%x -> *%s\n", v, name);
     qpci_io_writel(s->dev, s->reg_bar, reg, v);
-    global_qtest = qtest;
 }
 
 static inline void read_mem(IVState *s, uint64_t off, void *buf, size_t len)
 {
-    QTestState *qtest = global_qtest;
-
-    global_qtest = s->qs->qts;
     qpci_memread(s->dev, s->mem_bar, off, buf, len);
-    global_qtest = qtest;
 }
 
 static inline void write_mem(IVState *s, uint64_t off,
                              const void *buf, size_t len)
 {
-    QTestState *qtest = global_qtest;
-
-    global_qtest = s->qs->qts;
     qpci_memwrite(s->dev, s->mem_bar, off, buf, len);
-    global_qtest = qtest;
 }
 
 static void cleanup_vm(IVState *s)
 {
+    assert(!global_qtest);
     g_free(s->dev);
     qtest_shutdown(s->qs);
 }
@@ -131,6 +118,7 @@ static void setup_vm_cmd(IVState *s, const char *cmd, bool msix)
         g_printerr("ivshmem-test tests are only available on x86 or ppc64\n");
         exit(EXIT_FAILURE);
     }
+    global_qtest = NULL;
     s->dev = get_device(s->qs->pcibus);
 
     s->reg_bar = qpci_iomap(s->dev, 0, &barsize);
@@ -353,7 +341,6 @@ static void test_ivshmem_server(bool msi)
     g_assert_cmpint(vm1, !=, vm2);
 
     /* check number of MSI-X vectors */
-    global_qtest = s1->qs->qts;
     if (msi) {
         ret = qpci_msix_table_size(s1->dev);
         g_assert_cmpuint(ret, ==, nvectors);

tests/ivshmem-test.c static void test_ivshmem_server(bool msi) · line 368

Quoted 7 lines
tests/ivshmem-test.c +0 -1
@@ -376,7 +363,6 @@ static void test_ivshmem_server(bool msi)
     g_assert_cmpuint(ret, !=, 0);
 
     /* ping vm1 -> vm2 on vector 1 */
-    global_qtest = s2->qs->qts;
     if (msi) {
         ret = qpci_msix_pending(s2->dev, 1);
         g_assert_cmpuint(ret, ==, 0);

OMG, now I see why you want to get rid of this global_test stuff ... that was really ugly!

author
#64 lore raw

PATCH v6 19/29 postcopy-test: Drop dependence on global_qtest

In reply to Eric Blake

Managing parallel connections to two different monitors via the implicit global_qtest makes it hard to copy-and-paste code to tests that are not aware of the implicit state. We are already half-using the explicit APIs, so fix the remaining spots to also be explicit about which connection is in use, and avoid global_qtest.

We can assert that the conversion is correct by checking that global_qtest remains NULL throughout the test (a later patch that changes global_qtest to not be a public global variable will drop the assertions).

---
 tests/postcopy-test.c | 84 ++++++++++++++++++++++++---------------------------
 1 file changed, 40 insertions(+), 44 deletions(-)
tests/postcopy-test.c +40 -44
index 8142f2ab90..0e5fe20a83 100644
@@ -223,7 +223,7 @@ static void wait_for_serial(const char *side)
 /*
  * Events can get in the way of responses we are actually waiting for.
  */
-static QDict *return_or_event(QDict *response)
+static QDict *return_or_event(QTestState *qts, QDict *response)
 {
     const char *event_string;
     if (!qdict_haskey(response, "event")) {
@@ -236,7 +236,7 @@ static QDict *return_or_event(QDict *response)
         got_stop = true;
     }
     QDECREF(response);
-    return return_or_event(qtest_qmp_receive(global_qtest));
+    return return_or_event(qts, qtest_qmp_receive(qts));
 }
 
 
@@ -247,12 +247,13 @@ static QDict *return_or_event(QDict *response)
  * going postcopy.
  */
 
-static uint64_t get_migration_pass(void)
+static uint64_t get_migration_pass(QTestState *qts)
 {
     QDict *rsp, *rsp_return, *rsp_ram;
     uint64_t result;
 
-    rsp = return_or_event(qmp("{ 'execute': 'query-migrate' }"));
+    rsp = return_or_event(qts,
+                          qtest_qmp(qts, "{ 'execute': 'query-migrate' }"));
     rsp_return = qdict_get_qdict(rsp, "return");
     if (!qdict_haskey(rsp_return, "ram")) {
         /* Still in setup */
@@ -265,7 +266,7 @@ static uint64_t get_migration_pass(void)
     return result;
 }
 
-static void wait_for_migration_complete(void)
+static void wait_for_migration_complete(QTestState *qts)
 {
     QDict *rsp, *rsp_return;
     bool completed;
@@ -273,7 +274,8 @@ static void wait_for_migration_complete(void)
     do {
         const char *status;
 
-        rsp = return_or_event(qmp("{ 'execute': 'query-migrate' }"));
+        rsp = return_or_event(qts,
+                              qtest_qmp(qts, "{ 'execute': 'query-migrate' }"));
         rsp_return = qdict_get_qdict(rsp, "return");
         status = qdict_get_str(rsp_return, "status");
         completed = strcmp(status, "completed") == 0;
@@ -283,14 +285,14 @@ static void wait_for_migration_complete(void)
     } while (!completed);
 }
 
-static void wait_for_migration_pass(void)
+static void wait_for_migration_pass(QTestState *qts)
 {
-    uint64_t initial_pass = get_migration_pass();
+    uint64_t initial_pass = get_migration_pass(qts);
     uint64_t pass;
 
     /* Wait for the 1st sync */
     do {
-        initial_pass = get_migration_pass();
+        initial_pass = get_migration_pass(qts);
         if (got_stop || initial_pass) {
             break;
         }
@@ -299,11 +301,11 @@ static void wait_for_migration_pass(void)
 
     do {
         usleep(1000 * 100);
-        pass = get_migration_pass();
+        pass = get_migration_pass(qts);
     } while (pass == initial_pass && !got_stop);
 }
 
-static void check_guests_ram(void)
+static void check_guests_ram(QTestState *qts)
 {
     /* Our ASM test will have been incrementing one byte from each page from
      * 1MB to <100MB in order.
@@ -318,13 +320,13 @@ static void check_guests_ram(void)
     bool hit_edge = false;
     bool bad = false;
 
-    qtest_memread(global_qtest, start_address, &first_byte, 1);
+    qtest_memread(qts, start_address, &first_byte, 1);
     last_byte = first_byte;
 
     for (address = start_address + 4096; address < end_address; address += 4096)
     {
         uint8_t b;
-        qtest_memread(global_qtest, address, &b, 1);
+        qtest_memread(qts, address, &b, 1);
         if (b != last_byte) {
             if (((b + 1) % 256) == last_byte && !hit_edge) {
                 /* This is OK, the guest stopped at the point of
@@ -356,9 +358,9 @@ static void cleanup(const char *filename)
 static void test_migrate(void)
 {
     char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
-    QTestState *global = global_qtest, *from, *to;
+    QTestState *from, *to;
     unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d;
-    gchar *cmd, *cmd_src, *cmd_dst;
+    gchar *cmd_src, *cmd_dst;
     QDict *rsp;
 
     char *bootpath = g_strdup_printf("%s/bootsect", tmpfs);
@@ -401,24 +403,24 @@ static void test_migrate(void)
 
     g_free(bootpath);
 
-    from = qtest_start(cmd_src);
+    from = qtest_init(cmd_src);
     g_free(cmd_src);
 
     to = qtest_init(cmd_dst);
     g_free(cmd_dst);
 
-    global_qtest = from;
-    rsp = qmp("{ 'execute': 'migrate-set-capabilities',"
-                  "'arguments': { "
+    assert(!global_qtest);
+
+    rsp = qtest_qmp(from, "{ 'execute': 'migrate-set-capabilities',"
+                    "'arguments': { "
                       "'capabilities': [ {"
                           "'capability': 'postcopy-ram',"
                           "'state': true } ] } }");
     g_assert(qdict_haskey(rsp, "return"));
     QDECREF(rsp);
 
-    global_qtest = to;
-    rsp = qmp("{ 'execute': 'migrate-set-capabilities',"
-                  "'arguments': { "
+    rsp = qtest_qmp(to, "{ 'execute': 'migrate-set-capabilities',"
+                    "'arguments': { "
                       "'capabilities': [ {"
                           "'capability': 'postcopy-ram',"
                           "'state': true } ] } }");
@@ -429,15 +431,14 @@ static void test_migrate(void)
      * quickly, but that it doesn't complete precopy even on a slow
      * machine, so also set the downtime.
      */
-    global_qtest = from;
-    rsp = qmp("{ 'execute': 'migrate_set_speed',"
-              "'arguments': { 'value': 100000000 } }");
+    rsp = qtest_qmp(from, "{ 'execute': 'migrate_set_speed',"
+                    "'arguments': { 'value': 100000000 } }");
     g_assert(qdict_haskey(rsp, "return"));
     QDECREF(rsp);
 
     /* 1ms downtime - it should never finish precopy */
-    rsp = qmp("{ 'execute': 'migrate_set_downtime',"
-              "'arguments': { 'value': 0.001 } }");
+    rsp = qtest_qmp(from, "{ 'execute': 'migrate_set_downtime',"
+                    "'arguments': { 'value': 0.001 } }");
     g_assert(qdict_haskey(rsp, "return"));
     QDECREF(rsp);
 
@@ -445,35 +446,30 @@ static void test_migrate(void)
     /* Wait for the first serial output from the source */
     wait_for_serial("src_serial");
 
-    cmd = g_strdup_printf("{ 'execute': 'migrate',"
-                          "'arguments': { 'uri': '%s' } }",
-                          uri);
-    rsp = qmp(cmd);
-    g_free(cmd);
+    rsp = qtest_qmp(from,
+                    "{'execute': 'migrate', 'arguments': { 'uri': %s}}", uri);
     g_assert(qdict_haskey(rsp, "return"));
     QDECREF(rsp);
 
-    wait_for_migration_pass();
+    wait_for_migration_pass(from);
 
-    rsp = return_or_event(qmp("{ 'execute': 'migrate-start-postcopy' }"));
+    rsp = return_or_event(from,
+                          qtest_qmp(from,
+                                    "{ 'execute': 'migrate-start-postcopy' }"));
     g_assert(qdict_haskey(rsp, "return"));
     QDECREF(rsp);
 
     if (!got_stop) {
-        qmp_eventwait("STOP");
+        qtest_qmp_eventwait(from, "STOP");
     }
 
-    global_qtest = to;
-    qmp_eventwait("RESUME");
+    qtest_qmp_eventwait(to, "RESUME");
 
     wait_for_serial("dest_serial");
-    global_qtest = from;
-    wait_for_migration_complete();
+    wait_for_migration_complete(from);
 
     qtest_quit(from);
 
-    global_qtest = to;
-
     qtest_memread(to, start_address, &dest_byte_a, 1);
 
     /* Destination still running, wait for a byte to change */
@@ -482,19 +478,19 @@ static void test_migrate(void)
         usleep(10 * 1000);
     } while (dest_byte_a == dest_byte_b);
 
-    qmp_discard_response("{ 'execute' : 'stop'}");
+    qtest_qmp_discard_response(to, "{ 'execute' : 'stop'}");
     /* With it stopped, check nothing changes */
     qtest_memread(to, start_address, &dest_byte_c, 1);
     sleep(1);
     qtest_memread(to, start_address, &dest_byte_d, 1);
     g_assert_cmpint(dest_byte_c, ==, dest_byte_d);
 
-    check_guests_ram();
+    check_guests_ram(to);
 
     qtest_quit(to);
     g_free(uri);
 
-    global_qtest = global;
+    assert(!global_qtest);
 
     cleanup("bootsect");
     cleanup("migsocket");
Signature · 1 line
2.13.5
Reviewed-by on v6 19/29
#65 lore raw

Re: [Qemu-devel] [PATCH v6 19/29] postcopy-test: Drop dependence on global_qtest

Quoted 12 lines · Eric Blake

Managing parallel connections to two different monitors via the implicit global_qtest makes it hard to copy-and-paste code to tests that are not aware of the implicit state. We are already half-using the explicit APIs, so fix the remaining spots to also be explicit about which connection is in use, and avoid global_qtest.

We can assert that the conversion is correct by checking that global_qtest remains NULL throughout the test (a later patch that changes global_qtest to not be a public global variable will drop the assertions).

Quoted 4 lines
---
 tests/postcopy-test.c | 84 ++++++++++++++++++++++++---------------------------
 1 file changed, 40 insertions(+), 44 deletions(-)
author
#66 lore raw

PATCH v6 20/29 vhost-user-test: Drop dependence on global_qtest

In reply to Eric Blake

Managing parallel connections to two different monitors via the implicit global_qtest makes it hard to copy-and-paste code to tests that are not aware of the implicit state. Now that libqos is fully-explicit, it is easy to expand the rest of vhost-user-test to also use explicit state everywhere.

We can assert that the conversion is correct by checking that global_qtest remains NULL throughout the test (a later patch that changes global_qtest to not be a public global variable will drop the assertions).

---
 tests/vhost-user-test.c | 68 ++++++++++++++++++++++---------------------------
 1 file changed, 30 insertions(+), 38 deletions(-)
tests/vhost-user-test.c +30 -38
index 562bfaefd2..1e0c50d12a 100644
@@ -139,6 +139,7 @@ enum {
 };
 
 typedef struct TestServer {
+    QTestState *qts;
     QPCIBus *bus;
     gchar *socket_path;
     gchar *mig_path;
@@ -164,7 +165,7 @@ static void init_virtio_dev(TestServer *s)
     QVirtioPCIDevice *dev;
     uint32_t features;
 
-    s->bus = qpci_init_pc(global_qtest, NULL);
+    s->bus = qpci_init_pc(s->qts, NULL);
     g_assert_nonnull(s->bus);
 
     dev = qvirtio_pci_device_find(s->bus, VIRTIO_ID_NET);
@@ -236,8 +237,11 @@ static void read_guest_mem(const void *data)
         guest_mem += (s->memory.regions[i].mmap_offset / sizeof(*guest_mem));
 
         for (j = 0; j < 256; j++) {
-            uint32_t a = readl(s->memory.regions[i].guest_phys_addr + j*4);
-            uint32_t b = guest_mem[j];
+            uint32_t a, b;
+
+            a = qtest_readl(s->qts,
+                            s->memory.regions[i].guest_phys_addr + j * 4);
+            b = guest_mem[j];
 
             g_assert_cmpint(a, ==, b);
         }
@@ -515,6 +519,12 @@ static gboolean _test_server_free(TestServer *server)
 
 static void test_server_free(TestServer *server)
 {
+    assert(!global_qtest);
+    if (server->qts) {
+        qtest_quit(server->qts);
+        server->qts = NULL;
+    }
+
     g_idle_add((GSourceFunc)_test_server_free, server);
 }
 
@@ -626,7 +636,6 @@ static void test_migrate(void)
     TestServer *s = test_server_new("src");
     TestServer *dest = test_server_new("dest");
     char *uri = g_strdup_printf("%s%s", "unix:", dest->mig_path);
-    QTestState *global = global_qtest, *from, *to;
     GSource *source;
     gchar *cmd;
     QDict *rsp;
@@ -637,7 +646,7 @@ static void test_migrate(void)
     test_server_listen(dest);
 
     cmd = GET_QEMU_CMDE(s, 2, "", "");
-    from = qtest_start(cmd);
+    s->qts = qtest_init(cmd);
     g_free(cmd);
 
     init_virtio_dev(s);
@@ -646,7 +655,7 @@ static void test_migrate(void)
     g_assert_cmpint(size, ==, (2 * 1024 * 1024) / (VHOST_LOG_PAGE * 8));
 
     cmd = GET_QEMU_CMDE(dest, 2, "", " -incoming %s", uri);
-    to = qtest_init(cmd);
+    dest->qts = qtest_init(cmd);
     g_free(cmd);
 
     source = g_source_new(&test_migrate_source_funcs,
@@ -657,16 +666,13 @@ static void test_migrate(void)
 
     /* slow down migration to have time to fiddle with log */
     /* TODO: qtest could learn to break on some places */
-    rsp = qmp("{ 'execute': 'migrate_set_speed',"
-              "'arguments': { 'value': 10 } }");
+    rsp = qtest_qmp(s->qts, "{ 'execute': 'migrate_set_speed',"
+                    "'arguments': { 'value': 10 } }");
     g_assert(qdict_haskey(rsp, "return"));
     QDECREF(rsp);
 
-    cmd = g_strdup_printf("{ 'execute': 'migrate',"
-                          "'arguments': { 'uri': '%s' } }",
-                          uri);
-    rsp = qmp(cmd);
-    g_free(cmd);
+    rsp = qtest_qmp(s->qts,
+                    "{'execute': 'migrate', 'arguments': { 'uri': %s}}", uri);
     g_assert(qdict_haskey(rsp, "return"));
     QDECREF(rsp);
 
@@ -681,28 +687,23 @@ static void test_migrate(void)
     munmap(log, size);
 
     /* speed things up */
-    rsp = qmp("{ 'execute': 'migrate_set_speed',"
-              "'arguments': { 'value': 0 } }");
+    rsp = qtest_qmp(s->qts, "{ 'execute': 'migrate_set_speed',"
+                    "'arguments': { 'value': 0 } }");
     g_assert(qdict_haskey(rsp, "return"));
     QDECREF(rsp);
 
-    qmp_eventwait("STOP");
+    qtest_qmp_eventwait(s->qts, "STOP");
 
-    global_qtest = to;
-    qmp_eventwait("RESUME");
+    qtest_qmp_eventwait(dest->qts, "RESUME");
 
     read_guest_mem(dest);
 
     g_source_destroy(source);
     g_source_unref(source);
 
-    qtest_quit(to);
     test_server_free(dest);
-    qtest_quit(from);
     test_server_free(s);
     g_free(uri);
-
-    global_qtest = global;
 }
 
 static void wait_for_rings_started(TestServer *s, size_t count)
@@ -752,7 +753,7 @@ static void test_reconnect_subprocess(void)
 
     g_thread_new("connect", connect_thread, s);
     cmd = GET_QEMU_CMDE(s, 2, ",server", "");
-    qtest_start(cmd);
+    s->qts = qtest_init(cmd);
     g_free(cmd);
 
     init_virtio_dev(s);
@@ -766,7 +767,6 @@ static void test_reconnect_subprocess(void)
     wait_for_fds(s);
     wait_for_rings_started(s, 2);
 
-    qtest_end();
     test_server_free(s);
     return;
 }
@@ -788,14 +788,13 @@ static void test_connect_fail_subprocess(void)
     s->test_fail = true;
     g_thread_new("connect", connect_thread, s);
     cmd = GET_QEMU_CMDE(s, 2, ",server", "");
-    qtest_start(cmd);
+    s->qts = qtest_init(cmd);
     g_free(cmd);
 
     init_virtio_dev(s);
     wait_for_fds(s);
     wait_for_rings_started(s, 2);
 
-    qtest_end();
     test_server_free(s);
 }
 
@@ -816,14 +815,13 @@ static void test_flags_mismatch_subprocess(void)
     s->test_flags = TEST_FLAGS_DISCONNECT;
     g_thread_new("connect", connect_thread, s);
     cmd = GET_QEMU_CMDE(s, 2, ",server", "");
-    qtest_start(cmd);
+    s->qts = qtest_init(cmd);
     g_free(cmd);
 
     init_virtio_dev(s);
     wait_for_fds(s);
     wait_for_rings_started(s, 2);
 
-    qtest_end();
     test_server_free(s);
 }
 
@@ -888,13 +886,13 @@ static void test_multiqueue(void)
                           512, 512, root, s->chr_name,
                           s->socket_path, "", s->chr_name,
                           queues, queues * 2 + 2);
-    qtest_start(cmd);
+    s->qts = qtest_init(cmd);
     g_free(cmd);
 
-    bus = qpci_init_pc(global_qtest, NULL);
+    bus = qpci_init_pc(s->qts, NULL);
     dev = virtio_net_pci_init(bus, PCI_SLOT);
 
-    alloc = pc_alloc_init(global_qtest);
+    alloc = pc_alloc_init(s->qts);
     for (i = 0; i < queues * 2; i++) {
         vq[i] = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, alloc, i);
     }
@@ -911,14 +909,12 @@ static void test_multiqueue(void)
     g_free(dev->pdev);
     g_free(dev);
     qpci_free_pc(bus);
-    qtest_end();
 
     test_server_free(s);
 }
 
 int main(int argc, char **argv)
 {
-    QTestState *s = NULL;
     TestServer *server = NULL;
     const char *hugefs;
     char *qemu_cmd = NULL;
@@ -955,7 +951,7 @@ int main(int argc, char **argv)
 
     qemu_cmd = GET_QEMU_CMD(server);
 
-    s = qtest_start(qemu_cmd);
+    server->qts = qtest_init(qemu_cmd);
     g_free(qemu_cmd);
     init_virtio_dev(server);
 
@@ -976,10 +972,6 @@ int main(int argc, char **argv)
 
     ret = g_test_run();
 
-    if (s) {
-        qtest_quit(s);
-    }
-
     /* cleanup */
     test_server_free(server);
 
Signature · 1 line
2.13.5
Reviewed-by on v6 20/29
#67 lore raw

Re: [Qemu-devel] [PATCH v6 20/29] vhost-user-test: Drop dependence on global_qtest

Quoted 11 lines · Eric Blake

Managing parallel connections to two different monitors via the implicit global_qtest makes it hard to copy-and-paste code to tests that are not aware of the implicit state. Now that libqos is fully-explicit, it is easy to expand the rest of vhost-user-test to also use explicit state everywhere.

We can assert that the conversion is correct by checking that global_qtest remains NULL throughout the test (a later patch that changes global_qtest to not be a public global variable will drop the assertions).

Quoted 4 lines
---
 tests/vhost-user-test.c | 68 ++++++++++++++++++++++---------------------------
 1 file changed, 30 insertions(+), 38 deletions(-)
author
#68 lore raw

PATCH v6 21/29 qmp-test: Drop dependence on global_qtest

In reply to Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. Although qmp-test does not maintain parallel qtest connections, it was the last test assigning to global_qtest. It's just as easy to be explicit about the state; once all tests have been cleaned up, a later patch can then get rid of global_qtest and a layer of wrappers in libqtest.

---
 tests/qmp-test.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)
tests/qmp-test.c +18 -17
index 5d0260b2be..cf523b325e 100644
@@ -40,32 +40,32 @@ static void test_version(QObject *version)
     visit_free(v);
 }
 
-static void test_malformed(void)
+static void test_malformed(QTestState *qts)
 {
     QDict *resp;
 
     /* Not even a dictionary */
-    resp = qmp("null");
+    resp = qtest_qmp(qts, "null");
     g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
     QDECREF(resp);
 
     /* No "execute" key */
-    resp = qmp("{}");
+    resp = qtest_qmp(qts, "{}");
     g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
     QDECREF(resp);
 
     /* "execute" isn't a string */
-    resp = qmp("{ 'execute': true }");
+    resp = qtest_qmp(qts, "{ 'execute': true }");
     g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
     QDECREF(resp);
 
     /* "arguments" isn't a dictionary */
-    resp = qmp("{ 'execute': 'no-such-cmd', 'arguments': [] }");
+    resp = qtest_qmp(qts, "{ 'execute': 'no-such-cmd', 'arguments': [] }");
     g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
     QDECREF(resp);
 
     /* extra key */
-    resp = qmp("{ 'execute': 'no-such-cmd', 'extra': true }");
+    resp = qtest_qmp(qts, "{ 'execute': 'no-such-cmd', 'extra': true }");
     g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
     QDECREF(resp);
 }
@@ -74,11 +74,12 @@ static void test_qmp_protocol(void)
 {
     QDict *resp, *q, *ret;
     QList *capabilities;
+    QTestState *qts;
 
-    global_qtest = qtest_init_without_qmp_handshake(common_args);
+    qts = qtest_init_without_qmp_handshake(common_args);
 
     /* Test greeting */
-    resp = qmp_receive();
+    resp = qtest_qmp_receive(qts);
     q = qdict_get_qdict(resp, "QMP");
     g_assert(q);
     test_version(qdict_get(q, "version"));
@@ -87,46 +88,46 @@ static void test_qmp_protocol(void)
     QDECREF(resp);
 
     /* Test valid command before handshake */
-    resp = qmp("{ 'execute': 'query-version' }");
+    resp = qtest_qmp(qts, "{ 'execute': 'query-version' }");
     g_assert_cmpstr(get_error_class(resp), ==, "CommandNotFound");
     QDECREF(resp);
 
     /* Test malformed commands before handshake */
-    test_malformed();
+    test_malformed(qts);
 
     /* Test handshake */
-    resp = qmp("{ 'execute': 'qmp_capabilities' }");
+    resp = qtest_qmp(qts, "{ 'execute': 'qmp_capabilities' }");
     ret = qdict_get_qdict(resp, "return");
     g_assert(ret && !qdict_size(ret));
     QDECREF(resp);
 
     /* Test repeated handshake */
-    resp = qmp("{ 'execute': 'qmp_capabilities' }");
+    resp = qtest_qmp(qts, "{ 'execute': 'qmp_capabilities' }");
     g_assert_cmpstr(get_error_class(resp), ==, "CommandNotFound");
     QDECREF(resp);
 
     /* Test valid command */
-    resp = qmp("{ 'execute': 'query-version' }");
+    resp = qtest_qmp(qts, "{ 'execute': 'query-version' }");
     test_version(qdict_get(resp, "return"));
     QDECREF(resp);
 
     /* Test malformed commands */
-    test_malformed();
+    test_malformed(qts);
 
     /* Test 'id' */
-    resp = qmp("{ 'execute': 'query-name', 'id': 'cookie#1' }");
+    resp = qtest_qmp(qts, "{ 'execute': 'query-name', 'id': 'cookie#1' }");
     ret = qdict_get_qdict(resp, "return");
     g_assert(ret);
     g_assert_cmpstr(qdict_get_try_str(resp, "id"), ==, "cookie#1");
     QDECREF(resp);
 
     /* Test command failure with 'id' */
-    resp = qmp("{ 'execute': 'human-monitor-command', 'id': 2 }");
+    resp = qtest_qmp(qts, "{ 'execute': 'human-monitor-command', 'id': 2 }");
     g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
     g_assert_cmpint(qdict_get_int(resp, "id"), ==, 2);
     QDECREF(resp);
 
-    qtest_end();
+    qtest_quit(qts);
 }
 
 int main(int argc, char *argv[])
Signature · 1 line
2.13.5
Reviewed-by on v6 21/29
#69 lore raw

Re: [Qemu-devel] [PATCH v6 21/29] qmp-test: Drop dependence on global_qtest

Quoted 9 lines · Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. Although qmp-test does not maintain parallel qtest connections, it was the last test assigning to global_qtest. It's just as easy to be explicit about the state; once all tests have been cleaned up, a later patch can then get rid of global_qtest and a layer of wrappers in libqtest.

Quoted 4 lines
---
 tests/qmp-test.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)
author
#70 lore raw

PATCH v6 22/29 tests/boot-sector: Drop dependence on global_qtest

In reply to Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. Adjust the helper code to use explicit state instead, and update all callers.

Fix some trailing whitespace while touching the file.

---
 tests/boot-sector.h      | 6 ++++--
 tests/bios-tables-test.c | 2 +-
 tests/boot-sector.c      | 8 ++++----
 tests/pxe-test.c         | 2 +-
 tests/vmgenid-test.c     | 2 +-
 5 files changed, 11 insertions(+), 9 deletions(-)
tests/boot-sector.h +4 -2
index 35d61c7e2b..6ee6bb4d97 100644
@@ -5,7 +5,7 @@
  *
  * Authors:
  *  Michael S. Tsirkin <[email protected]>
- *  Victor Kaplansky <[email protected]>    
+ *  Victor Kaplansky <[email protected]>
  *
  * This work is licensed under the terms of the GNU GPL, version 2 or later.
  * See the COPYING file in the top-level directory.
@@ -14,11 +14,13 @@
 #ifndef TEST_BOOT_SECTOR_H
 #define TEST_BOOT_SECTOR_H
 
+#include "libqtest.h"
+
 /* Create boot disk file. fname must be a suitable string for mkstemp() */
 int boot_sector_init(char *fname);
 
 /* Loop until signature in memory is OK.  */
-void boot_sector_test(void);
+void boot_sector_test(QTestState *qts);
 
 /* unlink boot disk file.  */
 void boot_sector_cleanup(const char *fname);
tests/bios-tables-test.c +1 -1
index 564da45f65..bde62bf1cf 100644
@@ -632,7 +632,7 @@ static void test_acpi_one(const char *params, test_data *data)
 
     qtest_start(args);
 
-    boot_sector_test();
+    boot_sector_test(global_qtest);
 
     test_acpi_rsdp_address(data);
     test_acpi_rsdp_table(data);
tests/boot-sector.c +4 -4
index 9ee85370b0..8c8ac7f124 100644
@@ -5,7 +5,7 @@
  *
  * Authors:
  *  Michael S. Tsirkin <[email protected]>
- *  Victor Kaplansky <[email protected]>    
+ *  Victor Kaplansky <[email protected]>
  *
  * This work is licensed under the terms of the GNU GPL, version 2 or later.
  * See the COPYING file in the top-level directory.
@@ -130,7 +130,7 @@ int boot_sector_init(char *fname)
 }
 
 /* Loop until signature in memory is OK.  */
-void boot_sector_test(void)
+void boot_sector_test(QTestState *qts)
 {
     uint8_t signature_low;
     uint8_t signature_high;
@@ -146,8 +146,8 @@ void boot_sector_test(void)
      * instruction.
      */
     for (i = 0; i < TEST_CYCLES; ++i) {
-        signature_low = readb(SIGNATURE_ADDR);
-        signature_high = readb(SIGNATURE_ADDR + 1);
+        signature_low = qtest_readb(qts, SIGNATURE_ADDR);
+        signature_high = qtest_readb(qts, SIGNATURE_ADDR + 1);
         signature = (signature_high << 8) | signature_low;
         if (signature == SIGNATURE) {
             break;
tests/pxe-test.c +1 -1
index 0d70afccd6..e2d3853534 100644
@@ -31,7 +31,7 @@ static void test_pxe_one(const char *params, bool ipv6)
                            ipv6 ? "on" : "off", params);
 
     qtest_start(args);
-    boot_sector_test();
+    boot_sector_test(global_qtest);
     qtest_quit(global_qtest);
     g_free(args);
 }
tests/vmgenid-test.c +1 -1
index 3d5c1c3615..4bdc8a15e7 100644
@@ -47,7 +47,7 @@ static uint32_t acpi_find_vgia(void)
     int i;
 
     /* Wait for guest firmware to finish and start the payload. */
-    boot_sector_test();
+    boot_sector_test(global_qtest);
 
     /* Tables should be initialized now. */
     rsdp_offset = acpi_find_rsdp_address();
Signature · 1 line
2.13.5
Reviewed-by on v6 22/29
#71 lore raw

Re: [Qemu-devel] [PATCH v6 22/29] tests/boot-sector: Drop dependence on global_qtest

Quoted 7 lines · Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. Adjust the helper code to use explicit state instead, and update all callers.

Fix some trailing whitespace while touching the file.

Quoted 8 lines
---
 tests/boot-sector.h      | 6 ++++--
 tests/bios-tables-test.c | 2 +-
 tests/boot-sector.c      | 8 ++++----
 tests/pxe-test.c         | 2 +-
 tests/vmgenid-test.c     | 2 +-
 5 files changed, 11 insertions(+), 9 deletions(-)
Acked-by on v6 22/29
#72 lore raw

Re: [Qemu-devel] [PATCH v6 22/29] tests/boot-sector: Drop dependence on global_qtest

In reply to Eric Blake
Quoted 8 lines · Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. Adjust the helper code to use explicit state instead, and update all callers.

Fix some trailing whitespace while touching the file.

Quoted 111 lines
---
 tests/boot-sector.h      | 6 ++++--
 tests/bios-tables-test.c | 2 +-
 tests/boot-sector.c      | 8 ++++----
 tests/pxe-test.c         | 2 +-
 tests/vmgenid-test.c     | 2 +-
 5 files changed, 11 insertions(+), 9 deletions(-)
tests/boot-sector.h +4 -2
index 35d61c7e2b..6ee6bb4d97 100644
@@ -5,7 +5,7 @@
  *
  * Authors:
  *  Michael S. Tsirkin <[email protected]>
- *  Victor Kaplansky <[email protected]>    
+ *  Victor Kaplansky <[email protected]>
  *
  * This work is licensed under the terms of the GNU GPL, version 2 or later.
  * See the COPYING file in the top-level directory.
@@ -14,11 +14,13 @@
 #ifndef TEST_BOOT_SECTOR_H
 #define TEST_BOOT_SECTOR_H
 
+#include "libqtest.h"
+
 /* Create boot disk file. fname must be a suitable string for mkstemp() */
 int boot_sector_init(char *fname);
 
 /* Loop until signature in memory is OK.  */
-void boot_sector_test(void);
+void boot_sector_test(QTestState *qts);
 
 /* unlink boot disk file.  */
 void boot_sector_cleanup(const char *fname);
tests/bios-tables-test.c +1 -1
index 564da45f65..bde62bf1cf 100644
@@ -632,7 +632,7 @@ static void test_acpi_one(const char *params, test_data *data)
 
     qtest_start(args);
 
-    boot_sector_test();
+    boot_sector_test(global_qtest);
 
     test_acpi_rsdp_address(data);
     test_acpi_rsdp_table(data);
tests/boot-sector.c +4 -4
index 9ee85370b0..8c8ac7f124 100644
@@ -5,7 +5,7 @@
  *
  * Authors:
  *  Michael S. Tsirkin <[email protected]>
- *  Victor Kaplansky <[email protected]>    
+ *  Victor Kaplansky <[email protected]>
  *
  * This work is licensed under the terms of the GNU GPL, version 2 or later.
  * See the COPYING file in the top-level directory.
@@ -130,7 +130,7 @@ int boot_sector_init(char *fname)
 }
 
 /* Loop until signature in memory is OK.  */
-void boot_sector_test(void)
+void boot_sector_test(QTestState *qts)
 {
     uint8_t signature_low;
     uint8_t signature_high;
@@ -146,8 +146,8 @@ void boot_sector_test(void)
      * instruction.
      */
     for (i = 0; i < TEST_CYCLES; ++i) {
-        signature_low = readb(SIGNATURE_ADDR);
-        signature_high = readb(SIGNATURE_ADDR + 1);
+        signature_low = qtest_readb(qts, SIGNATURE_ADDR);
+        signature_high = qtest_readb(qts, SIGNATURE_ADDR + 1);
         signature = (signature_high << 8) | signature_low;
         if (signature == SIGNATURE) {
             break;
tests/pxe-test.c +1 -1
index 0d70afccd6..e2d3853534 100644
@@ -31,7 +31,7 @@ static void test_pxe_one(const char *params, bool ipv6)
                            ipv6 ? "on" : "off", params);
 
     qtest_start(args);
-    boot_sector_test();
+    boot_sector_test(global_qtest);
     qtest_quit(global_qtest);
     g_free(args);
 }
tests/vmgenid-test.c +1 -1
index 3d5c1c3615..4bdc8a15e7 100644
@@ -47,7 +47,7 @@ static uint32_t acpi_find_vgia(void)
     int i;
 
     /* Wait for guest firmware to finish and start the payload. */
-    boot_sector_test();
+    boot_sector_test(global_qtest);
 
     /* Tables should be initialized now. */
     rsdp_offset = acpi_find_rsdp_address();
Signature · 1 line
2.13.5
author
#73 lore raw

PATCH v6 23/29 tests/acpi-utils: Drop dependence on global_qtest

In reply to Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. Adjust the helper code to use explicit state instead, and update all callers.

---
 tests/acpi-utils.h       |  65 +++++++++----------
 tests/acpi-utils.c       |  19 +++---
 tests/bios-tables-test.c | 161 ++++++++++++++++++++++++-----------------------
 tests/vmgenid-test.c     |  18 +++---
 4 files changed, 133 insertions(+), 130 deletions(-)
tests/acpi-utils.h +33 -32
index f8d87236c6..8ec83f71b1 100644
@@ -28,20 +28,20 @@ typedef struct {
     bool tmp_files_retain;   /* do not delete the temp asl/aml */
 } AcpiSdtTable;
 
-#define ACPI_READ_FIELD(field, addr)           \
+#define ACPI_READ_FIELD(qts, field, addr)      \
     do {                                       \
         switch (sizeof(field)) {               \
         case 1:                                \
-            field = readb(addr);               \
+            field = qtest_readb(qts, addr);    \
             break;                             \
         case 2:                                \
-            field = readw(addr);               \
+            field = qtest_readw(qts, addr);    \
             break;                             \
         case 4:                                \
-            field = readl(addr);               \
+            field = qtest_readl(qts, addr);    \
             break;                             \
         case 8:                                \
-            field = readq(addr);               \
+            field = qtest_readq(qts, addr);    \
             break;                             \
         default:                               \
             g_assert(false);                   \
@@ -49,28 +49,28 @@ typedef struct {
         addr += sizeof(field);                  \
     } while (0);
 
-#define ACPI_READ_ARRAY_PTR(arr, length, addr)  \
-    do {                                        \
-        int idx;                                \
-        for (idx = 0; idx < length; ++idx) {    \
-            ACPI_READ_FIELD(arr[idx], addr);    \
-        }                                       \
+#define ACPI_READ_ARRAY_PTR(qts, arr, length, addr)      \
+    do {                                                 \
+        int idx;                                         \
+        for (idx = 0; idx < length; ++idx) {             \
+            ACPI_READ_FIELD(qts, arr[idx], addr);        \
+        }                                                \
     } while (0);
 
-#define ACPI_READ_ARRAY(arr, addr)                               \
-    ACPI_READ_ARRAY_PTR(arr, sizeof(arr) / sizeof(arr[0]), addr)
+#define ACPI_READ_ARRAY(qts, arr, addr)                                 \
+    ACPI_READ_ARRAY_PTR(qts, arr, sizeof(arr) / sizeof(arr[0]), addr)
 
-#define ACPI_READ_TABLE_HEADER(table, addr)                      \
+#define ACPI_READ_TABLE_HEADER(qts, table, addr)                 \
     do {                                                         \
-        ACPI_READ_FIELD((table)->signature, addr);               \
-        ACPI_READ_FIELD((table)->length, addr);                  \
-        ACPI_READ_FIELD((table)->revision, addr);                \
-        ACPI_READ_FIELD((table)->checksum, addr);                \
-        ACPI_READ_ARRAY((table)->oem_id, addr);                  \
-        ACPI_READ_ARRAY((table)->oem_table_id, addr);            \
-        ACPI_READ_FIELD((table)->oem_revision, addr);            \
-        ACPI_READ_ARRAY((table)->asl_compiler_id, addr);         \
-        ACPI_READ_FIELD((table)->asl_compiler_revision, addr);   \
+        ACPI_READ_FIELD(qts, (table)->signature, addr);          \
+        ACPI_READ_FIELD(qts, (table)->length, addr);             \
+        ACPI_READ_FIELD(qts, (table)->revision, addr);           \
+        ACPI_READ_FIELD(qts, (table)->checksum, addr);           \
+        ACPI_READ_ARRAY(qts, (table)->oem_id, addr);             \
+        ACPI_READ_ARRAY(qts, (table)->oem_table_id, addr);       \
+        ACPI_READ_FIELD(qts, (table)->oem_revision, addr);       \
+        ACPI_READ_ARRAY(qts, (table)->asl_compiler_id, addr);    \
+        ACPI_READ_FIELD(qts, (table)->asl_compiler_revision, addr);     \
     } while (0);
 
 #define ACPI_ASSERT_CMP(actual, expected) do { \
@@ -87,18 +87,19 @@ typedef struct {
     g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
 } while (0)
 
-#define ACPI_READ_GENERIC_ADDRESS(field, addr)       \
-    do {                                             \
-        ACPI_READ_FIELD((field).space_id, addr);     \
-        ACPI_READ_FIELD((field).bit_width, addr);    \
-        ACPI_READ_FIELD((field).bit_offset, addr);   \
-        ACPI_READ_FIELD((field).access_width, addr); \
-        ACPI_READ_FIELD((field).address, addr);      \
+#define ACPI_READ_GENERIC_ADDRESS(qts, field, addr)       \
+    do {                                                  \
+        ACPI_READ_FIELD(qts, (field).space_id, addr);     \
+        ACPI_READ_FIELD(qts, (field).bit_width, addr);    \
+        ACPI_READ_FIELD(qts, (field).bit_offset, addr);   \
+        ACPI_READ_FIELD(qts, (field).access_width, addr); \
+        ACPI_READ_FIELD(qts, (field).address, addr);      \
     } while (0);
 
 
 uint8_t acpi_calc_checksum(const uint8_t *data, int len);
-uint32_t acpi_find_rsdp_address(void);
-void acpi_parse_rsdp_table(uint32_t addr, AcpiRsdpDescriptor *rsdp_table);
+uint32_t acpi_find_rsdp_address(QTestState *qts);
+void acpi_parse_rsdp_table(QTestState *qts, uint32_t addr,
+                           AcpiRsdpDescriptor *rsdp_table);
 
 #endif  /* TEST_ACPI_UTILS_H */
tests/acpi-utils.c +10 -9
index 41dc1ea9b4..6dc8ca1a8c 100644
@@ -32,7 +32,7 @@ uint8_t acpi_calc_checksum(const uint8_t *data, int len)
     return sum;
 }
 
-uint32_t acpi_find_rsdp_address(void)
+uint32_t acpi_find_rsdp_address(QTestState *qts)
 {
     uint32_t off;
 
@@ -42,7 +42,7 @@ uint32_t acpi_find_rsdp_address(void)
         int i;
 
         for (i = 0; i < sizeof sig - 1; ++i) {
-            sig[i] = readb(off + i);
+            sig[i] = qtest_readb(qts, off + i);
         }
 
         if (!memcmp(sig, "RSD PTR ", sizeof sig)) {
@@ -52,14 +52,15 @@ uint32_t acpi_find_rsdp_address(void)
     return off;
 }
 
-void acpi_parse_rsdp_table(uint32_t addr, AcpiRsdpDescriptor *rsdp_table)
+void acpi_parse_rsdp_table(QTestState *qts, uint32_t addr,
+                           AcpiRsdpDescriptor *rsdp_table)
 {
-    ACPI_READ_FIELD(rsdp_table->signature, addr);
+    ACPI_READ_FIELD(qts, rsdp_table->signature, addr);
     ACPI_ASSERT_CMP64(rsdp_table->signature, "RSD PTR ");
 
-    ACPI_READ_FIELD(rsdp_table->checksum, addr);
-    ACPI_READ_ARRAY(rsdp_table->oem_id, addr);
-    ACPI_READ_FIELD(rsdp_table->revision, addr);
-    ACPI_READ_FIELD(rsdp_table->rsdt_physical_address, addr);
-    ACPI_READ_FIELD(rsdp_table->length, addr);
+    ACPI_READ_FIELD(qts, rsdp_table->checksum, addr);
+    ACPI_READ_ARRAY(qts, rsdp_table->oem_id, addr);
+    ACPI_READ_FIELD(qts, rsdp_table->revision, addr);
+    ACPI_READ_FIELD(qts, rsdp_table->rsdt_physical_address, addr);
+    ACPI_READ_FIELD(qts, rsdp_table->length, addr);
 }
tests/bios-tables-test.c +81 -80

228 lines not on this page · raw message

tests/vmgenid-test.c +9 -9
index 4bdc8a15e7..73473162d0 100644
@@ -50,15 +50,15 @@ static uint32_t acpi_find_vgia(void)
     boot_sector_test(global_qtest);
 
     /* Tables should be initialized now. */
-    rsdp_offset = acpi_find_rsdp_address();
+    rsdp_offset = acpi_find_rsdp_address(global_qtest);
 
     g_assert_cmphex(rsdp_offset, <, RSDP_ADDR_INVALID);
 
-    acpi_parse_rsdp_table(rsdp_offset, &rsdp_table);
+    acpi_parse_rsdp_table(global_qtest, rsdp_offset, &rsdp_table);
 
     rsdt = rsdp_table.rsdt_physical_address;
     /* read the header */
-    ACPI_READ_TABLE_HEADER(&rsdt_table, rsdt);
+    ACPI_READ_TABLE_HEADER(global_qtest, &rsdt_table, rsdt);
     ACPI_ASSERT_CMP(rsdt_table.signature, "RSDT");
 
     /* compute the table entries in rsdt */
@@ -68,21 +68,21 @@ static uint32_t acpi_find_vgia(void)
 
     /* get the addresses of the tables pointed by rsdt */
     tables = g_new0(uint32_t, tables_nr);
-    ACPI_READ_ARRAY_PTR(tables, tables_nr, rsdt);
+    ACPI_READ_ARRAY_PTR(global_qtest, tables, tables_nr, rsdt);
 
     for (i = 0; i < tables_nr; i++) {
-        ACPI_READ_TABLE_HEADER(&ssdt_table, tables[i]);
+        ACPI_READ_TABLE_HEADER(global_qtest, &ssdt_table, tables[i]);
         if (!strncmp((char *)ssdt_table.oem_table_id, "VMGENID", 7)) {
             /* the first entry in the table should be VGIA
              * That's all we need
              */
-            ACPI_READ_FIELD(vgid_table.name_op, tables[i]);
+            ACPI_READ_FIELD(global_qtest, vgid_table.name_op, tables[i]);
             g_assert(vgid_table.name_op == 0x08);  /* name */
-            ACPI_READ_ARRAY(vgid_table.vgia, tables[i]);
+            ACPI_READ_ARRAY(global_qtest, vgid_table.vgia, tables[i]);
             g_assert(memcmp(vgid_table.vgia, "VGIA", 4) == 0);
-            ACPI_READ_FIELD(vgid_table.val_op, tables[i]);
+            ACPI_READ_FIELD(global_qtest, vgid_table.val_op, tables[i]);
             g_assert(vgid_table.val_op == 0x0C);  /* dword */
-            ACPI_READ_FIELD(vgid_table.vgia_val, tables[i]);
+            ACPI_READ_FIELD(global_qtest, vgid_table.vgia_val, tables[i]);
             /* The GUID is written at a fixed offset into the fw_cfg file
              * in order to implement the "OVMF SDT Header probe suppressor"
              * see docs/specs/vmgenid.txt for more details
Signature · 1 line
2.13.5
#74 lore raw

Re: [Qemu-devel] [PATCH v6 23/29] tests/acpi-utils: Drop dependence on global_qtest

Quoted 12 lines · Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. Adjust the helper code to use explicit state instead, and update all callers.

---
 tests/acpi-utils.h       |  65 +++++++++----------
 tests/acpi-utils.c       |  19 +++---
 tests/bios-tables-test.c | 161 ++++++++++++++++++++++++-----------------------
 tests/vmgenid-test.c     |  18 +++---
 4 files changed, 133 insertions(+), 130 deletions(-)

[...]

Quoted 19 lines
tests/bios-tables-test.c +2 -2
@@ -87,7 +87,7 @@ static void test_acpi_rsdp_table(test_data *data)
     AcpiRsdpDescriptor *rsdp_table = &data->rsdp_table;
     uint32_t addr = data->rsdp_addr;
 
-    acpi_parse_rsdp_table(addr, rsdp_table);
+    acpi_parse_rsdp_table(global_qtest, addr, rsdp_table);
 
     /* rsdp checksum is not for the whole table, but for the first 20 bytes */
     g_assert(!acpi_calc_checksum((uint8_t *)rsdp_table, 20));
@@ -102,7 +102,7 @@ static void test_acpi_rsdt_table(test_data *data)
     uint8_t checksum;
 
     /* read the header */
-    ACPI_READ_TABLE_HEADER(rsdt_table, addr);
+    ACPI_READ_TABLE_HEADER(global_qtest, rsdt_table, addr);
     ACPI_ASSERT_CMP(rsdt_table->signature, "RSDT");
 
     /* compute the table entries in rsdt */

tests/bios-tables-test.c static void test_acpi_rsdt_table(test_data *data) · line 118

Quoted 8 lines
tests/bios-tables-test.c +1 -1
@@ -112,7 +112,7 @@ static void test_acpi_rsdt_table(test_data *data)
 
     /* get the addresses of the tables pointed by rsdt */
     tables = g_new0(uint32_t, tables_nr);
-    ACPI_READ_ARRAY_PTR(tables, tables_nr, addr);
+    ACPI_READ_ARRAY_PTR(global_qtest, tables, tables_nr, addr);
 
     checksum = acpi_calc_checksum((uint8_t *)rsdt_table, rsdt_table->length) +
                acpi_calc_checksum((uint8_t *)tables,

Wouldn't it be better to use a "QTestState *qts = global_qtest" variable in this function, like you do it below in test_acpi_fadt_table()? Or even pass it via test_data already? Otherwise you've got to change all lines again when finally getting rid of global_qtest ...

Quoted 126 lines
tests/bios-tables-test.c +54 -57
@@ -128,63 +128,64 @@ static void test_acpi_fadt_table(test_data *data)
 {
     AcpiFadtDescriptorRev3 *fadt_table = &data->fadt_table;
     uint32_t addr;
+    QTestState *qts = global_qtest;
 
     /* FADT table comes first */
     addr = data->rsdt_tables_addr[0];
-    ACPI_READ_TABLE_HEADER(fadt_table, addr);
+    ACPI_READ_TABLE_HEADER(qts, fadt_table, addr);
 
-    ACPI_READ_FIELD(fadt_table->firmware_ctrl, addr);
-    ACPI_READ_FIELD(fadt_table->dsdt, addr);
-    ACPI_READ_FIELD(fadt_table->model, addr);
-    ACPI_READ_FIELD(fadt_table->reserved1, addr);
-    ACPI_READ_FIELD(fadt_table->sci_int, addr);
-    ACPI_READ_FIELD(fadt_table->smi_cmd, addr);
-    ACPI_READ_FIELD(fadt_table->acpi_enable, addr);
-    ACPI_READ_FIELD(fadt_table->acpi_disable, addr);
-    ACPI_READ_FIELD(fadt_table->S4bios_req, addr);
-    ACPI_READ_FIELD(fadt_table->reserved2, addr);
-    ACPI_READ_FIELD(fadt_table->pm1a_evt_blk, addr);
-    ACPI_READ_FIELD(fadt_table->pm1b_evt_blk, addr);
-    ACPI_READ_FIELD(fadt_table->pm1a_cnt_blk, addr);
-    ACPI_READ_FIELD(fadt_table->pm1b_cnt_blk, addr);
-    ACPI_READ_FIELD(fadt_table->pm2_cnt_blk, addr);
-    ACPI_READ_FIELD(fadt_table->pm_tmr_blk, addr);
-    ACPI_READ_FIELD(fadt_table->gpe0_blk, addr);
-    ACPI_READ_FIELD(fadt_table->gpe1_blk, addr);
-    ACPI_READ_FIELD(fadt_table->pm1_evt_len, addr);
-    ACPI_READ_FIELD(fadt_table->pm1_cnt_len, addr);
-    ACPI_READ_FIELD(fadt_table->pm2_cnt_len, addr);
-    ACPI_READ_FIELD(fadt_table->pm_tmr_len, addr);
-    ACPI_READ_FIELD(fadt_table->gpe0_blk_len, addr);
-    ACPI_READ_FIELD(fadt_table->gpe1_blk_len, addr);
-    ACPI_READ_FIELD(fadt_table->gpe1_base, addr);
-    ACPI_READ_FIELD(fadt_table->reserved3, addr);
-    ACPI_READ_FIELD(fadt_table->plvl2_lat, addr);
-    ACPI_READ_FIELD(fadt_table->plvl3_lat, addr);
-    ACPI_READ_FIELD(fadt_table->flush_size, addr);
-    ACPI_READ_FIELD(fadt_table->flush_stride, addr);
-    ACPI_READ_FIELD(fadt_table->duty_offset, addr);
-    ACPI_READ_FIELD(fadt_table->duty_width, addr);
-    ACPI_READ_FIELD(fadt_table->day_alrm, addr);
-    ACPI_READ_FIELD(fadt_table->mon_alrm, addr);
-    ACPI_READ_FIELD(fadt_table->century, addr);
-    ACPI_READ_FIELD(fadt_table->boot_flags, addr);
-    ACPI_READ_FIELD(fadt_table->reserved, addr);
-    ACPI_READ_FIELD(fadt_table->flags, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->reset_register, addr);
-    ACPI_READ_FIELD(fadt_table->reset_value, addr);
-    ACPI_READ_FIELD(fadt_table->arm_boot_flags, addr);
-    ACPI_READ_FIELD(fadt_table->minor_revision, addr);
-    ACPI_READ_FIELD(fadt_table->x_facs, addr);
-    ACPI_READ_FIELD(fadt_table->x_dsdt, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm1a_event_block, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm1b_event_block, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm1a_control_block, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm1b_control_block, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm2_control_block, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm_timer_block, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->xgpe0_block, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->xgpe1_block, addr);
+    ACPI_READ_FIELD(qts, fadt_table->firmware_ctrl, addr);
+    ACPI_READ_FIELD(qts, fadt_table->dsdt, addr);
+    ACPI_READ_FIELD(qts, fadt_table->model, addr);
+    ACPI_READ_FIELD(qts, fadt_table->reserved1, addr);
+    ACPI_READ_FIELD(qts, fadt_table->sci_int, addr);
+    ACPI_READ_FIELD(qts, fadt_table->smi_cmd, addr);
+    ACPI_READ_FIELD(qts, fadt_table->acpi_enable, addr);
+    ACPI_READ_FIELD(qts, fadt_table->acpi_disable, addr);
+    ACPI_READ_FIELD(qts, fadt_table->S4bios_req, addr);
+    ACPI_READ_FIELD(qts, fadt_table->reserved2, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm1a_evt_blk, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm1b_evt_blk, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm1a_cnt_blk, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm1b_cnt_blk, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm2_cnt_blk, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm_tmr_blk, addr);
+    ACPI_READ_FIELD(qts, fadt_table->gpe0_blk, addr);
+    ACPI_READ_FIELD(qts, fadt_table->gpe1_blk, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm1_evt_len, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm1_cnt_len, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm2_cnt_len, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm_tmr_len, addr);
+    ACPI_READ_FIELD(qts, fadt_table->gpe0_blk_len, addr);
+    ACPI_READ_FIELD(qts, fadt_table->gpe1_blk_len, addr);
+    ACPI_READ_FIELD(qts, fadt_table->gpe1_base, addr);
+    ACPI_READ_FIELD(qts, fadt_table->reserved3, addr);
+    ACPI_READ_FIELD(qts, fadt_table->plvl2_lat, addr);
+    ACPI_READ_FIELD(qts, fadt_table->plvl3_lat, addr);
+    ACPI_READ_FIELD(qts, fadt_table->flush_size, addr);
+    ACPI_READ_FIELD(qts, fadt_table->flush_stride, addr);
+    ACPI_READ_FIELD(qts, fadt_table->duty_offset, addr);
+    ACPI_READ_FIELD(qts, fadt_table->duty_width, addr);
+    ACPI_READ_FIELD(qts, fadt_table->day_alrm, addr);
+    ACPI_READ_FIELD(qts, fadt_table->mon_alrm, addr);
+    ACPI_READ_FIELD(qts, fadt_table->century, addr);
+    ACPI_READ_FIELD(qts, fadt_table->boot_flags, addr);
+    ACPI_READ_FIELD(qts, fadt_table->reserved, addr);
+    ACPI_READ_FIELD(qts, fadt_table->flags, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->reset_register, addr);
+    ACPI_READ_FIELD(qts, fadt_table->reset_value, addr);
+    ACPI_READ_FIELD(qts, fadt_table->arm_boot_flags, addr);
+    ACPI_READ_FIELD(qts, fadt_table->minor_revision, addr);
+    ACPI_READ_FIELD(qts, fadt_table->x_facs, addr);
+    ACPI_READ_FIELD(qts, fadt_table->x_dsdt, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->xpm1a_event_block, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->xpm1b_event_block, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->xpm1a_control_block, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->xpm1b_control_block, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->xpm2_control_block, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->xpm_timer_block, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->xgpe0_block, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->xgpe1_block, addr);
 
     ACPI_ASSERT_CMP(fadt_table->signature, "FACP");
     g_assert(!acpi_calc_checksum((uint8_t *)fadt_table, fadt_table->length));
@@ -195,13 +196,13 @@ static void test_acpi_facs_table(test_data *data)
     AcpiFacsDescriptorRev1 *facs_table = &data->facs_table;
     uint32_t addr = data->fadt_table.firmware_ctrl;
 
-    ACPI_READ_FIELD(facs_table->signature, addr);
-    ACPI_READ_FIELD(facs_table->length, addr);
-    ACPI_READ_FIELD(facs_table->hardware_signature, addr);
-    ACPI_READ_FIELD(facs_table->firmware_waking_vector, addr);

tests/bios-tables-test.c static void test_acpi_facs_table(test_data *data) · line 205

Quoted 10 lines
tests/bios-tables-test.c +7 -3
-    ACPI_READ_FIELD(facs_table->global_lock, addr);
-    ACPI_READ_FIELD(facs_table->flags, addr);
-    ACPI_READ_ARRAY(facs_table->resverved3, addr);
+    ACPI_READ_FIELD(global_qtest, facs_table->signature, addr);
+    ACPI_READ_FIELD(global_qtest, facs_table->length, addr);
+    ACPI_READ_FIELD(global_qtest, facs_table->hardware_signature, addr);
+    ACPI_READ_FIELD(global_qtest, facs_table->firmware_waking_vector, addr);
+    ACPI_READ_FIELD(global_qtest, facs_table->global_lock, addr);
+    ACPI_READ_FIELD(global_qtest, facs_table->flags, addr);
+    ACPI_READ_ARRAY(global_qtest, facs_table->resverved3, addr);

Dito, i.e. use a local "QTestState *qts = global_qtest" variable instead?

Same comment applies to the other functions where you were using global_test like this.

Thomas

Acked-by on v6 23/29
#75 lore raw

Re: [Qemu-devel] [PATCH v6 23/29] tests/acpi-utils: Drop dependence on global_qtest

In reply to Eric Blake
Quoted 6 lines · Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. Adjust the helper code to use explicit state instead, and update all callers.

Quoted 452 lines
---
 tests/acpi-utils.h       |  65 +++++++++----------
 tests/acpi-utils.c       |  19 +++---
 tests/bios-tables-test.c | 161 ++++++++++++++++++++++++-----------------------
 tests/vmgenid-test.c     |  18 +++---
 4 files changed, 133 insertions(+), 130 deletions(-)
tests/acpi-utils.h +33 -32
index f8d87236c6..8ec83f71b1 100644
@@ -28,20 +28,20 @@ typedef struct {
     bool tmp_files_retain;   /* do not delete the temp asl/aml */
 } AcpiSdtTable;
 
-#define ACPI_READ_FIELD(field, addr)           \
+#define ACPI_READ_FIELD(qts, field, addr)      \
     do {                                       \
         switch (sizeof(field)) {               \
         case 1:                                \
-            field = readb(addr);               \
+            field = qtest_readb(qts, addr);    \
             break;                             \
         case 2:                                \
-            field = readw(addr);               \
+            field = qtest_readw(qts, addr);    \
             break;                             \
         case 4:                                \
-            field = readl(addr);               \
+            field = qtest_readl(qts, addr);    \
             break;                             \
         case 8:                                \
-            field = readq(addr);               \
+            field = qtest_readq(qts, addr);    \
             break;                             \
         default:                               \
             g_assert(false);                   \
@@ -49,28 +49,28 @@ typedef struct {
         addr += sizeof(field);                  \
     } while (0);
 
-#define ACPI_READ_ARRAY_PTR(arr, length, addr)  \
-    do {                                        \
-        int idx;                                \
-        for (idx = 0; idx < length; ++idx) {    \
-            ACPI_READ_FIELD(arr[idx], addr);    \
-        }                                       \
+#define ACPI_READ_ARRAY_PTR(qts, arr, length, addr)      \
+    do {                                                 \
+        int idx;                                         \
+        for (idx = 0; idx < length; ++idx) {             \
+            ACPI_READ_FIELD(qts, arr[idx], addr);        \
+        }                                                \
     } while (0);
 
-#define ACPI_READ_ARRAY(arr, addr)                               \
-    ACPI_READ_ARRAY_PTR(arr, sizeof(arr) / sizeof(arr[0]), addr)
+#define ACPI_READ_ARRAY(qts, arr, addr)                                 \
+    ACPI_READ_ARRAY_PTR(qts, arr, sizeof(arr) / sizeof(arr[0]), addr)
 
-#define ACPI_READ_TABLE_HEADER(table, addr)                      \
+#define ACPI_READ_TABLE_HEADER(qts, table, addr)                 \
     do {                                                         \
-        ACPI_READ_FIELD((table)->signature, addr);               \
-        ACPI_READ_FIELD((table)->length, addr);                  \
-        ACPI_READ_FIELD((table)->revision, addr);                \
-        ACPI_READ_FIELD((table)->checksum, addr);                \
-        ACPI_READ_ARRAY((table)->oem_id, addr);                  \
-        ACPI_READ_ARRAY((table)->oem_table_id, addr);            \
-        ACPI_READ_FIELD((table)->oem_revision, addr);            \
-        ACPI_READ_ARRAY((table)->asl_compiler_id, addr);         \
-        ACPI_READ_FIELD((table)->asl_compiler_revision, addr);   \
+        ACPI_READ_FIELD(qts, (table)->signature, addr);          \
+        ACPI_READ_FIELD(qts, (table)->length, addr);             \
+        ACPI_READ_FIELD(qts, (table)->revision, addr);           \
+        ACPI_READ_FIELD(qts, (table)->checksum, addr);           \
+        ACPI_READ_ARRAY(qts, (table)->oem_id, addr);             \
+        ACPI_READ_ARRAY(qts, (table)->oem_table_id, addr);       \
+        ACPI_READ_FIELD(qts, (table)->oem_revision, addr);       \
+        ACPI_READ_ARRAY(qts, (table)->asl_compiler_id, addr);    \
+        ACPI_READ_FIELD(qts, (table)->asl_compiler_revision, addr);     \
     } while (0);
 
 #define ACPI_ASSERT_CMP(actual, expected) do { \
@@ -87,18 +87,19 @@ typedef struct {
     g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
 } while (0)
 
-#define ACPI_READ_GENERIC_ADDRESS(field, addr)       \
-    do {                                             \
-        ACPI_READ_FIELD((field).space_id, addr);     \
-        ACPI_READ_FIELD((field).bit_width, addr);    \
-        ACPI_READ_FIELD((field).bit_offset, addr);   \
-        ACPI_READ_FIELD((field).access_width, addr); \
-        ACPI_READ_FIELD((field).address, addr);      \
+#define ACPI_READ_GENERIC_ADDRESS(qts, field, addr)       \
+    do {                                                  \
+        ACPI_READ_FIELD(qts, (field).space_id, addr);     \
+        ACPI_READ_FIELD(qts, (field).bit_width, addr);    \
+        ACPI_READ_FIELD(qts, (field).bit_offset, addr);   \
+        ACPI_READ_FIELD(qts, (field).access_width, addr); \
+        ACPI_READ_FIELD(qts, (field).address, addr);      \
     } while (0);
 
 
 uint8_t acpi_calc_checksum(const uint8_t *data, int len);
-uint32_t acpi_find_rsdp_address(void);
-void acpi_parse_rsdp_table(uint32_t addr, AcpiRsdpDescriptor *rsdp_table);
+uint32_t acpi_find_rsdp_address(QTestState *qts);
+void acpi_parse_rsdp_table(QTestState *qts, uint32_t addr,
+                           AcpiRsdpDescriptor *rsdp_table);
 
 #endif  /* TEST_ACPI_UTILS_H */
tests/acpi-utils.c +10 -9
index 41dc1ea9b4..6dc8ca1a8c 100644
@@ -32,7 +32,7 @@ uint8_t acpi_calc_checksum(const uint8_t *data, int len)
     return sum;
 }
 
-uint32_t acpi_find_rsdp_address(void)
+uint32_t acpi_find_rsdp_address(QTestState *qts)
 {
     uint32_t off;
 
@@ -42,7 +42,7 @@ uint32_t acpi_find_rsdp_address(void)
         int i;
 
         for (i = 0; i < sizeof sig - 1; ++i) {
-            sig[i] = readb(off + i);
+            sig[i] = qtest_readb(qts, off + i);
         }
 
         if (!memcmp(sig, "RSD PTR ", sizeof sig)) {
@@ -52,14 +52,15 @@ uint32_t acpi_find_rsdp_address(void)
     return off;
 }
 
-void acpi_parse_rsdp_table(uint32_t addr, AcpiRsdpDescriptor *rsdp_table)
+void acpi_parse_rsdp_table(QTestState *qts, uint32_t addr,
+                           AcpiRsdpDescriptor *rsdp_table)
 {
-    ACPI_READ_FIELD(rsdp_table->signature, addr);
+    ACPI_READ_FIELD(qts, rsdp_table->signature, addr);
     ACPI_ASSERT_CMP64(rsdp_table->signature, "RSD PTR ");
 
-    ACPI_READ_FIELD(rsdp_table->checksum, addr);
-    ACPI_READ_ARRAY(rsdp_table->oem_id, addr);
-    ACPI_READ_FIELD(rsdp_table->revision, addr);
-    ACPI_READ_FIELD(rsdp_table->rsdt_physical_address, addr);
-    ACPI_READ_FIELD(rsdp_table->length, addr);
+    ACPI_READ_FIELD(qts, rsdp_table->checksum, addr);
+    ACPI_READ_ARRAY(qts, rsdp_table->oem_id, addr);
+    ACPI_READ_FIELD(qts, rsdp_table->revision, addr);
+    ACPI_READ_FIELD(qts, rsdp_table->rsdt_physical_address, addr);
+    ACPI_READ_FIELD(qts, rsdp_table->length, addr);
 }
tests/bios-tables-test.c +81 -80
index bde62bf1cf..75b29df493 100644
@@ -77,7 +77,7 @@ static void free_test_data(test_data *data)
 
 static void test_acpi_rsdp_address(test_data *data)
 {
-    uint32_t off = acpi_find_rsdp_address();
+    uint32_t off = acpi_find_rsdp_address(global_qtest);
     g_assert_cmphex(off, <, 0x100000);
     data->rsdp_addr = off;
 }
@@ -87,7 +87,7 @@ static void test_acpi_rsdp_table(test_data *data)
     AcpiRsdpDescriptor *rsdp_table = &data->rsdp_table;
     uint32_t addr = data->rsdp_addr;
 
-    acpi_parse_rsdp_table(addr, rsdp_table);
+    acpi_parse_rsdp_table(global_qtest, addr, rsdp_table);
 
     /* rsdp checksum is not for the whole table, but for the first 20 bytes */
     g_assert(!acpi_calc_checksum((uint8_t *)rsdp_table, 20));
@@ -102,7 +102,7 @@ static void test_acpi_rsdt_table(test_data *data)
     uint8_t checksum;
 
     /* read the header */
-    ACPI_READ_TABLE_HEADER(rsdt_table, addr);
+    ACPI_READ_TABLE_HEADER(global_qtest, rsdt_table, addr);
     ACPI_ASSERT_CMP(rsdt_table->signature, "RSDT");
 
     /* compute the table entries in rsdt */
@@ -112,7 +112,7 @@ static void test_acpi_rsdt_table(test_data *data)
 
     /* get the addresses of the tables pointed by rsdt */
     tables = g_new0(uint32_t, tables_nr);
-    ACPI_READ_ARRAY_PTR(tables, tables_nr, addr);
+    ACPI_READ_ARRAY_PTR(global_qtest, tables, tables_nr, addr);
 
     checksum = acpi_calc_checksum((uint8_t *)rsdt_table, rsdt_table->length) +
                acpi_calc_checksum((uint8_t *)tables,
@@ -128,63 +128,64 @@ static void test_acpi_fadt_table(test_data *data)
 {
     AcpiFadtDescriptorRev3 *fadt_table = &data->fadt_table;
     uint32_t addr;
+    QTestState *qts = global_qtest;
 
     /* FADT table comes first */
     addr = data->rsdt_tables_addr[0];
-    ACPI_READ_TABLE_HEADER(fadt_table, addr);
+    ACPI_READ_TABLE_HEADER(qts, fadt_table, addr);
 
-    ACPI_READ_FIELD(fadt_table->firmware_ctrl, addr);
-    ACPI_READ_FIELD(fadt_table->dsdt, addr);
-    ACPI_READ_FIELD(fadt_table->model, addr);
-    ACPI_READ_FIELD(fadt_table->reserved1, addr);
-    ACPI_READ_FIELD(fadt_table->sci_int, addr);
-    ACPI_READ_FIELD(fadt_table->smi_cmd, addr);
-    ACPI_READ_FIELD(fadt_table->acpi_enable, addr);
-    ACPI_READ_FIELD(fadt_table->acpi_disable, addr);
-    ACPI_READ_FIELD(fadt_table->S4bios_req, addr);
-    ACPI_READ_FIELD(fadt_table->reserved2, addr);
-    ACPI_READ_FIELD(fadt_table->pm1a_evt_blk, addr);
-    ACPI_READ_FIELD(fadt_table->pm1b_evt_blk, addr);
-    ACPI_READ_FIELD(fadt_table->pm1a_cnt_blk, addr);
-    ACPI_READ_FIELD(fadt_table->pm1b_cnt_blk, addr);
-    ACPI_READ_FIELD(fadt_table->pm2_cnt_blk, addr);
-    ACPI_READ_FIELD(fadt_table->pm_tmr_blk, addr);
-    ACPI_READ_FIELD(fadt_table->gpe0_blk, addr);
-    ACPI_READ_FIELD(fadt_table->gpe1_blk, addr);
-    ACPI_READ_FIELD(fadt_table->pm1_evt_len, addr);
-    ACPI_READ_FIELD(fadt_table->pm1_cnt_len, addr);
-    ACPI_READ_FIELD(fadt_table->pm2_cnt_len, addr);
-    ACPI_READ_FIELD(fadt_table->pm_tmr_len, addr);
-    ACPI_READ_FIELD(fadt_table->gpe0_blk_len, addr);
-    ACPI_READ_FIELD(fadt_table->gpe1_blk_len, addr);
-    ACPI_READ_FIELD(fadt_table->gpe1_base, addr);
-    ACPI_READ_FIELD(fadt_table->reserved3, addr);
-    ACPI_READ_FIELD(fadt_table->plvl2_lat, addr);
-    ACPI_READ_FIELD(fadt_table->plvl3_lat, addr);
-    ACPI_READ_FIELD(fadt_table->flush_size, addr);
-    ACPI_READ_FIELD(fadt_table->flush_stride, addr);
-    ACPI_READ_FIELD(fadt_table->duty_offset, addr);
-    ACPI_READ_FIELD(fadt_table->duty_width, addr);
-    ACPI_READ_FIELD(fadt_table->day_alrm, addr);
-    ACPI_READ_FIELD(fadt_table->mon_alrm, addr);
-    ACPI_READ_FIELD(fadt_table->century, addr);
-    ACPI_READ_FIELD(fadt_table->boot_flags, addr);
-    ACPI_READ_FIELD(fadt_table->reserved, addr);
-    ACPI_READ_FIELD(fadt_table->flags, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->reset_register, addr);
-    ACPI_READ_FIELD(fadt_table->reset_value, addr);
-    ACPI_READ_FIELD(fadt_table->arm_boot_flags, addr);
-    ACPI_READ_FIELD(fadt_table->minor_revision, addr);
-    ACPI_READ_FIELD(fadt_table->x_facs, addr);
-    ACPI_READ_FIELD(fadt_table->x_dsdt, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm1a_event_block, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm1b_event_block, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm1a_control_block, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm1b_control_block, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm2_control_block, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm_timer_block, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->xgpe0_block, addr);
-    ACPI_READ_GENERIC_ADDRESS(fadt_table->xgpe1_block, addr);
+    ACPI_READ_FIELD(qts, fadt_table->firmware_ctrl, addr);
+    ACPI_READ_FIELD(qts, fadt_table->dsdt, addr);
+    ACPI_READ_FIELD(qts, fadt_table->model, addr);
+    ACPI_READ_FIELD(qts, fadt_table->reserved1, addr);
+    ACPI_READ_FIELD(qts, fadt_table->sci_int, addr);
+    ACPI_READ_FIELD(qts, fadt_table->smi_cmd, addr);
+    ACPI_READ_FIELD(qts, fadt_table->acpi_enable, addr);
+    ACPI_READ_FIELD(qts, fadt_table->acpi_disable, addr);
+    ACPI_READ_FIELD(qts, fadt_table->S4bios_req, addr);
+    ACPI_READ_FIELD(qts, fadt_table->reserved2, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm1a_evt_blk, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm1b_evt_blk, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm1a_cnt_blk, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm1b_cnt_blk, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm2_cnt_blk, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm_tmr_blk, addr);
+    ACPI_READ_FIELD(qts, fadt_table->gpe0_blk, addr);
+    ACPI_READ_FIELD(qts, fadt_table->gpe1_blk, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm1_evt_len, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm1_cnt_len, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm2_cnt_len, addr);
+    ACPI_READ_FIELD(qts, fadt_table->pm_tmr_len, addr);
+    ACPI_READ_FIELD(qts, fadt_table->gpe0_blk_len, addr);
+    ACPI_READ_FIELD(qts, fadt_table->gpe1_blk_len, addr);
+    ACPI_READ_FIELD(qts, fadt_table->gpe1_base, addr);
+    ACPI_READ_FIELD(qts, fadt_table->reserved3, addr);
+    ACPI_READ_FIELD(qts, fadt_table->plvl2_lat, addr);
+    ACPI_READ_FIELD(qts, fadt_table->plvl3_lat, addr);
+    ACPI_READ_FIELD(qts, fadt_table->flush_size, addr);
+    ACPI_READ_FIELD(qts, fadt_table->flush_stride, addr);
+    ACPI_READ_FIELD(qts, fadt_table->duty_offset, addr);
+    ACPI_READ_FIELD(qts, fadt_table->duty_width, addr);
+    ACPI_READ_FIELD(qts, fadt_table->day_alrm, addr);
+    ACPI_READ_FIELD(qts, fadt_table->mon_alrm, addr);
+    ACPI_READ_FIELD(qts, fadt_table->century, addr);
+    ACPI_READ_FIELD(qts, fadt_table->boot_flags, addr);
+    ACPI_READ_FIELD(qts, fadt_table->reserved, addr);
+    ACPI_READ_FIELD(qts, fadt_table->flags, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->reset_register, addr);
+    ACPI_READ_FIELD(qts, fadt_table->reset_value, addr);
+    ACPI_READ_FIELD(qts, fadt_table->arm_boot_flags, addr);
+    ACPI_READ_FIELD(qts, fadt_table->minor_revision, addr);
+    ACPI_READ_FIELD(qts, fadt_table->x_facs, addr);
+    ACPI_READ_FIELD(qts, fadt_table->x_dsdt, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->xpm1a_event_block, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->xpm1b_event_block, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->xpm1a_control_block, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->xpm1b_control_block, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->xpm2_control_block, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->xpm_timer_block, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->xgpe0_block, addr);
+    ACPI_READ_GENERIC_ADDRESS(qts, fadt_table->xgpe1_block, addr);
 
     ACPI_ASSERT_CMP(fadt_table->signature, "FACP");
     g_assert(!acpi_calc_checksum((uint8_t *)fadt_table, fadt_table->length));
@@ -195,13 +196,13 @@ static void test_acpi_facs_table(test_data *data)
     AcpiFacsDescriptorRev1 *facs_table = &data->facs_table;
     uint32_t addr = data->fadt_table.firmware_ctrl;
 
-    ACPI_READ_FIELD(facs_table->signature, addr);
-    ACPI_READ_FIELD(facs_table->length, addr);
-    ACPI_READ_FIELD(facs_table->hardware_signature, addr);
-    ACPI_READ_FIELD(facs_table->firmware_waking_vector, addr);
-    ACPI_READ_FIELD(facs_table->global_lock, addr);
-    ACPI_READ_FIELD(facs_table->flags, addr);
-    ACPI_READ_ARRAY(facs_table->resverved3, addr);
+    ACPI_READ_FIELD(global_qtest, facs_table->signature, addr);
+    ACPI_READ_FIELD(global_qtest, facs_table->length, addr);
+    ACPI_READ_FIELD(global_qtest, facs_table->hardware_signature, addr);
+    ACPI_READ_FIELD(global_qtest, facs_table->firmware_waking_vector, addr);
+    ACPI_READ_FIELD(global_qtest, facs_table->global_lock, addr);
+    ACPI_READ_FIELD(global_qtest, facs_table->flags, addr);
+    ACPI_READ_ARRAY(global_qtest, facs_table->resverved3, addr);
 
     ACPI_ASSERT_CMP(facs_table->signature, "FACS");
 }
@@ -210,11 +211,11 @@ static void test_dst_table(AcpiSdtTable *sdt_table, uint32_t addr)
 {
     uint8_t checksum;
 
-    ACPI_READ_TABLE_HEADER(&sdt_table->header, addr);
+    ACPI_READ_TABLE_HEADER(global_qtest, &sdt_table->header, addr);
 
     sdt_table->aml_len = sdt_table->header.length - sizeof(AcpiTableHeader);
     sdt_table->aml = g_malloc0(sdt_table->aml_len);
-    ACPI_READ_ARRAY_PTR(sdt_table->aml, sdt_table->aml_len, addr);
+    ACPI_READ_ARRAY_PTR(global_qtest, sdt_table->aml, sdt_table->aml_len, addr);
 
     checksum = acpi_calc_checksum((uint8_t *)sdt_table,
                                   sizeof(AcpiTableHeader)) +
@@ -492,32 +493,32 @@ static bool smbios_ep_table_ok(test_data *data)
     struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
     uint32_t addr = data->smbios_ep_addr;
 
-    ACPI_READ_ARRAY(ep_table->anchor_string, addr);
+    ACPI_READ_ARRAY(global_qtest, ep_table->anchor_string, addr);
     if (memcmp(ep_table->anchor_string, "_SM_", 4)) {
         return false;
     }
-    ACPI_READ_FIELD(ep_table->checksum, addr);
-    ACPI_READ_FIELD(ep_table->length, addr);
-    ACPI_READ_FIELD(ep_table->smbios_major_version, addr);
-    ACPI_READ_FIELD(ep_table->smbios_minor_version, addr);
-    ACPI_READ_FIELD(ep_table->max_structure_size, addr);
-    ACPI_READ_FIELD(ep_table->entry_point_revision, addr);
-    ACPI_READ_ARRAY(ep_table->formatted_area, addr);
-    ACPI_READ_ARRAY(ep_table->intermediate_anchor_string, addr);
+    ACPI_READ_FIELD(global_qtest, ep_table->checksum, addr);
+    ACPI_READ_FIELD(global_qtest, ep_table->length, addr);
+    ACPI_READ_FIELD(global_qtest, ep_table->smbios_major_version, addr);
+    ACPI_READ_FIELD(global_qtest, ep_table->smbios_minor_version, addr);
+    ACPI_READ_FIELD(global_qtest, ep_table->max_structure_size, addr);
+    ACPI_READ_FIELD(global_qtest, ep_table->entry_point_revision, addr);
+    ACPI_READ_ARRAY(global_qtest, ep_table->formatted_area, addr);
+    ACPI_READ_ARRAY(global_qtest, ep_table->intermediate_anchor_string, addr);
     if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) {
         return false;
     }
-    ACPI_READ_FIELD(ep_table->intermediate_checksum, addr);
-    ACPI_READ_FIELD(ep_table->structure_table_length, addr);
+    ACPI_READ_FIELD(global_qtest, ep_table->intermediate_checksum, addr);
+    ACPI_READ_FIELD(global_qtest, ep_table->structure_table_length, addr);
     if (ep_table->structure_table_length == 0) {
         return false;
     }
-    ACPI_READ_FIELD(ep_table->structure_table_address, addr);
-    ACPI_READ_FIELD(ep_table->number_of_structures, addr);
+    ACPI_READ_FIELD(global_qtest, ep_table->structure_table_address, addr);
+    ACPI_READ_FIELD(global_qtest, ep_table->number_of_structures, addr);
     if (ep_table->number_of_structures == 0) {
         return false;
     }
-    ACPI_READ_FIELD(ep_table->smbios_bcd_revision, addr);
+    ACPI_READ_FIELD(global_qtest, ep_table->smbios_bcd_revision, addr);
     if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) ||
         acpi_calc_checksum((uint8_t *)ep_table + 0x10,
                            sizeof *ep_table - 0x10)) {
tests/vmgenid-test.c +9 -9
index 4bdc8a15e7..73473162d0 100644
@@ -50,15 +50,15 @@ static uint32_t acpi_find_vgia(void)
     boot_sector_test(global_qtest);
 
     /* Tables should be initialized now. */
-    rsdp_offset = acpi_find_rsdp_address();
+    rsdp_offset = acpi_find_rsdp_address(global_qtest);
 
     g_assert_cmphex(rsdp_offset, <, RSDP_ADDR_INVALID);
 
-    acpi_parse_rsdp_table(rsdp_offset, &rsdp_table);
+    acpi_parse_rsdp_table(global_qtest, rsdp_offset, &rsdp_table);
 
     rsdt = rsdp_table.rsdt_physical_address;
     /* read the header */
-    ACPI_READ_TABLE_HEADER(&rsdt_table, rsdt);
+    ACPI_READ_TABLE_HEADER(global_qtest, &rsdt_table, rsdt);
     ACPI_ASSERT_CMP(rsdt_table.signature, "RSDT");
 
     /* compute the table entries in rsdt */
@@ -68,21 +68,21 @@ static uint32_t acpi_find_vgia(void)
 
     /* get the addresses of the tables pointed by rsdt */
     tables = g_new0(uint32_t, tables_nr);
-    ACPI_READ_ARRAY_PTR(tables, tables_nr, rsdt);
+    ACPI_READ_ARRAY_PTR(global_qtest, tables, tables_nr, rsdt);
 
     for (i = 0; i < tables_nr; i++) {
-        ACPI_READ_TABLE_HEADER(&ssdt_table, tables[i]);
+        ACPI_READ_TABLE_HEADER(global_qtest, &ssdt_table, tables[i]);
         if (!strncmp((char *)ssdt_table.oem_table_id, "VMGENID", 7)) {
             /* the first entry in the table should be VGIA
              * That's all we need
              */
-            ACPI_READ_FIELD(vgid_table.name_op, tables[i]);
+            ACPI_READ_FIELD(global_qtest, vgid_table.name_op, tables[i]);
             g_assert(vgid_table.name_op == 0x08);  /* name */
-            ACPI_READ_ARRAY(vgid_table.vgia, tables[i]);
+            ACPI_READ_ARRAY(global_qtest, vgid_table.vgia, tables[i]);
             g_assert(memcmp(vgid_table.vgia, "VGIA", 4) == 0);
-            ACPI_READ_FIELD(vgid_table.val_op, tables[i]);
+            ACPI_READ_FIELD(global_qtest, vgid_table.val_op, tables[i]);
             g_assert(vgid_table.val_op == 0x0C);  /* dword */
-            ACPI_READ_FIELD(vgid_table.vgia_val, tables[i]);
+            ACPI_READ_FIELD(global_qtest, vgid_table.vgia_val, tables[i]);
             /* The GUID is written at a fixed offset into the fw_cfg file
              * in order to implement the "OVMF SDT Header probe suppressor"
              * see docs/specs/vmgenid.txt for more details
Signature · 1 line
2.13.5
author
#76 lore raw

PATCH v6 24/29 bios-tables-test: Drop dependence on global_qtest

In reply to Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. Although bios-tables-test does not maintain parallel qtest connections, it's just as easy to be explicit about the state; once all tests have been cleaned up, a later patch can then get rid of global_qtest and a layer of wrappers in libqtest.

---
 tests/bios-tables-test.c | 78 +++++++++++++++++++++++++-----------------------
 1 file changed, 40 insertions(+), 38 deletions(-)
tests/bios-tables-test.c +40 -38
index 75b29df493..976792f2c5 100644
@@ -38,6 +38,7 @@ typedef struct {
     struct smbios_21_entry_point smbios_ep_table;
     uint8_t *required_struct_types;
     int required_struct_types_len;
+    QTestState *qts;
 } test_data;
 
 static char disk[] = "tests/acpi-test-disk-XXXXXX";
@@ -77,7 +78,7 @@ static void free_test_data(test_data *data)
 
 static void test_acpi_rsdp_address(test_data *data)
 {
-    uint32_t off = acpi_find_rsdp_address(global_qtest);
+    uint32_t off = acpi_find_rsdp_address(data->qts);
     g_assert_cmphex(off, <, 0x100000);
     data->rsdp_addr = off;
 }
@@ -87,7 +88,7 @@ static void test_acpi_rsdp_table(test_data *data)
     AcpiRsdpDescriptor *rsdp_table = &data->rsdp_table;
     uint32_t addr = data->rsdp_addr;
 
-    acpi_parse_rsdp_table(global_qtest, addr, rsdp_table);
+    acpi_parse_rsdp_table(data->qts, addr, rsdp_table);
 
     /* rsdp checksum is not for the whole table, but for the first 20 bytes */
     g_assert(!acpi_calc_checksum((uint8_t *)rsdp_table, 20));
@@ -102,7 +103,7 @@ static void test_acpi_rsdt_table(test_data *data)
     uint8_t checksum;
 
     /* read the header */
-    ACPI_READ_TABLE_HEADER(global_qtest, rsdt_table, addr);
+    ACPI_READ_TABLE_HEADER(data->qts, rsdt_table, addr);
     ACPI_ASSERT_CMP(rsdt_table->signature, "RSDT");
 
     /* compute the table entries in rsdt */
@@ -112,7 +113,7 @@ static void test_acpi_rsdt_table(test_data *data)
 
     /* get the addresses of the tables pointed by rsdt */
     tables = g_new0(uint32_t, tables_nr);
-    ACPI_READ_ARRAY_PTR(global_qtest, tables, tables_nr, addr);
+    ACPI_READ_ARRAY_PTR(data->qts, tables, tables_nr, addr);
 
     checksum = acpi_calc_checksum((uint8_t *)rsdt_table, rsdt_table->length) +
                acpi_calc_checksum((uint8_t *)tables,
@@ -128,7 +129,7 @@ static void test_acpi_fadt_table(test_data *data)
 {
     AcpiFadtDescriptorRev3 *fadt_table = &data->fadt_table;
     uint32_t addr;
-    QTestState *qts = global_qtest;
+    QTestState *qts = data->qts;
 
     /* FADT table comes first */
     addr = data->rsdt_tables_addr[0];
@@ -196,26 +197,27 @@ static void test_acpi_facs_table(test_data *data)
     AcpiFacsDescriptorRev1 *facs_table = &data->facs_table;
     uint32_t addr = data->fadt_table.firmware_ctrl;
 
-    ACPI_READ_FIELD(global_qtest, facs_table->signature, addr);
-    ACPI_READ_FIELD(global_qtest, facs_table->length, addr);
-    ACPI_READ_FIELD(global_qtest, facs_table->hardware_signature, addr);
-    ACPI_READ_FIELD(global_qtest, facs_table->firmware_waking_vector, addr);
-    ACPI_READ_FIELD(global_qtest, facs_table->global_lock, addr);
-    ACPI_READ_FIELD(global_qtest, facs_table->flags, addr);
-    ACPI_READ_ARRAY(global_qtest, facs_table->resverved3, addr);
+    ACPI_READ_FIELD(data->qts, facs_table->signature, addr);
+    ACPI_READ_FIELD(data->qts, facs_table->length, addr);
+    ACPI_READ_FIELD(data->qts, facs_table->hardware_signature, addr);
+    ACPI_READ_FIELD(data->qts, facs_table->firmware_waking_vector, addr);
+    ACPI_READ_FIELD(data->qts, facs_table->global_lock, addr);
+    ACPI_READ_FIELD(data->qts, facs_table->flags, addr);
+    ACPI_READ_ARRAY(data->qts, facs_table->resverved3, addr);
 
     ACPI_ASSERT_CMP(facs_table->signature, "FACS");
 }
 
-static void test_dst_table(AcpiSdtTable *sdt_table, uint32_t addr)
+static void test_dst_table(test_data *data, AcpiSdtTable *sdt_table,
+                           uint32_t addr)
 {
     uint8_t checksum;
 
-    ACPI_READ_TABLE_HEADER(global_qtest, &sdt_table->header, addr);
+    ACPI_READ_TABLE_HEADER(data->qts, &sdt_table->header, addr);
 
     sdt_table->aml_len = sdt_table->header.length - sizeof(AcpiTableHeader);
     sdt_table->aml = g_malloc0(sdt_table->aml_len);
-    ACPI_READ_ARRAY_PTR(global_qtest, sdt_table->aml, sdt_table->aml_len, addr);
+    ACPI_READ_ARRAY_PTR(data->qts, sdt_table->aml, sdt_table->aml_len, addr);
 
     checksum = acpi_calc_checksum((uint8_t *)sdt_table,
                                   sizeof(AcpiTableHeader)) +
@@ -232,7 +234,7 @@ static void test_acpi_dsdt_table(test_data *data)
     memset(&dsdt_table, 0, sizeof(dsdt_table));
     data->tables = g_array_new(false, true, sizeof(AcpiSdtTable));
 
-    test_dst_table(&dsdt_table, addr);
+    test_dst_table(data, &dsdt_table, addr);
     ACPI_ASSERT_CMP(dsdt_table.header.signature, "DSDT");
 
     /* Place DSDT first */
@@ -249,7 +251,7 @@ static void test_acpi_tables(test_data *data)
 
         memset(&ssdt_table, 0, sizeof(ssdt_table));
         uint32_t addr = data->rsdt_tables_addr[i + 1]; /* fadt is first */
-        test_dst_table(&ssdt_table, addr);
+        test_dst_table(data, &ssdt_table, addr);
         g_array_append_val(data->tables, ssdt_table);
     }
 }
@@ -493,32 +495,32 @@ static bool smbios_ep_table_ok(test_data *data)
     struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
     uint32_t addr = data->smbios_ep_addr;
 
-    ACPI_READ_ARRAY(global_qtest, ep_table->anchor_string, addr);
+    ACPI_READ_ARRAY(data->qts, ep_table->anchor_string, addr);
     if (memcmp(ep_table->anchor_string, "_SM_", 4)) {
         return false;
     }
-    ACPI_READ_FIELD(global_qtest, ep_table->checksum, addr);
-    ACPI_READ_FIELD(global_qtest, ep_table->length, addr);
-    ACPI_READ_FIELD(global_qtest, ep_table->smbios_major_version, addr);
-    ACPI_READ_FIELD(global_qtest, ep_table->smbios_minor_version, addr);
-    ACPI_READ_FIELD(global_qtest, ep_table->max_structure_size, addr);
-    ACPI_READ_FIELD(global_qtest, ep_table->entry_point_revision, addr);
-    ACPI_READ_ARRAY(global_qtest, ep_table->formatted_area, addr);
-    ACPI_READ_ARRAY(global_qtest, ep_table->intermediate_anchor_string, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->checksum, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->length, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->smbios_major_version, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->smbios_minor_version, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->max_structure_size, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->entry_point_revision, addr);
+    ACPI_READ_ARRAY(data->qts, ep_table->formatted_area, addr);
+    ACPI_READ_ARRAY(data->qts, ep_table->intermediate_anchor_string, addr);
     if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) {
         return false;
     }
-    ACPI_READ_FIELD(global_qtest, ep_table->intermediate_checksum, addr);
-    ACPI_READ_FIELD(global_qtest, ep_table->structure_table_length, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->intermediate_checksum, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->structure_table_length, addr);
     if (ep_table->structure_table_length == 0) {
         return false;
     }
-    ACPI_READ_FIELD(global_qtest, ep_table->structure_table_address, addr);
-    ACPI_READ_FIELD(global_qtest, ep_table->number_of_structures, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->structure_table_address, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->number_of_structures, addr);
     if (ep_table->number_of_structures == 0) {
         return false;
     }
-    ACPI_READ_FIELD(global_qtest, ep_table->smbios_bcd_revision, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->smbios_bcd_revision, addr);
     if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) ||
         acpi_calc_checksum((uint8_t *)ep_table + 0x10,
                            sizeof *ep_table - 0x10)) {
@@ -537,7 +539,7 @@ static void test_smbios_entry_point(test_data *data)
         int i;
 
         for (i = 0; i < sizeof sig - 1; ++i) {
-            sig[i] = readb(off + i);
+            sig[i] = qtest_readb(data->qts, off + i);
         }
 
         if (!memcmp(sig, "_SM_", sizeof sig)) {
@@ -580,9 +582,9 @@ static void test_smbios_structs(test_data *data)
     for (i = 0; i < ep_table->number_of_structures; i++) {
 
         /* grab type and formatted area length from struct header */
-        type = readb(addr);
+        type = qtest_readb(data->qts, addr);
         g_assert_cmpuint(type, <=, SMBIOS_MAX_TYPE);
-        len = readb(addr + 1);
+        len = qtest_readb(data->qts, addr + 1);
 
         /* single-instance structs must not have been encountered before */
         if (smbios_single_instance(type)) {
@@ -594,7 +596,7 @@ static void test_smbios_structs(test_data *data)
         prv = crt = 1;
         while (prv || crt) {
             prv = crt;
-            crt = readb(addr + len);
+            crt = qtest_readb(data->qts, addr + len);
             len++;
         }
 
@@ -631,9 +633,9 @@ static void test_acpi_one(const char *params, test_data *data)
                            data->machine, "kvm:tcg",
                            params ? params : "", disk);
 
-    qtest_start(args);
+    data->qts = qtest_init(args);
 
-    boot_sector_test(global_qtest);
+    boot_sector_test(data->qts);
 
     test_acpi_rsdp_address(data);
     test_acpi_rsdp_table(data);
@@ -654,7 +656,7 @@ static void test_acpi_one(const char *params, test_data *data)
     test_smbios_entry_point(data);
     test_smbios_structs(data);
 
-    qtest_quit(global_qtest);
+    qtest_quit(data->qts);
     g_free(args);
 }
 
Signature · 1 line
2.13.5
#77 lore raw

Re: [Qemu-devel] [PATCH v6 24/29] bios-tables-test: Drop dependence on global_qtest

Quoted 18 lines · Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. Although bios-tables-test does not maintain parallel qtest connections, it's just as easy to be explicit about the state; once all tests have been cleaned up, a later patch can then get rid of global_qtest and a layer of wrappers in libqtest.

---
 tests/bios-tables-test.c | 78 +++++++++++++++++++++++++-----------------------
 1 file changed, 40 insertions(+), 38 deletions(-)
tests/bios-tables-test.c +0 -0
index 75b29df493..976792f2c5 100644

tests/bios-tables-test.c typedef struct { · line 42

Quoted 5 lines
tests/bios-tables-test.c +1 -0
@@ -38,6 +38,7 @@ typedef struct {
     struct smbios_21_entry_point smbios_ep_table;
     uint8_t *required_struct_types;
     int required_struct_types_len;
+    QTestState *qts;
 } test_data;

Ah, well, ok, here it is. Please merge this with the previous patch!

Thomas

author
#78 lore raw

Re: [Qemu-devel] [PATCH v6 24/29] bios-tables-test: Drop dependence on global_qtest

Quoted 14 lines · Thomas Huth
Quoted 13 lines · Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. Although bios-tables-test does not maintain parallel qtest connections, it's just as easy to be explicit about the state; once all tests have been cleaned up, a later patch can then get rid of global_qtest and a layer of wrappers in libqtest.

---
 tests/bios-tables-test.c | 78 +++++++++++++++++++++++++-----------------------
 1 file changed, 40 insertions(+), 38 deletions(-)
Quoted 12 lines

tests/bios-tables-test.c typedef struct { · line 42

Quoted 10 lines
tests/bios-tables-test.c +1 -0
index 75b29df493..976792f2c5 100644
@@ -38,6 +38,7 @@ typedef struct {
     struct smbios_21_entry_point smbios_ep_table;
     uint8_t *required_struct_types;
     int required_struct_types_len;
+    QTestState *qts;
 } test_data;

Ah, well, ok, here it is. Please merge this with the previous patch!

Sure, I'll merge the two.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
Acked-by on v6 24/29
#79 lore raw

Re: [Qemu-devel] [PATCH v6 24/29] bios-tables-test: Drop dependence on global_qtest

In reply to Eric Blake
Quoted 9 lines · Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. Although bios-tables-test does not maintain parallel qtest connections, it's just as easy to be explicit about the state; once all tests have been cleaned up, a later patch can then get rid of global_qtest and a layer of wrappers in libqtest.

Quoted 218 lines
---
 tests/bios-tables-test.c | 78 +++++++++++++++++++++++++-----------------------
 1 file changed, 40 insertions(+), 38 deletions(-)
tests/bios-tables-test.c +40 -38
index 75b29df493..976792f2c5 100644
@@ -38,6 +38,7 @@ typedef struct {
     struct smbios_21_entry_point smbios_ep_table;
     uint8_t *required_struct_types;
     int required_struct_types_len;
+    QTestState *qts;
 } test_data;
 
 static char disk[] = "tests/acpi-test-disk-XXXXXX";
@@ -77,7 +78,7 @@ static void free_test_data(test_data *data)
 
 static void test_acpi_rsdp_address(test_data *data)
 {
-    uint32_t off = acpi_find_rsdp_address(global_qtest);
+    uint32_t off = acpi_find_rsdp_address(data->qts);
     g_assert_cmphex(off, <, 0x100000);
     data->rsdp_addr = off;
 }
@@ -87,7 +88,7 @@ static void test_acpi_rsdp_table(test_data *data)
     AcpiRsdpDescriptor *rsdp_table = &data->rsdp_table;
     uint32_t addr = data->rsdp_addr;
 
-    acpi_parse_rsdp_table(global_qtest, addr, rsdp_table);
+    acpi_parse_rsdp_table(data->qts, addr, rsdp_table);
 
     /* rsdp checksum is not for the whole table, but for the first 20 bytes */
     g_assert(!acpi_calc_checksum((uint8_t *)rsdp_table, 20));
@@ -102,7 +103,7 @@ static void test_acpi_rsdt_table(test_data *data)
     uint8_t checksum;
 
     /* read the header */
-    ACPI_READ_TABLE_HEADER(global_qtest, rsdt_table, addr);
+    ACPI_READ_TABLE_HEADER(data->qts, rsdt_table, addr);
     ACPI_ASSERT_CMP(rsdt_table->signature, "RSDT");
 
     /* compute the table entries in rsdt */
@@ -112,7 +113,7 @@ static void test_acpi_rsdt_table(test_data *data)
 
     /* get the addresses of the tables pointed by rsdt */
     tables = g_new0(uint32_t, tables_nr);
-    ACPI_READ_ARRAY_PTR(global_qtest, tables, tables_nr, addr);
+    ACPI_READ_ARRAY_PTR(data->qts, tables, tables_nr, addr);
 
     checksum = acpi_calc_checksum((uint8_t *)rsdt_table, rsdt_table->length) +
                acpi_calc_checksum((uint8_t *)tables,
@@ -128,7 +129,7 @@ static void test_acpi_fadt_table(test_data *data)
 {
     AcpiFadtDescriptorRev3 *fadt_table = &data->fadt_table;
     uint32_t addr;
-    QTestState *qts = global_qtest;
+    QTestState *qts = data->qts;
 
     /* FADT table comes first */
     addr = data->rsdt_tables_addr[0];
@@ -196,26 +197,27 @@ static void test_acpi_facs_table(test_data *data)
     AcpiFacsDescriptorRev1 *facs_table = &data->facs_table;
     uint32_t addr = data->fadt_table.firmware_ctrl;
 
-    ACPI_READ_FIELD(global_qtest, facs_table->signature, addr);
-    ACPI_READ_FIELD(global_qtest, facs_table->length, addr);
-    ACPI_READ_FIELD(global_qtest, facs_table->hardware_signature, addr);
-    ACPI_READ_FIELD(global_qtest, facs_table->firmware_waking_vector, addr);
-    ACPI_READ_FIELD(global_qtest, facs_table->global_lock, addr);
-    ACPI_READ_FIELD(global_qtest, facs_table->flags, addr);
-    ACPI_READ_ARRAY(global_qtest, facs_table->resverved3, addr);
+    ACPI_READ_FIELD(data->qts, facs_table->signature, addr);
+    ACPI_READ_FIELD(data->qts, facs_table->length, addr);
+    ACPI_READ_FIELD(data->qts, facs_table->hardware_signature, addr);
+    ACPI_READ_FIELD(data->qts, facs_table->firmware_waking_vector, addr);
+    ACPI_READ_FIELD(data->qts, facs_table->global_lock, addr);
+    ACPI_READ_FIELD(data->qts, facs_table->flags, addr);
+    ACPI_READ_ARRAY(data->qts, facs_table->resverved3, addr);
 
     ACPI_ASSERT_CMP(facs_table->signature, "FACS");
 }
 
-static void test_dst_table(AcpiSdtTable *sdt_table, uint32_t addr)
+static void test_dst_table(test_data *data, AcpiSdtTable *sdt_table,
+                           uint32_t addr)
 {
     uint8_t checksum;
 
-    ACPI_READ_TABLE_HEADER(global_qtest, &sdt_table->header, addr);
+    ACPI_READ_TABLE_HEADER(data->qts, &sdt_table->header, addr);
 
     sdt_table->aml_len = sdt_table->header.length - sizeof(AcpiTableHeader);
     sdt_table->aml = g_malloc0(sdt_table->aml_len);
-    ACPI_READ_ARRAY_PTR(global_qtest, sdt_table->aml, sdt_table->aml_len, addr);
+    ACPI_READ_ARRAY_PTR(data->qts, sdt_table->aml, sdt_table->aml_len, addr);
 
     checksum = acpi_calc_checksum((uint8_t *)sdt_table,
                                   sizeof(AcpiTableHeader)) +
@@ -232,7 +234,7 @@ static void test_acpi_dsdt_table(test_data *data)
     memset(&dsdt_table, 0, sizeof(dsdt_table));
     data->tables = g_array_new(false, true, sizeof(AcpiSdtTable));
 
-    test_dst_table(&dsdt_table, addr);
+    test_dst_table(data, &dsdt_table, addr);
     ACPI_ASSERT_CMP(dsdt_table.header.signature, "DSDT");
 
     /* Place DSDT first */
@@ -249,7 +251,7 @@ static void test_acpi_tables(test_data *data)
 
         memset(&ssdt_table, 0, sizeof(ssdt_table));
         uint32_t addr = data->rsdt_tables_addr[i + 1]; /* fadt is first */
-        test_dst_table(&ssdt_table, addr);
+        test_dst_table(data, &ssdt_table, addr);
         g_array_append_val(data->tables, ssdt_table);
     }
 }
@@ -493,32 +495,32 @@ static bool smbios_ep_table_ok(test_data *data)
     struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
     uint32_t addr = data->smbios_ep_addr;
 
-    ACPI_READ_ARRAY(global_qtest, ep_table->anchor_string, addr);
+    ACPI_READ_ARRAY(data->qts, ep_table->anchor_string, addr);
     if (memcmp(ep_table->anchor_string, "_SM_", 4)) {
         return false;
     }
-    ACPI_READ_FIELD(global_qtest, ep_table->checksum, addr);
-    ACPI_READ_FIELD(global_qtest, ep_table->length, addr);
-    ACPI_READ_FIELD(global_qtest, ep_table->smbios_major_version, addr);
-    ACPI_READ_FIELD(global_qtest, ep_table->smbios_minor_version, addr);
-    ACPI_READ_FIELD(global_qtest, ep_table->max_structure_size, addr);
-    ACPI_READ_FIELD(global_qtest, ep_table->entry_point_revision, addr);
-    ACPI_READ_ARRAY(global_qtest, ep_table->formatted_area, addr);
-    ACPI_READ_ARRAY(global_qtest, ep_table->intermediate_anchor_string, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->checksum, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->length, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->smbios_major_version, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->smbios_minor_version, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->max_structure_size, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->entry_point_revision, addr);
+    ACPI_READ_ARRAY(data->qts, ep_table->formatted_area, addr);
+    ACPI_READ_ARRAY(data->qts, ep_table->intermediate_anchor_string, addr);
     if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) {
         return false;
     }
-    ACPI_READ_FIELD(global_qtest, ep_table->intermediate_checksum, addr);
-    ACPI_READ_FIELD(global_qtest, ep_table->structure_table_length, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->intermediate_checksum, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->structure_table_length, addr);
     if (ep_table->structure_table_length == 0) {
         return false;
     }
-    ACPI_READ_FIELD(global_qtest, ep_table->structure_table_address, addr);
-    ACPI_READ_FIELD(global_qtest, ep_table->number_of_structures, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->structure_table_address, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->number_of_structures, addr);
     if (ep_table->number_of_structures == 0) {
         return false;
     }
-    ACPI_READ_FIELD(global_qtest, ep_table->smbios_bcd_revision, addr);
+    ACPI_READ_FIELD(data->qts, ep_table->smbios_bcd_revision, addr);
     if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) ||
         acpi_calc_checksum((uint8_t *)ep_table + 0x10,
                            sizeof *ep_table - 0x10)) {
@@ -537,7 +539,7 @@ static void test_smbios_entry_point(test_data *data)
         int i;
 
         for (i = 0; i < sizeof sig - 1; ++i) {
-            sig[i] = readb(off + i);
+            sig[i] = qtest_readb(data->qts, off + i);
         }
 
         if (!memcmp(sig, "_SM_", sizeof sig)) {
@@ -580,9 +582,9 @@ static void test_smbios_structs(test_data *data)
     for (i = 0; i < ep_table->number_of_structures; i++) {
 
         /* grab type and formatted area length from struct header */
-        type = readb(addr);
+        type = qtest_readb(data->qts, addr);
         g_assert_cmpuint(type, <=, SMBIOS_MAX_TYPE);
-        len = readb(addr + 1);
+        len = qtest_readb(data->qts, addr + 1);
 
         /* single-instance structs must not have been encountered before */
         if (smbios_single_instance(type)) {
@@ -594,7 +596,7 @@ static void test_smbios_structs(test_data *data)
         prv = crt = 1;
         while (prv || crt) {
             prv = crt;
-            crt = readb(addr + len);
+            crt = qtest_readb(data->qts, addr + len);
             len++;
         }
 
@@ -631,9 +633,9 @@ static void test_acpi_one(const char *params, test_data *data)
                            data->machine, "kvm:tcg",
                            params ? params : "", disk);
 
-    qtest_start(args);
+    data->qts = qtest_init(args);
 
-    boot_sector_test(global_qtest);
+    boot_sector_test(data->qts);
 
     test_acpi_rsdp_address(data);
     test_acpi_rsdp_table(data);
@@ -654,7 +656,7 @@ static void test_acpi_one(const char *params, test_data *data)
     test_smbios_entry_point(data);
     test_smbios_structs(data);
 
-    qtest_quit(global_qtest);
+    qtest_quit(data->qts);
     g_free(args);
 }
 
Signature · 1 line
2.13.5
author
#80 lore raw

PATCH v6 25/29 wdt_ib700-test: Drop dependence on global_qtest

In reply to Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. Improve this test to be explicit about the state.

---
 tests/wdt_ib700-test.c | 63 +++++++++++++++++++++++++++-----------------------
 1 file changed, 34 insertions(+), 29 deletions(-)
tests/wdt_ib700-test.c +34 -29
index 4fc8eeae86..4bb8374011 100644
@@ -11,9 +11,9 @@
 #include "libqtest.h"
 #include "qemu/timer.h"
 
-static void qmp_check_no_event(void)
+static void qmp_check_no_event(QTestState *s)
 {
-    QDict *resp = qmp("{'execute':'query-status'}");
+    QDict *resp = qtest_qmp(s, "{'execute':'query-status'}");
     g_assert(qdict_haskey(resp, "return"));
     QDECREF(resp);
 }
@@ -22,30 +22,30 @@ static QDict *ib700_program_and_wait(QTestState *s)
 {
     QDict *event, *data;
 
-    clock_step(NANOSECONDS_PER_SECOND * 40);
-    qmp_check_no_event();
+    qtest_clock_step(s, NANOSECONDS_PER_SECOND * 40);
+    qmp_check_no_event(s);
 
     /* 2 second limit */
-    outb(0x443, 14);
+    qtest_outb(s, 0x443, 14);
 
     /* Ping */
-    clock_step(NANOSECONDS_PER_SECOND);
-    qmp_check_no_event();
-    outb(0x443, 14);
+    qtest_clock_step(s, NANOSECONDS_PER_SECOND);
+    qmp_check_no_event(s);
+    qtest_outb(s, 0x443, 14);
 
     /* Disable */
-    clock_step(NANOSECONDS_PER_SECOND);
-    qmp_check_no_event();
-    outb(0x441, 1);
-    clock_step(3 * NANOSECONDS_PER_SECOND);
-    qmp_check_no_event();
+    qtest_clock_step(s, NANOSECONDS_PER_SECOND);
+    qmp_check_no_event(s);
+    qtest_outb(s, 0x441, 1);
+    qtest_clock_step(s, 3 * NANOSECONDS_PER_SECOND);
+    qmp_check_no_event(s);
 
     /* Enable and let it fire */
-    outb(0x443, 13);
-    clock_step(3 * NANOSECONDS_PER_SECOND);
-    qmp_check_no_event();
-    clock_step(2 * NANOSECONDS_PER_SECOND);
-    event = qmp_eventwait_ref("WATCHDOG");
+    qtest_outb(s, 0x443, 13);
+    qtest_clock_step(s, 3 * NANOSECONDS_PER_SECOND);
+    qmp_check_no_event(s);
+    qtest_clock_step(s, 2 * NANOSECONDS_PER_SECOND);
+    event = qtest_qmp_eventwait_ref(s, "WATCHDOG");
     data = qdict_get_qdict(event, "data");
     QINCREF(data);
     QDECREF(event);
@@ -56,48 +56,53 @@ static QDict *ib700_program_and_wait(QTestState *s)
 static void ib700_pause(void)
 {
     QDict *d;
-    QTestState *s = qtest_start("-watchdog-action pause -device ib700");
+    QTestState *s = qtest_init("-watchdog-action pause -device ib700");
+
     qtest_irq_intercept_in(s, "ioapic");
     d = ib700_program_and_wait(s);
     g_assert(!strcmp(qdict_get_str(d, "action"), "pause"));
     QDECREF(d);
-    qmp_eventwait("STOP");
-    qtest_end();
+    qtest_qmp_eventwait(s, "STOP");
+    qtest_quit(s);
 }
 
 static void ib700_reset(void)
 {
     QDict *d;
-    QTestState *s = qtest_start("-watchdog-action reset -device ib700");
+    QTestState *s = qtest_init("-watchdog-action reset -device ib700");
+
     qtest_irq_intercept_in(s, "ioapic");
     d = ib700_program_and_wait(s);
     g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
     QDECREF(d);
-    qmp_eventwait("RESET");
-    qtest_end();
+    qtest_qmp_eventwait(s, "RESET");
+    qtest_quit(s);
 }
 
 static void ib700_shutdown(void)
 {
     QDict *d;
-    QTestState *s = qtest_start("-watchdog-action reset -no-reboot -device ib700");
+    QTestState *s;
+
+    s = qtest_init("-watchdog-action reset -no-reboot -device ib700");
     qtest_irq_intercept_in(s, "ioapic");
     d = ib700_program_and_wait(s);
     g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
     QDECREF(d);
-    qmp_eventwait("SHUTDOWN");
-    qtest_end();
+    qtest_qmp_eventwait(s, "SHUTDOWN");
+    qtest_quit(s);
 }
 
 static void ib700_none(void)
 {
     QDict *d;
-    QTestState *s = qtest_start("-watchdog-action none -device ib700");
+    QTestState *s = qtest_init("-watchdog-action none -device ib700");
+
     qtest_irq_intercept_in(s, "ioapic");
     d = ib700_program_and_wait(s);
     g_assert(!strcmp(qdict_get_str(d, "action"), "none"));
     QDECREF(d);
-    qtest_end();
+    qtest_quit(s);
 }
 
 int main(int argc, char **argv)
Signature · 1 line
2.13.5
Reviewed-by on v6 25/29
#81 lore raw

Re: [Qemu-devel] [PATCH v6 25/29] wdt_ib700-test: Drop dependence on global_qtest

Quoted 9 lines · Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. Improve this test to be explicit about the state.

---
 tests/wdt_ib700-test.c | 63 +++++++++++++++++++++++++++-----------------------
 1 file changed, 34 insertions(+), 29 deletions(-)
author
#82 lore raw

PATCH v6 26/29 fw_cfg-test: Drop dependence on global_qtest

In reply to Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. It turns out that with the recent changes to libqos, fw_cfg-test was not even using global_qtest any more. Avoid a pointless strdup while at it.

---
 tests/fw_cfg-test.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
tests/fw_cfg-test.c +1 -4
index 47596c57a1..3a8dc7a2cd 100644
@@ -102,14 +102,11 @@ static void test_fw_cfg_boot_menu(void)
 int main(int argc, char **argv)
 {
     QTestState *s;
-    char *cmdline;
     int ret;
 
     g_test_init(&argc, &argv, NULL);
 
-    cmdline = g_strdup_printf("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8 ");
-    s = qtest_start(cmdline);
-    g_free(cmdline);
+    s = qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8");
 
     fw_cfg = pc_fw_cfg_init(s);
 
Signature · 1 line
2.13.5
Reviewed-by on v6 26/29
#83 lore raw

Re: [Qemu-devel] [PATCH v6 26/29] fw_cfg-test: Drop dependence on global_qtest

Quoted 7 lines · Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. It turns out that with the recent changes to libqos, fw_cfg-test was not even using global_qtest any more. Avoid a pointless strdup while at it.

Quoted 24 lines
---
  tests/fw_cfg-test.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
tests/fw_cfg-test.c +1 -4
index 47596c57a1..3a8dc7a2cd 100644
@@ -102,14 +102,11 @@ static void test_fw_cfg_boot_menu(void)
  int main(int argc, char **argv)
  {
      QTestState *s;
-    char *cmdline;
      int ret;
 
      g_test_init(&argc, &argv, NULL);
 
-    cmdline = g_strdup_printf("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8 ");
-    s = qtest_start(cmdline);
-    g_free(cmdline);
+    s = qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8");
 
      fw_cfg = pc_fw_cfg_init(s);
 
#84 lore raw

Re: [Qemu-devel] [PATCH v6 26/29] fw_cfg-test: Drop dependence on global_qtest

In reply to Eric Blake
Quoted 21 lines · Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. It turns out that with the recent changes to libqos, fw_cfg-test was not even using global_qtest any more. Avoid a pointless strdup while at it.

---
 tests/fw_cfg-test.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
tests/fw_cfg-test.c +0 -1
index 47596c57a1..3a8dc7a2cd 100644
@@ -102,14 +102,11 @@ static void test_fw_cfg_boot_menu(void)
 int main(int argc, char **argv)
 {
     QTestState *s;
-    char *cmdline;
     int ret;

tests/fw_cfg-test.c static void test_fw_cfg_boot_menu(void) · line 112

Quoted 10 lines
tests/fw_cfg-test.c +1 -3
 
     g_test_init(&argc, &argv, NULL);
 
-    cmdline = g_strdup_printf("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8 ");
-    s = qtest_start(cmdline);
-    g_free(cmdline);
+    s = qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8");
 
     fw_cfg = pc_fw_cfg_init(s);
 

Why don't you merge this with patch 14/29?

Thomas

author
#85 lore raw

Re: [Qemu-devel] [PATCH v6 26/29] fw_cfg-test: Drop dependence on global_qtest

Quoted 15 lines · Thomas Huth
Quoted 6 lines · Eric Blake

As a general rule, we prefer avoiding implicit global state because it makes code harder to safely copy and paste without thinking about the global state. It turns out that with the recent changes to libqos, fw_cfg-test was not even using global_qtest any more. Avoid a pointless strdup while at it.

Quoted 7 lines
---
 tests/fw_cfg-test.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
Quoted 1 line

Why don't you merge this with patch 14/29?

Sure.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
author
#86 lore raw

PATCH v6 27/29 libqtest: Make qtest_init() accept format string

In reply to Eric Blake

Several callers were formatting a string into a temporary variable before calling qtest_init(); factor that into the common code.

---
 tests/libqtest.h         |  7 ++++---
 tests/libqtest.c         | 13 ++++++++++--
 tests/bios-tables-test.c |  7 +------
 tests/postcopy-test.c    |  4 ++--
 tests/vhost-user-test.c  | 51 ++++++++++++++----------------------------------
 5 files changed, 33 insertions(+), 49 deletions(-)
tests/libqtest.h +4 -3
index 3ae570927a..d338de3e22 100644
@@ -25,11 +25,12 @@ extern QTestState *global_qtest;
 
 /**
  * qtest_init:
- * @extra_args: other arguments to pass to QEMU.
+ * @extra_args...: other arguments to pass to QEMU, formatted as if by
+ * sprintf().
  *
  * Returns: #QTestState instance.
  */
-QTestState *qtest_init(const char *extra_args);
+QTestState *qtest_init(const char *extra_args, ...) GCC_FMT_ATTR(1, 2);
 
 /**
  * qtest_init_without_qmp_handshake:
@@ -518,7 +519,7 @@ void qtest_add_abrt_handler(GHookFunc fn, const void *data);
  */
 static inline QTestState *qtest_start(const char *args)
 {
-    global_qtest = qtest_init(args);
+    global_qtest = qtest_init("%s", args);
     return global_qtest;
 }
 
tests/libqtest.c +11 -2
index b6dd26e54a..18facbf130 100644
@@ -347,9 +347,18 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     return s;
 }
 
-QTestState *qtest_init(const char *extra_args)
+QTestState *qtest_init(const char *extra_args, ...)
 {
-    QTestState *s = qtest_init_without_qmp_handshake(extra_args);
+    va_list ap;
+    QTestState *s;
+    char *cmd;
+
+    va_start(ap, extra_args);
+    cmd = g_strdup_vprintf(extra_args, ap);
+    va_end(ap);
+
+    s = qtest_init_without_qmp_handshake(cmd);
+    g_free(cmd);
 
     /* Read the QMP greeting and then do the handshake */
     qtest_qmp_discard_response(s, "");
tests/bios-tables-test.c +1 -6
index 976792f2c5..f8a107499f 100644
@@ -623,18 +623,14 @@ static void test_smbios_structs(test_data *data)
 
 static void test_acpi_one(const char *params, test_data *data)
 {
-    char *args;
-
     /* Disable kernel irqchip to be able to override apic irq0. */
-    args = g_strdup_printf("-machine %s,accel=%s,kernel-irqchip=off "
+    data->qts = qtest_init("-machine %s,accel=%s,kernel-irqchip=off "
                            "-net none -display none %s "
                            "-drive id=hd0,if=none,file=%s,format=raw "
                            "-device ide-hd,drive=hd0 ",
                            data->machine, "kvm:tcg",
                            params ? params : "", disk);
 
-    data->qts = qtest_init(args);
-
     boot_sector_test(data->qts);
 
     test_acpi_rsdp_address(data);
@@ -657,7 +653,6 @@ static void test_acpi_one(const char *params, test_data *data)
     test_smbios_structs(data);
 
     qtest_quit(data->qts);
-    g_free(args);
 }
 
 static uint8_t base_required_struct_types[] = {
tests/postcopy-test.c +2 -2
index 0e5fe20a83..20cfb280f6 100644
@@ -403,10 +403,10 @@ static void test_migrate(void)
 
     g_free(bootpath);
 
-    from = qtest_init(cmd_src);
+    from = qtest_init("%s", cmd_src);
     g_free(cmd_src);
 
-    to = qtest_init(cmd_dst);
+    to = qtest_init("%s", cmd_dst);
     g_free(cmd_dst);
 
     assert(!global_qtest);
tests/vhost-user-test.c +15 -36

126 lines not on this page · raw message

Signature · 1 line
2.13.5
#87 lore raw

Re: [Qemu-devel] [PATCH v6 27/29] libqtest: Make qtest_init() accept format string

Quoted 19 lines · Eric Blake

Several callers were formatting a string into a temporary variable before calling qtest_init(); factor that into the common code.

---
 tests/libqtest.h         |  7 ++++---
 tests/libqtest.c         | 13 ++++++++++--
 tests/bios-tables-test.c |  7 +------
 tests/postcopy-test.c    |  4 ++--
 tests/vhost-user-test.c  | 51 ++++++++++++++----------------------------------
 5 files changed, 33 insertions(+), 49 deletions(-)
tests/libqtest.h +0 -0
index 3ae570927a..d338de3e22 100644
@@ -25,11 +25,12 @@ extern QTestState *global_qtest;
 

tests/libqtest.h extern QTestState *global_qtest; · line 33

Quoted 10 lines
tests/libqtest.h +3 -2
 /**
  * qtest_init:
- * @extra_args: other arguments to pass to QEMU.
+ * @extra_args...: other arguments to pass to QEMU, formatted as if by
+ * sprintf().
  *
  * Returns: #QTestState instance.
  */
-QTestState *qtest_init(const char *extra_args);
+QTestState *qtest_init(const char *extra_args, ...) GCC_FMT_ATTR(1, 2);

Maybe the parameter should be called "fmt" or "format" now instead? (similar to printf() and friends)

tests/libqtest.h void qtest_add_abrt_handler(GHookFunc fn, const void *data); · line 522

Quoted 8 lines
tests/libqtest.h +1 -1
 /**
  * qtest_init_without_qmp_handshake:
@@ -518,7 +519,7 @@ void qtest_add_abrt_handler(GHookFunc fn, const void *data);
  */
 static inline QTestState *qtest_start(const char *args)
 {
-    global_qtest = qtest_init(args);
+    global_qtest = qtest_init("%s", args);

That's a little bit sad that there are some spots which need an explicit "%s" now ... maybe it would be nicer to add a new function called qtest_initf() instead and keep the old one (without the "f") as it is?

Quoted 67 lines
tests/libqtest.h +0 -0
     return global_qtest;
 }
 
tests/libqtest.c +11 -2
index b6dd26e54a..18facbf130 100644
@@ -347,9 +347,18 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     return s;
 }
 
-QTestState *qtest_init(const char *extra_args)
+QTestState *qtest_init(const char *extra_args, ...)
 {
-    QTestState *s = qtest_init_without_qmp_handshake(extra_args);
+    va_list ap;
+    QTestState *s;
+    char *cmd;
+
+    va_start(ap, extra_args);
+    cmd = g_strdup_vprintf(extra_args, ap);
+    va_end(ap);
+
+    s = qtest_init_without_qmp_handshake(cmd);
+    g_free(cmd);
 
     /* Read the QMP greeting and then do the handshake */
     qtest_qmp_discard_response(s, "");
tests/bios-tables-test.c +1 -6
index 976792f2c5..f8a107499f 100644
@@ -623,18 +623,14 @@ static void test_smbios_structs(test_data *data)
 
 static void test_acpi_one(const char *params, test_data *data)
 {
-    char *args;
-
     /* Disable kernel irqchip to be able to override apic irq0. */
-    args = g_strdup_printf("-machine %s,accel=%s,kernel-irqchip=off "
+    data->qts = qtest_init("-machine %s,accel=%s,kernel-irqchip=off "
                            "-net none -display none %s "
                            "-drive id=hd0,if=none,file=%s,format=raw "
                            "-device ide-hd,drive=hd0 ",
                            data->machine, "kvm:tcg",
                            params ? params : "", disk);
 
-    data->qts = qtest_init(args);
-
     boot_sector_test(data->qts);
 
     test_acpi_rsdp_address(data);
@@ -657,7 +653,6 @@ static void test_acpi_one(const char *params, test_data *data)
     test_smbios_structs(data);
 
     qtest_quit(data->qts);
-    g_free(args);
 }
 
 static uint8_t base_required_struct_types[] = {
tests/postcopy-test.c +0 -0
index 0e5fe20a83..20cfb280f6 100644
@@ -403,10 +403,10 @@ static void test_migrate(void)
 
     g_free(bootpath);

tests/postcopy-test.c static void test_migrate(void) · line 412

Quoted 10 lines
tests/postcopy-test.c +2 -2
 
-    from = qtest_init(cmd_src);
+    from = qtest_init("%s", cmd_src);
     g_free(cmd_src);
 
-    to = qtest_init(cmd_dst);
+    to = qtest_init("%s", cmd_dst);
     g_free(cmd_dst);
 
     assert(!global_qtest);

Thomas

author
#88 lore raw

Re: [Qemu-devel] [PATCH v6 27/29] libqtest: Make qtest_init() accept format string

Quoted 5 lines · Thomas Huth
Quoted 4 lines · Eric Blake

Several callers were formatting a string into a temporary variable before calling qtest_init(); factor that into the common code.

Quoted 8 lines

tests/libqtest.h extern QTestState *global_qtest; · line 33

Quoted 5 lines

---

tests/libqtest.h +1 -1
-QTestState *qtest_init(const char *extra_args);
+QTestState *qtest_init(const char *extra_args, ...) GCC_FMT_ATTR(1, 2);

Maybe the parameter should be called "fmt" or "format" now instead? (similar to printf() and friends)

Sure.

Quoted 13 lines

tests/libqtest.h void qtest_add_abrt_handler(GHookFunc fn, const void *data); · line 522

Quoted 9 lines

/**
* qtest_init_without_qmp_handshake:

tests/libqtest.h +1 -1
@@ -518,7 +519,7 @@ void qtest_add_abrt_handler(GHookFunc fn, const void *data);
  */
 static inline QTestState *qtest_start(const char *args)
 {
-    global_qtest = qtest_init(args);
+    global_qtest = qtest_init("%s", args);

That's a little bit sad that there are some spots which need an explicit "%s" now ... maybe it would be nicer to add a new function called qtest_initf() instead and keep the old one (without the "f") as it is?

Indeed, and looking back over my series, I see we could also benefit from a va_list form.

Also, since you already questioned me on the churn from qtest_start() => qtest_init() => qtest_start(), I can make less churn in the next spin by converging on qtest_start() from the get-go.

So I will go with qtest_start() (plain string), qtest_startf() (formatted like sprintf), and qtest_vstartf() (formatted like vsprintf).

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#89 lore raw

Re: [Qemu-devel] [PATCH v6 27/29] libqtest: Make qtest_init() accept format string

Quoted 34 lines · Eric Blake
Quoted 5 lines · Thomas Huth
Quoted 4 lines · Eric Blake

Several callers were formatting a string into a temporary variable before calling qtest_init(); factor that into the common code.

Quoted 8 lines

tests/libqtest.h extern QTestState *global_qtest; · line 33

Quoted 5 lines

---

tests/libqtest.h +1 -1
-QTestState *qtest_init(const char *extra_args);
+QTestState *qtest_init(const char *extra_args, ...) GCC_FMT_ATTR(1, 2);

Maybe the parameter should be called "fmt" or "format" now instead? (similar to printf() and friends)

Sure.

Quoted 13 lines

tests/libqtest.h void qtest_add_abrt_handler(GHookFunc fn, const void *data); · line 522

Quoted 9 lines

/**
* qtest_init_without_qmp_handshake:

tests/libqtest.h +1 -1
@@ -518,7 +519,7 @@ void qtest_add_abrt_handler(GHookFunc fn, const void *data);
  */
 static inline QTestState *qtest_start(const char *args)
 {
-    global_qtest = qtest_init(args);
+    global_qtest = qtest_init("%s", args);

That's a little bit sad that there are some spots which need an explicit "%s" now ... maybe it would be nicer to add a new function called qtest_initf() instead and keep the old one (without the "f") as it is?

Indeed, and looking back over my series, I see we could also benefit from a va_list form.

Quoted 6 lines

Also, since you already questioned me on the churn from qtest_start() => qtest_init() => qtest_start(), I can make less churn in the next spin by converging on qtest_start() from the get-go.

So I will go with qtest_start() (plain string), qtest_startf() (formatted like sprintf), and qtest_vstartf() (formatted like vsprintf).

Thanks, that sounds like a better way to me, too!

Thomas

author
#90 lore raw

PATCH v6 28/29 libqtest: Remove qtest_start() and qtest_end() shortcuts

In reply to Eric Blake

Remove the trivial wrappers qtest_start() and qtest_end(), to make it obvious in the rest of the testsuite where we are still relying on global_qtest. Doing this makes it easier to see what remaining cleanups will be needed if we don't want an implicit dependency on global state. Many tests can also take advantage of qtest_init() doing formatting of args, avoiding a temporary local variable.

---
 tests/libqtest.h               | 26 ------------------
 tests/libqtest.c               |  4 +--
 tests/ac97-test.c              |  4 +--
 tests/boot-order-test.c        | 11 +++-----
 tests/boot-serial-test.c       | 12 +++------
 tests/device-introspect-test.c | 24 ++++++++---------
 tests/display-vga-test.c       | 18 +++++--------
 tests/drive_del-test.c         | 17 ++++++------
 tests/ds1338-test.c            |  2 +-
 tests/e1000-test.c             | 10 ++-----
 tests/e1000e-test.c            | 14 +++-------
 tests/eepro100-test.c          | 11 ++------
 tests/endianness-test.c        | 33 +++++++++--------------
 tests/es1370-test.c            |  4 +--
 tests/fdc-test.c               |  4 +--
 tests/hd-geo-test.c            | 16 +++++------
 tests/i440fx-test.c            | 16 +++++------
 tests/i82801b11-test.c         |  5 ++--
 tests/ide-test.c               |  4 +--
 tests/intel-hda-test.c         | 11 ++++----
 tests/ioh3420-test.c           |  7 ++---
 tests/ipmi-bt-test.c           | 11 +++-----
 tests/ipmi-kcs-test.c          |  5 +---
 tests/ipoctal232-test.c        |  5 ++--
 tests/ivshmem-test.c           |  4 +--
 tests/libqos/libqos.c          |  2 +-
 tests/m25p80-test.c            |  9 +++----
 tests/m48t59-test.c            |  2 +-
 tests/ne2000-test.c            |  4 +--
 tests/numa-test.c              | 28 ++++++++++----------
 tests/nvme-test.c              |  7 ++---
 tests/pc-cpu-test.c            | 26 +++++++-----------
 tests/pcnet-test.c             |  4 +--
 tests/pnv-xscom-test.c         | 14 ++--------
 tests/prom-env-test.c          | 13 ++++-----
 tests/pvpanic-test.c           |  4 +--
 tests/pxe-test.c               | 14 ++++------
 tests/q35-test.c               |  8 +++---
 tests/qom-test.c               |  7 ++---
 tests/rtc-test.c               |  2 +-
 tests/rtl8139-test.c           |  4 +--
 tests/spapr-phb-test.c         |  5 ++--
 tests/tco-test.c               | 12 ++++-----
 tests/test-arm-mptimer.c       |  4 +--
 tests/test-filter-mirror.c     | 16 +++++------
 tests/test-filter-redirector.c | 60 ++++++++++++++++++++----------------------
 tests/test-hmp.c               |  7 ++---
 tests/test-netfilter.c         |  9 +++----
 tests/test-x86-cpuid-compat.c  | 13 ++++-----
 tests/tmp105-test.c            |  2 +-
 tests/tpci200-test.c           |  4 +--
 tests/usb-hcd-ehci-test.c      | 25 +++++++++---------
 tests/usb-hcd-ohci-test.c      |  4 +--
 tests/usb-hcd-xhci-test.c      |  4 +--
 tests/virtio-balloon-test.c    |  4 +--
 tests/virtio-blk-test.c        | 13 ++++-----
 tests/virtio-console-test.c    |  8 +++---
 tests/virtio-net-test.c        |  4 +--
 tests/virtio-rng-test.c        |  4 +--
 tests/virtio-serial-test.c     |  4 +--
 tests/vmgenid-test.c           | 29 ++++++--------------
 tests/vmxnet3-test.c           |  4 +--
 62 files changed, 267 insertions(+), 394 deletions(-)
tests/libqtest.h +0 -26
index d338de3e22..0459526187 100644
@@ -509,32 +509,6 @@ void qtest_add_data_func_full(const char *str, void *data,
 void qtest_add_abrt_handler(GHookFunc fn, const void *data);
 
 /**
- * qtest_start:
- * @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("%s", args);
-    return global_qtest;
-}
-
-/**
- * qtest_end:
- *
- * Shut down the QEMU process started by qtest_start().
- */
-static inline void qtest_end(void)
-{
-    qtest_quit(global_qtest);
-    global_qtest = NULL;
-}
-
-/**
  * qmp:
  * @fmt...: QMP message to send to qemu
  *
tests/libqtest.c +2 -2
index 18facbf130..fa4e47c137 100644
@@ -970,7 +970,7 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine))
     QString *qstr;
     const char *mname;
 
-    qtest_start("-machine none");
+    global_qtest = qtest_init("-machine none");
     response = qmp("{ 'execute': 'query-machines' }");
     g_assert(response);
     list = qdict_get_qlist(response, "return");
@@ -987,6 +987,6 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine))
         cb(mname);
     }
 
-    qtest_end();
+    qtest_quit(global_qtest);
     QDECREF(response);
 }
tests/ac97-test.c +2 -2
index e0d177bd9c..6a1edaa85a 100644
@@ -22,10 +22,10 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/ac97/nop", nop);
 
-    qtest_start("-device AC97");
+    global_qtest = qtest_init("-device AC97");
     ret = g_test_run();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/boot-order-test.c +4 -7
index 5fc2ca8e9e..e6efea6852 100644
@@ -28,14 +28,12 @@ static void test_a_boot_order(const char *machine,
                               uint64_t expected_boot,
                               uint64_t expected_reboot)
 {
-    char *args;
     uint64_t actual;
 
-    args = g_strdup_printf("-nodefaults%s%s %s",
-                           machine ? " -M " : "",
-                           machine ?: "",
-                           test_args);
-    qtest_start(args);
+    global_qtest = qtest_init("-nodefaults%s%s %s",
+                              machine ? " -M " : "",
+                              machine ?: "",
+                              test_args);
     actual = read_boot_order();
     g_assert_cmphex(actual, ==, expected_boot);
     qmp_discard_response("{ 'execute': 'system_reset' }");
@@ -47,7 +45,6 @@ static void test_a_boot_order(const char *machine,
     actual = read_boot_order();
     g_assert_cmphex(actual, ==, expected_reboot);
     qtest_quit(global_qtest);
-    g_free(args);
 }
 
 static void test_boot_orders(const char *machine,
tests/boot-serial-test.c +4 -8
index b95c5e74ea..d7c0c320d7 100644
@@ -71,7 +71,6 @@ done:
 static void test_machine(const void *data)
 {
     const testdef_t *test = data;
-    char *args;
     char tmpname[] = "/tmp/qtest-boot-serial-XXXXXX";
     int fd;
 
@@ -82,18 +81,15 @@ static void test_machine(const void *data)
      * Make sure that this test uses tcg if available: It is used as a
      * fast-enough smoketest for that.
      */
-    args = g_strdup_printf("-M %s,accel=tcg:kvm "
-                           "-chardev file,id=serial0,path=%s "
-                           "-no-shutdown -serial chardev:serial0 %s",
-                           test->machine, tmpname, test->extra);
-
-    qtest_start(args);
+    global_qtest = qtest_init("-M %s,accel=tcg:kvm "
+                              "-chardev file,id=serial0,path=%s "
+                              "-no-shutdown -serial chardev:serial0 %s",
+                              test->machine, tmpname, test->extra);
     unlink(tmpname);
 
     check_guest_output(test, fd);
     qtest_quit(global_qtest);
 
-    g_free(args);
     close(fd);
 }
 
tests/device-introspect-test.c +12 -12
index f7162c023f..1c23b71038 100644
@@ -126,7 +126,7 @@ static void test_device_intro_list(void)
     QList *types;
     char *help;
 
-    qtest_start(common_args);
+    global_qtest = qtest_init("%s", common_args);
 
     types = device_type_list(true);
     QDECREF(types);
@@ -134,7 +134,7 @@ static void test_device_intro_list(void)
     help = hmp("device_add help");
     g_free(help);
 
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 /*
@@ -167,7 +167,7 @@ static void test_qom_list_fields(void)
     QList *non_abstract;
     QListEntry *e;
 
-    qtest_start(common_args);
+    global_qtest = qtest_init("%s", common_args);
 
     all_types = qom_list_types(NULL, true);
     non_abstract = qom_list_types(NULL, false);
@@ -189,21 +189,21 @@ static void test_qom_list_fields(void)
 
     QDECREF(all_types);
     QDECREF(non_abstract);
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 static void test_device_intro_none(void)
 {
-    qtest_start(common_args);
+    global_qtest = qtest_init("%s", common_args);
     test_one_device("nonexistent");
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 static void test_device_intro_abstract(void)
 {
-    qtest_start(common_args);
+    global_qtest = qtest_init("%s", common_args);
     test_one_device("device");
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 static void test_device_intro_concrete(void)
@@ -212,7 +212,7 @@ static void test_device_intro_concrete(void)
     QListEntry *entry;
     const char *type;
 
-    qtest_start(common_args);
+    global_qtest = qtest_init("%s", common_args);
     types = device_type_list(false);
 
     QLIST_FOREACH_ENTRY(types, entry) {
@@ -223,7 +223,7 @@ static void test_device_intro_concrete(void)
     }
 
     QDECREF(types);
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 static void test_abstract_interfaces(void)
@@ -232,7 +232,7 @@ static void test_abstract_interfaces(void)
     QListEntry *e;
     QDict *index;
 
-    qtest_start(common_args);
+    global_qtest = qtest_init("%s", common_args);
 
     all_types = qom_list_types("interface", true);
     index = qom_type_index(all_types);
@@ -257,7 +257,7 @@ static void test_abstract_interfaces(void)
 
     QDECREF(all_types);
     QDECREF(index);
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 int main(int argc, char **argv)
tests/display-vga-test.c +6 -12
index 2d7d24eee0..51c6feaaf1 100644
@@ -12,39 +12,33 @@
 
 static void pci_cirrus(void)
 {
-    qtest_start("-vga none -device cirrus-vga");
-    qtest_end();
+    qtest_quit(qtest_init("-vga none -device cirrus-vga"));
 }
 
 static void pci_stdvga(void)
 {
-    qtest_start("-vga none -device VGA");
-    qtest_end();
+    qtest_quit(qtest_init("-vga none -device VGA"));
 }
 
 static void pci_secondary(void)
 {
-    qtest_start("-vga none -device secondary-vga");
-    qtest_end();
+    qtest_quit(qtest_init("-vga none -device secondary-vga"));
 }
 
 static void pci_multihead(void)
 {
-    qtest_start("-vga none -device VGA -device secondary-vga");
-    qtest_end();
+    qtest_quit(qtest_init("-vga none -device VGA -device secondary-vga"));
 }
 
 static void pci_virtio_gpu(void)
 {
-    qtest_start("-vga none -device virtio-gpu-pci");
-    qtest_end();
+    qtest_quit(qtest_init("-vga none -device virtio-gpu-pci"));
 }
 
 #ifdef CONFIG_VIRTIO_VGA
 static void pci_virtio_vga(void)
 {
-    qtest_start("-vga none -device virtio-vga");
-    qtest_end();
+    qtest_quit(qtest_init("-vga none -device virtio-vga"));
 }
 #endif
 
tests/drive_del-test.c +9 -8
index 2175139abb..602ab062b4 100644
@@ -45,7 +45,7 @@ static void device_del(void)
 static void test_drive_without_dev(void)
 {
     /* Start with an empty drive */
-    qtest_start("-drive if=none,id=drive0");
+    global_qtest = qtest_init("-drive if=none,id=drive0");
 
     /* Delete the drive */
     drive_del();
@@ -55,7 +55,7 @@ static void test_drive_without_dev(void)
      */
     drive_add();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 static void test_after_failed_device_add(void)
@@ -63,7 +63,7 @@ static void test_after_failed_device_add(void)
     QDict *response;
     QDict *error;
 
-    qtest_start("-drive if=none,id=drive0");
+    global_qtest = qtest_init("-drive if=none,id=drive0");
 
     /* Make device_add fail.  If this leaks the virtio-blk-pci device then a
      * reference to drive0 will also be held (via qdev properties).
@@ -86,15 +86,16 @@ static void test_after_failed_device_add(void)
      */
     drive_add();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 static void test_drive_del_device_del(void)
 {
     /* Start with a drive used by a device that unplugs instantaneously */
-    qtest_start("-drive if=none,id=drive0,file=null-co://,format=raw"
-                " -device virtio-scsi-pci"
-                " -device scsi-hd,drive=drive0,id=dev0");
+    global_qtest = qtest_init(
+        "-drive if=none,id=drive0,file=null-co://,format=raw"
+        " -device virtio-scsi-pci"
+        " -device scsi-hd,drive=drive0,id=dev0");
 
     /*
      * Delete the drive, and then the device
@@ -103,7 +104,7 @@ static void test_drive_del_device_del(void)
     drive_del();
     device_del();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 int main(int argc, char **argv)
tests/ds1338-test.c +1 -1
index 26968bc82a..da5b852351 100644
@@ -60,7 +60,7 @@ int main(int argc, char **argv)
 
     g_test_init(&argc, &argv, NULL);
 
-    s = qtest_start("-display none -machine imx25-pdk");
+    s = global_qtest = qtest_init("-display none -machine imx25-pdk");
     i2c = imx_i2c_create(IMX25_I2C_0_BASE);
     addr = DS1338_ADDR;
 
tests/e1000-test.c +2 -8
index 0c5fcdcc44..59bd8b781f 100644
@@ -15,15 +15,9 @@ static void test_device(gconstpointer data)
 {
     const char *model = data;
     QTestState *s;
-    char *args;
 
-    args = g_strdup_printf("-device %s", model);
-    s = qtest_start(args);
-
-    if (s) {
-        qtest_quit(s);
-    }
-    g_free(args);
+    s = qtest_init("-device %s", model);
+    qtest_quit(s);
 }
 
 static const char *models[] = {
tests/e1000e-test.c +4 -10
index 32aa738b72..6ef240dc8f 100644
@@ -380,17 +380,11 @@ static void e1000e_device_clear(QPCIBus *bus, e1000e_device *d)
 
 static void data_test_init(e1000e_device *d)
 {
-    char *cmdline;
-
     int ret = socketpair(PF_UNIX, SOCK_STREAM, 0, test_sockets);
     g_assert_cmpint(ret, != , -1);
 
-    cmdline = g_strdup_printf("-netdev socket,fd=%d,id=hs0 "
+    global_qtest = qtest_init("-netdev socket,fd=%d,id=hs0 "
                               "-device e1000e,netdev=hs0", test_sockets[1]);
-    g_assert_nonnull(cmdline);
-
-    qtest_start(cmdline);
-    g_free(cmdline);
 
     test_alloc = pc_alloc_init(global_qtest);
     g_assert_nonnull(test_alloc);
@@ -408,7 +402,7 @@ static void data_test_clear(e1000e_device *d)
     pc_alloc_uninit(test_alloc);
     g_free(d->pci_dev);
     qpci_free_pc(test_bus);
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 static void test_e1000e_init(gconstpointer data)
@@ -458,12 +452,12 @@ static void test_e1000e_hotplug(gconstpointer data)
 {
     static const uint8_t slot = 0x06;
 
-    qtest_start("-device e1000e");
+    global_qtest = qtest_init("-device e1000e");
 
     qpci_plug_device_test("e1000e", "e1000e_net", slot, NULL);
     qpci_unplug_acpi_device_test("e1000e_net", slot);
 
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 int main(int argc, char **argv)
tests/eepro100-test.c +2 -9
index bdc8a67d57..6f49ac2656 100644
@@ -14,17 +14,10 @@ static void test_device(gconstpointer data)
 {
     const char *model = data;
     QTestState *s;
-    char *args;
-
-    args = g_strdup_printf("-device %s", model);
-    s = qtest_start(args);
 
     /* Tests only initialization so far. TODO: Implement functional tests */
-
-    if (s) {
-        qtest_quit(s);
-    }
-    g_free(args);
+    s = qtest_init("-device %s", model);
+    qtest_quit(s);
 }
 
 static const char *models[] = {
tests/endianness-test.c +12 -21
index ed0bf52019..68d5dbcd14 100644
@@ -114,13 +114,11 @@ static void isa_outl(const TestCase *test, uint16_t addr, uint32_t value)
 static void test_endianness(gconstpointer data)
 {
     const TestCase *test = data;
-    char *args;
 
-    args = g_strdup_printf("-M %s%s%s -device pc-testdev",
-                           test->machine,
-                           test->superio ? " -device " : "",
-                           test->superio ?: "");
-    qtest_start(args);
+    global_qtest = qtest_init("-M %s%s%s -device pc-testdev",
+                              test->machine,
+                              test->superio ? " -device " : "",
+                              test->superio ?: "");
     isa_outl(test, 0xe0, 0x87654321);
     g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654321);
     g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765);
@@ -183,19 +181,16 @@ static void test_endianness(gconstpointer data)
     g_assert_cmphex(isa_inb(test, 0xe1), ==, 0x43);
     g_assert_cmphex(isa_inb(test, 0xe0), ==, 0x21);
     qtest_quit(global_qtest);
-    g_free(args);
 }
 
 static void test_endianness_split(gconstpointer data)
 {
     const TestCase *test = data;
-    char *args;
 
-    args = g_strdup_printf("-M %s%s%s -device pc-testdev",
-                           test->machine,
-                           test->superio ? " -device " : "",
-                           test->superio ?: "");
-    qtest_start(args);
+    global_qtest = qtest_init("-M %s%s%s -device pc-testdev",
+                              test->machine,
+                              test->superio ? " -device " : "",
+                              test->superio ?: "");
     isa_outl(test, 0xe8, 0x87654321);
     g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654321);
     g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765);
@@ -230,19 +225,16 @@ static void test_endianness_split(gconstpointer data)
     g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765);
     g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4321);
     qtest_quit(global_qtest);
-    g_free(args);
 }
 
 static void test_endianness_combine(gconstpointer data)
 {
     const TestCase *test = data;
-    char *args;
 
-    args = g_strdup_printf("-M %s%s%s -device pc-testdev",
-                           test->machine,
-                           test->superio ? " -device " : "",
-                           test->superio ?: "");
-    qtest_start(args);
+    global_qtest = qtest_init("-M %s%s%s -device pc-testdev",
+                              test->machine,
+                              test->superio ? " -device " : "",
+                              test->superio ?: "");
     isa_outl(test, 0xe0, 0x87654321);
     g_assert_cmphex(isa_inl(test, 0xe8), ==, 0x87654321);
     g_assert_cmphex(isa_inw(test, 0xea), ==, 0x8765);
@@ -277,7 +269,6 @@ static void test_endianness_combine(gconstpointer data)
     g_assert_cmphex(isa_inw(test, 0xea), ==, 0x8765);
     g_assert_cmphex(isa_inw(test, 0xe8), ==, 0x4321);
     qtest_quit(global_qtest);
-    g_free(args);
 }
 
 int main(int argc, char **argv)
tests/es1370-test.c +2 -2
index 199fe193ce..edeea13ae7 100644
@@ -22,10 +22,10 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/es1370/nop", nop);
 
-    qtest_start("-device ES1370");
+    global_qtest = qtest_init("-device ES1370");
     ret = g_test_run();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/fdc-test.c +2 -2
index 325712e0f2..893097f5a3 100644
@@ -564,7 +564,7 @@ int main(int argc, char **argv)
     /* Run the tests */
     g_test_init(&argc, &argv, NULL);
 
-    qtest_start("-device floppy,id=floppy0");
+    global_qtest = qtest_init("-device floppy,id=floppy0");
     qtest_irq_intercept_in(global_qtest, "ioapic");
     qtest_add_func("/fdc/cmos", test_cmos);
     qtest_add_func("/fdc/no_media_on_start", test_no_media_on_start);
@@ -583,7 +583,7 @@ int main(int argc, char **argv)
     ret = g_test_run();
 
     /* Cleanup */
-    qtest_end();
+    qtest_quit(global_qtest);
     unlink(test_image);
 
     return ret;
tests/hd-geo-test.c +8 -8
index 24870b38f4..e0b19cdf17 100644
@@ -241,11 +241,11 @@ static void test_ide_none(void)
 
     setup_common(argv, ARGV_SIZE);
     args = g_strjoinv(" ", argv);
-    qtest_start(args);
+    global_qtest = qtest_init("%s", args);
     g_strfreev(argv);
     g_free(args);
     test_cmos();
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 static void test_ide_mbr(bool use_device, MBRcontents mbr)
@@ -263,11 +263,11 @@ static void test_ide_mbr(bool use_device, MBRcontents mbr)
         argc = setup_ide(argc, argv, ARGV_SIZE, i, dev, i, mbr, "");
     }
     args = g_strjoinv(" ", argv);
-    qtest_start(args);
+    global_qtest = qtest_init("%s", args);
     g_strfreev(argv);
     g_free(args);
     test_cmos();
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 /*
@@ -339,11 +339,11 @@ static void test_ide_drive_user(const char *dev, bool trans)
                      dev ? "" : opts);
     g_free(opts);
     args = g_strjoinv(" ", argv);
-    qtest_start(args);
+    global_qtest = qtest_init("%s", args);
     g_strfreev(argv);
     g_free(args);
     test_cmos();
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 /*
@@ -396,11 +396,11 @@ static void test_ide_drive_cd_0(void)
                          ide_idx, NULL, i, mbr_blank, "");
     }
     args = g_strjoinv(" ", argv);
-    qtest_start(args);
+    global_qtest = qtest_init("%s", args);
     g_strfreev(argv);
     g_free(args);
     test_cmos();
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 int main(int argc, char **argv)
tests/i440fx-test.c +6 -10
index 4390e5591e..bfedd5d953 100644
@@ -33,11 +33,7 @@ typedef struct FirmwareTestFixture {
 
 static QPCIBus *test_start_get_bus(const TestData *s)
 {
-    char *cmdline;
-
-    cmdline = g_strdup_printf("-smp %d", s->num_cpus);
-    qtest_start(cmdline);
-    g_free(cmdline);
+    global_qtest = qtest_init("-smp %d", s->num_cpus);
     return qpci_init_pc(global_qtest, NULL);
 }
 
@@ -136,7 +132,7 @@ static void test_i440fx_defaults(gconstpointer opaque)
 
     g_free(dev);
     qpci_free_pc(bus);
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 #define PAM_RE 1
@@ -275,7 +271,7 @@ static void test_i440fx_pam(gconstpointer opaque)
 
     g_free(dev);
     qpci_free_pc(bus);
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 #define BLOB_SIZE ((size_t)65536)
@@ -344,10 +340,10 @@ static void test_i440fx_firmware(FirmwareTestFixture *fixture,
                                          : "-drive if=pflash,format=raw,file=",
                               fw_pathname);
     g_test_message("qemu cmdline: %s", cmdline);
-    qtest_start(cmdline);
+    global_qtest = qtest_init("%s", cmdline);
     g_free(cmdline);
 
-    /* QEMU has loaded the firmware (because qtest_start() only returns after
+    /* QEMU has loaded the firmware (because qtest_init() only returns after
      * the QMP handshake completes). We must unlink the firmware blob right
      * here, because any assertion firing below would leak it in the
      * filesystem. This is also the reason why we recreate the blob every time
@@ -373,7 +369,7 @@ static void test_i440fx_firmware(FirmwareTestFixture *fixture,
     }
 
     g_free(buf);
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 static void add_firmware_test(const char *testpath,
tests/i82801b11-test.c +3 -2
index a6e31594c9..58436172b7 100644
@@ -22,10 +22,11 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/i82801b11/nop", nop);
 
-    qtest_start("-machine q35 -device i82801b11-bridge,bus=pcie.0,addr=1e.0");
+    global_qtest = qtest_init("-machine q35 "
+                              "-device i82801b11-bridge,bus=pcie.0,addr=1e.0");
     ret = g_test_run();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/ide-test.c +2 -2
index 084f6a5f96..b22a4fc1c5 100644
@@ -124,7 +124,7 @@ static void ide_test_start(const char *cmdline_fmt, ...)
     cmdline = g_strdup_vprintf(cmdline_fmt, ap);
     va_end(ap);
 
-    qtest_start(cmdline);
+    global_qtest = qtest_init("%s", cmdline);
     guest_malloc = pc_alloc_init(global_qtest);
 
     g_free(cmdline);
@@ -134,7 +134,7 @@ static void ide_test_quit(void)
 {
     pc_alloc_uninit(guest_malloc);
     guest_malloc = NULL;
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 static QPCIDevice *get_pci_device(QPCIBar *bmdma_bar, QPCIBar *ide_bar)
tests/intel-hda-test.c +6 -5
index b782b2e944..c10a59d932 100644
@@ -18,15 +18,16 @@
 /* Tests only initialization so far. TODO: Replace with functional tests */
 static void ich6_test(void)
 {
-    qtest_start("-device intel-hda,id=" HDA_ID CODEC_DEVICES);
-    qtest_end();
+    global_qtest = qtest_init("-device intel-hda,id=" HDA_ID CODEC_DEVICES);
+    qtest_quit(global_qtest);
 }
 
 static void ich9_test(void)
 {
-    qtest_start("-machine q35 -device ich9-intel-hda,bus=pcie.0,addr=1b.0,id="
-                HDA_ID CODEC_DEVICES);
-    qtest_end();
+    global_qtest = qtest_init(
+        "-machine q35 -device ich9-intel-hda,bus=pcie.0,addr=1b.0,id="
+        HDA_ID CODEC_DEVICES);
+    qtest_quit(global_qtest);
 }
 
 int main(int argc, char **argv)
tests/ioh3420-test.c +4 -3
index b54c4b9f11..cd5d062370 100644
@@ -22,11 +22,12 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/ioh3420/nop", nop);
 
-    qtest_start("-machine q35 -device ioh3420,bus=pcie.0,addr=1c.0,port=1,"
-                "chassis=1,multifunction=on");
+    global_qtest = qtest_init(
+        "-machine q35 -device ioh3420,bus=pcie.0,addr=1c.0,port=1,"
+        "chassis=1,multifunction=on");
     ret = g_test_run();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/ipmi-bt-test.c +4 -7
index 7e21a9bbcb..476d527cfd 100644
@@ -401,7 +401,6 @@ static void open_socket(void)
 int main(int argc, char **argv)
 {
     const char *arch = qtest_get_arch();
-    char *cmdline;
     int ret;
 
     /* Check architecture */
@@ -415,12 +414,10 @@ int main(int argc, char **argv)
     /* Run the tests */
     g_test_init(&argc, &argv, NULL);
 
-    cmdline = g_strdup_printf(
-          " -chardev socket,id=ipmi0,host=localhost,port=%d,reconnect=10"
-          " -device ipmi-bmc-extern,chardev=ipmi0,id=bmc0"
-          " -device isa-ipmi-bt,bmc=bmc0", emu_port);
-    qtest_start(cmdline);
-    g_free(cmdline);
+    global_qtest = qtest_init(
+        " -chardev socket,id=ipmi0,host=localhost,port=%d,reconnect=10"
+        " -device ipmi-bmc-extern,chardev=ipmi0,id=bmc0"
+        " -device isa-ipmi-bt,bmc=bmc0", emu_port);
     qtest_irq_intercept_in(global_qtest, "ioapic");
     qtest_add_func("/ipmi/extern/connect", test_connect);
     qtest_add_func("/ipmi/extern/bt_base", test_bt_base);
tests/ipmi-kcs-test.c +1 -4
index 178ffc1797..2bd3771e9f 100644
@@ -264,7 +264,6 @@ static void test_enable_irq(void)
 int main(int argc, char **argv)
 {
     const char *arch = qtest_get_arch();
-    char *cmdline;
     int ret;
 
     /* Check architecture */
@@ -276,10 +275,8 @@ int main(int argc, char **argv)
     /* Run the tests */
     g_test_init(&argc, &argv, NULL);
 
-    cmdline = g_strdup_printf("-device ipmi-bmc-sim,id=bmc0"
+    global_qtest = qtest_init("-device ipmi-bmc-sim,id=bmc0"
                               " -device isa-ipmi-kcs,bmc=bmc0");
-    qtest_start(cmdline);
-    g_free(cmdline);
     qtest_irq_intercept_in(global_qtest, "ioapic");
     qtest_add_func("/ipmi/local/kcs_base", test_kcs_base);
     qtest_add_func("/ipmi/local/kcs_abort", test_kcs_abort);
tests/ipoctal232-test.c +3 -2
index 684914164d..5e1cae3917 100644
@@ -22,10 +22,11 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/ipoctal232/tpci200/nop", nop);
 
-    qtest_start("-device tpci200,id=ipack0 -device ipoctal232,bus=ipack0.0");
+    global_qtest = qtest_init("-device tpci200,id=ipack0 "
+                              "-device ipoctal232,bus=ipack0.0");
     ret = g_test_run();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/ivshmem-test.c +2 -2
index b9e0f573f6..f254f09487 100644
@@ -407,7 +407,7 @@ static void test_ivshmem_hotplug(void)
     const char *arch = qtest_get_arch();
     gchar *opts;
 
-    qtest_start("");
+    global_qtest = qtest_init(" ");
 
     opts = g_strdup_printf("'shm': '%s', 'size': '1M'", tmpshm);
 
@@ -416,7 +416,7 @@ static void test_ivshmem_hotplug(void)
         qpci_unplug_acpi_device_test("iv1", PCI_SLOT_HP);
     }
 
-    qtest_end();
+    qtest_quit(global_qtest);
     g_free(opts);
 }
 
tests/libqos/libqos.c +1 -1
index 24e8156fe2..bd9106a132 100644
@@ -20,7 +20,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
     struct QOSState *qs = g_malloc(sizeof(QOSState));
 
     cmdline = g_strdup_vprintf(cmdline_fmt, ap);
-    qs->qts = qtest_start(cmdline);
+    qs->qts = global_qtest = qtest_init("%s", cmdline);
     qs->ops = ops;
     if (ops) {
         if (ops->init_allocator) {
tests/m25p80-test.c +3 -6
index 244aa33dd9..18135cfb86 100644
@@ -354,7 +354,6 @@ int main(int argc, char **argv)
 {
     int ret;
     int fd;
-    char *args;
 
     g_test_init(&argc, &argv, NULL);
 
@@ -364,10 +363,9 @@ int main(int argc, char **argv)
     g_assert(ret == 0);
     close(fd);
 
-    args = g_strdup_printf("-m 256 -machine palmetto-bmc "
-                           "-drive file=%s,format=raw,if=mtd",
-                           tmp_path);
-    qtest_start(args);
+    global_qtest = qtest_init("-m 256 -machine palmetto-bmc "
+                              "-drive file=%s,format=raw,if=mtd",
+                              tmp_path);
 
     qtest_add_func("/m25p80/read_jedec", test_read_jedec);
     qtest_add_func("/m25p80/erase_sector", test_erase_sector);
@@ -380,6 +378,5 @@ int main(int argc, char **argv)
 
     qtest_quit(global_qtest);
     unlink(tmp_path);
-    g_free(args);
     return ret;
 }
tests/m48t59-test.c +1 -1
index 0f921ef38a..52c61fe33e 100644
@@ -246,7 +246,7 @@ int main(int argc, char **argv)
 
     g_test_init(&argc, &argv, NULL);
 
-    s = qtest_start("-rtc clock=vm");
+    s = global_qtest = qtest_init("-rtc clock=vm");
 
     qtest_add_func("/rtc/bcd/check-time", bcd_check_time);
     qtest_add_func("/rtc/fuzz-registers", fuzz_registers);
tests/ne2000-test.c +2 -2
index b7cf3dd2f5..d205bc91a6 100644
@@ -22,10 +22,10 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/ne2000/pci/nop", pci_nop);
 
-    qtest_start("-device ne2k_pci");
+    global_qtest = qtest_init("-device ne2k_pci");
     ret = g_test_run();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/numa-test.c +14 -14
index e1b6152244..17bbc0f5f8 100644
@@ -25,14 +25,14 @@ static void test_mon_explicit(const void *data)
     cli = make_cli(data, "-smp 8 "
                    "-numa node,nodeid=0,cpus=0-3 "
                    "-numa node,nodeid=1,cpus=4-7 ");
-    qtest_start(cli);
+    global_qtest = qtest_init("%s", cli);
 
     s = hmp("info numa");
     g_assert(strstr(s, "node 0 cpus: 0 1 2 3"));
     g_assert(strstr(s, "node 1 cpus: 4 5 6 7"));
     g_free(s);
 
-    qtest_end();
+    qtest_quit(global_qtest);
     g_free(cli);
 }
 
@@ -42,14 +42,14 @@ static void test_mon_default(const void *data)
     char *cli;
 
     cli = make_cli(data, "-smp 8 -numa node -numa node");
-    qtest_start(cli);
+    global_qtest = qtest_init("%s", cli);
 
     s = hmp("info numa");
     g_assert(strstr(s, "node 0 cpus: 0 2 4 6"));
     g_assert(strstr(s, "node 1 cpus: 1 3 5 7"));
     g_free(s);
 
-    qtest_end();
+    qtest_quit(global_qtest);
     g_free(cli);
 }
 
@@ -61,14 +61,14 @@ static void test_mon_partial(const void *data)
     cli = make_cli(data, "-smp 8 "
                    "-numa node,nodeid=0,cpus=0-1 "
                    "-numa node,nodeid=1,cpus=4-5 ");
-    qtest_start(cli);
+    global_qtest = qtest_init("%s", cli);
 
     s = hmp("info numa");
     g_assert(strstr(s, "node 0 cpus: 0 1 2 3 6 7"));
     g_assert(strstr(s, "node 1 cpus: 4 5"));
     g_free(s);
 
-    qtest_end();
+    qtest_quit(global_qtest);
     g_free(cli);
 }
 
@@ -88,7 +88,7 @@ static void test_query_cpus(const void *data)
     QObject *e;
 
     cli = make_cli(data, "-smp 8 -numa node,cpus=0-3 -numa node,cpus=4-7");
-    qtest_start(cli);
+    global_qtest = qtest_init("%s", cli);
     cpus = get_cpus(&resp);
     g_assert(cpus);
 
@@ -113,7 +113,7 @@ static void test_query_cpus(const void *data)
     }
 
     QDECREF(resp);
-    qtest_end();
+    qtest_quit(global_qtest);
     g_free(cli);
 }
 
@@ -130,7 +130,7 @@ static void pc_numa_cpu(const void *data)
         "-numa cpu,node-id=0,socket-id=1,core-id=0 "
         "-numa cpu,node-id=0,socket-id=1,core-id=1,thread-id=0 "
         "-numa cpu,node-id=1,socket-id=1,core-id=1,thread-id=1");
-    qtest_start(cli);
+    global_qtest = qtest_init("%s", cli);
     cpus = get_cpus(&resp);
     g_assert(cpus);
 
@@ -166,7 +166,7 @@ static void pc_numa_cpu(const void *data)
     }
 
     QDECREF(resp);
-    qtest_end();
+    qtest_quit(global_qtest);
     g_free(cli);
 }
 
@@ -183,7 +183,7 @@ static void spapr_numa_cpu(const void *data)
         "-numa cpu,node-id=0,core-id=1 "
         "-numa cpu,node-id=0,core-id=2 "
         "-numa cpu,node-id=1,core-id=3");
-    qtest_start(cli);
+    global_qtest = qtest_init("%s", cli);
     cpus = get_cpus(&resp);
     g_assert(cpus);
 
@@ -211,7 +211,7 @@ static void spapr_numa_cpu(const void *data)
     }
 
     QDECREF(resp);
-    qtest_end();
+    qtest_quit(global_qtest);
     g_free(cli);
 }
 
@@ -226,7 +226,7 @@ static void aarch64_numa_cpu(const void *data)
         "-numa node,nodeid=0 -numa node,nodeid=1 "
         "-numa cpu,node-id=1,thread-id=0 "
         "-numa cpu,node-id=0,thread-id=1");
-    qtest_start(cli);
+    global_qtest = qtest_init("%s", cli);
     cpus = get_cpus(&resp);
     g_assert(cpus);
 
@@ -254,7 +254,7 @@ static void aarch64_numa_cpu(const void *data)
     }
 
     QDECREF(resp);
-    qtest_end();
+    qtest_quit(global_qtest);
     g_free(cli);
 }
 
tests/nvme-test.c +4 -3
index 7674a446e4..382d26671f 100644
@@ -22,11 +22,12 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/nvme/nop", nop);
 
-    qtest_start("-drive id=drv0,if=none,file=null-co://,format=raw "
-                "-device nvme,drive=drv0,serial=foo");
+    global_qtest = qtest_init(
+        "-drive id=drv0,if=none,file=null-co://,format=raw "
+        "-device nvme,drive=drv0,serial=foo");
     ret = g_test_run();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/pc-cpu-test.c +10 -16
index c4211a4e85..9c36051c07 100644
@@ -26,15 +26,13 @@ typedef struct PCTestData PCTestData;
 static void test_pc_with_cpu_add(gconstpointer data)
 {
     const PCTestData *s = data;
-    char *args;
     QDict *response;
     unsigned int i;
 
-    args = g_strdup_printf("-machine %s -cpu %s "
-                           "-smp sockets=%u,cores=%u,threads=%u,maxcpus=%u",
-                           s->machine, s->cpu_model,
-                           s->sockets, s->cores, s->threads, s->maxcpus);
-    qtest_start(args);
+    global_qtest = qtest_init("-machine %s -cpu %s "
+                              "-smp sockets=%u,cores=%u,threads=%u,maxcpus=%u",
+                              s->machine, s->cpu_model,
+                              s->sockets, s->cores, s->threads, s->maxcpus);
 
     for (i = s->sockets * s->cores * s->threads; i < s->maxcpus; i++) {
         response = qmp("{ 'execute': 'cpu-add',"
@@ -44,21 +42,18 @@ static void test_pc_with_cpu_add(gconstpointer data)
         QDECREF(response);
     }
 
-    qtest_end();
-    g_free(args);
+    qtest_quit(global_qtest);
 }
 
 static void test_pc_without_cpu_add(gconstpointer data)
 {
     const PCTestData *s = data;
-    char *args;
     QDict *response;
 
-    args = g_strdup_printf("-machine %s -cpu %s "
-                           "-smp sockets=%u,cores=%u,threads=%u,maxcpus=%u",
-                           s->machine, s->cpu_model,
-                           s->sockets, s->cores, s->threads, s->maxcpus);
-    qtest_start(args);
+    global_qtest = qtest_init("-machine %s -cpu %s "
+                              "-smp sockets=%u,cores=%u,threads=%u,maxcpus=%u",
+                              s->machine, s->cpu_model,
+                              s->sockets, s->cores, s->threads, s->maxcpus);
 
     response = qmp("{ 'execute': 'cpu-add',"
                    "  'arguments': { 'id': %d } }",
@@ -67,8 +62,7 @@ static void test_pc_without_cpu_add(gconstpointer data)
     g_assert(qdict_haskey(response, "error"));
     QDECREF(response);
 
-    qtest_end();
-    g_free(args);
+    qtest_quit(global_qtest);
 }
 
 static void test_data_free(gpointer data)
tests/pcnet-test.c +2 -2
index efb1ef44e9..23e36da805 100644
@@ -22,10 +22,10 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/pcnet/pci/nop", pci_nop);
 
-    qtest_start("-device pcnet");
+    global_qtest = qtest_init("-device pcnet");
     ret = g_test_run();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/pnv-xscom-test.c +2 -12
index 5adc3fd3a9..852322b3f2 100644
@@ -81,16 +81,11 @@ static void test_xscom_cfam_id(const PnvChip *chip)
 
 static void test_cfam_id(const void *data)
 {
-    char *args;
     const PnvChip *chip = data;
 
-    args = g_strdup_printf("-M powernv,accel=tcg -cpu %s", chip->cpu_model);
-
-    qtest_start(args);
+    global_qtest = qtest_init("-M powernv,accel=tcg -cpu %s", chip->cpu_model);
     test_xscom_cfam_id(chip);
     qtest_quit(global_qtest);
-
-    g_free(args);
 }
 
 #define PNV_XSCOM_EX_CORE_BASE(chip, i)                 \
@@ -109,16 +104,11 @@ static void test_xscom_core(const PnvChip *chip)
 
 static void test_core(const void *data)
 {
-    char *args;
     const PnvChip *chip = data;
 
-    args = g_strdup_printf("-M powernv,accel=tcg -cpu %s", chip->cpu_model);
-
-    qtest_start(args);
+    global_qtest = qtest_init("-M powernv,accel=tcg -cpu %s", chip->cpu_model);
     test_xscom_core(chip);
     qtest_quit(global_qtest);
-
-    g_free(args);
 }
 
 static void add_test(const char *name, void (*test)(const void *data))
tests/prom-env-test.c +5 -8
index eac207b30e..fffef0b252 100644
@@ -44,21 +44,18 @@ static void check_guest_memory(void)
 
 static void test_machine(const void *machine)
 {
-    char *args;
     const char *extra_args;
 
     /* The pseries firmware boots much faster without the default devices */
     extra_args = strcmp(machine, "pseries") == 0 ? "-nodefaults" : "";
 
-    args = g_strdup_printf("-M %s,accel=tcg %s -prom-env 'use-nvramrc?=true' "
-                           "-prom-env 'nvramrc=%x %x l!' ",
-                           (const char *)machine, extra_args, MAGIC, ADDRESS);
-
-    qtest_start(args);
+    global_qtest = qtest_init("-M %s,accel=tcg %s "
+                              "-prom-env 'use-nvramrc?=true' "
+                              "-prom-env 'nvramrc=%x %x l!' ",
+                              (const char *)machine, extra_args,
+                              MAGIC, ADDRESS);
     check_guest_memory();
     qtest_quit(global_qtest);
-
-    g_free(args);
 }
 
 static void add_tests(const char *machines[])
tests/pvpanic-test.c +2 -2
index 71ebb5c02c..48b71be26f 100644
@@ -37,10 +37,10 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/pvpanic/panic", test_panic);
 
-    qtest_start("-device pvpanic");
+    global_qtest = qtest_init("-device pvpanic");
     ret = g_test_run();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/pxe-test.c +5 -9
index e2d3853534..eaad88601a 100644
@@ -23,17 +23,13 @@ static char disk[] = "tests/pxe-test-disk-XXXXXX";
 
 static void test_pxe_one(const char *params, bool ipv6)
 {
-    char *args;
-
-    args = g_strdup_printf("-machine accel=kvm:tcg -nodefaults -boot order=n "
-                           "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,"
-                           "ipv4=%s,ipv6=%s %s", disk, ipv6 ? "off" : "on",
-                           ipv6 ? "on" : "off", params);
-
-    qtest_start(args);
+    global_qtest = qtest_init("-machine accel=kvm:tcg -nodefaults "
+                              "-boot order=n "
+                              "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,"
+                              "ipv4=%s,ipv6=%s %s", disk, ipv6 ? "off" : "on",
+                              ipv6 ? "on" : "off", params);
     boot_sector_test(global_qtest);
     qtest_quit(global_qtest);
-    g_free(args);
 }
 
 static void test_pxe_e1000(void)
tests/q35-test.c +4 -4
index e149c4c51d..91a189ce62 100644
@@ -84,7 +84,7 @@ static void test_smram_lock(void)
     QPCIDevice *pcidev;
     QDict *response;
 
-    qtest_start("-M q35");
+    global_qtest = qtest_init("-M q35");
 
     pcibus = qpci_init_pc(global_qtest, NULL);
     g_assert(pcibus != NULL);
@@ -119,7 +119,7 @@ static void test_smram_lock(void)
     g_free(pcidev);
     qpci_free_pc(pcibus);
 
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 static void test_tseg_size(const void *data)
@@ -141,7 +141,7 @@ static void test_tseg_size(const void *data)
         cmdline = g_strdup_printf("-M q35 -m %uM",
                                   TSEG_SIZE_TEST_GUEST_RAM_MBYTES);
     }
-    qtest_start(cmdline);
+    global_qtest = qtest_init("%s", cmdline);
     g_free(cmdline);
 
     /* locate the DRAM controller */
@@ -185,7 +185,7 @@ static void test_tseg_size(const void *data)
 
     g_free(pcidev);
     qpci_free_pc(pcibus);
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 int main(int argc, char **argv)
tests/qom-test.c +2 -5
index ab0595dc75..5edd735387 100644
@@ -90,11 +90,9 @@ static void test_properties(const char *path, bool recurse)
 static void test_machine(gconstpointer data)
 {
     const char *machine = data;
-    char *args;
     QDict *response;
 
-    args = g_strdup_printf("-machine %s", machine);
-    qtest_start(args);
+    global_qtest = qtest_init("-machine %s", machine);
 
     test_properties("/machine", true);
 
@@ -102,8 +100,7 @@ static void test_machine(gconstpointer data)
     g_assert(qdict_haskey(response, "return"));
     QDECREF(response);
 
-    qtest_end();
-    g_free(args);
+    qtest_quit(global_qtest);
     g_free((void *)machine);
 }
 
tests/rtc-test.c +1 -1
index d7a96cbd79..b6058d28f5 100644
@@ -690,7 +690,7 @@ int main(int argc, char **argv)
 
     g_test_init(&argc, &argv, NULL);
 
-    s = qtest_start("-rtc clock=vm");
+    s = global_qtest = qtest_init("-rtc clock=vm");
     qtest_irq_intercept_in(s, "ioapic");
 
     qtest_add_func("/rtc/check-time/bcd", bcd_check_time);
tests/rtl8139-test.c +2 -2
index 68bfc42178..dc9935439f 100644
@@ -197,7 +197,7 @@ int main(int argc, char **argv)
 {
     int ret;
 
-    qtest_start("-device rtl8139");
+    global_qtest = qtest_init("-device rtl8139");
 
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/rtl8139/nop", nop);
@@ -205,7 +205,7 @@ int main(int argc, char **argv)
 
     ret = g_test_run();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/spapr-phb-test.c +3 -2
index d3522ea093..0d26cbda6c 100644
@@ -25,11 +25,12 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/spapr-phb/device", test_phb_device);
 
-    qtest_start("-device " TYPE_SPAPR_PCI_HOST_BRIDGE ",index=30");
+    global_qtest = qtest_init("-device " TYPE_SPAPR_PCI_HOST_BRIDGE
+                              ",index=30");
 
     ret = g_test_run();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/tco-test.c +5 -7
index 0387971953..b2a4baeeef 100644
@@ -49,20 +49,18 @@ static void test_end(TestData *d)
 {
     g_free(d->dev);
     qpci_free_pc(d->bus);
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 static void test_init(TestData *d)
 {
     QTestState *qs;
-    char *s;
 
-    s = g_strdup_printf("-machine q35 %s %s",
-                        d->noreboot ? "" : "-global ICH9-LPC.noreboot=false",
-                        !d->args ? "" : d->args);
-    qs = qtest_start(s);
+    qs = qtest_init("-machine q35 %s %s",
+                    d->noreboot ? "" : "-global ICH9-LPC.noreboot=false",
+                    !d->args ? "" : d->args);
+    global_qtest = qs;
     qtest_irq_intercept_in(qs, "ioapic");
-    g_free(s);
 
     d->bus = qpci_init_pc(qs, NULL);
     d->dev = qpci_device_find(d->bus, QPCI_DEVFN(0x1f, 0x00));
tests/test-arm-mptimer.c +2 -2
index cb8f2df914..a4bef2322a 100644
@@ -1097,9 +1097,9 @@ tests_with_prescaler_arg:
         goto tests_with_prescaler_arg;
     }
 
-    qtest_start("-machine vexpress-a9");
+    global_qtest = qtest_init("-machine vexpress-a9");
     ret = g_test_run();
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/test-filter-mirror.c +7 -9
index d569d27657..9d8608a609 100644
@@ -18,7 +18,6 @@
 static void test_mirror(void)
 {
     int send_sock[2], recv_sock;
-    char *cmdline;
     uint32_t ret = 0, len = 0;
     char send_buf[] = "Hello! filter-mirror~";
     char sock_path[] = "filter-mirror.XXXXXX";
@@ -37,13 +36,12 @@ static void test_mirror(void)
     ret = mkstemp(sock_path);
     g_assert_cmpint(ret, !=, -1);
 
-    cmdline = g_strdup_printf("-netdev socket,id=qtest-bn0,fd=%d "
-                 "-device %s,netdev=qtest-bn0,id=qtest-e0 "
-                 "-chardev socket,id=mirror0,path=%s,server,nowait "
-                 "-object filter-mirror,id=qtest-f0,netdev=qtest-bn0,queue=tx,outdev=mirror0 "
-                 , send_sock[1], devstr, sock_path);
-    qtest_start(cmdline);
-    g_free(cmdline);
+    global_qtest = qtest_init(
+        "-netdev socket,id=qtest-bn0,fd=%d "
+        "-device %s,netdev=qtest-bn0,id=qtest-e0 "
+        "-chardev socket,id=mirror0,path=%s,server,nowait "
+        "-object filter-mirror,id=qtest-f0,netdev=qtest-bn0,queue=tx,outdev=mirror0 "
+        , send_sock[1], devstr, sock_path);
 
     recv_sock = unix_connect(sock_path, NULL);
     g_assert_cmpint(recv_sock, !=, -1);
@@ -86,7 +84,7 @@ int main(int argc, char **argv)
 
     qtest_add_func("/netfilter/mirror", test_mirror);
     ret = g_test_run();
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/test-filter-redirector.c +28 -32

95 lines not on this page · raw message

tests/test-hmp.c +2 -5
index 729c0339f7..dd03693707 100644
@@ -119,16 +119,13 @@ static void test_info_commands(void)
 static void test_machine(gconstpointer data)
 {
     const char *machine = data;
-    char *args;
 
-    args = g_strdup_printf("-S -M %s", machine);
-    qtest_start(args);
+    global_qtest = qtest_init("-S -M %s", machine);
 
     test_info_commands();
     test_commands();
 
-    qtest_end();
-    g_free(args);
+    qtest_quit(global_qtest);
     g_free((void *)data);
 }
 
tests/test-netfilter.c +3 -6
index 2506473365..76caaedfc1 100644
@@ -182,7 +182,6 @@ static void remove_netdev_with_multi_netfilter(void)
 int main(int argc, char **argv)
 {
     int ret;
-    char *args;
     const char *devstr = "e1000";
 
     if (g_str_equal(qtest_get_arch(), "s390x")) {
@@ -197,13 +196,11 @@ int main(int argc, char **argv)
     qtest_add_func("/netfilter/remove_netdev_multi",
                    remove_netdev_with_multi_netfilter);
 
-    args = g_strdup_printf("-netdev user,id=qtest-bn0 "
-                           "-device %s,netdev=qtest-bn0", devstr);
-    qtest_start(args);
+    global_qtest = qtest_init("-netdev user,id=qtest-bn0 "
+                              "-device %s,netdev=qtest-bn0", devstr);
     ret = g_test_run();
 
-    qtest_end();
-    g_free(args);
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/test-x86-cpuid-compat.c +7 -6
index 58a2dd9fe8..5b026ac38a 100644
@@ -59,12 +59,12 @@ static void test_cpuid_prop(const void *data)
     QNum *value;
     int64_t val;
 
-    qtest_start(args->cmdline);
+    global_qtest = qtest_init("%s", args->cmdline);
     path = get_cpu0_qom_path();
     value = qobject_to_qnum(qom_get(path, args->property));
     g_assert(qnum_get_try_int(value, &val));
     g_assert_cmpint(val, ==, args->expected_value);
-    qtest_end();
+    qtest_quit(global_qtest);
 
     QDECREF(value);
     g_free(path);
@@ -131,13 +131,13 @@ static void test_feature_flag(const void *data)
     QList *present, *filtered;
     uint32_t value;
 
-    qtest_start(args->cmdline);
+    global_qtest = qtest_init("%s", args->cmdline);
     path = get_cpu0_qom_path();
     present = qobject_to_qlist(qom_get(path, "feature-words"));
     filtered = qobject_to_qlist(qom_get(path, "filtered-features"));
     value = get_feature_word(present, args->in_eax, args->in_ecx, args->reg);
     value |= get_feature_word(filtered, args->in_eax, args->in_ecx, args->reg);
-    qtest_end();
+    qtest_quit(global_qtest);
 
     g_assert(!!(value & (1U << args->bitnr)) == args->expected_value);
 
@@ -181,7 +181,8 @@ static void test_plus_minus_subprocess(void)
      * Note: rules 1 and 2 are planned to be removed soon, and
      * should generate a warning.
      */
-    qtest_start("-cpu pentium,-fpu,+fpu,-mce,mce=on,+cx8,cx8=off,+sse4_1,sse4_2=on");
+    global_qtest = qtest_init("-cpu pentium,-fpu,+fpu,-mce,mce=on,+cx8,"
+                              "cx8=off,+sse4_1,sse4_2=on");
     path = get_cpu0_qom_path();
 
     g_assert_false(qom_get_bool(path, "fpu"));
@@ -195,7 +196,7 @@ static void test_plus_minus_subprocess(void)
     g_assert_true(qom_get_bool(path, "sse4-2"));
     g_assert_true(qom_get_bool(path, "sse4.2"));
 
-    qtest_end();
+    qtest_quit(global_qtest);
     g_free(path);
 }
 
tests/tmp105-test.c +1 -1
index a7940a4639..3ef2efff6e 100644
@@ -151,7 +151,7 @@ int main(int argc, char **argv)
 
     g_test_init(&argc, &argv, NULL);
 
-    s = qtest_start("-machine n800 "
+    s = global_qtest = qtest_init("-machine n800 "
                     "-device tmp105,bus=i2c-bus.0,id=" TMP105_TEST_ID
                     ",address=0x49");
     i2c = omap_i2c_create(OMAP2_I2C_1_BASE);
tests/tpci200-test.c +2 -2
index 0321ec27ec..2ed378196d 100644
@@ -22,10 +22,10 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/tpci200/nop", nop);
 
-    qtest_start("-device tpci200");
+    global_qtest = qtest_init("-device tpci200");
     ret = g_test_run();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/usb-hcd-ehci-test.c +13 -12
index 55d4743a2a..55349a39a2 100644
@@ -156,23 +156,24 @@ int main(int argc, char **argv)
     qtest_add_func("/ehci/pci/ehci-port-2", pci_ehci_port_2);
     qtest_add_func("/ehci/pci/ehci-port-3-hotplug", pci_ehci_port_hotplug);
 
-    qtest_start("-machine q35 -device ich9-usb-ehci1,bus=pcie.0,addr=1d.7,"
-                "multifunction=on,id=ich9-ehci-1 "
-                "-device ich9-usb-uhci1,bus=pcie.0,addr=1d.0,"
-                "multifunction=on,masterbus=ich9-ehci-1.0,firstport=0 "
-                "-device ich9-usb-uhci2,bus=pcie.0,addr=1d.1,"
-                "multifunction=on,masterbus=ich9-ehci-1.0,firstport=2 "
-                "-device ich9-usb-uhci3,bus=pcie.0,addr=1d.2,"
-                "multifunction=on,masterbus=ich9-ehci-1.0,firstport=4 "
-                "-drive if=none,id=usbcdrom,media=cdrom "
-                "-device usb-tablet,bus=ich9-ehci-1.0,port=1,usb_version=1 "
-                "-device usb-storage,bus=ich9-ehci-1.0,port=2,drive=usbcdrom ");
+    global_qtest = qtest_init(
+        "-machine q35 -device ich9-usb-ehci1,bus=pcie.0,addr=1d.7,"
+        "multifunction=on,id=ich9-ehci-1 "
+        "-device ich9-usb-uhci1,bus=pcie.0,addr=1d.0,"
+        "multifunction=on,masterbus=ich9-ehci-1.0,firstport=0 "
+        "-device ich9-usb-uhci2,bus=pcie.0,addr=1d.1,"
+        "multifunction=on,masterbus=ich9-ehci-1.0,firstport=2 "
+        "-device ich9-usb-uhci3,bus=pcie.0,addr=1d.2,"
+        "multifunction=on,masterbus=ich9-ehci-1.0,firstport=4 "
+        "-drive if=none,id=usbcdrom,media=cdrom "
+        "-device usb-tablet,bus=ich9-ehci-1.0,port=1,usb_version=1 "
+        "-device usb-storage,bus=ich9-ehci-1.0,port=2,drive=usbcdrom ");
 
     test_init();
     ret = g_test_run();
     test_deinit();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/usb-hcd-ohci-test.c +2 -2
index 4758813d78..2763c9ec24 100644
@@ -31,9 +31,9 @@ int main(int argc, char **argv)
     qtest_add_func("/ohci/pci/init", test_ohci_init);
     qtest_add_func("/ohci/pci/hotplug", test_ohci_hotplug);
 
-    qtest_start("-device pci-ohci,id=ohci");
+    global_qtest = qtest_init("-device pci-ohci,id=ohci");
     ret = g_test_run();
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/usb-hcd-xhci-test.c +2 -2
index c05a339894..cc3fcd82fa 100644
@@ -80,10 +80,10 @@ int main(int argc, char **argv)
     qtest_add_func("/xhci/pci/hotplug", test_xhci_hotplug);
     qtest_add_func("/xhci/pci/hotplug/usb-uas", test_usb_uas_hotplug);
 
-    qtest_start("-device nec-usb-xhci,id=xhci"
+    global_qtest = qtest_init("-device nec-usb-xhci,id=xhci"
                 " -drive id=drive0,if=none,file=null-co://,format=raw");
     ret = g_test_run();
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/virtio-balloon-test.c +2 -2
index 0d0046bf25..7304392c17 100644
@@ -22,10 +22,10 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/virtio/balloon/pci/nop", pci_nop);
 
-    qtest_start("-device virtio-balloon-pci");
+    global_qtest = qtest_init("-device virtio-balloon-pci");
     ret = g_test_run();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/virtio-blk-test.c +5 -8
index 26d0a7e9af..063b0f4013 100644
@@ -84,24 +84,21 @@ static QOSState *pci_test_start(void)
 
 static void arm_test_start(void)
 {
-    char *cmdline;
     char *tmp_path;
 
     tmp_path = drive_create();
 
-    cmdline = g_strdup_printf("-machine virt "
-                                "-drive if=none,id=drive0,file=%s,format=raw "
-                                "-device virtio-blk-device,drive=drive0",
-                                tmp_path);
-    qtest_start(cmdline);
+    global_qtest = qtest_init("-machine virt "
+                              "-drive if=none,id=drive0,file=%s,format=raw "
+                              "-device virtio-blk-device,drive=drive0",
+                              tmp_path);
     unlink(tmp_path);
     g_free(tmp_path);
-    g_free(cmdline);
 }
 
 static void test_end(void)
 {
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 static QVirtioPCIDevice *virtio_blk_pci_init(QPCIBus *bus, int slot)
tests/virtio-console-test.c +4 -4
index 1c3de072f4..73fb30b051 100644
@@ -13,16 +13,16 @@
 /* Tests only initialization so far. TODO: Replace with functional tests */
 static void console_pci_nop(void)
 {
-    qtest_start("-device virtio-serial-pci,id=vser0 "
+    global_qtest = qtest_init("-device virtio-serial-pci,id=vser0 "
                 "-device virtconsole,bus=vser0.0");
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 static void serialport_pci_nop(void)
 {
-    qtest_start("-device virtio-serial-pci,id=vser0 "
+    global_qtest = qtest_init("-device virtio-serial-pci,id=vser0 "
                 "-device virtserialport,bus=vser0.0");
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 int main(int argc, char **argv)
tests/virtio-net-test.c +2 -2
index 635b942c36..9b32866fb1 100644
@@ -30,7 +30,7 @@
 
 static void test_end(void)
 {
-    qtest_end();
+    qtest_quit(global_qtest);
 }
 
 #ifndef _WIN32
@@ -243,7 +243,7 @@ static void hotplug(void)
 {
     const char *arch = qtest_get_arch();
 
-    qtest_start("-device virtio-net-pci");
+    global_qtest = qtest_init("-device virtio-net-pci");
 
     qpci_plug_device_test("virtio-net-pci", "net1", PCI_SLOT_HP, NULL);
 
tests/virtio-rng-test.c +2 -2
index dcecf77463..e1b1e89b59 100644
@@ -37,10 +37,10 @@ int main(int argc, char **argv)
     qtest_add_func("/virtio/rng/pci/nop", pci_nop);
     qtest_add_func("/virtio/rng/pci/hotplug", hotplug);
 
-    qtest_start("-device virtio-rng-pci");
+    global_qtest = qtest_init("-device virtio-rng-pci");
     ret = g_test_run();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/virtio-serial-test.c +2 -2
index b14d943ada..ce708cc11e 100644
@@ -49,10 +49,10 @@ int main(int argc, char **argv)
     qtest_add_func("/virtio/serial/pci/nop", pci_nop);
     qtest_add_func("/virtio/serial/pci/hotplug", hotplug);
 
-    qtest_start("-device virtio-serial-pci");
+    global_qtest = qtest_init("-device virtio-serial-pci");
     ret = g_test_run();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
tests/vmgenid-test.c +8 -21
index 73473162d0..b149690a1a 100644
@@ -130,41 +130,32 @@ static void read_guid_from_monitor(QemuUUID *guid)
 
 static char disk[] = "tests/vmgenid-test-disk-XXXXXX";
 
-static char *guid_cmd_strdup(const char *guid)
-{
-    return g_strdup_printf("-machine accel=kvm:tcg "
-                           "-device vmgenid,id=testvgid,guid=%s "
-                           "-drive id=hd0,if=none,file=%s,format=raw "
-                           "-device ide-hd,drive=hd0 ",
-                           guid, disk);
-}
-
+#define GUID_CMD(guid)                          \
+    "-machine accel=kvm:tcg "                   \
+    "-device vmgenid,id=testvgid,guid=%s "      \
+    "-drive id=hd0,if=none,file=%s,format=raw " \
+    "-device ide-hd,drive=hd0 ", guid, disk
 
 static void vmgenid_set_guid_test(void)
 {
     QemuUUID expected, measured;
-    gchar *cmd;
 
     g_assert(qemu_uuid_parse(VGID_GUID, &expected) == 0);
 
-    cmd = guid_cmd_strdup(VGID_GUID);
-    qtest_start(cmd);
+    global_qtest = qtest_init(GUID_CMD(VGID_GUID));
 
     /* Read the GUID from accessing guest memory */
     read_guid_from_memory(&measured);
     g_assert(memcmp(measured.data, expected.data, sizeof(measured.data)) == 0);
 
     qtest_quit(global_qtest);
-    g_free(cmd);
 }
 
 static void vmgenid_set_guid_auto_test(void)
 {
-    char *cmd;
     QemuUUID measured;
 
-    cmd = guid_cmd_strdup("auto");
-    qtest_start(cmd);
+    global_qtest = qtest_init(GUID_CMD("auto"));
 
     read_guid_from_memory(&measured);
 
@@ -172,25 +163,21 @@ static void vmgenid_set_guid_auto_test(void)
     g_assert(!qemu_uuid_is_null(&measured));
 
     qtest_quit(global_qtest);
-    g_free(cmd);
 }
 
 static void vmgenid_query_monitor_test(void)
 {
     QemuUUID expected, measured;
-    gchar *cmd;
 
     g_assert(qemu_uuid_parse(VGID_GUID, &expected) == 0);
 
-    cmd = guid_cmd_strdup(VGID_GUID);
-    qtest_start(cmd);
+    global_qtest = qtest_init(GUID_CMD(VGID_GUID));
 
     /* Read the GUID via the monitor */
     read_guid_from_monitor(&measured);
     g_assert(memcmp(measured.data, expected.data, sizeof(measured.data)) == 0);
 
     qtest_quit(global_qtest);
-    g_free(cmd);
 }
 
 int main(int argc, char **argv)
tests/vmxnet3-test.c +2 -2
index 159c0ad728..c9a876bcd9 100644
@@ -22,10 +22,10 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/vmxnet3/nop", nop);
 
-    qtest_start("-device vmxnet3");
+    global_qtest = qtest_init("-device vmxnet3");
     ret = g_test_run();
 
-    qtest_end();
+    qtest_quit(global_qtest);
 
     return ret;
 }
Signature · 1 line
2.13.5
Reviewed-by on v6 28/29
#91 lore raw

Re: [Qemu-devel] [PATCH v6 28/29] libqtest: Remove qtest_start() and qtest_end() shortcuts

Quoted 8 lines · Eric Blake

Remove the trivial wrappers qtest_start() and qtest_end(), to make it obvious in the rest of the testsuite where we are still relying on global_qtest. Doing this makes it easier to see what remaining cleanups will be needed if we don't want an implicit dependency on global state. Many tests can also take advantage of qtest_init() doing formatting of args, avoiding a temporary local variable.

diffstat looks like a win overall, unless it's just a local minima ;)

#92 lore raw

Re: [Qemu-devel] [PATCH v6 28/29] libqtest: Remove qtest_start() and qtest_end() shortcuts

In reply to Eric Blake
Quoted 124 lines · Eric Blake

Remove the trivial wrappers qtest_start() and qtest_end(), to make it obvious in the rest of the testsuite where we are still relying on global_qtest. Doing this makes it easier to see what remaining cleanups will be needed if we don't want an implicit dependency on global state. Many tests can also take advantage of qtest_init() doing formatting of args, avoiding a temporary local variable.

---
 tests/libqtest.h               | 26 ------------------
 tests/libqtest.c               |  4 +--
 tests/ac97-test.c              |  4 +--
 tests/boot-order-test.c        | 11 +++-----
 tests/boot-serial-test.c       | 12 +++------
 tests/device-introspect-test.c | 24 ++++++++---------
 tests/display-vga-test.c       | 18 +++++--------
 tests/drive_del-test.c         | 17 ++++++------
 tests/ds1338-test.c            |  2 +-
 tests/e1000-test.c             | 10 ++-----
 tests/e1000e-test.c            | 14 +++-------
 tests/eepro100-test.c          | 11 ++------
 tests/endianness-test.c        | 33 +++++++++--------------
 tests/es1370-test.c            |  4 +--
 tests/fdc-test.c               |  4 +--
 tests/hd-geo-test.c            | 16 +++++------
 tests/i440fx-test.c            | 16 +++++------
 tests/i82801b11-test.c         |  5 ++--
 tests/ide-test.c               |  4 +--
 tests/intel-hda-test.c         | 11 ++++----
 tests/ioh3420-test.c           |  7 ++---
 tests/ipmi-bt-test.c           | 11 +++-----
 tests/ipmi-kcs-test.c          |  5 +---
 tests/ipoctal232-test.c        |  5 ++--
 tests/ivshmem-test.c           |  4 +--
 tests/libqos/libqos.c          |  2 +-
 tests/m25p80-test.c            |  9 +++----
 tests/m48t59-test.c            |  2 +-
 tests/ne2000-test.c            |  4 +--
 tests/numa-test.c              | 28 ++++++++++----------
 tests/nvme-test.c              |  7 ++---
 tests/pc-cpu-test.c            | 26 +++++++-----------
 tests/pcnet-test.c             |  4 +--
 tests/pnv-xscom-test.c         | 14 ++--------
 tests/prom-env-test.c          | 13 ++++-----
 tests/pvpanic-test.c           |  4 +--
 tests/pxe-test.c               | 14 ++++------
 tests/q35-test.c               |  8 +++---
 tests/qom-test.c               |  7 ++---
 tests/rtc-test.c               |  2 +-
 tests/rtl8139-test.c           |  4 +--
 tests/spapr-phb-test.c         |  5 ++--
 tests/tco-test.c               | 12 ++++-----
 tests/test-arm-mptimer.c       |  4 +--
 tests/test-filter-mirror.c     | 16 +++++------
 tests/test-filter-redirector.c | 60 ++++++++++++++++++++----------------------
 tests/test-hmp.c               |  7 ++---
 tests/test-netfilter.c         |  9 +++----
 tests/test-x86-cpuid-compat.c  | 13 ++++-----
 tests/tmp105-test.c            |  2 +-
 tests/tpci200-test.c           |  4 +--
 tests/usb-hcd-ehci-test.c      | 25 +++++++++---------
 tests/usb-hcd-ohci-test.c      |  4 +--
 tests/usb-hcd-xhci-test.c      |  4 +--
 tests/virtio-balloon-test.c    |  4 +--
 tests/virtio-blk-test.c        | 13 ++++-----
 tests/virtio-console-test.c    |  8 +++---
 tests/virtio-net-test.c        |  4 +--
 tests/virtio-rng-test.c        |  4 +--
 tests/virtio-serial-test.c     |  4 +--
 tests/vmgenid-test.c           | 29 ++++++--------------
 tests/vmxnet3-test.c           |  4 +--
 62 files changed, 267 insertions(+), 394 deletions(-)
tests/libqtest.h +0 -26
index d338de3e22..0459526187 100644
@@ -509,32 +509,6 @@ void qtest_add_data_func_full(const char *str, void *data,
 void qtest_add_abrt_handler(GHookFunc fn, const void *data);
 
 /**
- * qtest_start:
- * @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("%s", args);
-    return global_qtest;
-}
-
-/**
- * qtest_end:
- *
- * Shut down the QEMU process started by qtest_start().
- */
-static inline void qtest_end(void)
-{
-    qtest_quit(global_qtest);
-    global_qtest = NULL;
-}
-
-/**
  * qmp:
  * @fmt...: QMP message to send to qemu
  *
tests/libqtest.c +1 -1
index 18facbf130..fa4e47c137 100644
@@ -970,7 +970,7 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine))
     QString *qstr;
     const char *mname;
 
-    qtest_start("-machine none");
+    global_qtest = qtest_init("-machine none");
     response = qmp("{ 'execute': 'query-machines' }");
     g_assert(response);
     list = qdict_get_qlist(response, "return");

tests/libqtest.c void qtest_cb_for_every_machine(void (*cb)(const char *machine)) · line 992

Quoted 7 lines
tests/libqtest.c +1 -1
@@ -987,6 +987,6 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine))
         cb(mname);
     }
 
-    qtest_end();
+    qtest_quit(global_qtest);
     QDECREF(response);
 }

[...]

Maybe this patch could be postponed 'till we can completely remove global_qtest? Otherwise you've got to change these lines over and over again...

Thomas

author
#93 lore raw

PATCH v6 29/29 libqtest: Rename qtest_init() to qtest_start()

In reply to Eric Blake

We already have another qtest_init() in the tree, for the top-level qtest.c device; having two functions with different signatures is confusing. Rename the libqtest version to qtest_start() to eliminate the duplication.

---
 tests/libqtest.h               |  8 ++++----
 tests/libqtest.c               |  8 ++++----
 tests/ac97-test.c              |  2 +-
 tests/bios-tables-test.c       | 12 ++++++------
 tests/boot-order-test.c        |  8 ++++----
 tests/boot-serial-test.c       |  8 ++++----
 tests/device-introspect-test.c | 12 ++++++------
 tests/display-vga-test.c       | 12 ++++++------
 tests/drive_del-test.c         |  6 +++---
 tests/ds1338-test.c            |  2 +-
 tests/e1000-test.c             |  2 +-
 tests/e1000e-test.c            |  6 +++---
 tests/eepro100-test.c          |  2 +-
 tests/endianness-test.c        | 24 ++++++++++++------------
 tests/es1370-test.c            |  2 +-
 tests/fdc-test.c               |  2 +-
 tests/fw_cfg-test.c            |  2 +-
 tests/hd-geo-test.c            |  8 ++++----
 tests/i440fx-test.c            |  6 +++---
 tests/i82801b11-test.c         |  4 ++--
 tests/ide-test.c               |  2 +-
 tests/intel-hda-test.c         |  4 ++--
 tests/ioh3420-test.c           |  2 +-
 tests/ipmi-bt-test.c           |  2 +-
 tests/ipmi-kcs-test.c          |  4 ++--
 tests/ipoctal232-test.c        |  4 ++--
 tests/ivshmem-test.c           |  2 +-
 tests/libqos/libqos.c          |  2 +-
 tests/m25p80-test.c            |  6 +++---
 tests/m48t59-test.c            |  2 +-
 tests/ne2000-test.c            |  2 +-
 tests/numa-test.c              | 14 +++++++-------
 tests/nvme-test.c              |  2 +-
 tests/pc-cpu-test.c            | 16 ++++++++--------
 tests/pcnet-test.c             |  2 +-
 tests/pnv-xscom-test.c         |  4 ++--
 tests/postcopy-test.c          |  4 ++--
 tests/prom-env-test.c          | 10 +++++-----
 tests/pvpanic-test.c           |  2 +-
 tests/pxe-test.c               | 10 +++++-----
 tests/q35-test.c               |  4 ++--
 tests/qmp-test.c               |  2 +-
 tests/qom-test.c               |  2 +-
 tests/rtc-test.c               |  2 +-
 tests/rtl8139-test.c           |  2 +-
 tests/spapr-phb-test.c         |  4 ++--
 tests/tco-test.c               |  6 +++---
 tests/test-arm-mptimer.c       |  2 +-
 tests/test-filter-mirror.c     |  2 +-
 tests/test-filter-redirector.c |  4 ++--
 tests/test-hmp.c               |  2 +-
 tests/test-netfilter.c         |  4 ++--
 tests/test-x86-cpuid-compat.c  |  8 ++++----
 tests/tmp105-test.c            |  7 ++++---
 tests/tpci200-test.c           |  2 +-
 tests/usb-hcd-ehci-test.c      |  2 +-
 tests/usb-hcd-ohci-test.c      |  2 +-
 tests/usb-hcd-xhci-test.c      |  5 +++--
 tests/vhost-user-test.c        | 22 +++++++++++-----------
 tests/virtio-balloon-test.c    |  2 +-
 tests/virtio-blk-test.c        |  8 ++++----
 tests/virtio-console-test.c    |  8 ++++----
 tests/virtio-net-test.c        |  2 +-
 tests/virtio-rng-test.c        |  2 +-
 tests/virtio-serial-test.c     |  2 +-
 tests/vmgenid-test.c           |  6 +++---
 tests/vmxnet3-test.c           |  2 +-
 tests/wdt_ib700-test.c         |  8 ++++----
 68 files changed, 179 insertions(+), 177 deletions(-)
tests/libqtest.h +4 -4
index 0459526187..3f6c71f0e3 100644
@@ -24,21 +24,21 @@ typedef struct QTestState QTestState;
 extern QTestState *global_qtest;
 
 /**
- * qtest_init:
+ * qtest_start:
  * @extra_args...: other arguments to pass to QEMU, formatted as if by
  * sprintf().
  *
  * Returns: #QTestState instance.
  */
-QTestState *qtest_init(const char *extra_args, ...) GCC_FMT_ATTR(1, 2);
+QTestState *qtest_start(const char *extra_args, ...) GCC_FMT_ATTR(1, 2);
 
 /**
- * qtest_init_without_qmp_handshake:
+ * qtest_start_without_qmp_handshake:
  * @extra_args: other arguments to pass to QEMU.
  *
  * Returns: #QTestState instance.
  */
-QTestState *qtest_init_without_qmp_handshake(const char *extra_args);
+QTestState *qtest_start_without_qmp_handshake(const char *extra_args);
 
 /**
  * qtest_quit:
tests/libqtest.c +4 -4
index fa4e47c137..76c8029f7e 100644
@@ -266,7 +266,7 @@ void qtest_add_abrt_handler(GHookFunc fn, const void *data)
     g_hook_prepend(&abrt_hooks, hook);
 }
 
-QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
+QTestState *qtest_start_without_qmp_handshake(const char *extra_args)
 {
     QTestState *s;
     int sock, qmpsock, i;
@@ -347,7 +347,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     return s;
 }
 
-QTestState *qtest_init(const char *extra_args, ...)
+QTestState *qtest_start(const char *extra_args, ...)
 {
     va_list ap;
     QTestState *s;
@@ -357,7 +357,7 @@ QTestState *qtest_init(const char *extra_args, ...)
     cmd = g_strdup_vprintf(extra_args, ap);
     va_end(ap);
 
-    s = qtest_init_without_qmp_handshake(cmd);
+    s = qtest_start_without_qmp_handshake(cmd);
     g_free(cmd);
 
     /* Read the QMP greeting and then do the handshake */
@@ -970,7 +970,7 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine))
     QString *qstr;
     const char *mname;
 
-    global_qtest = qtest_init("-machine none");
+    global_qtest = qtest_start("-machine none");
     response = qmp("{ 'execute': 'query-machines' }");
     g_assert(response);
     list = qdict_get_qlist(response, "return");
tests/ac97-test.c +1 -1
index 6a1edaa85a..2f5fb10632 100644
@@ -22,7 +22,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/ac97/nop", nop);
 
-    global_qtest = qtest_init("-device AC97");
+    global_qtest = qtest_start("-device AC97");
     ret = g_test_run();
 
     qtest_quit(global_qtest);
tests/bios-tables-test.c +6 -6
index f8a107499f..9735073c22 100644
@@ -624,12 +624,12 @@ static void test_smbios_structs(test_data *data)
 static void test_acpi_one(const char *params, test_data *data)
 {
     /* Disable kernel irqchip to be able to override apic irq0. */
-    data->qts = qtest_init("-machine %s,accel=%s,kernel-irqchip=off "
-                           "-net none -display none %s "
-                           "-drive id=hd0,if=none,file=%s,format=raw "
-                           "-device ide-hd,drive=hd0 ",
-                           data->machine, "kvm:tcg",
-                           params ? params : "", disk);
+    data->qts = qtest_start("-machine %s,accel=%s,kernel-irqchip=off "
+                            "-net none -display none %s "
+                            "-drive id=hd0,if=none,file=%s,format=raw "
+                            "-device ide-hd,drive=hd0 ",
+                            data->machine, "kvm:tcg",
+                            params ? params : "", disk);
 
     boot_sector_test(data->qts);
 
tests/boot-order-test.c +4 -4
index e6efea6852..81b0d32a01 100644
@@ -30,10 +30,10 @@ static void test_a_boot_order(const char *machine,
 {
     uint64_t actual;
 
-    global_qtest = qtest_init("-nodefaults%s%s %s",
-                              machine ? " -M " : "",
-                              machine ?: "",
-                              test_args);
+    global_qtest = qtest_start("-nodefaults%s%s %s",
+                               machine ? " -M " : "",
+                               machine ?: "",
+                               test_args);
     actual = read_boot_order();
     g_assert_cmphex(actual, ==, expected_boot);
     qmp_discard_response("{ 'execute': 'system_reset' }");
tests/boot-serial-test.c +4 -4
index d7c0c320d7..d337fc9c4b 100644
@@ -81,10 +81,10 @@ static void test_machine(const void *data)
      * Make sure that this test uses tcg if available: It is used as a
      * fast-enough smoketest for that.
      */
-    global_qtest = qtest_init("-M %s,accel=tcg:kvm "
-                              "-chardev file,id=serial0,path=%s "
-                              "-no-shutdown -serial chardev:serial0 %s",
-                              test->machine, tmpname, test->extra);
+    global_qtest = qtest_start("-M %s,accel=tcg:kvm "
+                               "-chardev file,id=serial0,path=%s "
+                               "-no-shutdown -serial chardev:serial0 %s",
+                               test->machine, tmpname, test->extra);
     unlink(tmpname);
 
     check_guest_output(test, fd);
tests/device-introspect-test.c +6 -6
index 1c23b71038..f7af40acc2 100644
@@ -126,7 +126,7 @@ static void test_device_intro_list(void)
     QList *types;
     char *help;
 
-    global_qtest = qtest_init("%s", common_args);
+    global_qtest = qtest_start("%s", common_args);
 
     types = device_type_list(true);
     QDECREF(types);
@@ -167,7 +167,7 @@ static void test_qom_list_fields(void)
     QList *non_abstract;
     QListEntry *e;
 
-    global_qtest = qtest_init("%s", common_args);
+    global_qtest = qtest_start("%s", common_args);
 
     all_types = qom_list_types(NULL, true);
     non_abstract = qom_list_types(NULL, false);
@@ -194,14 +194,14 @@ static void test_qom_list_fields(void)
 
 static void test_device_intro_none(void)
 {
-    global_qtest = qtest_init("%s", common_args);
+    global_qtest = qtest_start("%s", common_args);
     test_one_device("nonexistent");
     qtest_quit(global_qtest);
 }
 
 static void test_device_intro_abstract(void)
 {
-    global_qtest = qtest_init("%s", common_args);
+    global_qtest = qtest_start("%s", common_args);
     test_one_device("device");
     qtest_quit(global_qtest);
 }
@@ -212,7 +212,7 @@ static void test_device_intro_concrete(void)
     QListEntry *entry;
     const char *type;
 
-    global_qtest = qtest_init("%s", common_args);
+    global_qtest = qtest_start("%s", common_args);
     types = device_type_list(false);
 
     QLIST_FOREACH_ENTRY(types, entry) {
@@ -232,7 +232,7 @@ static void test_abstract_interfaces(void)
     QListEntry *e;
     QDict *index;
 
-    global_qtest = qtest_init("%s", common_args);
+    global_qtest = qtest_start("%s", common_args);
 
     all_types = qom_list_types("interface", true);
     index = qom_type_index(all_types);
tests/display-vga-test.c +6 -6
index 51c6feaaf1..d638f15ec3 100644
@@ -12,33 +12,33 @@
 
 static void pci_cirrus(void)
 {
-    qtest_quit(qtest_init("-vga none -device cirrus-vga"));
+    qtest_quit(qtest_start("-vga none -device cirrus-vga"));
 }
 
 static void pci_stdvga(void)
 {
-    qtest_quit(qtest_init("-vga none -device VGA"));
+    qtest_quit(qtest_start("-vga none -device VGA"));
 }
 
 static void pci_secondary(void)
 {
-    qtest_quit(qtest_init("-vga none -device secondary-vga"));
+    qtest_quit(qtest_start("-vga none -device secondary-vga"));
 }
 
 static void pci_multihead(void)
 {
-    qtest_quit(qtest_init("-vga none -device VGA -device secondary-vga"));
+    qtest_quit(qtest_start("-vga none -device VGA -device secondary-vga"));
 }
 
 static void pci_virtio_gpu(void)
 {
-    qtest_quit(qtest_init("-vga none -device virtio-gpu-pci"));
+    qtest_quit(qtest_start("-vga none -device virtio-gpu-pci"));
 }
 
 #ifdef CONFIG_VIRTIO_VGA
 static void pci_virtio_vga(void)
 {
-    qtest_quit(qtest_init("-vga none -device virtio-vga"));
+    qtest_quit(qtest_start("-vga none -device virtio-vga"));
 }
 #endif
 
tests/drive_del-test.c +3 -3
index 602ab062b4..f68c4bc176 100644
@@ -45,7 +45,7 @@ static void device_del(void)
 static void test_drive_without_dev(void)
 {
     /* Start with an empty drive */
-    global_qtest = qtest_init("-drive if=none,id=drive0");
+    global_qtest = qtest_start("-drive if=none,id=drive0");
 
     /* Delete the drive */
     drive_del();
@@ -63,7 +63,7 @@ static void test_after_failed_device_add(void)
     QDict *response;
     QDict *error;
 
-    global_qtest = qtest_init("-drive if=none,id=drive0");
+    global_qtest = qtest_start("-drive if=none,id=drive0");
 
     /* Make device_add fail.  If this leaks the virtio-blk-pci device then a
      * reference to drive0 will also be held (via qdev properties).
@@ -92,7 +92,7 @@ static void test_after_failed_device_add(void)
 static void test_drive_del_device_del(void)
 {
     /* Start with a drive used by a device that unplugs instantaneously */
-    global_qtest = qtest_init(
+    global_qtest = qtest_start(
         "-drive if=none,id=drive0,file=null-co://,format=raw"
         " -device virtio-scsi-pci"
         " -device scsi-hd,drive=drive0,id=dev0");
tests/ds1338-test.c +1 -1
index da5b852351..ad5f5b138a 100644
@@ -60,7 +60,7 @@ int main(int argc, char **argv)
 
     g_test_init(&argc, &argv, NULL);
 
-    s = global_qtest = qtest_init("-display none -machine imx25-pdk");
+    s = global_qtest = qtest_start("-display none -machine imx25-pdk");
     i2c = imx_i2c_create(IMX25_I2C_0_BASE);
     addr = DS1338_ADDR;
 
tests/e1000-test.c +1 -1
index 59bd8b781f..1ee33fdd52 100644
@@ -16,7 +16,7 @@ static void test_device(gconstpointer data)
     const char *model = data;
     QTestState *s;
 
-    s = qtest_init("-device %s", model);
+    s = qtest_start("-device %s", model);
     qtest_quit(s);
 }
 
tests/e1000e-test.c +3 -3
index 6ef240dc8f..0f6214b70a 100644
@@ -383,8 +383,8 @@ static void data_test_init(e1000e_device *d)
     int ret = socketpair(PF_UNIX, SOCK_STREAM, 0, test_sockets);
     g_assert_cmpint(ret, != , -1);
 
-    global_qtest = qtest_init("-netdev socket,fd=%d,id=hs0 "
-                              "-device e1000e,netdev=hs0", test_sockets[1]);
+    global_qtest = qtest_start("-netdev socket,fd=%d,id=hs0 "
+                               "-device e1000e,netdev=hs0", test_sockets[1]);
 
     test_alloc = pc_alloc_init(global_qtest);
     g_assert_nonnull(test_alloc);
@@ -452,7 +452,7 @@ static void test_e1000e_hotplug(gconstpointer data)
 {
     static const uint8_t slot = 0x06;
 
-    global_qtest = qtest_init("-device e1000e");
+    global_qtest = qtest_start("-device e1000e");
 
     qpci_plug_device_test("e1000e", "e1000e_net", slot, NULL);
     qpci_unplug_acpi_device_test("e1000e_net", slot);
tests/eepro100-test.c +1 -1
index 6f49ac2656..be31f5d40d 100644
@@ -16,7 +16,7 @@ static void test_device(gconstpointer data)
     QTestState *s;
 
     /* Tests only initialization so far. TODO: Implement functional tests */
-    s = qtest_init("-device %s", model);
+    s = qtest_start("-device %s", model);
     qtest_quit(s);
 }
 
tests/endianness-test.c +12 -12
index 68d5dbcd14..2c0f2df366 100644
@@ -115,10 +115,10 @@ static void test_endianness(gconstpointer data)
 {
     const TestCase *test = data;
 
-    global_qtest = qtest_init("-M %s%s%s -device pc-testdev",
-                              test->machine,
-                              test->superio ? " -device " : "",
-                              test->superio ?: "");
+    global_qtest = qtest_start("-M %s%s%s -device pc-testdev",
+                               test->machine,
+                               test->superio ? " -device " : "",
+                               test->superio ?: "");
     isa_outl(test, 0xe0, 0x87654321);
     g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654321);
     g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765);
@@ -187,10 +187,10 @@ static void test_endianness_split(gconstpointer data)
 {
     const TestCase *test = data;
 
-    global_qtest = qtest_init("-M %s%s%s -device pc-testdev",
-                              test->machine,
-                              test->superio ? " -device " : "",
-                              test->superio ?: "");
+    global_qtest = qtest_start("-M %s%s%s -device pc-testdev",
+                               test->machine,
+                               test->superio ? " -device " : "",
+                               test->superio ?: "");
     isa_outl(test, 0xe8, 0x87654321);
     g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654321);
     g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765);
@@ -231,10 +231,10 @@ static void test_endianness_combine(gconstpointer data)
 {
     const TestCase *test = data;
 
-    global_qtest = qtest_init("-M %s%s%s -device pc-testdev",
-                              test->machine,
-                              test->superio ? " -device " : "",
-                              test->superio ?: "");
+    global_qtest = qtest_start("-M %s%s%s -device pc-testdev",
+                               test->machine,
+                               test->superio ? " -device " : "",
+                               test->superio ?: "");
     isa_outl(test, 0xe0, 0x87654321);
     g_assert_cmphex(isa_inl(test, 0xe8), ==, 0x87654321);
     g_assert_cmphex(isa_inw(test, 0xea), ==, 0x8765);
tests/es1370-test.c +1 -1
index edeea13ae7..ff6fdbfe57 100644
@@ -22,7 +22,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/es1370/nop", nop);
 
-    global_qtest = qtest_init("-device ES1370");
+    global_qtest = qtest_start("-device ES1370");
     ret = g_test_run();
 
     qtest_quit(global_qtest);
tests/fdc-test.c +1 -1
index 893097f5a3..ec83625db2 100644
@@ -564,7 +564,7 @@ int main(int argc, char **argv)
     /* Run the tests */
     g_test_init(&argc, &argv, NULL);
 
-    global_qtest = qtest_init("-device floppy,id=floppy0");
+    global_qtest = qtest_start("-device floppy,id=floppy0");
     qtest_irq_intercept_in(global_qtest, "ioapic");
     qtest_add_func("/fdc/cmos", test_cmos);
     qtest_add_func("/fdc/no_media_on_start", test_no_media_on_start);
tests/fw_cfg-test.c +1 -1
index 3a8dc7a2cd..37214fdf10 100644
@@ -106,7 +106,7 @@ int main(int argc, char **argv)
 
     g_test_init(&argc, &argv, NULL);
 
-    s = qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8");
+    s = qtest_start("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8");
 
     fw_cfg = pc_fw_cfg_init(s);
 
tests/hd-geo-test.c +4 -4
index e0b19cdf17..73d23b14b8 100644
@@ -241,7 +241,7 @@ static void test_ide_none(void)
 
     setup_common(argv, ARGV_SIZE);
     args = g_strjoinv(" ", argv);
-    global_qtest = qtest_init("%s", args);
+    global_qtest = qtest_start("%s", args);
     g_strfreev(argv);
     g_free(args);
     test_cmos();
@@ -263,7 +263,7 @@ static void test_ide_mbr(bool use_device, MBRcontents mbr)
         argc = setup_ide(argc, argv, ARGV_SIZE, i, dev, i, mbr, "");
     }
     args = g_strjoinv(" ", argv);
-    global_qtest = qtest_init("%s", args);
+    global_qtest = qtest_start("%s", args);
     g_strfreev(argv);
     g_free(args);
     test_cmos();
@@ -339,7 +339,7 @@ static void test_ide_drive_user(const char *dev, bool trans)
                      dev ? "" : opts);
     g_free(opts);
     args = g_strjoinv(" ", argv);
-    global_qtest = qtest_init("%s", args);
+    global_qtest = qtest_start("%s", args);
     g_strfreev(argv);
     g_free(args);
     test_cmos();
@@ -396,7 +396,7 @@ static void test_ide_drive_cd_0(void)
                          ide_idx, NULL, i, mbr_blank, "");
     }
     args = g_strjoinv(" ", argv);
-    global_qtest = qtest_init("%s", args);
+    global_qtest = qtest_start("%s", args);
     g_strfreev(argv);
     g_free(args);
     test_cmos();
tests/i440fx-test.c +3 -3
index bfedd5d953..ac98101e6f 100644
@@ -33,7 +33,7 @@ typedef struct FirmwareTestFixture {
 
 static QPCIBus *test_start_get_bus(const TestData *s)
 {
-    global_qtest = qtest_init("-smp %d", s->num_cpus);
+    global_qtest = qtest_start("-smp %d", s->num_cpus);
     return qpci_init_pc(global_qtest, NULL);
 }
 
@@ -340,10 +340,10 @@ static void test_i440fx_firmware(FirmwareTestFixture *fixture,
                                          : "-drive if=pflash,format=raw,file=",
                               fw_pathname);
     g_test_message("qemu cmdline: %s", cmdline);
-    global_qtest = qtest_init("%s", cmdline);
+    global_qtest = qtest_start("%s", cmdline);
     g_free(cmdline);
 
-    /* QEMU has loaded the firmware (because qtest_init() only returns after
+    /* QEMU has loaded the firmware (because qtest_start() only returns after
      * the QMP handshake completes). We must unlink the firmware blob right
      * here, because any assertion firing below would leak it in the
      * filesystem. This is also the reason why we recreate the blob every time
tests/i82801b11-test.c +2 -2
index 58436172b7..b76714ae16 100644
@@ -22,8 +22,8 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/i82801b11/nop", nop);
 
-    global_qtest = qtest_init("-machine q35 "
-                              "-device i82801b11-bridge,bus=pcie.0,addr=1e.0");
+    global_qtest = qtest_start("-machine q35 "
+                               "-device i82801b11-bridge,bus=pcie.0,addr=1e.0");
     ret = g_test_run();
 
     qtest_quit(global_qtest);
tests/ide-test.c +1 -1
index b22a4fc1c5..7b7cc10176 100644
@@ -124,7 +124,7 @@ static void ide_test_start(const char *cmdline_fmt, ...)
     cmdline = g_strdup_vprintf(cmdline_fmt, ap);
     va_end(ap);
 
-    global_qtest = qtest_init("%s", cmdline);
+    global_qtest = qtest_start("%s", cmdline);
     guest_malloc = pc_alloc_init(global_qtest);
 
     g_free(cmdline);
tests/intel-hda-test.c +2 -2
index c10a59d932..86f7719d39 100644
@@ -18,13 +18,13 @@
 /* Tests only initialization so far. TODO: Replace with functional tests */
 static void ich6_test(void)
 {
-    global_qtest = qtest_init("-device intel-hda,id=" HDA_ID CODEC_DEVICES);
+    global_qtest = qtest_start("-device intel-hda,id=" HDA_ID CODEC_DEVICES);
     qtest_quit(global_qtest);
 }
 
 static void ich9_test(void)
 {
-    global_qtest = qtest_init(
+    global_qtest = qtest_start(
         "-machine q35 -device ich9-intel-hda,bus=pcie.0,addr=1b.0,id="
         HDA_ID CODEC_DEVICES);
     qtest_quit(global_qtest);
tests/ioh3420-test.c +1 -1
index cd5d062370..aff569b99e 100644
@@ -22,7 +22,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/ioh3420/nop", nop);
 
-    global_qtest = qtest_init(
+    global_qtest = qtest_start(
         "-machine q35 -device ioh3420,bus=pcie.0,addr=1c.0,port=1,"
         "chassis=1,multifunction=on");
     ret = g_test_run();
tests/ipmi-bt-test.c +1 -1
index 476d527cfd..fdcbadb755 100644
@@ -414,7 +414,7 @@ int main(int argc, char **argv)
     /* Run the tests */
     g_test_init(&argc, &argv, NULL);
 
-    global_qtest = qtest_init(
+    global_qtest = qtest_start(
         " -chardev socket,id=ipmi0,host=localhost,port=%d,reconnect=10"
         " -device ipmi-bmc-extern,chardev=ipmi0,id=bmc0"
         " -device isa-ipmi-bt,bmc=bmc0", emu_port);
tests/ipmi-kcs-test.c +2 -2
index 2bd3771e9f..5acc0d9e35 100644
@@ -275,8 +275,8 @@ int main(int argc, char **argv)
     /* Run the tests */
     g_test_init(&argc, &argv, NULL);
 
-    global_qtest = qtest_init("-device ipmi-bmc-sim,id=bmc0"
-                              " -device isa-ipmi-kcs,bmc=bmc0");
+    global_qtest = qtest_start("-device ipmi-bmc-sim,id=bmc0"
+                               " -device isa-ipmi-kcs,bmc=bmc0");
     qtest_irq_intercept_in(global_qtest, "ioapic");
     qtest_add_func("/ipmi/local/kcs_base", test_kcs_base);
     qtest_add_func("/ipmi/local/kcs_abort", test_kcs_abort);
tests/ipoctal232-test.c +2 -2
index 5e1cae3917..90b683284a 100644
@@ -22,8 +22,8 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/ipoctal232/tpci200/nop", nop);
 
-    global_qtest = qtest_init("-device tpci200,id=ipack0 "
-                              "-device ipoctal232,bus=ipack0.0");
+    global_qtest = qtest_start("-device tpci200,id=ipack0 "
+                               "-device ipoctal232,bus=ipack0.0");
     ret = g_test_run();
 
     qtest_quit(global_qtest);
tests/ivshmem-test.c +1 -1
index f254f09487..6ad3e5f834 100644
@@ -407,7 +407,7 @@ static void test_ivshmem_hotplug(void)
     const char *arch = qtest_get_arch();
     gchar *opts;
 
-    global_qtest = qtest_init(" ");
+    global_qtest = qtest_start(" ");
 
     opts = g_strdup_printf("'shm': '%s', 'size': '1M'", tmpshm);
 
tests/libqos/libqos.c +1 -1
index bd9106a132..1dea434e37 100644
@@ -20,7 +20,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
     struct QOSState *qs = g_malloc(sizeof(QOSState));
 
     cmdline = g_strdup_vprintf(cmdline_fmt, ap);
-    qs->qts = global_qtest = qtest_init("%s", cmdline);
+    qs->qts = global_qtest = qtest_start("%s", cmdline);
     qs->ops = ops;
     if (ops) {
         if (ops->init_allocator) {
tests/m25p80-test.c +3 -3
index 18135cfb86..82d9bb9ff0 100644
@@ -363,9 +363,9 @@ int main(int argc, char **argv)
     g_assert(ret == 0);
     close(fd);
 
-    global_qtest = qtest_init("-m 256 -machine palmetto-bmc "
-                              "-drive file=%s,format=raw,if=mtd",
-                              tmp_path);
+    global_qtest = qtest_start("-m 256 -machine palmetto-bmc "
+                               "-drive file=%s,format=raw,if=mtd",
+                               tmp_path);
 
     qtest_add_func("/m25p80/read_jedec", test_read_jedec);
     qtest_add_func("/m25p80/erase_sector", test_erase_sector);
tests/m48t59-test.c +1 -1
index 52c61fe33e..aadd770f4f 100644
@@ -246,7 +246,7 @@ int main(int argc, char **argv)
 
     g_test_init(&argc, &argv, NULL);
 
-    s = global_qtest = qtest_init("-rtc clock=vm");
+    s = global_qtest = qtest_start("-rtc clock=vm");
 
     qtest_add_func("/rtc/bcd/check-time", bcd_check_time);
     qtest_add_func("/rtc/fuzz-registers", fuzz_registers);
tests/ne2000-test.c +1 -1
index d205bc91a6..8e6f7b07c6 100644
@@ -22,7 +22,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/ne2000/pci/nop", pci_nop);
 
-    global_qtest = qtest_init("-device ne2k_pci");
+    global_qtest = qtest_start("-device ne2k_pci");
     ret = g_test_run();
 
     qtest_quit(global_qtest);
tests/numa-test.c +7 -7
index 17bbc0f5f8..5653eaac47 100644
@@ -25,7 +25,7 @@ static void test_mon_explicit(const void *data)
     cli = make_cli(data, "-smp 8 "
                    "-numa node,nodeid=0,cpus=0-3 "
                    "-numa node,nodeid=1,cpus=4-7 ");
-    global_qtest = qtest_init("%s", cli);
+    global_qtest = qtest_start("%s", cli);
 
     s = hmp("info numa");
     g_assert(strstr(s, "node 0 cpus: 0 1 2 3"));
@@ -42,7 +42,7 @@ static void test_mon_default(const void *data)
     char *cli;
 
     cli = make_cli(data, "-smp 8 -numa node -numa node");
-    global_qtest = qtest_init("%s", cli);
+    global_qtest = qtest_start("%s", cli);
 
     s = hmp("info numa");
     g_assert(strstr(s, "node 0 cpus: 0 2 4 6"));
@@ -61,7 +61,7 @@ static void test_mon_partial(const void *data)
     cli = make_cli(data, "-smp 8 "
                    "-numa node,nodeid=0,cpus=0-1 "
                    "-numa node,nodeid=1,cpus=4-5 ");
-    global_qtest = qtest_init("%s", cli);
+    global_qtest = qtest_start("%s", cli);
 
     s = hmp("info numa");
     g_assert(strstr(s, "node 0 cpus: 0 1 2 3 6 7"));
@@ -88,7 +88,7 @@ static void test_query_cpus(const void *data)
     QObject *e;
 
     cli = make_cli(data, "-smp 8 -numa node,cpus=0-3 -numa node,cpus=4-7");
-    global_qtest = qtest_init("%s", cli);
+    global_qtest = qtest_start("%s", cli);
     cpus = get_cpus(&resp);
     g_assert(cpus);
 
@@ -130,7 +130,7 @@ static void pc_numa_cpu(const void *data)
         "-numa cpu,node-id=0,socket-id=1,core-id=0 "
         "-numa cpu,node-id=0,socket-id=1,core-id=1,thread-id=0 "
         "-numa cpu,node-id=1,socket-id=1,core-id=1,thread-id=1");
-    global_qtest = qtest_init("%s", cli);
+    global_qtest = qtest_start("%s", cli);
     cpus = get_cpus(&resp);
     g_assert(cpus);
 
@@ -183,7 +183,7 @@ static void spapr_numa_cpu(const void *data)
         "-numa cpu,node-id=0,core-id=1 "
         "-numa cpu,node-id=0,core-id=2 "
         "-numa cpu,node-id=1,core-id=3");
-    global_qtest = qtest_init("%s", cli);
+    global_qtest = qtest_start("%s", cli);
     cpus = get_cpus(&resp);
     g_assert(cpus);
 
@@ -226,7 +226,7 @@ static void aarch64_numa_cpu(const void *data)
         "-numa node,nodeid=0 -numa node,nodeid=1 "
         "-numa cpu,node-id=1,thread-id=0 "
         "-numa cpu,node-id=0,thread-id=1");
-    global_qtest = qtest_init("%s", cli);
+    global_qtest = qtest_start("%s", cli);
     cpus = get_cpus(&resp);
     g_assert(cpus);
 
tests/nvme-test.c +1 -1
index 382d26671f..b054ad6fcd 100644
@@ -22,7 +22,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/nvme/nop", nop);
 
-    global_qtest = qtest_init(
+    global_qtest = qtest_start(
         "-drive id=drv0,if=none,file=null-co://,format=raw "
         "-device nvme,drive=drv0,serial=foo");
     ret = g_test_run();
tests/pc-cpu-test.c +8 -8
index 9c36051c07..1243bc64b8 100644
@@ -29,10 +29,10 @@ static void test_pc_with_cpu_add(gconstpointer data)
     QDict *response;
     unsigned int i;
 
-    global_qtest = qtest_init("-machine %s -cpu %s "
-                              "-smp sockets=%u,cores=%u,threads=%u,maxcpus=%u",
-                              s->machine, s->cpu_model,
-                              s->sockets, s->cores, s->threads, s->maxcpus);
+    global_qtest = qtest_start("-machine %s -cpu %s "
+                               "-smp sockets=%u,cores=%u,threads=%u,maxcpus=%u",
+                               s->machine, s->cpu_model,
+                               s->sockets, s->cores, s->threads, s->maxcpus);
 
     for (i = s->sockets * s->cores * s->threads; i < s->maxcpus; i++) {
         response = qmp("{ 'execute': 'cpu-add',"
@@ -50,10 +50,10 @@ static void test_pc_without_cpu_add(gconstpointer data)
     const PCTestData *s = data;
     QDict *response;
 
-    global_qtest = qtest_init("-machine %s -cpu %s "
-                              "-smp sockets=%u,cores=%u,threads=%u,maxcpus=%u",
-                              s->machine, s->cpu_model,
-                              s->sockets, s->cores, s->threads, s->maxcpus);
+    global_qtest = qtest_start("-machine %s -cpu %s "
+                               "-smp sockets=%u,cores=%u,threads=%u,maxcpus=%u",
+                               s->machine, s->cpu_model,
+                               s->sockets, s->cores, s->threads, s->maxcpus);
 
     response = qmp("{ 'execute': 'cpu-add',"
                    "  'arguments': { 'id': %d } }",
tests/pcnet-test.c +1 -1
index 23e36da805..a58a5fd7bf 100644
@@ -22,7 +22,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/pcnet/pci/nop", pci_nop);
 
-    global_qtest = qtest_init("-device pcnet");
+    global_qtest = qtest_start("-device pcnet");
     ret = g_test_run();
 
     qtest_quit(global_qtest);
tests/pnv-xscom-test.c +2 -2
index 852322b3f2..ee25bf7dae 100644
@@ -83,7 +83,7 @@ static void test_cfam_id(const void *data)
 {
     const PnvChip *chip = data;
 
-    global_qtest = qtest_init("-M powernv,accel=tcg -cpu %s", chip->cpu_model);
+    global_qtest = qtest_start("-M powernv,accel=tcg -cpu %s", chip->cpu_model);
     test_xscom_cfam_id(chip);
     qtest_quit(global_qtest);
 }
@@ -106,7 +106,7 @@ static void test_core(const void *data)
 {
     const PnvChip *chip = data;
 
-    global_qtest = qtest_init("-M powernv,accel=tcg -cpu %s", chip->cpu_model);
+    global_qtest = qtest_start("-M powernv,accel=tcg -cpu %s", chip->cpu_model);
     test_xscom_core(chip);
     qtest_quit(global_qtest);
 }
tests/postcopy-test.c +2 -2
index 20cfb280f6..4cd75400af 100644
@@ -403,10 +403,10 @@ static void test_migrate(void)
 
     g_free(bootpath);
 
-    from = qtest_init("%s", cmd_src);
+    from = qtest_start("%s", cmd_src);
     g_free(cmd_src);
 
-    to = qtest_init("%s", cmd_dst);
+    to = qtest_start("%s", cmd_dst);
     g_free(cmd_dst);
 
     assert(!global_qtest);
tests/prom-env-test.c +5 -5
index fffef0b252..501075724a 100644
@@ -49,11 +49,11 @@ static void test_machine(const void *machine)
     /* The pseries firmware boots much faster without the default devices */
     extra_args = strcmp(machine, "pseries") == 0 ? "-nodefaults" : "";
 
-    global_qtest = qtest_init("-M %s,accel=tcg %s "
-                              "-prom-env 'use-nvramrc?=true' "
-                              "-prom-env 'nvramrc=%x %x l!' ",
-                              (const char *)machine, extra_args,
-                              MAGIC, ADDRESS);
+    global_qtest = qtest_start("-M %s,accel=tcg %s "
+                               "-prom-env 'use-nvramrc?=true' "
+                               "-prom-env 'nvramrc=%x %x l!' ",
+                               (const char *)machine, extra_args,
+                               MAGIC, ADDRESS);
     check_guest_memory();
     qtest_quit(global_qtest);
 }
tests/pvpanic-test.c +1 -1
index 48b71be26f..c09b3ddac6 100644
@@ -37,7 +37,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/pvpanic/panic", test_panic);
 
-    global_qtest = qtest_init("-device pvpanic");
+    global_qtest = qtest_start("-device pvpanic");
     ret = g_test_run();
 
     qtest_quit(global_qtest);
tests/pxe-test.c +5 -5
index eaad88601a..4bcf8ce124 100644
@@ -23,11 +23,11 @@ static char disk[] = "tests/pxe-test-disk-XXXXXX";
 
 static void test_pxe_one(const char *params, bool ipv6)
 {
-    global_qtest = qtest_init("-machine accel=kvm:tcg -nodefaults "
-                              "-boot order=n "
-                              "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,"
-                              "ipv4=%s,ipv6=%s %s", disk, ipv6 ? "off" : "on",
-                              ipv6 ? "on" : "off", params);
+    global_qtest = qtest_start(
+        "-machine accel=kvm:tcg -nodefaults -boot order=n "
+        "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,"
+        "ipv4=%s,ipv6=%s %s", disk, ipv6 ? "off" : "on",
+        ipv6 ? "on" : "off", params);
     boot_sector_test(global_qtest);
     qtest_quit(global_qtest);
 }
tests/q35-test.c +2 -2
index 91a189ce62..21c0fd9bab 100644
@@ -84,7 +84,7 @@ static void test_smram_lock(void)
     QPCIDevice *pcidev;
     QDict *response;
 
-    global_qtest = qtest_init("-M q35");
+    global_qtest = qtest_start("-M q35");
 
     pcibus = qpci_init_pc(global_qtest, NULL);
     g_assert(pcibus != NULL);
@@ -141,7 +141,7 @@ static void test_tseg_size(const void *data)
         cmdline = g_strdup_printf("-M q35 -m %uM",
                                   TSEG_SIZE_TEST_GUEST_RAM_MBYTES);
     }
-    global_qtest = qtest_init("%s", cmdline);
+    global_qtest = qtest_start("%s", cmdline);
     g_free(cmdline);
 
     /* locate the DRAM controller */
tests/qmp-test.c +1 -1
index cf523b325e..14f4f57600 100644
@@ -76,7 +76,7 @@ static void test_qmp_protocol(void)
     QList *capabilities;
     QTestState *qts;
 
-    qts = qtest_init_without_qmp_handshake(common_args);
+    qts = qtest_start_without_qmp_handshake(common_args);
 
     /* Test greeting */
     resp = qtest_qmp_receive(qts);
tests/qom-test.c +1 -1
index 5edd735387..9aecf40f96 100644
@@ -92,7 +92,7 @@ static void test_machine(gconstpointer data)
     const char *machine = data;
     QDict *response;
 
-    global_qtest = qtest_init("-machine %s", machine);
+    global_qtest = qtest_start("-machine %s", machine);
 
     test_properties("/machine", true);
 
tests/rtc-test.c +1 -1
index b6058d28f5..dd5430dd2d 100644
@@ -690,7 +690,7 @@ int main(int argc, char **argv)
 
     g_test_init(&argc, &argv, NULL);
 
-    s = global_qtest = qtest_init("-rtc clock=vm");
+    s = global_qtest = qtest_start("-rtc clock=vm");
     qtest_irq_intercept_in(s, "ioapic");
 
     qtest_add_func("/rtc/check-time/bcd", bcd_check_time);
tests/rtl8139-test.c +1 -1
index dc9935439f..1741f0ec47 100644
@@ -197,7 +197,7 @@ int main(int argc, char **argv)
 {
     int ret;
 
-    global_qtest = qtest_init("-device rtl8139");
+    global_qtest = qtest_start("-device rtl8139");
 
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/rtl8139/nop", nop);
tests/spapr-phb-test.c +2 -2
index 0d26cbda6c..058ab447d7 100644
@@ -25,8 +25,8 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/spapr-phb/device", test_phb_device);
 
-    global_qtest = qtest_init("-device " TYPE_SPAPR_PCI_HOST_BRIDGE
-                              ",index=30");
+    global_qtest = qtest_start("-device " TYPE_SPAPR_PCI_HOST_BRIDGE
+                               ",index=30");
 
     ret = g_test_run();
 
tests/tco-test.c +3 -3
index b2a4baeeef..9d406dcdc7 100644
@@ -56,9 +56,9 @@ static void test_init(TestData *d)
 {
     QTestState *qs;
 
-    qs = qtest_init("-machine q35 %s %s",
-                    d->noreboot ? "" : "-global ICH9-LPC.noreboot=false",
-                    !d->args ? "" : d->args);
+    qs = qtest_start("-machine q35 %s %s",
+                     d->noreboot ? "" : "-global ICH9-LPC.noreboot=false",
+                     !d->args ? "" : d->args);
     global_qtest = qs;
     qtest_irq_intercept_in(qs, "ioapic");
 
tests/test-arm-mptimer.c +1 -1
index a4bef2322a..9631c55fe3 100644
@@ -1097,7 +1097,7 @@ tests_with_prescaler_arg:
         goto tests_with_prescaler_arg;
     }
 
-    global_qtest = qtest_init("-machine vexpress-a9");
+    global_qtest = qtest_start("-machine vexpress-a9");
     ret = g_test_run();
     qtest_quit(global_qtest);
 
tests/test-filter-mirror.c +1 -1
index 9d8608a609..18f7af5f25 100644
@@ -36,7 +36,7 @@ static void test_mirror(void)
     ret = mkstemp(sock_path);
     g_assert_cmpint(ret, !=, -1);
 
-    global_qtest = qtest_init(
+    global_qtest = qtest_start(
         "-netdev socket,id=qtest-bn0,fd=%d "
         "-device %s,netdev=qtest-bn0,id=qtest-e0 "
         "-chardev socket,id=mirror0,path=%s,server,nowait "
tests/test-filter-redirector.c +2 -2
index b34f8ec2ad..becf74ef14 100644
@@ -86,7 +86,7 @@ static void test_redirector_tx(void)
     ret = mkstemp(sock_path1);
     g_assert_cmpint(ret, !=, -1);
 
-    global_qtest = qtest_init(
+    global_qtest = qtest_start(
         "-netdev socket,id=qtest-bn0,fd=%d "
         "-device %s,netdev=qtest-bn0,id=qtest-e0 "
         "-chardev socket,id=redirector0,path=%s,server,nowait "
@@ -155,7 +155,7 @@ static void test_redirector_rx(void)
     ret = mkstemp(sock_path1);
     g_assert_cmpint(ret, !=, -1);
 
-    global_qtest = qtest_init(
+    global_qtest = qtest_start(
         "-netdev socket,id=qtest-bn0,fd=%d "
         "-device %s,netdev=qtest-bn0,id=qtest-e0 "
         "-chardev socket,id=redirector0,path=%s,server,nowait "
tests/test-hmp.c +1 -1
index dd03693707..d7d5f13a14 100644
@@ -120,7 +120,7 @@ static void test_machine(gconstpointer data)
 {
     const char *machine = data;
 
-    global_qtest = qtest_init("-S -M %s", machine);
+    global_qtest = qtest_start("-S -M %s", machine);
 
     test_info_commands();
     test_commands();
tests/test-netfilter.c +2 -2
index 76caaedfc1..1215d13a62 100644
@@ -196,8 +196,8 @@ int main(int argc, char **argv)
     qtest_add_func("/netfilter/remove_netdev_multi",
                    remove_netdev_with_multi_netfilter);
 
-    global_qtest = qtest_init("-netdev user,id=qtest-bn0 "
-                              "-device %s,netdev=qtest-bn0", devstr);
+    global_qtest = qtest_start("-netdev user,id=qtest-bn0 "
+                               "-device %s,netdev=qtest-bn0", devstr);
     ret = g_test_run();
 
     qtest_quit(global_qtest);
tests/test-x86-cpuid-compat.c +4 -4
index 5b026ac38a..a5c2f10ebb 100644
@@ -59,7 +59,7 @@ static void test_cpuid_prop(const void *data)
     QNum *value;
     int64_t val;
 
-    global_qtest = qtest_init("%s", args->cmdline);
+    global_qtest = qtest_start("%s", args->cmdline);
     path = get_cpu0_qom_path();
     value = qobject_to_qnum(qom_get(path, args->property));
     g_assert(qnum_get_try_int(value, &val));
@@ -131,7 +131,7 @@ static void test_feature_flag(const void *data)
     QList *present, *filtered;
     uint32_t value;
 
-    global_qtest = qtest_init("%s", args->cmdline);
+    global_qtest = qtest_start("%s", args->cmdline);
     path = get_cpu0_qom_path();
     present = qobject_to_qlist(qom_get(path, "feature-words"));
     filtered = qobject_to_qlist(qom_get(path, "filtered-features"));
@@ -181,8 +181,8 @@ static void test_plus_minus_subprocess(void)
      * Note: rules 1 and 2 are planned to be removed soon, and
      * should generate a warning.
      */
-    global_qtest = qtest_init("-cpu pentium,-fpu,+fpu,-mce,mce=on,+cx8,"
-                              "cx8=off,+sse4_1,sse4_2=on");
+    global_qtest = qtest_start("-cpu pentium,-fpu,+fpu,-mce,mce=on,+cx8,"
+                               "cx8=off,+sse4_1,sse4_2=on");
     path = get_cpu0_qom_path();
 
     g_assert_false(qom_get_bool(path, "fpu"));
tests/tmp105-test.c +4 -3
index 3ef2efff6e..9233585e4b 100644
@@ -151,9 +151,10 @@ int main(int argc, char **argv)
 
     g_test_init(&argc, &argv, NULL);
 
-    s = global_qtest = qtest_init("-machine n800 "
-                    "-device tmp105,bus=i2c-bus.0,id=" TMP105_TEST_ID
-                    ",address=0x49");
+    s = global_qtest = qtest_start(
+        "-machine n800 "
+        "-device tmp105,bus=i2c-bus.0,id=" TMP105_TEST_ID
+        ",address=0x49");
     i2c = omap_i2c_create(OMAP2_I2C_1_BASE);
 
     qtest_add_func("/tmp105/tx-rx", send_and_receive);
tests/tpci200-test.c +1 -1
index 2ed378196d..223d44da35 100644
@@ -22,7 +22,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/tpci200/nop", nop);
 
-    global_qtest = qtest_init("-device tpci200");
+    global_qtest = qtest_start("-device tpci200");
     ret = g_test_run();
 
     qtest_quit(global_qtest);
tests/usb-hcd-ehci-test.c +1 -1
index 55349a39a2..c3568a1782 100644
@@ -156,7 +156,7 @@ int main(int argc, char **argv)
     qtest_add_func("/ehci/pci/ehci-port-2", pci_ehci_port_2);
     qtest_add_func("/ehci/pci/ehci-port-3-hotplug", pci_ehci_port_hotplug);
 
-    global_qtest = qtest_init(
+    global_qtest = qtest_start(
         "-machine q35 -device ich9-usb-ehci1,bus=pcie.0,addr=1d.7,"
         "multifunction=on,id=ich9-ehci-1 "
         "-device ich9-usb-uhci1,bus=pcie.0,addr=1d.0,"
tests/usb-hcd-ohci-test.c +1 -1
index 2763c9ec24..62fd35f69a 100644
@@ -31,7 +31,7 @@ int main(int argc, char **argv)
     qtest_add_func("/ohci/pci/init", test_ohci_init);
     qtest_add_func("/ohci/pci/hotplug", test_ohci_hotplug);
 
-    global_qtest = qtest_init("-device pci-ohci,id=ohci");
+    global_qtest = qtest_start("-device pci-ohci,id=ohci");
     ret = g_test_run();
     qtest_quit(global_qtest);
 
tests/usb-hcd-xhci-test.c +3 -2
index cc3fcd82fa..bd3c65ae85 100644
@@ -80,8 +80,9 @@ int main(int argc, char **argv)
     qtest_add_func("/xhci/pci/hotplug", test_xhci_hotplug);
     qtest_add_func("/xhci/pci/hotplug/usb-uas", test_usb_uas_hotplug);
 
-    global_qtest = qtest_init("-device nec-usb-xhci,id=xhci"
-                " -drive id=drive0,if=none,file=null-co://,format=raw");
+    global_qtest = qtest_start(
+        "-device nec-usb-xhci,id=xhci"
+        " -drive id=drive0,if=none,file=null-co://,format=raw");
     ret = g_test_run();
     qtest_quit(global_qtest);
 
tests/vhost-user-test.c +11 -11
index 0dbed5a36a..0fe52428e6 100644
@@ -644,14 +644,14 @@ static void test_migrate(void)
     test_server_listen(s);
     test_server_listen(dest);
 
-    s->qts = qtest_init(GET_QEMU_CMDE(s, 2, "", ""));
+    s->qts = qtest_start(GET_QEMU_CMDE(s, 2, "", ""));
 
     init_virtio_dev(s);
     wait_for_fds(s);
     size = get_log_size(s);
     g_assert_cmpint(size, ==, (2 * 1024 * 1024) / (VHOST_LOG_PAGE * 8));
 
-    dest->qts = qtest_init(GET_QEMU_CMDE(dest, 2, "", " -incoming %s", uri));
+    dest->qts = qtest_start(GET_QEMU_CMDE(dest, 2, "", " -incoming %s", uri));
 
     source = g_source_new(&test_migrate_source_funcs,
                           sizeof(TestMigrateSource));
@@ -746,7 +746,7 @@ static void test_reconnect_subprocess(void)
     TestServer *s = test_server_new("reconnect");
 
     g_thread_new("connect", connect_thread, s);
-    s->qts = qtest_init(GET_QEMU_CMDE(s, 2, ",server", ""));
+    s->qts = qtest_start(GET_QEMU_CMDE(s, 2, ",server", ""));
 
     init_virtio_dev(s);
     wait_for_fds(s);
@@ -778,7 +778,7 @@ static void test_connect_fail_subprocess(void)
 
     s->test_fail = true;
     g_thread_new("connect", connect_thread, s);
-    s->qts = qtest_init(GET_QEMU_CMDE(s, 2, ",server", ""));
+    s->qts = qtest_start(GET_QEMU_CMDE(s, 2, ",server", ""));
 
     init_virtio_dev(s);
     wait_for_fds(s);
@@ -802,7 +802,7 @@ static void test_flags_mismatch_subprocess(void)
 
     s->test_flags = TEST_FLAGS_DISCONNECT;
     g_thread_new("connect", connect_thread, s);
-    s->qts = qtest_init(GET_QEMU_CMDE(s, 2, ",server", ""));
+    s->qts = qtest_start(GET_QEMU_CMDE(s, 2, ",server", ""));
 
     init_virtio_dev(s);
     wait_for_fds(s);
@@ -866,11 +866,11 @@ static void test_multiqueue(void)
     s->queues = queues;
     test_server_listen(s);
 
-    s->qts = qtest_init(QEMU_CMD_MEM QEMU_CMD_CHR QEMU_CMD_NETDEV ",queues=%d "
-                        "-device virtio-net-pci,netdev=net0,mq=on,vectors=%d",
-                        512, 512, root, s->chr_name,
-                        s->socket_path, "", s->chr_name,
-                        queues, queues * 2 + 2);
+    s->qts = qtest_start(QEMU_CMD_MEM QEMU_CMD_CHR QEMU_CMD_NETDEV ",queues=%d "
+                         "-device virtio-net-pci,netdev=net0,mq=on,vectors=%d",
+                         512, 512, root, s->chr_name,
+                         s->socket_path, "", s->chr_name,
+                         queues, queues * 2 + 2);
 
     bus = qpci_init_pc(s->qts, NULL);
     dev = virtio_net_pci_init(bus, PCI_SLOT);
@@ -931,7 +931,7 @@ int main(int argc, char **argv)
     /* run the main loop thread so the chardev may operate */
     thread = g_thread_new(NULL, thread_function, loop);
 
-    server->qts = qtest_init(GET_QEMU_CMD(server));
+    server->qts = qtest_start(GET_QEMU_CMD(server));
     init_virtio_dev(server);
 
     qtest_add_data_func("/vhost-user/read-guest-mem", server, read_guest_mem);
tests/virtio-balloon-test.c +1 -1
index 7304392c17..cca7b0e8fb 100644
@@ -22,7 +22,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/virtio/balloon/pci/nop", pci_nop);
 
-    global_qtest = qtest_init("-device virtio-balloon-pci");
+    global_qtest = qtest_start("-device virtio-balloon-pci");
     ret = g_test_run();
 
     qtest_quit(global_qtest);
tests/virtio-blk-test.c +4 -4
index 063b0f4013..146e182ae9 100644
@@ -88,10 +88,10 @@ static void arm_test_start(void)
 
     tmp_path = drive_create();
 
-    global_qtest = qtest_init("-machine virt "
-                              "-drive if=none,id=drive0,file=%s,format=raw "
-                              "-device virtio-blk-device,drive=drive0",
-                              tmp_path);
+    global_qtest = qtest_start("-machine virt "
+                               "-drive if=none,id=drive0,file=%s,format=raw "
+                               "-device virtio-blk-device,drive=drive0",
+                               tmp_path);
     unlink(tmp_path);
     g_free(tmp_path);
 }
tests/virtio-console-test.c +4 -4
index 73fb30b051..ce0da47b2d 100644
@@ -13,15 +13,15 @@
 /* Tests only initialization so far. TODO: Replace with functional tests */
 static void console_pci_nop(void)
 {
-    global_qtest = qtest_init("-device virtio-serial-pci,id=vser0 "
-                "-device virtconsole,bus=vser0.0");
+    global_qtest = qtest_start("-device virtio-serial-pci,id=vser0 "
+                               "-device virtconsole,bus=vser0.0");
     qtest_quit(global_qtest);
 }
 
 static void serialport_pci_nop(void)
 {
-    global_qtest = qtest_init("-device virtio-serial-pci,id=vser0 "
-                "-device virtserialport,bus=vser0.0");
+    global_qtest = qtest_start("-device virtio-serial-pci,id=vser0 "
+                               "-device virtserialport,bus=vser0.0");
     qtest_quit(global_qtest);
 }
 
tests/virtio-net-test.c +1 -1
index 9b32866fb1..13a4116d26 100644
@@ -243,7 +243,7 @@ static void hotplug(void)
 {
     const char *arch = qtest_get_arch();
 
-    global_qtest = qtest_init("-device virtio-net-pci");
+    global_qtest = qtest_start("-device virtio-net-pci");
 
     qpci_plug_device_test("virtio-net-pci", "net1", PCI_SLOT_HP, NULL);
 
tests/virtio-rng-test.c +1 -1
index e1b1e89b59..64b2bd4b19 100644
@@ -37,7 +37,7 @@ int main(int argc, char **argv)
     qtest_add_func("/virtio/rng/pci/nop", pci_nop);
     qtest_add_func("/virtio/rng/pci/hotplug", hotplug);
 
-    global_qtest = qtest_init("-device virtio-rng-pci");
+    global_qtest = qtest_start("-device virtio-rng-pci");
     ret = g_test_run();
 
     qtest_quit(global_qtest);
tests/virtio-serial-test.c +1 -1
index ce708cc11e..1cc43465e6 100644
@@ -49,7 +49,7 @@ int main(int argc, char **argv)
     qtest_add_func("/virtio/serial/pci/nop", pci_nop);
     qtest_add_func("/virtio/serial/pci/hotplug", hotplug);
 
-    global_qtest = qtest_init("-device virtio-serial-pci");
+    global_qtest = qtest_start("-device virtio-serial-pci");
     ret = g_test_run();
 
     qtest_quit(global_qtest);
tests/vmgenid-test.c +3 -3
index b149690a1a..832c82c32f 100644
@@ -142,7 +142,7 @@ static void vmgenid_set_guid_test(void)
 
     g_assert(qemu_uuid_parse(VGID_GUID, &expected) == 0);
 
-    global_qtest = qtest_init(GUID_CMD(VGID_GUID));
+    global_qtest = qtest_start(GUID_CMD(VGID_GUID));
 
     /* Read the GUID from accessing guest memory */
     read_guid_from_memory(&measured);
@@ -155,7 +155,7 @@ static void vmgenid_set_guid_auto_test(void)
 {
     QemuUUID measured;
 
-    global_qtest = qtest_init(GUID_CMD("auto"));
+    global_qtest = qtest_start(GUID_CMD("auto"));
 
     read_guid_from_memory(&measured);
 
@@ -171,7 +171,7 @@ static void vmgenid_query_monitor_test(void)
 
     g_assert(qemu_uuid_parse(VGID_GUID, &expected) == 0);
 
-    global_qtest = qtest_init(GUID_CMD(VGID_GUID));
+    global_qtest = qtest_start(GUID_CMD(VGID_GUID));
 
     /* Read the GUID via the monitor */
     read_guid_from_monitor(&measured);
tests/vmxnet3-test.c +1 -1
index c9a876bcd9..0b4b807616 100644
@@ -22,7 +22,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/vmxnet3/nop", nop);
 
-    global_qtest = qtest_init("-device vmxnet3");
+    global_qtest = qtest_start("-device vmxnet3");
     ret = g_test_run();
 
     qtest_quit(global_qtest);
tests/wdt_ib700-test.c +4 -4
index 4bb8374011..a169265e16 100644
@@ -56,7 +56,7 @@ static QDict *ib700_program_and_wait(QTestState *s)
 static void ib700_pause(void)
 {
     QDict *d;
-    QTestState *s = qtest_init("-watchdog-action pause -device ib700");
+    QTestState *s = qtest_start("-watchdog-action pause -device ib700");
 
     qtest_irq_intercept_in(s, "ioapic");
     d = ib700_program_and_wait(s);
@@ -69,7 +69,7 @@ static void ib700_pause(void)
 static void ib700_reset(void)
 {
     QDict *d;
-    QTestState *s = qtest_init("-watchdog-action reset -device ib700");
+    QTestState *s = qtest_start("-watchdog-action reset -device ib700");
 
     qtest_irq_intercept_in(s, "ioapic");
     d = ib700_program_and_wait(s);
@@ -84,7 +84,7 @@ static void ib700_shutdown(void)
     QDict *d;
     QTestState *s;
 
-    s = qtest_init("-watchdog-action reset -no-reboot -device ib700");
+    s = qtest_start("-watchdog-action reset -no-reboot -device ib700");
     qtest_irq_intercept_in(s, "ioapic");
     d = ib700_program_and_wait(s);
     g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
@@ -96,7 +96,7 @@ static void ib700_shutdown(void)
 static void ib700_none(void)
 {
     QDict *d;
-    QTestState *s = qtest_init("-watchdog-action none -device ib700");
+    QTestState *s = qtest_start("-watchdog-action none -device ib700");
 
     qtest_irq_intercept_in(s, "ioapic");
     d = ib700_program_and_wait(s);
Signature · 1 line
2.13.5
Reviewed-by on v6 29/29
#94 lore raw

Re: [Qemu-devel] [PATCH v6 29/29] libqtest: Rename qtest_init() to qtest_start()

Quoted 6 lines · Eric Blake

We already have another qtest_init() in the tree, for the top-level qtest.c device; having two functions with different signatures is confusing. Rename the libqtest version to qtest_start() to eliminate the duplication.

Why not.

#95 lore raw

Re: [Qemu-devel] [PATCH v6 29/29] libqtest: Rename qtest_init() to qtest_start()

In reply to Eric Blake
Quoted 4 lines · Eric Blake

We already have another qtest_init() in the tree, for the top-level qtest.c device; having two functions with different signatures is confusing. Rename the libqtest version to qtest_start() to eliminate the duplication.

This is too much code churn for my taste, and I also do not like the idea of naming the function qtest_start() - since this was a function with different semantics before your patch 28/29, so this will cause confusion for all the people who are used to the old qtest_start() function or who want to backport patches that have done after this change to a code level before this change.

If you are really bugged by the qtest_init() name clash, I think it's way easier if you rename the qtest_init() in the qtest.c file instead.

Thomas

author
#96 lore raw

Re: [Qemu-devel] [PATCH v6 29/29] libqtest: Rename qtest_init() to qtest_start()

Quoted 13 lines · Thomas Huth
Quoted 4 lines · Eric Blake

We already have another qtest_init() in the tree, for the top-level qtest.c device; having two functions with different signatures is confusing. Rename the libqtest version to qtest_start() to eliminate the duplication.

This is too much code churn for my taste, and I also do not like the idea of naming the function qtest_start() - since this was a function with different semantics before your patch 28/29, so this will cause confusion for all the people who are used to the old qtest_start() function or who want to backport patches that have done after this change to a code level before this change.

Quoted 2 lines

If you are really bugged by the qtest_init() name clash, I think it's way easier if you rename the qtest_init() in the qtest.c file instead.

Except the qtest_init() in qtest.c really is our normal pattern of *_init for devices, so that one's named correctly. Our testsuite is the one that is using a name different from its normal usage in the rest of the tree.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org