From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38430) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFJt8-0008Lv-Lh for qemu-devel@nongnu.org; Thu, 16 Nov 2017 08:07:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eFJt7-0007Cc-KT for qemu-devel@nongnu.org; Thu, 16 Nov 2017 08:07:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54438) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eFJt7-0007Bf-Br for qemu-devel@nongnu.org; Thu, 16 Nov 2017 08:07:25 -0500 From: Peter Xu Date: Thu, 16 Nov 2017 21:05:54 +0800 Message-Id: <20171116130610.23582-12-peterx@redhat.com> In-Reply-To: <20171116130610.23582-1-peterx@redhat.com> References: <20171116130610.23582-1-peterx@redhat.com> Subject: [Qemu-devel] [RFC v4 11/27] qmp: introduce QMPCapability List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , "Daniel P . Berrange" , Paolo Bonzini , Fam Zheng , Juan Quintela , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Eric Blake , Laurent Vivier , Markus Armbruster , marcandre.lureau@redhat.com, "Dr . David Alan Gilbert" There was no QMP capabilities defined. Define the first "oob" as capability to allow out-of-band messages. Also, touch up qmp-test.c to test the new bits. Signed-off-by: Peter Xu --- monitor.c | 15 +++++++++++++-- qapi-schema.json | 13 +++++++++++++ tests/qmp-test.c | 10 +++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/monitor.c b/monitor.c index 685938b9f2..468303b472 100644 --- a/monitor.c +++ b/monitor.c @@ -3944,12 +3944,23 @@ void monitor_resume(Monitor *mon) static QObject *get_qmp_greeting(void) { + QDict *result = qdict_new(), *qmp = qdict_new(); + QList *cap_list = qlist_new(); QObject *ver = NULL; + QMPCapability cap; + + qdict_put(result, "QMP", qmp); qmp_marshal_query_version(NULL, &ver, NULL); + qdict_put_obj(qmp, "version", ver); + + for (cap = 0; cap < QMP_CAPABILITY__MAX; cap++) { + qlist_append(cap_list, qstring_from_str( + QMPCapability_str(cap))); + } + qdict_put(qmp, "capabilities", cap_list); - return qobject_from_jsonf("{'QMP': {'version': %p, 'capabilities': []}}", - ver); + return QOBJECT(result); } static void monitor_qmp_event(void *opaque, int event) diff --git a/qapi-schema.json b/qapi-schema.json index 18457954a8..03201578b4 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -119,6 +119,19 @@ { 'command': 'qmp_capabilities' } ## +# @QMPCapability: +# +# QMP supported capabilities to be broadcasted to the clients. +# +# @oob: QMP ability to support Out-Of-Band requests. +# +# Since: 2.12 +# +## +{ 'enum': 'QMPCapability', + 'data': [ 'oob' ] } + +## # @VersionTriple: # # A three-part version number. diff --git a/tests/qmp-test.c b/tests/qmp-test.c index c5a5c10b41..292c5f135a 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -17,6 +17,7 @@ #include "qapi/qobject-input-visitor.h" #include "qapi/util.h" #include "qapi/visitor.h" +#include "qapi/qmp/qstring.h" const char common_args[] = "-nodefaults -machine none"; @@ -75,6 +76,8 @@ static void test_qmp_protocol(void) { QDict *resp, *q, *ret; QList *capabilities; + const QListEntry *entry; + QString *qstr; global_qtest = qtest_init_without_qmp_handshake(common_args); @@ -84,7 +87,12 @@ static void test_qmp_protocol(void) g_assert(q); test_version(qdict_get(q, "version")); capabilities = qdict_get_qlist(q, "capabilities"); - g_assert(capabilities && qlist_empty(capabilities)); + g_assert(capabilities); + entry = qlist_first(capabilities); + g_assert(entry); + qstr = qobject_to_qstring(entry->value); + g_assert(qstr); + g_assert_cmpstr(qstring_get_str(qstr), ==, "oob"); QDECREF(resp); /* Test valid command before handshake */ -- 2.13.6