qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, akong@redhat.com, berto@igalia.com,
	armbru@redhat.com, mdroth@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH v4 15/16] qapi: Support downstream events and commands
Date: Thu, 14 May 2015 06:51:01 -0600	[thread overview]
Message-ID: <1431607862-9238-16-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1431607862-9238-1-git-send-email-eblake@redhat.com>

Enhance the testsuite to cover downstream events and commands.
Events worked without more tweaks, but commands needed a few final
updates in the generator to mangle names in the appropriate places.
In making those tweaks, it was easier to drop type_visitor() and
inline its actions instead.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi-commands.py                | 16 +++++-----------
 tests/qapi-schema/qapi-schema-test.json |  5 +++++
 tests/qapi-schema/qapi-schema-test.out  |  4 +++-
 tests/test-qmp-commands.c               | 15 +++++++++++++++
 4 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 8c125ca..0a1d636 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -20,12 +20,6 @@ import os
 import getopt
 import errno

-def type_visitor(name):
-    if type(name) == list:
-        return 'visit_type_%sList' % name[0]
-    else:
-        return 'visit_type_%s' % name
-
 def generate_command_decl(name, args, ret_type):
     arglist=""
     for argname, argtype, optional in parse_args(args):
@@ -153,10 +147,10 @@ if (has_%(c_name)s) {
                          c_name=c_name(argname))
             push_indent()
         ret += mcgen('''
-%(visitor)s(v, &%(c_name)s, "%(name)s", %(errp)s);
+visit_type_%(visitor)s(v, &%(c_name)s, "%(name)s", %(errp)s);
 ''',
                      c_name=c_name(argname), name=argname, argtype=argtype,
-                     visitor=type_visitor(argtype), errp=errparg)
+                     visitor=type_name(argtype), errp=errparg)
         ret += gen_err_check(errarg)
         if optional:
             pop_indent()
