xref: /openbmc/qemu/tests/qapi-schema/qapi-schema-test.json (revision 05ebf841efac494d8bd1f6d74642c3e9a3df4c19)
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    'command-returns-exceptions': [
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': 'test-if-union-cmd',
234  'data': { 'union_cmd_arg': 'TestIfUnion' },
235  'if': 'defined(TEST_IF_UNION)' }
236
237{ 'alternate': 'TestIfAlternate', 'data':
238  { 'foo': 'int',
239    'bar': { 'type': 'TestStruct', 'if': 'defined(TEST_IF_ALT_BAR)'} },
240  'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' }
241
242{ 'command': 'test-if-alternate-cmd',
243  'data': { 'alt_cmd_arg': 'TestIfAlternate' },
244  'if': 'defined(TEST_IF_ALT)' }
245
246{ 'command': 'test-if-cmd',
247  'data': {
248    'foo': 'TestIfStruct',
249    'bar': { 'type': 'TestIfEnum', 'if': 'defined(TEST_IF_CMD_BAR)' } },
250  'returns': 'UserDefThree',
251  'if': ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] }
252
253{ 'command': 'test-cmd-return-def-three', 'returns': 'UserDefThree' }
254
255{ 'event': 'TEST_IF_EVENT', 'data':
256  { 'foo': 'TestIfStruct',
257    'bar': { 'type': ['TestIfEnum'], 'if': 'defined(TEST_IF_EVT_BAR)' } },
258  'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' }
259
260# test 'features'
261
262{ 'struct': 'FeatureStruct0',
263  'data': { 'foo': 'int' },
264  'features': [] }
265{ 'struct': 'FeatureStruct1',
266  'data': { 'foo': { 'type': 'int', 'features': [ 'deprecated' ] } },
267  'features': [ 'feature1' ] }
268{ 'struct': 'FeatureStruct2',
269  'data': { 'foo': 'int' },
270  'features': [ { 'name': 'feature1' } ] }
271{ 'struct': 'FeatureStruct3',
272  'data': { 'foo': 'int' },
273  'features': [ 'feature1', 'feature2' ] }
274{ 'struct': 'FeatureStruct4',
275  'data': { 'namespace-test': 'int' },
276  'features': [ 'namespace-test', 'int', 'name', 'if' ] }
277
278{ 'struct': 'CondFeatureStruct1',
279  'data': { 'foo': 'int' },
280  'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'} ] }
281{ 'struct': 'CondFeatureStruct2',
282  'data': { 'foo': 'int' },
283  'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'},
284                { 'name': 'feature2', 'if': 'defined(TEST_IF_FEATURE_2)'} ] }
285{ 'struct': 'CondFeatureStruct3',
286  'data': { 'foo': 'int' },
287  'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)',
288                                              'defined(TEST_IF_COND_2)'] } ] }
289
290{ 'enum': 'FeatureEnum1',
291  'data': [ 'eins', 'zwei', 'drei' ],
292  'features': [ 'feature1' ] }
293
294{ 'union': 'FeatureUnion1',
295  'base': { 'tag': 'FeatureEnum1' },
296  'discriminator': 'tag',
297  'data': { 'eins': 'FeatureStruct1' },
298  'features': [ 'feature1' ] }
299
300{ 'alternate': 'FeatureAlternate1',
301  'data': { 'eins': 'FeatureStruct1' },
302  'features': [ 'feature1' ] }
303
304{ 'command': 'test-features0',
305  'data': { '*fs0': 'FeatureStruct0',
306            '*fs1': 'FeatureStruct1',
307            '*fs2': 'FeatureStruct2',
308            '*fs3': 'FeatureStruct3',
309            '*fs4': 'FeatureStruct4',
310            '*cfs1': 'CondFeatureStruct1',
311            '*cfs2': 'CondFeatureStruct2',
312            '*cfs3': 'CondFeatureStruct3' },
313  'returns': 'FeatureStruct1',
314  'features': [] }
315
316{ 'command': 'test-command-features1',
317  'features': [ 'deprecated' ] }
318{ 'command': 'test-command-features3',
319  'features': [ 'feature1', 'feature2' ] }
320
321{ 'command': 'test-command-cond-features1',
322  'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'} ] }
323{ 'command': 'test-command-cond-features2',
324  'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'},
325                { 'name': 'feature2', 'if': 'defined(TEST_IF_FEATURE_2)'} ] }
326{ 'command': 'test-command-cond-features3',
327  'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)',
328                                              'defined(TEST_IF_COND_2)'] } ] }
329
330{ 'event': 'TEST_EVENT_FEATURES0',
331  'data': 'FeatureStruct1' }
332
333{ 'event': 'TEST_EVENT_FEATURES1',
334  'features': [ 'deprecated' ] }
335