[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 4/6] tests: Introduce generic device hot-plug/ho
From: |
Cornelia Huck |
Subject: |
Re: [Qemu-devel] [PATCH 4/6] tests: Introduce generic device hot-plug/hot-unplug functions |
Date: |
Thu, 17 Aug 2017 11:00:16 +0200 |
On Thu, 17 Aug 2017 08:25:11 +0200
Thomas Huth <address@hidden> wrote:
> A lot of tests provide code for adding and removing a device via the
> device_add and device_del QMP commands. Maintaining this code in so
> many places is cumbersome and error-prone (some of the code parts
> check the responses in an incorrect way, for example), so let's
> provide some proper generic qtest functions for adding and removing a
> device instead.
This sounds like a good idea.
>
> Signed-off-by: Thomas Huth <address@hidden>
> ---
> tests/libqos/pci.c | 19 ++-------------
> tests/libqos/usb.c | 30 +++++------------------
> tests/libqtest.c | 60
> ++++++++++++++++++++++++++++++++++++++++++++++
> tests/libqtest.h | 19 +++++++++++++++
> tests/usb-hcd-uhci-test.c | 26 ++------------------
> tests/usb-hcd-xhci-test.c | 51 ++++-----------------------------------
> tests/virtio-scsi-test.c | 24 ++-----------------
> tests/virtio-serial-test.c | 25 +++----------------
> 8 files changed, 98 insertions(+), 156 deletions(-)
>
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index b9a1f18..4339d97 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -987,3 +987,63 @@ void qtest_cb_for_every_machine(void (*cb)(const char
> *machine))
> qtest_end();
> QDECREF(response);
> }
> +
> +/**
> + * Generic hot-plugging test via the device_add QMP command
> + */
> +void qtest_hot_plug_device(const char *driver, const char *id,
> + const char *fmt, ...)
> +{
> + QDict *response;
> + char *cmd, *opts = NULL;
> + va_list va;
> +
> + if (fmt) {
> + va_start(va, fmt);
> + opts = g_strdup_vprintf(fmt, va);
> + va_end(va);
> + }
> +
> + cmd = g_strdup_printf("{'execute': 'device_add',"
> + " 'arguments': { 'driver': '%s', 'id': '%s'%s%s
> }}",
> + driver, id, opts ? ", " : "", opts ? opts : "");
> + g_free(opts);
> +
> + response = qmp(cmd);
> + g_free(cmd);
> + g_assert(response);
> + while (qdict_haskey(response, "event")) {
> + /* We can get DEVICE_DELETED events in case something went wrong */
> + g_assert_cmpstr(qdict_get_str(response, "event"), !=,
> "DEVICE_DELETED");
Is there other stuff we should check for?
> + QDECREF(response);
> + response = qmp("");
> + g_assert(response);
> + }
> + g_assert(!qdict_haskey(response, "error"));
> + QDECREF(response);
> +}
> +
> +/**
> + * Generic hot-unplugging test via the device_del QMP command
> + */
> +void qtest_hot_unplug_device(const char *id)
> +{
> + QDict *response;
> + char *cmd;
> +
> + cmd = g_strdup_printf("{'execute': 'device_del',"
> + " 'arguments': { 'id': '%s' }}", id);
> +
> + response = qmp(cmd);
> + g_free(cmd);
> + g_assert(response);
> + while (qdict_haskey(response, "event")) {
> + /* We should get DEVICE_DELETED event first */
> + g_assert_cmpstr(qdict_get_str(response, "event"), ==,
> "DEVICE_DELETED");
'should' does not sound assert-worthy to me :) Is this an expected event?
> + QDECREF(response);
> + response = qmp("");
> + g_assert(response);
> + }
> + g_assert(!qdict_haskey(response, "error"));
> + QDECREF(response);
> +}
- Re: [Qemu-devel] [PATCH 2/6] tests: Add network filter tests to the check-qtest-s390x list, (continued)
[Qemu-devel] [PATCH 3/6] tests: Enable the drive_del test also on s390x, Thomas Huth, 2017/08/17
[Qemu-devel] [PATCH 4/6] tests: Introduce generic device hot-plug/hot-unplug functions, Thomas Huth, 2017/08/17
[Qemu-devel] [PATCH 5/6] tests: Add qvirtio_(un)plug_device_test wrapper functions, Thomas Huth, 2017/08/17
[Qemu-devel] [PATCH 6/6] tests: Enable the simple virtio tests on s390x, too, Thomas Huth, 2017/08/17
Re: [Qemu-devel] [PATCH for-2.11 0/6] Enable more qtests for s390x, Cornelia Huck, 2017/08/17