diff mbox

[18/24] qtest: add qtest_init_qmp_caps()

Message ID 20161010092301.14974-19-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau Oct. 10, 2016, 9:22 a.m. UTC
Add a function to specify the qmp capabilities content.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 tests/libqtest.c | 13 +++++++++++--
 tests/libqtest.h |  9 +++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 6f6bdf1..d672adb 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -146,7 +146,7 @@  void qtest_add_abrt_handler(GHookFunc fn, const void *data)
     g_hook_prepend(&abrt_hooks, hook);
 }
 
-QTestState *qtest_init(const char *extra_args)
+QTestState *qtest_init_qmp_caps(const char *extra_args, const char *qmp_caps)
 {
     QTestState *s;
     int sock, qmpsock, i;
@@ -203,7 +203,11 @@  QTestState *qtest_init(const char *extra_args)
 
     /* Read the QMP greeting and then do the handshake */
     qtest_qmp_discard_response(s, "");
-    qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }");
+    command = g_strdup_printf(
+        "{ 'execute': 'qmp_capabilities',"
+        " 'arguments': {'capabilities': [%s]}}", qmp_caps);
+    qtest_qmp_discard_response(s, command);
+    g_free(command);
 
     if (getenv("QTEST_STOP")) {
         kill(s->qemu_pid, SIGSTOP);
@@ -212,6 +216,11 @@  QTestState *qtest_init(const char *extra_args)
     return s;
 }
 
+QTestState *qtest_init(const char *extra_args)
+{
+    return qtest_init_qmp_caps(extra_args, "");
+}
+
 void qtest_quit(QTestState *s)
 {
     qtest_instances = g_list_remove(qtest_instances, s);
diff --git a/tests/libqtest.h b/tests/libqtest.h
index f7402e0..bdec5de 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -31,6 +31,15 @@  extern QTestState *global_qtest;
  */
 QTestState *qtest_init(const char *extra_args);
 
+/**
+ * qtest_init_qmp_caps:
+ * @extra_args: other arguments to pass to QEMU.
+ * @qmp_caps: qmp capabilities
+ *
+ * Returns: #QTestState instance.
+ */
+QTestState *qtest_init_qmp_caps(const char *extra_args, const char *qmp_caps);
+
 /**
  * qtest_quit:
  * @s: #QTestState instance to operate on.