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
152# Returning a non-dictionary requires a name from the whitelist
153{ 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' },
154  'returns': 'int' }
155{ 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' }
156{ 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' }
157{ 'command': 'boxed-union', 'data': 'UserDefListUnion', 'boxed': true }
158{ 'command': 'boxed-empty', 'boxed': true, 'data': 'Empty1' }
159
160# Smoke test on out-of-band and allow-preconfig-test
161{ 'command': 'test-flags-command', 'allow-oob': true, 'allow-preconfig': true }
162
163# For testing integer range flattening in opts-visitor. The following schema
164# corresponds to the option format:
165#
166# -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12
167#
168# For simplicity, this example doesn't use [type=]discriminator nor optargs
169# specific to discriminator values.
170{ 'struct': 'UserDefOptions',
171  'data': {
172    '*i64' : [ 'int'    ],
173    '*u64' : [ 'uint64' ],
174    '*u16' : [ 'uint16' ],
175    '*i64x':   'int'     ,
176    '*u64x':   'uint64'  } }
177
178# testing event
179{ 'struct': 'EventStructOne',
180  'data': { 'struct1': {'type': 'UserDefOne'}, 'string': 'str', '*enum2': 'EnumOne' } }
181
182{ 'event': 'EVENT_A' }
183{ 'event': 'EVENT_B',
184  'data': { } }
185{ 'event': 'EVENT_C',
186  'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
187{ 'event': 'EVENT_D',
188  'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } }
189{ 'event': 'EVENT_E', 'boxed': true, 'data': 'UserDefZero' }
190{ 'event': 'EVENT_F', 'boxed': true, 'data': 'UserDefFlatUnion' }
191{ 'event': 'EVENT_G', 'boxed': true, 'data': 'Empty1' }
192
193# test that we correctly compile downstream extensions, as well as munge
194# ticklish names
195# also test union and alternate with just one branch
196{ 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
197{ 'struct': '__org.qemu_x-Base',
198  'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
199{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
200  'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } }
201{ 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }
202{ 'alternate': '__org.qemu_x-Alt1', 'data': { '__org.qemu_x-branch': 'str' } }
203{ 'struct': '__org.qemu_x-Struct2',
204  'data': { 'array': ['__org.qemu_x-Union1'] } }
205{ 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base',
206  'discriminator': '__org.qemu_x-member1',
207  'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
208{ 'alternate': '__org.qemu_x-Alt',
209  'data': { '__org.qemu_x-branch': '__org.qemu_x-Base' } }
210{ 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
211{ 'command': '__org.qemu_x-command',
212  'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'],
213            'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' },
214  'returns': '__org.qemu_x-Union1' }
215
216# test 'if' condition handling
217
218{ 'struct': 'TestIfStruct', 'data':
219  { 'foo': 'int',
220    'bar': { 'type': 'int', 'if': 'defined(TEST_IF_STRUCT_BAR)'} },
221  'if': 'defined(TEST_IF_STRUCT)' }
222
223{ 'enum': 'TestIfEnum', 'data':
224  [ 'foo', { 'name' : 'bar', 'if': 'defined(TEST_IF_ENUM_BAR)' } ],
225  'if': 'defined(TEST_IF_ENUM)' }
226
227{ 'union': 'TestIfUnion', 'data':
228  { 'foo': 'TestStruct',
229    'union_bar': { 'type': 'str', 'if': 'defined(TEST_IF_UNION_BAR)'} },
230  'if': 'defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)' }
231
232{ 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' },
233  'if': 'defined(TEST_IF_UNION)' }
234
235{ 'alternate': 'TestIfAlternate', 'data':
236  { 'foo': 'int',
237    'bar': { 'type': 'TestStruct', 'if': 'defined(TEST_IF_ALT_BAR)'} },
238  'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' }
239
240{ 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlternate' },
241  'if': 'defined(TEST_IF_ALT)' }
242
243{ 'command': 'TestIfCmd', 'data':
244  { 'foo': 'TestIfStruct',
245    'bar': { 'type': 'TestIfEnum', 'if': 'defined(TEST_IF_CMD_BAR)' } },
246  'returns': 'UserDefThree',
247  'if': ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] }
248
249{ 'command': 'TestCmdReturnDefThree', 'returns': 'UserDefThree' }
250
251{ 'event': 'TestIfEvent', 'data':
252  { 'foo': 'TestIfStruct',
253    'bar': { 'type': ['TestIfEnum'], 'if': 'defined(TEST_IF_EVT_BAR)' } },
254  'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' }
255
256# test 'features'
257
258{ 'struct': 'FeatureStruct0',
259  'data': { 'foo': 'int' },
260  'features': [] }
261{ 'struct': 'FeatureStruct1',
262  'data': { 'foo': { 'type': 'int', 'features': [ 'deprecated' ] } },
263  'features': [ 'feature1' ] }
264{ 'struct': 'FeatureStruct2',
265  'data': { 'foo': 'int' },
266  'features': [ { 'name': 'feature1' } ] }
267{ 'struct': 'FeatureStruct3',
268  'data': { 'foo': 'int' },
269  'features': [ 'feature1', 'feature2' ] }
270{ 'struct': 'FeatureStruct4',
271  'data': { 'namespace-test': 'int' },
272  'features': [ 'namespace-test', 'int', 'name', 'if' ] }
273
274{ 'struct': 'CondFeatureStruct1',
275  'data': { 'foo': 'int' },
276  'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'} ] }
277{ 'struct': 'CondFeatureStruct2',
278  'data': { 'foo': 'int' },
279  'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'},
280                { 'name': 'feature2', 'if': 'defined(TEST_IF_FEATURE_2)'} ] }
281{ 'struct': 'CondFeatureStruct3',
282  'data': { 'foo': 'int' },
283  'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)',
284                                              'defined(TEST_IF_COND_2)'] } ] }
285
286{ 'enum': 'FeatureEnum1',
287  'data': [ 'eins', 'zwei', 'drei' ],
288  'features': [ 'feature1' ] }
289
290{ 'union': 'FeatureUnion1',
291  'base': { 'tag': 'FeatureEnum1' },
292  'discriminator': 'tag',
293  'data': { 'eins': 'FeatureStruct1' },
294  'features': [ 'feature1' ] }
295
296{ 'alternate': 'FeatureAlternate1',
297  'data': { 'eins': 'FeatureStruct1' },
298  'features': [ 'feature1' ] }
299
300{ 'command': 'test-features0',
301  'data': { 'fs0': 'FeatureStruct0',
302            'fs1': 'FeatureStruct1',
303            'fs2': 'FeatureStruct2',
304            'fs3': 'FeatureStruct3',
305            'fs4': 'FeatureStruct4',
306            'cfs1': 'CondFeatureStruct1',
307            'cfs2': 'CondFeatureStruct2',
308            'cfs3': 'CondFeatureStruct3' },
309  'features': [] }
310
311{ 'command': 'test-command-features1',
312  'features': [ 'deprecated' ] }
313{ 'command': 'test-command-features3',
314  'features': [ 'feature1', 'feature2' ] }
315
316{ 'command': 'test-command-cond-features1',
317  'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'} ] }
318{ 'command': 'test-command-cond-features2',
319  'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'},
320                { 'name': 'feature2', 'if': 'defined(TEST_IF_FEATURE_2)'} ] }
321{ 'command': 'test-command-cond-features3',
322  'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)',
323                                              'defined(TEST_IF_COND_2)'] } ] }
324
325{ 'event': 'TEST-EVENT-FEATURES1',
326  'features': [ 'deprecated' ] }
327