qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 18/36] qtest: Avoid dynamic JSON in fdc-test


From: Eric Blake
Subject: [Qemu-devel] [PATCH 18/36] qtest: Avoid dynamic JSON in fdc-test
Date: Wed, 30 Nov 2016 13:44:36 -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/fdc-test.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/tests/fdc-test.c b/tests/fdc-test.c
index f5ff68d..ac75e87 100644
--- a/tests/fdc-test.c
+++ b/tests/fdc-test.c
@@ -27,6 +27,8 @@

 #include "libqtest.h"
 #include "qemu-common.h"
+#include "qapi/qmp/qjson.h"
+#include "qapi/qobject-output-visitor.h"

 #define TEST_IMAGE_SIZE 1440 * 1024

@@ -295,13 +297,19 @@ static void test_read_without_media(void)
 static void test_media_insert(void)
 {
     uint8_t dir;
+    QObject *args;
+    BlockdevChangeMedium bcm = {
+        .has_device = true,
+        .device = (char *)"floppy0",
+        .filename = test_image,
+        .has_format = true,
+        .format = (char *)"raw",
+    };

     /* Insert media in drive. DSKCHK should not be reset until a step pulse
      * is sent. */
-    qmp_discard_response("{'execute':'blockdev-change-medium', 'arguments':{"
-                         " 'device':'floppy0', 'filename': %s, "
-                         "'format': 'raw' }}",
-                         test_image);
+    args = QAPI_TO_QOBJECT(BlockdevChangeMedium, &bcm, &error_abort);
+    qmp_cmd_discard_response("blockdev-change-medium", qobject_to_qdict(args));

     dir = inb(FLOPPY_BASE + reg_dir);
     assert_bit_set(dir, DSKCHG);
-- 
2.7.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]