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 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{ 'struct': 'ArrayStruct',
127  'data': { 'integer': ['int'],
128            's8': ['int8'],
129            's16': ['int16'],
130            's32': ['int32'],
131            's64': ['int64'],
132            'u8': ['uint8'],
133            'u16': ['uint16'],
134            'u32': ['uint32'],
135            'u64': ['uint64'],
136            'number': ['number'],
137            'boolean': ['bool'],
138            'string': ['str'],
139            '*sz': ['size'],
140            '*any': ['any'],
141            '*user': ['Status'] } } # intentional forward ref. to sub-module
142
143# for testing sub-modules
144{ 'include': 'include/sub-module.json' }
145
146# testing commands
147{ 'command': 'user-def-cmd', 'data': {} }
148{ 'command': 'user-def-cmd1', 'data': {'ud1a': 'UserDefOne'} }
149{ 'command': 'user-def-cmd2',
150  'data': {'ud1a': {'type': 'UserDefOne'}, '*ud1b': 'UserDefOne'},
151  'returns': 'UserDefTwo' }
152
153{ 'command': 'cmd-success-response', 'data': {}, 'success-response': false }
154{ 'command': 'coroutine-cmd', 'data': {}, 'coroutine': true }
155
156# Returning a non-dictionary requires a name from the whitelist
157{ 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' },
158  'returns': 'int' }
159{ 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' }
160{ 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' }
161{ 'command': 'boxed-union', 'data': 'UserDefFlatUnion', 'boxed': true }
162{ 'command': 'boxed-empty', 'boxed': true, 'data': 'Empty1' }
163
164# Smoke test on out-of-band and allow-preconfig-test
165{ 'command': 'test-flags-command', 'allow-oob': true, 'allow-preconfig': true }
166
167# For testing integer range flattening in opts-visitor. The following schema
168# corresponds to the option format:
169#
170# -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12
171#
172# For simplicity, this example doesn't use [type=]discriminator nor optargs
173# specific to discriminator values.
174{ 'struct': 'UserDefOptions',
175  'data': {
176    '*i64' : [ 'int'    ],
177    '*u64' : [ 'uint64' ],
178    '*u16' : [ 'uint16' ],
179    '*i64x':   'int'     ,
180    '*u64x':   'uint64'  } }
181
182# testing event
183{ 'struct': 'EventStructOne',
184  'data': { 'struct1': {'type': 'UserDefOne'}, 'string': 'str', '*enum2': 'EnumOne' } }
185
186{ 'event': 'EVENT_A' }
187{ 'event': 'EVENT_B',
188  'data': { } }
189{ 'event': 'EVENT_C',
190  'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
191{ 'event': 'EVENT_D',
192  'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } }
193{ 'event': 'EVENT_E', 'boxed': true, 'data': 'UserDefZero' }
194{ 'event': 'EVENT_F', 'boxed': true, 'data': 'UserDefFlatUnion' }
195{ 'event': 'EVENT_G', 'boxed': true, 'data': 'Empty1' }
196
197# test that we correctly compile downstream extensions, as well as munge
198# ticklish names
199# also test union and alternate with just one branch
200{ 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
201{ 'struct': '__org.qemu_x-Base',
202  'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
203{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
204  'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } }
205{ 'alternate': '__org.qemu_x-Alt1', 'data': { '__org.qemu_x-branch': 'str' } }
206{ 'struct': '__org.qemu_x-Struct2',
207  'data': { 'array': ['__org.qemu_x-Union'] } }
208{ 'union': '__org.qemu_x-Union', 'base': '__org.qemu_x-Base',
209  'discriminator': '__org.qemu_x-member1',
210  'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
211{ 'alternate': '__org.qemu_x-Alt',
212  'data': { '__org.qemu_x-branch': '__org.qemu_x-Base' } }
213{ 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
214{ 'command': '__org.qemu_x-command',
215  'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'],
216            'c': '__org.qemu_x-Union', 'd': '__org.qemu_x-Alt' } }
217
218# test 'if' condition handling
219
220{ 'struct': 'TestIfStruct',
221  'data': { 'foo': 'int',
222            'bar': { 'type': 'int', 'if': 'TEST_IF_STRUCT_BAR'} },
223  'if': 'TEST_IF_STRUCT' }
224
225{ 'enum': 'TestIfEnum',
226  'data': [ 'foo', { 'name' : 'bar', 'if': 'TEST_IF_ENUM_BAR' } ],
227  'if': 'TEST_IF_ENUM' }
228
229{ 'union': 'TestIfUnion',
230  'base': { 'type': 'TestIfEnum' },
231  'discriminator': 'type',
232  'data': { 'foo': 'TestStruct',
233            'bar': { 'type': 'UserDefZero', 'if': 'TEST_IF_ENUM_BAR'} },
234  'if': { 'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT'] } }
235
236{ 'command': 'test-if-union-cmd',
237  'data': { 'union-cmd-arg': 'TestIfUnion' },
238  'if': { 'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT'] } }
239
240{ 'alternate': 'TestIfAlternate',
241  'data': { 'foo': 'int',
242            'bar': { 'type': 'TestStruct', 'if': 'TEST_IF_ALT_BAR'} },
243  'if': { 'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT'] } }
244
245{ 'command': 'test-if-alternate-cmd',
246  'data': { 'alt-cmd-arg': 'TestIfAlternate' },
247  'if': { 'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT'] } }
248
249{ 'command': 'test-if-cmd',
250  'data': {
251    'foo': 'TestIfStruct',
252    'bar': { 'type': 'TestIfEnum', 'if': 'TEST_IF_CMD_BAR' } },
253  'returns': 'UserDefThree',
254  'if': { 'all': ['TEST_IF_CMD', 'TEST_IF_STRUCT'] } }
255
256{ 'command': 'test-cmd-return-def-three', 'returns': 'UserDefThree' }
257
258{ 'event': 'TEST_IF_EVENT',
259  'data': { 'foo': 'TestIfStruct',
260            'bar': { 'type': ['TestIfEnum'], 'if': 'TEST_IF_EVT_BAR' } },
261  'if': { 'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT'] } }
262
263{ 'event': 'TEST_IF_EVENT2', 'data': {},
264  'if': { 'not': { 'any': [ { 'not': 'TEST_IF_EVT' },
265                            { 'not': 'TEST_IF_STRUCT' } ] } } }
266
267# test 'features'
268
269{ 'struct': 'FeatureStruct0',
270  'data': { 'foo': 'int' },
271  'features': [] }
272{ 'struct': 'FeatureStruct1',
273  'data': { 'foo': { 'type': 'int', 'features': [ 'deprecated' ] } },
274  'features': [ 'feature1' ] }
275{ 'struct': 'FeatureStruct2',
276  'data': { 'foo': 'int' },
277  'features': [ { 'name': 'feature1' } ] }
278{ 'struct': 'FeatureStruct3',
279  'data': { 'foo': 'int' },
280  'features': [ 'feature1', 'feature2' ] }
281{ 'struct': 'FeatureStruct4',
282  'data': { 'namespace-test': 'int' },
283  'features': [ 'namespace-test', 'int', 'name', 'if' ] }
284
285{ 'struct': 'CondFeatureStruct1',
286  'data': { 'foo': 'int' },
287  'features': [ { 'name': 'feature1', 'if': 'TEST_IF_FEATURE_1'} ] }
288{ 'struct': 'CondFeatureStruct2',
289  'data': { 'foo': 'int' },
290  'features': [ { 'name': 'feature1', 'if': 'TEST_IF_FEATURE_1'},
291                { 'name': 'feature2', 'if': 'TEST_IF_FEATURE_2'} ] }
292{ 'struct': 'CondFeatureStruct3',
293  'data': { 'foo': 'int' },
294  'features': [ { 'name': 'feature1',
295                  'if': { 'all': [ 'TEST_IF_COND_1',
296                                   'TEST_IF_COND_2'] } } ] }
297{ 'struct': 'CondFeatureStruct4',
298  'data': { 'foo': 'int' },
299  'features': [ { 'name': 'feature1',
300                  'if': {'any': ['TEST_IF_COND_1',
301                                 'TEST_IF_COND_2'] } } ] }
302
303{ 'enum': 'FeatureEnum1',
304  'data': [ 'eins', 'zwei', 'drei' ],
305  'features': [ 'feature1' ] }
306
307{ 'union': 'FeatureUnion1',
308  'base': { 'tag': 'FeatureEnum1' },
309  'discriminator': 'tag',
310  'data': { 'eins': 'FeatureStruct1' },
311  'features': [ 'feature1' ] }
312
313{ 'alternate': 'FeatureAlternate1',
314  'data': { 'eins': 'FeatureStruct1' },
315  'features': [ 'feature1' ] }
316
317{ 'command': 'test-features0',
318  'data': { '*fs0': 'FeatureStruct0',
319            '*fs1': 'FeatureStruct1',
320            '*fs2': 'FeatureStruct2',
321            '*fs3': 'FeatureStruct3',
322            '*fs4': 'FeatureStruct4',
323            '*cfs1': 'CondFeatureStruct1',
324            '*cfs2': 'CondFeatureStruct2',
325            '*cfs3': 'CondFeatureStruct3',
326            '*cfs4': 'CondFeatureStruct4' },
327  'returns': 'FeatureStruct1',
328  'features': [] }
329
330{ 'command': 'test-command-features1',
331  'features': [ 'deprecated' ] }
332{ 'command': 'test-command-features3',
333  'features': [ 'feature1', 'feature2' ] }
334
335{ 'command': 'test-command-cond-features1',
336  'features': [ { 'name': 'feature1', 'if': 'TEST_IF_FEATURE_1'} ] }
337{ 'command': 'test-command-cond-features2',
338  'features': [ { 'name': 'feature1', 'if': 'TEST_IF_FEATURE_1'},
339                { 'name': 'feature2', 'if': 'TEST_IF_FEATURE_2'} ] }
340{ 'command': 'test-command-cond-features3',
341  'features': [ { 'name': 'feature1',
342                  'if': { 'all': [ 'TEST_IF_COND_1',
343                                   'TEST_IF_COND_2'] } } ] }
344
345{ 'event': 'TEST_EVENT_FEATURES0',
346  'data': 'FeatureStruct1' }
347
348{ 'event': 'TEST_EVENT_FEATURES1',
349  'features': [ 'deprecated' ] }
350