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