diff mbox

[3/4] libqtest: add qmp_device_add()

Message ID 1505295366-25295-4-git-send-email-peterx@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Peter Xu Sept. 13, 2017, 9:36 a.m. UTC
Since we have qmp_device_del(), pair them up.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 tests/libqtest.c | 15 +++++++++++++++
 tests/libqtest.h |  9 +++++++++
 2 files changed, 24 insertions(+)

Comments

Thomas Huth Sept. 13, 2017, 10:01 a.m. UTC | #1
On 13.09.2017 11:36, Peter Xu wrote:
> Since we have qmp_device_del(), pair them up.
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  tests/libqtest.c | 15 +++++++++++++++
>  tests/libqtest.h |  9 +++++++++
>  2 files changed, 24 insertions(+)
> 
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index a34d8c4..c7da962 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -925,6 +925,21 @@ QDict *qmp(const char *fmt, ...)
>      return response;
>  }
>  
> +void qmp_device_add(const char *args)

I think it would be nicer to have a function with variable args here, so
that the callers do not have to do the g_strdup_printf() dance all over
the place. See e.g. my qtest_hot_plug_device() function in my patch
here: http://patchwork.ozlabs.org/patch/801487/

If you fix that, I don't mind if we finally go with my patch or with
yours... If we decide to go with my patch, it would be nice to get some
Reviewed-bys for it. I think I could then send a PULL request for it,
since I've got some other test related patches in my queue and we do not
have a real maintainer for the tests directory...

 Thomas
diff mbox

Patch

diff --git a/tests/libqtest.c b/tests/libqtest.c
index a34d8c4..c7da962 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -925,6 +925,21 @@  QDict *qmp(const char *fmt, ...)
     return response;
 }
 
+void qmp_device_add(const char *args)
+{
+    QDict *response;
+    char *cmd;
+
+    cmd = g_strdup_printf("{'execute': 'device_add',"
+                          " 'arguments': { %s }"
+                          "}", args);
+    response = qmp(cmd);
+    g_free(cmd);
+    g_assert(response);
+    g_assert(!qdict_haskey(response, "error"));
+    QDECREF(response);
+}
+
 void qmp_device_del(const char *id)
 {
     QDict *response1, *response2, *event = NULL;
diff --git a/tests/libqtest.h b/tests/libqtest.h
index 0d48e4b..ecd02ac 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -920,6 +920,15 @@  QDict *qmp_fdv(int fd, const char *fmt, va_list ap);
 QDict *qmp_fd(int fd, const char *fmt, ...);
 
 /**
+ * qmp_device_add:
+ * @args: Parameters for the new device, like:
+ *        "'driver': 'XXX', 'id': 'XXX', 'addr': 'XXX'"
+ *
+ * Create a new device with parameter @args provided.
+ */
+void qmp_device_add(const char *args);
+
+/**
  * qmp_device_del:
  * @id: The device ID to be deleted
  *