1 # *-*- Mode: Python -*-*
4 # This file is a stress test of supported qapi constructs that must
5 # parse and compile correctly.
7 # Whitelists to permit QAPI rule violations
9 # Commands allowed to return a non-dictionary:
10 'returns-whitelist': [
14 { 'struct': 'TestStruct',
15 'data': { 'integer': {'type': 'int'}, 'boolean': 'bool', 'string': 'str' } }
18 { 'struct': 'NestedEnumsOne',
19 'data': { 'enum1': 'EnumOne', # Intentional forward reference
20 '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } }
22 # An empty enum, although unusual, is currently acceptable
23 { 'enum': 'MyEnum', 'data': [ ] }
25 # Likewise for an empty struct, including an empty base
26 { 'struct': 'Empty1', 'data': { } }
27 { 'struct': 'Empty2', 'base': 'Empty1', 'data': { } }
29 # Likewise for an empty flat union
31 'base': { 'type': 'EnumOne' }, 'discriminator': 'type',
34 { 'command': 'user_def_cmd0', 'data': 'Empty2', 'returns': 'Empty2' }
36 # for testing override of default naming heuristic
38 'prefix': 'QENUM_TWO',
39 'data': [ 'value1', 'value2' ] }
41 # for testing nested structs
42 { 'struct': 'UserDefOne',
43 'base': 'UserDefZero', # intentional forward reference
44 'data': { 'string': 'str',
45 '*enum1': 'EnumOne' } } # intentional forward reference
48 'data': [ 'value1', 'value2', 'value3', 'value4' ] }
50 { 'struct': 'UserDefZero',
51 'data': { 'integer': 'int' } }
53 { 'struct': 'UserDefTwoDictDict',
54 'data': { 'userdef': 'UserDefOne', 'string': 'str' } }
56 { 'struct': 'UserDefTwoDict',
57 'data': { 'string1': 'str',
58 'dict2': 'UserDefTwoDictDict',
59 '*dict3': 'UserDefTwoDictDict' } }
61 { 'struct': 'UserDefTwo',
62 'data': { 'string0': 'str',
63 'dict1': 'UserDefTwoDict' } }
65 { 'struct': 'UserDefThree',
66 'data': { 'string0': 'str' } }
68 # dummy struct to force generation of array types not otherwise mentioned
69 { 'struct': 'ForceArrays',
70 'data': { 'unused1':['UserDefOne'], 'unused2':['UserDefTwo'],
71 'unused3':['TestStruct'] } }
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' } }
80 { 'struct': 'UserDefB',
81 'data': { 'intb': 'int', '*a-b': 'bool' } }
83 { 'union': 'UserDefFlatUnion',
84 'base': 'UserDefUnionBase', # intentional forward reference
85 'discriminator': 'enum1',
86 'data': { 'value1' : {'type': 'UserDefA'},
87 'value2' : 'UserDefB',
89 # 'value4' defaults to empty
92 { 'struct': 'UserDefUnionBase',
93 'base': 'UserDefZero',
94 'data': { 'string': 'str', 'enum1': 'EnumOne' } }
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' } }
104 { 'struct': 'WrapAlternate',
105 'data': { 'alt': 'UserDefAlternate' } }
106 { 'alternate': 'UserDefAlternate',
107 'data': { 'udfu': {'type': 'UserDefFlatUnion'}, 'e': 'EnumOne', 'i': 'int',
110 { 'struct': 'UserDefC',
111 'data': { 'string1': 'str', 'string2': 'str' } }
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' } }
119 # for testing use of 'str' within alternates
120 { 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } }
123 { 'union': 'UserDefListUnion',
124 'data': { 'integer': ['int'],
133 'number': ['number'],
138 'user': ['Status'] } } # intentional forward ref. to sub-module
140 # for testing sub-modules
141 { 'include': 'include/sub-module.json' }
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' }
150 { 'command': 'cmd-success-response', 'data': {}, 'success-response': false }
151 { 'command': 'coroutine-cmd', 'data': {}, 'coroutine': true }
153 # Returning a non-dictionary requires a name from the whitelist
154 { 'command': 'guest-get-time', 'data': {'a': 'int', '*b': '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' }
161 # Smoke test on out-of-band and allow-preconfig-test
162 { 'command': 'test-flags-command', 'allow-oob': true, 'allow-preconfig': true }
164 # For testing integer range flattening in opts-visitor. The following schema
165 # corresponds to the option format:
167 # -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12
169 # For simplicity, this example doesn't use [type=]discriminator nor optargs
170 # specific to discriminator values.
171 { 'struct': 'UserDefOptions',
174 '*u64' : [ 'uint64' ],
175 '*u16' : [ 'uint16' ],
177 '*u64x': 'uint64' } }
180 { 'struct': 'EventStructOne',
181 'data': { 'struct1': {'type': 'UserDefOne'}, 'string': 'str', '*enum2': 'EnumOne' } }
183 { 'event': 'EVENT_A' }
184 { 'event': 'EVENT_B',
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' }
194 # test that we correctly compile downstream extensions, as well as munge
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' }
217 # test 'if' condition handling
219 { 'struct': 'TestIfStruct', 'data':
221 'bar': { 'type': 'int', 'if': 'defined(TEST_IF_STRUCT_BAR)'} },
222 'if': 'defined(TEST_IF_STRUCT)' }
224 { 'enum': 'TestIfEnum', 'data':
225 [ 'foo', { 'name' : 'bar', 'if': 'defined(TEST_IF_ENUM_BAR)' } ],
226 'if': 'defined(TEST_IF_ENUM)' }
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)' }
233 { 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' },
234 'if': 'defined(TEST_IF_UNION)' }
236 { 'alternate': 'TestIfAlternate', 'data':
238 'bar': { 'type': 'TestStruct', 'if': 'defined(TEST_IF_ALT_BAR)'} },
239 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' }
241 { 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlternate' },
242 'if': 'defined(TEST_IF_ALT)' }
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)'] }
250 { 'command': 'TestCmdReturnDefThree', 'returns': 'UserDefThree' }
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)' }
259 { 'struct': 'FeatureStruct0',
260 'data': { 'foo': 'int' },
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' ] }
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)'] } ] }
287 { 'enum': 'FeatureEnum1',
288 'data': [ 'eins', 'zwei', 'drei' ],
289 'features': [ 'feature1' ] }
291 { 'union': 'FeatureUnion1',
292 'base': { 'tag': 'FeatureEnum1' },
293 'discriminator': 'tag',
294 'data': { 'eins': 'FeatureStruct1' },
295 'features': [ 'feature1' ] }
297 { 'alternate': 'FeatureAlternate1',
298 'data': { 'eins': 'FeatureStruct1' },
299 'features': [ 'feature1' ] }
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' },
312 { 'command': 'test-command-features1',
313 'features': [ 'deprecated' ] }
314 { 'command': 'test-command-features3',
315 'features': [ 'feature1', 'feature2' ] }
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)'] } ] }
326 { 'event': 'TEST-EVENT-FEATURES1',
327 'features': [ 'deprecated' ] }