* [Qemu-devel] [PATCH v2 0/4] test virtio-blk hotplug
@ 2014-06-05 5:45 Amos Kong
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 1/4] virtio-blk-test.c: change pci_nop() to virtblk_init() Amos Kong
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Amos Kong @ 2014-06-05 5:45 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha, afaerber, mst
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
Amos Kong (4):
virtio-blk-test.c: change pci_nop() to virtblk_init()
qtest: introduce qmp_exec_hmp_cmd()
virtio-blk-test.c: add hotplug subtest
qtest: use qmp_exec_hmp_cmd() in blockdev-test
tests/blockdev-test.c | 23 ++--------------------
tests/libqtest.c | 16 ++++++++++++++++
tests/libqtest.h | 8 ++++++++
tests/virtio-blk-test.c | 51 ++++++++++++++++++++++++++++++++++++++++++-------
4 files changed, 70 insertions(+), 28 deletions(-)
--
1.9.3
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH v2 1/4] virtio-blk-test.c: change pci_nop() to virtblk_init()
2014-06-05 5:45 [Qemu-devel] [PATCH v2 0/4] test virtio-blk hotplug Amos Kong
@ 2014-06-05 5:45 ` Amos Kong
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 2/4] qtest: introduce qmp_exec_hmp_cmd() Amos Kong
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Amos Kong @ 2014-06-05 5:45 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha, afaerber, mst
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.
Signed-off-by: Amos Kong <akong@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] 9+ messages in thread
* [Qemu-devel] [PATCH v2 2/4] qtest: introduce qmp_exec_hmp_cmd()
2014-06-05 5:45 [Qemu-devel] [PATCH v2 0/4] test virtio-blk hotplug Amos Kong
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 1/4] virtio-blk-test.c: change pci_nop() to virtblk_init() Amos Kong
@ 2014-06-05 5:45 ` Amos Kong
2014-06-05 7:16 ` Gonglei (Arei)
2014-06-05 9:29 ` Stefan Hajnoczi
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 3/4] virtio-blk-test.c: add hotplug subtest Amos Kong
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 4/4] qtest: use qmp_exec_hmp_cmd() in blockdev-test Amos Kong
3 siblings, 2 replies; 9+ messages in thread
From: Amos Kong @ 2014-06-05 5:45 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha, afaerber, mst
Signed-off-by: Amos Kong <akong@redhat.com>
---
tests/libqtest.c | 16 ++++++++++++++++
tests/libqtest.h | 8 ++++++++
2 files changed, 24 insertions(+)
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 71468ac..ceb1734 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -646,3 +646,19 @@ 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 *cmd, const char *expected_ret)
+{
+ QDict *response;
+ const char *response_return;
+
+ response = qmp("{\"execute\": \"human-monitor-command\","
+ " \"arguments\": {"
+ " \"command-line\": \"%s\""
+ "}}", g_strescape(cmd, NULL));
+ 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..e095df2 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -375,6 +375,14 @@ QDict *qmp(const char *fmt, ...);
void qmp_discard_response(const char *fmt, ...);
/**
+ * qmp_exec_hmp_cmd:
+ * @fmt...: HMP command to execute
+ *
+ * Executes HMP command by 'human-monitor-command'.
+ */
+void qmp_exec_hmp_cmd(const char *cmd, const char *expected_ret);
+
+/**
* qmp_receive:
*
* Reads a QMP message from QEMU and returns the response.
--
1.9.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH v2 3/4] virtio-blk-test.c: add hotplug subtest
2014-06-05 5:45 [Qemu-devel] [PATCH v2 0/4] test virtio-blk hotplug Amos Kong
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 1/4] virtio-blk-test.c: change pci_nop() to virtblk_init() Amos Kong
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 2/4] qtest: introduce qmp_exec_hmp_cmd() Amos Kong
@ 2014-06-05 5:45 ` Amos Kong
2014-06-05 9:31 ` Stefan Hajnoczi
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 4/4] qtest: use qmp_exec_hmp_cmd() in blockdev-test Amos Kong
3 siblings, 1 reply; 9+ messages in thread
From: Amos Kong @ 2014-06-05 5:45 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha, afaerber, mst
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 | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index 0fdec01..616599a 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -7,11 +7,48 @@
* 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"
+static void test_blk_hotplug(void)
+{
+ char addr[6];
+ char cmd[100];
+ int i, j;
+
+ /* start with no network/block device, slots 3~0x1f are free */
+ qtest_start("-net none");
+
+ for (i = 3; i <= 0x1f; i++) {
+ for (j = 7; j >= 0; j--) {
+ sprintf(addr, "%x.%x", i, j);
+ sprintf(cmd, "drive_add 0 if=none,file=/dev/null,id=drv-%s", addr);
+ qmp_exec_hmp_cmd(cmd, "OK\r\n");
+
+ sprintf(cmd, "device_add virtio-blk-pci,id=dev-%s,drive=drv-%s,"
+ "addr=0x%s,multifunction=on", addr, addr, addr);
+ qmp_exec_hmp_cmd(cmd, "");
+ }
+ }
+
+ /* hot-unplug doesn't work without cooperation of guest OS */
+ for (i = 3; i <= 0x1f; i++) {
+ for (j = 7; j >= 0; j--) {
+ sprintf(addr, "%x.%x", i, j);
+ sprintf(cmd, "drive_del drv-%s", addr);
+ qmp_exec_hmp_cmd(cmd, "");
+
+ sprintf(cmd, "device_del dev-%s", addr);
+ qmp_exec_hmp_cmd(cmd, "");
+ }
+ }
+
+ qtest_end();
+}
+
/* Tests only initialization */
static void virtblk_init(void)
{
@@ -26,6 +63,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] 9+ messages in thread
* [Qemu-devel] [PATCH v2 4/4] qtest: use qmp_exec_hmp_cmd() in blockdev-test
2014-06-05 5:45 [Qemu-devel] [PATCH v2 0/4] test virtio-blk hotplug Amos Kong
` (2 preceding siblings ...)
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 3/4] virtio-blk-test.c: add hotplug subtest Amos Kong
@ 2014-06-05 5:45 ` Amos Kong
2014-06-05 9:32 ` Stefan Hajnoczi
3 siblings, 1 reply; 9+ messages in thread
From: Amos Kong @ 2014-06-05 5:45 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha, afaerber, mst
Signed-off-by: Amos Kong <akong@redhat.com>
---
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..a84345c 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("drive_add 0 if=none,id=drive0", "OK\r\n");
qtest_end();
}
--
1.9.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v2 2/4] qtest: introduce qmp_exec_hmp_cmd()
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 2/4] qtest: introduce qmp_exec_hmp_cmd() Amos Kong
@ 2014-06-05 7:16 ` Gonglei (Arei)
2014-06-05 9:29 ` Stefan Hajnoczi
1 sibling, 0 replies; 9+ messages in thread
From: Gonglei (Arei) @ 2014-06-05 7:16 UTC (permalink / raw)
To: Amos Kong, qemu-devel; +Cc: stefanha, afaerber, mst
> -----Original Message-----
> From: qemu-devel-bounces+arei.gonglei=huawei.com@nongnu.org
> [mailto:qemu-devel-bounces+arei.gonglei=huawei.com@nongnu.org] On
> Behalf Of Amos Kong
> Sent: Thursday, June 05, 2014 1:45 PM
> To: qemu-devel@nongnu.org
> Cc: stefanha@gmail.com; afaerber@suse.de; mst@redhat.com
> Subject: [Qemu-devel] [PATCH v2 2/4] qtest: introduce qmp_exec_hmp_cmd()
>
> Signed-off-by: Amos Kong <akong@redhat.com>
> ---
> tests/libqtest.c | 16 ++++++++++++++++
> tests/libqtest.h | 8 ++++++++
> 2 files changed, 24 insertions(+)
>
Nice job :)
I will use it for usb host adapters hotplug/unplug qtests.
Best regards,
-Gonglei
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v2 2/4] qtest: introduce qmp_exec_hmp_cmd()
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 2/4] qtest: introduce qmp_exec_hmp_cmd() Amos Kong
2014-06-05 7:16 ` Gonglei (Arei)
@ 2014-06-05 9:29 ` Stefan Hajnoczi
1 sibling, 0 replies; 9+ messages in thread
From: Stefan Hajnoczi @ 2014-06-05 9:29 UTC (permalink / raw)
To: Amos Kong; +Cc: mst, qemu-devel, afaerber
On Thu, Jun 05, 2014 at 01:45:16PM +0800, Amos Kong wrote:
> Signed-off-by: Amos Kong <akong@redhat.com>
> ---
> tests/libqtest.c | 16 ++++++++++++++++
> tests/libqtest.h | 8 ++++++++
> 2 files changed, 24 insertions(+)
>
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index 71468ac..ceb1734 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -646,3 +646,19 @@ 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 *cmd, const char *expected_ret)
> +{
> + QDict *response;
> + const char *response_return;
> +
> + response = qmp("{\"execute\": \"human-monitor-command\","
> + " \"arguments\": {"
> + " \"command-line\": \"%s\""
> + "}}", g_strescape(cmd, NULL));
You need to free the g_strescape() return value after using it.
> + 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..e095df2 100644
> --- a/tests/libqtest.h
> +++ b/tests/libqtest.h
> @@ -375,6 +375,14 @@ QDict *qmp(const char *fmt, ...);
> void qmp_discard_response(const char *fmt, ...);
>
> /**
> + * qmp_exec_hmp_cmd:
> + * @fmt...: HMP command to execute
'fmt...' doesn't exist. Please document cmd and expected_ret.
> + *
> + * Executes HMP command by 'human-monitor-command'.
> + */
> +void qmp_exec_hmp_cmd(const char *cmd, const char *expected_ret);
> +
> +/**
> * qmp_receive:
> *
> * Reads a QMP message from QEMU and returns the response.
> --
> 1.9.3
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v2 3/4] virtio-blk-test.c: add hotplug subtest
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 3/4] virtio-blk-test.c: add hotplug subtest Amos Kong
@ 2014-06-05 9:31 ` Stefan Hajnoczi
0 siblings, 0 replies; 9+ messages in thread
From: Stefan Hajnoczi @ 2014-06-05 9:31 UTC (permalink / raw)
To: Amos Kong; +Cc: mst, qemu-devel, afaerber
On Thu, Jun 05, 2014 at 01:45:17PM +0800, Amos Kong wrote:
> 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 | 38 ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 38 insertions(+)
>
> diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
> index 0fdec01..616599a 100644
> --- a/tests/virtio-blk-test.c
> +++ b/tests/virtio-blk-test.c
> @@ -7,11 +7,48 @@
> * 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"
>
> +static void test_blk_hotplug(void)
> +{
> + char addr[6];
> + char cmd[100];
> + int i, j;
> +
> + /* start with no network/block device, slots 3~0x1f are free */
> + qtest_start("-net none");
> +
> + for (i = 3; i <= 0x1f; i++) {
> + for (j = 7; j >= 0; j--) {
> + sprintf(addr, "%x.%x", i, j);
> + sprintf(cmd, "drive_add 0 if=none,file=/dev/null,id=drv-%s", addr);
> + qmp_exec_hmp_cmd(cmd, "OK\r\n");
> +
> + sprintf(cmd, "device_add virtio-blk-pci,id=dev-%s,drive=drv-%s,"
> + "addr=0x%s,multifunction=on", addr, addr, addr);
> + qmp_exec_hmp_cmd(cmd, "");
> + }
> + }
> +
> + /* hot-unplug doesn't work without cooperation of guest OS */
> + for (i = 3; i <= 0x1f; i++) {
> + for (j = 7; j >= 0; j--) {
> + sprintf(addr, "%x.%x", i, j);
> + sprintf(cmd, "drive_del drv-%s", addr);
> + qmp_exec_hmp_cmd(cmd, "");
> +
> + sprintf(cmd, "device_del dev-%s", addr);
> + qmp_exec_hmp_cmd(cmd, "");
> + }
> + }
All of this sprintf() usage makes me wonder about:
qmp_exec_hmp_cmd(const char *expected_ret, const char *fmt, ...);
This way callers don't need to manage formatting buffers themselves.
Besides that:
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v2 4/4] qtest: use qmp_exec_hmp_cmd() in blockdev-test
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 4/4] qtest: use qmp_exec_hmp_cmd() in blockdev-test Amos Kong
@ 2014-06-05 9:32 ` Stefan Hajnoczi
0 siblings, 0 replies; 9+ messages in thread
From: Stefan Hajnoczi @ 2014-06-05 9:32 UTC (permalink / raw)
To: Amos Kong; +Cc: mst, qemu-devel, afaerber
On Thu, Jun 05, 2014 at 01:45:18PM +0800, Amos Kong wrote:
> Signed-off-by: Amos Kong <akong@redhat.com>
> ---
> tests/blockdev-test.c | 23 ++---------------------
> 1 file changed, 2 insertions(+), 21 deletions(-)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-06-05 9:32 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-05 5:45 [Qemu-devel] [PATCH v2 0/4] test virtio-blk hotplug Amos Kong
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 1/4] virtio-blk-test.c: change pci_nop() to virtblk_init() Amos Kong
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 2/4] qtest: introduce qmp_exec_hmp_cmd() Amos Kong
2014-06-05 7:16 ` Gonglei (Arei)
2014-06-05 9:29 ` Stefan Hajnoczi
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 3/4] virtio-blk-test.c: add hotplug subtest Amos Kong
2014-06-05 9:31 ` Stefan Hajnoczi
2014-06-05 5:45 ` [Qemu-devel] [PATCH v2 4/4] qtest: use qmp_exec_hmp_cmd() in blockdev-test Amos Kong
2014-06-05 9:32 ` Stefan Hajnoczi
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.