[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 17/36] qtest: Avoid dynamic JSON in ahci-test
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH 17/36] qtest: Avoid dynamic JSON in ahci-test |
Date: |
Wed, 30 Nov 2016 13:44:35 -0600 |
As argued elsewhere, it's less code to maintain if we convert
from a dynamic string passed to qobject_from_jsonv() to instead
use a hand-built QDict.
Rather than build up a QDict by manual qdict_put*() calls, we
can let QAPI do the work for us. The result is more lines of
code to initialize the QAPI struct, but the result will force us
to track any changes to the qapi (whereas the dynamic JSON string
would not detect qapi changes until runtime).
Signed-off-by: Eric Blake <address@hidden>
---
tests/ahci-test.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/tests/ahci-test.c b/tests/ahci-test.c
index ef17629..dfa9c52 100644
--- a/tests/ahci-test.c
+++ b/tests/ahci-test.c
@@ -32,6 +32,8 @@
#include "qemu-common.h"
#include "qemu/host-utils.h"
+#include "qapi/qmp/qjson.h"
+#include "qapi/qobject-output-visitor.h"
#include "hw/pci/pci_ids.h"
#include "hw/pci/pci_regs.h"
@@ -1576,6 +1578,7 @@ static void test_atapi_tray(void)
uint8_t port, sense, asc;
uint64_t iso_size = ATAPI_SECTOR_SIZE;
QDict *rsp;
+ QObject *args;
fd = prepare_iso(iso_size, &tx, &iso);
ahci = ahci_boot_and_enable("-drive if=none,id=drive0,file=%s,format=raw "
@@ -1607,11 +1610,24 @@ static void test_atapi_tray(void)
atapi_wait_tray(true);
/* Re-insert media */
- qmp_discard_response("{'execute': 'blockdev-add', "
- "'arguments': {'node-name': 'node0', "
- "'driver': 'raw', "
- "'file': { 'driver': 'file', "
- "'filename': %s }}}", iso);
+ {
+ BlockdevRef ref = {
+ .type = QTYPE_QDICT,
+ .u.definition = {
+ .driver = BLOCKDEV_DRIVER_FILE,
+ .u.file.filename = iso,
+ },
+ };
+ BlockdevOptions opts = {
+ .has_node_name = true,
+ .node_name = (char *)"node0",
+ .driver = BLOCKDEV_DRIVER_RAW,
+ .u.raw.file = &ref,
+ };
+ args = QAPI_TO_QOBJECT(BlockdevOptions, &opts, &error_abort);
+ }
+
+ qmp_cmd_discard_response("blockdev-add", qobject_to_qdict(args));
qmp_discard_response("{'execute': 'x-blockdev-insert-medium',"
"'arguments': { 'device': 'drive0', "
"'node-name': 'node0' }}");
--
2.7.4
- [Qemu-devel] [PATCH 24/36] qtest: Drop unused qmp_fdv(), (continued)
- [Qemu-devel] [PATCH 24/36] qtest: Drop unused qmp_fdv(), Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 27/36] qtest: Avoid dynamic JSON in qmp_cmd(), Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 18/36] qtest: Avoid dynamic JSON in fdc-test, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 33/36] qtest: Avoid dynamic JSON in test-x86-cpuid-compat, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 35/36] qapi: Rip out dynamic JSON parser escape sequence support, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 31/36] qtest: Document calling conventions, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 15/36] blockdev: Use simpler QAPI_TO_QOBJECT(), Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 34/36] qapi: Rip out dynamic JSON parser frontend, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 32/36] qtest: Avoid dynamic JSON in qom-test, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 17/36] qtest: Avoid dynamic JSON in ahci-test,
Eric Blake <=
- [Qemu-devel] [PATCH 36/36] qapi: Rip out dynamic JSON parser backend, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 02/36] qdict: Add convenience helpers for wrapped puts, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 23/36] qtest: Avoid dynamic JSON in virtio-blk-test, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 30/36] qtest: Avoid dynamic JSON in qmp_fd_sendv(), Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 29/36] qapi: Add qstring_append_printf(), Eric Blake, 2016/11/30
- Re: [Qemu-devel] [PATCH 00/36] Rip out dynamic JSON parsing, Eric Blake, 2016/11/30