xref: /qemu/tests/qapi-schema/qapi-schema-test.json (revision ac4338f8eb783fd421aae492ca262a586918471e)
1501e5104SMichael Roth# *-*- Mode: Python -*-*
2501e5104SMichael Roth
3625b251cSEric Blake# This file is a stress test of supported qapi constructs that must
4625b251cSEric Blake# parse and compile correctly.
5625b251cSEric Blake
6748053c9SEric Blake{ 'struct': 'TestStruct',
7748053c9SEric Blake  'data': { 'integer': 'int', 'boolean': 'bool', 'string': 'str' } }
8748053c9SEric Blake
9501e5104SMichael Roth# for testing enums
10895a2a80SEric Blake{ 'struct': 'NestedEnumsOne',
1170478cefSEric Blake  'data': { 'enum1': 'EnumOne',   # Intentional forward reference
1270478cefSEric Blake            '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } }
13501e5104SMichael Roth
14625b251cSEric Blake# An empty enum, although unusual, is currently acceptable
15625b251cSEric Blake{ 'enum': 'MyEnum', 'data': [ ] }
16625b251cSEric Blake
1719767083SEric Blake# Likewise for an empty struct, including an empty base
1819767083SEric Blake{ 'struct': 'Empty1', 'data': { } }
1919767083SEric Blake{ 'struct': 'Empty2', 'base': 'Empty1', 'data': { } }
2019767083SEric Blake
21972a1101SEric Blake{ 'command': 'user_def_cmd0', 'data': 'Empty2', 'returns': 'Empty2' }
22972a1101SEric Blake
23351d36e4SDaniel P. Berrange# for testing override of default naming heuristic
24351d36e4SDaniel P. Berrange{ 'enum': 'QEnumTwo',
25351d36e4SDaniel P. Berrange  'prefix': 'QENUM_TWO',
26351d36e4SDaniel P. Berrange  'data': [ 'value1', 'value2' ] }
27351d36e4SDaniel P. Berrange
28501e5104SMichael Roth# for testing nested structs
298c3f8e77SMarkus Armbruster{ 'struct': 'UserDefOne',
308c3f8e77SMarkus Armbruster  'base': 'UserDefZero',        # intentional forward reference
3170478cefSEric Blake  'data': { 'string': 'str',
3270478cefSEric Blake            '*enum1': 'EnumOne' } }   # intentional forward reference
3370478cefSEric Blake
3470478cefSEric Blake{ 'enum': 'EnumOne',
3570478cefSEric Blake  'data': [ 'value1', 'value2', 'value3' ] }
368c3f8e77SMarkus Armbruster
37895a2a80SEric Blake{ 'struct': 'UserDefZero',
38aabbd472SMarkus Armbruster  'data': { 'integer': 'int' } }
39aabbd472SMarkus Armbruster
406446a592SEric Blake{ 'struct': 'UserDefTwoDictDict',
416446a592SEric Blake  'data': { 'userdef': 'UserDefOne', 'string': 'str' } }
426446a592SEric Blake
436446a592SEric Blake{ 'struct': 'UserDefTwoDict',
446446a592SEric Blake  'data': { 'string1': 'str',
456446a592SEric Blake            'dict2': 'UserDefTwoDictDict',
466446a592SEric Blake            '*dict3': 'UserDefTwoDictDict' } }
476446a592SEric Blake
48895a2a80SEric Blake{ 'struct': 'UserDefTwo',
49f294f82aSLuiz Capitulino  'data': { 'string0': 'str',
506446a592SEric Blake            'dict1': 'UserDefTwoDict' } }
51f294f82aSLuiz Capitulino
529f08c8ecSEric Blake# dummy struct to force generation of array types not otherwise mentioned
539f08c8ecSEric Blake{ 'struct': 'ForceArrays',
54748053c9SEric Blake  'data': { 'unused1':['UserDefOne'], 'unused2':['UserDefTwo'],
55748053c9SEric Blake            'unused3':['TestStruct'] } }
569f08c8ecSEric Blake
57dc8fb6dfSPaolo Bonzini# for testing unions
58d220fbcdSEric Blake# Among other things, test that a name collision between branches does
59d220fbcdSEric Blake# not cause any problems (since only one branch can be in use at a time),
60d220fbcdSEric Blake# by intentionally using two branches that both have a C member 'a_b'
61895a2a80SEric Blake{ 'struct': 'UserDefA',
62d220fbcdSEric Blake  'data': { 'boolean': 'bool', '*a_b': 'int' } }
63dc8fb6dfSPaolo Bonzini
64895a2a80SEric Blake{ 'struct': 'UserDefB',
65d220fbcdSEric Blake  'data': { 'intb': 'int', '*a-b': 'bool' } }
66dc8fb6dfSPaolo Bonzini
678c3f8e77SMarkus Armbruster{ 'union': 'UserDefFlatUnion',
688c3f8e77SMarkus Armbruster  'base': 'UserDefUnionBase',   # intentional forward reference
698c3f8e77SMarkus Armbruster  'discriminator': 'enum1',
708c3f8e77SMarkus Armbruster  'data': { 'value1' : 'UserDefA',
718c3f8e77SMarkus Armbruster            'value2' : 'UserDefB',
728c3f8e77SMarkus Armbruster            'value3' : 'UserDefB' } }
73cb55111bSMichael Roth
74895a2a80SEric Blake{ 'struct': 'UserDefUnionBase',
7580e60a19SMarkus Armbruster  'base': 'UserDefZero',
765223070cSWenchao Xia  'data': { 'string': 'str', 'enum1': 'EnumOne' } }
775223070cSWenchao Xia
7814f00c6cSEric Blake# this variant of UserDefFlatUnion defaults to a union that uses members with
79cb55111bSMichael Roth# allocated types to test corner cases in the cleanup/dealloc visitor
80cb55111bSMichael Roth{ 'union': 'UserDefFlatUnion2',
81*ac4338f8SEric Blake  'base': { '*integer': 'int', 'string': 'str', 'enum1': 'QEnumTwo' },
82cb55111bSMichael Roth  'discriminator': 'enum1',
838c3f8e77SMarkus Armbruster  'data': { 'value1' : 'UserDefC', # intentional forward reference
849d3524b3SEric Blake            'value2' : 'UserDefB' } }
85cb55111bSMichael Roth
8668d07839SEric Blake{ 'struct': 'WrapAlternate',
8768d07839SEric Blake  'data': { 'alt': 'UserDefAlternate' } }
88ab916fadSEric Blake{ 'alternate': 'UserDefAlternate',
8968d07839SEric Blake  'data': { 'udfu': 'UserDefFlatUnion', 's': 'str', 'i': 'int' } }
902c38b600SMarkus Armbruster
918c3f8e77SMarkus Armbruster{ 'struct': 'UserDefC',
928c3f8e77SMarkus Armbruster  'data': { 'string1': 'str', 'string2': 'str' } }
938c3f8e77SMarkus Armbruster
949c51b441SEric Blake# for testing use of 'number' within alternates
959c51b441SEric Blake{ 'alternate': 'AltStrBool', 'data': { 's': 'str', 'b': 'bool' } }
969c51b441SEric Blake{ 'alternate': 'AltStrNum', 'data': { 's': 'str', 'n': 'number' } }
979c51b441SEric Blake{ 'alternate': 'AltNumStr', 'data': { 'n': 'number', 's': 'str' } }
989c51b441SEric Blake{ 'alternate': 'AltStrInt', 'data': { 's': 'str', 'i': 'int' } }
999c51b441SEric Blake{ 'alternate': 'AltIntNum', 'data': { 'i': 'int', 'n': 'number' } }
1009c51b441SEric Blake{ 'alternate': 'AltNumInt', 'data': { 'n': 'number', 'i': 'int' } }
1019c51b441SEric Blake
10283c84667SMichael Roth# for testing native lists
10383c84667SMichael Roth{ 'union': 'UserDefNativeListUnion',
10483c84667SMichael Roth  'data': { 'integer': ['int'],
10583c84667SMichael Roth            's8': ['int8'],
10683c84667SMichael Roth            's16': ['int16'],
10783c84667SMichael Roth            's32': ['int32'],
10883c84667SMichael Roth            's64': ['int64'],
10983c84667SMichael Roth            'u8': ['uint8'],
11083c84667SMichael Roth            'u16': ['uint16'],
11183c84667SMichael Roth            'u32': ['uint32'],
11283c84667SMichael Roth            'u64': ['uint64'],
11383c84667SMichael Roth            'number': ['number'],
11483c84667SMichael Roth            'boolean': ['bool'],
115cb17f79eSEric Blake            'string': ['str'],
11628770e05SMarkus Armbruster            'sizes': ['size'],
11728770e05SMarkus Armbruster            'any': ['any'] } }
11883c84667SMichael Roth
119501e5104SMichael Roth# testing commands
120501e5104SMichael Roth{ 'command': 'user_def_cmd', 'data': {} }
121501e5104SMichael Roth{ 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} }
122ab22ad96SMarkus Armbruster{ 'command': 'user_def_cmd2',
123ab22ad96SMarkus Armbruster  'data': {'ud1a': 'UserDefOne', '*ud1b': 'UserDefOne'},
124ab22ad96SMarkus Armbruster  'returns': 'UserDefTwo' }
125cae95eaeSEric Blake
126cae95eaeSEric Blake# Returning a non-dictionary requires a name from the whitelist
127cae95eaeSEric Blake{ 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' },
128c2216a8aSMarkus Armbruster  'returns': 'int' }
12928770e05SMarkus Armbruster{ 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' }
1303953e3a5SLaszlo Ersek
1313953e3a5SLaszlo Ersek# For testing integer range flattening in opts-visitor. The following schema
1323953e3a5SLaszlo Ersek# corresponds to the option format:
1333953e3a5SLaszlo Ersek#
1343953e3a5SLaszlo Ersek# -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12
1353953e3a5SLaszlo Ersek#
1363953e3a5SLaszlo Ersek# For simplicity, this example doesn't use [type=]discriminator nor optargs
1373953e3a5SLaszlo Ersek# specific to discriminator values.
138895a2a80SEric Blake{ 'struct': 'UserDefOptions',
1393953e3a5SLaszlo Ersek  'data': {
1403953e3a5SLaszlo Ersek    '*i64' : [ 'int'    ],
1413953e3a5SLaszlo Ersek    '*u64' : [ 'uint64' ],
1423953e3a5SLaszlo Ersek    '*u16' : [ 'uint16' ],
1433953e3a5SLaszlo Ersek    '*i64x':   'int'     ,
1443953e3a5SLaszlo Ersek    '*u64x':   'uint64'  } }
145f6dadb02SWenchao Xia
146f6dadb02SWenchao Xia# testing event
147895a2a80SEric Blake{ 'struct': 'EventStructOne',
148f6dadb02SWenchao Xia  'data': { 'struct1': 'UserDefOne', 'string': 'str', '*enum2': 'EnumOne' } }
149f6dadb02SWenchao Xia
150f6dadb02SWenchao Xia{ 'event': 'EVENT_A' }
151f6dadb02SWenchao Xia{ 'event': 'EVENT_B',
152f6dadb02SWenchao Xia  'data': { } }
153f6dadb02SWenchao Xia{ 'event': 'EVENT_C',
154f6dadb02SWenchao Xia  'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
155f6dadb02SWenchao Xia{ 'event': 'EVENT_D',
156f6dadb02SWenchao Xia  'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } }
157fce384b8SEric Blake
158c43567c1SEric Blake# test that we correctly compile downstream extensions, as well as munge
159c43567c1SEric Blake# ticklish names
160fce384b8SEric Blake{ 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
16183a02706SEric Blake{ 'struct': '__org.qemu_x-Base',
16283a02706SEric Blake  'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
16383a02706SEric Blake{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
164c43567c1SEric Blake  'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } }
165bb337290SEric Blake{ 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }
166857af5f0SEric Blake{ 'struct': '__org.qemu_x-Struct2',
167857af5f0SEric Blake  'data': { 'array': ['__org.qemu_x-Union1'] } }
168857af5f0SEric Blake{ 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base',
169857af5f0SEric Blake  'discriminator': '__org.qemu_x-member1',
170857af5f0SEric Blake  'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
171d1f07c86SEric Blake{ 'alternate': '__org.qemu_x-Alt',
172d1f07c86SEric Blake  'data': { '__org.qemu_x-branch': 'str', 'b': '__org.qemu_x-Base' } }
173e3c4c3d7SEric Blake{ 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
174e3c4c3d7SEric Blake{ 'command': '__org.qemu_x-command',
175e3c4c3d7SEric Blake  'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'],
176e3c4c3d7SEric Blake            'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' },
177e3c4c3d7SEric Blake  'returns': '__org.qemu_x-Union1' }
178