14f193e34SMarkus Armbruster# *-*- Mode: Python -*-*
24f193e34SMarkus Armbruster
3625b251cSEric Blake# This file is a stress test of supported qapi constructs that must
4625b251cSEric Blake# parse and compile correctly.
5625b251cSEric Blake
61554a8faSMarkus Armbruster# Whitelists to permit QAPI rule violations
71554a8faSMarkus Armbruster{ 'pragma': {
81554a8faSMarkus Armbruster    # Commands allowed to return a non-dictionary:
91554a8faSMarkus Armbruster    'returns-whitelist': [
101554a8faSMarkus Armbruster        'guest-get-time',
111554a8faSMarkus Armbruster        'guest-sync' ] } }
121554a8faSMarkus Armbruster
13748053c9SEric Blake{ 'struct': 'TestStruct',
1487adbbffSMarc-André Lureau  'data': { 'integer': {'type': 'int'}, 'boolean': 'bool', 'string': 'str' } }
15748053c9SEric Blake
164f193e34SMarkus Armbruster# for testing enums
17895a2a80SEric Blake{ 'struct': 'NestedEnumsOne',
1870478cefSEric Blake  'data': { 'enum1': 'EnumOne',   # Intentional forward reference
1970478cefSEric Blake            '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } }
204f193e34SMarkus Armbruster
21625b251cSEric Blake# An empty enum, although unusual, is currently acceptable
22625b251cSEric Blake{ 'enum': 'MyEnum', 'data': [ ] }
23625b251cSEric Blake
2419767083SEric Blake# Likewise for an empty struct, including an empty base
2519767083SEric Blake{ 'struct': 'Empty1', 'data': { } }
2619767083SEric Blake{ 'struct': 'Empty2', 'base': 'Empty1', 'data': { } }
2719767083SEric Blake
28972a1101SEric Blake{ 'command': 'user_def_cmd0', 'data': 'Empty2', 'returns': 'Empty2' }
29972a1101SEric Blake
30351d36e4SDaniel P. Berrange# for testing override of default naming heuristic
31351d36e4SDaniel P. Berrange{ 'enum': 'QEnumTwo',
32351d36e4SDaniel P. Berrange  'prefix': 'QENUM_TWO',
33351d36e4SDaniel P. Berrange  'data': [ 'value1', 'value2' ] }
34351d36e4SDaniel P. Berrange
354f193e34SMarkus Armbruster# for testing nested structs
368c3f8e77SMarkus Armbruster{ 'struct': 'UserDefOne',
378c3f8e77SMarkus Armbruster  'base': 'UserDefZero',        # intentional forward reference
3870478cefSEric Blake  'data': { 'string': 'str',
3970478cefSEric Blake            '*enum1': 'EnumOne' } }   # intentional forward reference
4070478cefSEric Blake
4170478cefSEric Blake{ 'enum': 'EnumOne',
42800877bbSAnton Nefedov  'data': [ 'value1', 'value2', 'value3', 'value4' ] }
438c3f8e77SMarkus Armbruster
44895a2a80SEric Blake{ 'struct': 'UserDefZero',
45aabbd472SMarkus Armbruster  'data': { 'integer': 'int' } }
46aabbd472SMarkus Armbruster
476446a592SEric Blake{ 'struct': 'UserDefTwoDictDict',
486446a592SEric Blake  'data': { 'userdef': 'UserDefOne', 'string': 'str' } }
496446a592SEric Blake
506446a592SEric Blake{ 'struct': 'UserDefTwoDict',
516446a592SEric Blake  'data': { 'string1': 'str',
526446a592SEric Blake            'dict2': 'UserDefTwoDictDict',
536446a592SEric Blake            '*dict3': 'UserDefTwoDictDict' } }
546446a592SEric Blake
55895a2a80SEric Blake{ 'struct': 'UserDefTwo',
564f193e34SMarkus Armbruster  'data': { 'string0': 'str',
576446a592SEric Blake            'dict1': 'UserDefTwoDict' } }
584f193e34SMarkus Armbruster
59967c8851SMarc-André Lureau{ 'struct': 'UserDefThree',
60967c8851SMarc-André Lureau  'data': { 'string0': 'str' } }
61967c8851SMarc-André Lureau
629f08c8ecSEric Blake# dummy struct to force generation of array types not otherwise mentioned
639f08c8ecSEric Blake{ 'struct': 'ForceArrays',
64748053c9SEric Blake  'data': { 'unused1':['UserDefOne'], 'unused2':['UserDefTwo'],
65748053c9SEric Blake            'unused3':['TestStruct'] } }
669f08c8ecSEric Blake
674f193e34SMarkus Armbruster# for testing unions
68d220fbcdSEric Blake# Among other things, test that a name collision between branches does
69d220fbcdSEric Blake# not cause any problems (since only one branch can be in use at a time),
70d220fbcdSEric Blake# by intentionally using two branches that both have a C member 'a_b'
71895a2a80SEric Blake{ 'struct': 'UserDefA',
72d220fbcdSEric Blake  'data': { 'boolean': 'bool', '*a_b': 'int' } }
734f193e34SMarkus Armbruster
74895a2a80SEric Blake{ 'struct': 'UserDefB',
75d220fbcdSEric Blake  'data': { 'intb': 'int', '*a-b': 'bool' } }
764f193e34SMarkus Armbruster
778c3f8e77SMarkus Armbruster{ 'union': 'UserDefFlatUnion',
788c3f8e77SMarkus Armbruster  'base': 'UserDefUnionBase',   # intentional forward reference
798c3f8e77SMarkus Armbruster  'discriminator': 'enum1',
8087adbbffSMarc-André Lureau  'data': { 'value1' : {'type': 'UserDefA'},
818c3f8e77SMarkus Armbruster            'value2' : 'UserDefB',
82800877bbSAnton Nefedov            'value3' : 'UserDefB'
83800877bbSAnton Nefedov            # 'value4' defaults to empty
84800877bbSAnton Nefedov  } }
85cb55111bSMichael Roth
86895a2a80SEric Blake{ 'struct': 'UserDefUnionBase',
8780e60a19SMarkus Armbruster  'base': 'UserDefZero',
885223070cSWenchao Xia  'data': { 'string': 'str', 'enum1': 'EnumOne' } }
895223070cSWenchao Xia
9014f00c6cSEric Blake# this variant of UserDefFlatUnion defaults to a union that uses members with
91cb55111bSMichael Roth# allocated types to test corner cases in the cleanup/dealloc visitor
92cb55111bSMichael Roth{ 'union': 'UserDefFlatUnion2',
93ac4338f8SEric Blake  'base': { '*integer': 'int', 'string': 'str', 'enum1': 'QEnumTwo' },
94cb55111bSMichael Roth  'discriminator': 'enum1',
958c3f8e77SMarkus Armbruster  'data': { 'value1' : 'UserDefC', # intentional forward reference
969d3524b3SEric Blake            'value2' : 'UserDefB' } }
97cb55111bSMichael Roth
9868d07839SEric Blake{ 'struct': 'WrapAlternate',
9968d07839SEric Blake  'data': { 'alt': 'UserDefAlternate' } }
100ab916fadSEric Blake{ 'alternate': 'UserDefAlternate',
10187adbbffSMarc-André Lureau  'data': { 'udfu': {'type': 'UserDefFlatUnion'}, 'e': 'EnumOne', 'i': 'int',
1024d2d5c41SMarkus Armbruster            'n': 'null' } }
1032c38b600SMarkus Armbruster
1048c3f8e77SMarkus Armbruster{ 'struct': 'UserDefC',
1058c3f8e77SMarkus Armbruster  'data': { 'string1': 'str', 'string2': 'str' } }
1068c3f8e77SMarkus Armbruster
1079c51b441SEric Blake# for testing use of 'number' within alternates
1088168ca8eSMarkus Armbruster{ 'alternate': 'AltEnumBool', 'data': { 'e': 'EnumOne', 'b': 'bool' } }
1098168ca8eSMarkus Armbruster{ 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } }
1108168ca8eSMarkus Armbruster{ 'alternate': 'AltNumEnum', 'data': { 'n': 'number', 'e': 'EnumOne' } }
1118168ca8eSMarkus Armbruster{ 'alternate': 'AltEnumInt', 'data': { 'e': 'EnumOne', 'i': 'int' } }
1129c51b441SEric Blake
113c0644771SMarkus Armbruster# for testing use of 'str' within alternates
114c0644771SMarkus Armbruster{ 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } }
115c0644771SMarkus Armbruster
1164f193e34SMarkus Armbruster# for testing native lists
1174f193e34SMarkus Armbruster{ 'union': 'UserDefNativeListUnion',
1184f193e34SMarkus Armbruster  'data': { 'integer': ['int'],
1194f193e34SMarkus Armbruster            's8': ['int8'],
1204f193e34SMarkus Armbruster            's16': ['int16'],
1214f193e34SMarkus Armbruster            's32': ['int32'],
1224f193e34SMarkus Armbruster            's64': ['int64'],
1234f193e34SMarkus Armbruster            'u8': ['uint8'],
1244f193e34SMarkus Armbruster            'u16': ['uint16'],
1254f193e34SMarkus Armbruster            'u32': ['uint32'],
1264f193e34SMarkus Armbruster            'u64': ['uint64'],
1274f193e34SMarkus Armbruster            'number': ['number'],
1284f193e34SMarkus Armbruster            'boolean': ['bool'],
129cb17f79eSEric Blake            'string': ['str'],
13028770e05SMarkus Armbruster            'sizes': ['size'],
13128770e05SMarkus Armbruster            'any': ['any'] } }
1324f193e34SMarkus Armbruster
1334f193e34SMarkus Armbruster# testing commands
1344f193e34SMarkus Armbruster{ 'command': 'user_def_cmd', 'data': {} }
1354f193e34SMarkus Armbruster{ 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} }
136ab22ad96SMarkus Armbruster{ 'command': 'user_def_cmd2',
13787adbbffSMarc-André Lureau  'data': {'ud1a': {'type': 'UserDefOne'}, '*ud1b': 'UserDefOne'},
138ab22ad96SMarkus Armbruster  'returns': 'UserDefTwo' }
139cae95eaeSEric Blake
140ae6bf766SMarc-André Lureau{ 'command': 'cmd-success-response', 'data': {}, 'success-response': false }
141ae6bf766SMarc-André Lureau
142cae95eaeSEric Blake# Returning a non-dictionary requires a name from the whitelist
143cae95eaeSEric Blake{ 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' },
144c2216a8aSMarkus Armbruster  'returns': 'int' }
14528770e05SMarkus Armbruster{ 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' }
146c818408eSEric Blake{ 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' }
147c818408eSEric Blake{ 'command': 'boxed-union', 'data': 'UserDefNativeListUnion', 'boxed': true }
1483953e3a5SLaszlo Ersek
149c0698212SMarkus Armbruster# Smoke test on out-of-band and allow-preconfig-test
1507b13f2c2SIgor Mammedov{ 'command': 'test-flags-command', 'allow-oob': true, 'allow-preconfig': true }
1511a1b11dcSPeter Xu
1523953e3a5SLaszlo Ersek# For testing integer range flattening in opts-visitor. The following schema
1533953e3a5SLaszlo Ersek# corresponds to the option format:
1543953e3a5SLaszlo Ersek#
1553953e3a5SLaszlo Ersek# -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12
1563953e3a5SLaszlo Ersek#
1573953e3a5SLaszlo Ersek# For simplicity, this example doesn't use [type=]discriminator nor optargs
1583953e3a5SLaszlo Ersek# specific to discriminator values.
159895a2a80SEric Blake{ 'struct': 'UserDefOptions',
1603953e3a5SLaszlo Ersek  'data': {
1613953e3a5SLaszlo Ersek    '*i64' : [ 'int'    ],
1623953e3a5SLaszlo Ersek    '*u64' : [ 'uint64' ],
1633953e3a5SLaszlo Ersek    '*u16' : [ 'uint16' ],
1643953e3a5SLaszlo Ersek    '*i64x':   'int'     ,
1653953e3a5SLaszlo Ersek    '*u64x':   'uint64'  } }
166f6dadb02SWenchao Xia
167f6dadb02SWenchao Xia# testing event
168895a2a80SEric Blake{ 'struct': 'EventStructOne',
16987adbbffSMarc-André Lureau  'data': { 'struct1': {'type': 'UserDefOne'}, 'string': 'str', '*enum2': 'EnumOne' } }
170f6dadb02SWenchao Xia
171f6dadb02SWenchao Xia{ 'event': 'EVENT_A' }
172f6dadb02SWenchao Xia{ 'event': 'EVENT_B',
173f6dadb02SWenchao Xia  'data': { } }
174f6dadb02SWenchao Xia{ 'event': 'EVENT_C',
175f6dadb02SWenchao Xia  'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
176f6dadb02SWenchao Xia{ 'event': 'EVENT_D',
177f6dadb02SWenchao Xia  'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } }
178c818408eSEric Blake{ 'event': 'EVENT_E', 'boxed': true, 'data': 'UserDefZero' }
179c818408eSEric Blake{ 'event': 'EVENT_F', 'boxed': true, 'data': 'UserDefAlternate' }
180fce384b8SEric Blake
181c43567c1SEric Blake# test that we correctly compile downstream extensions, as well as munge
182c43567c1SEric Blake# ticklish names
183fce384b8SEric Blake{ 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
18483a02706SEric Blake{ 'struct': '__org.qemu_x-Base',
18583a02706SEric Blake  'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
18683a02706SEric Blake{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
187c43567c1SEric Blake  'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } }
188bb337290SEric Blake{ 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }
189857af5f0SEric Blake{ 'struct': '__org.qemu_x-Struct2',
190857af5f0SEric Blake  'data': { 'array': ['__org.qemu_x-Union1'] } }
191857af5f0SEric Blake{ 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base',
192857af5f0SEric Blake  'discriminator': '__org.qemu_x-member1',
193857af5f0SEric Blake  'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
194d1f07c86SEric Blake{ 'alternate': '__org.qemu_x-Alt',
195d1f07c86SEric Blake  'data': { '__org.qemu_x-branch': 'str', 'b': '__org.qemu_x-Base' } }
196e3c4c3d7SEric Blake{ 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
197e3c4c3d7SEric Blake{ 'command': '__org.qemu_x-command',
198e3c4c3d7SEric Blake  'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'],
199e3c4c3d7SEric Blake            'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' },
200e3c4c3d7SEric Blake  'returns': '__org.qemu_x-Union1' }
201967c8851SMarc-André Lureau
202967c8851SMarc-André Lureau# test 'if' condition handling
203967c8851SMarc-André Lureau
204ccadd6bcSMarc-André Lureau{ 'struct': 'TestIfStruct', 'data':
205ccadd6bcSMarc-André Lureau  { 'foo': 'int',
206ccadd6bcSMarc-André Lureau    'bar': { 'type': 'int', 'if': 'defined(TEST_IF_STRUCT_BAR)'} },
207967c8851SMarc-André Lureau  'if': 'defined(TEST_IF_STRUCT)' }
208967c8851SMarc-André Lureau
2096cc32b0eSMarc-André Lureau{ 'enum': 'TestIfEnum', 'data':
2106cc32b0eSMarc-André Lureau  [ 'foo', { 'name' : 'bar', 'if': 'defined(TEST_IF_ENUM_BAR)' } ],
211967c8851SMarc-André Lureau  'if': 'defined(TEST_IF_ENUM)' }
212967c8851SMarc-André Lureau
213a2724280SMarc-André Lureau{ 'union': 'TestIfUnion', 'data':
214a2724280SMarc-André Lureau  { 'foo': 'TestStruct',
215a2724280SMarc-André Lureau    'union_bar': { 'type': 'str', 'if': 'defined(TEST_IF_UNION_BAR)'} },
216967c8851SMarc-André Lureau  'if': 'defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)' }
217967c8851SMarc-André Lureau
218f8c4fdd6SMarc-André Lureau{ 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' },
219f8c4fdd6SMarc-André Lureau  'if': 'defined(TEST_IF_UNION)' }
220f8c4fdd6SMarc-André Lureau
2213e270dcaSMarc-André Lureau{ 'alternate': 'TestIfAlternate', 'data':
2223e270dcaSMarc-André Lureau  { 'foo': 'int',
2233e270dcaSMarc-André Lureau    'bar': { 'type': 'TestStruct', 'if': 'defined(TEST_IF_ALT_BAR)'} },
224967c8851SMarc-André Lureau  'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' }
225967c8851SMarc-André Lureau
226f8c4fdd6SMarc-André Lureau{ 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlternate' },
227f8c4fdd6SMarc-André Lureau  'if': 'defined(TEST_IF_ALT)' }
228f8c4fdd6SMarc-André Lureau
229ccadd6bcSMarc-André Lureau{ 'command': 'TestIfCmd', 'data':
230ccadd6bcSMarc-André Lureau  { 'foo': 'TestIfStruct',
231ccadd6bcSMarc-André Lureau    'bar': { 'type': 'TestIfEnum', 'if': 'defined(TEST_IF_CMD_BAR)' } },
232967c8851SMarc-André Lureau  'returns': 'UserDefThree',
233967c8851SMarc-André Lureau  'if': ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] }
234967c8851SMarc-André Lureau
235967c8851SMarc-André Lureau{ 'command': 'TestCmdReturnDefThree', 'returns': 'UserDefThree' }
236967c8851SMarc-André Lureau
237ccadd6bcSMarc-André Lureau{ 'event': 'TestIfEvent', 'data':
238ccadd6bcSMarc-André Lureau  { 'foo': 'TestIfStruct',
239*0f20628bSMarkus Armbruster    'bar': { 'type': ['TestIfEnum'], 'if': 'defined(TEST_IF_EVT_BAR)' } },
240967c8851SMarc-André Lureau  'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' }
241