Skip to contentSkip to conversation

test virtio-blk hotplug

PATCH In review Amos Kong 1 participant 7 messages Jun 25, 2014 – Aug 23, 2014

lore
Share & tools
lore

Amos Kong

author
#0 lore raw

v6 cover test virtio-blk hotplug

It's worth to add a hotplug test to qtest, but without cooperation of guest OS, new devices can't be initialized by guest, and hot-unplug doesn't work.

However, the new test can cover some part of code of hotplug/unplug.

I will write another subtest to test hotplug with pci support.

V2: move qmp_exec_hmp_cmd() to libqtest.c
excape hmp cmd (stefanha)
use qmp_exec_hmp_cmd() in blockdev-test
V3: use vp_list to format string, free escaped string
V4: free escaped string by g_free()
V5: escape cmd string in QMP command (so this patchset depends on
http://article.gmane.org/gmane.comp.emulators.qemu/279835)
directly use QMP cmd to add/del device and blockdev cleanup as suggested by Andreas
V6: hot-unplug devices of one slot once
escaping string fix in 1st patch depends on
(https://lists.nongnu.org/archive/html/qemu-devel/2014-06/msg03024.html)

Amos Kong (4):
qtest: introduce qmp_exec_hmp_cmd()
qtest: use qmp_exec_hmp_cmd() in blockdev-test
virtio-blk-test: change pci_nop() to virtblk_init()
virtio-blk-test: add hotplug subtest

 tests/blockdev-test.c   | 23 ++------------
 tests/libqtest.c        | 23 ++++++++++++++
 tests/libqtest.h        |  9 ++++++
 tests/virtio-blk-test.c | 81 ++++++++++++++++++++++++++++++++++++++++++++-----
 4 files changed, 108 insertions(+), 28 deletions(-)
Signature · 1 line
1.9.3
author
#1 lore raw

PATCH v6 1/4 qtest: introduce qmp_exec_hmp_cmd()

This patch wraps a helper function to execute human command by one QMP command (human-monitor-command). It also checks the return string.

---
 tests/libqtest.c | 23 +++++++++++++++++++++++
 tests/libqtest.h |  9 +++++++++
 2 files changed, 32 insertions(+)
tests/libqtest.c +23 -0
index 98e8f4b..80e0024 100644
@@ -673,3 +673,26 @@ void qmp_discard_response(const char *fmt, ...)
     qtest_qmpv_discard_response(global_qtest, fmt, ap);
     va_end(ap);
 }
+
+void qmp_exec_hmp_cmd(const char *expected_ret, const char *fmt, ...)
+{
+    va_list ap;
+    char cmd[1024];
+    QDict *response;
+    const char *response_return;
+
+    va_start(ap, fmt);
+    vsprintf(cmd, fmt, ap);
+    va_end(ap);
+
+    response = qmp("{'execute': 'human-monitor-command',"
+                   " 'arguments': {"
+                   "   'command-line': %s"
+                   "}}", cmd);
+
+    g_assert(response);
+    response_return = qdict_get_try_str(response, "return");
+    g_assert(response_return);
+    g_assert_cmpstr(response_return, ==, expected_ret);
+    QDECREF(response);
+}
tests/libqtest.h +9 -0
index 8f323c7..d2959d3 100644
@@ -375,6 +375,15 @@ QDict *qmp(const char *fmt, ...);
 void qmp_discard_response(const char *fmt, ...);
 
 /**
+ * qmp_exec_hmp_cmd:
+ * @expected_ret: expected return string
+ * @fmt...: HMP command to execute
+ *
+ * Executes HMP command by 'human-monitor-command'.
+ */
+void qmp_exec_hmp_cmd(const char *expected_ret, const char *fmt, ...);
+
+/**
  * qmp_receive:
  *
  * Reads a QMP message from QEMU and returns the response.
Signature · 1 line
1.9.3
author
#2 lore raw

PATCH v6 2/4 qtest: use qmp_exec_hmp_cmd() in blockdev-test

In reply to Amos Kong
---
 tests/blockdev-test.c | 23 ++---------------------
 1 file changed, 2 insertions(+), 21 deletions(-)
tests/blockdev-test.c +2 -21
index c940e00..c9127c0 100644
@@ -16,35 +16,16 @@
 
 static void test_drive_add_empty(void)
 {
-    QDict *response;
-    const char *response_return;
-
     /* Start with an empty drive */
     qtest_start("-drive if=none,id=drive0");
 
     /* Delete the drive */
-    response = qmp("{\"execute\": \"human-monitor-command\","
-                   " \"arguments\": {"
-                   "   \"command-line\": \"drive_del drive0\""
-                   "}}");
-    g_assert(response);
-    response_return = qdict_get_try_str(response, "return");
-    g_assert(response_return);
-    g_assert(strcmp(response_return, "") == 0);
-    QDECREF(response);
+    qmp_exec_hmp_cmd("", "drive_del drive0");
 
     /* Ensure re-adding the drive works - there should be no duplicate ID error
      * because the old drive must be gone.
      */
-    response = qmp("{\"execute\": \"human-monitor-command\","
-                   " \"arguments\": {"
-                   "   \"command-line\": \"drive_add 0 if=none,id=drive0\""
-                   "}}");
-    g_assert(response);
-    response_return = qdict_get_try_str(response, "return");
-    g_assert(response_return);
-    g_assert(strcmp(response_return, "OK\r\n") == 0);
-    QDECREF(response);
+    qmp_exec_hmp_cmd("OK\r\n", "drive_add 0 if=none,id=drive0");
 
     qtest_end();
 }
