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 }
152 # Returning a non-dictionary requires a name from the whitelist
153 { 'command': 'guest-get-time', 'data': {'a': 'int', '*b': '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' }
160 # Smoke test on out-of-band and allow-preconfig-test
161 { 'command': 'test-flags-command', 'allow-oob': true, 'allow-preconfig': true }
163 # For testing integer range flattening in opts-visitor. The following schema
164 # corresponds to the option format:
166 # -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12
168 # For simplicity, this example doesn't use [type=]discriminator nor optargs
169 # specific to discriminator values.
170 { 'struct': 'UserDefOptions',
173 '*u64' : [ 'uint64' ],
174 '*u16' : [ 'uint16' ],
176 '*u64x': 'uint64' } }
179 { 'struct': 'EventStructOne',
180 'data': { 'struct1': {'type': 'UserDefOne'}, 'string': 'str', '*enum2': 'EnumOne' } }
182 { 'event': 'EVENT_A' }
183 { 'event': 'EVENT_B',
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' }
193 # test that we correctly compile downstream extensions, as well as munge
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' }
216 # test 'if' condition handling
218 { 'struct': 'TestIfStruct', 'data':
220 'bar': { 'type': 'int', 'if': 'defined(TEST_IF_STRUCT_BAR)'} },
221 'if': 'defined(TEST_IF_STRUCT)' }
223 { 'enum': 'TestIfEnum', 'data':
224 [ 'foo', { 'name' : 'bar', 'if': 'defined(TEST_IF_ENUM_BAR)' } ],
225 'if': 'defined(TEST_IF_ENUM)' }
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)' }
232 { 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' },
233 'if': 'defined(TEST_IF_UNION)' }
235 { 'alternate': 'TestIfAlternate', 'data':
237 'bar': { 'type': 'TestStruct', 'if': 'defined(TEST_IF_ALT_BAR)'} },
238 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' }
240 { 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlternate' },
241 'if': 'defined(TEST_IF_ALT)' }
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)'] }
249 { 'command': 'TestCmdReturnDefThree', 'returns': 'UserDefThree' }
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)' }
258 { 'struct': 'FeatureStruct0',
259 'data': { 'foo': 'int' },
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' ] }
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)'] } ] }
286 { 'enum': 'FeatureEnum1',
287 'data': [ 'eins', 'zwei', 'drei' ],
288 'features': [ 'feature1' ] }
290 { 'union': 'FeatureUnion1',
291 'base': { 'tag': 'FeatureEnum1' },
292 'discriminator': 'tag',
293 'data': { 'eins': 'FeatureStruct1' },
294 'features': [ 'feature1' ] }
296 { 'alternate': 'FeatureAlternate1',
297 'data': { 'eins': 'FeatureStruct1' },
298 'features': [ 'feature1' ] }
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' },
311 { 'command': 'test-command-features1',
312 'features': [ 'deprecated' ] }
313 { 'command': 'test-command-features3',
314 'features': [ 'feature1', 'feature2' ] }
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)'] } ] }
325 { 'event': 'TEST-EVENT-FEATURES1',
326 'features': [ 'deprecated' ] }