Skip to contentSkip to conversation

test virtio-blk hotplug

PATCH Superseded Amos Kong 4 participants 11 messages Jun 18, 2014 – Jun 19, 2014

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Amos Kong

author
#0 lore raw

v5 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

Amos Kong (4):
qtest: introduce qmp_exec_hmp_cmd()
qtest: use qmp_exec_hmp_cmd() in blockdev-test virtio-blk-test.c: change pci_nop() to virtblk_init() virtio-blk-test.c: 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 v5 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 v5 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 v5 3/4 virtio-blk-test.c: change pci_nop() to virtblk_init()

In reply to Amos Kong

I want to add a new subtest in virtio-blk-test.c, 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
#4 lore raw

Re: [Qemu-devel] [PATCH v5 3/4] virtio-blk-test.c: change pci_nop() to virtblk_init()

Am 18.06.2014 18:24, schrieb Amos Kong:

Quoted 15 lines

I want to add a new subtest in virtio-blk-test.c, 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 +0 -0
index d53f875..0fdec01 100644

tests/virtio-blk-test.c line 15

Quoted 4 lines
tests/virtio-blk-test.c +0 -1
@@ -12,9 +12,12 @@
 #include "libqtest.h"
 #include "qemu/osdep.h"
 
-/* Tests only initialization so far. TODO: Replace with functional tests */

One thing of note here is that this TODO is neither resolved here nor later in this series. Stefan had originally asked me to add it.

Andreas

Quoted 10 lines
tests/virtio-blk-test.c +5 -1
-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)

[snip]

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
author
#5 lore raw

Re: [Qemu-devel] [PATCH v5 3/4] virtio-blk-test.c: change pci_nop() to virtblk_init()

Quoted 19 lines · Andreas Färber

Am 18.06.2014 18:24, schrieb Amos Kong:

Quoted 18 lines

I want to add a new subtest in virtio-blk-test.c, 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 +0 -0
index d53f875..0fdec01 100644
@@ -12,9 +12,12 @@
 #include "libqtest.h"
 #include "qemu/osdep.h"
 
Quoted 4 lines

tests/virtio-blk-test.c line 15

Quoted 1 line
tests/virtio-blk-test.c +0 -1
-/* Tests only initialization so far. TODO: Replace with functional tests */

One thing of note here is that this TODO is neither resolved here nor later in this series. Stefan had originally asked me to add it.

We don't treated pci_nop() as test in the past, but in this patch we rename and split it as a single initialization testing.

We also added another functional test by next patchset.

So we can remove the 'TODO'

Quoted 17 lines

Andreas

Quoted 10 lines
tests/virtio-blk-test.c +5 -1
-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)

[snip]

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Signature · 1 line
			Amos.
author
#6 lore raw

PATCH v5 4/4 virtio-blk-test.c: 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..77817ca 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 with no network/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--) {
+            if (j == MAX_PCI_FUNC) {
+                qmp_exec_hmp_cmd("", "drive_del drv-%x.%x", i, 0);
+            }
+            sprintf(device_id, "dev-%x.%x", i, j);
+            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
#7 lore raw

Re: [Qemu-devel] [PATCH v5 4/4] virtio-blk-test.c: add hotplug subtest

tests/virtio-blk-test.c line 67

Quoted 5 lines · Amos Kong
tests/virtio-blk-test.c +5 -0
+    for (i = MIN_PCI_SLOT; i <= MAX_PCI_SLOT; i++) {
+        for (j = MAX_PCI_FUNC; j >= 0; j--) {
+            if (j == MAX_PCI_FUNC) {
+                qmp_exec_hmp_cmd("", "drive_del drv-%x.%x", i, 0);
+            }

Why is only drv-%x.0 deleted? Previous revisions of this patch series deleted all drives.

Stefan

author
#8 lore raw

Re: [Qemu-devel] [PATCH v5 4/4] virtio-blk-test.c: add hotplug subtest

Quoted 9 lines · Stefan Hajnoczi

tests/virtio-blk-test.c line 67

Quoted 5 lines · Amos Kong
tests/virtio-blk-test.c +5 -0
+    for (i = MIN_PCI_SLOT; i <= MAX_PCI_SLOT; i++) {
+        for (j = MAX_PCI_FUNC; j >= 0; j--) {
+            if (j == MAX_PCI_FUNC) {
+                qmp_exec_hmp_cmd("", "drive_del drv-%x.%x", i, 0);
+            }

Why is only drv-%x.0 deleted? Previous revisions of this patch series deleted all drives.

Hot-unplug any single function, all functions in the slot will be removed. So once is enough.

Quoted 1 line

Stefan

Signature · 1 line
			Amos.
#9 lore raw

Re: [Qemu-devel] [PATCH v5 4/4] virtio-blk-test.c: add hotplug subtest

Hi,

Quoted 16 lines

-----Original Message-----
From: Amos Kong [mailto:[email protected]]
Sent: Thursday, June 19, 2014 11:58 AM
To: Stefan Hajnoczi
Cc: [email protected]; Gonglei (Arei); [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 4/4] virtio-blk-test.c: add hotplug subtest

Quoted 7 lines · Stefan Hajnoczi
Quoted 5 lines · Amos Kong
tests/virtio-blk-test.c +5 -0
+    for (i = MIN_PCI_SLOT; i <= MAX_PCI_SLOT; i++) {
+        for (j = MAX_PCI_FUNC; j >= 0; j--) {
+            if (j == MAX_PCI_FUNC) {
+                qmp_exec_hmp_cmd("", "drive_del drv-%x.%x", i, 0);
+            }
Quoted 6 lines
Quoted 2 lines

Why is only drv-%x.0 deleted? Previous revisions of this patch series deleted all drives.

Hot-unplug any single function, all functions in the slot will be removed. So once is enough.

IMHO, the below devices as the same as the drive about multifunction hot-unplug, right?

Best regards,
-Gonglei

author
#10 lore raw

Re: [Qemu-devel] [PATCH v5 4/4] virtio-blk-test.c: add hotplug subtest

Quoted 18 lines · Gonglei (Arei)

Hi,

Quoted 16 lines

-----Original Message-----
From: Amos Kong [mailto:[email protected]]
Sent: Thursday, June 19, 2014 11:58 AM
To: Stefan Hajnoczi
Cc: [email protected]; Gonglei (Arei); [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 4/4] virtio-blk-test.c: add hotplug subtest

Quoted 7 lines · Stefan Hajnoczi
Quoted 5 lines · Amos Kong
tests/virtio-blk-test.c +5 -0
+    for (i = MIN_PCI_SLOT; i <= MAX_PCI_SLOT; i++) {
+        for (j = MAX_PCI_FUNC; j >= 0; j--) {
+            if (j == MAX_PCI_FUNC) {
+                qmp_exec_hmp_cmd("", "drive_del drv-%x.%x", i, 0);
+            }
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

Why is only drv-%x.0 deleted? Previous revisions of this patch series deleted all drives.

Hot-unplug any single function, all functions in the slot will be removed. So once is enough.

IMHO, the below devices as the same as the drive about multifunction hot-unplug, right?

I'm wrong. drive should be hot-unplugged one by one, device will be removed by slot. PCI device has multifunction feature, not drive.

Quoted 2 lines

Best regards,
-Gonglei

Signature · 1 line
			Amos.