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