* [Qemu-devel] [PATCH v6 0/4] test virtio-blk hotplug
@ 2014-06-25 1:15 Amos Kong
2014-06-25 1:15 ` [Qemu-devel] [PATCH v6 1/4] qtest: introduce qmp_exec_hmp_cmd() Amos Kong
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Amos Kong @ 2014-06-25 1:15 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha, arei.gonglei, afaerber, pbonzini
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(-)
--
1.9.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH v6 1/4] qtest: introduce qmp_exec_hmp_cmd()
2014-06-25 1:15 [Qemu-devel] [PATCH v6 0/4] test virtio-blk hotplug Amos Kong
@ 2014-06-25 1:15 ` Amos Kong
2014-06-25 1:15 ` [Qemu-devel] [PATCH v6 2/4] qtest: use qmp_exec_hmp_cmd() in blockdev-test Amos Kong
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Amos Kong @ 2014-06-25 1:15 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha, arei.gonglei, afaerber, pbonzini
This patch wraps a helper function to execute human command by
one QMP command (human-monitor-command). It also checks the return
string.
Signed-off-by: Amos Kong <akong@redhat.com>
---
tests/libqtest.c | 23 +++++++++++++++++++++++
tests/libqtest.h | 9 +++++++++
2 files changed, 32 insertions(+)
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 98e8f4b..80e0024 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -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);
+}
diff --git a/tests/libqtest.h b/tests/libqtest.h
index 8f323c7..d2959d3 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -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.
--
1.9.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH v6 2/4] qtest: use qmp_exec_hmp_cmd() in blockdev-test
2014-06-25 1:15 [Qemu-devel] [PATCH v6 0/4] test virtio-blk hotplug Amos Kong
2014-06-25 1:15 ` [Qemu-devel] [PATCH v6 1/4] qtest: introduce qmp_exec_hmp_cmd() Amos Kong
@ 2014-06-25 1:15 ` Amos Kong
2014-06-25 1:15 ` [Qemu-devel] [PATCH v6 3/4] virtio-blk-test: change pci_nop() to virtblk_init() Amos Kong
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Amos Kong @ 2014-06-25 1:15 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha, arei.gonglei, afaerber, pbonzini
Signed-off-by: Amos Kong <akong@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Andreas Färber <afaerber@suse.de>
---
tests/blockdev-test.c | 23 ++---------------------
1 file changed, 2 insertions(+), 21 deletions(-)
diff --git a/tests/blockdev-test.c b/tests/blockdev-test.c
index c940e00..c9127c0 100644
--- a/tests/blockdev-test.c
+++ b/tests/blockdev-test.c
@@ -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();
}
--
1.9.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH v6 3/4] virtio-blk-test: change pci_nop() to virtblk_init()
2014-06-25 1:15 [Qemu-devel] [PATCH v6 0/4] test virtio-blk hotplug Amos Kong
2014-06-25 1:15 ` [Qemu-devel] [PATCH v6 1/4] qtest: introduce qmp_exec_hmp_cmd() Amos Kong
2014-06-25 1:15 ` [Qemu-devel] [PATCH v6 2/4] qtest: use qmp_exec_hmp_cmd() in blockdev-test Amos Kong
@ 2014-06-25 1:15 ` Amos Kong
2014-06-25 1:15 ` [Qemu-devel] [PATCH v6 4/4] virtio-blk-test: add hotplug subtest Amos Kong
2014-07-06 12:14 ` [Qemu-devel] [PATCH v6 0/4] test virtio-blk hotplug Amos Kong
4 siblings, 0 replies; 7+ messages in thread
From: Amos Kong @ 2014-06-25 1:15 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha, arei.gonglei, afaerber, pbonzini
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.
Signed-off-by: Amos Kong <akong@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
tests/virtio-blk-test.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index d53f875..0fdec01 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -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;
}
--
1.9.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH v6 4/4] virtio-blk-test: add hotplug subtest
2014-06-25 1:15 [Qemu-devel] [PATCH v6 0/4] test virtio-blk hotplug Amos Kong
` (2 preceding siblings ...)
2014-06-25 1:15 ` [Qemu-devel] [PATCH v6 3/4] virtio-blk-test: change pci_nop() to virtblk_init() Amos Kong
@ 2014-06-25 1:15 ` Amos Kong
2014-07-06 12:14 ` [Qemu-devel] [PATCH v6 0/4] test virtio-blk hotplug Amos Kong
4 siblings, 0 replies; 7+ messages in thread
From: Amos Kong @ 2014-06-25 1:15 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha, arei.gonglei, afaerber, pbonzini
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.
Signed-off-by: Amos Kong <akong@redhat.com>
---
tests/virtio-blk-test.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index 0fdec01..7cb55cd 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -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();
--
1.9.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v6 0/4] test virtio-blk hotplug
2014-06-25 1:15 [Qemu-devel] [PATCH v6 0/4] test virtio-blk hotplug Amos Kong
` (3 preceding siblings ...)
2014-06-25 1:15 ` [Qemu-devel] [PATCH v6 4/4] virtio-blk-test: add hotplug subtest Amos Kong
@ 2014-07-06 12:14 ` Amos Kong
2014-08-23 0:24 ` Amos Kong
4 siblings, 1 reply; 7+ messages in thread
From: Amos Kong @ 2014-07-06 12:14 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha, arei.gonglei, afaerber, pbonzini
On Wed, Jun 25, 2014 at 09:15:12AM +0800, Amos Kong wrote:
> 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)
Kevin, Stefan, Andreas
Can you help to review & apply this set?
Thanks. Amos
> 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(-)
>
> --
> 1.9.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v6 0/4] test virtio-blk hotplug
2014-07-06 12:14 ` [Qemu-devel] [PATCH v6 0/4] test virtio-blk hotplug Amos Kong
@ 2014-08-23 0:24 ` Amos Kong
0 siblings, 0 replies; 7+ messages in thread
From: Amos Kong @ 2014-08-23 0:24 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha, arei.gonglei, afaerber, pbonzini
On Sun, Jul 06, 2014 at 08:14:46PM +0800, Amos Kong wrote:
> On Wed, Jun 25, 2014 at 09:15:12AM +0800, Amos Kong wrote:
> > 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)
>
> Kevin, Stefan, Andreas
>
> Can you help to review & apply this set?
ping :-)
> Thanks. Amos
>
> > 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(-)
> >
> > --
> > 1.9.3
--
Amos.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-08-23 0:24 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-25 1:15 [Qemu-devel] [PATCH v6 0/4] test virtio-blk hotplug Amos Kong
2014-06-25 1:15 ` [Qemu-devel] [PATCH v6 1/4] qtest: introduce qmp_exec_hmp_cmd() Amos Kong
2014-06-25 1:15 ` [Qemu-devel] [PATCH v6 2/4] qtest: use qmp_exec_hmp_cmd() in blockdev-test Amos Kong
2014-06-25 1:15 ` [Qemu-devel] [PATCH v6 3/4] virtio-blk-test: change pci_nop() to virtblk_init() Amos Kong
2014-06-25 1:15 ` [Qemu-devel] [PATCH v6 4/4] virtio-blk-test: add hotplug subtest Amos Kong
2014-07-06 12:14 ` [Qemu-devel] [PATCH v6 0/4] test virtio-blk hotplug Amos Kong
2014-08-23 0:24 ` Amos Kong
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.