1# *-*- Mode: Python -*-*
2# vim: filetype=python
3
4# This file is a stress test of supported qapi constructs that must
5# parse and compile correctly.
6
7# Whitelists to permit QAPI rule violations
8{ 'pragma': {
9    # Types whose member names may use '_'
10    'member-name-exceptions': [
11        'UserDefA'
12    ],
13    # Commands allowed to return a non-dictionary:
14    'command-returns-exceptions': [
15        'guest-get-time',
16        'guest-sync' ] } }
17
18{ 'struct': 'TestStruct',
19  'data': { 'integer': {'type': 'int'}, 'boolean': 'bool', 'string': 'str' } }
20
21# for testing enums
22{ 'struct': 'NestedEnumsOne',
23  'data': { 'enum1': 'EnumOne',   # Intentional forward reference
24            '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } }
25
26# An empty enum, although unusual, is currently acceptable
27{ 'enum': 'MyEnum', 'data': [ ] }
28
29# Likewise for an empty struct, including an empty base
30{ 'struct': 'Empty1', 'data': { } }
31{ 'struct': 'Empty2', 'base': 'Empty1', 'data': { } }
32
33# Likewise for an empty flat union
34{ 'union': 'Union',
35  'base': { 'type': 'EnumOne' }, 'discriminator': 'type',
36  'data': { } }
37
38{ 'command': 'user-def-cmd0', 'data': 'Empty2', 'returns': 'Empty2' }
39
40# for testing override of default naming heuristic
41{ 'enum': 'QEnumTwo',
42  'prefix': 'QENUM_TWO',
43  'data': [ 'value1', 'value2' ] }
44
45# for testing nested structs
46{ 'struct': 'UserDefOne',
47  'base': 'UserDefZero',        # intentional forward reference
48  'data': { 'string': 'str',
49            '*enum1': 'EnumOne' } }   # intentional forward reference
50
51{ 'enum': 'EnumOne',
52  'data': [ 'value1', 'value2', 'value3', 'value4' ] }
53
54{ 'struct': 'UserDefZero',
55  'data': { 'integer': 'int' } }
56
57{ 'struct': 'UserDefTwoDictDict',
58  'data': { 'userdef': 'UserDefOne', 'string': 'str' } }
59
60{ 'struct': 'UserDefTwoDict',
61  'data': { 'string1': 'str',
62            'dict2': 'UserDefTwoDictDict',
63            '*dict3': 'UserDefTwoDictDict' } }
64
65{ 'struct': 'UserDefTwo',
66  'data': { 'string0': 'str',
67            'dict1': 'UserDefTwoDict' } }
68
69{ 'struct': 'UserDefThree',
70  'data': { 'string0': 'str' } }
71
72# dummy struct to force generation of array types not otherwise mentioned
73{ 'struct': 'ForceArrays',
74  'data': { 'unused1':['UserDefOne'], 'unused2':['UserDefTwo'],
75            'unused3':['TestStruct'] } }
76
77# for testing unions
78# Among other things, test that a name collision between branches does
79# not cause any problems (since only one branch can be in use at a time),
80# by intentionally using two branches that both have a C member 'a_b'
81{ 'struct': 'UserDefA',
82  'data': { 'boolean': 'bool', '*a_b': 'int' } }
83
84{ 'struct': 'UserDefB',
85  'data': { 'intb': 'int', '*a-b': 'bool' } }
86
87{ 'union': 'UserDefFlatUnion',
88  'base': 'UserDefUnionBase',   # intentional forward reference
89  'discriminator': 'enum1',
90  'data': { 'value1' : {'type': 'UserDefA'},
91            'value2' : 'UserDefB',
92            'value3' : 'UserDefB'
93            # 'value4' defaults to empty
94  } }
95
96{ 'struct': 'UserDefUnionBase',
97  'base': 'UserDefZero',
98  'data': { 'string': 'str', 'enum1': 'EnumOne' } }
99
100# this variant of UserDefFlatUnion defaults to a union that uses members with
101# allocated types to test corner cases in the cleanup/dealloc visitor
102{ 'union': 'UserDefFlatUnion2',
103  'base': { '*integer': 'int', 'string': 'str', 'enum1': 'QEnumTwo' },
104  'discriminator': 'enum1',
105  'data': { 'value1' : 'UserDefC', # intentional forward reference
106            'value2' : 'UserDefB' } }
107
108{ 'struct': 'WrapAlternate',
109  'data': { 'alt': 'UserDefAlternate' } }
110{ 'alternate': 'UserDefAlternate',
111  'data': { 'udfu': {'type': 'UserDefFlatUnion'}, 'e': 'EnumOne', 'i': 'int',
112            'n': 'null' } }
113
114{ 'struct': 'UserDefC',
115  'data': { 'string1': 'str', 'string2': 'str' } }
116
117# for testing use of 'number' within alternates
118{ 'alternate': 'AltEnumBool', 'data': { 'e': 'EnumOne', 'b': 'bool' } }
119{ 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } }
120{ 'alternate': 'AltNumEnum', 'data': { 'n': 'number', 'e': 'EnumOne' } }
121{ 'alternate': 'AltEnumInt', 'data': { 'e': 'EnumOne', 'i': 'int' } }
122
123# for testing use of 'str' within alternates
124{ 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } }
125
126# for testing lists
127{ 'union': 'UserDefListUnion',
128  'data': { 'integer': ['int'],
129            's8': ['int8'],
130            's16': ['int16'],
131            's32': ['int32'],
132            's64': ['int64'],
133            'u8': ['uint8'],
134            'u16': ['uint16'],
135            'u32': ['uint32'],
136            'u64': ['uint64'],
137            'number': ['number'],
138            'boolean': ['bool'],
139            'string': ['str'],
140            'sizes': ['size'],
141            'any': ['any'],
142            'user': ['Status'] } } # intentional forward ref. to sub-module
143{ 'struct': 'ArrayStruct',
144  'data': { 'integer': ['int'],
145            's8': ['int8'],
146            's16': ['int16'],
147            's32': ['int32'],
148            's64': ['int64'],
149            'u8': ['uint8'],
150            'u16': ['uint16'],
151            'u32': ['uint32'],
152            'u64': ['uint64'],
153            'number': ['number'],
154            'boolean': ['bool'],
155            'string': ['str'],
156            '*sz': ['size'],
157            '*any': ['any'],
158            '*user': ['Status'] } } # intentional forward ref. to sub-module
159
160# for testing sub-modules
161{ 'include': 'include/sub-module.json' }
162
163# testing commands
164{ 'command': 'user-def-cmd', 'data': {} }
165{ 'command': 'user-def-cmd1', 'data': {'ud1a': 'UserDefOne'} }
166{ 'command': 'user-def-cmd2',
167  'data': {'ud1a': {'type': 'UserDefOne'}, '*ud1b': 'UserDefOne'},
168  'returns': 'UserDefTwo' }
169
170{ 'command': 'cmd-success-response', 'data': {}, 'success-response': false }
171{ 'command': 'coroutine-cmd', 'data': {}, 'coroutine': true }
172
173# Returning a non-dictionary requires a name from the whitelist
174{ 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' },
175  'returns': 'int' }
176{ 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' }
177{ 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' }
178{ 'command': 'boxed-union', 'data': 'UserDefListUnion', 'boxed': true }
179{ 'command': 'boxed-empty', 'boxed': true, 'data': 'Empty1' }
180
181# Smoke test on out-of-band and allow-preconfig-test
182{ 'command': 'test-flags-command', 'allow-oob': true, 'allow-preconfig': true }
183
184# For testing integer range flattening in opts-visitor. The following schema
185# corresponds to the option format:
186#
187# -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12
188#
189# For simplicity, this example doesn't use [type=]discriminator nor optargs
190# specific to discriminator values.
191{ 'struct': 'UserDefOptions',
192  'data': {
193    '*i64' : [ 'int'    ],
194    '*u64' : [ 'uint64' ],
195    '*u16' : [ 'uint16' ],
196    '*i64x':   'int'     ,
197    '*u64x':   'uint64'  } }
198
199# testing event
200{ 'struct': 'EventStructOne',
201  'data': { 'struct1': {'type': 'UserDefOne'}, 'string': 'str', '*enum2': 'EnumOne' } }
202
203{ 'event': 'EVENT_A' }
204{ 'event': 'EVENT_B',
205  'data': { } }
206{ 'event': 'EVENT_C',
207  'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
208{ 'event': 'EVENT_D',
209  'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } }
210{ 'event': 'EVENT_E', 'boxed': true, 'data': 'UserDefZero' }
211{ 'event': 'EVENT_F', 'boxed': true, 'data': 'UserDefFlatUnion' }
212{ 'event': 'EVENT_G', 'boxed': true, 'data': 'Empty1' }
213
214# test that we correctly compile downstream extensions, as well as munge
215# ticklish names
216# also test union and alternate with just one branch
217{ 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
218{ 'struct': '__org.qemu_x-Base',
219  'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
220{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
221  'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } }
222{ 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }
223{ 'alternate': '__org.qemu_x-Alt1', 'data': { '__org.qemu_x-branch': 'str' } }
224{ 'struct': '__org.qemu_x-Struct2',
225  'data': { 'array': ['__org.qemu_x-Union1'] } }
226{ 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base',
227  'discriminator': '__org.qemu_x-member1',
228  'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
229{ 'alternate': '__org.qemu_x-Alt',
230  'data': { '__org.qemu_x-branch': '__org.qemu_x-Base' } }
231{ 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
232{ 'command': '__org.qemu_x-command',
233  'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'],
234            'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' },
235  'returns': '__org.qemu_x-Union1' }
236
237# test 'if' condition handling
238
239{ 'struct': 'TestIfStruct',
240  'data': { 'foo': 'int',
241            'bar': { 'type': 'int', 'if': 'TEST_IF_STRUCT_BAR'} },
242  'if': 'TEST_IF_STRUCT' }
243
244{ 'enum': 'TestIfEnum',
245  'data': [ 'foo', { 'name' : 'bar', 'if': 'TEST_IF_ENUM_BAR' } ],
246  'if': 'TEST_IF_ENUM' }
247
248{ 'union': 'TestIfUnion',
249  'data': { 'foo': 'TestStruct',
250            'bar': { 'type': 'str', 'if': 'TEST_IF_UNION_BAR'} },
251  'if': { 'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT'] } }
252
253{ 'command': 'test-if-union-cmd',
254  'data': { 'union-cmd-arg': 'TestIfUnion' },
255  'if': { 'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT'] } }
256
257{ 'alternate': 'TestIfAlternate',
258  'data': { 'foo': 'int',
259            'bar': { 'type': 'TestStruct', 'if': 'TEST_IF_ALT_BAR'} },
260  'if': { 'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT'] } }
261
262{ 'command': 'test-if-alternate-cmd',
263  'data': { 'alt-cmd-arg': 'TestIfAlternate' },
264  'if': { 'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT'] } }
265
266{ 'command': 'test-if-cmd',
267  'data': {
268    'foo': 'TestIfStruct',
269    'bar': { 'type': 'TestIfEnum', 'if': 'TEST_IF_CMD_BAR' } },
270  'returns': 'UserDefThree',
271  'if': { 'all': ['TEST_IF_CMD', 'TEST_IF_STRUCT'] } }
272
273{ 'command': 'test-cmd-return-def-three', 'returns': 'UserDefThree' }
274
275{ 'event': 'TEST_IF_EVENT',
276  'data': { 'foo': 'TestIfStruct',
277            'bar': { 'type': ['TestIfEnum'], 'if': 'TEST_IF_EVT_BAR' } },
278  'if': { 'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT'] } }
279
280{ 'event': 'TEST_IF_EVENT2', 'data': {},
281  'if': { 'not': { 'any': [ { 'not': 'TEST_IF_EVT' },
282                            { 'not': 'TEST_IF_STRUCT' } ] } } }
283
284# test 'features'
285
286{ 'struct': 'FeatureStruct0',
287  'data': { 'foo': 'int' },
288  'features': [] }
289{ 'struct': 'FeatureStruct1',
290  'data': { 'foo': { 'type': 'int', 'features': [ 'deprecated' ] } },
291  'features': [ 'feature1' ] }
292{ 'struct': 'FeatureStruct2',
293  'data': { 'foo': 'int' },
294  'features': [ { 'name': 'feature1' } ] }
295{ 'struct': 'FeatureStruct3',
296  'data': { 'foo': 'int' },
297  'features': [ 'feature1', 'feature2' ] }
298{ 'struct': 'FeatureStruct4',
299  'data': { 'namespace-test': 'int' },
300  'features': [ 'namespace-test', 'int', 'name', 'if' ] }
301
302{ 'struct': 'CondFeatureStruct1',
303  'data': { 'foo': 'int' },
304  'features': [ { 'name': 'feature1', 'if': 'TEST_IF_FEATURE_1'} ] }
305{ 'struct': 'CondFeatureStruct2',
306  'data': { 'foo': 'int' },
307  'features': [ { 'name': 'feature1', 'if': 'TEST_IF_FEATURE_1'},
308                { 'name': 'feature2', 'if': 'TEST_IF_FEATURE_2'} ] }
309{ 'struct': 'CondFeatureStruct3',
310  'data': { 'foo': 'int' },
311  'features': [ { 'name': 'feature1',
312                  'if': { 'all': [ 'TEST_IF_COND_1',
313                                   'TEST_IF_COND_2'] } } ] }
314{ 'struct': 'CondFeatureStruct4',
315  'data': { 'foo': 'int' },
316  'features': [ { 'name': 'feature1',
317                  'if': {'any': ['TEST_IF_COND_1',
318                                 'TEST_IF_COND_2'] } } ] }
319
320{ 'enum': 'FeatureEnum1',
321  'data': [ 'eins', 'zwei', 'drei' ],
322  'features': [ 'feature1' ] }
323
324{ 'union': 'FeatureUnion1',
325  'base': { 'tag': 'FeatureEnum1' },
326  'discriminator': 'tag',
327  'data': { 'eins': 'FeatureStruct1' },
328  'features': [ 'feature1' ] }
329
330{ 'alternate': 'FeatureAlternate1',
331  'data': { 'eins': 'FeatureStruct1' },
332  'features': [ 'feature1' ] }
333
334{ 'command': 'test-features0',
335  'data': { '*fs0': 'FeatureStruct0',
336            '*fs1': 'FeatureStruct1',
337            '*fs2': 'FeatureStruct2',
338            '*fs3': 'FeatureStruct3',
339            '*fs4': 'FeatureStruct4',
340            '*cfs1': 'CondFeatureStruct1',
341            '*cfs2': 'CondFeatureStruct2',
342            '*cfs3': 'CondFeatureStruct3',
343            '*cfs4': 'CondFeatureStruct4' },
344  'returns': 'FeatureStruct1',
345  'features': [] }
346
347{ 'command': 'test-command-features1',
348  'features': [ 'deprecated' ] }
349{ 'command': 'test-command-features3',
350  'features': [ 'feature1', 'feature2' ] }
351
352{ 'command': 'test-command-cond-features1',
353  'features': [ { 'name': 'feature1', 'if': 'TEST_IF_FEATURE_1'} ] }
354{ 'command': 'test-command-cond-features2',
355  'features': [ { 'name': 'feature1', 'if': 'TEST_IF_FEATURE_1'},
356                { 'name': 'feature2', 'if': 'TEST_IF_FEATURE_2'} ] }
357{ 'command': 'test-command-cond-features3',
358  'features': [ { 'name': 'feature1',
359                  'if': { 'all': [ 'TEST_IF_COND_1',
360                                   'TEST_IF_COND_2'] } } ] }
361
362{ 'event': 'TEST_EVENT_FEATURES0',
363  'data': 'FeatureStruct1' }
364
365{ 'event': 'TEST_EVENT_FEATURES1',
366  'features': [ 'deprecated' ] }
367