Signature · 1 line
1.9.3
author
#3 lore raw

PATCH v6 3/4 virtio-blk-test: change pci_nop() to virtblk_init()

In reply to Amos Kong

I want to add a new subtest in virtio-blk-test, it will start guest without network. The original pci_init() did nothing, but it's good to reserve a very simple initialization testing.

---
 tests/virtio-blk-test.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
tests/virtio-blk-test.c +6 -7
index d53f875..0fdec01 100644
@@ -12,9 +12,12 @@
 #include "libqtest.h"
 #include "qemu/osdep.h"
 
-/* Tests only initialization so far. TODO: Replace with functional tests */
-static void pci_nop(void)
+/* Tests only initialization */
+static void virtblk_init(void)
 {
+    qtest_start("-drive id=drv0,if=none,file=/dev/null "
+                "-device virtio-blk-pci,drive=drv0");
+    qtest_end();
 }
 
 int main(int argc, char **argv)
@@ -22,13 +25,9 @@ int main(int argc, char **argv)
     int ret;
 
     g_test_init(&argc, &argv, NULL);
-    qtest_add_func("/virtio/blk/pci/nop", pci_nop);
+    qtest_add_func("/virtio/blk/pci/init", virtblk_init);
 
-    qtest_start("-drive id=drv0,if=none,file=/dev/null "
-                "-device virtio-blk-pci,drive=drv0");
     ret = g_test_run();
 
-    qtest_end();
-
     return ret;
 }
Signature · 1 line
1.9.3
author
#4 lore raw

PATCH v6 4/4 virtio-blk-test: add hotplug subtest

In reply to Amos Kong

This patch adds a new subtest, it hotplugs 29 * 8 = 232 virtio-blk devices to guest, and try to hot-unplug them.

Note: the hot-unplug can't work without cooperation of guest OS.

---
 tests/virtio-blk-test.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
tests/virtio-blk-test.c +68 -0
index 0fdec01..7cb55cd 100644
@@ -7,11 +7,78 @@
  * See the COPYING file in the top-level directory.
  */
 
+#include <stdio.h>
 #include <glib.h>
 #include <string.h>
 #include "libqtest.h"
 #include "qemu/osdep.h"
 
