qemu-e2k/tests
Eric Blake 3b098d5697 qapi: Add new visit_complete() function
Making each output visitor provide its own output collection
function was the only remaining reason for exposing visitor
sub-types to the rest of the code base.  Add a polymorphic
visit_complete() function which is a no-op for input visitors,
and which populates an opaque pointer for output visitors.  For
maximum type-safety, also add a parameter to the output visitor
constructors with a type-correct version of the output pointer,
and assert that the two uses match.

This approach was considered superior to either passing the
output parameter only during construction (action at a distance
during visit_free() feels awkward) or only during visit_complete()
(defeating type safety makes it easier to use incorrectly).

Most callers were function-local, and therefore a mechanical
conversion; the testsuite was a bit trickier, but the previous
cleanup patch minimized the churn here.

The visit_complete() function may be called at most once; doing
so lets us use transfer semantics rather than duplication or
ref-count semantics to get the just-built output back to the
caller, even though it means our behavior is not idempotent.

Generated code is simplified as follows for events:

|@@ -26,7 +26,7 @@ void qapi_event_send_acpi_device_ost(ACP
|     QDict *qmp;
|     Error *err = NULL;
|     QMPEventFuncEmit emit;
|-    QmpOutputVisitor *qov;
|+    QObject *obj;
|     Visitor *v;
|     q_obj_ACPI_DEVICE_OST_arg param = {
|         info
|@@ -39,8 +39,7 @@ void qapi_event_send_acpi_device_ost(ACP
|
|     qmp = qmp_event_build_dict("ACPI_DEVICE_OST");
|
|-    qov = qmp_output_visitor_new();
|-    v = qmp_output_get_visitor(qov);
|+    v = qmp_output_visitor_new(&obj);
|
|     visit_start_struct(v, "ACPI_DEVICE_OST", NULL, 0, &err);
|     if (err) {
|@@ -55,7 +54,8 @@ void qapi_event_send_acpi_device_ost(ACP
|         goto out;
|     }
|
|-    qdict_put_obj(qmp, "data", qmp_output_get_qobject(qov));
|+    visit_complete(v, &obj);
|+    qdict_put_obj(qmp, "data", obj);
|     emit(QAPI_EVENT_ACPI_DEVICE_OST, qmp, &err);

and for commands:

| {
|     Error *err = NULL;
|-    QmpOutputVisitor *qov = qmp_output_visitor_new();
|     Visitor *v;
|
|-    v = qmp_output_get_visitor(qov);
|+    v = qmp_output_visitor_new(ret_out);
|     visit_type_AddfdInfo(v, "unused", &ret_in, &err);
|-    if (err) {
|-        goto out;
|+    if (!err) {
|+        visit_complete(v, ret_out);
|     }
|-    *ret_out = qmp_output_get_qobject(qov);
|-
|-out:
|     error_propagate(errp, err);

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-13-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-07-06 10:52:04 +02:00
..
acpi-test-data tests: add APIC.cphp and DSDT.cphp blobs 2016-07-04 19:43:33 +03:00
docker tests/docker: build all targets in test-clang 2016-06-08 15:19:30 +08:00
guest-debug tests/guest-debug: introduce basic gdbstub tests 2015-12-17 13:37:15 +00:00
image-fuzzer tests: Use Python 2.6 "except E as ..." syntax 2016-02-08 17:29:54 +01:00
libqos libqos: add qvirtqueue_cleanup() 2016-06-20 11:44:12 +01:00
multiboot tests/multiboot: Add test for modules 2015-01-26 12:22:44 +01:00
qapi-schema qapi: Allow anonymous base for flat union 2016-03-18 10:29:26 +01:00
qemu-iotests crypto: fix handling of iv generator hash defaults 2016-07-04 10:46:59 +01:00
rocker rocker: tests: don't need to specify master/self when setting vlans 2015-07-07 13:13:22 +01:00
tcg Fix some typos found by codespell 2016-05-18 15:04:27 +03:00
vmstate-static-checker-data tests: vmstate static checker: add size mismatch inside substructure 2014-06-23 19:14:52 +02:00
.gitignore qht: add test-qht-par to invoke qht-bench from 'check' target 2016-06-11 17:11:16 -07:00
Makefile.include crypto: switch hash code to use nettle/gcrypt directly 2016-07-04 10:47:09 +01:00
ac97-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
ahci-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
bios-tables-test.c tests: acpi: add CPU hotplug testcase 2016-07-04 16:49:34 +03:00
boot-order-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
boot-sector.c all: Clean up includes 2016-02-23 12:43:05 +00:00
boot-sector.h tests: add pxe e1000 and virtio-pci tests 2016-02-16 12:05:18 +02:00
check-block.sh qemu-iotests: make check-block.sh work on out-of-tree builds 2016-01-07 21:30:16 +01:00
check-qdict.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
check-qfloat.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
check-qint.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
check-qjson.c qapi: Improve use of qmp/types.h 2016-07-06 10:52:03 +02:00
check-qlist.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
check-qnull.c qapi: Add new visit_complete() function 2016-07-06 10:52:04 +02:00
check-qom-interface.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
check-qom-proplist.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
check-qstring.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
crypto-tls-x509-helpers.c tests: Clean up includes 2016-02-16 14:29:27 +00:00
crypto-tls-x509-helpers.h crypto: add sanity checking of TLS x509 credentials 2015-09-15 15:05:09 +01:00
device-introspect-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
display-vga-test.c coccinelle: Remove unnecessary variables for function return value 2016-06-20 16:38:13 +02:00
drive_del-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
ds1338-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
e1000-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
e1000e-test.c clean-includes: run it once more 2016-06-16 18:39:03 +02:00
eepro100-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
endianness-test.c coccinelle: Remove unnecessary variables for function return value 2016-06-20 16:38:13 +02:00
es1370-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
fdc-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
fw_cfg-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
hd-geo-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
i440fx-test.c coccinelle: Remove unnecessary variables for function return value 2016-06-20 16:38:13 +02:00
i82801b11-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
ide-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
intel-hda-test.c coccinelle: Remove unnecessary variables for function return value 2016-06-20 16:38:13 +02:00
io-channel-helpers.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
io-channel-helpers.h io: add QIOChannelSocket class 2015-12-18 12:18:31 +00:00
ioh3420-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
ipmi-bt-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
ipmi-kcs-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
ipoctal232-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
ivshmem-test.c os-posix: include sys/mman.h 2016-06-16 18:39:03 +02:00
libqtest.c tests: fix libqtest socket timeouts 2016-06-16 09:50:07 +05:30
libqtest.h all: Clean up includes 2016-02-23 12:43:05 +00:00
m48t59-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
ne2000-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
nvme-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
pc-cpu-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
pcnet-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
pkix_asn1_tab.c tests: Clean up includes 2016-02-16 14:29:27 +00:00
postcopy-test.c clean-includes: run it once more 2016-06-16 18:39:03 +02:00
prom-env-test.c ppc / sparc: Add a tester for checking whether OpenBIOS runs successfully 2016-06-17 15:57:59 +10:00
pvpanic-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
pxe-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
q35-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
qemu-iotests-quick.sh qemu-iotests: Speed up make check-block 2015-01-13 11:47:55 +00:00
qht-bench.c clean-includes: run it once more 2016-06-16 18:39:03 +02:00
qom-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
rcutorture.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
rtc-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
rtl8139-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
spapr-phb-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
tco-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-aio.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-base64.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-bitops.c bitops.h: Implement half-shuffle and half-unshuffle ops 2016-06-17 15:23:51 +01:00
test-blockjob-txn.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-coroutine.c trivial patches for 2016-06-07 2016-06-07 16:34:45 +01:00
test-crypto-afsplit.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
test-crypto-block.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
test-crypto-cipher.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-crypto-hash.c crypto: implement sha224, sha384, sha512 and ripemd160 hashes 2016-07-04 15:52:36 +01:00
test-crypto-ivgen.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
test-crypto-pbkdf.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
test-crypto-secret.c crypto: remove temp files on completion of secrets test 2016-06-13 12:41:17 +01:00
test-crypto-tlscredsx509.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
test-crypto-tlssession.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
test-crypto-xts.c crypto: rename OUT to out in xts test to avoid clash on MinGW 2016-07-04 10:46:59 +01:00
test-cutils.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-filter-mirror.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-filter-redirector.c coccinelle: Remove unnecessary variables for function return value 2016-06-20 16:38:13 +02:00
test-hbitmap.c hbitmap: Use DIV_ROUND_UP 2016-06-07 18:19:25 +03:00
test-int128.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-io-channel-buffer.c tests: Clean up includes 2016-02-16 14:29:27 +00:00
test-io-channel-command.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
test-io-channel-file.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
test-io-channel-socket.c socket: unlink unix socket on remove 2016-06-29 16:49:41 +02:00
test-io-channel-tls.c tests: Clean up includes 2016-02-16 14:29:27 +00:00
test-io-task.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-iov.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-logging.c log: Permit -dfilter 0..0xffffffffffffffff 2016-07-04 16:49:33 +03:00
test-mul64.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-netfilter.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-opts-visitor.c opts-visitor: Favor new visit_free() function 2016-07-06 10:52:04 +02:00
test-qdev-global-props.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-qdist.c clean-includes: run it once more 2016-06-16 18:39:03 +02:00
test-qemu-opts.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-qga.c tests: start a /qga/guest-exec test 2016-06-07 11:25:06 -05:00
test-qht-par.c clean-includes: run it once more 2016-06-16 18:39:03 +02:00
test-qht.c clean-includes: run it once more 2016-06-16 18:39:03 +02:00
test-qmp-commands.c qmp-input-visitor: Favor new visit_free() function 2016-07-06 10:52:04 +02:00
test-qmp-event.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-qmp-input-strict.c qmp-input-visitor: Favor new visit_free() function 2016-07-06 10:52:04 +02:00
test-qmp-input-visitor.c qmp-input-visitor: Favor new visit_free() function 2016-07-06 10:52:04 +02:00
test-qmp-output-visitor.c qapi: Add new visit_complete() function 2016-07-06 10:52:04 +02:00
test-rcu-list.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-rfifolock.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-string-input-visitor.c string-input-visitor: Favor new visit_free() function 2016-07-06 10:52:04 +02:00
test-string-output-visitor.c qapi: Add new visit_complete() function 2016-07-06 10:52:04 +02:00
test-thread-pool.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-throttle.c trivial patches for 2016-06-07 2016-06-07 16:34:45 +01:00
test-timed-average.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-visitor-serialization.c qapi: Add new visit_complete() function 2016-07-06 10:52:04 +02:00
test-vmstate.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-write-threshold.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-x86-cpuid.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
test-xbzrle.c util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00
tmp105-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
tpci200-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
usb-hcd-ehci-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
usb-hcd-ohci-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
usb-hcd-uhci-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
usb-hcd-xhci-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
vhost-user-bridge.c pc, pci, virtio: new features, cleanups, fixes 2016-06-17 11:25:46 +01:00
vhost-user-test.c vhost-user-test: fix g_cond_wait_until compat implementation 2016-06-29 16:49:40 +02:00
virtio-9p-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
virtio-balloon-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
virtio-blk-test.c Error reporting patches for 2016-06-20 2016-06-20 16:19:18 +01:00
virtio-console-test.c coccinelle: Remove unnecessary variables for function return value 2016-06-20 16:38:13 +02:00
virtio-net-test.c Error reporting patches for 2016-06-20 2016-06-20 16:19:18 +01:00
virtio-rng-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
virtio-scsi-test.c Error reporting patches for 2016-06-20 2016-06-20 16:19:18 +01:00
virtio-serial-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
vmxnet3-test.c tests: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
wdt_ib700-test.c coccinelle: Remove unnecessary variables for function return value 2016-06-20 16:38:13 +02:00