qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 3/3] tests: more strict command batching test


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH 3/3] tests: more strict command batching test
Date: Wed, 21 Mar 2018 07:55:19 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

On 03/21/2018 01:55 AM, Peter Xu wrote:
Add "id" fields to the commands, and check that the command returns are
in order.

Signed-off-by: Peter Xu <address@hidden>
---
  tests/qmp-test.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)


+++ b/tests/qmp-test.c
@@ -83,6 +83,7 @@ static void test_qmp_protocol(void)
      const QListEntry *entry;
      QString *qstr;
      int i;
+    char buf[128];

Eww, we shouldn't need this.

qts = qtest_init_without_qmp_handshake(common_args); @@ -150,7 +151,10 @@ static void test_qmp_protocol(void)
       * best-effort test.
       */
      for (i = 0; i < 16; i++) {
-        qtest_async_qmp(qts, "{ 'execute': 'query-version' }");
+        snprintf(buf, sizeof(buf) - 1, "{ 'execute': 'query-version', "
+                 "'id': %d }", i);
+        buf[sizeof(buf) - 1] = '\0';
+        qtest_async_qmp(qts, buf);

snprintf() of JSON strings is prone to failures especially when the JSON string is reinterpreted as a printf argument in qtest_async_qmp. Better is to let qtest_async_qmp() directly do the formatting, as in:

qtest_async_qmp(qts, "{ 'execute':'query-version', 'id':%d}", i);

And then I was right - you don't need buf.

Otherwise the addition is good.

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



reply via email to

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