Commitd88f5fd
and friends first introduced the various test-qmp-* tests in 2011, with duplicated hand-rolled TestStruct machinery, to make sure the qapi visitor interface was tested. Later, commit4f193e3
in 2013 added a .json file for further testing use by the files, but without consolidating any of the existing hand-rolled visitors. And with four copies, subtle differences have crept in, between the tests themselves (mainly whitespace differences, but also a question of whether to use NULL or "TestStruct" when calling visit_start_struct()) and from what the generator produces (the hand-rolled versions did not cater to partially-allocated objects, because they did not have a deallocation usage). Of course, just because the visitor interface is tested does not mean it is a sane interface; and future patches will be changing some of the visitor contracts. Rather than having to duplicate the cleanup work in each copy of the TestStruct visitor, and keep each hand-rolled copy in sync with what the generator supplies, we might as well just test what the generator should give us in the first place. Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1446791754-23823-2-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
174 lines
6.1 KiB
Python
174 lines
6.1 KiB
Python
# *-*- Mode: Python -*-*
|
|
|
|
# This file is a stress test of supported qapi constructs that must
|
|
# parse and compile correctly.
|
|
|
|
{ 'struct': 'TestStruct',
|
|
'data': { 'integer': 'int', 'boolean': 'bool', 'string': 'str' } }
|
|
|
|
# for testing enums
|
|
{ 'struct': 'NestedEnumsOne',
|
|
'data': { 'enum1': 'EnumOne', # Intentional forward reference
|
|
'*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } }
|
|
|
|
# An empty enum, although unusual, is currently acceptable
|
|
{ 'enum': 'MyEnum', 'data': [ ] }
|
|
|
|
# Likewise for an empty struct, including an empty base
|
|
{ 'struct': 'Empty1', 'data': { } }
|
|
{ 'struct': 'Empty2', 'base': 'Empty1', 'data': { } }
|
|
|
|
# for testing override of default naming heuristic
|
|
{ 'enum': 'QEnumTwo',
|
|
'prefix': 'QENUM_TWO',
|
|
'data': [ 'value1', 'value2' ] }
|
|
|
|
# for testing nested structs
|
|
{ 'struct': 'UserDefOne',
|
|
'base': 'UserDefZero', # intentional forward reference
|
|
'data': { 'string': 'str',
|
|
'*enum1': 'EnumOne' } } # intentional forward reference
|
|
|
|
{ 'enum': 'EnumOne',
|
|
'data': [ 'value1', 'value2', 'value3' ] }
|
|
|
|
{ 'struct': 'UserDefZero',
|
|
'data': { 'integer': 'int' } }
|
|
|
|
{ 'struct': 'UserDefTwoDictDict',
|
|
'data': { 'userdef': 'UserDefOne', 'string': 'str' } }
|
|
|
|
{ 'struct': 'UserDefTwoDict',
|
|
'data': { 'string1': 'str',
|
|
'dict2': 'UserDefTwoDictDict',
|
|
'*dict3': 'UserDefTwoDictDict' } }
|
|
|
|
{ 'struct': 'UserDefTwo',
|
|
'data': { 'string0': 'str',
|
|
'dict1': 'UserDefTwoDict' } }
|
|
|
|
# dummy struct to force generation of array types not otherwise mentioned
|
|
{ 'struct': 'ForceArrays',
|
|
'data': { 'unused1':['UserDefOne'], 'unused2':['UserDefTwo'],
|
|
'unused3':['TestStruct'] } }
|
|
|
|
# for testing unions
|
|
# Among other things, test that a name collision between branches does
|
|
# not cause any problems (since only one branch can be in use at a time),
|
|
# by intentionally using two branches that both have a C member 'a_b'
|
|
{ 'struct': 'UserDefA',
|
|
'data': { 'boolean': 'bool', '*a_b': 'int' } }
|
|
|
|
{ 'struct': 'UserDefB',
|
|
'data': { 'intb': 'int', '*a-b': 'bool' } }
|
|
|
|
{ 'union': 'UserDefFlatUnion',
|
|
'base': 'UserDefUnionBase', # intentional forward reference
|
|
'discriminator': 'enum1',
|
|
'data': { 'value1' : 'UserDefA',
|
|
'value2' : 'UserDefB',
|
|
'value3' : 'UserDefB' } }
|
|
|
|
{ 'struct': 'UserDefUnionBase',
|
|
'base': 'UserDefZero',
|
|
'data': { 'string': 'str', 'enum1': 'EnumOne' } }
|
|
|
|
# this variant of UserDefFlatUnion defaults to a union that uses fields with
|
|
# allocated types to test corner cases in the cleanup/dealloc visitor
|
|
{ 'union': 'UserDefFlatUnion2',
|
|
'base': 'UserDefUnionBase',
|
|
'discriminator': 'enum1',
|
|
'data': { 'value1' : 'UserDefC', # intentional forward reference
|
|
'value2' : 'UserDefB',
|
|
'value3' : 'UserDefA' } }
|
|
|
|
{ 'alternate': 'UserDefAlternate',
|
|
'data': { 'uda': 'UserDefA', 's': 'str', 'i': 'int' } }
|
|
|
|
{ 'struct': 'UserDefC',
|
|
'data': { 'string1': 'str', 'string2': 'str' } }
|
|
|
|
# for testing use of 'number' within alternates
|
|
{ 'alternate': 'AltStrBool', 'data': { 's': 'str', 'b': 'bool' } }
|
|
{ 'alternate': 'AltStrNum', 'data': { 's': 'str', 'n': 'number' } }
|
|
{ 'alternate': 'AltNumStr', 'data': { 'n': 'number', 's': 'str' } }
|
|
{ 'alternate': 'AltStrInt', 'data': { 's': 'str', 'i': 'int' } }
|
|
{ 'alternate': 'AltIntNum', 'data': { 'i': 'int', 'n': 'number' } }
|
|
{ 'alternate': 'AltNumInt', 'data': { 'n': 'number', 'i': 'int' } }
|
|
|
|
# for testing native lists
|
|
{ 'union': 'UserDefNativeListUnion',
|
|
'data': { 'integer': ['int'],
|
|
's8': ['int8'],
|
|
's16': ['int16'],
|
|
's32': ['int32'],
|
|
's64': ['int64'],
|
|
'u8': ['uint8'],
|
|
'u16': ['uint16'],
|
|
'u32': ['uint32'],
|
|
'u64': ['uint64'],
|
|
'number': ['number'],
|
|
'boolean': ['bool'],
|
|
'string': ['str'],
|
|
'sizes': ['size'],
|
|
'any': ['any'] } }
|
|
|
|
# testing commands
|
|
{ 'command': 'user_def_cmd', 'data': {} }
|
|
{ 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} }
|
|
{ 'command': 'user_def_cmd2',
|
|
'data': {'ud1a': 'UserDefOne', '*ud1b': 'UserDefOne'},
|
|
'returns': 'UserDefTwo' }
|
|
|
|
# Returning a non-dictionary requires a name from the whitelist
|
|
{ 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' },
|
|
'returns': 'int' }
|
|
{ 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' }
|
|
|
|
# For testing integer range flattening in opts-visitor. The following schema
|
|
# corresponds to the option format:
|
|
#
|
|
# -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12
|
|
#
|
|
# For simplicity, this example doesn't use [type=]discriminator nor optargs
|
|
# specific to discriminator values.
|
|
{ 'struct': 'UserDefOptions',
|
|
'data': {
|
|
'*i64' : [ 'int' ],
|
|
'*u64' : [ 'uint64' ],
|
|
'*u16' : [ 'uint16' ],
|
|
'*i64x': 'int' ,
|
|
'*u64x': 'uint64' } }
|
|
|
|
# testing event
|
|
{ 'struct': 'EventStructOne',
|
|
'data': { 'struct1': 'UserDefOne', 'string': 'str', '*enum2': 'EnumOne' } }
|
|
|
|
{ 'event': 'EVENT_A' }
|
|
{ 'event': 'EVENT_B',
|
|
'data': { } }
|
|
{ 'event': 'EVENT_C',
|
|
'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
|
|
{ 'event': 'EVENT_D',
|
|
'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } }
|
|
|
|
# test that we correctly compile downstream extensions
|
|
{ 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
|
|
{ 'struct': '__org.qemu_x-Base',
|
|
'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
|
|
{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
|
|
'data': { '__org.qemu_x-member2': 'str' } }
|
|
{ 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }
|
|
{ 'struct': '__org.qemu_x-Struct2',
|
|
'data': { 'array': ['__org.qemu_x-Union1'] } }
|
|
{ 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base',
|
|
'discriminator': '__org.qemu_x-member1',
|
|
'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' }
|