Preliminary libqtest cleanups
v7 cover Preliminary libqtest cleanups
I'm trying to get rid of some of the duplication in libqtest.h before tackling the project of making qmp() easier to use. v6 got some positive review on the direction of making dependence on global_qtest explicit (compared to v5 where I went the opposite direction and tried to use global_qtest even more than it was already being abused for), so most of the changes in this posting are related to additional cleanups or addressing good review comments.
Still to come: I still have work pending on overhauling the qmp() and qtest_qmp() code, using naming that makes more sense, as well as getting us to the point that we can reliably use -Wformat checking on qmp().
Available as a tag at:
git fetch git://repo.or.cz/qemu/ericb.git qapi-qmp-cleanup-v7
Since v6 (https://lists.gnu.org/archive/html/qemu-devel/2017-09/msg00308.html):
- Add review tags where appropriate
- merge a couple of patches [Thomas]
- split ahci into multiple patches [Thomas]
- add qtest_[v]startf rather than overloading (and churn) on qtest_start [Thomas]
- catch more depedencies on global_qtest under tests/libqos/
- lots more patches added to make use of global_qtest obvious
- drop .gitignore changes for a later series
001/38:[----] [--] 'test-qga: Kill broken and dead QGA_TEST_SIDE_EFFECTING code' 002/38:[----] [--] 'qtest: Don't perform side effects inside assertion' 003/38:[----] [--] 'numa-test: Use hmp()'
004/38:[----] [--] 'tests: Clean up wait for event'
005/38:[----] [--] 'libqtest: Remove dead qtest_instances variable' 006/38:[----] [--] 'libqtest: Use qemu_strtoul()'
007/38:[0020] [FC] 'libqtest: Inline qtest_query_target_endianness()' 008/38:[0019] [FC] 'libqos: Track QTestState with QPCIBus'
009/38:[down] 'libqos: Track QTestState with QVirtioBus'
010/38:[down] 'libqos: Move/rename qpci_unplug_acpi_device_test() to pci.c' 011/38:[0045] [FC] 'libqos: Use explicit QTestState for pci operations' 012/38:[0179] [FC] 'libqos: Use explicit QTestState for virtio operations' 013/38:[0011] [FC] 'libqos: Use explicit QTestState for fw_cfg operations' 014/38:[0015] [FC] 'libqos: Use explicit QTestState for rtas operations' 015/38:[down] 'libqos: Use explicit QTestState for i2c operations' 016/38:[down] 'libqos: Use explicit QTestState for ahci operations' 017/38:[down] 'libqos: Use explicit QTestState for remaining libqos operations' 018/38:[0079] [FC] 'ahci-test: Drop dependence on global_qtest' 019/38:[0012] [FC] 'ivshmem-test: Drop dependence on global_qtest' 020/38:[----] [--] 'postcopy-test: Drop dependence on global_qtest' 021/38:[----] [--] 'vhost-user-test: Drop dependence on global_qtest' 022/38:[----] [-C] 'qmp-test: Drop dependence on global_qtest' 023/38:[----] [--] 'tests/boot-sector: Drop dependence on global_qtest' 024/38:[0079] [FC] 'tests/acpi-utils: Drop dependence on global_qtest' 025/38:[----] [--] 'wdt_ib700-test: Drop dependence on global_qtest' 026/38:[down] 'libqtest: Merge qtest_end() into qtest_quit()'
027/38:[down] 'libqtest: Swap order of qtest_init() and qtest_start()' 028/38:[down] 'libqtest: Add qtest_[v]startf()'
029/38:[down] 'libqtest: Merge qtest_init() into qtest_start()' 030/38:[0008] [FC] 'qtest: Avoid passing raw strings through hmp()' 031/38:[down] 'libqtest: Merge qtest_clock_*() with clock_*()' 032/38:[down] 'libqtest: Merge qtest_irq*() with irq*()'
033/38:[down] 'libqtest: Merge qtest_{in,out}[bwl]() with {in,out}[bwl]()' 034/38:[down] 'libqtest: Merge qtest_{read,write}[bwlq]() with {read,write}[bwlq]()' 035/38:[down] 'libqtest: Merge qtest_{mem,buf}{read,write}() with {mem,buf}{read,write}()' 036/38:[down] 'libqtest: Merge qtest_memset() with qmemset()'
037/38:[0088] [FC] 'libqtest: Separate qmp_discard_response() from command' 038/38:[down] 'libqtest: Merge qtest_hmp() with hmp()'
Eric Blake (37):
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: Use qemu_strtoul()
libqtest: Inline qtest_query_target_endianness()
libqos: Track QTestState with QPCIBus
libqos: Track QTestState with QVirtioBus
libqos: Move/rename qpci_unplug_acpi_device_test() to pci.c
libqos: Use explicit QTestState for pci operations
libqos: Use explicit QTestState for virtio operations
libqos: Use explicit QTestState for fw_cfg operations
libqos: Use explicit QTestState for rtas operations
libqos: Use explicit QTestState for i2c operations
libqos: Use explicit QTestState for ahci operations
libqos: Use explicit QTestState for remaining libqos 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
wdt_ib700-test: Drop dependence on global_qtest
libqtest: Merge qtest_end() into qtest_quit()
libqtest: Swap order of qtest_init() and qtest_start()
libqtest: Add qtest_[v]startf()
libqtest: Merge qtest_init() into qtest_start()
qtest: Avoid passing raw strings through hmp()
libqtest: Merge qtest_clock_*() with clock_*()
libqtest: Merge qtest_irq*() with irq*()
libqtest: Merge qtest_{in,out}[bwl]() with {in,out}[bwl]()
libqtest: Merge qtest_{read,write}[bwlq]() with {read,write}[bwlq]()
libqtest: Merge qtest_{mem,buf}{read,write}() with
{mem,buf}{read,write}() libqtest: Merge qtest_memset() with qmemset()
libqtest: Separate qmp_discard_response() from command
libqtest: Merge qtest_hmp() with hmp()
Markus Armbruster (1):
tests: Clean up wait for event
tests/libqtest.h | 522 +++++++---------------------------------- tests/acpi-utils.h | 67 +++--- tests/boot-sector.h | 6 +- tests/libqos/ahci.h | 2 +- tests/libqos/fw_cfg.h | 10 +- tests/libqos/i2c.h | 7 +- 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 | 5 +- tests/libqos/rtas.h | 9 +- tests/libqos/virtio-mmio.h | 6 +- tests/libqos/virtio-pci.h | 2 - tests/libqos/virtio.h | 13 +- tests/multiboot/libc.h | 2 +- tests/libqtest.c | 192 ++++++++------- qtest.c | 80 +++++-- tests/ac97-test.c | 4 +- tests/acpi-utils.c | 19 +- tests/ahci-test.c | 92 ++++---- tests/bios-tables-test.c | 199 ++++++++-------- tests/boot-order-test.c | 31 ++- tests/boot-sector.c | 8 +- tests/boot-serial-test.c | 12 +- tests/device-introspect-test.c | 30 +-- tests/display-vga-test.c | 18 +- tests/drive_del-test.c | 26 +- tests/ds1338-test.c | 6 +- tests/e1000-test.c | 10 +- tests/e1000e-test.c | 46 ++-- tests/eepro100-test.c | 11 +- tests/endianness-test.c | 57 ++--- tests/es1370-test.c | 4 +- tests/fdc-test.c | 144 ++++++------ tests/fw_cfg-test.c | 13 +- tests/hd-geo-test.c | 20 +- tests/i440fx-test.c | 24 +- tests/i82801b11-test.c | 5 +- tests/ide-test.c | 58 +++-- tests/intel-hda-test.c | 9 +- tests/ioh3420-test.c | 7 +- tests/ipmi-bt-test.c | 29 +-- tests/ipmi-kcs-test.c | 23 +- tests/ipoctal232-test.c | 5 +- tests/ivshmem-test.c | 27 +-- tests/libqos/ahci.c | 47 ++-- tests/libqos/fw_cfg.c | 14 +- tests/libqos/i2c-imx.c | 67 +++--- tests/libqos/i2c-omap.c | 45 ++-- tests/libqos/libqos-pc.c | 2 +- tests/libqos/libqos.c | 52 +--- tests/libqos/malloc-pc.c | 8 +- tests/libqos/malloc-spapr.c | 4 +- tests/libqos/pci-pc.c | 81 +++---- tests/libqos/pci-spapr.c | 45 ++-- tests/libqos/pci.c | 22 +- tests/libqos/rtas.c | 36 +-- tests/libqos/virtio-mmio.c | 61 +++-- tests/libqos/virtio-pci.c | 14 +- tests/libqos/virtio.c | 87 ++++--- tests/m25p80-test.c | 89 ++++--- tests/m48t59-test.c | 14 +- tests/megasas-test.c | 7 +- tests/multiboot/libc.c | 2 +- tests/ne2000-test.c | 4 +- tests/numa-test.c | 102 +++----- tests/nvme-test.c | 7 +- tests/pc-cpu-test.c | 24 +- tests/pcnet-test.c | 4 +- tests/pnv-xscom-test.c | 18 +- tests/postcopy-test.c | 93 ++++---- tests/prom-env-test.c | 15 +- tests/pvpanic-test.c | 8 +- tests/pxe-test.c | 16 +- tests/q35-test.c | 24 +- tests/qmp-test.c | 43 ++-- tests/qom-test.c | 7 +- tests/rtas-test.c | 3 +- tests/rtc-test.c | 94 ++++---- tests/rtl8139-test.c | 17 +- tests/spapr-phb-test.c | 5 +- tests/tco-test.c | 45 ++-- tests/test-arm-mptimer.c | 43 ++-- tests/test-filter-mirror.c | 19 +- tests/test-filter-redirector.c | 66 +++--- tests/test-hmp.c | 13 +- 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 | 7 +- tests/usb-hcd-xhci-test.c | 19 +- tests/vhost-user-test.c | 105 +++------ tests/virtio-9p-test.c | 5 +- tests/virtio-balloon-test.c | 4 +- tests/virtio-blk-test.c | 83 ++++--- tests/virtio-console-test.c | 10 +- tests/virtio-net-test.c | 30 ++- tests/virtio-rng-test.c | 9 +- tests/virtio-scsi-test.c | 22 +- tests/virtio-serial-test.c | 4 +- tests/vmgenid-test.c | 51 ++-- tests/vmxnet3-test.c | 4 +- tests/wdt_ib700-test.c | 92 ++++---- 110 files changed, 1632 insertions(+), 2210 deletions(-)
Signature · 1 line
2.13.5
PATCH v7 1/38 test-qga: Kill broken and dead QGA_TEST_SIDE_EFFECTING code
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
@@ -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
PATCH v7 2/38 qtest: Don't perform side effects inside assertion
In reply to Eric BlakeAssertions 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
@@ -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
PATCH v7 3/38 numa-test: Use hmp()
In reply to Eric BlakeDon'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
@@ -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
PATCH v7 4/38 tests: Clean up wait for event
In reply to Eric BlakeFrom: 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v7 5/38 libqtest: Remove dead qtest_instances variable
In reply to Eric BlakePrior 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
@@ -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
PATCH v7 6/38 libqtest: Use qemu_strtoul()
In reply to Eric BlakeThis 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
@@ -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"
@@ -331,12 +332,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);
@@ -699,11 +702,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;
@@ -754,11 +759,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
PATCH v7 7/38 libqtest: Inline qtest_query_target_endianness()
In reply to Eric BlakeThere was only one caller; it's easier to inline things. (It trades one forward declaration for two others, but it's not worth the additional churn of topological sorting, even though that would be possible.)
---
v7: Drop the topological sorting
--- tests/libqtest.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-)
tests/libqtest.c +9 -17
@@ -49,7 +49,9 @@ static struct sigaction sigact_old; g_assert_cmpint(ret, !=, -1); \ }while (0 ) -static int qtest_query_target_endianness(QTestState *s); +static void qtest_sendf(QTestState *s, const char *fmt, ...) + GCC_FMT_ATTR(2, 3); +static gchar **qtest_rsp (QTestState *s,int expected_args);static int init_socket (const char *socket_path) {
@@ -158,6 +160,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) {
@@ -221,8 +224,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; }
@@ -367,20 +373,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; -} - typedef struct { JSONMessageParser parser; QDict *response;
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PATCH v7 07/38] libqtest: Inline qtest_query_target_endianness()
Quoted 61 lines · Eric Blake
There was only one caller; it's easier to inline things. (It trades one forward declaration for two others, but it's not worth the additional churn of topological sorting, even though that would be possible.)
Signed-off-by Eric Blake <[email protected]>---
v7: Drop the topological sorting--- tests/libqtest.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-)tests/libqtest.c +9
-10@@ -49,7 +49,9 @@ static struct sigaction sigact_old; g_assert_cmpint(ret, !=, -1); \ }while (0 ) -static int qtest_query_target_endianness(QTestState *s); +static void qtest_sendf(QTestState *s, const char *fmt, ...) + GCC_FMT_ATTR(2, 3); +static gchar **qtest_rsp (QTestState *s,int expected_args);static int init_socket (const char *socket_path) {@@ -158,6 +160,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) {@@ -221,8 +224,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; }@@ -367,20 +373,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 );
tests/libqtest.c redo: · line 378
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;
Looking at this patch again, I'm not sure anymore whether this is really worth the effort. Keeping code that belongs together in a separate function also makes sense ... Not sure, but I'd maybe rather drop this patch. But in case you want to keep it:
PATCH v7 8/38 libqos: Track QTestState with QPCIBus
In reply to Eric BlakeWhen 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).
Touch up some allocations to use g_new0() rather than g_malloc() while in the area, and simplify some code (all implementations of QOSOps provide a .init_allocator() that never fails).
---
v7: use g_new0() instead of g_malloc(), drop dead conditionals
--- 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 | 10 +++------- tests/libqos/pci-pc.c | 7 ++++--- tests/libqos/pci-spapr.c | 7 ++++--- 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(+), 33 deletions(-)
tests/libqos/ahci.h +1 -1
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 +3 -7
@@ -17,18 +17,14 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap) {char *cmdline; -struct QOSState *qs =g_malloc (sizeof (QOSState)); +QOSState *qs =g_new0 (QOSState,1 ); cmdline =g_strdup_vprintf (cmdline_fmt, ap); qs->qts =qtest_start (cmdline); qs->ops = ops;if (ops) { -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); - } + qs->alloc = ops->init_allocator (ALLOC_NO_FLAGS ); + qs->pcibus = ops->qpci_init (qs->qts, qs->alloc); }g_free (cmdline);
tests/libqos/pci-pc.c +4 -3
@@ -115,11 +115,11 @@ static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3outl (0xcfc , value); } -QPCIBus *qpci_init_pc (QGuestAllocator *alloc) +QPCIBus *qpci_init_pc (QTestState *qts,QGuestAllocator *alloc) { -QPCIBusPC *ret; +QPCIBusPC *ret =g_new0 (QPCIBusPC,1 ); - ret =g_malloc (sizeof (*ret)); +assert (qts); ret->bus.pio_readb = qpci_pc_pio_readb; ret->bus.pio_readw = qpci_pc_pio_readw;
@@ -142,6 +142,7 @@ QPCIBus *qpci_init_pc(QGuestAllocator *alloc) ret->bus.config_writew = qpci_pc_config_writew; ret->bus.config_writel = qpci_pc_config_writel; + ret->bus.qts = qts; ret->bus.pio_alloc_ptr =0xc000 ; ret->bus.mmio_alloc_ptr =0xE0000000 ; ret->bus.mmio_limit =0x100000000ULL ;
tests/libqos/pci-spapr.c +4 -3
@@ -154,11 +154,11 @@ 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; +QPCIBusSPAPR *ret =g_new0 (QPCIBusSPAPR,1 ); - ret =g_malloc (sizeof (*ret)); +assert (qts); ret->alloc = alloc;
@@ -197,6 +197,7 @@ QPCIBus *qpci_init_spapr(QGuestAllocator *alloc) ret->mmio32.pci_base =SPAPR_PCI_MMIO32_WIN_SIZE ; ret->mmio32.size =SPAPR_PCI_MMIO32_WIN_SIZE ; + ret->bus.qts = qts; ret->bus.pio_alloc_ptr =0xc000 ; ret->bus.mmio_alloc_ptr = ret->mmio32.pci_base; ret->bus.mmio_limit = ret->mmio32.pci_base + ret->mmio32.size;
tests/q35-test.c +2 -2
@@ -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
@@ -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
@@ -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
@@ -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
@@ -166,7 +166,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 );
@@ -893,7 +893,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
Re: [Qemu-devel] [PATCH v7 08/38] libqos: Track QTestState with QPCIBus
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 currentglobal_qtestas the current state, although this required fixing the order of initialization to ensureqtest_start()is called before qpci_init*() in rtl8139-test, and provided an opportunity to pass in the allocator in e1000e-test).
Quoted 5 lines
Touch up some allocations to use
g_new0()rather thang_malloc()while in the area, and simplify some code (all implementations of QOSOps provide a .init_allocator() that never fails).Signed-off-by Eric Blake <[email protected]>
Re: [Qemu-devel] [PATCH v7 08/38] libqos: Track QTestState with QPCIBus
In reply to Eric BlakeQuoted 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 currentglobal_qtestas the current state, although this required fixing the order of initialization to ensureqtest_start()is called before qpci_init*() in rtl8139-test, and provided an opportunity to pass in the allocator in e1000e-test).
Quoted 5 lines
Touch up some allocations to use
g_new0()rather thang_malloc()while in the area, and simplify some code (all implementations of QOSOps provide a .init_allocator() that never fails).Signed-off-by Eric Blake <[email protected]>
PATCH v7 9/38 libqos: Track QTestState with QVirtioBus
In reply to Eric BlakeWhen initializing a QVirtioDevice (which always has an associated QVirtioBus), we want to track which QTestState to use for all I/O processed through that bus and device. Copy the paradigm used for QPCIBus, and track the test state at the bus level; this in turn requires a separate bus object per device (and associated cleanup) rather than just sharing a const version of the dispatch table. Update all affected callers.
Likewise, let QVirtQueue trace back to its associated QVirtioDevice.
A later patch can then explicitly use the QTestState associated with the bus rather than blindly relying on global_qtest.
--- tests/libqos/virtio-mmio.h | 6 +++--- tests/libqos/virtio-pci.h | 2 -- tests/libqos/virtio.h | 7 ++++++- tests/libqos/virtio-mmio.c | 12 ++++++++++-- tests/libqos/virtio-pci.c | 6 ++++-- tests/libqos/virtio.c | 10 ++++++++++ tests/virtio-blk-test.c | 5 +++-- 7 files changed, 36 insertions(+), 12 deletions(-)
tests/libqos/virtio-mmio.h +3 -3
@@ -39,8 +39,8 @@ typedef struct QVirtioMMIODevice { uint32_t features; /* As it cannot be read later, save it */ } 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); +void qvirtio_mmio_device_free (QVirtioMMIODevice *dev);#endif
tests/libqos/virtio-pci.h +0 -2
@@ -29,8 +29,6 @@ typedef struct QVirtQueuePCI {uint32_t msix_data; } QVirtQueuePCI; -extern const QVirtioBus qvirtio_pci; -QVirtioPCIDevice *qvirtio_pci_device_find (QPCIBus *bus,uint16_t device_type);QVirtioPCIDevice *qvirtio_pci_device_find_slot (QPCIBus *bus,uint16_t device_type,int slot);
tests/libqos/virtio.h +6 -1
@@ -18,12 +18,13 @@typedef struct QVirtioBus QVirtioBus ;typedef struct QVirtioDevice { -const QVirtioBus *bus; +QVirtioBus *bus;/* Device type */ uint16_t device_type; }QVirtioDevice ; typedef struct QVirtQueue { + QVirtioDevice *dev; uint64_t desc; /* This points to an array of struct vring_desc */ uint64_t avail; /* This points to a struct vring_avail */ uint64_t used; /* This points to a struct vring_used */
@@ -88,6 +89,8 @@ struct QVirtioBus {/* Notify changes in virtqueue */ void (*virtqueue_kick)(QVirtioDevice *d,QVirtQueue *vq); + +QTestState *qts; };static inline bool qvirtio_is_big_endian (QVirtioDevice *d)
@@ -103,6 +106,8 @@ static inline uint32_t qvring_size(uint32_t num, uint32_t align) +sizeof (uint16_t ) *3 +sizeof (struct vring_used_elem ) * num; } +QVirtioBus *qvirtio_init_bus (QTestState *qts,const QVirtioBus *base); +uint8_t qvirtio_config_readb (QVirtioDevice *d,uint64_t addr);uint16_t qvirtio_config_readw (QVirtioDevice *d,uint64_t addr);uint32_t qvirtio_config_readl (QVirtioDevice *d,uint64_t addr);
tests/libqos/virtio-mmio.c +10 -2
@@ -131,6 +131,7 @@ static QVirtQueue *qvirtio_mmio_virtqueue_setup(QVirtioDevice *d,qvirtio_mmio_queue_select (d, index);writel (dev->addr +QVIRTIO_MMIO_QUEUE_ALIGN , dev->page_size); + vq->dev = d; vq->index = index; vq->size =qvirtio_mmio_get_queue_size (d); vq->free_head =0 ;
@@ -187,7 +188,8 @@ const QVirtioBus qvirtio_mmio = { .virtqueue_kick = qvirtio_mmio_virtqueue_kick, }; -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) {QVirtioMMIODevice *dev;uint32_t magic;
@@ -199,9 +201,15 @@ QVirtioMMIODevice *qvirtio_mmio_init_device(uint64_t addr, uint32_t page_size) dev->addr = addr; dev->page_size = page_size; dev->vdev.device_type =readl (addr +QVIRTIO_MMIO_DEVICE_ID ); - dev->vdev.bus = &qvirtio_mmio; + dev->vdev.bus =qvirtio_init_bus (qts, &qvirtio_mmio);writel (addr +QVIRTIO_MMIO_GUEST_PAGE_SIZE , page_size);return dev; } + +void qvirtio_mmio_device_free (QVirtioMMIODevice *dev) +{ +g_free (dev->vdev.bus); +g_free (dev); +}
tests/libqos/virtio-pci.c +4 -2
@@ -31,6 +31,7 @@ typedef struct QVirtioPCIForeachData {void qvirtio_pci_device_free (QVirtioPCIDevice *dev) { +g_free (dev->vdev.bus);g_free (dev->pdev);g_free (dev); }
@@ -233,6 +234,7 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d, feat =qvirtio_pci_get_guest_features (d);qvirtio_pci_queue_select (d, index); + vqpci->vq.dev = d; vqpci->vq.index = index; vqpci->vq.size =qvirtio_pci_get_queue_size (d); vqpci->vq.free_head =0 ;
@@ -315,7 +317,7 @@ QVirtioPCIDevice *qvirtio_pci_device_find(QPCIBus *bus, uint16_t device_type)qvirtio_pci_foreach (bus, device_type, false,0 , qvirtio_pci_assign_device, &dev); - dev->vdev.bus = &qvirtio_pci; + dev->vdev.bus =qvirtio_init_bus (bus->qts, &qvirtio_pci);return dev; }
@@ -328,7 +330,7 @@ QVirtioPCIDevice *qvirtio_pci_device_find_slot(QPCIBus *bus,qvirtio_pci_foreach (bus, device_type, true, slot, qvirtio_pci_assign_device, &dev); - dev->vdev.bus = &qvirtio_pci; + dev->vdev.bus =qvirtio_init_bus (bus->qts, &qvirtio_pci);return dev; }
tests/libqos/virtio.c +10 -0
@@ -13,6 +13,16 @@#include "standard-headers/linux/virtio_config.h" #include "standard-headers/linux/virtio_ring.h" +QVirtioBus *qvirtio_init_bus (QTestState *qts,const QVirtioBus *base) +{ +QVirtioBus *bus =g_new0 (QVirtioBus,1 ); + +assert (qts); + *bus = *base; + bus->qts = qts; +return bus; +} +uint8_t qvirtio_config_readb (QVirtioDevice *d,uint64_t addr) {return d->bus->config_readb (d, addr);
tests/virtio-blk-test.c +3 -2
@@ -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);
@@ -711,7 +712,7 @@ static void mmio_basic(void)/* End test */ qvirtqueue_cleanup (dev->vdev.bus, vq, alloc); -g_free (dev); +qvirtio_mmio_device_free (dev);generic_alloc_uninit (alloc);test_end (); }
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PATCH v7 09/38] libqos: Track QTestState with QVirtioBus
Quoted 7 lines · Eric Blake
When initializing a QVirtioDevice (which always has an associated QVirtioBus), we want to track which QTestState to use for all I/O processed through that bus and device. Copy the paradigm used for QPCIBus, and track the test state at the bus level; this in turn requires a separate bus object per device (and associated cleanup) rather than just sharing a const version of the dispatch table.
I fail to see why we need a separate bus object here for each device. The bus is only available one time, not multiple times, isn't it? So there should also only be one bus object floating around, not multiple ones... or do I miss something?
Thomas
Re: [Qemu-devel] [PATCH v7 09/38] libqos: Track QTestState with QVirtioBus
Quoted 8 lines · Thomas Huth
Quoted 7 lines · Eric Blake
When initializing a QVirtioDevice (which always has an associated QVirtioBus), we want to track which QTestState to use for all I/O processed through that bus and device. Copy the paradigm used for QPCIBus, and track the test state at the bus level; this in turn requires a separate bus object per device (and associated cleanup) rather than just sharing a const version of the dispatch table.
Quoted 4 lines
I fail to see why we need a separate bus object here for each device. The bus is only available one time, not multiple times, isn't it? So there should also only be one bus object floating around, not multiple ones... or do I miss something?
You are right that there is only one bus for the machine - the problem is that the object representing the bus is dynamically created on the fly at the point where the device is first grabbed, rather than up front as part of creating the machine (in other words, the device search is not performed on a pre-existing bus object).
Contrast qpci_device_find() (lookup based on a pre-existing bus) with qvirtio_mmio_init_device() (lookup that did not use a pre-existing bus); also note that qvirtio_pci_device_find() takes a pre-existing QPCIBus (since on that architecture, the QVirtioBus is itself a device on the QPCIBus).
I suppose that we could indeed refactor the code to require callers to create the QVirtioBus object up front, and then make the device lookup (both qvirtio_mmio_init_device() and qvirtio_pci_device_find()) take a QVirtioBus parameter instead of QTestState or QPCIBus. That's slightly more work, but I'm happy to attempt it if you think it will be better.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v7 09/38] libqos: Track QTestState with QVirtioBus
Quoted 1 line · Eric Blake
On 09/12/2017 02:21 AM, Thomas Huth wrote:
[...]
Quoted 17 lines
Quoted 4 lines
I fail to see why we need a separate bus object here for each device. The bus is only available one time, not multiple times, isn't it? So there should also only be one bus object floating around, not multiple ones... or do I miss something?
You are right that there is only one bus for the machine - the problem is that the object representing the bus is dynamically created on the fly at the point where the device is first grabbed, rather than up front as part of creating the machine (in other words, the device search is not performed on a pre-existing bus object).
Contrast
qpci_device_find()(lookup based on a pre-existing bus) withqvirtio_mmio_init_device()(lookup that did not use a pre-existing bus); also note thatqvirtio_pci_device_find()takes a pre-existing QPCIBus (since on that architecture, the QVirtioBus is itself a device on the QPCIBus).
Quoted 5 lines
I suppose that we could indeed refactor the code to require callers to create the QVirtioBus object up front, and then make the device lookup (both
qvirtio_mmio_init_device()andqvirtio_pci_device_find()) take a QVirtioBus parameter instead of QTestState or QPCIBus. That's slightly more work, but I'm happy to attempt it if you think it will be better.
At least to me, that sounds like the right way to go. I guess we might run into other problems later if we have multiple instances of the bus object floating around ... so sorry if this is extra work, but I'd say let's better do it properly now instead of having to rework this again later.
Thomas
PATCH v7 10/38 libqos: Move/rename qpci_unplug_acpi_device_test() to pci.c
In reply to Eric BlakeCommit 2f8b2767 originally added qpci_plug_device_test() and qpci_unplug_acpi_device_test() as a pair, both in pci-pc.c. Later, commit cf716b31 moved one half of the pair to pci.c when adding PPC64 support. Keep the implementations of the two functions together, and shorten the name to qpci_unplug_device_test(), since all callers use the two functions in tandem.
--- tests/libqos/pci.h | 2 +- tests/e1000e-test.c | 2 +- tests/ivshmem-test.c | 2 +- tests/libqos/pci-pc.c | 23 ----------------------- tests/libqos/pci.c | 23 +++++++++++++++++++++++ tests/virtio-blk-test.c | 2 +- tests/virtio-net-test.c | 2 +- tests/virtio-rng-test.c | 2 +- 8 files changed, 29 insertions(+), 29 deletions(-)
tests/libqos/pci.h +1 -1
@@ -111,5 +111,5 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr);void qpci_plug_device_test (const char *driver,const char *id,uint8_t slot,const char *opts); -void qpci_unplug_acpi_device_test (const char *id,uint8_t slot); +void qpci_unplug_device_test (const char *id,uint8_t slot);#endif
tests/e1000e-test.c +1 -1
@@ -461,7 +461,7 @@ static void test_e1000e_hotplug(gconstpointer data)qtest_start ("-device e1000e" );qpci_plug_device_test ("e1000e" ,"e1000e_net" , slot,NULL ); -qpci_unplug_acpi_device_test ("e1000e_net" , slot); +qpci_unplug_device_test ("e1000e_net" , slot);qtest_end (); }
tests/ivshmem-test.c +1 -1
@@ -427,7 +427,7 @@ static void test_ivshmem_hotplug(void)qpci_plug_device_test ("ivshmem" ,"iv1" ,PCI_SLOT_HP , opts);if (strcmp (arch,"ppc64" ) !=0 ) { -qpci_unplug_acpi_device_test ("iv1" ,PCI_SLOT_HP ); +qpci_unplug_device_test ("iv1" ,PCI_SLOT_HP ); }qtest_end ();
tests/libqos/pci-pc.c +0 -23
@@ -19,9 +19,6 @@#include "qemu-common.h" -#define ACPI_PCIHP_ADDR 0xae00 -#define PCI_EJ_BASE 0x0008 - typedef struct QPCIBusPC { QPCIBus bus;
@@ -156,23 +153,3 @@ void qpci_free_pc(QPCIBus *bus)g_free (s); } - -void qpci_unplug_acpi_device_test (const char *id,uint8_t slot) -{ -QDict *response; -char *cmd; - - cmd =g_strdup_printf ("{'execute': 'device_del'," -" 'arguments': {" -" 'id': '%s'" -"}}" , id); - response =qmp (cmd); -g_free (cmd); -g_assert (response); -g_assert (!qdict_haskey (response,"error" )); -QDECREF (response); - -outb (ACPI_PCIHP_ADDR +PCI_EJ_BASE ,1 << slot); - -qmp_eventwait ("DEVICE_DELETED" ); -}
tests/libqos/pci.c +23 -0
@@ -16,6 +16,9 @@#include "hw/pci/pci_regs.h" #include "qemu/host-utils.h" +#define ACPI_PCIHP_ADDR 0xae00 +#define PCI_EJ_BASE 0x0008 +void qpci_device_foreach (QPCIBus *bus,int vendor_id,int device_id,void (*func)(QPCIDevice *dev,int devfn,void *data),void *data)
@@ -412,3 +415,23 @@ void qpci_plug_device_test(const char *driver, const char *id,g_assert (!qdict_haskey (response,"error" ));QDECREF (response); } + +void qpci_unplug_device_test (const char *id,uint8_t slot) +{ +QDict *response; +char *cmd; + + cmd =g_strdup_printf ("{'execute': 'device_del'," +" 'arguments': {" +" 'id': '%s'" +"}}" , id); + response =qmp (cmd); +g_free (cmd); +g_assert (response); +g_assert (!qdict_haskey (response,"error" )); +QDECREF (response); + +outb (ACPI_PCIHP_ADDR +PCI_EJ_BASE ,1 << slot); + +qmp_eventwait ("DEVICE_DELETED" ); +}
tests/virtio-blk-test.c +1 -1
@@ -672,7 +672,7 @@ static void pci_hotplug(void)/* unplug secondary disk */ if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) { -qpci_unplug_acpi_device_test ("drv1" ,PCI_SLOT_HP ); +qpci_unplug_device_test ("drv1" ,PCI_SLOT_HP ); }qtest_shutdown (qs); }
tests/virtio-net-test.c +1 -1
@@ -248,7 +248,7 @@ static void hotplug(void)qpci_plug_device_test ("virtio-net-pci" ,"net1" ,PCI_SLOT_HP ,NULL );if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) { -qpci_unplug_acpi_device_test ("net1" ,PCI_SLOT_HP ); +qpci_unplug_device_test ("net1" ,PCI_SLOT_HP ); }test_end ();
tests/virtio-rng-test.c +1 -1
@@ -25,7 +25,7 @@ static void hotplug(void)qpci_plug_device_test ("virtio-rng-pci" ,"rng1" ,PCI_SLOT_HP ,NULL );if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) { -qpci_unplug_acpi_device_test ("rng1" ,PCI_SLOT_HP ); +qpci_unplug_device_test ("rng1" ,PCI_SLOT_HP ); } }
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PATCH v7 10/38] libqos: Move/rename qpci_unplug_acpi_device_test() to pci.c
Quoted 123 lines · Eric Blake
Commit
2f8b2767originally addedqpci_plug_device_test()andqpci_unplug_acpi_device_test()as a pair, both inpci-pc.c. Later, commitcf716b31moved one half of the pair topci.cwhen adding PPC64 support. Keep the implementations of the two functions together, and shorten the name toqpci_unplug_device_test(), since all callers use the two functions in tandem.Signed-off-by Eric Blake <[email protected]>--- tests/libqos/pci.h | 2 +- tests/e1000e-test.c | 2 +- tests/ivshmem-test.c | 2 +- tests/libqos/pci-pc.c | 23 ----------------------- tests/libqos/pci.c | 23 +++++++++++++++++++++++ tests/virtio-blk-test.c | 2 +- tests/virtio-net-test.c | 2 +- tests/virtio-rng-test.c | 2 +- 8 files changed, 29 insertions(+), 29 deletions(-)tests/libqos/pci.h +1
-1@@ -111,5 +111,5 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr);void qpci_plug_device_test (const char *driver,const char *id,uint8_t slot,const char *opts); -void qpci_unplug_acpi_device_test (const char *id,uint8_t slot); +void qpci_unplug_device_test (const char *id,uint8_t slot);#endif tests/e1000e-test.c +1
-1@@ -461,7 +461,7 @@ static void test_e1000e_hotplug(gconstpointer data)qtest_start ("-device e1000e" );qpci_plug_device_test ("e1000e" ,"e1000e_net" , slot,NULL ); -qpci_unplug_acpi_device_test ("e1000e_net" , slot); +qpci_unplug_device_test ("e1000e_net" , slot);qtest_end (); }tests/ivshmem-test.c +1
-1@@ -427,7 +427,7 @@ static void test_ivshmem_hotplug(void)qpci_plug_device_test ("ivshmem" ,"iv1" ,PCI_SLOT_HP , opts);if (strcmp (arch,"ppc64" ) !=0 ) { -qpci_unplug_acpi_device_test ("iv1" ,PCI_SLOT_HP ); +qpci_unplug_device_test ("iv1" ,PCI_SLOT_HP ); }qtest_end ();tests/libqos/pci-pc.c +0
-23@@ -19,9 +19,6 @@#include "qemu-common.h" -#define ACPI_PCIHP_ADDR 0xae00 -#define PCI_EJ_BASE 0x0008 - typedef struct QPCIBusPC { QPCIBus bus;@@ -156,23 +153,3 @@ void qpci_free_pc(QPCIBus *bus)g_free (s); } - -void qpci_unplug_acpi_device_test (const char *id,uint8_t slot) -{ -QDict *response; -char *cmd; - - cmd =g_strdup_printf ("{'execute': 'device_del'," -" 'arguments': {" -" 'id': '%s'" -"}}" , id); - response =qmp (cmd); -g_free (cmd); -g_assert (response); -g_assert (!qdict_haskey (response,"error" )); -QDECREF (response); - -outb (ACPI_PCIHP_ADDR +PCI_EJ_BASE ,1 << slot); - -qmp_eventwait ("DEVICE_DELETED" ); -}tests/libqos/pci.c +13
-0@@ -16,6 +16,9 @@#include "hw/pci/pci_regs.h" #include "qemu/host-utils.h" +#define ACPI_PCIHP_ADDR 0xae00 +#define PCI_EJ_BASE 0x0008 +void qpci_device_foreach (QPCIBus *bus,int vendor_id,int device_id,void (*func)(QPCIDevice *dev,int devfn,void *data),void *data)@@ -412,3 +415,23 @@ void qpci_plug_device_test(const char *driver, const char *id,g_assert (!qdict_haskey (response,"error" ));QDECREF (response); } + +void qpci_unplug_device_test (const char *id,uint8_t slot) +{ +QDict *response; +char *cmd; + + cmd =g_strdup_printf ("{'execute': 'device_del'," +" 'arguments': {" +" 'id': '%s'" +"}}" , id);
tests/libqos/pci.c void qpci_plug_device_test(const char *driver, const char *id, · line 437
Quoted 10 lines
tests/libqos/pci.c +10
-0+ response =qmp (cmd); +g_free (cmd); +g_assert (response); +g_assert (!qdict_haskey (response,"error" )); +QDECREF (response); + +outb (ACPI_PCIHP_ADDR +PCI_EJ_BASE ,1 << slot); + +qmp_eventwait ("DEVICE_DELETED" ); +}
No, that's a bad idea. ACPI and that outb() is clearly something specific to x86, so this should not reside in pci.c but in pci-pc.c
We might be able to unify this - I've had a similar patch here:
https://patchwork.kernel.org/patch/9905031/
... but I think this needs some more careful thinking and discussion, so I'd suggest that you remove this from your already huge patch series for now and we fix it later instead.
Thomas
Re: [Qemu-devel] [PATCH v7 10/38] libqos: Move/rename qpci_unplug_acpi_device_test() to pci.c
Quoted 14 lines · Thomas Huth
Quoted 8 lines · Eric Blake
Commit
2f8b2767originally addedqpci_plug_device_test()andqpci_unplug_acpi_device_test()as a pair, both inpci-pc.c. Later, commitcf716b31moved one half of the pair topci.cwhen adding PPC64 support. Keep the implementations of the two functions together, and shorten the name toqpci_unplug_device_test(), since all callers use the two functions in tandem.No, that's a bad idea. ACPI and that
outb()is clearly something specific to x86, so this should not reside inpci.cbut inpci-pc.c
Quoted 7 lines
We might be able to unify this - I've had a similar patch here:
https://patchwork.kernel.org/patch/9905031/
... but I think this needs some more careful thinking and discussion, so I'd suggest that you remove this from your already huge patch series for now and we fix it later instead.
Okay, I'm fine dropping this patch, and can base my respin on top of your cleanup instead.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v7 10/38] libqos: Move/rename qpci_unplug_acpi_device_test() to pci.c
Quoted 17 lines · Eric Blake
Quoted 16 lines · Thomas Huth
Quoted 8 lines · Eric Blake
Commit
2f8b2767originally addedqpci_plug_device_test()andqpci_unplug_acpi_device_test()as a pair, both inpci-pc.c. Later, commitcf716b31moved one half of the pair topci.cwhen adding PPC64 support. Keep the implementations of the two functions together, and shorten the name toqpci_unplug_device_test(), since all callers use the two functions in tandem.No, that's a bad idea. ACPI and that
outb()is clearly something specific to x86, so this should not reside inpci.cbut inpci-pc.cWe might be able to unify this - I've had a similar patch here:
Quoted 8 lines
Quoted 5 lines
https://patchwork.kernel.org/patch/9905031/
... but I think this needs some more careful thinking and discussion, so I'd suggest that you remove this from your already huge patch series for now and we fix it later instead.
Okay, I'm fine dropping this patch, and can base my respin on top of your cleanup instead.
Note that my patches are currently on halt since I'm waiting for your qemu_startf() reworks to get included first :-) ... so feel free to pick up ideas or patches from my series into your series if that helps.
Thomas
PATCH v7 11/38 libqos: Use explicit QTestState for pci operations
In reply to Eric BlakeNow that the QPCIBus tracks QTestState, use that state instead of an implicit reliance on global_qtest.
Pass an explicit QTestState to the remaining few functions in the same file that don't have direct access to QPCIBus, and update all callers.
---
v7: more sites with explicit state, drop R-b
--- tests/libqos/pci.h | 4 ++-- tests/e1000e-test.c | 4 ++-- tests/ivshmem-test.c | 4 ++-- tests/libqos/pci-pc.c | 47 ++++++++++++++++++++++++----------------------- tests/libqos/pci-spapr.c | 20 ++++++++++---------- tests/libqos/pci.c | 19 +++++++------------ tests/virtio-blk-test.c | 4 ++-- tests/virtio-net-test.c | 5 +++-- tests/virtio-rng-test.c | 5 +++-- 9 files changed, 55 insertions(+), 57 deletions(-)
tests/libqos/pci.h +2 -2
@@ -109,7 +109,7 @@ QPCIBar qpci_iomap(QPCIDevice *dev, int barno, uint64_t *sizeptr);void qpci_iounmap (QPCIDevice *dev,QPCIBar addr);QPCIBar qpci_legacy_iomap (QPCIDevice *dev,uint16_t addr); -void qpci_plug_device_test (const char *driver,const char *id, +void qpci_plug_device_test (QTestState *qts,const char *driver,const char *id,uint8_t slot,const char *opts); -void qpci_unplug_device_test (const char *id,uint8_t slot); +void qpci_unplug_device_test (QTestState *qts,const char *id,uint8_t slot);#endif
tests/e1000e-test.c +2 -2
@@ -460,8 +460,8 @@ static void test_e1000e_hotplug(gconstpointer data)qtest_start ("-device e1000e" ); -qpci_plug_device_test ("e1000e" ,"e1000e_net" , slot,NULL ); -qpci_unplug_device_test ("e1000e_net" , slot); +qpci_plug_device_test (global_qtest,"e1000e" ,"e1000e_net" , slot,NULL ); +qpci_unplug_device_test (global_qtest,"e1000e_net" , slot);qtest_end (); }
tests/ivshmem-test.c +2 -2
@@ -425,9 +425,9 @@ static void test_ivshmem_hotplug(void) opts =g_strdup_printf ("'shm': '%s', 'size': '1M'" , tmpshm); -qpci_plug_device_test ("ivshmem" ,"iv1" ,PCI_SLOT_HP , opts); +qpci_plug_device_test (global_qtest,"ivshmem" ,"iv1" ,PCI_SLOT_HP , opts);if (strcmp (arch,"ppc64" ) !=0 ) { -qpci_unplug_device_test ("iv1" ,PCI_SLOT_HP ); +qpci_unplug_device_test (global_qtest,"iv1" ,PCI_SLOT_HP ); }qtest_end ();
tests/libqos/pci-pc.c +24 -23
114 lines not on this page · raw message
tests/libqos/pci-spapr.c +10 -10
@@ -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)
tests/libqos/pci.c +7 -12
@@ -394,7 +394,7 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr)return bar; } -void qpci_plug_device_test (const char *driver,const char *id, +void qpci_plug_device_test (QTestState *qts,const char *driver,const char *id,uint8_t slot,const char *opts) {QDict *response;
@@ -409,29 +409,24 @@ void qpci_plug_device_test(const char *driver, const char *id,"}}" , driver, slot, opts ? opts :"" , opts ?"," :"" , id); - response =qmp (cmd); + response =qtest_qmp (qts, cmd);g_free (cmd);g_assert (response);g_assert (!qdict_haskey (response,"error" ));QDECREF (response); } -void qpci_unplug_device_test (const char *id,uint8_t slot) +void qpci_unplug_device_test (QTestState *qts,const char *id,uint8_t slot) {QDict *response; -char *cmd; - cmd =g_strdup_printf ("{'execute': 'device_del'," -" 'arguments': {" -" 'id': '%s'" -"}}" , id); - response =qmp (cmd); -g_free (cmd); + response =qtest_qmp (qts,"{'execute': 'device_del'," +" 'arguments': { 'id': %s }}" , id);g_assert (response);g_assert (!qdict_haskey (response,"error" ));QDECREF (response); -outb (ACPI_PCIHP_ADDR +PCI_EJ_BASE ,1 << slot); +qtest_outb (qts,ACPI_PCIHP_ADDR +PCI_EJ_BASE ,1 << slot); -qmp_eventwait ("DEVICE_DELETED" ); +qtest_qmp_eventwait (qts,"DEVICE_DELETED" ); }
tests/virtio-blk-test.c +2 -2
@@ -662,7 +662,7 @@ static void pci_hotplug(void) qs =pci_test_start ();/* plug secondary disk */ -qpci_plug_device_test ("virtio-blk-pci" ,"drv1" ,PCI_SLOT_HP , +qpci_plug_device_test (global_qtest,"virtio-blk-pci" ,"drv1" ,PCI_SLOT_HP ,"'drive': 'drive1'" ); dev =virtio_blk_pci_init (qs->pcibus,PCI_SLOT_HP );
@@ -672,7 +672,7 @@ static void pci_hotplug(void)/* unplug secondary disk */ if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) { -qpci_unplug_device_test ("drv1" ,PCI_SLOT_HP ); +qpci_unplug_device_test (global_qtest,"drv1" ,PCI_SLOT_HP ); }qtest_shutdown (qs); }
tests/virtio-net-test.c +3 -2
@@ -245,10 +245,11 @@ static void hotplug(void)qtest_start ("-device virtio-net-pci" ); -qpci_plug_device_test ("virtio-net-pci" ,"net1" ,PCI_SLOT_HP ,NULL ); +qpci_plug_device_test (global_qtest,"virtio-net-pci" ,"net1" , +PCI_SLOT_HP ,NULL );if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) { -qpci_unplug_device_test ("net1" ,PCI_SLOT_HP ); +qpci_unplug_device_test (global_qtest,"net1" ,PCI_SLOT_HP ); }test_end ();
tests/virtio-rng-test.c +3 -2
@@ -22,10 +22,11 @@ static void hotplug(void) {const char *arch =qtest_get_arch (); -qpci_plug_device_test ("virtio-rng-pci" ,"rng1" ,PCI_SLOT_HP ,NULL ); +qpci_plug_device_test (global_qtest,"virtio-rng-pci" ,"rng1" , +PCI_SLOT_HP ,NULL );if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) { -qpci_unplug_device_test ("rng1" ,PCI_SLOT_HP ); +qpci_unplug_device_test (global_qtest,"rng1" ,PCI_SLOT_HP ); } }
Signature · 1 line
2.13.5
PATCH v7 12/38 libqos: Use explicit QTestState for virtio operations
In reply to Eric BlakeNow that QVirtioDevice and QVirtQueue point back to QVirtioBus, we can reuse the explicit QTestState stored there rather than relying on implicit global_qtest. We also have to pass QTestState through a few functions that can't trace back through QVirtioDevice, and update those callers.
Drop some useless casts while touching things.
--- tests/libqos/virtio.h | 6 ++-- tests/libqos/virtio-mmio.c | 57 ++++++++++++++++++------------- tests/libqos/virtio-pci.c | 8 ++--- tests/libqos/virtio.c | 84 ++++++++++++++++++++++++++-------------------- tests/virtio-blk-test.c | 11 +++--- 5 files changed, 94 insertions(+), 72 deletions(-)
tests/libqos/virtio.h +3 -3
@@ -96,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->bus->qts); }static inline uint32_t qvring_size (uint32_t num,uint32_t align)
@@ -139,8 +139,8 @@ void qvirtqueue_cleanup(const QVirtioBus *bus, QVirtQueue *vq,void qvring_init (const QGuestAllocator *alloc,QVirtQueue *vq,uint64_t addr);QVRingIndirectDesc *qvring_indirect_desc_setup (QVirtioDevice *d,QGuestAllocator *alloc,uint16_t elem); -void qvring_indirect_desc_add (QVRingIndirectDesc *indirect,uint64_t data, -uint32_t len,bool write); +void qvring_indirect_desc_add (QTestState *qts,QVRingIndirectDesc *indirect, +uint64_t data,uint32_t len,bool write);uint32_t qvirtqueue_add (QVirtQueue *vq,uint64_t data,uint32_t len,bool write,bool next);uint32_t qvirtqueue_add_indirect (QVirtQueue *vq,QVRingIndirectDesc *indirect);
tests/libqos/virtio-mmio.c +33 -24
161 lines not on this page · raw message
tests/libqos/virtio-pci.c +4 -4
@@ -168,9 +168,9 @@ static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)/* No ISR checking should be done if masked, but read anyway */ return qpci_msix_pending (dev->pdev, vqpci->msix_entry); }else { - data =readl (vqpci->msix_addr); + data =qtest_readl (d->bus->qts, vqpci->msix_addr);if (data == vqpci->msix_data) { -writel (vqpci->msix_addr,0 ); +qtest_writel (d->bus->qts, vqpci->msix_addr,0 );return true; }else {return false;
@@ -192,9 +192,9 @@ static bool qvirtio_pci_get_config_isr_status(QVirtioDevice *d)/* No ISR checking should be done if masked, but read anyway */ return qpci_msix_pending (dev->pdev, dev->config_msix_entry); }else { - data =readl (dev->config_msix_addr); + data =qtest_readl (d->bus->qts, dev->config_msix_addr);if (data == dev->config_msix_data) { -writel (dev->config_msix_addr,0 ); +qtest_writel (d->bus->qts, dev->config_msix_addr,0 );return true; }else {return false;
tests/libqos/virtio.c +47 -37
196 lines not on this page · raw message
tests/virtio-blk-test.c +7 -4
@@ -343,8 +343,10 @@ static void pci_indirect(void)g_free (req.data); indirect =qvring_indirect_desc_setup (&dev->vdev, qs->alloc,2 ); -qvring_indirect_desc_add (indirect, req_addr,528 , false); -qvring_indirect_desc_add (indirect, req_addr +528 ,1 , true); +qvring_indirect_desc_add (dev->vdev.bus->qts, indirect, req_addr,528 , + false); +qvring_indirect_desc_add (dev->vdev.bus->qts, indirect, req_addr +528 ,1 , + true); free_head =qvirtqueue_add_indirect (&vqpci->vq, indirect);qvirtqueue_kick (&dev->vdev, &vqpci->vq, free_head);
@@ -368,8 +370,9 @@ static void pci_indirect(void)g_free (req.data); indirect =qvring_indirect_desc_setup (&dev->vdev, qs->alloc,2 ); -qvring_indirect_desc_add (indirect, req_addr,16 , false); -qvring_indirect_desc_add (indirect, req_addr +16 ,513 , true); +qvring_indirect_desc_add (dev->vdev.bus->qts, indirect, req_addr,16 , false); +qvring_indirect_desc_add (dev->vdev.bus->qts, indirect, req_addr +16 ,513 , + true); free_head =qvirtqueue_add_indirect (&vqpci->vq, indirect);qvirtqueue_kick (&dev->vdev, &vqpci->vq, free_head);
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PATCH v7 12/38] libqos: Use explicit QTestState for virtio operations
Quoted 8 lines · Eric Blake
Now that QVirtioDevice and QVirtQueue point back to QVirtioBus, we can reuse the explicit QTestState stored there rather than relying on implicit
global_qtest. We also have to pass QTestState through a few functions that can't trace back through QVirtioDevice, and update those callers.Drop some useless casts while touching things.
Quoted 8 lines
Signed-off-by Eric Blake <[email protected]>--- tests/libqos/virtio.h | 6 ++-- tests/libqos/virtio-mmio.c | 57 ++++++++++++++++++------------- tests/libqos/virtio-pci.c | 8 ++--- tests/libqos/virtio.c | 84 ++++++++++++++++++++++++++-------------------- tests/virtio-blk-test.c | 11 +++--- 5 files changed, 94 insertions(+), 72 deletions(-)
PATCH v7 13/38 libqos: Use explicit QTestState for fw_cfg operations
In reply to Eric BlakeDrop 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 (and drop a pointless strdup in the meantime), but that test now no longer depends on global_qtest.
---
v7: squash in typedef fixup as well as fw_cfg-test cleanup
--- 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 | 13 ++++--------- 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, 36 insertions(+), 36 deletions(-)
tests/libqos/fw_cfg.h +6 -4
@@ -13,12 +13,14 @@#ifndef LIBQOS_FW_CFG_H #define LIBQOS_FW_CFG_H +#include "libqtest.h" typedef struct QFWCFG QFWCFG ;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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 +4 -9
@@ -102,12 +102,13 @@ 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 ); - fw_cfg =pc_fw_cfg_init (); + s =qtest_init ("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8" ); + + 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 +126,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
@@ -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
@@ -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
@@ -23,7 +23,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap) qs->qts =qtest_start (cmdline); qs->ops = ops;if (ops) { - qs->alloc = ops->init_allocator (ALLOC_NO_FLAGS ); + qs->alloc = ops->init_allocator (qs->qts,ALLOC_NO_FLAGS ); qs->pcibus = ops->qpci_init (qs->qts, qs->alloc); }
tests/libqos/malloc-pc.c +4 -4
@@ -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
@@ -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
@@ -896,7 +896,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
Re: [Qemu-devel] [PATCH v7 13/38] libqos: Use explicit QTestState for fw_cfg operations
Quoted 9 lines · Eric Blake
Drop one more client of
global_qtestby teaching allfw_cfgtest 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 thefw_cfg(and drop a pointless strdup in the meantime), but that test now no longer depends onglobal_qtest.Signed-off-by Eric Blake <[email protected]>
Re: [Qemu-devel] [PATCH v7 13/38] libqos: Use explicit QTestState for fw_cfg operations
In reply to Eric BlakeQuoted 8 lines · Eric Blake
Drop one more client of
global_qtestby teaching allfw_cfgtest 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 thefw_cfg(and drop a pointless strdup in the meantime), but that test now no longer depends onglobal_qtest.Signed-off-by Eric Blake <[email protected]>
PATCH v7 14/38 libqos: Use explicit QTestState for rtas operations
In reply to Eric BlakeDrop one more client of global_qtest by teaching all rtas test functionality to pass in an explicit QTestState, adjusting all callers.
---
v7: catch a couple more operations, drop R-b
--- tests/libqos/rtas.h | 9 ++++++--- tests/libqos/pci-spapr.c | 18 ++++++++++++------ tests/libqos/rtas.c | 36 ++++++++++++++++++++---------------- tests/rtas-test.c | 2 +- 4 files changed, 39 insertions(+), 26 deletions(-)
tests/libqos/rtas.h +6 -3
@@ -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
@@ -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 +20 -16
@@ -7,26 +7,28 @@#include "libqtest.h" #include "libqos/rtas.h" -static void qrtas_copy_args (uint64_t target_args,uint32_t nargs, -uint32_t *args) +static void qrtas_copy_args (QTestState *qts,uint64_t target_args, +uint32_t nargs,uint32_t *args) {int i;for (i =0 ; i < nargs; i++) { -writel (target_args + i *sizeof (uint32_t ), args[i]); +qtest_writel (qts, target_args + i *sizeof (uint32_t ), args[i]); } } -static void qrtas_copy_ret (uint64_t target_ret,uint32_t nret,uint32_t *ret) +static void qrtas_copy_ret (QTestState *qts,uint64_t target_ret, +uint32_t nret,uint32_t *ret) {int i;for (i =0 ; i < nret; i++) { - ret[i] =readl (target_ret + i *sizeof (uint32_t )); + ret[i] =qtest_readl (qts, target_ret + i *sizeof (uint32_t )); } } -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) {
@@ -36,10 +38,9 @@ static uint64_t qrtas_call(QGuestAllocator *alloc, const char *name, target_args =guest_alloc (alloc, nargs *sizeof (uint32_t )); 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); -qrtas_copy_ret (target_ret, nret, ret); +qrtas_copy_args (qts, target_args, nargs, args); + res =qtest_rtas_call (qts, name, nargs, target_args, nret, target_ret); +qrtas_copy_ret (qts, target_ret, nret, ret);guest_free (alloc, target_ret);guest_free (alloc, target_args);
@@ -47,12 +48,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 +72,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 +83,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 +95,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 +107,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
@@ -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
Re: [Qemu-devel] [PATCH v7 14/38] libqos: Use explicit QTestState for rtas operations
Quoted 24 lines · Eric Blake
Drop one more client of
global_qtestby teaching all rtas test functionality to pass in an explicit QTestState, adjusting all callers.Signed-off-by Eric Blake <[email protected]>---
v7: catch a couple more operations, drop R-b--- tests/libqos/rtas.h | 9 ++++++--- tests/libqos/pci-spapr.c | 18 ++++++++++++------ tests/libqos/rtas.c | 36 ++++++++++++++++++++---------------- tests/rtas-test.c | 2 +- 4 files changed, 39 insertions(+), 26 deletions(-)tests/libqos/rtas.h +0
-1@@ -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);
tests/libqos/rtas.h line 17
Quoted 10 lines
tests/libqos/rtas.h +6
-2-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);
Nit: I'd prefer if you rather put hte "uint32_t val" on a separate line instead of the "buid".
[...]
tests/libqos/rtas.h uint32_t qrtas_ibm_read_pci_config(QGuestAllocator *alloc, uint64_t buid, · line 100
Quoted 8 lines
tests/libqos/rtas.h +2
-1@@ -92,7 +95,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)
dito
Quoted 17 lines
tests/libqos/rtas.h +1
-1{int res;@@ -103,7 +107,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
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 */
PATCH v7 15/38 libqos: Use explicit QTestState for i2c operations
In reply to Eric BlakeDrop one more client of global_qtest by teaching all i2c test functionality to pass in an explicit QTestState, adjusting all callers.
--- tests/libqos/i2c.h | 7 ++++-- tests/ds1338-test.c | 6 ++--- tests/libqos/i2c-imx.c | 67 +++++++++++++++++++++++++------------------------ tests/libqos/i2c-omap.c | 45 +++++++++++++++++---------------- tests/tmp105-test.c | 6 ++--- 5 files changed, 66 insertions(+), 65 deletions(-)
tests/libqos/i2c.h +5 -2
@@ -9,6 +9,7 @@#ifndef LIBQOS_I2C_H #define LIBQOS_I2C_H +#include "libqtest.h" typedef struct I2CAdapter I2CAdapter ; struct I2CAdapter {
@@ -16,6 +17,8 @@ struct I2CAdapter { const uint8_t *buf, uint16_t len);void (*recv)(I2CAdapter *adapter,uint8_t addr,uint8_t *buf,uint16_t len); + +QTestState *qts; }; void i2c_send(I2CAdapter *i2c, uint8_t addr,
@@ -24,9 +27,9 @@ void i2c_recv(I2CAdapter *i2c, uint8_t addr, uint8_t *buf, uint16_t len);/* libi2c-omap.c */ -I2CAdapter *omap_i2c_create (uint64_t addr); +I2CAdapter *omap_i2c_create (QTestState *qts,uint64_t addr);/* libi2c-imx.c */ -I2CAdapter *imx_i2c_create (uint64_t addr); +I2CAdapter *imx_i2c_create (QTestState *qts,uint64_t addr);#endif
tests/ds1338-test.c +2 -4
@@ -61,16 +61,14 @@ int main(int argc, char **argv)g_test_init (&argc, &argv,NULL ); s =qtest_start ("-display none -machine imx25-pdk" ); - i2c =imx_i2c_create (IMX25_I2C_0_BASE ); + i2c =imx_i2c_create (s,IMX25_I2C_0_BASE ); addr =DS1338_ADDR ;qtest_add_func ("/ds1338/tx-rx" , send_and_receive); ret =g_test_run (); -if (s) { -qtest_quit (s); - } +qtest_quit (s);g_free (i2c);return ret;
tests/libqos/i2c-imx.c +34 -33
163 lines not on this page · raw message
tests/libqos/i2c-omap.c +23 -22
119 lines not on this page · raw message
tests/tmp105-test.c +2 -4
@@ -154,15 +154,13 @@ int main(int argc, char **argv) s =qtest_start ("-machine n800 " "-device tmp105,bus=i2c-bus.0,id=" TMP105_TEST_ID ",address=0x49" ); - i2c =omap_i2c_create (OMAP2_I2C_1_BASE ); + i2c =omap_i2c_create (s,OMAP2_I2C_1_BASE );qtest_add_func ("/tmp105/tx-rx" , send_and_receive); ret =g_test_run (); -if (s) { -qtest_quit (s); - } +qtest_quit (s);g_free (i2c);return ret;
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PATCH v7 15/38] libqos: Use explicit QTestState for i2c operations
Quoted 4 lines · Eric Blake
Drop one more client of
global_qtestby teaching all i2c test functionality to pass in an explicit QTestState, adjusting all callers.
Quoted 8 lines
Signed-off-by Eric Blake <[email protected]>--- tests/libqos/i2c.h | 7 ++++-- tests/ds1338-test.c | 6 ++--- tests/libqos/i2c-imx.c | 67 +++++++++++++++++++++++++------------------------ tests/libqos/i2c-omap.c | 45 +++++++++++++++++---------------- tests/tmp105-test.c | 6 ++--- 5 files changed, 66 insertions(+), 65 deletions(-)
PATCH v7 16/38 libqos: Use explicit QTestState for ahci operations
In reply to Eric BlakeDrop one more client of global_qtest by teaching all ahci test functionality to pass in an explicit QTestState. The state was already available, so no callers had to be adjusted.
---
v7: split libqos changes from test-ahci
--- tests/libqos/ahci.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-)
tests/libqos/ahci.c +23 -22
@@ -283,7 +283,8 @@ void ahci_hba_enable(AHCIQState *ahci)/* Allocate Memory for the Command List Buffer & FIS Buffer */ /* PxCLB space ... 0x20 per command, as in 4.2.2 p 36 */ ahci->port[i].clb =ahci_alloc (ahci, num_cmd_slots *0x20 ); -qmemset (ahci->port[i].clb,0x00 , num_cmd_slots *0x20 ); +qtest_memset (ahci->parent->qts, ahci->port[i].clb,0x00 , + num_cmd_slots *0x20 );g_test_message ("CLB: 0x%08" PRIx64, ahci->port[i].clb);ahci_px_wreg (ahci, i,AHCI_PX_CLB , ahci->port[i].clb); g_assert_cmphex(ahci->port[i].clb, ==,
@@ -291,7 +292,7 @@ void ahci_hba_enable(AHCIQState *ahci)/* PxFB space ... 0x100, as in 4.2.1 p 35 */ ahci->port[i].fb =ahci_alloc (ahci,0x100 ); -qmemset (ahci->port[i].fb,0x00 ,0x100 ); +qtest_memset (ahci->parent->qts, ahci->port[i].fb,0x00 ,0x100 );g_test_message ("FB: 0x%08" PRIx64, ahci->port[i].fb);ahci_px_wreg (ahci, i,AHCI_PX_FB , ahci->port[i].fb); g_assert_cmphex(ahci->port[i].fb, ==,
@@ -397,7 +398,7 @@ void ahci_port_clear(AHCIQState *ahci, uint8_t port) g_assert_cmphex(ahci_px_rreg(ahci, port, AHCI_PX_IS), ==, 0);/* Wipe the FIS-Receive Buffer */ -qmemset (ahci->port[port].fb,0x00 ,0x100 ); +qtest_memset (ahci->parent->qts, ahci->port[port].fb,0x00 ,0x100 ); }/**
@@ -466,7 +467,7 @@ void ahci_port_check_d2h_sanity(AHCIQState *ahci, uint8_t port, uint8_t slot)RegD2HFIS *d2h =g_malloc0 (0x20 );uint32_t reg; -memread (ahci->port[port].fb +0x40 , d2h,0x20 ); +qtest_memread (ahci->parent->qts, ahci->port[port].fb +0x40 , d2h,0x20 ); g_assert_cmphex(d2h->fis_type, ==, 0x34); reg =ahci_px_rreg (ahci, port,AHCI_PX_TFD );
@@ -484,7 +485,7 @@ void ahci_port_check_pio_sanity(AHCIQState *ahci, uint8_t port,/* We cannot check the Status or E_Status registers, because * the status may have again changed between the PIO Setup FIS * and the conclusion of the command with the D2H Register FIS. */ -memread (ahci->port[port].fb +0x20 , pio,0x20 ); +qtest_memread (ahci->parent->qts, ahci->port[port].fb +0x20 , pio,0x20 ); g_assert_cmphex(pio->fis_type, ==, 0x5f);/* BUG: PIO Setup FIS as utilized by QEMU tries to fit the entire
@@ -516,7 +517,7 @@ void ahci_get_command_header(AHCIQState *ahci, uint8_t port, {uint64_t ba = ahci->port[port].clb; ba += slot *sizeof (AHCICommandHeader); -memread (ba, cmd,sizeof (AHCICommandHeader)); +qtest_memread (ahci->parent->qts, ba, cmd,sizeof (AHCICommandHeader)); cmd->flags =le16_to_cpu (cmd->flags); cmd->prdtl =le16_to_cpu (cmd->prdtl);
@@ -537,7 +538,7 @@ void ahci_set_command_header(AHCIQState *ahci, uint8_t port, tmp.prdbc =cpu_to_le32 (cmd->prdbc); tmp.ctba =cpu_to_le64 (cmd->ctba); -memwrite (ba, &tmp,sizeof (AHCICommandHeader)); +qtest_memwrite (ahci->parent->qts, ba, &tmp,sizeof (AHCICommandHeader)); }void ahci_destroy_command (AHCIQState *ahci,uint8_t port,uint8_t slot)
@@ -575,7 +576,7 @@ void ahci_write_fis(AHCIQState *ahci, AHCICommand *cmd) tmp.count =cpu_to_le16 (tmp.count); } -memwrite (addr, &tmp,sizeof (tmp)); +qtest_memwrite (ahci->parent->qts, addr, &tmp,sizeof (tmp)); }unsigned ahci_pick_cmd (AHCIQState *ahci,uint8_t port)
@@ -636,7 +637,7 @@ void ahci_exec(AHCIQState *ahci, uint8_t port,if (opts->size && !opts->buffer) { opts->buffer =ahci_alloc (ahci, opts->size);g_assert (opts->buffer); -qmemset (opts->buffer,0x00 , opts->size); +qtest_memset (ahci->parent->qts, opts->buffer,0x00 , opts->size); }/* Command creation */
@@ -661,15 +662,15 @@ void ahci_exec(AHCIQState *ahci, uint8_t port,ahci_command_commit (ahci, cmd, port);ahci_command_issue_async (ahci, cmd);if (opts->error) { -qmp_eventwait ("STOP" ); +qtest_qmp_eventwait (ahci->parent->qts,"STOP" ); }if (opts->mid_cb) { rc = opts->mid_cb (ahci, cmd, opts); g_assert_cmpint(rc, ==, 0); }if (opts->error) { -qmp_async ("{'execute':'cont' }" ); -qmp_eventwait ("RESUME" ); +qtest_async_qmp (ahci->parent->qts,"{'execute':'cont' }" ); +qtest_qmp_eventwait (ahci->parent->qts,"RESUME" ); }/* Wait for command to complete and verify sanity */
@@ -697,7 +698,7 @@ AHCICommand *ahci_guest_io_halt(AHCIQState *ahci, uint8_t port,ahci_command_adjust (cmd, sector, buffer, bufsize,0 );ahci_command_commit (ahci, cmd, port);ahci_command_issue_async (ahci, cmd); -qmp_eventwait ("STOP" ); +qtest_qmp_eventwait (ahci->parent->qts,"STOP" );return cmd; }
@@ -706,8 +707,8 @@ AHCICommand *ahci_guest_io_halt(AHCIQState *ahci, uint8_t port,void ahci_guest_io_resume (AHCIQState *ahci,AHCICommand *cmd) {/* Complete the command */ -qmp_async ("{'execute':'cont' }" ); -qmp_eventwait ("RESUME" ); +qtest_async_qmp (ahci->parent->qts,"{'execute':'cont' }" ); +qtest_qmp_eventwait (ahci->parent->qts,"RESUME" );ahci_command_wait (ahci, cmd);ahci_command_verify (ahci, cmd);ahci_command_free (cmd);
@@ -754,16 +755,16 @@ void ahci_io(AHCIQState *ahci, uint8_t port, uint8_t ide_cmd,g_assert (props); ptr =ahci_alloc (ahci, bufsize);g_assert (!bufsize || ptr); -qmemset (ptr,0x00 , bufsize); +qtest_memset (ahci->parent->qts, ptr,0x00 , bufsize);if (bufsize && props->write) { -bufwrite (ptr, buffer, bufsize); +qtest_bufwrite (ahci->parent->qts, ptr, buffer, bufsize); }ahci_guest_io (ahci, port, ide_cmd, ptr, bufsize, sector);if (bufsize && props->read) { -bufread (ptr, buffer, bufsize); +qtest_bufread (ahci->parent->qts, ptr, buffer, bufsize); }ahci_free (ahci, ptr);
@@ -901,7 +902,7 @@ static int copy_buffer(AHCIQState *ahci, AHCICommand *cmd, const AHCIOpts *opts) {unsigned char *rx = opts->opaque; -bufread (opts->buffer, rx, opts->size); +qtest_bufread (ahci->parent->qts, opts->buffer, rx, opts->size);return 0 ; }
@@ -1141,7 +1142,7 @@ void ahci_command_commit(AHCIQState *ahci, AHCICommand *cmd, uint8_t port)ahci_write_fis (ahci, cmd);/* Then ATAPI CMD, if needed */ if (cmd->props->atapi) { -memwrite (table_ptr +0x40 , cmd->atapi_cmd,16 ); +qtest_memwrite (ahci->parent->qts, table_ptr +0x40 , cmd->atapi_cmd,16 ); }/* Construct and write the PRDs to the command table */
@@ -1162,8 +1163,8 @@ void ahci_command_commit(AHCIQState *ahci, AHCICommand *cmd, uint8_t port) prd.dbc |=cpu_to_le32 (0x80000000 );/* Request DPS Interrupt */ /* Commit the PRD entry to the Command Table */ -memwrite (table_ptr +0x80 + (i *sizeof (PRD )), - &prd,sizeof (PRD )); +qtest_memwrite (ahci->parent->qts, table_ptr +0x80 + (i *sizeof (PRD )), + &prd,sizeof (PRD )); }/* Bookmark the PRDTL and CTBA values */
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PATCH v7 16/38] libqos: Use explicit QTestState for ahci operations
Quoted 5 lines · Eric Blake
Drop one more client of
global_qtestby teaching all ahci test functionality to pass in an explicit QTestState. The state was already available, so no callers had to be adjusted.Signed-off-by Eric Blake <[email protected]>
I should admit that this makes my urge to write a wrapper/macro increase just a little bit, but ... admitting you have a problem is the first step to recovery.
Re: [Qemu-devel] [PATCH v7 16/38] libqos: Use explicit QTestState for ahci operations
In reply to Eric BlakeQuoted 5 lines · Eric Blake
Drop one more client of
global_qtestby teaching all ahci test functionality to pass in an explicit QTestState. The state was already available, so no callers had to be adjusted.Signed-off-by Eric Blake <[email protected]>
PATCH v7 17/38 libqos: Use explicit QTestState for remaining libqos operations
In reply to Eric BlakeDrop one more client of global_qtest by teaching all remaining libqos stragglers to pass in an explicit QTestState. Change the setting of global_qtest from being implicit in libqos' call to qtest_start() to instead be explicit in all clients that are still relying on global_qtest.
Note that qmp_execute() can be greatly simplified in the process, and that we also get rid of interpolation of a JSON string into a temporary variable when qtest_qmp() can do it more reliably.
---
v7: split libqos changes from test-ahci, catch more spots
--- tests/ahci-test.c | 1 + tests/ivshmem-test.c | 1 + tests/libqos/libqos-pc.c | 2 +- tests/libqos/libqos.c | 30 ++++++++++-------------------- tests/megasas-test.c | 5 ++++- tests/rtas-test.c | 1 + tests/usb-hcd-uhci-test.c | 1 + tests/virtio-9p-test.c | 1 + tests/virtio-blk-test.c | 1 + tests/virtio-net-test.c | 15 +++++++++------ tests/virtio-scsi-test.c | 16 +++++++++------- 11 files changed, 39 insertions(+), 35 deletions(-)
tests/ahci-test.c +1 -0
@@ -157,6 +157,7 @@ static AHCIQState *ahci_vboot(const char *cli, va_list ap) s =g_malloc0 (sizeof (AHCIQState)); s->parent =qtest_pc_vboot (cli, ap); + global_qtest = s->parent->qts;alloc_set_flags (s->parent->alloc,ALLOC_LEAK_ASSERT );/* Verify that we have an AHCI device present. */
tests/ivshmem-test.c +1 -0
@@ -131,6 +131,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 = s->qs->qts; s->dev =get_device (s->qs->pcibus); s->reg_bar =qpci_iomap (s->dev,0 , &barsize);
tests/libqos/libqos-pc.c +1 -1
@@ -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 +10 -20
@@ -20,7 +20,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)QOSState *qs =g_new0 (QOSState,1 ); cmdline =g_strdup_vprintf (cmdline_fmt, ap); - qs->qts =qtest_start (cmdline); + qs->qts =qtest_init (cmdline); qs->ops = ops;if (ops) { qs->alloc = ops->init_allocator (qs->qts,ALLOC_NO_FLAGS );
@@ -80,29 +80,21 @@ void set_context(QOSState *s) global_qtest = s->qts; } -static QDict *qmp_execute (const char *command) +static QDict *qmp_execute (QTestState *qts,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" ));
@@ -110,30 +102,28 @@ 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" ));
tests/megasas-test.c +4 -1
@@ -15,13 +15,16 @@static QOSState *qmegasas_start (const char *extra_opts) { +QOSState *qs;const char *arch =qtest_get_arch ();const char *cmd ="-drive id=hd0,if=none,file=null-co://,format=raw " "-device megasas,id=scsi0,addr=04.0 " "-device scsi-hd,bus=scsi0.0,drive=hd0 %s" ;if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) { -return qtest_pc_boot (cmd, extra_opts ? :"" ); + qs =qtest_pc_boot (cmd, extra_opts ? :"" ); + global_qtest = qs->qts; +return qs; }g_printerr ("virtio-scsi tests are only available on x86 or ppc64\n" );
tests/rtas-test.c +1 -0
@@ -14,6 +14,7 @@ static void test_rtas_get_time_of_day(void)time_t t1, t2; qs =qtest_spapr_boot ("-machine pseries" ); + global_qtest = qs->qts; t1 =time (NULL ); ret =qrtas_get_time_of_day (qs->qts, qs->alloc, &tm, &ns);
tests/usb-hcd-uhci-test.c +1 -0
@@ -95,6 +95,7 @@ int main(int argc, char **argv) "available on x86 or ppc64\n");exit (EXIT_FAILURE ); } + global_qtest = qs->qts; ret =g_test_run ();qtest_shutdown (qs);
tests/virtio-9p-test.c +1 -0
@@ -46,6 +46,7 @@ static QVirtIO9P *qvirtio_9p_start(const char *driver)g_printerr ("virtio-9p tests are only available on x86 or ppc64\n" );exit (EXIT_FAILURE ); } + global_qtest = v9p->qs->qts;return v9p; }
tests/virtio-blk-test.c +1 -0
@@ -77,6 +77,7 @@ static QOSState *pci_test_start(void)g_printerr ("virtio-blk tests are only available on x86 or ppc64\n" );exit (EXIT_FAILURE ); } + global_qtest = qs->qts;unlink (tmp_path);g_free (tmp_path);return qs;
tests/virtio-net-test.c +9 -6
@@ -53,18 +53,21 @@ static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot)static QOSState *pci_test_start (int socket) { +QOSState *qs;const char *arch =qtest_get_arch ();const char *cmd ="-netdev socket,fd=%d,id=hs0 -device " "virtio-net-pci,netdev=hs0" ;if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) { -return qtest_pc_boot (cmd, socket); + qs =qtest_pc_boot (cmd, socket); + }else if (strcmp (arch,"ppc64" ) ==0 ) { + qs =qtest_spapr_boot (cmd, socket); + }else { +g_printerr ("virtio-net tests are only available on x86 or ppc64\n" ); +exit (EXIT_FAILURE ); } -if (strcmp (arch,"ppc64" ) ==0 ) { -return qtest_spapr_boot (cmd, socket); - } -g_printerr ("virtio-net tests are only available on x86 or ppc64\n" ); -exit (EXIT_FAILURE ); + global_qtest = qs->qts; +return qs; }static void driver_init (QVirtioDevice *dev)
tests/virtio-scsi-test.c +9 -7
@@ -34,20 +34,22 @@ typedef struct {static QOSState *qvirtio_scsi_start (const char *extra_opts) { +QOSState *qs;const char *arch =qtest_get_arch ();const char *cmd ="-drive id=drv0,if=none,file=null-co://,format=raw " "-device virtio-scsi-pci,id=vs0 " "-device scsi-hd,bus=vs0.0,drive=drv0 %s" ;if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) { -return qtest_pc_boot (cmd, extra_opts ? :"" ); + qs =qtest_pc_boot (cmd, extra_opts ? :"" ); + }else if (strcmp (arch,"ppc64" ) ==0 ) { + qs =qtest_spapr_boot (cmd, extra_opts ? :"" ); + }else { +g_printerr ("virtio-scsi tests are only available on x86 or ppc64\n" ); +exit (EXIT_FAILURE ); } -if (strcmp (arch,"ppc64" ) ==0 ) { -return qtest_spapr_boot (cmd, extra_opts ? :"" ); - } - -g_printerr ("virtio-scsi tests are only available on x86 or ppc64\n" ); -exit (EXIT_FAILURE ); + global_qtest = qs->qts; +return qs; }static void qvirtio_scsi_stop (QOSState *qs)
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PATCH v7 17/38] libqos: Use explicit QTestState for remaining libqos operations
Quoted 10 lines · On Mon, 11 Sep 2017 12:20:01 -0500 Eric Blake <[email protected]> wrote:
Drop one more client of
global_qtestby teaching all remaining libqos stragglers to pass in an explicit QTestState. Change the setting ofglobal_qtestfrom being implicit in libqos' call toqtest_start()to instead be explicit in all clients that are still relying onglobal_qtest.Note that
qmp_execute()can be greatly simplified in the process, and that we also get rid of interpolation of a JSON string into a temporary variable whenqtest_qmp()can do it more reliably.
Quoted 5 lines
Signed-off-by Eric Blake <[email protected]>---
v7: split libqos changes from test-ahci, catch more spots
---
For tests/virtio-9p-test.c.
Quoted 269 lines
tests/ahci-test.c | 1 + tests/ivshmem-test.c | 1 + tests/libqos/libqos-pc.c | 2 +- tests/libqos/libqos.c | 30 ++++++++++-------------------- tests/megasas-test.c | 5 ++++- tests/rtas-test.c | 1 + tests/usb-hcd-uhci-test.c | 1 + C | 1 + tests/virtio-blk-test.c | 1 + tests/virtio-net-test.c | 15 +++++++++------ tests/virtio-scsi-test.c | 16 +++++++++------- 11 files changed, 39 insertions(+), 35 deletions(-)tests/ahci-test.c +1
-0@@ -157,6 +157,7 @@ static AHCIQState *ahci_vboot(const char *cli, va_list ap) s =g_malloc0 (sizeof (AHCIQState)); s->parent =qtest_pc_vboot (cli, ap); + global_qtest = s->parent->qts;alloc_set_flags (s->parent->alloc,ALLOC_LEAK_ASSERT );/* Verify that we have an AHCI device present. */ tests/ivshmem-test.c +1
-0@@ -131,6 +131,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 = s->qs->qts; s->dev =get_device (s->qs->pcibus); s->reg_bar =qpci_iomap (s->dev,0 , &barsize);tests/libqos/libqos-pc.c +1
-1@@ -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 +10
-20@@ -20,7 +20,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)QOSState *qs =g_new0 (QOSState,1 ); cmdline =g_strdup_vprintf (cmdline_fmt, ap); - qs->qts =qtest_start (cmdline); + qs->qts =qtest_init (cmdline); qs->ops = ops;if (ops) { qs->alloc = ops->init_allocator (qs->qts,ALLOC_NO_FLAGS );@@ -80,29 +80,21 @@ void set_context(QOSState *s) global_qtest = s->qts; } -static QDict *qmp_execute (const char *command) +static QDict *qmp_execute (QTestState *qts,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" ));@@ -110,30 +102,28 @@ 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" ));tests/megasas-test.c +4
-1@@ -15,13 +15,16 @@static QOSState *qmegasas_start (const char *extra_opts) { +QOSState *qs;const char *arch =qtest_get_arch ();const char *cmd ="-drive id=hd0,if=none,file=null-co://,format=raw " "-device megasas,id=scsi0,addr=04.0 " "-device scsi-hd,bus=scsi0.0,drive=hd0 %s" ;if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) { -return qtest_pc_boot (cmd, extra_opts ? :"" ); + qs =qtest_pc_boot (cmd, extra_opts ? :"" ); + global_qtest = qs->qts; +return qs; }g_printerr ("virtio-scsi tests are only available on x86 or ppc64\n" );tests/rtas-test.c +1
-0@@ -14,6 +14,7 @@ static void test_rtas_get_time_of_day(void)time_t t1, t2; qs =qtest_spapr_boot ("-machine pseries" ); + global_qtest = qs->qts; t1 =time (NULL ); ret =qrtas_get_time_of_day (qs->qts, qs->alloc, &tm, &ns);tests/usb-hcd-uhci-test.c +1
-0@@ -95,6 +95,7 @@ int main(int argc, char **argv) "available on x86 or ppc64\n");exit (EXIT_FAILURE ); } + global_qtest = qs->qts; ret =g_test_run ();qtest_shutdown (qs);tests/virtio-9p-test.c +1
-0@@ -46,6 +46,7 @@ static QVirtIO9P *qvirtio_9p_start(const char *driver)g_printerr ("virtio-9p tests are only available on x86 or ppc64\n" );exit (EXIT_FAILURE ); } + global_qtest = v9p->qs->qts;return v9p; }tests/virtio-blk-test.c +1
-0@@ -77,6 +77,7 @@ static QOSState *pci_test_start(void)g_printerr ("virtio-blk tests are only available on x86 or ppc64\n" );exit (EXIT_FAILURE ); } + global_qtest = qs->qts;unlink (tmp_path);g_free (tmp_path);return qs;tests/virtio-net-test.c +9
-6@@ -53,18 +53,21 @@ static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot)static QOSState *pci_test_start (int socket) { +QOSState *qs;const char *arch =qtest_get_arch ();const char *cmd ="-netdev socket,fd=%d,id=hs0 -device " "virtio-net-pci,netdev=hs0" ;if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) { -return qtest_pc_boot (cmd, socket); + qs =qtest_pc_boot (cmd, socket); + }else if (strcmp (arch,"ppc64" ) ==0 ) { + qs =qtest_spapr_boot (cmd, socket); + }else { +g_printerr ("virtio-net tests are only available on x86 or ppc64\n" ); +exit (EXIT_FAILURE ); } -if (strcmp (arch,"ppc64" ) ==0 ) { -return qtest_spapr_boot (cmd, socket); - } -g_printerr ("virtio-net tests are only available on x86 or ppc64\n" ); -exit (EXIT_FAILURE ); + global_qtest = qs->qts; +return qs; }static void driver_init (QVirtioDevice *dev)tests/virtio-scsi-test.c +9
-7@@ -34,20 +34,22 @@ typedef struct {static QOSState *qvirtio_scsi_start (const char *extra_opts) { +QOSState *qs;const char *arch =qtest_get_arch ();const char *cmd ="-drive id=drv0,if=none,file=null-co://,format=raw " "-device virtio-scsi-pci,id=vs0 " "-device scsi-hd,bus=vs0.0,drive=drv0 %s" ;if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) { -return qtest_pc_boot (cmd, extra_opts ? :"" ); + qs =qtest_pc_boot (cmd, extra_opts ? :"" ); + }else if (strcmp (arch,"ppc64" ) ==0 ) { + qs =qtest_spapr_boot (cmd, extra_opts ? :"" ); + }else { +g_printerr ("virtio-scsi tests are only available on x86 or ppc64\n" ); +exit (EXIT_FAILURE ); } -if (strcmp (arch,"ppc64" ) ==0 ) { -return qtest_spapr_boot (cmd, extra_opts ? :"" ); - } - -g_printerr ("virtio-scsi tests are only available on x86 or ppc64\n" ); -exit (EXIT_FAILURE ); + global_qtest = qs->qts; +return qs; }static void qvirtio_scsi_stop (QOSState *qs)
Re: [Qemu-devel] [PATCH v7 17/38] libqos: Use explicit QTestState for remaining libqos operations
In reply to Eric BlakeQuoted 6 lines · Eric Blake
Drop one more client of
global_qtestby teaching all remaining libqos stragglers to pass in an explicit QTestState. Change the setting ofglobal_qtestfrom being implicit in libqos' call toqtest_start()to instead be explicit in all clients that are still relying onglobal_qtest.
Quoted 6 lines
Note that
qmp_execute()can be greatly simplified in the process, and that we also get rid of interpolation of a JSON string into a temporary variable whenqtest_qmp()can do it more reliably.Signed-off-by Eric Blake <[email protected]>
PATCH v7 18/38 ahci-test: Drop dependence on global_qtest
In reply to Eric BlakeManaging 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 was one spots that was creating a needless temporary variable to execute the 'cont' command, rather than just directly passing the literal command through qtest_qmp(). Fixing that gets us one step closer to enabling -Wformat checking on constructed JSON.
---
v7: split bulk of libqos changes into earlier patch
--- tests/libqos/libqos.h | 1 - tests/ahci-test.c | 83 ++++++++++++++++++++++++--------------------------- tests/libqos/libqos.c | 9 ------ 3 files changed, 39 insertions(+), 54 deletions(-)
tests/libqos/libqos.h +0 -1
@@ -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 +39 -44
218 lines not on this page · raw message
tests/libqos/libqos.c +0 -9
@@ -75,11 +75,6 @@ void qtest_shutdown(QOSState *qs) } } -void set_context (QOSState *s) -{ - global_qtest = s->qts; -} -static QDict *qmp_execute (QTestState *qts,const char *command) {return qtest_qmp (qts,"{ 'execute': %s }" , command);
@@ -91,8 +86,6 @@ void migrate(QOSState *from, QOSState *to, const char *uri)QDict *rsp, *sub;bool running; -set_context (from); -/* Is the machine currently running? */ rsp =qmp_execute (from->qts,"query-status" );g_assert (qdict_haskey (rsp,"return" ));
@@ -116,7 +109,6 @@ void migrate(QOSState *from, QOSState *to, const char *uri)/* If we were running, we can wait for an event. */ if (running) {migrate_allocator (from->alloc, to->alloc); -set_context (to);qtest_qmp_eventwait (to->qts,"RESUME" );return ; }
@@ -146,7 +138,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
Re: [Qemu-devel] [PATCH v7 18/38] ahci-test: Drop dependence on global_qtest
Quoted 16 lines · Eric Blake
Managing parallel connections to two different monitors via the implicit
global_qtestmakes it hard to copy-and-paste code to tests that are not aware of the implicit state; the management ofglobal_qtestis even harder to follow because it was masked behindset_context().Instead, explicitly pass QTestState* around (generally, by reusing the member already present in
ahci->parentQOSState), 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_qtestremains NULL throughout the test (a later patch that changesglobal_qtestto not be a public global variable will drop the assertions).
Quoted 7 lines
Bonus: there was one spots that was creating a needless temporary variable to execute the 'cont' command, rather than just directly passing the literal command through
qtest_qmp(). Fixing that gets us one step closer to enabling -Wformat checking on constructed JSON.Signed-off-by Eric Blake <[email protected]>
still LGTM, you can probably still see why I was a little iffy about making the global qstate ubiquitous instead of doing it this way.
(Though it does make the calls a little more verbose, they are IMO a lot easier to reason about in tests that deal with mixed-state and migrations and so on, which -- most of my qtest experience was from AHCI -- there is a lot of here. (Sorry Markus, I'm a
Re: [Qemu-devel] [PATCH v7 18/38] ahci-test: Drop dependence on global_qtest
Quoted 27 lines · John Snow
Quoted 16 lines · Eric Blake
Managing parallel connections to two different monitors via the implicit
global_qtestmakes it hard to copy-and-paste code to tests that are not aware of the implicit state; the management ofglobal_qtestis even harder to follow because it was masked behindset_context().Instead, explicitly pass QTestState* around (generally, by reusing the member already present in
ahci->parentQOSState), 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_qtestremains NULL throughout the test (a later patch that changesglobal_qtestto not be a public global variable will drop the assertions).Quoted 7 lines
Bonus: there was one spots that was creating a needless temporary variable to execute the 'cont' command, rather than just directly passing the literal command through
qtest_qmp(). Fixing that gets us one step closer to enabling -Wformat checking on constructed JSON.Signed-off-by Eric Blake <[email protected]>
Quoted 7 lines
still LGTM, you can probably still see why I was a little iffy about making the global qstate ubiquitous instead of doing it this way.
(Though it does make the calls a little more verbose, they are IMO a lot easier to reason about in tests that deal with mixed-state and migrations and so on, which -- most of my qtest experience was from AHCI -- there is a lot of here. (Sorry Markus, I'm a
lol! I hit send too soon, I tabbed away to look for Markus' previous email which used some German term to refer to people who preferred explicit state.
I wound up not finding it and then getting distracted.
Enjoy.
PATCH v7 19/38 ivshmem-test: Drop dependence on global_qtest
In reply to Eric BlakeManaging 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).
---
v7: fix a couple more spots
--- tests/ivshmem-test.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-)
tests/ivshmem-test.c +7 -21
@@ -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,7 +118,6 @@ 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 = s->qs->qts; s->dev =get_device (s->qs->pcibus); s->reg_bar =qpci_iomap (s->dev,0 , &barsize);
@@ -354,7 +340,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);
@@ -377,7 +362,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);
@@ -421,17 +405,19 @@ static void test_ivshmem_hotplug(void) {const char *arch =qtest_get_arch ();gchar *opts; +QTestState *qts; -qtest_start ("" ); + qts =qtest_init ("" ); opts =g_strdup_printf ("'shm': '%s', 'size': '1M'" , tmpshm); -qpci_plug_device_test (global_qtest,"ivshmem" ,"iv1" ,PCI_SLOT_HP , opts); +qpci_plug_device_test (qts,"ivshmem" ,"iv1" ,PCI_SLOT_HP , opts);if (strcmp (arch,"ppc64" ) !=0 ) { -qpci_unplug_device_test (global_qtest,"iv1" ,PCI_SLOT_HP ); +qpci_unplug_device_test (qts,"iv1" ,PCI_SLOT_HP ); } -qtest_end (); +assert (!global_qtest); +qtest_quit (qts);g_free (opts); }
Signature · 1 line
2.13.5
PATCH v7 20/38 postcopy-test: Drop dependence on global_qtest
In reply to Eric BlakeManaging 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
@@ -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
PATCH v7 21/38 vhost-user-test: Drop dependence on global_qtest
In reply to Eric BlakeManaging 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
@@ -141,6 +141,7 @@ enum { }; typedef struct TestServer { + QTestState *qts; QPCIBus *bus; gchar *socket_path; gchar *mig_path;
@@ -166,7 +167,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 );
@@ -238,8 +239,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); }
@@ -512,6 +516,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); }
@@ -623,7 +633,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;
@@ -634,7 +643,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);
@@ -643,7 +652,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,
@@ -654,16 +663,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);
@@ -678,28 +684,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)
@@ -754,7 +755,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);
@@ -768,7 +769,6 @@ static void test_reconnect_subprocess(void)wait_for_fds (s);wait_for_rings_started (s,2 ); -qtest_end ();test_server_free (s);return ; }
@@ -790,14 +790,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); }
@@ -818,14 +817,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); }
@@ -890,13 +888,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); }
@@ -913,14 +911,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 ;
@@ -957,7 +953,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);
@@ -979,10 +975,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
PATCH v7 22/38 qmp-test: Drop dependence on global_qtest
In reply to Eric BlakeAs 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
@@ -41,32 +41,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); }
@@ -75,11 +75,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" ));
@@ -88,46 +89,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); }static int query_error_class (const char *cmd)
Signature · 1 line
2.13.5
PATCH v7 23/38 tests/boot-sector: Drop dependence on global_qtest
In reply to Eric BlakeAs 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v7 24/38 tests/acpi-utils: Drop dependence on global_qtest
In reply to Eric BlakeAs 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.
bios-tables-test no longer depends on global_qtest, now that it passes explicit state through the testsuite data; an assert proves this fact (although we will get rid of it later, once global_qtest is gone).
---
v7: merge two patches for less churn on bios-tables-test
--- tests/acpi-utils.h | 65 ++++++++--------- tests/acpi-utils.c | 19 ++--- tests/bios-tables-test.c | 184 ++++++++++++++++++++++++----------------------- tests/vmgenid-test.c | 18 ++--- 4 files changed, 146 insertions(+), 140 deletions(-)
tests/acpi-utils.h +33 -32
@@ -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
@@ -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 +94 -90
302 lines not on this page · raw message
tests/vmgenid-test.c +9 -9
@@ -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
Re: [Qemu-devel] [PATCH v7 24/38] tests/acpi-utils: Drop dependence on global_qtest
Quoted 11 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.
bios-tables-test no longer depends on
global_qtest, now that it passes explicit state through the testsuite data; an assert proves this fact (although we will get rid of it later, onceglobal_qtestis gone).Signed-off-by Eric Blake <[email protected]>
[...]
Quoted 42 lines
tests/vmgenid-test.c +6
-7@@ -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]);
tests/vmgenid-test.c static uint32_t acpi_find_vgia(void) · line 88
Quoted 10 lines
tests/vmgenid-test.c +3
-2+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
I'd maybe use a local "QTestState *qts = global_qtest;" at the beginning of this function instead, and then use "qts" instead of "global_qtest in this function ... then we have to only touch one line later instead of changing all lines with "global_qtest" again.
Any way:
PATCH v7 25/38 wdt_ib700-test: Drop dependence on global_qtest
In reply to Eric BlakeAs 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
@@ -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
PATCH v7 26/38 libqtest: Merge qtest_end() into qtest_quit()
In reply to Eric BlakeRather than have two similar shutdown functions, where one requires the use of global_qtest in the header, it is better to have a single shutdown function that still takes care of cleaning up global_qtest if it is set. All callers are updated.
--- tests/libqtest.h | 11 ----------- tests/libqtest.c | 6 +++++- tests/ac97-test.c | 2 +- tests/device-introspect-test.c | 12 ++++++------ tests/display-vga-test.c | 12 ++++++------ tests/drive_del-test.c | 6 +++--- tests/e1000e-test.c | 4 ++-- tests/es1370-test.c | 2 +- tests/fdc-test.c | 2 +- tests/hd-geo-test.c | 8 ++++---- tests/i440fx-test.c | 6 +++--- tests/i82801b11-test.c | 2 +- tests/ide-test.c | 2 +- tests/intel-hda-test.c | 4 ++-- tests/ioh3420-test.c | 2 +- tests/ipoctal232-test.c | 2 +- tests/ne2000-test.c | 2 +- tests/numa-test.c | 14 +++++++------- tests/nvme-test.c | 2 +- tests/pc-cpu-test.c | 4 ++-- tests/pcnet-test.c | 2 +- tests/pvpanic-test.c | 2 +- tests/q35-test.c | 4 ++-- tests/qmp-test.c | 4 ++-- tests/qom-test.c | 2 +- tests/rtl8139-test.c | 2 +- tests/spapr-phb-test.c | 2 +- tests/tco-test.c | 2 +- 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 | 2 +- tests/test-x86-cpuid-compat.c | 6 +++--- 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 | 2 +- tests/virtio-balloon-test.c | 2 +- tests/virtio-blk-test.c | 2 +- tests/virtio-console-test.c | 4 ++-- tests/virtio-net-test.c | 2 +- tests/virtio-rng-test.c | 2 +- tests/virtio-serial-test.c | 2 +- tests/vmxnet3-test.c | 2 +- 45 files changed, 80 insertions(+), 87 deletions(-)
tests/libqtest.h +0 -11
@@ -523,17 +523,6 @@ static inline QTestState *qtest_start(const char *args) }/** -* 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 +5 -1
@@ -246,6 +246,10 @@ QTestState *qtest_init(const char *extra_args)void qtest_quit (QTestState *s) { +if (global_qtest) { +assert (s == global_qtest); + global_qtest =NULL ; + }g_hook_destroy_link (&abrt_hooks,g_hook_find_data (&abrt_hooks, TRUE, s));/* Uninstall SIGABRT handler on last instance */
@@ -979,6 +983,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 +1 -1
@@ -25,7 +25,7 @@ int main(int argc, char **argv)qtest_start ("-device AC97" ); ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
tests/device-introspect-test.c +6 -6
@@ -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); }/*
@@ -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);test_one_device ("nonexistent" ); -qtest_end (); +qtest_quit (global_qtest); }static void test_device_intro_abstract (void ) {qtest_start (common_args);test_one_device ("device" ); -qtest_end (); +qtest_quit (global_qtest); }static void test_device_intro_concrete (void )
@@ -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 )
@@ -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 -6
@@ -13,38 +13,38 @@static void pci_cirrus (void ) {qtest_start ("-vga none -device cirrus-vga" ); -qtest_end (); +qtest_quit (global_qtest); }static void pci_stdvga (void ) {qtest_start ("-vga none -device VGA" ); -qtest_end (); +qtest_quit (global_qtest); }static void pci_secondary (void ) {qtest_start ("-vga none -device secondary-vga" ); -qtest_end (); +qtest_quit (global_qtest); }static void pci_multihead (void ) {qtest_start ("-vga none -device VGA -device secondary-vga" ); -qtest_end (); +qtest_quit (global_qtest); }static void pci_virtio_gpu (void ) {qtest_start ("-vga none -device virtio-gpu-pci" ); -qtest_end (); +qtest_quit (global_qtest); }#ifdef CONFIG_VIRTIO_VGA static void pci_virtio_vga (void ) {qtest_start ("-vga none -device virtio-vga" ); -qtest_end (); +qtest_quit (global_qtest); }#endif
tests/drive_del-test.c +3 -3
@@ -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 )
@@ -86,7 +86,7 @@ static void test_after_failed_device_add(void)*/ drive_add (); -qtest_end (); +qtest_quit (global_qtest); }static void test_drive_del_device_del (void )
@@ -103,7 +103,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/e1000e-test.c +2 -2
@@ -408,7 +408,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)
@@ -463,7 +463,7 @@ static void test_e1000e_hotplug(gconstpointer data)qpci_plug_device_test (global_qtest,"e1000e" ,"e1000e_net" , slot,NULL );qpci_unplug_device_test (global_qtest,"e1000e_net" , slot); -qtest_end (); +qtest_quit (global_qtest); }int main (int argc,char **argv)
tests/es1370-test.c +1 -1
@@ -25,7 +25,7 @@ int main(int argc, char **argv)qtest_start ("-device ES1370" ); ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
tests/fdc-test.c +1 -1
@@ -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 +4 -4
@@ -245,7 +245,7 @@ static void test_ide_none(void)g_strfreev (argv);g_free (args);test_cmos (); -qtest_end (); +qtest_quit (global_qtest); }static void test_ide_mbr (bool use_device,MBRcontents mbr)
@@ -267,7 +267,7 @@ static void test_ide_mbr(bool use_device, MBRcontents mbr)g_strfreev (argv);g_free (args);test_cmos (); -qtest_end (); +qtest_quit (global_qtest); }/*
@@ -343,7 +343,7 @@ static void test_ide_drive_user(const char *dev, bool trans)g_strfreev (argv);g_free (args);test_cmos (); -qtest_end (); +qtest_quit (global_qtest); }/*
@@ -400,7 +400,7 @@ static void test_ide_drive_cd_0(void)g_strfreev (argv);g_free (args);test_cmos (); -qtest_end (); +qtest_quit (global_qtest); }int main (int argc,char **argv)
tests/i440fx-test.c +3 -3
@@ -136,7 +136,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 +275,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)
@@ -373,7 +373,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 +1 -1
@@ -25,7 +25,7 @@ int main(int argc, char **argv)qtest_start ("-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 +1 -1
@@ -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 +2 -2
@@ -19,14 +19,14 @@static void ich6_test (void ) {qtest_start ("-device intel-hda,id=" HDA_ID CODEC_DEVICES ); -qtest_end (); +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 (); +qtest_quit (global_qtest); }int main (int argc,char **argv)
tests/ioh3420-test.c +1 -1
@@ -26,7 +26,7 @@ int main(int argc, char **argv) "chassis=1,multifunction=on"); ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
tests/ipoctal232-test.c +1 -1
@@ -25,7 +25,7 @@ int main(int argc, char **argv)qtest_start ("-device tpci200,id=ipack0 -device ipoctal232,bus=ipack0.0" ); ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
tests/ne2000-test.c +1 -1
@@ -25,7 +25,7 @@ int main(int argc, char **argv)qtest_start ("-device ne2k_pci" ); ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
tests/numa-test.c +7 -7
@@ -32,7 +32,7 @@ static void test_mon_explicit(const void *data)g_assert (strstr (s,"node 1 cpus: 4 5 6 7" ));g_free (s); -qtest_end (); +qtest_quit (global_qtest);g_free (cli); }
@@ -49,7 +49,7 @@ static void test_mon_default(const void *data)g_assert (strstr (s,"node 1 cpus: 1 3 5 7" ));g_free (s); -qtest_end (); +qtest_quit (global_qtest);g_free (cli); }
@@ -68,7 +68,7 @@ static void test_mon_partial(const void *data)g_assert (strstr (s,"node 1 cpus: 4 5" ));g_free (s); -qtest_end (); +qtest_quit (global_qtest);g_free (cli); }
@@ -113,7 +113,7 @@ static void test_query_cpus(const void *data) }QDECREF (resp); -qtest_end (); +qtest_quit (global_qtest);g_free (cli); }
@@ -166,7 +166,7 @@ static void pc_numa_cpu(const void *data) }QDECREF (resp); -qtest_end (); +qtest_quit (global_qtest);g_free (cli); }
@@ -211,7 +211,7 @@ static void spapr_numa_cpu(const void *data) }QDECREF (resp); -qtest_end (); +qtest_quit (global_qtest);g_free (cli); }
@@ -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 +1 -1
@@ -26,7 +26,7 @@ int main(int argc, char **argv) "-device nvme,drive=drv0,serial=foo"); ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
tests/pc-cpu-test.c +2 -2
@@ -44,7 +44,7 @@ static void test_pc_with_cpu_add(gconstpointer data)QDECREF (response); } -qtest_end (); +qtest_quit (global_qtest);g_free (args); }
@@ -67,7 +67,7 @@ static void test_pc_without_cpu_add(gconstpointer data)g_assert (qdict_haskey (response,"error" ));QDECREF (response); -qtest_end (); +qtest_quit (global_qtest);g_free (args); }
tests/pcnet-test.c +1 -1
@@ -25,7 +25,7 @@ int main(int argc, char **argv)qtest_start ("-device pcnet" ); ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
tests/pvpanic-test.c +1 -1
@@ -40,7 +40,7 @@ int main(int argc, char **argv)qtest_start ("-device pvpanic" ); ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
tests/q35-test.c +2 -2
@@ -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)
@@ -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/qmp-test.c +2 -2
@@ -188,7 +188,7 @@ static void test_query(const void *data) }QDECREF (resp); -qtest_end (); +qtest_quit (global_qtest); }static bool query_is_blacklisted (const char *cmd)
@@ -232,7 +232,7 @@ static void qmp_schema_init(QmpSchema *schema)visit_free (qiv);QDECREF (resp); -qtest_end (); +qtest_quit (global_qtest); schema->hash =g_hash_table_new (g_str_hash, g_str_equal);
tests/qom-test.c +1 -1
@@ -102,7 +102,7 @@ static void test_machine(gconstpointer data)g_assert (qdict_haskey (response,"return" ));QDECREF (response); -qtest_end (); +qtest_quit (global_qtest);g_free (args);g_free ((void *)machine); }
tests/rtl8139-test.c +1 -1
@@ -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 +1 -1
@@ -29,7 +29,7 @@ int main(int argc, char **argv) ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
tests/tco-test.c +1 -1
@@ -49,7 +49,7 @@ 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)
tests/test-arm-mptimer.c +1 -1
@@ -1099,7 +1099,7 @@ tests_with_prescaler_arg:qtest_start ("-machine vexpress-a9" ); ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
tests/test-filter-mirror.c +1 -1
@@ -86,7 +86,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 +2 -2
@@ -135,7 +135,7 @@ static void test_redirector_tx(void)close (recv_sock);unlink (sock_path0);unlink (sock_path1); -qtest_end (); +qtest_quit (global_qtest); }static void test_redirector_rx (void )
@@ -204,7 +204,7 @@ static void test_redirector_rx(void)g_free (recv_buf);unlink (sock_path0);unlink (sock_path1); -qtest_end (); +qtest_quit (global_qtest); }int main (int argc,char **argv)
tests/test-hmp.c +1 -1
@@ -127,7 +127,7 @@ static void test_machine(gconstpointer data)test_info_commands ();test_commands (); -qtest_end (); +qtest_quit (global_qtest);g_free (args);g_free ((void *)data); }
tests/test-netfilter.c +1 -1
@@ -202,7 +202,7 @@ int main(int argc, char **argv)qtest_start (args); ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);g_free (args);return ret;
tests/test-x86-cpuid-compat.c +3 -3
@@ -64,7 +64,7 @@ static void test_cpuid_prop(const void *data) 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);
@@ -137,7 +137,7 @@ static void test_feature_flag(const void *data) 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);
@@ -195,7 +195,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/tpci200-test.c +1 -1
@@ -25,7 +25,7 @@ int main(int argc, char **argv)qtest_start ("-device tpci200" ); ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
tests/usb-hcd-ehci-test.c +1 -1
@@ -172,7 +172,7 @@ int main(int argc, char **argv) ret =g_test_run ();test_deinit (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
tests/usb-hcd-ohci-test.c +1 -1
@@ -33,7 +33,7 @@ int main(int argc, char **argv)qtest_start ("-device pci-ohci,id=ohci" ); ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
tests/usb-hcd-xhci-test.c +1 -1
@@ -83,7 +83,7 @@ int main(int argc, char **argv)qtest_start ("-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 +1 -1
@@ -25,7 +25,7 @@ int main(int argc, char **argv)qtest_start ("-device virtio-balloon-pci" ); ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
tests/virtio-blk-test.c +1 -1
@@ -102,7 +102,7 @@ static void arm_test_start(void)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 +2 -2
@@ -15,14 +15,14 @@ static void console_pci_nop(void) {qtest_start ("-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 " "-device virtserialport,bus=vser0.0" ); -qtest_end (); +qtest_quit (global_qtest); }int main (int argc,char **argv)
tests/virtio-net-test.c +1 -1
@@ -30,7 +30,7 @@static void test_end (void ) { -qtest_end (); +qtest_quit (global_qtest); }#ifndef _WIN32
tests/virtio-rng-test.c +1 -1
@@ -41,7 +41,7 @@ int main(int argc, char **argv)qtest_start ("-device virtio-rng-pci" ); ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
tests/virtio-serial-test.c +1 -1
@@ -52,7 +52,7 @@ int main(int argc, char **argv)qtest_start ("-device virtio-serial-pci" ); ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
tests/vmxnet3-test.c +1 -1
@@ -25,7 +25,7 @@ int main(int argc, char **argv)qtest_start ("-device vmxnet3" ); ret =g_test_run (); -qtest_end (); +qtest_quit (global_qtest);return ret; }
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PATCH v7 26/38] libqtest: Merge qtest_end() into qtest_quit()
Quoted 9 lines · Eric Blake
Rather than have two similar shutdown functions, where one requires the use of
global_qtestin the header, it is better to have a single shutdown function that still takes care of cleaning upglobal_qtestif it is set. All callers are updated.Signed-off-by Eric Blake <[email protected]>--- tests/libqtest.h | 11 ----------- tests/libqtest.c | 6 +++++-
[...]
Quoted 1 line
tests/fdc-test.c | 2 +-
[...]
Quoted 1 line
tests/ide-test.c | 2 +-
The rest: "ACK." Change looks sane and I assume the rest of the patch is fairly straightforward mechanical changes. Everything still compiles and runs successfully.
Re: [Qemu-devel] [PATCH v7 26/38] libqtest: Merge qtest_end() into qtest_quit()
In reply to Eric BlakeQuoted 6 lines · Eric Blake
Rather than have two similar shutdown functions, where one requires the use of
global_qtestin the header, it is better to have a single shutdown function that still takes care of cleaning upglobal_qtestif it is set. All callers are updated.Signed-off-by Eric Blake <[email protected]>
PATCH v7 27/38 libqtest: Swap order of qtest_init() and qtest_start()
In reply to Eric BlakeWe already have another qtest_init() in the tree (namely, as part of the device initialization of the qtest device at the top level qtest.c), with a different signature; having two different qtest_init() is confusing, so an upcoming patch will consolidate all testsuite callers onto a unified spelling. But the consolidation is easier if qtest_start() is further down the call chain, rather than an intermediate wrapper, so swap the call chain around. This includes renaming qtest_init_without_qmp_handshake() into qtest_start_without_qmp_handshake(), as it remains the lowest point in the call stack.
Note that qtest_init() now asserts that global_qtest was not set on entry, and clears it on exit, to preserve the behavior of existing tests that assert the same (and also proving that we fixed all tests that had parallel connections); but later patches will eventually simplify things by getting rid of qtest_init() and global_qtest altogether.
--- tests/libqtest.h | 52 ++++++++++++++++++++++++++++------------------------ tests/libqtest.c | 9 +++++---- tests/qmp-test.c | 2 +- 3 files changed, 34 insertions(+), 29 deletions(-)
tests/libqtest.h +28 -24
@@ -24,20 +24,39 @@ typedef struct QTestState QTestState;extern QTestState *global_qtest;/** +* qtest_start_without_qmp_handshake: +* @extra_args: other arguments to pass to QEMU. +* +* Returns: #QTestState instance. Does not affect #global_qtest. +*/ +QTestState *qtest_start_without_qmp_handshake (const char *extra_args); + +/** +* qtest_start: +* @args: other arguments to pass to QEMU +* +* Start QEMU and assign the resulting #QTestState to #global_qtest. +* The global variable is used by "shortcut" functions documented below. +* +* Returns: #QTestState instance. +*/ +QTestState *qtest_start (const char *args); + +/** * qtest_init: * @extra_args: other arguments to pass to QEMU. * -* Returns: #QTestState instance. +* Returns: #QTestState instance. Does not affect #global_qtest. */ -QTestState *qtest_init (const char *extra_args); +static inline QTestState *qtest_init (const char *extra_args) +{ +QTestState *s; -/** -* qtest_init_without_qmp_handshake: -* @extra_args: other arguments to pass to QEMU. -* -* Returns: #QTestState instance. -*/ -QTestState *qtest_init_without_qmp_handshake (const char *extra_args); +assert (!global_qtest); + s =qtest_start (extra_args); + global_qtest =NULL ; +return s; +}/** * qtest_quit:
@@ -508,21 +527,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 (args); -return global_qtest; -} - -/** * qmp: * @fmt...: QMP message to send to qemu *
tests/libqtest.c +5 -4
@@ -152,7 +152,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;
@@ -233,15 +233,16 @@ 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) { -QTestState *s =qtest_init_without_qmp_handshake (extra_args); +QTestState *s =qtest_start_without_qmp_handshake (extra_args);/* Read the QMP greeting and then do the handshake */ qtest_qmp_discard_response (s,"" );qtest_qmp_discard_response (s,"{ 'execute': 'qmp_capabilities' }" ); -return s; +assert (!global_qtest); +return global_qtest = s; }void qtest_quit (QTestState *s)
tests/qmp-test.c +1 -1
@@ -77,7 +77,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);
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PATCH v7 27/38] libqtest: Swap order of qtest_init() and qtest_start()
Quoted 11 lines · Eric Blake
We already have another
qtest_init()in the tree (namely, as part of the device initialization of the qtest device at the top levelqtest.c), with a different signature; having two differentqtest_init()is confusing, so an upcoming patch will consolidate all testsuite callers onto a unified spelling. But the consolidation is easier ifqtest_start()is further down the call chain, rather than an intermediate wrapper, so swap the call chain around. This includes renamingqtest_init_without_qmp_handshake()intoqtest_start_without_qmp_handshake(), as it remains the lowest point in the call stack.
Quoted 8 lines
Note that
qtest_init()now asserts thatglobal_qtestwas not set on entry, and clears it on exit, to preserve the behavior of existing tests that assert the same (and also proving that we fixed all tests that had parallel connections); but later patches will eventually simplify things by getting rid ofqtest_init()andglobal_qtestaltogether.Signed-off-by Eric Blake <[email protected]>
PATCH v7 28/38 libqtest: Add qtest_[v]startf()
In reply to Eric BlakeWe have several callers that were formatting the argument strings themselves; consolidate this effort by adding new convenience functions directly in libqtest, and update all call-sites that can benefit from it.
Note that the new functions qtest_startf() and qtest_vstartf() behave more like qtest_init() (the caller must assign global_qtest after the fact, rather than getting it implicitly set). This helps us prepare for future patches that get rid of the global variable, by explicitly highlighting which tests still depend on it now.
In ide-test, we now have to pass a space to keep -Wformat from complaining about a zero-length format string (one of gcc's more pointless warnings, oh well).
--- tests/libqtest.h | 25 ++++++++++++++++ tests/libqtest.c | 21 +++++++++++++ tests/bios-tables-test.c | 17 ++++------- tests/boot-order-test.c | 11 +++---- tests/boot-serial-test.c | 12 +++----- tests/e1000-test.c | 10 +------ tests/e1000e-test.c | 12 ++------ tests/eepro100-test.c | 11 +------ tests/endianness-test.c | 33 ++++++++------------- tests/i440fx-test.c | 6 +--- tests/ide-test.c | 10 ++----- tests/ipmi-bt-test.c | 11 +++---- tests/libqos/libqos.c | 5 +--- tests/m25p80-test.c | 9 ++---- tests/numa-test.c | 67 ++++++++++++++++-------------------------- tests/pc-cpu-test.c | 20 ++++--------- tests/pnv-xscom-test.c | 16 +++------- tests/prom-env-test.c | 13 ++++---- tests/pxe-test.c | 14 ++++----- tests/qom-test.c | 5 +--- tests/tco-test.c | 10 +++---- tests/test-filter-mirror.c | 14 ++++----- tests/test-filter-redirector.c | 56 ++++++++++++++++------------------- tests/test-hmp.c | 5 +--- tests/test-netfilter.c | 7 ++--- tests/vhost-user-test.c | 51 ++++++++++---------------------- tests/virtio-blk-test.c | 5 +--- tests/vmgenid-test.c | 29 +++++------------- 28 files changed, 199 insertions(+), 306 deletions(-)
tests/libqtest.h +25 -0
@@ -43,6 +43,31 @@ QTestState *qtest_start_without_qmp_handshake(const char *extra_args);QTestState *qtest_start (const char *args);/** +* qtest_startf: +* @fmt...: Format for creating other arguments to pass to QEMU, formatted +* like sprintf(). +* +* Start QEMU and return the resulting #QTestState (but unlike qtest_start(), +* #global_qtest is left at NULL). +* +* Returns: #QTestState instance. +*/ +QTestState *qtest_startf (const char *fmt, ...)GCC_FMT_ATTR (1 ,2 ); + +/** +* qtest_vstartf: +* @fmt: Format for creating other arguments to pass to QEMU, formatted +* like vsprintf(). +* @ap: Format arguments. +* +* Start QEMU and return the resulting #QTestState (but unlike qtest_start(), +* #global_qtest is left at NULL). +* +* Returns: #QTestState instance. +*/ +QTestState *qtest_vstartf (const char *fmt,va_list ap)GCC_FMT_ATTR (1 ,0 ); + +/** * qtest_init: * @extra_args: other arguments to pass to QEMU. *
tests/libqtest.c +21 -0
@@ -245,6 +245,27 @@ QTestState *qtest_start(const char *extra_args)return global_qtest = s; } +QTestState *qtest_vstartf (const char *fmt,va_list ap) +{ +char *args =g_strdup_vprintf (fmt, ap); +QTestState *s; + + s =qtest_start (args); + global_qtest =NULL ; +return s; +} + +QTestState *qtest_startf (const char *fmt, ...) +{ +va_list ap; +QTestState *s; + +va_start (ap, fmt); + s =qtest_vstartf (fmt, ap); +va_end (ap); +return s; +} +void qtest_quit (QTestState *s) {if (global_qtest) {
tests/bios-tables-test.c +6 -11
@@ -623,17 +623,13 @@ 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 " -"-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); + data->qts =qtest_startf ("-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);
@@ -658,7 +654,6 @@ static void test_acpi_one(const char *params, test_data *data)assert (!global_qtest);qtest_quit (data->qts); -g_free (args); }static uint8_t base_required_struct_types[] = {
tests/boot-order-test.c +4 -7
@@ -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_startf ("-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
@@ -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_startf ("-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/e1000-test.c +1 -9
@@ -14,16 +14,8 @@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); +qtest_quit (qtest_startf ("-device %s" , model)); }static const char *models[] = {
tests/e1000e-test.c +3 -9
@@ -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 " -"-device e1000e,netdev=hs0" , test_sockets[1 ]); -g_assert_nonnull (cmdline); - -qtest_start (cmdline); -g_free (cmdline); + global_qtest =qtest_startf ("-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);
@@ -458,7 +452,7 @@ static void test_e1000e_hotplug(gconstpointer data) {static const uint8_t slot =0x06 ; -qtest_start ("-device e1000e" ); + global_qtest =qtest_start ("-device e1000e" );qpci_plug_device_test (global_qtest,"e1000e" ,"e1000e_net" , slot,NULL );qpci_unplug_device_test (global_qtest,"e1000e_net" , slot);
tests/eepro100-test.c +1 -10
@@ -13,18 +13,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);/* Tests only initialization so far. TODO: Implement functional tests */ - -if (s) { -qtest_quit (s); - } -g_free (args); +qtest_quit (qtest_startf ("-device %s" , model)); }static const char *models[] = {
tests/endianness-test.c +12 -21
@@ -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_startf ("-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_startf ("-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_startf ("-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/i440fx-test.c +1 -5
@@ -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_startf ("-smp %d" , s->num_cpus);return qpci_init_pc (global_qtest,NULL ); }
tests/ide-test.c +3 -7
@@ -115,19 +115,15 @@ static QGuestAllocator *guest_malloc;static char tmp_path[] ="/tmp/qtest.XXXXXX" ;static char debug_path[] ="/tmp/qtest-blkdebug.XXXXXX" ; -static void ide_test_start (const char *cmdline_fmt, ...) +static void GCC_FMT_ATTR(1, 2) ide_test_start(const char *cmdline_fmt, ...) { va_list ap; -char *cmdline; va_start(ap, cmdline_fmt); - cmdline =g_strdup_vprintf (cmdline_fmt, ap); + global_qtest = qtest_vstartf(cmdline_fmt, ap); va_end(ap); -qtest_start (cmdline); guest_malloc = pc_alloc_init(global_qtest); - -g_free (cmdline); } static void ide_test_quit(void)
@@ -675,7 +671,7 @@ static void test_flush_nodev(void)QPCIDevice *dev;QPCIBar bmdma_bar, ide_bar; -ide_test_start ("" ); +ide_test_start (" " ); dev =get_pci_device (&bmdma_bar, &ide_bar);
tests/ipmi-bt-test.c +4 -7
@@ -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_startf ( +" -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/libqos/libqos.c +1 -4
@@ -15,19 +15,16 @@*/ QOSState *qtest_vboot (QOSOps *ops,const char *cmdline_fmt,va_list ap) { -char *cmdline;QOSState *qs =g_new0 (QOSState,1 ); - cmdline =g_strdup_vprintf (cmdline_fmt, ap); - qs->qts =qtest_init (cmdline); + qs->qts =qtest_vstartf (cmdline_fmt, ap); qs->ops = ops;if (ops) { qs->alloc = ops->init_allocator (qs->qts,ALLOC_NO_FLAGS ); qs->pcibus = ops->qpci_init (qs->qts, qs->alloc); } -g_free (cmdline);return qs; }
tests/m25p80-test.c +3 -6
@@ -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_startf ("-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/numa-test.c +26 -41
179 lines not on this page · raw message
tests/pc-cpu-test.c +6 -14
@@ -26,15 +26,12 @@ 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_startf ( +"-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',"
@@ -45,20 +42,16 @@ static void test_pc_with_cpu_add(gconstpointer data) }qtest_quit (global_qtest); -g_free (args); }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_startf ( +"-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 } }",
@@ -68,7 +61,6 @@ static void test_pc_without_cpu_add(gconstpointer data)QDECREF (response);qtest_quit (global_qtest); -g_free (args); }static void test_data_free (gpointer data)
tests/pnv-xscom-test.c +4 -12
@@ -81,16 +81,12 @@ 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_startf ("-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 +105,12 @@ 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_startf ("-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
@@ -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_startf ("-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/pxe-test.c +5 -9
@@ -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_startf ( +"-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/qom-test.c +1 -4
@@ -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_startf ("-machine %s" , machine);test_properties ("/machine" , true);
@@ -103,7 +101,6 @@ static void test_machine(gconstpointer data)QDECREF (response);qtest_quit (global_qtest); -g_free (args);g_free ((void *)machine); }
tests/tco-test.c +4 -6
@@ -55,14 +55,12 @@ static void test_end(TestData *d)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_startf ("-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-filter-mirror.c +6 -8
@@ -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_startf ( +"-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);
tests/test-filter-redirector.c +26 -30
80 lines not on this page · raw message
tests/test-hmp.c +1 -4
@@ -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_startf ("-S -M %s" , machine);test_info_commands ();test_commands ();qtest_quit (global_qtest); -g_free (args);g_free ((void *)data); }
tests/test-netfilter.c +2 -5
@@ -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_startf ("-netdev user,id=qtest-bn0 " +"-device %s,netdev=qtest-bn0" , devstr); ret =g_test_run ();qtest_quit (global_qtest); -g_free (args);return ret; }
tests/vhost-user-test.c +15 -36
126 lines not on this page · raw message
tests/virtio-blk-test.c +1 -4
@@ -85,19 +85,16 @@ 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 " + global_qtest =qtest_startf ("-machine virt " "-drive if=none,id=drive0,file=%s,format=raw " "-device virtio-blk-device,drive=drive0" , tmp_path); -qtest_start (cmdline);unlink (tmp_path);g_free (tmp_path); -g_free (cmdline); }static void test_end (void )
tests/vmgenid-test.c +8 -21
@@ -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, diskstatic 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_startf (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_startf (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_startf (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)
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PATCH v7 28/38] libqtest: Add qtest_[v]startf()
Quoted 4 lines · Eric Blake
We have several callers that were formatting the argument strings themselves; consolidate this effort by adding new convenience functions directly in libqtest, and update all call-sites that can benefit from it.
[...]
Quoted 5 lines
tests/libqtest.c +0
-0
tests/libqtest.c QTestState *qtest_start(const char *extra_args) · line 254
Quoted 10 lines
tests/libqtest.c +7
-0@@ -245,6 +245,27 @@ QTestState *qtest_start(const char *extra_args)return global_qtest = s; } +QTestState *qtest_vstartf (const char *fmt,va_list ap) +{ +char *args =g_strdup_vprintf (fmt, ap); +QTestState *s; + + s =qtest_start (args); + global_qtest =NULL ;
Don't you need a g_free(args) here?
Quoted 13 lines
tests/libqtest.c +13
-0+return s; +} + +QTestState *qtest_startf (const char *fmt, ...) +{ +va_list ap; +QTestState *s; + +va_start (ap, fmt); + s =qtest_vstartf (fmt, ap); +va_end (ap); +return s; +}
[...]
Quoted 9 lines
tests/e1000-test.c +0
-1@@ -14,16 +14,8 @@static void test_device (gconstpointer data) {const char *model = data; -QTestState *s;
tests/e1000-test.c line 18
Quoted 10 lines
tests/e1000-test.c +1
-8-char *args; - args =g_strdup_printf ("-device %s" , model); - s =qtest_start (args); - -if (s) { -qtest_quit (s); - } -g_free (args); +qtest_quit (qtest_startf ("-device %s" , model));
Just my personal taste, but I think I'd be nicer to keep this on separate lines:
QTestState *s;
s = qtest_startf("-device %s", model);
qtest_quit(s);Quoted 1 line
tests/e1000-test.c +0
-0}
[...]
Quoted 12 lines
tests/eepro100-test.c +0
-4@@ -13,18 +13,9 @@static void test_device (gconstpointer data) {const char *model = data; -QTestState *s; -char *args; - - args =g_strdup_printf ("-device %s" , model);
tests/eepro100-test.c line 19
Quoted 10 lines
tests/eepro100-test.c +1
-6- s =qtest_start (args);/* Tests only initialization so far. TODO: Implement functional tests */ - -if (s) { -qtest_quit (s); - } -g_free (args); +qtest_quit (qtest_startf ("-device %s" , model)); }
dito
[...]
Quoted 58 lines
tests/numa-test.c +6
-15@@ -12,20 +12,14 @@#include "qemu/osdep.h" #include "libqtest.h" -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 void test_mon_explicit (const void *data) {char *s; -char *cli; +const char *args = 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_startf ("%s -smp 8 " +"-numa node,nodeid=0,cpus=0-3 " +"-numa node,nodeid=1,cpus=4-7 " , args); s =hmp ("info numa" );g_assert (strstr (s,"node 0 cpus: 0 1 2 3" ));@@ -33,16 +27,14 @@ static void test_mon_explicit(const void *data)g_free (s);qtest_quit (global_qtest); -g_free (cli); }static void test_mon_default (const void *data) {char *s; -char *cli; +const char *args = data; - cli =make_cli (data,"-smp 8 -numa node -numa node" ); -qtest_start (cli); + global_qtest =qtest_startf ("%s -smp 8 -numa node -numa node" , args); s =hmp ("info numa" );g_assert (strstr (s,"node 0 cpus: 0 2 4 6" ));@@ -50,18 +42,16 @@ static void test_mon_default(const void *data)g_free (s);qtest_quit (global_qtest); -g_free (cli); }static void test_mon_partial (const void *data) {char *s;
tests/numa-test.c static void test_mon_default(const void *data) · line 54
Quoted 10 lines
tests/numa-test.c +4
-5-char *cli; +const char *args = 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_startf ("%s -smp 8 " +"-numa node,nodeid=0,cpus=0-1 " +"-numa node,nodeid=1,cpus=4-5 " , args);
Does GCC emit a warning if you'd used data here directly? Otherwise I think you could simply do this without the local args variable...
Thomas
Re: [Qemu-devel] [PATCH v7 28/38] libqtest: Add qtest_[v]startf()
Quoted 14 lines · Thomas Huth
Quoted 4 lines · Eric Blake
We have several callers that were formatting the argument strings themselves; consolidate this effort by adding new convenience functions directly in libqtest, and update all call-sites that can benefit from it.
[...]
Quoted 8 lines
tests/libqtest.c +0
-0@@ -245,6 +245,27 @@ QTestState *qtest_start(const char *extra_args)return global_qtest = s; }
Quoted 9 lines
tests/libqtest.c QTestState *qtest_start(const char *extra_args) · line 254
Quoted 7 lines
tests/libqtest.c +7
-0+QTestState *qtest_vstartf (const char *fmt,va_list ap) +{ +char *args =g_strdup_vprintf (fmt, ap); +QTestState *s; + + s =qtest_start (args); + global_qtest =NULL ;Don't you need a
g_free(args)here?
D'oh. Yes, I do.
Quoted 9 lines
tests/libqtest.c QTestState *qtest_start(const char *extra_args) · line 255
Quoted 1 line
tests/libqtest.c +1
-0+qtest_quit (qtest_startf ("-device %s" , model));Just my personal taste, but I think I'd be nicer to keep this on separate lines:
QTestState *s; s = qtest_startf("-device %s", model); qtest_quit(s);
Sure. I debated about it. If we ever do more than just create/destroy, then having the separate lines makes it easier to stick the actual test in between the two lines, so I'll avoid my abbreviation and go with the longer form on respin.
Quoted 14 lines
tests/libqtest.c QTestState *qtest_start(const char *extra_args)
Quoted 13 lines
tests/libqtest.c +4
-5static void test_mon_partial (const void *data) {char *s; -char *cli; +const char *args = 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_startf ("%s -smp 8 " +"-numa node,nodeid=0,cpus=0-1 " +"-numa node,nodeid=1,cpus=4-5 " , args);
Quoted 2 lines
Does GCC emit a warning if you'd used data here directly? Otherwise I think you could simply do this without the local args variable...
Passing void* through varargs, with the intent of the receiver parsing it as char*, is technically undefined in C. I don't know if gcc warns, but I'm also worried that clang might warn. I prefer to err on the side of defined behavior in this case, even though it annoyingly requires a temporary variable.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v7 28/38] libqtest: Add qtest_[v]startf()
Quoted 6 lines · Eric Blake
Quoted 5 lines · Thomas Huth
Quoted 4 lines · Eric Blake
We have several callers that were formatting the argument strings themselves; consolidate this effort by adding new convenience functions directly in libqtest, and update all call-sites that can benefit from it.
[...]
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
static void
test_mon_partial(const void *data){ char *s;tests/numa-test.c +4
-5-char *cli; +const char *args = 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_startf ("%s -smp 8 " +"-numa node,nodeid=0,cpus=0-1 " +"-numa node,nodeid=1,cpus=4-5 " , args);
Quoted 8 lines
Quoted 2 lines
Does GCC emit a warning if you'd used data here directly? Otherwise I think you could simply do this without the local args variable...
Passing void* through varargs, with the intent of the receiver parsing it as char*, is technically undefined in C. I don't know if gcc warns, but I'm also worried that clang might warn. I prefer to err on the side of defined behavior in this case, even though it annoyingly requires a temporary variable.
OK, sounds reasonable, so let's keep it!
Thomas
PATCH v7 29/38 libqtest: Merge qtest_init() into qtest_start()
In reply to Eric BlakeRemove the trivial wrapper qtest_init(), and change qtest_start() to no longer implicitly set global_qtest, to make it obvious in the rest of the testsuite where we are still relying on global_qtest. Everything now uses qtest_start() (and friends) and qtest_quit(), and explicitly tracks the QTestState between the two (although in many cases, this tracking is still done through 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.
A few more places that were needlessly strdup'ing a temporary variable are cleaned up in the process.
As mentioned in an earlier commit, the choice to get rid of qtest_init() also reduces confusion with the device initializer of the non-testsuite qtest.c device.
--- tests/libqtest.h | 33 ++++----------------------------- tests/libqtest.c | 4 ++-- tests/ac97-test.c | 2 +- tests/device-introspect-test.c | 12 ++++++------ tests/display-vga-test.c | 18 ++++++------------ tests/drive_del-test.c | 11 ++++++----- 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 | 2 +- tests/i82801b11-test.c | 3 ++- tests/intel-hda-test.c | 9 ++++----- tests/ioh3420-test.c | 5 +++-- tests/ipmi-kcs-test.c | 7 ++----- tests/ipoctal232-test.c | 3 ++- tests/ivshmem-test.c | 2 +- tests/m48t59-test.c | 2 +- tests/ne2000-test.c | 2 +- tests/nvme-test.c | 5 +++-- tests/pcnet-test.c | 2 +- tests/postcopy-test.c | 4 ++-- tests/pvpanic-test.c | 2 +- tests/q35-test.c | 4 ++-- tests/qmp-test.c | 4 ++-- tests/rtc-test.c | 2 +- tests/rtl8139-test.c | 2 +- tests/spapr-phb-test.c | 5 +++-- tests/test-arm-mptimer.c | 2 +- tests/test-x86-cpuid-compat.c | 7 ++++--- tests/tmp105-test.c | 1 + tests/tpci200-test.c | 2 +- tests/usb-hcd-ehci-test.c | 23 ++++++++++++----------- tests/usb-hcd-ohci-test.c | 2 +- tests/usb-hcd-xhci-test.c | 5 +++-- tests/virtio-balloon-test.c | 2 +- tests/virtio-console-test.c | 10 ++++------ tests/virtio-net-test.c | 2 +- tests/virtio-rng-test.c | 2 +- tests/virtio-serial-test.c | 2 +- tests/vmxnet3-test.c | 2 +- tests/wdt_ib700-test.c | 8 ++++---- 42 files changed, 101 insertions(+), 128 deletions(-)
tests/libqtest.h +4 -29
@@ -27,7 +27,7 @@ extern QTestState *global_qtest;* qtest_start_without_qmp_handshake: * @extra_args: other arguments to pass to QEMU. * -* Returns: #QTestState instance. Does not affect #global_qtest. +* Returns: #QTestState instance, handshaking not yet completed. */ QTestState *qtest_start_without_qmp_handshake (const char *extra_args);
@@ -35,10 +35,7 @@ QTestState *qtest_start_without_qmp_handshake(const char *extra_args);* qtest_start: * @args: other arguments to pass to QEMU * -* Start QEMU and assign the resulting #QTestState to #global_qtest. -* The global variable is used by "shortcut" functions documented below. -* -* Returns: #QTestState instance. +* Returns: #QTestState instance, handshaking completed. */ QTestState *qtest_start (const char *args);
@@ -47,10 +44,7 @@ QTestState *qtest_start(const char *args);* @fmt...: Format for creating other arguments to pass to QEMU, formatted * like sprintf(). * -* Start QEMU and return the resulting #QTestState (but unlike qtest_start(), -* #global_qtest is left at NULL). -* -* Returns: #QTestState instance. +* Returns: #QTestState instance, handshaking completed. */ QTestState *qtest_startf (const char *fmt, ...)GCC_FMT_ATTR (1 ,2 );
@@ -60,30 +54,11 @@ QTestState *qtest_startf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);* like vsprintf(). * @ap: Format arguments. * -* Start QEMU and return the resulting #QTestState (but unlike qtest_start(), -* #global_qtest is left at NULL). -* -* Returns: #QTestState instance. +* Returns: #QTestState instance, handshaking completed. */ QTestState *qtest_vstartf (const char *fmt,va_list ap)GCC_FMT_ATTR (1 ,0 );/** -* qtest_init: -* @extra_args: other arguments to pass to QEMU. -* -* Returns: #QTestState instance. Does not affect #global_qtest. -*/ -static inline QTestState *qtest_init (const char *extra_args) -{ -QTestState *s; - -assert (!global_qtest); - s =qtest_start (extra_args); - global_qtest =NULL ; -return s; -} - -/** * qtest_quit: * @s: #QTestState instance to operate on. *
tests/libqtest.c +2 -2
@@ -242,7 +242,7 @@ QTestState *qtest_start(const char *extra_args)qtest_qmp_discard_response (s,"{ 'execute': 'qmp_capabilities' }" );assert (!global_qtest); -return global_qtest = s; +return s; }QTestState *qtest_vstartf (const char *fmt,va_list ap)
@@ -988,7 +988,7 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine))QString *qstr;const char *mname; -qtest_start ("-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
@@ -22,7 +22,7 @@ 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_start ("-device AC97" ); ret =g_test_run ();qtest_quit (global_qtest);
tests/device-introspect-test.c +6 -6
@@ -126,7 +126,7 @@ static void test_device_intro_list(void)QList *types;char *help; -qtest_start (common_args); + global_qtest =qtest_start (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; -qtest_start (common_args); + global_qtest =qtest_start (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 ) { -qtest_start (common_args); + global_qtest =qtest_start (common_args);test_one_device ("nonexistent" );qtest_quit (global_qtest); }static void test_device_intro_abstract (void ) { -qtest_start (common_args); + global_qtest =qtest_start (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; -qtest_start (common_args); + global_qtest =qtest_start (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; -qtest_start (common_args); + global_qtest =qtest_start (common_args); all_types =qom_list_types ("interface" , true); index =qom_type_index (all_types);
tests/display-vga-test.c +6 -12
@@ -12,39 +12,33 @@static void pci_cirrus (void ) { -qtest_start ("-vga none -device cirrus-vga" ); -qtest_quit (global_qtest); +qtest_quit (qtest_start ("-vga none -device cirrus-vga" )); }static void pci_stdvga (void ) { -qtest_start ("-vga none -device VGA" ); -qtest_quit (global_qtest); +qtest_quit (qtest_start ("-vga none -device VGA" )); }static void pci_secondary (void ) { -qtest_start ("-vga none -device secondary-vga" ); -qtest_quit (global_qtest); +qtest_quit (qtest_start ("-vga none -device secondary-vga" )); }static void pci_multihead (void ) { -qtest_start ("-vga none -device VGA -device secondary-vga" ); -qtest_quit (global_qtest); +qtest_quit (qtest_start ("-vga none -device VGA -device secondary-vga" )); }static void pci_virtio_gpu (void ) { -qtest_start ("-vga none -device virtio-gpu-pci" ); -qtest_quit (global_qtest); +qtest_quit (qtest_start ("-vga none -device virtio-gpu-pci" )); }#ifdef CONFIG_VIRTIO_VGA static void pci_virtio_vga (void ) { -qtest_start ("-vga none -device virtio-vga" ); -qtest_quit (global_qtest); +qtest_quit (qtest_start ("-vga none -device virtio-vga" )); }#endif
tests/drive_del-test.c +6 -5
@@ -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_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; -qtest_start ("-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,9 +92,10 @@ 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 */ -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_start ( +"-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
tests/es1370-test.c +1 -1
@@ -22,7 +22,7 @@ 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_start ("-device ES1370" ); ret =g_test_run ();qtest_quit (global_qtest);
tests/fdc-test.c +1 -1
@@ -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_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
@@ -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
@@ -241,7 +241,7 @@ static void test_ide_none(void)setup_common (argv,ARGV_SIZE ); args =g_strjoinv (" " , argv); -qtest_start (args); + global_qtest =qtest_start (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); -qtest_start (args); + global_qtest =qtest_start (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); -qtest_start (args); + global_qtest =qtest_start (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); -qtest_start (args); + global_qtest =qtest_start (args);g_strfreev (argv);g_free (args);test_cmos ();
tests/i440fx-test.c +1 -1
@@ -340,7 +340,7 @@ 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_start (cmdline);g_free (cmdline);/* QEMU has loaded the firmware (because qtest_start() only returns after
tests/i82801b11-test.c +2 -1
@@ -22,7 +22,8 @@ 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_start ("-machine q35 " +"-device i82801b11-bridge,bus=pcie.0,addr=1e.0" ); ret =g_test_run ();qtest_quit (global_qtest);
tests/intel-hda-test.c +4 -5
@@ -18,15 +18,14 @@/* 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_quit (global_qtest); +qtest_quit (qtest_start ("-device intel-hda,id=" HDA_ID CODEC_DEVICES )); }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_quit (global_qtest); +qtest_quit (qtest_start ( +"-machine q35 -device ich9-intel-hda,bus=pcie.0,addr=1b.0,id=" +HDA_ID CODEC_DEVICES )); }int main (int argc,char **argv)
tests/ioh3420-test.c +3 -2
@@ -22,8 +22,9 @@ 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_start ( +"-machine q35 -device ioh3420,bus=pcie.0,addr=1c.0,port=1," +"chassis=1,multifunction=on" ); ret =g_test_run ();qtest_quit (global_qtest);
tests/ipmi-kcs-test.c +2 -5
@@ -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" -" -device isa-ipmi-kcs,bmc=bmc0" ); -qtest_start (cmdline); -g_free (cmdline); + 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 -1
@@ -22,7 +22,8 @@ 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_start ("-device tpci200,id=ipack0 " +"-device ipoctal232,bus=ipack0.0" ); ret =g_test_run ();qtest_quit (global_qtest);
tests/ivshmem-test.c +1 -1
@@ -407,7 +407,7 @@ static void test_ivshmem_hotplug(void)gchar *opts;QTestState *qts; - qts =qtest_init ("" ); + qts =qtest_start ("" ); opts =g_strdup_printf ("'shm': '%s', 'size': '1M'" , tmpshm);
tests/m48t59-test.c +1 -1
@@ -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_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
@@ -22,7 +22,7 @@ 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_start ("-device ne2k_pci" ); ret =g_test_run ();qtest_quit (global_qtest);
tests/nvme-test.c +3 -2
@@ -22,8 +22,9 @@ 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_start ( +"-drive id=drv0,if=none,file=null-co://,format=raw " +"-device nvme,drive=drv0,serial=foo" ); ret =g_test_run ();qtest_quit (global_qtest);
tests/pcnet-test.c +1 -1
@@ -22,7 +22,7 @@ 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_start ("-device pcnet" ); ret =g_test_run ();qtest_quit (global_qtest);
tests/postcopy-test.c +2 -2
@@ -403,10 +403,10 @@ static void test_migrate(void)g_free (bootpath); - from =qtest_init (cmd_src); + from =qtest_start (cmd_src);g_free (cmd_src); - to =qtest_init (cmd_dst); + to =qtest_start (cmd_dst);g_free (cmd_dst);assert (!global_qtest);
tests/pvpanic-test.c +1 -1
@@ -37,7 +37,7 @@ 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_start ("-device pvpanic" ); ret =g_test_run ();qtest_quit (global_qtest);
tests/q35-test.c +2 -2
@@ -84,7 +84,7 @@ static void test_smram_lock(void)QPCIDevice *pcidev;QDict *response; -qtest_start ("-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 ); } -qtest_start (cmdline); + global_qtest =qtest_start (cmdline);g_free (cmdline);/* locate the DRAM controller */
tests/qmp-test.c +2 -2
@@ -172,7 +172,7 @@ static void test_query(const void *data)QDict *resp, *error;const char *error_class; -qtest_start (common_args); + global_qtest =qtest_start (common_args); resp =qmp ("{ 'execute': %s }" , cmd); error =qdict_get_qdict (resp,"error" );
@@ -224,7 +224,7 @@ static void qmp_schema_init(QmpSchema *schema)Visitor *qiv;SchemaInfoList *tail; -qtest_start (common_args); + global_qtest =qtest_start (common_args); resp =qmp ("{ 'execute': 'query-qmp-schema' }" ); qiv =qobject_input_visitor_new (qdict_get (resp,"return" ));
tests/rtc-test.c +1 -1
@@ -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_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
@@ -197,7 +197,7 @@ int main(int argc, char **argv) {int ret; -qtest_start ("-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 +3 -2
@@ -21,15 +21,16 @@ static void test_phb_device(void)int main (int argc,char **argv) {int ret; +QTestState *qts;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" ); + qts =qtest_start ("-device " TYPE_SPAPR_PCI_HOST_BRIDGE ",index=30" ); ret =g_test_run (); -qtest_quit (global_qtest); +qtest_quit (qts);return ret; }
tests/test-arm-mptimer.c +1 -1
@@ -1097,7 +1097,7 @@ tests_with_prescaler_arg: goto tests_with_prescaler_arg; } -qtest_start ("-machine vexpress-a9" ); + global_qtest =qtest_start ("-machine vexpress-a9" ); ret =g_test_run ();qtest_quit (global_qtest);
tests/test-x86-cpuid-compat.c +4 -3
@@ -59,7 +59,7 @@ static void test_cpuid_prop(const void *data)QNum *value;int64_t val; -qtest_start (args->cmdline); + global_qtest =qtest_start (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; -qtest_start (args->cmdline); + global_qtest =qtest_start (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,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_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 +1 -0
@@ -154,6 +154,7 @@ int main(int argc, char **argv) s =qtest_start ("-machine n800 " "-device tmp105,bus=i2c-bus.0,id=" TMP105_TEST_ID ",address=0x49" ); + global_qtest = s; i2c =omap_i2c_create (s,OMAP2_I2C_1_BASE );qtest_add_func ("/tmp105/tx-rx" , send_and_receive);
tests/tpci200-test.c +1 -1
@@ -22,7 +22,7 @@ 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_start ("-device tpci200" ); ret =g_test_run ();qtest_quit (global_qtest);
tests/usb-hcd-ehci-test.c +12 -11
@@ -156,17 +156,18 @@ 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_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 " );test_init (); ret =g_test_run ();
tests/usb-hcd-ohci-test.c +1 -1
@@ -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); -qtest_start ("-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
@@ -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); -qtest_start ("-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/virtio-balloon-test.c +1 -1
@@ -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); -qtest_start ("-device virtio-balloon-pci" ); + global_qtest =qtest_start ("-device virtio-balloon-pci" ); ret =g_test_run ();qtest_quit (global_qtest);
tests/virtio-console-test.c +4 -6
@@ -13,16 +13,14 @@/* Tests only initialization so far. TODO: Replace with functional tests */ static void console_pci_nop (void ) { -qtest_start ("-device virtio-serial-pci,id=vser0 " -"-device virtconsole,bus=vser0.0" ); -qtest_quit (global_qtest); +qtest_quit (qtest_start ("-device virtio-serial-pci,id=vser0 " +"-device virtconsole,bus=vser0.0" )); }static void serialport_pci_nop (void ) { -qtest_start ("-device virtio-serial-pci,id=vser0 " -"-device virtserialport,bus=vser0.0" ); -qtest_quit (global_qtest); +qtest_quit (qtest_start ("-device virtio-serial-pci,id=vser0 " +"-device virtserialport,bus=vser0.0" )); }int main (int argc,char **argv)
tests/virtio-net-test.c +1 -1
@@ -246,7 +246,7 @@ static void hotplug(void) {const char *arch =qtest_get_arch (); -qtest_start ("-device virtio-net-pci" ); + global_qtest =qtest_start ("-device virtio-net-pci" );qpci_plug_device_test (global_qtest,"virtio-net-pci" ,"net1" ,PCI_SLOT_HP ,NULL );
tests/virtio-rng-test.c +1 -1
@@ -38,7 +38,7 @@ 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_start ("-device virtio-rng-pci" ); ret =g_test_run ();qtest_quit (global_qtest);
tests/virtio-serial-test.c +1 -1
@@ -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); -qtest_start ("-device virtio-serial-pci" ); + global_qtest =qtest_start ("-device virtio-serial-pci" ); ret =g_test_run ();qtest_quit (global_qtest);
tests/vmxnet3-test.c +1 -1
@@ -22,7 +22,7 @@ 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_start ("-device vmxnet3" ); ret =g_test_run ();qtest_quit (global_qtest);
tests/wdt_ib700-test.c +4 -4
@@ -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
Re: [Qemu-devel] [PATCH v7 29/38] libqtest: Merge qtest_init() into qtest_start()
Quoted 8 lines · Eric Blake
Remove the trivial wrapper
qtest_init(), and changeqtest_start()to no longer implicitly setglobal_qtest, to make it obvious in the rest of the testsuite where we are still relying onglobal_qtest. Everything now usesqtest_start()(and friends) andqtest_quit(), and explicitly tracks the QTestState between the two (although in many cases, this tracking is still done throughglobal_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.
[...]
tests/libqtest.h extern QTestState *global_qtest; · line 30
Quoted 10 lines
tests/libqtest.h +1
-1@@ -27,7 +27,7 @@ extern QTestState *global_qtest;* qtest_start_without_qmp_handshake: * @extra_args: other arguments to pass to QEMU. * -* Returns: #QTestState instance. Does not affect #global_qtest. +* Returns: #QTestState instance, handshaking not yet completed.
I'd rather add a description a la:
* Start QEMU, but do not execute the QMP handshake yet. *
* Returns: #QTestState instance
tests/libqtest.h QTestState *qtest_start_without_qmp_handshake(const char *extra_args); · line 39
Quoted 12 lines
tests/libqtest.h +1
-3*/ QTestState *qtest_start_without_qmp_handshake (const char *extra_args);@@ -35,10 +35,7 @@ QTestState *qtest_start_without_qmp_handshake(const char *extra_args);* qtest_start: * @args: other arguments to pass to QEMU * -* Start QEMU and assign the resulting #QTestState to #global_qtest. -* The global variable is used by "shortcut" functions documented below. * -* Returns: #QTestState instance. +* Returns: #QTestState instance, handshaking completed.
I'd rather change the description instead of removing it:
* Start QEMU and execute the initial QMP handshake *
* Returns: #QTestState instance.
tests/libqtest.h QTestState *qtest_start(const char *args); · line 47
Quoted 12 lines
tests/libqtest.h +1
-4*/ QTestState *qtest_start (const char *args);@@ -47,10 +44,7 @@ QTestState *qtest_start(const char *args);* @fmt...: Format for creating other arguments to pass to QEMU, formatted * like sprintf(). * -* Start QEMU and return the resulting #QTestState (but unlike qtest_start(), -* #global_qtest is left at NULL). -* -* Returns: #QTestState instance. +* Returns: #QTestState instance, handshaking completed.
dito
tests/libqtest.h QTestState *qtest_startf(const char *fmt, ...) GCC_FMT_ATTR(1, 2); · line 57
Quoted 12 lines
tests/libqtest.h +1
-4*/ QTestState *qtest_startf (const char *fmt, ...)GCC_FMT_ATTR (1 ,2 );@@ -60,30 +54,11 @@ QTestState *qtest_startf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);* like vsprintf(). * @ap: Format arguments. * -* Start QEMU and return the resulting #QTestState (but unlike qtest_start(), -* #global_qtest is left at NULL). -* -* Returns: #QTestState instance. +* Returns: #QTestState instance, handshaking completed.
dito
Quoted 18 lines
tests/libqtest.h +0
-14*/ QTestState *qtest_vstartf (const char *fmt,va_list ap)GCC_FMT_ATTR (1 ,0 );/** -* qtest_init: -* @extra_args: other arguments to pass to QEMU. -* -* Returns: #QTestState instance. Does not affect #global_qtest. -*/ -static inline QTestState *qtest_init (const char *extra_args) -{ -QTestState *s; - -assert (!global_qtest); - s =qtest_start (extra_args); - global_qtest =NULL ; -return s; -}
[...]
tests/display-vga-test.c line 15
Quoted 11 lines
tests/display-vga-test.c +1
-2@@ -12,39 +12,33 @@static void pci_cirrus (void ) { -qtest_start ("-vga none -device cirrus-vga" ); -qtest_quit (global_qtest); +qtest_quit (qtest_start ("-vga none -device cirrus-vga" ));
I'd prefer to keep this on separate lines ... but that's again just my personal taste. (also for the othe changes below)
Quoted 38 lines
tests/display-vga-test.c +5
-10}static void pci_stdvga (void ) { -qtest_start ("-vga none -device VGA" ); -qtest_quit (global_qtest); +qtest_quit (qtest_start ("-vga none -device VGA" )); }static void pci_secondary (void ) { -qtest_start ("-vga none -device secondary-vga" ); -qtest_quit (global_qtest); +qtest_quit (qtest_start ("-vga none -device secondary-vga" )); }static void pci_multihead (void ) { -qtest_start ("-vga none -device VGA -device secondary-vga" ); -qtest_quit (global_qtest); +qtest_quit (qtest_start ("-vga none -device VGA -device secondary-vga" )); }static void pci_virtio_gpu (void ) { -qtest_start ("-vga none -device virtio-gpu-pci" ); -qtest_quit (global_qtest); +qtest_quit (qtest_start ("-vga none -device virtio-gpu-pci" )); }#ifdef CONFIG_VIRTIO_VGA static void pci_virtio_vga (void ) { -qtest_start ("-vga none -device virtio-vga" ); -qtest_quit (global_qtest); +qtest_quit (qtest_start ("-vga none -device virtio-vga" )); }#endif
[...]
tests/ne2000-test.c int main(int argc, char **argv) · line 28
Quoted 13 lines
tests/ne2000-test.c +1
-1@@ -22,7 +22,7 @@ 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_start ("-device ne2k_pci" ); ret =g_test_run ();qtest_quit (global_qtest);
For such very trivial tests, it maybe makes sense to use a local "QTestState *qts" variable here already, so we don't have to touch this code again later?
Quoted 6 lines
tests/nvme-test.c +0
-0@@ -22,8 +22,9 @@ int main(int argc, char **argv)g_test_init (&argc, &argv,NULL );
tests/nvme-test.c int main(int argc, char **argv) · line 30
Quoted 10 lines
tests/nvme-test.c +3
-2qtest_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_start ( +"-drive id=drv0,if=none,file=null-co://,format=raw " +"-device nvme,drive=drv0,serial=foo" ); ret =g_test_run ();qtest_quit (global_qtest);
dito
tests/pcnet-test.c int main(int argc, char **argv) · line 28
Quoted 13 lines
tests/pcnet-test.c +1
-1@@ -22,7 +22,7 @@ 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_start ("-device pcnet" ); ret =g_test_run ();qtest_quit (global_qtest);
dito
[...]
tests/virtio-balloon-test.c int main(int argc, char **argv) · line 28
Quoted 13 lines
tests/virtio-balloon-test.c +1
-1@@ -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); -qtest_start ("-device virtio-balloon-pci" ); + global_qtest =qtest_start ("-device virtio-balloon-pci" ); ret =g_test_run ();qtest_quit (global_qtest);
dito
[...]
tests/vmxnet3-test.c int main(int argc, char **argv) · line 28
Quoted 13 lines
tests/vmxnet3-test.c +1
-1@@ -22,7 +22,7 @@ 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_start ("-device vmxnet3" ); ret =g_test_run ();qtest_quit (global_qtest);
dito
Thomas
PATCH v7 30/38 qtest: Avoid passing raw strings through hmp()
In reply to Eric Blakehmp() passes its string argument through the sprintf() family; with a proper attribute, gcc -Wformat warns us when we do something dangerous like passing a non-constant format string. Fortunately, all our strings were safe, but checking whether the string can contain an unintended % is easy to avoid and therefore worth doing.
---
v7: add GCC_FMT_ATTR here, drop R-b
--- tests/libqtest.h | 8 ++++---- tests/test-hmp.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
tests/libqtest.h +4 -4
@@ -153,14 +153,14 @@ QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event);/** * qtest_hmp: * @s: #QTestState instance to operate on. -* @fmt...: HMP command to send to QEMU +* @fmt...: HMP command to send to QEMU, formats arguments like sprintf(). * * Send HMP command to QEMU via QMP's human-monitor-command. * QMP events are discarded. * * Returns: the command's output. The caller should g_free() it. */ -char *qtest_hmp (QTestState *s,const char *fmt, ...); +char *qtest_hmp (QTestState *s,const char *fmt, ...)GCC_FMT_ATTR (2 ,3 );/** * qtest_hmpv:
@@ -585,13 +585,13 @@ static inline QDict *qmp_eventwait_ref(const char *event)/** * hmp: -* @fmt...: HMP command to send to QEMU +* @fmt...: HMP command to send to QEMU, formats arguments like sprintf(). * * Send HMP command to QEMU via QMP's human-monitor-command. * * Returns: the command's output. The caller should g_free() it. */ -char *hmp (const char *fmt, ...); +char *hmp (const char *fmt, ...)GCC_FMT_ATTR (1 ,2 );/** * get_irq:
tests/test-hmp.c +2 -2
@@ -80,7 +80,7 @@ static void test_commands(void)if (verbose) {fprintf (stderr,"\t%s\n" , hmp_cmds[i]); } - response =hmp (hmp_cmds[i]); + response =hmp ("%s" , hmp_cmds[i]);g_free (response); }
@@ -103,7 +103,7 @@ static void test_info_commands(void)if (verbose) {fprintf (stderr,"\t%s\n" , info); } - resp =hmp (info); + resp =hmp ("%s" , info);g_free (resp);/* And move forward to the next line */ info =strchr (endp +1 ,'\n' );
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PATCH v7 30/38] qtest: Avoid passing raw strings through hmp()
Quoted 8 lines · * Eric Blake ([email protected]) wrote:
hmp()passes its string argument through thesprintf()family; with a proper attribute, gcc -Wformat warns us when we do something dangerous like passing a non-constant format string. Fortunately, all our strings were safe, but checking whether the string can contain an unintended % is easy to avoid and therefore worth doing.Signed-off-by Eric Blake <[email protected]>
Quoted 69 lines
---
v7: addGCC_FMT_ATTRhere, drop R-b--- tests/libqtest.h | 8 ++++---- tests/test-hmp.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)tests/libqtest.h +4
-4@@ -153,14 +153,14 @@ QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event);/** * qtest_hmp: * @s: #QTestState instance to operate on. -* @fmt...: HMP command to send to QEMU +* @fmt...: HMP command to send to QEMU, formats arguments like sprintf(). * * Send HMP command to QEMU via QMP's human-monitor-command. * QMP events are discarded. * * Returns: the command's output. The caller should g_free() it. */ -char *qtest_hmp (QTestState *s,const char *fmt, ...); +char *qtest_hmp (QTestState *s,const char *fmt, ...)GCC_FMT_ATTR (2 ,3 );/** * qtest_hmpv: @@ -585,13 +585,13 @@ static inline QDict *qmp_eventwait_ref(const char *event)/** * hmp: -* @fmt...: HMP command to send to QEMU +* @fmt...: HMP command to send to QEMU, formats arguments like sprintf(). * * Send HMP command to QEMU via QMP's human-monitor-command. * * Returns: the command's output. The caller should g_free() it. */ -char *hmp (const char *fmt, ...); +char *hmp (const char *fmt, ...)GCC_FMT_ATTR (1 ,2 );/** * get_irq: tests/test-hmp.c +2
-2@@ -80,7 +80,7 @@ static void test_commands(void)if (verbose) {fprintf (stderr,"\t%s\n" , hmp_cmds[i]); } - response =hmp (hmp_cmds[i]); + response =hmp ("%s" , hmp_cmds[i]);g_free (response); }@@ -103,7 +103,7 @@ static void test_info_commands(void)if (verbose) {fprintf (stderr,"\t%s\n" , info); } - resp =hmp (info); + resp =hmp ("%s" , info);g_free (resp);/* And move forward to the next line */ info =strchr (endp +1 ,'\n' );Signature · 1 line
2.13.5
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH v7 30/38] qtest: Avoid passing raw strings through hmp()
In reply to Eric BlakeQuoted 6 lines · Eric Blake
hmp()passes its string argument through thesprintf()family; with a proper attribute, gcc -Wformat warns us when we do something dangerous like passing a non-constant format string. Fortunately, all our strings were safe, but checking whether the string can contain an unintended % is easy to avoid and therefore worth doing.
Quoted 8 lines
Signed-off-by Eric Blake <[email protected]>---
v7: addGCC_FMT_ATTRhere, drop R-b--- tests/libqtest.h | 8 ++++---- tests/test-hmp.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
PATCH v7 31/38 libqtest: Merge qtest_clock_*() with clock_*()
In reply to Eric BlakeMaintaining two layers of libqtest APIs, one that takes an explicit QTestState object, and the other that uses the implicit global_qtest, is annoying. In the interest of getting rid of global implicit state and having less code to maintain, merge:
qtest_clock_set()
qtest_clock_step()
qtest_clock_step_next()
with their short counterparts. All callers that previously used the short form now make it explicit that they are relying on global_qtest, and later patches can then clean things up to remove the global variable.
--- tests/libqtest.h | 50 ++++---------------------------- tests/libqtest.c | 6 ++-- tests/e1000e-test.c | 2 +- tests/fdc-test.c | 4 +-- tests/ide-test.c | 2 +- tests/libqos/virtio.c | 8 +++--- tests/rtc-test.c | 74 ++++++++++++++++++++++++------------------------ tests/rtl8139-test.c | 10 +++---- tests/tco-test.c | 22 +++++++------- tests/test-arm-mptimer.c | 25 +++++++++------- tests/wdt_ib700-test.c | 12 ++++---- 11 files changed, 90 insertions(+), 125 deletions(-)
tests/libqtest.h +6 -44
@@ -417,17 +417,17 @@ void qtest_bufwrite(QTestState *s, uint64_t addr,void qtest_memset (QTestState *s,uint64_t addr,uint8_t patt,size_t size);/** -* qtest_clock_step_next: +* clock_step_next: * @s: #QTestState instance to operate on. * * Advance the QEMU_CLOCK_VIRTUAL to the next deadline. * * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. */ -int64_t qtest_clock_step_next (QTestState *s); +int64_t clock_step_next (QTestState *s);/** -* qtest_clock_step: +* clock_step: * @s: QTestState instance to operate on. * @step: Number of nanoseconds to advance the clock by. *
@@ -435,10 +435,10 @@ int64_t qtest_clock_step_next(QTestState *s);* * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. */ -int64_t qtest_clock_step (QTestState *s,int64_t step); +int64_t clock_step (QTestState *s,int64_t step);/** -* qtest_clock_set: +* clock_set: * @s: QTestState instance to operate on. * @val: Nanoseconds value to advance the clock to. *
@@ -446,7 +446,7 @@ int64_t qtest_clock_step(QTestState *s, int64_t step);* * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. */ -int64_t qtest_clock_set (QTestState *s,int64_t val); +int64_t clock_set (QTestState *s,int64_t val);/** * qtest_big_endian:
@@ -868,44 +868,6 @@ static inline void qmemset(uint64_t addr, uint8_t patt, size_t size)qtest_memset (global_qtest, addr, patt, size); } -/** -* clock_step_next: -* -* Advance the QEMU_CLOCK_VIRTUAL to the next deadline. -* -* Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. -*/ -static inline int64_t clock_step_next (void ) -{ -return qtest_clock_step_next (global_qtest); -} - -/** -* clock_step: -* @step: Number of nanoseconds to advance the clock by. -* -* Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds. -* -* Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. -*/ -static inline int64_t clock_step (int64_t step) -{ -return qtest_clock_step (global_qtest, step); -} - -/** -* clock_set: -* @val: Nanoseconds value to advance the clock to. -* -* Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched. -* -* Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. -*/ -static inline int64_t clock_set (int64_t val) -{ -return qtest_clock_set (global_qtest, val); -} -QDict *qmp_fd_receive (int fd);void qmp_fd_sendv (int fd,const char *fmt,va_list ap);void qmp_fd_send (int fd,const char *fmt, ...);
tests/libqtest.c +3 -3
@@ -666,19 +666,19 @@ static int64_t qtest_clock_rsp(QTestState *s)return clock; } -int64_t qtest_clock_step_next (QTestState *s) +int64_t clock_step_next (QTestState *s) {qtest_sendf (s,"clock_step\n" );return qtest_clock_rsp (s); } -int64_t qtest_clock_step (QTestState *s,int64_t step) +int64_t clock_step (QTestState *s,int64_t step) {qtest_sendf (s,"clock_step %" PRIi64"\n" , step);return qtest_clock_rsp (s); } -int64_t qtest_clock_set (QTestState *s,int64_t val) +int64_t clock_set (QTestState *s,int64_t val) {qtest_sendf (s,"clock_set %" PRIi64"\n" , val);return qtest_clock_rsp (s);
tests/e1000e-test.c +1 -1
@@ -229,7 +229,7 @@ static void e1000e_wait_isr(e1000e_device *d, uint16_t msg_id)if (qpci_msix_pending (d->pci_dev, msg_id)) {return ; } -clock_step (10000 ); +clock_step (global_qtest,10000 ); }while (g_get_monotonic_time () < end_time);g_error ("Timeout expired" );
tests/fdc-test.c +2 -2
@@ -424,7 +424,7 @@ static void test_read_id(void)while (!get_irq (FLOPPY_IRQ )) {/* qemu involves a timer with READ ID... */ -clock_step (1000000000LL /50 ); +clock_step (global_qtest,1000000000LL /50 ); } msr =inb (FLOPPY_BASE + reg_msr);
@@ -467,7 +467,7 @@ static void test_read_id(void)while (!get_irq (FLOPPY_IRQ )) {/* qemu involves a timer with READ ID... */ -clock_step (1000000000LL /50 ); +clock_step (global_qtest,1000000000LL /50 ); } msr =inb (FLOPPY_BASE + reg_msr);
tests/ide-test.c +1 -1
@@ -749,7 +749,7 @@ static void nsleep(int64_t nsecs) {const struct timespec val = { .tv_nsec = nsecs };nanosleep (&val,NULL ); -clock_set (nsecs); +clock_set (global_qtest, nsecs); }static uint8_t ide_wait_clear (uint8_t flag)
tests/libqos/virtio.c +4 -4
@@ -97,7 +97,7 @@ void qvirtio_wait_queue_isr(QVirtioDevice *d,gint64 start_time =g_get_monotonic_time ();for (;;) { -qtest_clock_step (d->bus->qts,100 ); +clock_step (d->bus->qts,100 );if (d->bus->get_queue_isr_status (d, vq)) {return ; }
@@ -119,7 +119,7 @@ uint8_t qvirtio_wait_status_byte_no_isr(QVirtioDevice *d,uint8_t val;while ((val =qtest_readb (d->bus->qts, addr)) ==0xff ) { -qtest_clock_step (d->bus->qts,100 ); +clock_step (d->bus->qts,100 );g_assert (!d->bus->get_queue_isr_status (d, vq));g_assert (g_get_monotonic_time () - start_time <= timeout_us); }
@@ -143,7 +143,7 @@ void qvirtio_wait_used_elem(QVirtioDevice *d,for (;;) {uint32_t got_desc_idx; -qtest_clock_step (d->bus->qts,100 ); +clock_step (d->bus->qts,100 );if (d->bus->get_queue_isr_status (d, vq) &&qvirtqueue_get_buf (vq, &got_desc_idx)) {
@@ -160,7 +160,7 @@ void qvirtio_wait_config_isr(QVirtioDevice *d, gint64 timeout_us)gint64 start_time =g_get_monotonic_time ();for (;;) { -qtest_clock_step (d->bus->qts,100 ); +clock_step (d->bus->qts,100 );if (d->bus->get_config_isr_status (d)) {return ; }
tests/rtc-test.c +37 -37
239 lines not on this page · raw message
tests/rtl8139-test.c +5 -5
@@ -84,7 +84,7 @@ static void test_timer(void)fatal ("time too big %u\n" , curr); }for (cnt =0 ; ; ) { -clock_step (1 *NANOSECONDS_PER_SECOND ); +clock_step (global_qtest,1 *NANOSECONDS_PER_SECOND ); prev = curr; curr =in_Timer ();
@@ -106,7 +106,7 @@ static void test_timer(void)/* Test 3. Setting TimerInt to 1 and Timer to 0 get interrupt */ out_TimerInt (1 );out_Timer (0 ); -clock_step (40 ); +clock_step (global_qtest,40 );if ((in_IntrStatus () &0x4000 ) ==0 ) {fatal ("we should have an interrupt here!\n" ); }
@@ -123,7 +123,7 @@ static void test_timer(void)out_IntrStatus (0x4000 ); curr =in_Timer ();out_TimerInt (curr +0.5 *CLK ); -clock_step (1 *NANOSECONDS_PER_SECOND ); +clock_step (global_qtest,1 *NANOSECONDS_PER_SECOND );out_Timer (0 );if ((in_IntrStatus () &0x4000 ) ==0 ) {fatal ("we should have an interrupt here!\n" );
@@ -135,7 +135,7 @@ static void test_timer(void)out_IntrStatus (0x4000 ); curr =in_Timer ();out_TimerInt (curr +0.5 *CLK ); -clock_step (1 *NANOSECONDS_PER_SECOND ); +clock_step (global_qtest,1 *NANOSECONDS_PER_SECOND );out_TimerInt (0 );if ((in_IntrStatus () &0x4000 ) ==0 ) {fatal ("we should have an interrupt here!\n" );
@@ -146,7 +146,7 @@ static void test_timer(void) next = curr +5.0 *CLK ;out_TimerInt (next);for (cnt =0 ; ; ) { -clock_step (1 *NANOSECONDS_PER_SECOND ); +clock_step (global_qtest,1 *NANOSECONDS_PER_SECOND ); prev = curr; curr =in_Timer (); diff = (curr-prev) &0xffffffffu ;
tests/tco-test.c +11 -11
@@ -173,7 +173,7 @@ static void test_tco_timeout(void)set_tco_timeout (&d, ticks);load_tco (&d);start_tco (&d); -clock_step (ticks *TCO_TICK_NSEC ); +clock_step (global_qtest, ticks *TCO_TICK_NSEC );/* test first timeout */ val =qpci_io_readw (d.dev, d.tco_io_bar,TCO1_STS );
@@ -188,7 +188,7 @@ static void test_tco_timeout(void)g_assert (ret ==0 );/* test second timeout */ -clock_step (ticks *TCO_TICK_NSEC ); +clock_step (global_qtest, ticks *TCO_TICK_NSEC ); val =qpci_io_readw (d.dev, d.tco_io_bar,TCO1_STS ); ret = val &TCO_TIMEOUT ?1 :0 ;g_assert (ret ==1 );
@@ -217,14 +217,14 @@ static void test_tco_max_timeout(void)set_tco_timeout (&d, ticks);load_tco (&d);start_tco (&d); -clock_step (((ticks &TCO_TMR_MASK ) -1 ) *TCO_TICK_NSEC ); +clock_step (global_qtest, ((ticks &TCO_TMR_MASK ) -1 ) *TCO_TICK_NSEC ); val =qpci_io_readw (d.dev, d.tco_io_bar,TCO_RLD ); g_assert_cmpint(val & TCO_RLD_MASK, ==, 1); val =qpci_io_readw (d.dev, d.tco_io_bar,TCO1_STS ); ret = val &TCO_TIMEOUT ?1 :0 ;g_assert (ret ==0 ); -clock_step (TCO_TICK_NSEC ); +clock_step (global_qtest,TCO_TICK_NSEC ); val =qpci_io_readw (d.dev, d.tco_io_bar,TCO1_STS ); ret = val &TCO_TIMEOUT ?1 :0 ;g_assert (ret ==1 );
@@ -260,7 +260,7 @@ static void test_tco_second_timeout_pause(void)set_tco_timeout (&td,TCO_SECS_TO_TICKS (16 ));load_tco (&td);start_tco (&td); -clock_step (ticks *TCO_TICK_NSEC *2 ); +clock_step (global_qtest, ticks *TCO_TICK_NSEC *2 ); ad =get_watchdog_action ();g_assert (!strcmp (qdict_get_str (ad,"action" ),"pause" ));QDECREF (ad);
@@ -285,7 +285,7 @@ static void test_tco_second_timeout_reset(void)set_tco_timeout (&td,TCO_SECS_TO_TICKS (16 ));load_tco (&td);start_tco (&td); -clock_step (ticks *TCO_TICK_NSEC *2 ); +clock_step (global_qtest, ticks *TCO_TICK_NSEC *2 ); ad =get_watchdog_action ();g_assert (!strcmp (qdict_get_str (ad,"action" ),"reset" ));QDECREF (ad);
@@ -310,7 +310,7 @@ static void test_tco_second_timeout_shutdown(void)set_tco_timeout (&td, ticks);load_tco (&td);start_tco (&td); -clock_step (ticks *TCO_TICK_NSEC *2 ); +clock_step (global_qtest, ticks *TCO_TICK_NSEC *2 ); ad =get_watchdog_action ();g_assert (!strcmp (qdict_get_str (ad,"action" ),"shutdown" ));QDECREF (ad);
@@ -335,7 +335,7 @@ static void test_tco_second_timeout_none(void)set_tco_timeout (&td, ticks);load_tco (&td);start_tco (&td); -clock_step (ticks *TCO_TICK_NSEC *2 ); +clock_step (global_qtest, ticks *TCO_TICK_NSEC *2 ); ad =get_watchdog_action ();g_assert (!strcmp (qdict_get_str (ad,"action" ),"none" ));QDECREF (ad);
@@ -364,7 +364,7 @@ static void test_tco_ticks_counter(void)do { rld =qpci_io_readw (d.dev, d.tco_io_bar,TCO_RLD ) &TCO_RLD_MASK ; g_assert_cmpint(rld, ==, ticks); -clock_step (TCO_TICK_NSEC ); +clock_step (global_qtest,TCO_TICK_NSEC ); ticks--; }while (!(qpci_io_readw (d.dev, d.tco_io_bar,TCO1_STS ) &TCO_TIMEOUT ));
@@ -407,7 +407,7 @@ static void test_tco1_status_bits(void)set_tco_timeout (&d, ticks);load_tco (&d);start_tco (&d); -clock_step (ticks *TCO_TICK_NSEC ); +clock_step (global_qtest, ticks *TCO_TICK_NSEC );qpci_io_writeb (d.dev, d.tco_io_bar,TCO_DAT_IN ,0 );qpci_io_writeb (d.dev, d.tco_io_bar,TCO_DAT_OUT ,0 );
@@ -436,7 +436,7 @@ static void test_tco2_status_bits(void)set_tco_timeout (&d, ticks);load_tco (&d);start_tco (&d); -clock_step (ticks *TCO_TICK_NSEC *2 ); +clock_step (global_qtest, ticks *TCO_TICK_NSEC *2 ); val =qpci_io_readw (d.dev, d.tco_io_bar,TCO2_STS ); ret = val & (TCO_SECOND_TO_STS |TCO_BOOT_STS ) ?1 :0 ;
tests/test-arm-mptimer.c +14 -11
@@ -14,7 +14,8 @@#define TIMER_BLOCK_SCALE (s) ((((s) & 0xff) + 1) * 10)#define TIMER_BLOCK_STEP (scaler, steps_nb) \ - clock_step(TIMER_BLOCK_SCALE(scaler) * (int64_t)(steps_nb) + 1) + clock_step(global_qtest, \ + TIMER_BLOCK_SCALE(scaler) * (int64_t)(steps_nb) + 1)#define TIMER_BASE_PHYS 0x1e000600
@@ -185,12 +186,14 @@ static void test_timer_periodic(gconstpointer arg)timer_start (PERIODIC , scaler);while (repeat--) { -clock_step (TIMER_BLOCK_SCALE (scaler) * (101 + repeat) +1 ); +clock_step (global_qtest, +TIMER_BLOCK_SCALE (scaler) * (101 + repeat) +1 ); g_assert_cmpuint(timer_counter(), ==, 100 - repeat); g_assert_cmpuint(timer_get_and_clr_int_sts(), ==, 1); -clock_step (TIMER_BLOCK_SCALE (scaler) * (101 - repeat) -1 ); +clock_step (global_qtest, +TIMER_BLOCK_SCALE (scaler) * (101 - repeat) -1 ); } }
@@ -686,10 +689,10 @@ static void test_periodic_counter(gconstpointer arg)timer_load (test_load);timer_start (PERIODIC , scaler); -clock_step (1 ); +clock_step (global_qtest,1 );for (test_val =0 ; test_val <= test_load; test_val++) { -clock_step (TIMER_BLOCK_SCALE (scaler) * test_load); +clock_step (global_qtest,TIMER_BLOCK_SCALE (scaler) * test_load); g_assert_cmpint(timer_counter(), ==, test_val); } }
@@ -783,7 +786,7 @@ again:timer_reset ();timer_start (mode,255 ); -clock_step (100 ); +clock_step (global_qtest,100 ); g_assert_cmpuint(timer_counter(), ==, 0);
@@ -795,7 +798,7 @@ again:timer_load (2 );timer_start (mode,255 ); -clock_step (100 ); +clock_step (global_qtest,100 ); g_assert_cmpuint(timer_get_and_clr_int_sts(), ==, 0);
@@ -811,13 +814,13 @@ again:timer_load (UINT32_MAX );timer_start (mode,255 ); -clock_step (100 ); +clock_step (global_qtest,100 ); g_assert_cmpuint(timer_get_and_clr_int_sts(), ==, 0);timer_set_counter (0 ); -clock_step (100 ); +clock_step (global_qtest,100 ); g_assert_cmpuint(timer_get_and_clr_int_sts(), ==, 0);
@@ -829,13 +832,13 @@ again:timer_load (UINT32_MAX );timer_start (mode,255 ); -clock_step (100 ); +clock_step (global_qtest,100 ); g_assert_cmpuint(timer_get_and_clr_int_sts(), ==, 0);timer_load (0 ); -clock_step (100 ); +clock_step (global_qtest,100 ); g_assert_cmpuint(timer_get_and_clr_int_sts(), ==, 0);
tests/wdt_ib700-test.c +6 -6
@@ -22,29 +22,29 @@ static QDict *ib700_program_and_wait(QTestState *s) {QDict *event, *data; -qtest_clock_step (s,NANOSECONDS_PER_SECOND *40 ); +clock_step (s,NANOSECONDS_PER_SECOND *40 );qmp_check_no_event (s);/* 2 second limit */ qtest_outb (s,0x443 ,14 );/* Ping */ -qtest_clock_step (s,NANOSECONDS_PER_SECOND ); +clock_step (s,NANOSECONDS_PER_SECOND );qmp_check_no_event (s);qtest_outb (s,0x443 ,14 );/* Disable */ -qtest_clock_step (s,NANOSECONDS_PER_SECOND ); +clock_step (s,NANOSECONDS_PER_SECOND );qmp_check_no_event (s);qtest_outb (s,0x441 ,1 ); -qtest_clock_step (s,3 *NANOSECONDS_PER_SECOND ); +clock_step (s,3 *NANOSECONDS_PER_SECOND );qmp_check_no_event (s);/* Enable and let it fire */ qtest_outb (s,0x443 ,13 ); -qtest_clock_step (s,3 *NANOSECONDS_PER_SECOND ); +clock_step (s,3 *NANOSECONDS_PER_SECOND );qmp_check_no_event (s); -qtest_clock_step (s,2 *NANOSECONDS_PER_SECOND ); +clock_step (s,2 *NANOSECONDS_PER_SECOND ); event =qtest_qmp_eventwait_ref (s,"WATCHDOG" ); data =qdict_get_qdict (event,"data" );QINCREF (data);
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PATCH v7 31/38] libqtest: Merge qtest_clock_*() with clock_*()
Quoted 66 lines · Eric Blake
Maintaining two layers of libqtest APIs, one that takes an explicit QTestState object, and the other that uses the implicit
global_qtest, is annoying. In the interest of getting rid of global implicit state and having less code to maintain, merge:
qtest_clock_set()
qtest_clock_step()
qtest_clock_step_next()
with their short counterparts. All callers that previously used the short form now make it explicit that they are relying onglobal_qtest, and later patches can then clean things up to remove the global variable.Signed-off-by Eric Blake <[email protected]>--- tests/libqtest.h | 50 ++++---------------------------- tests/libqtest.c | 6 ++-- tests/e1000e-test.c | 2 +- tests/fdc-test.c | 4 +-- tests/ide-test.c | 2 +- tests/libqos/virtio.c | 8 +++--- tests/rtc-test.c | 74 ++++++++++++++++++++++++------------------------ tests/rtl8139-test.c | 10 +++---- tests/tco-test.c | 22 +++++++------- tests/test-arm-mptimer.c | 25 +++++++++------- tests/wdt_ib700-test.c | 12 ++++---- 11 files changed, 90 insertions(+), 125 deletions(-)tests/libqtest.h +5
-5@@ -417,17 +417,17 @@ void qtest_bufwrite(QTestState *s, uint64_t addr,void qtest_memset (QTestState *s,uint64_t addr,uint8_t patt,size_t size);/** -* qtest_clock_step_next: +* clock_step_next: * @s: #QTestState instance to operate on. * * Advance the QEMU_CLOCK_VIRTUAL to the next deadline. * * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. */ -int64_t qtest_clock_step_next (QTestState *s); +int64_t clock_step_next (QTestState *s);/** -* qtest_clock_step: +* clock_step: * @s: QTestState instance to operate on. * @step: Number of nanoseconds to advance the clock by. * @@ -435,10 +435,10 @@ int64_t qtest_clock_step_next(QTestState *s);* * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. */ -int64_t qtest_clock_step (QTestState *s,int64_t step); +int64_t clock_step (QTestState *s,int64_t step);/** -* qtest_clock_set: +* clock_set: * @s: QTestState instance to operate on. * @val: Nanoseconds value to advance the clock to. *
tests/libqtest.h int64_t qtest_clock_step(QTestState *s, int64_t step); · line 449
Quoted 5 lines
tests/libqtest.h +1
-1@@ -446,7 +446,7 @@ int64_t qtest_clock_step(QTestState *s, int64_t step);* * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. */ -int64_t qtest_clock_set (QTestState *s,int64_t val); +int64_t clock_set (QTestState *s,int64_t val);
Could we please keep the "qtest" prefix here and rather get rid of the
other ones? Even if it's more to type, I prefer to have a proper prefix here so that it is clear at the first sight that the functions belong to the qtest framework.
Thomas
Re: [Qemu-devel] [PATCH v7 31/38] libqtest: Merge qtest_clock_*() with clock_*()
Quoted 14 lines · Thomas Huth
Quoted 12 lines · Eric Blake
Maintaining two layers of libqtest APIs, one that takes an explicit QTestState object, and the other that uses the implicit
global_qtest, is annoying. In the interest of getting rid of global implicit state and having less code to maintain, merge:
qtest_clock_set()
qtest_clock_step()
qtest_clock_step_next()
with their short counterparts. All callers that previously used the short form now make it explicit that they are relying onglobal_qtest, and later patches can then clean things up to remove the global variable.
Quoted 10 lines
tests/libqtest.h int64_t qtest_clock_step(QTestState *s, int64_t step); · line 449
Quoted 6 lines
tests/libqtest.h +1
-1@@ -446,7 +446,7 @@ int64_t qtest_clock_step(QTestState *s, int64_t step);* * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. */ -int64_t qtest_clock_set (QTestState *s,int64_t val); +int64_t clock_set (QTestState *s,int64_t val);Could we please keep the "qtest" prefix here and rather get rid of the
other ones? Even if it's more to type, I prefer to have a proper prefix here so that it is clear at the first sight that the functions belong to the qtest framework.
I suppose we can, although it makes more lines that are likely to bump up against 80 columns, and thus slightly more churn to reformat things to keep checkpatch happy. I like the shorter name, because less typing is easier to remember. I'd prefer a second opinion on naming before doing anything about it though - Markus or Paolo, do you have any preference?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v7 31/38] libqtest: Merge qtest_clock_*() with clock_*()
Quoted 26 lines · Eric Blake
Quoted 14 lines · Thomas Huth
Quoted 12 lines · Eric Blake
Maintaining two layers of libqtest APIs, one that takes an explicit QTestState object, and the other that uses the implicit
global_qtest, is annoying. In the interest of getting rid of global implicit state and having less code to maintain, merge:
qtest_clock_set()
qtest_clock_step()
qtest_clock_step_next()
with their short counterparts. All callers that previously used the short form now make it explicit that they are relying onglobal_qtest, and later patches can then clean things up to remove the global variable.Quoted 10 lines
tests/libqtest.h int64_t qtest_clock_step(QTestState *s, int64_t step); · line 449
Quoted 6 lines
tests/libqtest.h +1
-1@@ -446,7 +446,7 @@ int64_t qtest_clock_step(QTestState *s, int64_t step);* * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. */ -int64_t qtest_clock_set (QTestState *s,int64_t val); +int64_t clock_set (QTestState *s,int64_t val);Could we please keep the "qtest" prefix here and rather get rid of the
other ones? Even if it's more to type, I prefer to have a proper prefix here so that it is clear at the first sight that the functions belong to the qtest framework.
Quoted 6 lines
I suppose we can, although it makes more lines that are likely to bump up against 80 columns, and thus slightly more churn to reformat things to keep checkpatch happy. I like the shorter name, because less typing is easier to remember. I'd prefer a second opinion on naming before doing anything about it though - Markus or Paolo, do you have any preference?
IMHO you should at least keep the qtest prefix in patch 33/38 to avoid confusion with the system definitions that have the same names (see "man 2 outb" for example).
Thomas
PATCH v7 32/38 libqtest: Merge qtest_irq*() with irq*()
In reply to Eric BlakeMaintaining two layers of libqtest APIs, one that takes an explicit QTestState object, and the other that uses the implicit global_qtest, is annoying. In the interest of getting rid of global implicit state and having less code to maintain, merge:
qtest_get_irq()
qtest_irq_intercept_in()
qtest_irq_intercept_out()
with their short counterparts. All callers that previously used the short form now make it explicit that they are relying on global_qtest, and later patches can then clean things up to remove the global variable.
--- tests/libqtest.h | 47 ++++++----------------------------------------- tests/libqtest.c | 6 +++--- tests/fdc-test.c | 48 ++++++++++++++++++++++++------------------------ tests/ide-test.c | 17 +++++++++-------- tests/ipmi-bt-test.c | 6 +++--- tests/ipmi-kcs-test.c | 8 ++++---- tests/libqos/libqos-pc.c | 2 +- tests/rtc-test.c | 10 +++++----- tests/tco-test.c | 2 +- tests/wdt_ib700-test.c | 8 ++++---- 10 files changed, 60 insertions(+), 94 deletions(-)
tests/libqtest.h +6 -41
@@ -176,33 +176,33 @@ char *qtest_hmp(QTestState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3);char *qtest_hmpv (QTestState *s,const char *fmt,va_list ap);/** -* qtest_get_irq: +* get_irq: * @s: #QTestState instance to operate on. * @num: Interrupt to observe. * * Returns: The level of the @num interrupt. */ -bool qtest_get_irq (QTestState *s,int num); +bool get_irq (QTestState *s,int num);/** -* qtest_irq_intercept_in: +* irq_intercept_in: * @s: #QTestState instance to operate on. * @string: QOM path of a device. * * Associate qtest irqs with the GPIO-in pins of the device * whose path is specified by @string. */ -void qtest_irq_intercept_in (QTestState *s,const char *string); +void irq_intercept_in (QTestState *s,const char *string);/** -* qtest_irq_intercept_out: +* irq_intercept_out: * @s: #QTestState instance to operate on. * @string: QOM path of a device. * * Associate qtest irqs with the GPIO-out pins of the device * whose path is specified by @string. */ -void qtest_irq_intercept_out (QTestState *s,const char *string); +void irq_intercept_out (QTestState *s,const char *string);/** * qtest_outb:
@@ -594,41 +594,6 @@ static inline QDict *qmp_eventwait_ref(const char *event)char *hmp (const char *fmt, ...)GCC_FMT_ATTR (1 ,2 );/** -* get_irq: -* @num: Interrupt to observe. -* -* Returns: The level of the @num interrupt. -*/ -static inline bool get_irq (int num) -{ -return qtest_get_irq (global_qtest, num); -} - -/** -* irq_intercept_in: -* @string: QOM path of a device. -* -* Associate qtest irqs with the GPIO-in pins of the device -* whose path is specified by @string. -*/ -static inline void irq_intercept_in (const char *string) -{ -qtest_irq_intercept_in (global_qtest, string); -} - -/** -* qtest_irq_intercept_out: -* @string: QOM path of a device. -* -* Associate qtest irqs with the GPIO-out pins of the device -* whose path is specified by @string. -*/ -static inline void irq_intercept_out (const char *string) -{ -qtest_irq_intercept_out (global_qtest, string); -} - -/** * outb: * @addr: I/O port to write to. * @value: Value being written.
tests/libqtest.c +3 -3
@@ -648,7 +648,7 @@ const char *qtest_get_arch(void)return end +strlen ("/qemu-system-" ); } -bool qtest_get_irq (QTestState *s,int num) +bool get_irq (QTestState *s,int num) {/* dummy operation in order to make sure irq is up to date */ qtest_inb (s,0 );
@@ -684,13 +684,13 @@ int64_t clock_set(QTestState *s, int64_t val)return qtest_clock_rsp (s); } -void qtest_irq_intercept_out (QTestState *s,const char *qom_path) +void irq_intercept_out (QTestState *s,const char *qom_path) {qtest_sendf (s,"irq_intercept_out %s\n" , qom_path);qtest_rsp (s,0 ); } -void qtest_irq_intercept_in (QTestState *s,const char *qom_path) +void irq_intercept_in (QTestState *s,const char *qom_path) {qtest_sendf (s,"irq_intercept_in %s\n" , qom_path);qtest_rsp (s,0 );
tests/fdc-test.c +24 -24
164 lines not on this page · raw message
tests/ide-test.c +9 -8
@@ -255,14 +255,15 @@ static int send_dma_request(int cmd, uint64_t sector, int nb_sectors, status =qpci_io_readb (dev, bmdma_bar, bmreg_status); }while ((status & (BM_STS_ACTIVE |BM_STS_INTR )) ==BM_STS_ACTIVE ); - g_assert_cmpint(get_irq(IDE_PRIMARY_IRQ), ==, !!(status & BM_STS_INTR)); + g_assert_cmpint(get_irq(global_qtest, IDE_PRIMARY_IRQ), ==, + !!(status &BM_STS_INTR ));/* Check IDE status code */ assert_bit_set (qpci_io_readb (dev, ide_bar, reg_status),DRDY );assert_bit_clear (qpci_io_readb (dev, ide_bar, reg_status),BSY |DRQ );/* Reading the status register clears the IRQ */ -g_assert (!get_irq (IDE_PRIMARY_IRQ )); +g_assert (!get_irq (global_qtest,IDE_PRIMARY_IRQ ));/* Stop DMA transfer if still active */ if (status &BM_STS_ACTIVE ) {
@@ -458,7 +459,7 @@ static void test_bmdma_setup(void)"-drive file=%s,if=ide,serial=%s,cache=writeback,format=raw " "-global ide-hd.ver=%s" , tmp_path, "testdisk", "version"); -qtest_irq_intercept_in (global_qtest,"ioapic" ); +irq_intercept_in (global_qtest,"ioapic" ); }static void test_bmdma_teardown (void )
@@ -580,7 +581,7 @@ static void test_flush(void) dev =get_pci_device (&bmdma_bar, &ide_bar); -qtest_irq_intercept_in (global_qtest,"ioapic" ); +irq_intercept_in (global_qtest,"ioapic" );/* Dirty media so that CMD_FLUSH_CACHE will actually go to disk */ make_dirty (0 );
@@ -631,7 +632,7 @@ static void test_retry_flush(const char *machine) dev =get_pci_device (&bmdma_bar, &ide_bar); -qtest_irq_intercept_in (global_qtest,"ioapic" ); +irq_intercept_in (global_qtest,"ioapic" );/* Dirty media so that CMD_FLUSH_CACHE will actually go to disk */ make_dirty (0 );
@@ -784,7 +785,7 @@ static void ide_wait_intr(int irq)time (&st);while (true) { - intr =get_irq (irq); + intr =get_irq (global_qtest, irq);if (intr) {return ; }
@@ -822,7 +823,7 @@ static void cdrom_pio_impl(int nblocks)ide_test_start ("-drive if=none,file=%s,media=cdrom,format=raw,id=sr0,index=0 " "-device ide-cd,drive=sr0,bus=ide.0" , tmp_path); dev =get_pci_device (&bmdma_bar, &ide_bar); -qtest_irq_intercept_in (global_qtest,"ioapic" ); +irq_intercept_in (global_qtest,"ioapic" );/* PACKET command on device 0 */ qpci_io_writeb (dev, ide_bar, reg_device,0 );
@@ -905,7 +906,7 @@ static void test_cdrom_dma(void)ide_test_start ("-drive if=none,file=%s,media=cdrom,format=raw,id=sr0,index=0 " "-device ide-cd,drive=sr0,bus=ide.0" , tmp_path); -qtest_irq_intercept_in (global_qtest,"ioapic" ); +irq_intercept_in (global_qtest,"ioapic" ); guest_buf =guest_alloc (guest_malloc, len); prdt[0 ].addr =cpu_to_le32 (guest_buf);
tests/ipmi-bt-test.c +3 -3
@@ -276,10 +276,10 @@ static void bt_cmd(uint8_t *cmd, unsigned int cmd_len,bt_wait_b2h_atn ();if (bt_ints_enabled) {g_assert ((bt_get_irqreg () &0x02 ) ==0x02 ); -g_assert (get_irq (IPMI_IRQ )); +g_assert (get_irq (global_qtest,IPMI_IRQ ));bt_write_irqreg (0x03 ); }else { -g_assert (!get_irq (IPMI_IRQ )); +g_assert (!get_irq (global_qtest,IPMI_IRQ )); }IPMI_BT_CTLREG_SET_H_BUSY ();IPMI_BT_CTLREG_SET_B2H_ATN ();
@@ -418,7 +418,7 @@ int main(int argc, char **argv)" -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" ); +irq_intercept_in (global_qtest,"ioapic" );qtest_add_func ("/ipmi/extern/connect" , test_connect);qtest_add_func ("/ipmi/extern/bt_base" , test_bt_base);qtest_add_func ("/ipmi/extern/bt_enable_irq" , test_enable_irq);
tests/ipmi-kcs-test.c +4 -4
@@ -89,14 +89,14 @@ static void kcs_wait_obf(void)static void kcs_clear_obf (void ) {if (kcs_ints_enabled) { -g_assert (get_irq (IPMI_IRQ )); +g_assert (get_irq (global_qtest,IPMI_IRQ )); }else { -g_assert (!get_irq (IPMI_IRQ )); +g_assert (!get_irq (global_qtest,IPMI_IRQ )); }g_assert (IPMI_KCS_CMDREG_GET_OBF () ==1 );kcs_get_datareg ();g_assert (IPMI_KCS_CMDREG_GET_OBF () ==0 ); -g_assert (!get_irq (IPMI_IRQ )); +g_assert (!get_irq (global_qtest,IPMI_IRQ )); }static void kcs_check_state (uint8_t state)
@@ -277,7 +277,7 @@ int main(int argc, char **argv) global_qtest =qtest_start ("-device ipmi-bmc-sim,id=bmc0" " -device isa-ipmi-kcs,bmc=bmc0" ); -qtest_irq_intercept_in (global_qtest,"ioapic" ); +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);qtest_add_func ("/ipmi/local/kcs_enable_irq" , test_enable_irq);
tests/libqos/libqos-pc.c +1 -1
@@ -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 (qs->qts,"ioapic" ); +irq_intercept_in (qs->qts,"ioapic" );return qs; }
tests/rtc-test.c +5 -5
@@ -277,7 +277,7 @@ static void alarm_time(void)/* set DEC mode */ cmos_write (RTC_REG_B ,REG_B_24H |REG_B_DM ); -g_assert (!get_irq (RTC_ISA_IRQ )); +g_assert (!get_irq (global_qtest,RTC_ISA_IRQ ));cmos_read (RTC_REG_C ); now.tm_sec = (now.tm_sec +2 ) %60 ;
@@ -287,14 +287,14 @@ static void alarm_time(void)cmos_write (RTC_REG_B ,cmos_read (RTC_REG_B ) |REG_B_AIE );for (i =0 ; i <2 + wiggle; i++) { -if (get_irq (RTC_ISA_IRQ )) { +if (get_irq (global_qtest,RTC_ISA_IRQ )) {break ; }clock_step (global_qtest,1000000000 ); } -g_assert (get_irq (RTC_ISA_IRQ )); +g_assert (get_irq (global_qtest,RTC_ISA_IRQ ));g_assert ((cmos_read (RTC_REG_C ) ®_C_AF ) !=0 );g_assert (cmos_read (RTC_REG_C ) ==0 ); }
@@ -644,7 +644,7 @@ static void uip_stuck(void)static uint64_t wait_periodic_interrupt (uint64_t real_time) { -while (!get_irq (RTC_ISA_IRQ )) { +while (!get_irq (global_qtest,RTC_ISA_IRQ )) { real_time =clock_step_next (global_qtest); }
@@ -691,7 +691,7 @@ int main(int argc, char **argv)g_test_init (&argc, &argv,NULL ); s = global_qtest =qtest_start ("-rtc clock=vm" ); -qtest_irq_intercept_in (s,"ioapic" ); +irq_intercept_in (s,"ioapic" );qtest_add_func ("/rtc/check-time/bcd" , bcd_check_time);qtest_add_func ("/rtc/check-time/dec" , dec_check_time);
tests/tco-test.c +1 -1
@@ -60,7 +60,7 @@ static void test_init(TestData *d) d->noreboot ?"" :"-global ICH9-LPC.noreboot=false" , !d->args ? "" : d->args); global_qtest = qs; -qtest_irq_intercept_in (qs,"ioapic" ); +irq_intercept_in (qs,"ioapic" ); d->bus =qpci_init_pc (qs,NULL ); d->dev =qpci_device_find (d->bus,QPCI_DEVFN (0x1f ,0x00 ));
tests/wdt_ib700-test.c +4 -4
@@ -58,7 +58,7 @@ static void ib700_pause(void)QDict *d;QTestState *s =qtest_start ("-watchdog-action pause -device ib700" ); -qtest_irq_intercept_in (s,"ioapic" ); +irq_intercept_in (s,"ioapic" ); d =ib700_program_and_wait (s);g_assert (!strcmp (qdict_get_str (d,"action" ),"pause" ));QDECREF (d);
@@ -71,7 +71,7 @@ static void ib700_reset(void)QDict *d;QTestState *s =qtest_start ("-watchdog-action reset -device ib700" ); -qtest_irq_intercept_in (s,"ioapic" ); +irq_intercept_in (s,"ioapic" ); d =ib700_program_and_wait (s);g_assert (!strcmp (qdict_get_str (d,"action" ),"reset" ));QDECREF (d);
@@ -85,7 +85,7 @@ static void ib700_shutdown(void)QTestState *s; s =qtest_start ("-watchdog-action reset -no-reboot -device ib700" ); -qtest_irq_intercept_in (s,"ioapic" ); +irq_intercept_in (s,"ioapic" ); d =ib700_program_and_wait (s);g_assert (!strcmp (qdict_get_str (d,"action" ),"reset" ));QDECREF (d);
@@ -98,7 +98,7 @@ static void ib700_none(void)QDict *d;QTestState *s =qtest_start ("-watchdog-action none -device ib700" ); -qtest_irq_intercept_in (s,"ioapic" ); +irq_intercept_in (s,"ioapic" ); d =ib700_program_and_wait (s);g_assert (!strcmp (qdict_get_str (d,"action" ),"none" ));QDECREF (d);
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PATCH v7 32/38] libqtest: Merge qtest_irq*() with irq*()
Quoted 57 lines · Eric Blake
Maintaining two layers of libqtest APIs, one that takes an explicit QTestState object, and the other that uses the implicit
global_qtest, is annoying. In the interest of getting rid of global implicit state and having less code to maintain, merge:
qtest_get_irq()
qtest_irq_intercept_in()
qtest_irq_intercept_out()
with their short counterparts. All callers that previously used the short form now make it explicit that they are relying onglobal_qtest, and later patches can then clean things up to remove the global variable.Signed-off-by Eric Blake <[email protected]>--- tests/libqtest.h | 47 ++++++----------------------------------------- tests/libqtest.c | 6 +++--- tests/fdc-test.c | 48 ++++++++++++++++++++++++------------------------ tests/ide-test.c | 17 +++++++++-------- tests/ipmi-bt-test.c | 6 +++--- tests/ipmi-kcs-test.c | 8 ++++---- tests/libqos/libqos-pc.c | 2 +- tests/rtc-test.c | 10 +++++----- tests/tco-test.c | 2 +- tests/wdt_ib700-test.c | 8 ++++---- 10 files changed, 60 insertions(+), 94 deletions(-)tests/libqtest.h +4
-4@@ -176,33 +176,33 @@ char *qtest_hmp(QTestState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3);char *qtest_hmpv (QTestState *s,const char *fmt,va_list ap);/** -* qtest_get_irq: +* get_irq: * @s: #QTestState instance to operate on. * @num: Interrupt to observe. * * Returns: The level of the @num interrupt. */ -bool qtest_get_irq (QTestState *s,int num); +bool get_irq (QTestState *s,int num);/** -* qtest_irq_intercept_in: +* irq_intercept_in: * @s: #QTestState instance to operate on. * @string: QOM path of a device. * * Associate qtest irqs with the GPIO-in pins of the device * whose path is specified by @string. */ -void qtest_irq_intercept_in (QTestState *s,const char *string); +void irq_intercept_in (QTestState *s,const char *string);/**
tests/libqtest.h char *qtest_hmp(QTestState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3); · line 205
Quoted 10 lines
tests/libqtest.h +2
-2-* qtest_irq_intercept_out: +* irq_intercept_out: * @s: #QTestState instance to operate on. * @string: QOM path of a device. * * Associate qtest irqs with the GPIO-out pins of the device * whose path is specified by @string. */ -void qtest_irq_intercept_out (QTestState *s,const char *string); +void irq_intercept_out (QTestState *s,const char *string);
Could we please also keep the qtest prefix here?
Thomas
PATCH v7 33/38 libqtest: Merge qtest_{in, out}[bwl]() with {in, out}[bwl]()
In reply to Eric BlakeMaintaining two layers of libqtest APIs, one that takes an explicit QTestState object, and the other that uses the implicit global_qtest, is annoying. In the interest of getting rid of global implicit state and having less code to maintain, merge:
qtest_outb()
qtest_outw()
qtest_outl()
qtest_inb()
qtest_inw()
qtest_inl()
with their short counterparts. All callers that previously used the short form now make it explicit that they are relying on global_qtest, and later patches can then clean things up to remove the global variable.
--- tests/libqtest.h | 99 ++++++------------------------------------------- tests/multiboot/libc.h | 2 +- tests/libqtest.c | 14 +++---- tests/boot-order-test.c | 4 +- tests/endianness-test.c | 12 +++--- tests/fdc-test.c | 77 ++++++++++++++++++++------------------ tests/hd-geo-test.c | 4 +- tests/ipmi-bt-test.c | 12 +++--- tests/ipmi-kcs-test.c | 8 ++-- tests/libqos/fw_cfg.c | 4 +- tests/libqos/pci-pc.c | 44 +++++++++++----------- tests/libqos/pci.c | 2 +- tests/m48t59-test.c | 8 ++-- tests/multiboot/libc.c | 2 +- tests/pvpanic-test.c | 4 +- tests/rtc-test.c | 8 ++-- tests/wdt_ib700-test.c | 8 ++-- 17 files changed, 120 insertions(+), 192 deletions(-)
tests/libqtest.h +12 -87
@@ -205,61 +205,61 @@ void irq_intercept_in(QTestState *s, const char *string);void irq_intercept_out (QTestState *s,const char *string);/** -* qtest_outb: +* outb: * @s: #QTestState instance to operate on. * @addr: I/O port to write to. * @value: Value being written. * * Write an 8-bit value to an I/O port. */ -void qtest_outb (QTestState *s,uint16_t addr,uint8_t value); +void outb (QTestState *s,uint16_t addr,uint8_t value);/** -* qtest_outw: +* outw: * @s: #QTestState instance to operate on. * @addr: I/O port to write to. * @value: Value being written. * * Write a 16-bit value to an I/O port. */ -void qtest_outw (QTestState *s,uint16_t addr,uint16_t value); +void outw (QTestState *s,uint16_t addr,uint16_t value);/** -* qtest_outl: +* outl: * @s: #QTestState instance to operate on. * @addr: I/O port to write to. * @value: Value being written. * * Write a 32-bit value to an I/O port. */ -void qtest_outl (QTestState *s,uint16_t addr,uint32_t value); +void outl (QTestState *s,uint16_t addr,uint32_t value);/** -* qtest_inb: +* inb: * @s: #QTestState instance to operate on. * @addr: I/O port to read from. * * Returns an 8-bit value from an I/O port. */ -uint8_t qtest_inb (QTestState *s,uint16_t addr); +uint8_t inb (QTestState *s,uint16_t addr);/** -* qtest_inw: +* inw: * @s: #QTestState instance to operate on. * @addr: I/O port to read from. * * Returns a 16-bit value from an I/O port. */ -uint16_t qtest_inw (QTestState *s,uint16_t addr); +uint16_t inw (QTestState *s,uint16_t addr);/** -* qtest_inl: +* inl: * @s: #QTestState instance to operate on. * @addr: I/O port to read from. * * Returns a 32-bit value from an I/O port. */ -uint32_t qtest_inl (QTestState *s,uint16_t addr); +uint32_t inl (QTestState *s,uint16_t addr);/** * qtest_writeb:
@@ -594,81 +594,6 @@ static inline QDict *qmp_eventwait_ref(const char *event)char *hmp (const char *fmt, ...)GCC_FMT_ATTR (1 ,2 );/** -* outb: -* @addr: I/O port to write to. -* @value: Value being written. -* -* Write an 8-bit value to an I/O port. -*/ -static inline void outb (uint16_t addr,uint8_t value) -{ -qtest_outb (global_qtest, addr, value); -} - -/** -* outw: -* @addr: I/O port to write to. -* @value: Value being written. -* -* Write a 16-bit value to an I/O port. -*/ -static inline void outw (uint16_t addr,uint16_t value) -{ -qtest_outw (global_qtest, addr, value); -} - -/** -* outl: -* @addr: I/O port to write to. -* @value: Value being written. -* -* Write a 32-bit value to an I/O port. -*/ -static inline void outl (uint16_t addr,uint32_t value) -{ -qtest_outl (global_qtest, addr, value); -} - -/** -* inb: -* @addr: I/O port to read from. -* -* Reads an 8-bit value from an I/O port. -* -* Returns: Value read. -*/ -static inline uint8_t inb (uint16_t addr) -{ -return qtest_inb (global_qtest, addr); -} - -/** -* inw: -* @addr: I/O port to read from. -* -* Reads a 16-bit value from an I/O port. -* -* Returns: Value read. -*/ -static inline uint16_t inw (uint16_t addr) -{ -return qtest_inw (global_qtest, addr); -} - -/** -* inl: -* @addr: I/O port to read from. -* -* Reads a 32-bit value from an I/O port. -* -* Returns: Value read. -*/ -static inline uint32_t inl (uint16_t addr) -{ -return qtest_inl (global_qtest, addr); -} - -/** * writeb: * @addr: Guest address to write to. * @value: Value being written.
tests/multiboot/libc.h +1 -1
@@ -48,7 +48,7 @@ typedef __builtin_va_list va_list;/* Port I/O functions */ -static inline void outb (uint16_t port,uint8_t data) +static inline void outb (global_qtest ,uint16_t port,uint8_t data) { asmvolatile ("outb %0, %1" : :"a" (data),"Nd" (port)); }
tests/libqtest.c +7 -7
@@ -651,7 +651,7 @@ const char *qtest_get_arch(void)bool get_irq (QTestState *s,int num) {/* dummy operation in order to make sure irq is up to date */ -qtest_inb (s,0 ); +inb (s,0 );return s->irq_level[num]; }
@@ -702,17 +702,17 @@ static void qtest_out(QTestState *s, const char *cmd, uint16_t addr, uint32_t vaqtest_rsp (s,0 ); } -void qtest_outb (QTestState *s,uint16_t addr,uint8_t value) +void outb (QTestState *s,uint16_t addr,uint8_t value) {qtest_out (s,"outb" , addr, value); } -void qtest_outw (QTestState *s,uint16_t addr,uint16_t value) +void outw (QTestState *s,uint16_t addr,uint16_t value) {qtest_out (s,"outw" , addr, value); } -void qtest_outl (QTestState *s,uint16_t addr,uint32_t value) +void outl (QTestState *s,uint16_t addr,uint32_t value) {qtest_out (s,"outl" , addr, value); }
@@ -732,17 +732,17 @@ static uint32_t qtest_in(QTestState *s, const char *cmd, uint16_t addr)return value; } -uint8_t qtest_inb (QTestState *s,uint16_t addr) +uint8_t inb (QTestState *s,uint16_t addr) {return qtest_in (s,"inb" , addr); } -uint16_t qtest_inw (QTestState *s,uint16_t addr) +uint16_t inw (QTestState *s,uint16_t addr) {return qtest_in (s,"inw" , addr); } -uint32_t qtest_inl (QTestState *s,uint16_t addr) +uint32_t inl (QTestState *s,uint16_t addr) {return qtest_in (s,"inl" , addr); }
tests/boot-order-test.c +2 -2
@@ -63,8 +63,8 @@ static void test_boot_orders(const char *machine,static uint8_t read_mc146818 (uint16_t port,uint8_t reg) { -outb (port, reg); -return inb (port +1 ); +outb (global_qtest, port, reg); +return inb (global_qtest, port +1 ); }static uint64_t read_boot_order_pc (void )
tests/endianness-test.c +6 -6
@@ -52,7 +52,7 @@ static uint8_t isa_inb(const TestCase *test, uint16_t addr) {uint8_t value;if (test->isa_base ==-1 ) { - value =inb (addr); + value =inb (global_qtest, addr); }else { value =readb (test->isa_base + addr); }
@@ -63,7 +63,7 @@ static uint16_t isa_inw(const TestCase *test, uint16_t addr) {uint16_t value;if (test->isa_base ==-1 ) { - value =inw (addr); + value =inw (global_qtest, addr); }else { value =readw (test->isa_base + addr); }
@@ -74,7 +74,7 @@ static uint32_t isa_inl(const TestCase *test, uint16_t addr) {uint32_t value;if (test->isa_base ==-1 ) { - value =inl (addr); + value =inl (global_qtest, addr); }else { value =readl (test->isa_base + addr); }
@@ -84,7 +84,7 @@ static uint32_t isa_inl(const TestCase *test, uint16_t addr)static void isa_outb (const TestCase *test,uint16_t addr,uint8_t value) {if (test->isa_base ==-1 ) { -outb (addr, value); +outb (global_qtest, addr, value); }else {writeb (test->isa_base + addr, value); }
@@ -94,7 +94,7 @@ static void isa_outw(const TestCase *test, uint16_t addr, uint16_t value) { value = test->bswap ?bswap16 (value) : value;if (test->isa_base ==-1 ) { -outw (addr, value); +outw (global_qtest, addr, value); }else {writew (test->isa_base + addr, value); }
@@ -104,7 +104,7 @@ static void isa_outl(const TestCase *test, uint16_t addr, uint32_t value) { value = test->bswap ?bswap32 (value) : value;if (test->isa_base ==-1 ) { -outl (addr, value); +outl (global_qtest, addr, value); }else {writel (test->isa_base + addr, value); }
tests/fdc-test.c +40 -37
216 lines not on this page · raw message
tests/hd-geo-test.c +2 -2
@@ -82,8 +82,8 @@ static void test_cmos_byte(int reg, int expected)enum { cmos_base =0x70 };int actual; -outb (cmos_base +0 , reg); - actual =inb (cmos_base +1 ); +outb (global_qtest, cmos_base +0 , reg); + actual =inb (global_qtest, cmos_base +1 );g_assert (actual == expected); }
tests/ipmi-bt-test.c +6 -6
@@ -66,32 +66,32 @@ static int bt_ints_enabled;static uint8_t bt_get_ctrlreg (void ) { -return inb (IPMI_BT_BASE ); +return inb (global_qtest,IPMI_BT_BASE ); }static void bt_write_ctrlreg (uint8_t val) { -outb (IPMI_BT_BASE , val); +outb (global_qtest,IPMI_BT_BASE , val); }static uint8_t bt_get_buf (void ) { -return inb (IPMI_BT_BASE +1 ); +return inb (global_qtest,IPMI_BT_BASE +1 ); }static void bt_write_buf (uint8_t val) { -outb (IPMI_BT_BASE +1 , val); +outb (global_qtest,IPMI_BT_BASE +1 , val); }static uint8_t bt_get_irqreg (void ) { -return inb (IPMI_BT_BASE +2 ); +return inb (global_qtest,IPMI_BT_BASE +2 ); }static void bt_write_irqreg (uint8_t val) { -outb (IPMI_BT_BASE +2 , val); +outb (global_qtest,IPMI_BT_BASE +2 , val); }static void bt_wait_b_busy (void )
tests/ipmi-kcs-test.c +4 -4
@@ -52,22 +52,22 @@ static int kcs_ints_enabled;static uint8_t kcs_get_cmdreg (void ) { -return inb (IPMI_KCS_BASE +1 ); +return inb (global_qtest,IPMI_KCS_BASE +1 ); }static void kcs_write_cmdreg (uint8_t val) { -outb (IPMI_KCS_BASE +1 , val); +outb (global_qtest,IPMI_KCS_BASE +1 , val); }static uint8_t kcs_get_datareg (void ) { -return inb (IPMI_KCS_BASE ); +return inb (global_qtest,IPMI_KCS_BASE ); }static void kcs_write_datareg (uint8_t val) { -outb (IPMI_KCS_BASE , val); +outb (global_qtest,IPMI_KCS_BASE , val); }static void kcs_wait_ibf (void )
tests/libqos/fw_cfg.c +2 -2
@@ -83,7 +83,7 @@ QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base)static void io_fw_cfg_select (QFWCFG *fw_cfg,uint16_t key) { -qtest_outw (fw_cfg->qts, fw_cfg->base, key); +outw (fw_cfg->qts, fw_cfg->base, key); }static void io_fw_cfg_read (QFWCFG *fw_cfg,void *data,size_t len)
@@ -92,7 +92,7 @@ static void io_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)int i;for (i =0 ; i < len; i++) { - ptr[i] =qtest_inb (fw_cfg->qts, fw_cfg->base +1 ); + ptr[i] =inb (fw_cfg->qts, fw_cfg->base +1 ); } }
tests/libqos/pci-pc.c +22 -22
104 lines not on this page · raw message
tests/libqos/pci.c +1 -1
@@ -426,7 +426,7 @@ void qpci_unplug_device_test(QTestState *qts, const char *id, uint8_t slot)g_assert (!qdict_haskey (response,"error" ));QDECREF (response); -qtest_outb (qts,ACPI_PCIHP_ADDR +PCI_EJ_BASE ,1 << slot); +outb (qts,ACPI_PCIHP_ADDR +PCI_EJ_BASE ,1 << slot);qtest_qmp_eventwait (qts,"DEVICE_DELETED" ); }
tests/m48t59-test.c +4 -4
@@ -44,14 +44,14 @@ static void cmos_write_mmio(uint8_t reg, uint8_t val)static uint8_t cmos_read_ioio (uint8_t reg) { -outw (base +0 , reg_base + (uint16_t )reg); -return inb (base +3 ); +outw (global_qtest, base +0 , reg_base + (uint16_t )reg); +return inb (global_qtest, base +3 ); }static void cmos_write_ioio (uint8_t reg,uint8_t val) { -outw (base +0 , reg_base + (uint16_t )reg); -outb (base +3 , val); +outw (global_qtest, base +0 , reg_base + (uint16_t )reg); +outb (global_qtest, base +3 , val); }static uint8_t cmos_read (uint8_t reg)
tests/multiboot/libc.c +1 -1
@@ -36,7 +36,7 @@ void* memcpy(void *dest, const void *src, int n)static void print_char (char c) { -outb (0xe9 , c); +outb (global_qtest,0xe9 , c); }static void print_str (char *s)
tests/pvpanic-test.c +2 -2
@@ -15,10 +15,10 @@ static void test_panic(void)uint8_t val;QDict *response, *data; - val =inb (0x505 ); + val =inb (global_qtest,0x505 ); g_assert_cmpuint(val, ==, 1); -outb (0x505 ,0x1 ); +outb (global_qtest,0x505 ,0x1 ); response =qmp_receive ();g_assert (qdict_haskey (response,"event" ));
tests/rtc-test.c +4 -4
@@ -28,14 +28,14 @@ static int bcd2dec(int value)static uint8_t cmos_read (uint8_t reg) { -outb (base +0 , reg); -return inb (base +1 ); +outb (global_qtest, base +0 , reg); +return inb (global_qtest, base +1 ); }static void cmos_write (uint8_t reg,uint8_t val) { -outb (base +0 , reg); -outb (base +1 , val); +outb (global_qtest, base +0 , reg); +outb (global_qtest, base +1 , val); }static int tm_cmp (struct tm *lhs,struct tm *rhs)
tests/wdt_ib700-test.c +4 -4
@@ -26,22 +26,22 @@ static QDict *ib700_program_and_wait(QTestState *s)qmp_check_no_event (s);/* 2 second limit */ -qtest_outb (s,0x443 ,14 ); +outb (s,0x443 ,14 );/* Ping */ clock_step (s,NANOSECONDS_PER_SECOND );qmp_check_no_event (s); -qtest_outb (s,0x443 ,14 ); +outb (s,0x443 ,14 );/* Disable */ clock_step (s,NANOSECONDS_PER_SECOND );qmp_check_no_event (s); -qtest_outb (s,0x441 ,1 ); +outb (s,0x441 ,1 );clock_step (s,3 *NANOSECONDS_PER_SECOND );qmp_check_no_event (s);/* Enable and let it fire */ -qtest_outb (s,0x443 ,13 ); +outb (s,0x443 ,13 );clock_step (s,3 *NANOSECONDS_PER_SECOND );qmp_check_no_event (s);clock_step (s,2 *NANOSECONDS_PER_SECOND );
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PATCH v7 33/38] libqtest: Merge qtest_{in, out}[bwl]() with {in, out}[bwl]()
Quoted 44 lines · Eric Blake
Maintaining two layers of libqtest APIs, one that takes an explicit QTestState object, and the other that uses the implicit
global_qtest, is annoying. In the interest of getting rid of global implicit state and having less code to maintain, merge:
qtest_outb()
qtest_outw()
qtest_outl()
qtest_inb()
qtest_inw()
qtest_inl()
with their short counterparts. All callers that previously used the short form now make it explicit that they are relying onglobal_qtest, and later patches can then clean things up to remove the global variable.Signed-off-by Eric Blake <[email protected]>--- tests/libqtest.h | 99 ++++++------------------------------------------- tests/multiboot/libc.h | 2 +- tests/libqtest.c | 14 +++---- tests/boot-order-test.c | 4 +- tests/endianness-test.c | 12 +++--- tests/fdc-test.c | 77 ++++++++++++++++++++------------------ tests/hd-geo-test.c | 4 +- tests/ipmi-bt-test.c | 12 +++--- tests/ipmi-kcs-test.c | 8 ++-- tests/libqos/fw_cfg.c | 4 +- tests/libqos/pci-pc.c | 44 +++++++++++----------- tests/libqos/pci.c | 2 +- tests/m48t59-test.c | 8 ++-- tests/multiboot/libc.c | 2 +- tests/pvpanic-test.c | 4 +- tests/rtc-test.c | 8 ++-- tests/wdt_ib700-test.c | 8 ++-- 17 files changed, 120 insertions(+), 192 deletions(-)tests/libqtest.h +0
-0@@ -205,61 +205,61 @@ void irq_intercept_in(QTestState *s, const char *string);void irq_intercept_out (QTestState *s,const char *string);/**
tests/libqtest.h void irq_intercept_in(QTestState *s, const char *string); · line 215
Quoted 10 lines
tests/libqtest.h +2
-2-* qtest_outb: +* outb: * @s: #QTestState instance to operate on. * @addr: I/O port to write to. * @value: Value being written. * * Write an 8-bit value to an I/O port. */ -void qtest_outb (QTestState *s,uint16_t addr,uint8_t value); +void outb (QTestState *s,uint16_t addr,uint8_t value);
Could we please also keep the qtest prefix here? ... same applies for all your other following "Merge ..." patches in this series...
Thomas
PATCH v7 34/38 libqtest: Merge qtest_{read, write}[bwlq]() with {read, write}[bwlq]()
In reply to Eric BlakeMaintaining two layers of libqtest APIs, one that takes an explicit QTestState object, and the other that uses the implicit global_qtest, is annoying. In the interest of getting rid of global implicit state and having less code to maintain, merge:
qtest_readb()
qtest_readw()
qtest_readl()
qtest_readq()
qtest_writeb()
qtest_writew()
qtest_writel()
qtest_writeq()
with their short counterparts. All callers that previously used the short form now make it explicit that they are relying on global_qtest, and later patches can then clean things up to remove the global variable.
--- tests/libqtest.h | 132 ++++++--------------------------------------- tests/acpi-utils.h | 10 ++-- tests/libqtest.c | 16 +++--- tests/acpi-utils.c | 2 +- tests/bios-tables-test.c | 8 +-- tests/boot-order-test.c | 6 +-- tests/boot-sector.c | 4 +- tests/endianness-test.c | 12 ++--- tests/libqos/fw_cfg.c | 4 +- tests/libqos/i2c-imx.c | 64 +++++++++++----------- tests/libqos/i2c-omap.c | 42 +++++++-------- tests/libqos/pci-spapr.c | 16 +++--- tests/libqos/rtas.c | 4 +- tests/libqos/virtio-mmio.c | 58 +++++++++----------- tests/libqos/virtio-pci.c | 8 +-- tests/libqos/virtio.c | 73 ++++++++++++------------- tests/m25p80-test.c | 80 +++++++++++++-------------- tests/m48t59-test.c | 4 +- tests/pnv-xscom-test.c | 2 +- tests/prom-env-test.c | 2 +- tests/q35-test.c | 12 ++--- tests/tco-test.c | 4 +- tests/test-arm-mptimer.c | 14 ++--- tests/vhost-user-test.c | 2 +- tests/virtio-blk-test.c | 18 +++---- tests/virtio-scsi-test.c | 2 +- tests/vmgenid-test.c | 2 +- 27 files changed, 245 insertions(+), 356 deletions(-)
tests/libqtest.h +16 -116
@@ -262,47 +262,47 @@ uint16_t inw(QTestState *s, uint16_t addr);uint32_t inl (QTestState *s,uint16_t addr);/** -* qtest_writeb: +* writeb: * @s: #QTestState instance to operate on. * @addr: Guest address to write to. * @value: Value being written. * * Writes an 8-bit value to memory. */ -void qtest_writeb (QTestState *s,uint64_t addr,uint8_t value); +void writeb (QTestState *s,uint64_t addr,uint8_t value);/** -* qtest_writew: +* writew: * @s: #QTestState instance to operate on. * @addr: Guest address to write to. * @value: Value being written. * * Writes a 16-bit value to memory. */ -void qtest_writew (QTestState *s,uint64_t addr,uint16_t value); +void writew (QTestState *s,uint64_t addr,uint16_t value);/** -* qtest_writel: +* writel: * @s: #QTestState instance to operate on. * @addr: Guest address to write to. * @value: Value being written. * * Writes a 32-bit value to memory. */ -void qtest_writel (QTestState *s,uint64_t addr,uint32_t value); +void writel (QTestState *s,uint64_t addr,uint32_t value);/** -* qtest_writeq: +* writeq: * @s: #QTestState instance to operate on. * @addr: Guest address to write to. * @value: Value being written. * * Writes a 64-bit value to memory. */ -void qtest_writeq (QTestState *s,uint64_t addr,uint64_t value); +void writeq (QTestState *s,uint64_t addr,uint64_t value);/** -* qtest_readb: +* readb: * @s: #QTestState instance to operate on. * @addr: Guest address to read from. *
@@ -310,10 +310,10 @@ void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value);* * Returns: Value read. */ -uint8_t qtest_readb (QTestState *s,uint64_t addr); +uint8_t readb (QTestState *s,uint64_t addr);/** -* qtest_readw: +* readw: * @s: #QTestState instance to operate on. * @addr: Guest address to read from. *
@@ -321,10 +321,10 @@ uint8_t qtest_readb(QTestState *s, uint64_t addr);* * Returns: Value read. */ -uint16_t qtest_readw (QTestState *s,uint64_t addr); +uint16_t readw (QTestState *s,uint64_t addr);/** -* qtest_readl: +* readl: * @s: #QTestState instance to operate on. * @addr: Guest address to read from. *
@@ -332,10 +332,10 @@ uint16_t qtest_readw(QTestState *s, uint64_t addr);* * Returns: Value read. */ -uint32_t qtest_readl (QTestState *s,uint64_t addr); +uint32_t readl (QTestState *s,uint64_t addr);/** -* qtest_readq: +* readq: * @s: #QTestState instance to operate on. * @addr: Guest address to read from. *
@@ -343,7 +343,7 @@ uint32_t qtest_readl(QTestState *s, uint64_t addr);* * Returns: Value read. */ -uint64_t qtest_readq (QTestState *s,uint64_t addr); +uint64_t readq (QTestState *s,uint64_t addr);/** * qtest_memread:
@@ -594,106 +594,6 @@ static inline QDict *qmp_eventwait_ref(const char *event)char *hmp (const char *fmt, ...)GCC_FMT_ATTR (1 ,2 );/** -* writeb: -* @addr: Guest address to write to. -* @value: Value being written. -* -* Writes an 8-bit value to guest memory. -*/ -static inline void writeb (uint64_t addr,uint8_t value) -{ -qtest_writeb (global_qtest, addr, value); -} - -/** -* writew: -* @addr: Guest address to write to. -* @value: Value being written. -* -* Writes a 16-bit value to guest memory. -*/ -static inline void writew (uint64_t addr,uint16_t value) -{ -qtest_writew (global_qtest, addr, value); -} - -/** -* writel: -* @addr: Guest address to write to. -* @value: Value being written. -* -* Writes a 32-bit value to guest memory. -*/ -static inline void writel (uint64_t addr,uint32_t value) -{ -qtest_writel (global_qtest, addr, value); -} - -/** -* writeq: -* @addr: Guest address to write to. -* @value: Value being written. -* -* Writes a 64-bit value to guest memory. -*/ -static inline void writeq (uint64_t addr,uint64_t value) -{ -qtest_writeq (global_qtest, addr, value); -} - -/** -* readb: -* @addr: Guest address to read from. -* -* Reads an 8-bit value from guest memory. -* -* Returns: Value read. -*/ -static inline uint8_t readb (uint64_t addr) -{ -return qtest_readb (global_qtest, addr); -} - -/** -* readw: -* @addr: Guest address to read from. -* -* Reads a 16-bit value from guest memory. -* -* Returns: Value read. -*/ -static inline uint16_t readw (uint64_t addr) -{ -return qtest_readw (global_qtest, addr); -} - -/** -* readl: -* @addr: Guest address to read from. -* -* Reads a 32-bit value from guest memory. -* -* Returns: Value read. -*/ -static inline uint32_t readl (uint64_t addr) -{ -return qtest_readl (global_qtest, addr); -} - -/** -* readq: -* @addr: Guest address to read from. -* -* Reads a 64-bit value from guest memory. -* -* Returns: Value read. -*/ -static inline uint64_t readq (uint64_t addr) -{ -return qtest_readq (global_qtest, addr); -} - -/** * memread: * @addr: Guest address to read from. * @data: Pointer to where memory contents will be stored.
tests/acpi-utils.h +5 -5
@@ -32,21 +32,21 @@ typedef struct {do { \switch (sizeof (field)) { \case 1 : \ - field =qtest_readb (qts, addr); \ + field =readb (qts, addr); \break ; \case 2 : \ - field =qtest_readw (qts, addr); \ + field =readw (qts, addr); \break ; \case 4 : \ - field =qtest_readl (qts, addr); \ + field =readl (qts, addr); \break ; \case 8 : \ - field =qtest_readq (qts, addr); \ + field =readq (qts, addr); \break ; \default : \g_assert (false); \ } \ - addr +=sizeof (field); \ + addr +=sizeof (field); \ }while (0 );#define ACPI_READ_ARRAY_PTR (qts, arr, length, addr) \
tests/libqtest.c +8 -8
@@ -754,22 +754,22 @@ static void qtest_write(QTestState *s, const char *cmd, uint64_t addr,qtest_rsp (s,0 ); } -void qtest_writeb (QTestState *s,uint64_t addr,uint8_t value) +void writeb (QTestState *s,uint64_t addr,uint8_t value) {qtest_write (s,"writeb" , addr, value); } -void qtest_writew (QTestState *s,uint64_t addr,uint16_t value) +void writew (QTestState *s,uint64_t addr,uint16_t value) {qtest_write (s,"writew" , addr, value); } -void qtest_writel (QTestState *s,uint64_t addr,uint32_t value) +void writel (QTestState *s,uint64_t addr,uint32_t value) {qtest_write (s,"writel" , addr, value); } -void qtest_writeq (QTestState *s,uint64_t addr,uint64_t value) +void writeq (QTestState *s,uint64_t addr,uint64_t value) {qtest_write (s,"writeq" , addr, value); }
@@ -789,22 +789,22 @@ static uint64_t qtest_read(QTestState *s, const char *cmd, uint64_t addr)return value; } -uint8_t qtest_readb (QTestState *s,uint64_t addr) +uint8_t readb (QTestState *s,uint64_t addr) {return qtest_read (s,"readb" , addr); } -uint16_t qtest_readw (QTestState *s,uint64_t addr) +uint16_t readw (QTestState *s,uint64_t addr) {return qtest_read (s,"readw" , addr); } -uint32_t qtest_readl (QTestState *s,uint64_t addr) +uint32_t readl (QTestState *s,uint64_t addr) {return qtest_read (s,"readl" , addr); } -uint64_t qtest_readq (QTestState *s,uint64_t addr) +uint64_t readq (QTestState *s,uint64_t addr) {return qtest_read (s,"readq" , addr); }
tests/acpi-utils.c +1 -1
@@ -42,7 +42,7 @@ uint32_t acpi_find_rsdp_address(QTestState *qts)int i;for (i =0 ; i <sizeof sig -1 ; ++i) { - sig[i] =qtest_readb (qts, off + i); + sig[i] =readb (qts, off + i); }if (!memcmp (sig,"RSD PTR " ,sizeof sig)) {
tests/bios-tables-test.c +4 -4
@@ -539,7 +539,7 @@ static void test_smbios_entry_point(test_data *data)int i;for (i =0 ; i <sizeof sig -1 ; ++i) { - sig[i] =qtest_readb (data->qts, off + i); + sig[i] =readb (data->qts, off + i); }if (!memcmp (sig,"_SM_" ,sizeof sig)) {
@@ -582,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 =qtest_readb (data->qts, addr); + type =readb (data->qts, addr); g_assert_cmpuint(type, <=, SMBIOS_MAX_TYPE); - len =qtest_readb (data->qts, addr +1 ); + len =readb (data->qts, addr +1 );/* single-instance structs must not have been encountered before */ if (smbios_single_instance (type)) {
@@ -596,7 +596,7 @@ static void test_smbios_structs(test_data *data) prv = crt =1 ;while (prv || crt) { prv = crt; - crt =qtest_readb (data->qts, addr + len); + crt =readb (data->qts, addr + len); len++; }
tests/boot-order-test.c +3 -3
@@ -108,9 +108,9 @@ static void test_pc_boot_order(void)static uint8_t read_m48t59 (uint64_t addr,uint16_t reg) { -writeb (addr, reg &0xff ); -writeb (addr +1 , reg >>8 ); -return readb (addr +3 ); +writeb (global_qtest, addr, reg &0xff ); +writeb (global_qtest, addr +1 , reg >>8 ); +return readb (global_qtest, addr +3 ); }static uint64_t read_boot_order_prep (void )
tests/boot-sector.c +2 -2
@@ -146,8 +146,8 @@ void boot_sector_test(QTestState *qts)* instruction. */ for (i =0 ; i <TEST_CYCLES ; ++i) { - signature_low =qtest_readb (qts,SIGNATURE_ADDR ); - signature_high =qtest_readb (qts,SIGNATURE_ADDR +1 ); + signature_low =readb (qts,SIGNATURE_ADDR ); + signature_high =readb (qts,SIGNATURE_ADDR +1 ); signature = (signature_high <<8 ) | signature_low;if (signature ==SIGNATURE ) {break ;
tests/endianness-test.c +6 -6
@@ -54,7 +54,7 @@ static uint8_t isa_inb(const TestCase *test, uint16_t addr)if (test->isa_base ==-1 ) { value =inb (global_qtest, addr); }else { - value =readb (test->isa_base + addr); + value =readb (global_qtest, test->isa_base + addr); }return value; }
@@ -65,7 +65,7 @@ static uint16_t isa_inw(const TestCase *test, uint16_t addr)if (test->isa_base ==-1 ) { value =inw (global_qtest, addr); }else { - value =readw (test->isa_base + addr); + value =readw (global_qtest, test->isa_base + addr); }return test->bswap ?bswap16 (value) : value; }
@@ -76,7 +76,7 @@ static uint32_t isa_inl(const TestCase *test, uint16_t addr)if (test->isa_base ==-1 ) { value =inl (global_qtest, addr); }else { - value =readl (test->isa_base + addr); + value =readl (global_qtest, test->isa_base + addr); }return test->bswap ?bswap32 (value) : value; }
@@ -86,7 +86,7 @@ static void isa_outb(const TestCase *test, uint16_t addr, uint8_t value)if (test->isa_base ==-1 ) {outb (global_qtest, addr, value); }else { -writeb (test->isa_base + addr, value); +writeb (global_qtest, test->isa_base + addr, value); } }
@@ -96,7 +96,7 @@ static void isa_outw(const TestCase *test, uint16_t addr, uint16_t value)if (test->isa_base ==-1 ) {outw (global_qtest, addr, value); }else { -writew (test->isa_base + addr, value); +writew (global_qtest, test->isa_base + addr, value); } }
@@ -106,7 +106,7 @@ static void isa_outl(const TestCase *test, uint16_t addr, uint32_t value)if (test->isa_base ==-1 ) {outl (global_qtest, addr, value); }else { -writel (test->isa_base + addr, value); +writel (global_qtest, test->isa_base + addr, value); } }
tests/libqos/fw_cfg.c +2 -2
@@ -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) { -qtest_writew (fw_cfg->qts, fw_cfg->base, key); +writew (fw_cfg->qts, fw_cfg->base, key); }static void mm_fw_cfg_read (QFWCFG *fw_cfg,void *data,size_t len)
@@ -65,7 +65,7 @@ static void mm_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)int i;for (i =0 ; i < len; i++) { - ptr[i] =qtest_readb (fw_cfg->qts, fw_cfg->base +2 ); + ptr[i] =readb (fw_cfg->qts, fw_cfg->base +2 ); } }
tests/libqos/i2c-imx.c +32 -32
151 lines not on this page · raw message
tests/libqos/i2c-omap.c +21 -21
111 lines not on this page · raw message
tests/libqos/pci-spapr.c +8 -8
@@ -45,49 +45,49 @@ typedef struct QPCIBusSPAPR {static uint8_t qpci_spapr_pio_readb (QPCIBus *bus,uint32_t addr) {QPCIBusSPAPR *s =container_of (bus, QPCIBusSPAPR, bus); -return qtest_readb (bus->qts, s->pio_cpu_base + addr); +return 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); -qtest_writeb (bus->qts, s->pio_cpu_base + addr, val); +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 (qtest_readw (bus->qts, s->pio_cpu_base + addr)); +return bswap16 (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); -qtest_writew (bus->qts, s->pio_cpu_base + addr,bswap16 (val)); +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 (qtest_readl (bus->qts, s->pio_cpu_base + addr)); +return bswap32 (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); -qtest_writel (bus->qts, s->pio_cpu_base + addr,bswap32 (val)); +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 (qtest_readq (bus->qts, s->pio_cpu_base + addr)); +return bswap64 (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); -qtest_writeq (bus->qts, s->pio_cpu_base + addr,bswap64 (val)); +writeq (bus->qts, s->pio_cpu_base + addr,bswap64 (val)); } static void qpci_spapr_memread(QPCIBus *bus, uint32_t addr,
tests/libqos/rtas.c +2 -2
@@ -13,7 +13,7 @@ static void qrtas_copy_args(QTestState *qts, uint64_t target_args,int i;for (i =0 ; i < nargs; i++) { -qtest_writel (qts, target_args + i *sizeof (uint32_t ), args[i]); +writel (qts, target_args + i *sizeof (uint32_t ), args[i]); } }
@@ -23,7 +23,7 @@ static void qrtas_copy_ret(QTestState *qts, uint64_t target_ret,int i;for (i =0 ; i < nret; i++) { - ret[i] =qtest_readl (qts, target_ret + i *sizeof (uint32_t )); + ret[i] =readl (qts, target_ret + i *sizeof (uint32_t )); } }
tests/libqos/virtio-mmio.c +25 -33
162 lines not on this page · raw message
tests/libqos/virtio-pci.c +4 -4
@@ -168,9 +168,9 @@ static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)/* No ISR checking should be done if masked, but read anyway */ return qpci_msix_pending (dev->pdev, vqpci->msix_entry); }else { - data =qtest_readl (d->bus->qts, vqpci->msix_addr); + data =readl (d->bus->qts, vqpci->msix_addr);if (data == vqpci->msix_data) { -qtest_writel (d->bus->qts, vqpci->msix_addr,0 ); +writel (d->bus->qts, vqpci->msix_addr,0 );return true; }else {return false;
@@ -192,9 +192,9 @@ static bool qvirtio_pci_get_config_isr_status(QVirtioDevice *d)/* No ISR checking should be done if masked, but read anyway */ return qpci_msix_pending (dev->pdev, dev->config_msix_entry); }else { - data =qtest_readl (d->bus->qts, dev->config_msix_addr); + data =readl (d->bus->qts, dev->config_msix_addr);if (data == dev->config_msix_data) { -qtest_writel (d->bus->qts, dev->config_msix_addr,0 ); +writel (d->bus->qts, dev->config_msix_addr,0 );return true; }else {return false;
tests/libqos/virtio.c +34 -39
163 lines not on this page · raw message
tests/m25p80-test.c +41 -39
186 lines not on this page · raw message
tests/m48t59-test.c +2 -2
@@ -32,14 +32,14 @@ static bool use_mmio;static uint8_t cmos_read_mmio (uint8_t reg) { -return readb (base + (uint32_t )reg_base + (uint32_t )reg); +return readb (global_qtest, base + (uint32_t )reg_base + (uint32_t )reg); }static void cmos_write_mmio (uint8_t reg,uint8_t val) {uint8_t data = val; -writeb (base + (uint32_t )reg_base + (uint32_t )reg, data); +writeb (global_qtest, base + (uint32_t )reg_base + (uint32_t )reg, data); }static uint8_t cmos_read_ioio (uint8_t reg)
tests/pnv-xscom-test.c +1 -1
@@ -69,7 +69,7 @@ static uint64_t pnv_xscom_addr(const PnvChip *chip, uint32_t pcba)static uint64_t pnv_xscom_read (const PnvChip *chip,uint32_t pcba) { -return readq (pnv_xscom_addr (chip, pcba)); +return readq (global_qtest,pnv_xscom_addr (chip, pcba)); }static void test_xscom_cfam_id (const PnvChip *chip)
tests/prom-env-test.c +1 -1
@@ -32,7 +32,7 @@ static void check_guest_memory(void)/* Poll until code has run and modified memory. Wait at most 120 seconds */ for (i =0 ; i <12000 ; ++i) { - signature =readl (ADDRESS ); + signature =readl (global_qtest,ADDRESS );if (signature ==MAGIC ) {break ; }
tests/q35-test.c +6 -6
@@ -174,14 +174,14 @@ static void test_tseg_size(const void *data)*/ ram_offs = (TSEG_SIZE_TEST_GUEST_RAM_MBYTES - args->expected_tseg_mbytes) *1024 *1024 -1 ; - g_assert_cmpint(readb(ram_offs), ==, 0); -writeb (ram_offs,1 ); - g_assert_cmpint(readb(ram_offs), ==, 1); + g_assert_cmpint(readb(global_qtest, ram_offs), ==, 0); +writeb (global_qtest, ram_offs,1 ); + g_assert_cmpint(readb(global_qtest, ram_offs), ==, 1); ram_offs++; - g_assert_cmpint(readb(ram_offs), ==, 0xff); -writeb (ram_offs,1 ); - g_assert_cmpint(readb(ram_offs), ==, 0xff); + g_assert_cmpint(readb(global_qtest, ram_offs), ==, 0xff); +writeb (global_qtest, ram_offs,1 ); + g_assert_cmpint(readb(global_qtest, ram_offs), ==, 0xff);g_free (pcidev);qpci_free_pc (pcibus);
tests/tco-test.c +2 -2
@@ -117,13 +117,13 @@ static void reset_on_second_timeout(bool enable) {uint32_t val; - val =readl (RCBA_BASE_ADDR +ICH9_CC_GCS ); + val =readl (global_qtest,RCBA_BASE_ADDR +ICH9_CC_GCS );if (enable) { val &= ~ICH9_CC_GCS_NO_REBOOT ; }else { val |=ICH9_CC_GCS_NO_REBOOT ; } -writel (RCBA_BASE_ADDR +ICH9_CC_GCS , val); +writel (global_qtest,RCBA_BASE_ADDR +ICH9_CC_GCS , val); }static void test_tco_defaults (void )
tests/test-arm-mptimer.c +7 -7
@@ -38,7 +38,7 @@ static int scaled = 122;static void timer_load (uint32_t load) { -writel (TIMER_BASE_PHYS +TIMER_LOAD , load); +writel (global_qtest,TIMER_BASE_PHYS +TIMER_LOAD , load); }static void timer_start (int periodic,uint32_t scale)
@@ -49,17 +49,17 @@ static void timer_start(int periodic, uint32_t scale) ctl |=TIMER_CONTROL_PERIODIC ; } -writel (TIMER_BASE_PHYS +TIMER_CONTROL , ctl); +writel (global_qtest,TIMER_BASE_PHYS +TIMER_CONTROL , ctl); }static void timer_stop (void ) { -writel (TIMER_BASE_PHYS +TIMER_CONTROL ,0 ); +writel (global_qtest,TIMER_BASE_PHYS +TIMER_CONTROL ,0 ); }static void timer_int_clr (void ) { -writel (TIMER_BASE_PHYS +TIMER_INTSTAT ,1 ); +writel (global_qtest,TIMER_BASE_PHYS +TIMER_INTSTAT ,1 ); }static void timer_reset (void )
@@ -71,7 +71,7 @@ static void timer_reset(void)static uint32_t timer_get_and_clr_int_sts (void ) { -uint32_t int_sts =readl (TIMER_BASE_PHYS +TIMER_INTSTAT ); +uint32_t int_sts =readl (global_qtest,TIMER_BASE_PHYS +TIMER_INTSTAT );if (int_sts) {timer_int_clr ();
@@ -82,12 +82,12 @@ static uint32_t timer_get_and_clr_int_sts(void)static uint32_t timer_counter (void ) { -return readl (TIMER_BASE_PHYS +TIMER_COUNTER ); +return readl (global_qtest,TIMER_BASE_PHYS +TIMER_COUNTER ); }static void timer_set_counter (uint32_t value) { -writel (TIMER_BASE_PHYS +TIMER_COUNTER , value); +writel (global_qtest,TIMER_BASE_PHYS +TIMER_COUNTER , value); }static void test_timer_oneshot (gconstpointer arg)
tests/vhost-user-test.c +1 -1
@@ -241,7 +241,7 @@ static void read_guest_mem(const void *data)for (j =0 ; j <256 ; j++) {uint32_t a, b; - a =qtest_readl (s->qts, + a =readl (s->qts, s->memory.regions[i].guest_phys_addr + j *4 ); b = guest_mem[j];
tests/virtio-blk-test.c +9 -9
@@ -195,7 +195,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,qvirtqueue_kick (dev, vq, free_head);qvirtio_wait_used_elem (dev, vq, free_head,QVIRTIO_BLK_TIMEOUT_US ); - status =readb (req_addr +528 ); + status =readb (global_qtest, req_addr +528 ); g_assert_cmpint(status, ==, 0);guest_free (alloc, req_addr);
@@ -217,7 +217,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,qvirtqueue_kick (dev, vq, free_head);qvirtio_wait_used_elem (dev, vq, free_head,QVIRTIO_BLK_TIMEOUT_US ); - status =readb (req_addr +528 ); + status =readb (global_qtest, req_addr +528 ); g_assert_cmpint(status, ==, 0); data =g_malloc0 (512 );
@@ -245,7 +245,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,qvirtqueue_kick (dev, vq, free_head);qvirtio_wait_used_elem (dev, vq, free_head,QVIRTIO_BLK_TIMEOUT_US ); - status =readb (req_addr +528 ); + status =readb (global_qtest, req_addr +528 ); g_assert_cmpint(status, ==, 0);guest_free (alloc, req_addr);
@@ -266,7 +266,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,qvirtqueue_kick (dev, vq, free_head);qvirtio_wait_used_elem (dev, vq, free_head,QVIRTIO_BLK_TIMEOUT_US ); - status =readb (req_addr +528 ); + status =readb (global_qtest, req_addr +528 ); g_assert_cmpint(status, ==, 0); data =g_malloc0 (512 );
@@ -350,7 +350,7 @@ static void pci_indirect(void)qvirtio_wait_used_elem (&dev->vdev, &vqpci->vq, free_head,QVIRTIO_BLK_TIMEOUT_US ); - status =readb (req_addr +528 ); + status =readb (global_qtest, req_addr +528 ); g_assert_cmpint(status, ==, 0);g_free (indirect);
@@ -376,7 +376,7 @@ static void pci_indirect(void)qvirtio_wait_used_elem (&dev->vdev, &vqpci->vq, free_head,QVIRTIO_BLK_TIMEOUT_US ); - status =readb (req_addr +528 ); + status =readb (global_qtest, req_addr +528 ); g_assert_cmpint(status, ==, 0); data =g_malloc0 (512 );
@@ -488,7 +488,7 @@ static void pci_msix(void)qvirtio_wait_used_elem (&dev->vdev, &vqpci->vq, free_head,QVIRTIO_BLK_TIMEOUT_US ); - status =readb (req_addr +528 ); + status =readb (global_qtest, req_addr +528 ); g_assert_cmpint(status, ==, 0);guest_free (qs->alloc, req_addr);
@@ -513,7 +513,7 @@ static void pci_msix(void)qvirtio_wait_used_elem (&dev->vdev, &vqpci->vq, free_head,QVIRTIO_BLK_TIMEOUT_US ); - status =readb (req_addr +528 ); + status =readb (global_qtest, req_addr +528 ); g_assert_cmpint(status, ==, 0); data =g_malloc0 (512 );
@@ -636,7 +636,7 @@ static void pci_idx(void)g_assert (qvirtqueue_get_buf (&vqpci->vq, &desc_idx)); g_assert_cmpint(desc_idx, ==, free_head); - status =readb (req_addr +528 ); + status =readb (global_qtest, req_addr +528 ); g_assert_cmpint(status, ==, 0); data =g_malloc0 (512 );
tests/virtio-scsi-test.c +1 -1
@@ -125,7 +125,7 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb,qvirtqueue_kick (vs->dev, vq, free_head);qvirtio_wait_used_elem (vs->dev, vq, free_head,QVIRTIO_SCSI_TIMEOUT_US ); - response =readb (resp_addr + + response =readb (global_qtest, resp_addr + offsetof(struct virtio_scsi_cmd_resp , response));if (resp_out) {
tests/vmgenid-test.c +1 -1
@@ -105,7 +105,7 @@ static void read_guid_from_memory(QemuUUID *guid)/* Read the GUID directly from guest memory */ for (i =0 ; i <16 ; i++) { - guid->data[i] =readb (vmgenid_addr + i); + guid->data[i] =readb (global_qtest, vmgenid_addr + i); }/* The GUID is in little-endian format in the guest, while QEMU * uses big-endian. Swap after reading.
Signature · 1 line
2.13.5
PATCH v7 35/38 libqtest: Merge qtest_{mem, buf}{read, write}() with {mem, buf}{read, write}()
In reply to Eric BlakeMaintaining two layers of libqtest APIs, one that takes an explicit QTestState object, and the other that uses the implicit global_qtest, is annoying. In the interest of getting rid of global implicit state and having less code to maintain, merge:
qtest_memread()
qtest_bufread()
qtest_memwrite()
qtest_bufwrite()
with their short counterparts. All callers that previously used the short form now make it explicit that they are relying on global_qtest, and later patches can then clean things up to remove the global variable.
--- tests/libqtest.h | 69 ++++++------------------------------------------ tests/libqtest.c | 8 +++--- tests/ahci-test.c | 16 +++++------ tests/e1000e-test.c | 16 ++++++----- tests/i440fx-test.c | 8 +++--- tests/ide-test.c | 14 +++++----- tests/libqos/ahci.c | 22 +++++++-------- tests/libqos/pci-pc.c | 4 +-- tests/libqos/pci-spapr.c | 4 +-- tests/megasas-test.c | 2 +- tests/postcopy-test.c | 12 ++++----- tests/virtio-9p-test.c | 4 +-- tests/virtio-blk-test.c | 16 +++++------ tests/virtio-net-test.c | 6 ++--- tests/virtio-scsi-test.c | 4 +-- 15 files changed, 78 insertions(+), 127 deletions(-)
tests/libqtest.h +8 -61
@@ -346,7 +346,7 @@ uint32_t readl(QTestState *s, uint64_t addr);uint64_t readq (QTestState *s,uint64_t addr);/** -* qtest_memread: +* memread: * @s: #QTestState instance to operate on. * @addr: Guest address to read from. * @data: Pointer to where memory contents will be stored.
@@ -354,7 +354,7 @@ uint64_t readq(QTestState *s, uint64_t addr);* * Read guest memory into a buffer. */ -void qtest_memread (QTestState *s,uint64_t addr,void *data,size_t size); +void memread (QTestState *s,uint64_t addr,void *data,size_t size);/** * qtest_rtas_call:
@@ -372,7 +372,7 @@ uint64_t qtest_rtas_call(QTestState *s, const char *name, uint32_t nret, uint64_t ret);/** -* qtest_bufread: +* bufread: * @s: #QTestState instance to operate on. * @addr: Guest address to read from. * @data: Pointer to where memory contents will be stored.
@@ -380,10 +380,10 @@ uint64_t qtest_rtas_call(QTestState *s, const char *name,* * Read guest memory into a buffer and receive using a base64 encoding. */ -void qtest_bufread (QTestState *s,uint64_t addr,void *data,size_t size); +void bufread (QTestState *s,uint64_t addr,void *data,size_t size);/** -* qtest_memwrite: +* memwrite: * @s: #QTestState instance to operate on. * @addr: Guest address to write to. * @data: Pointer to the bytes that will be written to guest memory.
@@ -391,10 +391,10 @@ void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size);* * Write a buffer to guest memory. */ -void qtest_memwrite (QTestState *s,uint64_t addr,const void *data,size_t size); +void memwrite (QTestState *s,uint64_t addr,const void *data,size_t size);/** -* qtest_bufwrite: +* bufwrite: * @s: #QTestState instance to operate on. * @addr: Guest address to write to. * @data: Pointer to the bytes that will be written to guest memory.
@@ -402,8 +402,7 @@ void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size)* * Write a buffer to guest memory and transmit using a base64 encoding. */ -void qtest_bufwrite (QTestState *s,uint64_t addr, -const void *data,size_t size); +void bufwrite (QTestState *s,uint64_t addr,const void *data,size_t size);/** * qtest_memset:
@@ -594,58 +593,6 @@ static inline QDict *qmp_eventwait_ref(const char *event)char *hmp (const char *fmt, ...)GCC_FMT_ATTR (1 ,2 );/** -* memread: -* @addr: Guest address to read from. -* @data: Pointer to where memory contents will be stored. -* @size: Number of bytes to read. -* -* Read guest memory into a buffer. -*/ -static inline void memread (uint64_t addr,void *data,size_t size) -{ -qtest_memread (global_qtest, addr, data, size); -} - -/** -* bufread: -* @addr: Guest address to read from. -* @data: Pointer to where memory contents will be stored. -* @size: Number of bytes to read. -* -* Read guest memory into a buffer, receive using a base64 encoding. -*/ -static inline void bufread (uint64_t addr,void *data,size_t size) -{ -qtest_bufread (global_qtest, addr, data, size); -} - -/** -* memwrite: -* @addr: Guest address to write to. -* @data: Pointer to the bytes that will be written to guest memory. -* @size: Number of bytes to write. -* -* Write a buffer to guest memory. -*/ -static inline void memwrite (uint64_t addr,const void *data,size_t size) -{ -qtest_memwrite (global_qtest, addr, data, size); -} - -/** -* bufwrite: -* @addr: Guest address to write to. -* @data: Pointer to the bytes that will be written to guest memory. -* @size: Number of bytes to write. -* -* Write a buffer to guest memory, transmit using a base64 encoding. -*/ -static inline void bufwrite (uint64_t addr,const void *data,size_t size) -{ -qtest_bufwrite (global_qtest, addr, data, size); -} - -/** * qmemset: * @addr: Guest address to write to. * @patt: Byte pattern to fill the guest memory region with.
tests/libqtest.c +4 -4
@@ -822,7 +822,7 @@ static int hex2nib(char ch) } } -void qtest_memread (QTestState *s,uint64_t addr,void *data,size_t size) +void memread (QTestState *s,uint64_t addr,void *data,size_t size) {uint8_t *ptr = data;gchar **args;
@@ -877,7 +877,7 @@ void qtest_add_data_func(const char *str, const void *data,g_free (path); } -void qtest_bufwrite (QTestState *s,uint64_t addr,const void *data,size_t size) +void bufwrite (QTestState *s,uint64_t addr,const void *data,size_t size) {gchar *bdata;
@@ -889,7 +889,7 @@ void qtest_bufwrite(QTestState *s, uint64_t addr, const void *data, size_t size)g_free (bdata); } -void qtest_bufread (QTestState *s,uint64_t addr,void *data,size_t size) +void bufread (QTestState *s,uint64_t addr,void *data,size_t size) {gchar **args;size_t len;
@@ -908,7 +908,7 @@ void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size)g_strfreev (args); } -void qtest_memwrite (QTestState *s,uint64_t addr,const void *data,size_t size) +void memwrite (QTestState *s,uint64_t addr,const void *data,size_t size) {const uint8_t *ptr = data;size_t i;
tests/ahci-test.c +8 -8
@@ -869,7 +869,7 @@ static void ahci_test_io_rw_simple(AHCIQState *ahci, unsigned bufsize,/* Write some indicative pattern to our buffer. */ generate_pattern (tx, bufsize,AHCI_SECTOR_SIZE ); -qtest_bufwrite (ahci->parent->qts, ptr, tx, bufsize); +bufwrite (ahci->parent->qts, ptr, tx, bufsize);/* Write this buffer to disk, then read it back to the DMA buffer. */ ahci_guest_io (ahci, port, write_cmd, ptr, bufsize, sector);
@@ -877,7 +877,7 @@ static void ahci_test_io_rw_simple(AHCIQState *ahci, unsigned bufsize,ahci_guest_io (ahci, port, read_cmd, ptr, bufsize, sector);/*** Read back the Data ***/ -qtest_bufread (ahci->parent->qts, ptr, rx, bufsize); +bufread (ahci->parent->qts, ptr, rx, bufsize); g_assert_cmphex(memcmp(tx, rx, bufsize), ==, 0);ahci_free (ahci, ptr);
@@ -918,7 +918,7 @@ static void ahci_test_max(AHCIQState *ahci) } port =ahci_test_nondata (ahci, cmd); -qtest_memread (ahci->parent->qts, ahci->port[port].fb +0x40 , d2h,0x20 ); +memread (ahci->parent->qts, ahci->port[port].fb +0x40 , d2h,0x20 ); nsect = (uint64_t )d2h->lba_hi[2 ] <<40 | (uint64_t )d2h->lba_hi[1 ] <<32 | (uint64_t)d2h->lba_hi[0] << 24 |
@@ -1036,7 +1036,7 @@ static void test_dma_fragmented(void)/* Create a DMA buffer in guest memory, and write our pattern to it. */ ptr =guest_alloc (ahci->parent->alloc, bufsize);g_assert (ptr); -qtest_bufwrite (ahci->parent->qts, ptr, tx, bufsize); +bufwrite (ahci->parent->qts, ptr, tx, bufsize); cmd =ahci_command_create (CMD_WRITE_DMA );ahci_command_adjust (cmd,0 , ptr, bufsize,32 );
@@ -1053,7 +1053,7 @@ static void test_dma_fragmented(void)ahci_command_free (cmd);/* Read back the guest's receive buffer into local memory */ -qtest_bufread (ahci->parent->qts, ptr, rx, bufsize); +bufread (ahci->parent->qts, ptr, rx, bufsize);guest_free (ahci->parent->alloc, ptr); g_assert_cmphex(memcmp(tx, rx, bufsize), ==, 0);
@@ -1231,7 +1231,7 @@ static void ahci_halted_io_test(uint8_t cmd_read, uint8_t cmd_write)generate_pattern (tx, bufsize,AHCI_SECTOR_SIZE ); ptr =ahci_alloc (ahci, bufsize);g_assert (ptr); -qtest_memwrite (ahci->parent->qts, ptr, tx, bufsize); +memwrite (ahci->parent->qts, ptr, tx, bufsize);/* Attempt to write (and fail) */ cmd = ahci_guest_io_halt(ahci, port, cmd_write,
@@ -1305,7 +1305,7 @@ static void ahci_migrate_halted_io(uint8_t cmd_read, uint8_t cmd_write)/* create DMA source buffer and write pattern */ ptr =ahci_alloc (src, bufsize);g_assert (ptr); -qtest_memwrite (src->parent->qts, ptr, tx, bufsize); +memwrite (src->parent->qts, ptr, tx, bufsize);/* Write, trigger the VM to stop, migrate, then resume. */ cmd = ahci_guest_io_halt(src, port, cmd_write,
@@ -1472,7 +1472,7 @@ static int ahci_cb_cmp_buff(AHCIQState *ahci, AHCICommand *cmd, } rx =g_malloc0 (opts->size); -qtest_bufread (ahci->parent->qts, opts->buffer, rx, opts->size); +bufread (ahci->parent->qts, opts->buffer, rx, opts->size); g_assert_cmphex(memcmp(tx, rx, opts->size), ==, 0);g_free (rx);
tests/e1000e-test.c +10 -6
@@ -202,11 +202,13 @@ static void e1000e_tx_ring_push(e1000e_device *d, void *descr)uint32_t tail =e1000e_macreg_read (d,E1000E_TDT );uint32_t len =e1000e_macreg_read (d,E1000E_TDLEN ) /E1000E_TXD_LEN ; -memwrite (d->tx_ring + tail *E1000E_TXD_LEN , descr,E1000E_TXD_LEN ); +memwrite (global_qtest, d->tx_ring + tail *E1000E_TXD_LEN , descr, +E1000E_TXD_LEN );e1000e_macreg_write (d,E1000E_TDT , (tail +1 ) % len);/* Read WB data for the packet transmitted */ -memread (d->tx_ring + tail *E1000E_TXD_LEN , descr,E1000E_TXD_LEN ); +memread (global_qtest, d->tx_ring + tail *E1000E_TXD_LEN , descr, +E1000E_TXD_LEN ); }static void e1000e_rx_ring_push (e1000e_device *d,void *descr)
@@ -214,11 +216,13 @@ static void e1000e_rx_ring_push(e1000e_device *d, void *descr)uint32_t tail =e1000e_macreg_read (d,E1000E_RDT );uint32_t len =e1000e_macreg_read (d,E1000E_RDLEN ) /E1000E_RXD_LEN ; -memwrite (d->rx_ring + tail *E1000E_RXD_LEN , descr,E1000E_RXD_LEN ); +memwrite (global_qtest, d->rx_ring + tail *E1000E_RXD_LEN , descr, +E1000E_RXD_LEN );e1000e_macreg_write (d,E1000E_RDT , (tail +1 ) % len);/* Read WB data for the packet received */ -memread (d->rx_ring + tail *E1000E_RXD_LEN , descr,E1000E_RXD_LEN ); +memread (global_qtest, d->rx_ring + tail *E1000E_RXD_LEN , descr, +E1000E_RXD_LEN ); }static void e1000e_wait_isr (e1000e_device *d,uint16_t msg_id)
@@ -269,7 +273,7 @@ static void e1000e_send_verify(e1000e_device *d)/* Prepare test data buffer */ uint64_t data =guest_alloc (test_alloc, data_len); -memwrite (data,"TEST" ,5 ); +memwrite (global_qtest, data,"TEST" ,5 );/* Prepare TX descriptor */ memset (&descr,0 ,sizeof (descr));
@@ -365,7 +369,7 @@ static void e1000e_receive_verify(e1000e_device *d) esta_dd, ==, esta_dd);/* Check data sent to the backend */ -memread (data, buffer,sizeof (buffer)); +memread (global_qtest, data, buffer,sizeof (buffer)); g_assert_cmpstr(buffer, == , "TEST");/* Free test data buffer */
tests/i440fx-test.c +4 -4
@@ -160,7 +160,7 @@ static gboolean verify_area(uint32_t start, uint32_t end, uint8_t value)int i; data =g_malloc0 (size); -memread (start, data, size); +memread (global_qtest, start, data, size);g_test_message ("verify_area: data[0] = 0x%x" , data[0 ]);
@@ -183,7 +183,7 @@ static void write_area(uint32_t start, uint32_t end, uint8_t value) data =g_malloc (size);memset (data, value, size); -memwrite (start, data, size); +memwrite (global_qtest, start, data, size);g_free (data); }
@@ -354,7 +354,7 @@ static void test_i440fx_firmware(FirmwareTestFixture *fixture,/* check below 4G */ buf =g_malloc0 (BLOB_SIZE ); -memread (0x100000000ULL -BLOB_SIZE , buf,BLOB_SIZE ); +memread (global_qtest,0x100000000ULL -BLOB_SIZE , buf,BLOB_SIZE );for (i =0 ; i <BLOB_SIZE ; ++i) { g_assert_cmphex(buf[i], ==, (uint8_t)i); }
@@ -362,7 +362,7 @@ static void test_i440fx_firmware(FirmwareTestFixture *fixture,/* check in ISA space too */ memset (buf,0 ,BLOB_SIZE ); isa_bios_size =ISA_BIOS_MAXSZ <BLOB_SIZE ?ISA_BIOS_MAXSZ :BLOB_SIZE ; -memread (0x100000 - isa_bios_size, buf, isa_bios_size); +memread (global_qtest,0x100000 - isa_bios_size, buf, isa_bios_size);for (i =0 ; i < isa_bios_size; ++i) { g_assert_cmphex(buf[i], ==, (uint8_t )((BLOB_SIZE - isa_bios_size) + i));
tests/ide-test.c +7 -7
@@ -222,7 +222,7 @@ static int send_dma_request(int cmd, uint64_t sector, int nb_sectors,/* Setup PRDT */ len =sizeof (*prdt) * prdt_entries; guest_prdt =guest_alloc (guest_malloc, len); -memwrite (guest_prdt, prdt, len); +memwrite (global_qtest, guest_prdt, prdt, len);qpci_io_writel (dev, bmdma_bar, bmreg_prdt, guest_prdt);/* ATA DMA command */
@@ -299,7 +299,7 @@ static void test_bmdma_simple_rw(void)/* Write 0x55 pattern to sector 0 */ memset (buf,0x55 , len); -memwrite (guest_buf, buf, len); +memwrite (global_qtest, guest_buf, buf, len); status =send_dma_request (CMD_WRITE_DMA ,0 ,1 , prdt,ARRAY_SIZE (prdt),NULL );
@@ -308,7 +308,7 @@ static void test_bmdma_simple_rw(void)/* Write 0xaa pattern to sector 1 */ memset (buf,0xaa , len); -memwrite (guest_buf, buf, len); +memwrite (global_qtest, guest_buf, buf, len); status =send_dma_request (CMD_WRITE_DMA ,1 ,1 , prdt,ARRAY_SIZE (prdt),NULL );
@@ -322,7 +322,7 @@ static void test_bmdma_simple_rw(void) g_assert_cmphex(status, ==, BM_STS_INTR);assert_bit_clear (qpci_io_readb (dev, ide_bar, reg_status),DF |ERR ); -memread (guest_buf, buf, len); +memread (global_qtest, guest_buf, buf, len);g_assert (memcmp (buf, cmpbuf, len) ==0 );/* Read and verify 0xaa pattern in sector 1 */
@@ -332,7 +332,7 @@ static void test_bmdma_simple_rw(void) g_assert_cmphex(status, ==, BM_STS_INTR);assert_bit_clear (qpci_io_readb (dev, ide_bar, reg_status),DF |ERR ); -memread (guest_buf, buf, len); +memread (global_qtest, guest_buf, buf, len);g_assert (memcmp (buf, cmpbuf, len) ==0 );
@@ -551,7 +551,7 @@ static void make_dirty(uint8_t device)g_assert (guest_buf);g_assert (buf); -memwrite (guest_buf, buf, len); +memwrite (global_qtest, guest_buf, buf, len);PrdtEntry prdt[] = { {
@@ -921,7 +921,7 @@ static void test_cdrom_dma(void)send_dma_request (CMD_PACKET ,0 ,1 , prdt,1 , send_scsi_cdb_read10);/* Read back data from guest memory into local qtest memory */ -memread (guest_buf, rx, len); +memread (global_qtest, guest_buf, rx, len); g_assert_cmpint(memcmp(pattern, rx, len), ==, 0);g_free (pattern);
tests/libqos/ahci.c +11 -11
@@ -467,7 +467,7 @@ void ahci_port_check_d2h_sanity(AHCIQState *ahci, uint8_t port, uint8_t slot)RegD2HFIS *d2h =g_malloc0 (0x20 );uint32_t reg; -qtest_memread (ahci->parent->qts, ahci->port[port].fb +0x40 , d2h,0x20 ); +memread (ahci->parent->qts, ahci->port[port].fb +0x40 , d2h,0x20 ); g_assert_cmphex(d2h->fis_type, ==, 0x34); reg =ahci_px_rreg (ahci, port,AHCI_PX_TFD );
@@ -485,7 +485,7 @@ void ahci_port_check_pio_sanity(AHCIQState *ahci, uint8_t port,/* We cannot check the Status or E_Status registers, because * the status may have again changed between the PIO Setup FIS * and the conclusion of the command with the D2H Register FIS. */ -qtest_memread (ahci->parent->qts, ahci->port[port].fb +0x20 , pio,0x20 ); +memread (ahci->parent->qts, ahci->port[port].fb +0x20 , pio,0x20 ); g_assert_cmphex(pio->fis_type, ==, 0x5f);/* BUG: PIO Setup FIS as utilized by QEMU tries to fit the entire
@@ -517,7 +517,7 @@ void ahci_get_command_header(AHCIQState *ahci, uint8_t port, {uint64_t ba = ahci->port[port].clb; ba += slot *sizeof (AHCICommandHeader); -qtest_memread (ahci->parent->qts, ba, cmd,sizeof (AHCICommandHeader)); +memread (ahci->parent->qts, ba, cmd,sizeof (AHCICommandHeader)); cmd->flags =le16_to_cpu (cmd->flags); cmd->prdtl =le16_to_cpu (cmd->prdtl);
@@ -538,7 +538,7 @@ void ahci_set_command_header(AHCIQState *ahci, uint8_t port, tmp.prdbc =cpu_to_le32 (cmd->prdbc); tmp.ctba =cpu_to_le64 (cmd->ctba); -qtest_memwrite (ahci->parent->qts, ba, &tmp,sizeof (AHCICommandHeader)); +memwrite (ahci->parent->qts, ba, &tmp,sizeof (AHCICommandHeader)); }void ahci_destroy_command (AHCIQState *ahci,uint8_t port,uint8_t slot)
@@ -576,7 +576,7 @@ void ahci_write_fis(AHCIQState *ahci, AHCICommand *cmd) tmp.count =cpu_to_le16 (tmp.count); } -qtest_memwrite (ahci->parent->qts, addr, &tmp,sizeof (tmp)); +memwrite (ahci->parent->qts, addr, &tmp,sizeof (tmp)); }unsigned ahci_pick_cmd (AHCIQState *ahci,uint8_t port)
@@ -758,13 +758,13 @@ void ahci_io(AHCIQState *ahci, uint8_t port, uint8_t ide_cmd,qtest_memset (ahci->parent->qts, ptr,0x00 , bufsize);if (bufsize && props->write) { -qtest_bufwrite (ahci->parent->qts, ptr, buffer, bufsize); +bufwrite (ahci->parent->qts, ptr, buffer, bufsize); }ahci_guest_io (ahci, port, ide_cmd, ptr, bufsize, sector);if (bufsize && props->read) { -qtest_bufread (ahci->parent->qts, ptr, buffer, bufsize); +bufread (ahci->parent->qts, ptr, buffer, bufsize); }ahci_free (ahci, ptr);
@@ -902,7 +902,7 @@ static int copy_buffer(AHCIQState *ahci, AHCICommand *cmd, const AHCIOpts *opts) {unsigned char *rx = opts->opaque; -qtest_bufread (ahci->parent->qts, opts->buffer, rx, opts->size); +bufread (ahci->parent->qts, opts->buffer, rx, opts->size);return 0 ; }
@@ -1142,7 +1142,7 @@ void ahci_command_commit(AHCIQState *ahci, AHCICommand *cmd, uint8_t port)ahci_write_fis (ahci, cmd);/* Then ATAPI CMD, if needed */ if (cmd->props->atapi) { -qtest_memwrite (ahci->parent->qts, table_ptr +0x40 , cmd->atapi_cmd,16 ); +memwrite (ahci->parent->qts, table_ptr +0x40 , cmd->atapi_cmd,16 ); }/* Construct and write the PRDs to the command table */
@@ -1163,8 +1163,8 @@ void ahci_command_commit(AHCIQState *ahci, AHCICommand *cmd, uint8_t port) prd.dbc |=cpu_to_le32 (0x80000000 );/* Request DPS Interrupt */ /* Commit the PRD entry to the Command Table */ -qtest_memwrite (ahci->parent->qts, table_ptr +0x80 + (i *sizeof (PRD )), - &prd,sizeof (PRD )); +memwrite (ahci->parent->qts, table_ptr +0x80 + (i *sizeof (PRD )), + &prd,sizeof (PRD )); }/* Bookmark the PRDTL and CTBA values */
tests/libqos/pci-pc.c +2 -2
@@ -68,13 +68,13 @@ static void qpci_pc_pio_writeq(QPCIBus *bus, uint32_t addr, uint64_t val)static void qpci_pc_memread (QPCIBus *bus,uint32_t addr,void *buf,size_t len) { -qtest_memread (bus->qts, addr, buf, len); +memread (bus->qts, addr, buf, len); }static void qpci_pc_memwrite (QPCIBus *bus,uint32_t addr,const void *buf,size_t len) { -qtest_memwrite (bus->qts, addr, buf, len); +memwrite (bus->qts, addr, buf, len); }static uint8_t qpci_pc_config_readb (QPCIBus *bus,int devfn,uint8_t offset)
tests/libqos/pci-spapr.c +2 -2
@@ -94,14 +94,14 @@ static void qpci_spapr_memread(QPCIBus *bus, uint32_t addr, void *buf, size_t len) {QPCIBusSPAPR *s =container_of (bus, QPCIBusSPAPR, bus); -qtest_memread (bus->qts, s->mmio32_cpu_base + addr, buf, len); +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); -qtest_memwrite (bus->qts, s->mmio32_cpu_base + addr, buf, len); +memwrite (bus->qts, s->mmio32_cpu_base + addr, buf, len); }static uint8_t qpci_spapr_config_readb (QPCIBus *bus,int devfn,uint8_t offset)
tests/megasas-test.c +1 -1
@@ -72,7 +72,7 @@ static void megasas_pd_get_info_fuzz(void) context[7 ] =cpu_to_le32 (0 ); context_pa =qmalloc (qs,sizeof (context)); -memwrite (context_pa, context,sizeof (context)); +memwrite (global_qtest, context_pa, context,sizeof (context));qpci_io_writel (dev, bar,0x40 , context_pa);g_free (dev);
tests/postcopy-test.c +6 -6
@@ -320,13 +320,13 @@ static void check_guests_ram(QTestState *qts)bool hit_edge = false;bool bad = false; -qtest_memread (qts, start_address, &first_byte,1 ); +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 (qts, address, &b,1 ); +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
@@ -470,19 +470,19 @@ static void test_migrate(void)qtest_quit (from); -qtest_memread (to, start_address, &dest_byte_a,1 ); +memread (to, start_address, &dest_byte_a,1 );/* Destination still running, wait for a byte to change */ do { -qtest_memread (to, start_address, &dest_byte_b,1 ); +memread (to, start_address, &dest_byte_b,1 );usleep (10 *1000 ); }while (dest_byte_a == dest_byte_b);qtest_qmp_discard_response (to,"{ 'execute' : 'stop'}" );/* With it stopped, check nothing changes */ -qtest_memread (to, start_address, &dest_byte_c,1 ); +memread (to, start_address, &dest_byte_c,1 );sleep (1 ); -qtest_memread (to, start_address, &dest_byte_d,1 ); +memread (to, start_address, &dest_byte_d,1 ); g_assert_cmpint(dest_byte_c, ==, dest_byte_d);check_guests_ram (to);
tests/virtio-9p-test.c +2 -2
@@ -116,7 +116,7 @@ typedef struct {static void v9fs_memwrite (P9Req *req,const void *addr,size_t len) { -memwrite (req->t_msg + req->t_off, addr, len); +memwrite (global_qtest, req->t_msg + req->t_off, addr, len); req->t_off += len; }
@@ -132,7 +132,7 @@ static void v9fs_memrewind(P9Req *req, size_t len)static void v9fs_memread (P9Req *req,void *addr,size_t len) { -memread (req->r_msg + req->r_off, addr, len); +memread (global_qtest, req->r_msg + req->r_off, addr, len); req->r_off += len; }
tests/virtio-blk-test.c +8 -8
@@ -145,9 +145,9 @@ static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioDevice *d,virtio_blk_fix_request (d, req); -memwrite (addr, req,16 ); -memwrite (addr +16 , req->data, data_size); -memwrite (addr +16 + data_size, &status,sizeof (status)); +memwrite (global_qtest, addr, req,16 ); +memwrite (global_qtest, addr +16 , req->data, data_size); +memwrite (global_qtest, addr +16 + data_size, &status,sizeof (status));return addr; }
@@ -221,7 +221,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc, g_assert_cmpint(status, ==, 0); data =g_malloc0 (512 ); -memread (req_addr +16 , data,512 ); +memread (global_qtest, req_addr +16 , data,512 ); g_assert_cmpstr(data, ==, "TEST");g_free (data);
@@ -270,7 +270,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc, g_assert_cmpint(status, ==, 0); data =g_malloc0 (512 ); -memread (req_addr +16 , data,512 ); +memread (global_qtest, req_addr +16 , data,512 ); g_assert_cmpstr(data, ==, "TEST");g_free (data);
@@ -380,7 +380,7 @@ static void pci_indirect(void) g_assert_cmpint(status, ==, 0); data =g_malloc0 (512 ); -memread (req_addr +16 , data,512 ); +memread (global_qtest, req_addr +16 , data,512 ); g_assert_cmpstr(data, ==, "TEST");g_free (data);
@@ -517,7 +517,7 @@ static void pci_msix(void) g_assert_cmpint(status, ==, 0); data =g_malloc0 (512 ); -memread (req_addr +16 , data,512 ); +memread (global_qtest, req_addr +16 , data,512 ); g_assert_cmpstr(data, ==, "TEST");g_free (data);
@@ -640,7 +640,7 @@ static void pci_idx(void) g_assert_cmpint(status, ==, 0); data =g_malloc0 (512 ); -memread (req_addr +16 , data,512 ); +memread (global_qtest, req_addr +16 , data,512 ); g_assert_cmpstr(data, ==, "TEST");g_free (data);
tests/virtio-net-test.c +3 -3
@@ -112,7 +112,7 @@ static void rx_test(QVirtioDevice *dev, g_assert_cmpint(ret, ==, sizeof(test) + sizeof(len));qvirtio_wait_used_elem (dev, vq, free_head,QVIRTIO_NET_TIMEOUT_US ); -memread (req_addr +VNET_HDR_SIZE , buffer,sizeof (test)); +memread (global_qtest, req_addr +VNET_HDR_SIZE , buffer,sizeof (test)); g_assert_cmpstr(buffer, ==, "TEST");guest_free (alloc, req_addr);
@@ -129,7 +129,7 @@ static void tx_test(QVirtioDevice *dev,int ret; req_addr =guest_alloc (alloc,64 ); -memwrite (req_addr +VNET_HDR_SIZE ,"TEST" ,4 ); +memwrite (global_qtest, req_addr +VNET_HDR_SIZE ,"TEST" ,4 ); free_head =qvirtqueue_add (vq, req_addr,64 , false, false);qvirtqueue_kick (dev, vq, free_head);
@@ -186,7 +186,7 @@ static void rx_stop_cont_test(QVirtioDevice *dev,QDECREF (rsp);qvirtio_wait_used_elem (dev, vq, free_head,QVIRTIO_NET_TIMEOUT_US ); -memread (req_addr +VNET_HDR_SIZE , buffer,sizeof (test)); +memread (global_qtest, req_addr +VNET_HDR_SIZE , buffer,sizeof (test)); g_assert_cmpstr(buffer, ==, "TEST");guest_free (alloc, req_addr);
tests/virtio-scsi-test.c +2 -2
@@ -77,7 +77,7 @@ static uint64_t qvirtio_scsi_alloc(QVirtIOSCSI *vs, size_t alloc_size, addr =guest_alloc (vs->qs->alloc, alloc_size);if (data) { -memwrite (addr, data, alloc_size); +memwrite (global_qtest, addr, data, alloc_size); }return addr;
@@ -129,7 +129,7 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb, offsetof(struct virtio_scsi_cmd_resp, response));if (resp_out) { -memread (resp_addr, resp_out,sizeof (*resp_out)); +memread (global_qtest, resp_addr, resp_out,sizeof (*resp_out)); }guest_free (vs->qs->alloc, req_addr);
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PATCH v7 35/38] libqtest: Merge qtest_{mem, buf}{read, write}() with {mem, buf}{read, write}()
Quoted 32 lines · On Mon, 11 Sep 2017 12:20:19 -0500 Eric Blake <[email protected]> wrote:
Maintaining two layers of libqtest APIs, one that takes an explicit QTestState object, and the other that uses the implicit
global_qtest, is annoying. In the interest of getting rid of global implicit state and having less code to maintain, merge:
qtest_memread()
qtest_bufread()
qtest_memwrite()
qtest_bufwrite()
with their short counterparts. All callers that previously used the short form now make it explicit that they are relying onglobal_qtest, and later patches can then clean things up to remove the global variable.Signed-off-by Eric Blake <[email protected]>--- tests/libqtest.h | 69 ++++++------------------------------------------ tests/libqtest.c | 8 +++--- tests/ahci-test.c | 16 +++++------ tests/e1000e-test.c | 16 ++++++----- tests/i440fx-test.c | 8 +++--- tests/ide-test.c | 14 +++++----- tests/libqos/ahci.c | 22 +++++++-------- tests/libqos/pci-pc.c | 4 +-- tests/libqos/pci-spapr.c | 4 +-- tests/megasas-test.c | 2 +- tests/postcopy-test.c | 12 ++++----- tests/virtio-9p-test.c | 4 +-- tests/virtio-blk-test.c | 16 +++++------ tests/virtio-net-test.c | 6 ++--- tests/virtio-scsi-test.c | 4 +-- 15 files changed, 78 insertions(+), 127 deletions(-)
[...]
tests/virtio-9p-test.c typedef struct { · line 119
Quoted 10 lines
tests/virtio-9p-test.c +1
-1@@ -116,7 +116,7 @@ typedef struct {static void v9fs_memwrite (P9Req *req,const void *addr,size_t len) { -memwrite (req->t_msg + req->t_off, addr, len); +memwrite (global_qtest, req->t_msg + req->t_off, addr, len);
Maybe use req->v9p->qs->qts instead of global_qtest ?
tests/virtio-9p-test.c static void v9fs_memrewind(P9Req *req, size_t len) · line 135
Quoted 9 lines
tests/virtio-9p-test.c +1
-1req->t_off += len; }@@ -132,7 +132,7 @@ static void v9fs_memrewind(P9Req *req, size_t len)static void v9fs_memread (P9Req *req,void *addr,size_t len) { -memread (req->r_msg + req->r_off, addr, len); +memread (global_qtest, req->r_msg + req->r_off, addr, len);
Same here.
But this can be done in a follow-up patch. In case you don't respin, for tests/virtio-9p-test.c:
PATCH v7 36/38 libqtest: Merge qtest_memset() with qmemset()
In reply to Eric BlakeMaintaining two layers of libqtest APIs, one that takes an explicit QTestState object, and the other that uses the implicit global_qtest, is annoying. In the interest of getting rid of global implicit state and having less code to maintain, merge:
qtest_memset()
with its short counterpart. All callers that previously used the short form now make it explicit that they are relying on global_qtest, and later patches can then clean things up to remove the global variable.
--- tests/libqtest.h | 17 ++--------------- tests/libqtest.c | 2 +- tests/ahci-test.c | 2 +- tests/libqos/ahci.c | 12 ++++++------ 4 files changed, 10 insertions(+), 23 deletions(-)
tests/libqtest.h +2 -15
@@ -405,7 +405,7 @@ void memwrite(QTestState *s, uint64_t addr, const void *data, size_t size);void bufwrite (QTestState *s,uint64_t addr,const void *data,size_t size);/** -* qtest_memset: +* qmemset: * @s: #QTestState instance to operate on. * @addr: Guest address to write to. * @patt: Byte pattern to fill the guest memory region with.
@@ -413,7 +413,7 @@ void bufwrite(QTestState *s, uint64_t addr, const void *data, size_t size);* * Write a pattern to guest memory. */ -void qtest_memset (QTestState *s,uint64_t addr,uint8_t patt,size_t size); +void qmemset (QTestState *s,uint64_t addr,uint8_t patt,size_t size);/** * clock_step_next:
@@ -592,19 +592,6 @@ static inline QDict *qmp_eventwait_ref(const char *event)*/ char *hmp (const char *fmt, ...)GCC_FMT_ATTR (1 ,2 ); -/** -* qmemset: -* @addr: Guest address to write to. -* @patt: Byte pattern to fill the guest memory region with. -* @size: Number of bytes to write. -* -* Write a pattern to guest memory. -*/ -static inline void qmemset (uint64_t addr,uint8_t patt,size_t size) -{ -qtest_memset (global_qtest, addr, patt, size); -} -QDict *qmp_fd_receive (int fd);void qmp_fd_sendv (int fd,const char *fmt,va_list ap);void qmp_fd_send (int fd,const char *fmt, ...);
tests/libqtest.c +1 -1
@@ -929,7 +929,7 @@ void memwrite(QTestState *s, uint64_t addr, const void *data, size_t size)g_free (enc); } -void qtest_memset (QTestState *s,uint64_t addr,uint8_t pattern,size_t size) +void qmemset (QTestState *s,uint64_t addr,uint8_t pattern,size_t size) {qtest_sendf (s,"memset 0x%" PRIx64" 0x%zx 0x%02x\n" , addr, size, pattern);qtest_rsp (s,0 );
tests/ahci-test.c +1 -1
@@ -873,7 +873,7 @@ static void ahci_test_io_rw_simple(AHCIQState *ahci, unsigned bufsize,/* Write this buffer to disk, then read it back to the DMA buffer. */ ahci_guest_io (ahci, port, write_cmd, ptr, bufsize, sector); -qtest_memset (ahci->parent->qts, ptr,0x00 , bufsize); +qmemset (ahci->parent->qts, ptr,0x00 , bufsize);ahci_guest_io (ahci, port, read_cmd, ptr, bufsize, sector);/*** Read back the Data ***/
tests/libqos/ahci.c +6 -6
@@ -283,8 +283,8 @@ void ahci_hba_enable(AHCIQState *ahci)/* Allocate Memory for the Command List Buffer & FIS Buffer */ /* PxCLB space ... 0x20 per command, as in 4.2.2 p 36 */ ahci->port[i].clb =ahci_alloc (ahci, num_cmd_slots *0x20 ); -qtest_memset (ahci->parent->qts, ahci->port[i].clb,0x00 , - num_cmd_slots *0x20 ); +qmemset (ahci->parent->qts, ahci->port[i].clb,0x00 , + num_cmd_slots *0x20 );g_test_message ("CLB: 0x%08" PRIx64, ahci->port[i].clb);ahci_px_wreg (ahci, i,AHCI_PX_CLB , ahci->port[i].clb); g_assert_cmphex(ahci->port[i].clb, ==,
@@ -292,7 +292,7 @@ void ahci_hba_enable(AHCIQState *ahci)/* PxFB space ... 0x100, as in 4.2.1 p 35 */ ahci->port[i].fb =ahci_alloc (ahci,0x100 ); -qtest_memset (ahci->parent->qts, ahci->port[i].fb,0x00 ,0x100 ); +qmemset (ahci->parent->qts, ahci->port[i].fb,0x00 ,0x100 );g_test_message ("FB: 0x%08" PRIx64, ahci->port[i].fb);ahci_px_wreg (ahci, i,AHCI_PX_FB , ahci->port[i].fb); g_assert_cmphex(ahci->port[i].fb, ==,
@@ -398,7 +398,7 @@ void ahci_port_clear(AHCIQState *ahci, uint8_t port) g_assert_cmphex(ahci_px_rreg(ahci, port, AHCI_PX_IS), ==, 0);/* Wipe the FIS-Receive Buffer */ -qtest_memset (ahci->parent->qts, ahci->port[port].fb,0x00 ,0x100 ); +qmemset (ahci->parent->qts, ahci->port[port].fb,0x00 ,0x100 ); }/**
@@ -637,7 +637,7 @@ void ahci_exec(AHCIQState *ahci, uint8_t port,if (opts->size && !opts->buffer) { opts->buffer =ahci_alloc (ahci, opts->size);g_assert (opts->buffer); -qtest_memset (ahci->parent->qts, opts->buffer,0x00 , opts->size); +qmemset (ahci->parent->qts, opts->buffer,0x00 , opts->size); }/* Command creation */
@@ -755,7 +755,7 @@ void ahci_io(AHCIQState *ahci, uint8_t port, uint8_t ide_cmd,g_assert (props); ptr =ahci_alloc (ahci, bufsize);g_assert (!bufsize || ptr); -qtest_memset (ahci->parent->qts, ptr,0x00 , bufsize); +qmemset (ahci->parent->qts, ptr,0x00 , bufsize);if (bufsize && props->write) {bufwrite (ahci->parent->qts, ptr, buffer, bufsize);
Signature · 1 line
2.13.5
PATCH v7 37/38 libqtest: Separate qmp_discard_response() from command
In reply to Eric BlakeUpcoming patches will be adding new convenience methods for constructing QMP commands. But making every variation of sending support every variation of response handling becomes unwieldy; it's easier to specify that discarding a JSON response is unassociated with sending the command, where qmp_async() already fits the bill for sending a command without tying up a reference to the response.
Doing this renders qtest_qmpv_discard_response() unused.
Bonus: gets rid of a non-literal format string in ide-test, which is a step towards compile-time format string checking without triggering -Wformat-nonliteral.
--- tests/libqtest.h | 20 ++++---------------- tests/libqtest.c | 27 ++++++++------------------- tests/ahci-test.c | 26 +++++++++++++------------- tests/boot-order-test.c | 2 +- tests/drive_del-test.c | 5 +++-- tests/fdc-test.c | 11 ++++++----- tests/ide-test.c | 5 ++--- tests/postcopy-test.c | 3 ++- tests/test-filter-mirror.c | 3 ++- tests/test-filter-redirector.c | 6 ++++-- tests/virtio-blk-test.c | 21 ++++++++++++--------- 11 files changed, 57 insertions(+), 72 deletions(-)
tests/libqtest.h +4 -16
@@ -69,11 +69,10 @@ void qtest_quit(QTestState *s);/** * qtest_qmp_discard_response: * @s: #QTestState instance to operate on. -* @fmt...: QMP message to send to qemu * -* Sends a QMP message to QEMU and consumes the response. +* Read and discard a QMP response, typically after qtest_async_qmp(). */ -void qtest_qmp_discard_response (QTestState *s,const char *fmt, ...); +void qtest_qmp_discard_response (QTestState *s);/** * qtest_qmp:
@@ -94,16 +93,6 @@ QDict *qtest_qmp(QTestState *s, const char *fmt, ...);void qtest_async_qmp (QTestState *s,const char *fmt, ...);/** -* qtest_qmpv_discard_response: -* @s: #QTestState instance to operate on. -* @fmt: QMP message to send to QEMU -* @ap: QMP message arguments -* -* Sends a QMP message to QEMU and consumes the response. -*/ -void qtest_qmpv_discard_response (QTestState *s,const char *fmt,va_list ap); - -/** * qtest_qmpv: * @s: #QTestState instance to operate on. * @fmt: QMP message to send to QEMU
@@ -543,11 +532,10 @@ void qmp_async(const char *fmt, ...);/** * qmp_discard_response: -* @fmt...: QMP message to send to qemu * -* Sends a QMP message to QEMU and consumes the response. +* Read and discard a QMP response, typically after qmp_async(). */ -void qmp_discard_response (const char *fmt, ...); +void qmp_discard_response (void );/** * qmp_receive:
tests/libqtest.c +8 -19
@@ -238,8 +238,9 @@ QTestState *qtest_start(const char *extra_args)QTestState *s =qtest_start_without_qmp_handshake (extra_args);/* Read the QMP greeting and then do the handshake */ -qtest_qmp_discard_response (s,"" ); -qtest_qmp_discard_response (s,"{ 'execute': 'qmp_capabilities' }" ); +qtest_qmp_discard_response (s); +qtest_async_qmp (s,"{ 'execute': 'qmp_capabilities' }" ); +qtest_qmp_discard_response (s);assert (!global_qtest);return s;
@@ -566,20 +567,10 @@ void qtest_async_qmp(QTestState *s, const char *fmt, ...)va_end (ap); } -void qtest_qmpv_discard_response (QTestState *s,const char *fmt,va_list ap) +void qtest_qmp_discard_response (QTestState *s) { -QDict *response =qtest_qmpv (s, fmt, ap); -QDECREF (response); -} +QDict *response =qtest_qmp_receive (s); -void qtest_qmp_discard_response (QTestState *s,const char *fmt, ...) -{ -va_list ap; -QDict *response; - -va_start (ap, fmt); - response =qtest_qmpv (s, fmt, ap); -va_end (ap);QDECREF (response); }
@@ -955,13 +946,11 @@ void qmp_async(const char *fmt, ...)va_end (ap); } -void qmp_discard_response (const char *fmt, ...) +void qmp_discard_response (void ) { -va_list ap; +QDict *response =qmp_receive (); -va_start (ap, fmt); -qtest_qmpv_discard_response (global_qtest, fmt, ap); -va_end (ap); +QDECREF (response); }char *hmp (const char *fmt, ...) {
tests/ahci-test.c +13 -13
@@ -1589,9 +1589,10 @@ static void test_atapi_tray(void) rsp =qtest_qmp_receive (ahci->parent->qts);QDECREF (rsp); -qtest_qmp_discard_response (ahci->parent->qts, -"{'execute': 'x-blockdev-remove-medium', " -"'arguments': {'device': 'drive0'}}" ); +qtest_async_qmp (ahci->parent->qts, +"{'execute': 'x-blockdev-remove-medium', " +"'arguments': {'device': 'drive0'}}" ); +qtest_qmp_discard_response (ahci->parent->qts);/* Test the tray without a medium */ ahci_atapi_load (ahci, port);
@@ -1601,16 +1602,15 @@ static void test_atapi_tray(void)atapi_wait_tray (ahci, true);/* Re-insert media */ -qtest_qmp_discard_response (ahci->parent->qts, -"{'execute': 'blockdev-add', " -"'arguments': {'node-name': 'node0', " -"'driver': 'raw', " -"'file': { 'driver': 'file', " -"'filename': %s }}}" , iso); -qtest_qmp_discard_response (ahci->parent->qts, -"{'execute': 'x-blockdev-insert-medium'," -"'arguments': { 'device': 'drive0', " -"'node-name': 'node0' }}" ); +qtest_async_qmp (ahci->parent->qts, +"{'execute': 'blockdev-add', 'arguments': {" +" 'node-name': 'node0', 'driver': 'raw', " +" 'file': { 'driver': 'file', 'filename': %s }}}" , iso); +qtest_qmp_discard_response (ahci->parent->qts); +qtest_async_qmp (ahci->parent->qts, +"{'execute': 'x-blockdev-insert-medium'," +"'arguments': {'device': 'drive0', 'node-name': 'node0'}}" ); +qtest_qmp_discard_response (ahci->parent->qts);/* Again, the event shows up first */ qtest_async_qmp(ahci->parent->qts, "{'execute': 'blockdev-close-tray', "
tests/boot-order-test.c +1 -1
@@ -36,7 +36,7 @@ static void test_a_boot_order(const char *machine, test_args); actual =read_boot_order (); g_assert_cmphex(actual, ==, expected_boot); -qmp_discard_response ("{ 'execute': 'system_reset' }" ); +qmp_async ("{ 'execute': 'system_reset' }" );/* * system_reset only requests reset. We get a RESET event after * the actual reset completes. Need to wait for that.
tests/drive_del-test.c +3 -2
@@ -34,8 +34,9 @@ static void device_del(void)QDict *response;/* Complication: ignore DEVICE_DELETED event */ -qmp_discard_response ("{'execute': 'device_del'," -" 'arguments': { 'id': 'dev0' } }" ); +qmp_async ("{'execute': 'device_del'," +" 'arguments': { 'id': 'dev0' } }" ); +qmp_discard_response (); response =qmp_receive ();g_assert (response);g_assert (qdict_haskey (response,"return" ));
tests/fdc-test.c +6 -5
@@ -298,9 +298,10 @@ static void test_media_insert(void)/* Insert media in drive. DSKCHK should not be reset until a step pulse * is sent. */ -qmp_discard_response ("{'execute':'blockdev-change-medium', 'arguments':{" -" 'id':'floppy0', 'filename': %s, 'format': 'raw' }}" , - test_image); +qmp_async ("{'execute':'blockdev-change-medium', 'arguments':{" +" 'id':'floppy0', 'filename': %s, 'format': 'raw' }}" , + test_image); +qmp_discard_response (); dir =inb (global_qtest,FLOPPY_BASE + reg_dir);assert_bit_set (dir,DSKCHG );
@@ -329,8 +330,8 @@ static void test_media_change(void)/* Eject the floppy and check that DSKCHG is set. Reading it out doesn't * reset the bit. */ -qmp_discard_response ("{'execute':'eject', 'arguments':{" -" 'id':'floppy0' }}" ); +qmp_async ("{'execute':'eject', 'arguments':{ 'id':'floppy0' }}" ); +qmp_discard_response (); dir =inb (global_qtest,FLOPPY_BASE + reg_dir);assert_bit_set (dir,DSKCHG );
tests/ide-test.c +2 -3
@@ -621,7 +621,6 @@ static void test_retry_flush(const char *machine)QPCIDevice *dev;QPCIBar bmdma_bar, ide_bar;uint8_t data; -const char *s;prepare_blkdebug_script (debug_path,"flush_to_disk" );
@@ -649,8 +648,8 @@ static void test_retry_flush(const char *machine)qmp_eventwait ("STOP" );/* Complete the command */ - s ="{'execute':'cont' }" ; -qmp_discard_response (s); +qmp_async ("{'execute':'cont' }" ); +qmp_discard_response ();/* Check registers */ data =qpci_io_readb (dev, ide_bar, reg_device);
tests/postcopy-test.c +2 -1
@@ -478,7 +478,8 @@ static void test_migrate(void)usleep (10 *1000 ); }while (dest_byte_a == dest_byte_b); -qtest_qmp_discard_response (to,"{ 'execute' : 'stop'}" ); +qtest_async_qmp (to,"{ 'execute' : 'stop'}" ); +qtest_qmp_discard_response (to);/* With it stopped, check nothing changes */ memread (to, start_address, &dest_byte_c,1 );sleep (1 );
tests/test-filter-mirror.c +2 -1
@@ -57,7 +57,8 @@ static void test_mirror(void) };/* send a qmp command to guarantee that 'connected' is setting to true. */ -qmp_discard_response ("{ 'execute' : 'query-status'}" ); +qmp_async ("{ 'execute' : 'query-status'}" ); +qmp_discard_response (); ret =iov_send (send_sock[0 ], iov,2 ,0 ,sizeof (size) +sizeof (send_buf)); g_assert_cmpint(ret, ==, sizeof(send_buf) + sizeof(size));close (send_sock[0 ]);
tests/test-filter-redirector.c +4 -2
@@ -104,7 +104,8 @@ static void test_redirector_tx(void) g_assert_cmpint(recv_sock, !=, -1);/* send a qmp command to guarantee that 'connected' is setting to true. */ -qmp_discard_response ("{ 'execute' : 'query-status'}" ); +qmp_async ("{ 'execute' : 'query-status'}" ); +qmp_discard_response ();struct iovec iov[] = { {
@@ -182,7 +183,8 @@ static void test_redirector_rx(void) send_sock =unix_connect (sock_path1,NULL ); g_assert_cmpint(send_sock, !=, -1);/* send a qmp command to guarantee that 'connected' is setting to true. */ -qmp_discard_response ("{ 'execute' : 'query-status'}" ); +qmp_async ("{ 'execute' : 'query-status'}" ); +qmp_discard_response (); ret =iov_send (send_sock, iov,2 ,0 ,sizeof (size) +sizeof (send_buf)); g_assert_cmpint(ret, ==, sizeof(send_buf) + sizeof(size));
tests/virtio-blk-test.c +12 -9
@@ -410,9 +410,10 @@ static void pci_config(void)qvirtio_set_driver_ok (&dev->vdev); -qmp_discard_response ("{ 'execute': 'block_resize', " -" 'arguments': { 'device': 'drive0', " -" 'size': %d } }" , n_size); +qmp_async ("{ 'execute': 'block_resize', " +" 'arguments': { 'device': 'drive0', " +" 'size': %d } }" , n_size); +qmp_discard_response ();qvirtio_wait_config_isr (&dev->vdev,QVIRTIO_BLK_TIMEOUT_US ); capacity =qvirtio_config_readq (&dev->vdev,0 );
@@ -460,9 +461,10 @@ static void pci_msix(void)qvirtio_set_driver_ok (&dev->vdev); -qmp_discard_response ("{ 'execute': 'block_resize', " -" 'arguments': { 'device': 'drive0', " -" 'size': %d } }" , n_size); +qmp_async ("{ 'execute': 'block_resize', " +" 'arguments': { 'device': 'drive0', " +" 'size': %d } }" , n_size); +qmp_discard_response ();qvirtio_wait_config_isr (&dev->vdev,QVIRTIO_BLK_TIMEOUT_US );
@@ -702,9 +704,10 @@ static void mmio_basic(void)test_basic (&dev->vdev, alloc, vq); -qmp_discard_response ("{ 'execute': 'block_resize', " -" 'arguments': { 'device': 'drive0', " -" 'size': %d } }" , n_size); +qmp_async ("{ 'execute': 'block_resize', " +" 'arguments': { 'device': 'drive0', " +" 'size': %d } }" , n_size); +qmp_discard_response ();qvirtio_wait_queue_isr (&dev->vdev, vq,QVIRTIO_BLK_TIMEOUT_US );
Signature · 1 line
2.13.5