qapi: Unify type bypass and add tests

For a few QMP commands, we are forced to pass an arbitrary type
without tracking it properly in QAPI.  Among the existing clients,
this unnamed type was spelled 'dict', 'visitor', and '**'; this
patch standardizes on '**', matching the documentation changes
earlier in the series.

Meanwhile, for the 'gen' key, we have been ignoring the value,
although the schema consistently used "'no'" ('success-response'
was hard-coded to checking for 'no').  But now that we can support
a literal "false" in the schema, we might as well use that rather
than ignoring the value or special-casing a random string.  Note
that these are one-way switches (use of 'gen':true is not the same
as omitting 'gen'). Also, the use of '**' requires 'gen':false,
but the use of 'gen':false does not mandate the use of '**'.

There is no difference to the generated code.  Add some tests on
what we'd like to guarantee, although it will take later patches
to clean up test results and actually enforce the use of a bool
parameter.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
Eric Blake 2015-05-04 09:05:19 -06:00 committed by Markus Armbruster
parent e53188ada5
commit d708cdbe87
16 changed files with 32 additions and 18 deletions

View File

@ -1561,8 +1561,8 @@
##
{ 'command': 'qom-get',
'data': { 'path': 'str', 'property': 'str' },
'returns': 'visitor',
'gen': 'no' }
'returns': '**',
'gen': false }
##
# @qom-set:
@ -1579,8 +1579,8 @@
# Since: 1.2
##
{ 'command': 'qom-set',
'data': { 'path': 'str', 'property': 'str', 'value': 'visitor' },
'gen': 'no' }
'data': { 'path': 'str', 'property': 'str', 'value': '**' },
'gen': false }
##
# @set_password:
@ -1943,7 +1943,7 @@
##
{ 'command': 'netdev_add',
'data': {'type': 'str', 'id': 'str', '*props': '**'},
'gen': 'no' }
'gen': false }
##
# @netdev_del:
@ -1976,8 +1976,8 @@
# Since: 2.0
##
{ 'command': 'object-add',
'data': {'qom-type': 'str', 'id': 'str', '*props': 'dict'},
'gen': 'no' }
'data': {'qom-type': 'str', 'id': 'str', '*props': '**'},
'gen': false }
##
# @object-del:

View File

@ -195,7 +195,7 @@
# Since: 0.15.0
##
{ 'command': 'guest-shutdown', 'data': { '*mode': 'str' },
'success-response': 'no' }
'success-response': false }
##
# @guest-file-open:
@ -470,7 +470,7 @@
#
# Since: 1.1
##
{ 'command': 'guest-suspend-disk', 'success-response': 'no' }
{ 'command': 'guest-suspend-disk', 'success-response': false }
##
# @guest-suspend-ram
@ -502,7 +502,7 @@
#
# Since: 1.1
##
{ 'command': 'guest-suspend-ram', 'success-response': 'no' }
{ 'command': 'guest-suspend-ram', 'success-response': false }
##
# @guest-suspend-hybrid
@ -529,7 +529,7 @@
#
# Since: 1.1
##
{ 'command': 'guest-suspend-hybrid', 'success-response': 'no' }
{ 'command': 'guest-suspend-hybrid', 'success-response': false }
##
# @GuestIpAddressType:

View File

@ -2,7 +2,7 @@
# QAPI command marshaller generator
#
# Copyright IBM, Corp. 2011
# Copyright (C) 2014 Red Hat, Inc.
# Copyright (C) 2014-2015 Red Hat, Inc.
#
# Authors:
# Anthony Liguori <aliguori@us.ibm.com>
@ -293,17 +293,12 @@ out:
return ret
def option_value_matches(opt, val, cmd):
if opt in cmd and cmd[opt] == val:
return True
return False
def gen_registry(commands):
registry=""
push_indent()
for cmd in commands:
options = 'QCO_NO_OPTIONS'
if option_value_matches('success-response', 'no', cmd):
if not cmd.get('success-response', True):
options = 'QCO_NO_SUCCESS_RESP'
registry += mcgen('''

View File

@ -216,6 +216,7 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \
bad-type-dict.json double-data.json unknown-expr-key.json \
redefined-type.json redefined-command.json redefined-builtin.json \
redefined-event.json command-int.json event-max.json \
type-bypass.json type-bypass-no-gen.json type-bypass-bad-gen.json \
missing-colon.json missing-comma-list.json \
missing-comma-object.json non-objects.json \
qapi-schema-test.json quoted-structural-chars.json \

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,2 @@
# FIXME: 'gen' should only appear with value false
{ 'command': 'foo', 'gen': 'whatever' }

View File

@ -0,0 +1,3 @@
[OrderedDict([('command', 'foo'), ('gen', 'whatever')])]
[]
[]

View File

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,2 @@
# FIXME: type bypass should only work with 'gen':false
{ 'command': 'unsafe', 'data': { 'arg': '**' }, 'returns': '**' }

View File

@ -0,0 +1,3 @@
[OrderedDict([('command', 'unsafe'), ('data', OrderedDict([('arg', '**')])), ('returns', '**')])]
[]
[]

View File

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,2 @@
# Use of 'gen':false allows bypassing type system
{ 'command': 'unsafe', 'data': { 'arg': '**' }, 'returns': '**', 'gen': false }

View File

@ -0,0 +1,3 @@
[OrderedDict([('command', 'unsafe'), ('data', OrderedDict([('arg', '**')])), ('returns', '**'), ('gen', False)])]
[]
[]