+
+/* Start guest without net/block device, slots 3 to 0x1f are free */
+#define MIN_PCI_SLOT 3
+#define MAX_PCI_SLOT 0x1f
+#define MAX_PCI_FUNC 7
+
+static void test_blk_hotplug(void)
+{
+    QDict *response;
+    int i, j;
+    char drive_id[10];
+    char device_id[10];
+    char addr[10];
+
+    qtest_start("-net none");
+
+    for (i = MIN_PCI_SLOT; i <= MAX_PCI_SLOT; i++) {
+        for (j = MAX_PCI_FUNC; j >= 0; j--) {
+            sprintf(drive_id, "drv-%x.%x", i, j);
+            response = qmp("{ 'execute': 'blockdev-add',"
+                           " 'arguments': {"
+                           "   'options': {"
+                           "     'driver': 'file',"
+                           "     'filename': '/dev/null',"
+                           "     'id': %s"
+                           "} } }", drive_id);
+            g_assert(response);
+            g_assert(!qdict_haskey(response, "error"));
+            QDECREF(response);
+
+            sprintf(device_id, "dev-%x.%x", i, j);
+            sprintf(addr, "0x%x.%x", i, j);
+            response = qmp("{'execute': 'device_add',"
+                           " 'arguments': {"
+                           "   'driver': 'virtio-blk-pci',"
+                           "   'drive': %s,"
+                           "   'id': %s,"
+                           "   'addr': %s,"
+                           "   'multifunction': 'on'"
+                           "} }", drive_id, device_id, addr);
+            g_assert(response);
+            g_assert(!qdict_haskey(response, "error"));
+            QDECREF(response);
+        }
+    }
+
+    /* hot-unplug doesn't work without cooperation of guest OS */
+    for (i = MIN_PCI_SLOT; i <= MAX_PCI_SLOT; i++) {
+        for (j = MAX_PCI_FUNC; j >= 0; j--) {
+            qmp_exec_hmp_cmd("", "drive_del drv-%x.%x", i, j);
+            if (j == 0) {
+                sprintf(device_id, "dev-%x.%x", i, 0);
+                response = qmp("{'execute': 'device_del',"
+                               " 'arguments': {"
+                               "   'id': %s"
+                               "} }", device_id);
+                g_assert(response);
+                g_assert(!qdict_haskey(response, "error"));
+                QDECREF(response);
+            }
+        }
+    }
+
+    qtest_end();
+}
+
 /* Tests only initialization */
 static void virtblk_init(void)
 {
@@ -26,6 +93,7 @@ int main(int argc, char **argv)
 
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/virtio/blk/pci/init", virtblk_init);
+    qtest_add_func("/virtio/blk/pci/hotplug", test_blk_hotplug);
 
     ret = g_test_run();
 
Signature · 1 line
1.9.3
author
#5 lore raw
In reply to Amos Kong
Quoted 9 lines · Amos Kong

It's worth to add a hotplug test to qtest, but without cooperation of guest OS, new devices can't be initialized by guest, and hot-unplug doesn't work.

However, the new test can cover some part of code of hotplug/unplug.

I will write another subtest to test hotplug with pci support.

Quoted 12 lines

V2: move qmp_exec_hmp_cmd() to libqtest.c
excape hmp cmd (stefanha)
use qmp_exec_hmp_cmd() in blockdev-test
V3: use vp_list to format string, free escaped string
V4: free escaped string by g_free()
V5: escape cmd string in QMP command (so this patchset depends on
http://article.gmane.org/gmane.comp.emulators.qemu/279835)
directly use QMP cmd to add/del device and blockdev cleanup as suggested by Andreas
V6: hot-unplug devices of one slot once
escaping string fix in 1st patch depends on
(https://lists.nongnu.org/archive/html/qemu-devel/2014-06/msg03024.html)

Kevin, Stefan, Andreas

Can you help to review & apply this set?

Thanks. Amos

Quoted 14 lines

Amos Kong (4):
qtest: introduce qmp_exec_hmp_cmd()
qtest: use qmp_exec_hmp_cmd() in blockdev-test
virtio-blk-test: change pci_nop() to virtblk_init()
virtio-blk-test: add hotplug subtest

 tests/blockdev-test.c   | 23 ++------------
 tests/libqtest.c        | 23 ++++++++++++++
 tests/libqtest.h        |  9 ++++++
 tests/virtio-blk-test.c | 81 ++++++++++++++++++++++++++++++++++++++++++++-----
 4 files changed, 108 insertions(+), 28 deletions(-)
Signature · 1 line
1.9.3
author
#6 lore raw
Quoted 23 lines · Amos Kong
Quoted 9 lines · Amos Kong

It's worth to add a hotplug test to qtest, but without cooperation of guest OS, new devices can't be initialized by guest, and hot-unplug doesn't work.

However, the new test can cover some part of code of hotplug/unplug.

I will write another subtest to test hotplug with pci support.

Quoted 12 lines

V2: move qmp_exec_hmp_cmd() to libqtest.c
excape hmp cmd (stefanha)
use qmp_exec_hmp_cmd() in blockdev-test
V3: use vp_list to format string, free escaped string
V4: free escaped string by g_free()
V5: escape cmd string in QMP command (so this patchset depends on
http://article.gmane.org/gmane.comp.emulators.qemu/279835)
directly use QMP cmd to add/del device and blockdev cleanup as suggested by Andreas
V6: hot-unplug devices of one slot once
escaping string fix in 1st patch depends on
(https://lists.nongnu.org/archive/html/qemu-devel/2014-06/msg03024.html)

Quoted 3 lines

Kevin, Stefan, Andreas

Can you help to review & apply this set?

ping :-)

Quoted 16 lines

Thanks. Amos

Quoted 14 lines

Amos Kong (4):
qtest: introduce qmp_exec_hmp_cmd()
qtest: use qmp_exec_hmp_cmd() in blockdev-test
virtio-blk-test: change pci_nop() to virtblk_init()
virtio-blk-test: add hotplug subtest

 tests/blockdev-test.c   | 23 ++------------
 tests/libqtest.c        | 23 ++++++++++++++
 tests/libqtest.h        |  9 ++++++
 tests/virtio-blk-test.c | 81 ++++++++++++++++++++++++++++++++++++++++++++-----
 4 files changed, 108 insertions(+), 28 deletions(-)
Signature · 1 line
1.9.3
Signature · 1 line
			Amos.