@@ -184,7 +178,7 @@ static void qmp_marshal_output_%(c_name)s(%(c_ret_type)s ret_in, QObject **ret_o
     Visitor *v;

     v = qmp_output_get_visitor(mo);
-    %(visitor)s(v, &ret_in, "unused", &local_err);
+    visit_type_%(visitor)s(v, &ret_in, "unused", &local_err);
     if (local_err) {
         goto out;
     }
@@ -195,12 +189,12 @@ out:
     qmp_output_visitor_cleanup(mo);
     md = qapi_dealloc_visitor_new();
     v = qapi_dealloc_get_visitor(md);
-    %(visitor)s(v, &ret_in, "unused", NULL);
+    visit_type_%(visitor)s(v, &ret_in, "unused", NULL);
     qapi_dealloc_visitor_cleanup(md);
 }
 ''',
                 c_ret_type=c_type(ret_type), c_name=c_name(name),
-                visitor=type_visitor(ret_type))
+                visitor=type_name(ret_type))

     return ret

diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json
index d586b56..c7eaa86 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -122,3 +122,8 @@
   'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
 { 'alternate': '__org.qemu_x-Alt',
   'data': { '__org.qemu_x-branch': 'str', 'b': '__org.qemu_x-Base' } }
+{ 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
+{ 'command': '__org.qemu_x-command',
+  'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'],
+            'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' },
+  'returns': '__org.qemu_x-Union1' }
diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
index 2161a90..cf0ccc4 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -29,7 +29,9 @@
  OrderedDict([('union', '__org.qemu_x-Union1'), ('data', OrderedDict([('__org.qemu_x-branch', 'str')]))]),
  OrderedDict([('struct', '__org.qemu_x-Struct2'), ('data', OrderedDict([('array', ['__org.qemu_x-Union1'])]))]),
  OrderedDict([('union', '__org.qemu_x-Union2'), ('base', '__org.qemu_x-Base'), ('discriminator', '__org.qemu_x-member1'), ('data', OrderedDict([('__org.qemu_x-value', '__org.qemu_x-Struct2')]))]),
- OrderedDict([('alternate', '__org.qemu_x-Alt'), ('data', OrderedDict([('__org.qemu_x-branch', 'str'), ('b', '__org.qemu_x-Base')]))])]
+ OrderedDict([('alternate', '__org.qemu_x-Alt'), ('data', OrderedDict([('__org.qemu_x-branch', 'str'), ('b', '__org.qemu_x-Base')]))]),
+ OrderedDict([('event', '__ORG.QEMU_X-EVENT'), ('data', '__org.qemu_x-Struct')]),
+ OrderedDict([('command', '__org.qemu_x-command'), ('data', OrderedDict([('a', ['__org.qemu_x-Enum']), ('b', ['__org.qemu_x-Struct']), ('c', '__org.qemu_x-Union2'), ('d', '__org.qemu_x-Alt')])), ('returns', '__org.qemu_x-Union1')])]
 [{'enum_name': 'EnumOne', 'enum_values': ['value1', 'value2', 'value3']},
  {'enum_name': '__org.qemu_x-Enum', 'enum_values': ['__org.qemu_x-value']},
  {'enum_name': 'UserDefAlternateKind', 'enum_values': None},
diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c
index ad2e403..9918f23 100644
--- a/tests/test-qmp-commands.c
+++ b/tests/test-qmp-commands.c
@@ -51,6 +51,21 @@ int64_t qmp_user_def_cmd3(int64_t a, bool has_b, int64_t b, Error **errp)
     return a + (has_b ? b : 0);
 }

+__org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_qemu_x_EnumList *a,
+                                              __org_qemu_x_StructList *b,
+                                              __org_qemu_x_Union2 *c,
+                                              __org_qemu_x_Alt *d,
+                                              Error **errp)
+{
+    __org_qemu_x_Union1 *ret = g_new0(__org_qemu_x_Union1, 1);
+
+    ret->kind = ORG_QEMU_X_UNION1_KIND___ORG_QEMU_X_BRANCH;
+    ret->__org_qemu_x_branch = strdup("blah1");
+
+    return ret;
+}
+
+
 /* test commands with no input and no return value */
 static void test_dispatch_cmd(void)
 {
-- 
2.1.0

  parent reply	other threads:[~2015-05-14 12:51 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-14 12:50 [Qemu-devel] [PATCH v4 00/16] Fix qapi mangling of downstream names Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 01/16] qapi: Fix C identifiers generated for names containing '.' Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 02/16] qapi: Rename identical c_fun()/c_var() into c_name() Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 03/16] qapi: Rename _generate_enum_string() to camel_to_upper() Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 04/16] qapi: Rename generate_enum_full_value() to c_enum_const() Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 05/16] qapi: Simplify c_enum_const() Eric Blake
2015-05-19  8:12   ` Alberto Garcia
2015-05-19 10:15     ` Markus Armbruster
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 06/16] qapi: Use c_enum_const() in generate_alternate_qtypes() Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 07/16] qapi: Move camel_to_upper(), c_enum_const() to closely related code Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 08/16] qapi: Tidy c_type logic Eric Blake
2015-05-14 15:35   ` Markus Armbruster
2015-05-14 15:39   ` Eric Blake
2015-05-14 16:13     ` Markus Armbruster
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 09/16] qapi: Make c_type() consistently convert qapi names Eric Blake
2015-05-14 15:40   ` Markus Armbruster
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 10/16] qapi: Support downstream enums Eric Blake
2015-05-14 16:02   ` Markus Armbruster
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 11/16] qapi: Support downstream structs Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 12/16] qapi: Support downstream simple unions Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 13/16] qapi: Support downstream flat unions Eric Blake
2015-05-14 12:51 ` [Qemu-devel] [PATCH v4 14/16] qapi: Support downstream alternates Eric Blake
2015-05-14 12:51 ` Eric Blake [this message]
2015-05-14 12:51 ` [Qemu-devel] [PATCH v4 16/16] qapi: Prefer '"str" + var' over '"str%s" % var' Eric Blake
2015-05-14 16:09   ` Markus Armbruster
2015-05-14 16:25     ` Eric Blake
2015-05-14 13:07 ` [Qemu-devel] [PATCH v4 00/16] Fix qapi mangling of downstream names Eric Blake
2015-05-14 16:46   ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431607862-9238-16-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=akong@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berto@igalia.com \
    --cc=kwolf@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).