]> git.proxmox.com Git - mirror_qemu.git/blame - tests/qapi-schema/qapi-schema-test.json
tests/qapi-schema: Test for good feature lists in structs
[mirror_qemu.git] / tests / qapi-schema / qapi-schema-test.json
CommitLineData
501e5104
MR
1# *-*- Mode: Python -*-*
2
625b251c
EB
3# This file is a stress test of supported qapi constructs that must
4# parse and compile correctly.
5
1554a8fa
MA
6# Whitelists to permit QAPI rule violations
7{ 'pragma': {
8 # Commands allowed to return a non-dictionary:
9 'returns-whitelist': [
10 'guest-get-time',
11 'guest-sync' ] } }
12
748053c9 13{ 'struct': 'TestStruct',
87adbbff 14 'data': { 'integer': {'type': 'int'}, 'boolean': 'bool', 'string': 'str' } }
748053c9 15
501e5104 16# for testing enums
895a2a80 17{ 'struct': 'NestedEnumsOne',
70478cef
EB
18 'data': { 'enum1': 'EnumOne', # Intentional forward reference
19 '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } }
501e5104 20
625b251c
EB
21# An empty enum, although unusual, is currently acceptable
22{ 'enum': 'MyEnum', 'data': [ ] }
23
19767083
EB
24# Likewise for an empty struct, including an empty base
25{ 'struct': 'Empty1', 'data': { } }
26{ 'struct': 'Empty2', 'base': 'Empty1', 'data': { } }
27
972a1101
EB
28{ 'command': 'user_def_cmd0', 'data': 'Empty2', 'returns': 'Empty2' }
29
351d36e4
DB
30# for testing override of default naming heuristic
31{ 'enum': 'QEnumTwo',
32 'prefix': 'QENUM_TWO',
33 'data': [ 'value1', 'value2' ] }
34
501e5104 35# for testing nested structs
895a2a80 36{ 'struct': 'UserDefOne',
8c3f8e77 37 'base': 'UserDefZero', # intentional forward reference
70478cef
EB
38 'data': { 'string': 'str',
39 '*enum1': 'EnumOne' } } # intentional forward reference
40
41{ 'enum': 'EnumOne',
800877bb 42 'data': [ 'value1', 'value2', 'value3', 'value4' ] }
501e5104 43
8c3f8e77
MA
44{ 'struct': 'UserDefZero',
45 'data': { 'integer': 'int' } }
46
6446a592
EB
47{ 'struct': 'UserDefTwoDictDict',
48 'data': { 'userdef': 'UserDefOne', 'string': 'str' } }
49
50{ 'struct': 'UserDefTwoDict',
51 'data': { 'string1': 'str',
52 'dict2': 'UserDefTwoDictDict',
53 '*dict3': 'UserDefTwoDictDict' } }
54
895a2a80 55{ 'struct': 'UserDefTwo',
f294f82a 56 'data': { 'string0': 'str',
6446a592 57 'dict1': 'UserDefTwoDict' } }
f294f82a 58
967c8851
MAL
59{ 'struct': 'UserDefThree',
60 'data': { 'string0': 'str' } }
61
9f08c8ec
EB
62# dummy struct to force generation of array types not otherwise mentioned
63{ 'struct': 'ForceArrays',
748053c9
EB
64 'data': { 'unused1':['UserDefOne'], 'unused2':['UserDefTwo'],
65 'unused3':['TestStruct'] } }
9f08c8ec 66
dc8fb6df 67# for testing unions
d220fbcd
EB
68# Among other things, test that a name collision between branches does
69# not cause any problems (since only one branch can be in use at a time),
70# by intentionally using two branches that both have a C member 'a_b'
895a2a80 71{ 'struct': 'UserDefA',
d220fbcd 72 'data': { 'boolean': 'bool', '*a_b': 'int' } }
dc8fb6df 73
895a2a80 74{ 'struct': 'UserDefB',
d220fbcd 75 'data': { 'intb': 'int', '*a-b': 'bool' } }
dc8fb6df 76
2fc00432 77{ 'union': 'UserDefFlatUnion',
8c3f8e77 78 'base': 'UserDefUnionBase', # intentional forward reference
5223070c 79 'discriminator': 'enum1',
87adbbff 80 'data': { 'value1' : {'type': 'UserDefA'},
8c3f8e77 81 'value2' : 'UserDefB',
800877bb
AN
82 'value3' : 'UserDefB'
83 # 'value4' defaults to empty
84 } }
2fc00432 85
8c3f8e77 86{ 'struct': 'UserDefUnionBase',
80e60a19 87 'base': 'UserDefZero',
8c3f8e77
MA
88 'data': { 'string': 'str', 'enum1': 'EnumOne' } }
89
14f00c6c 90# this variant of UserDefFlatUnion defaults to a union that uses members with
cb55111b
MR
91# allocated types to test corner cases in the cleanup/dealloc visitor
92{ 'union': 'UserDefFlatUnion2',
ac4338f8 93 'base': { '*integer': 'int', 'string': 'str', 'enum1': 'QEnumTwo' },
cb55111b 94 'discriminator': 'enum1',
8c3f8e77 95 'data': { 'value1' : 'UserDefC', # intentional forward reference
9d3524b3 96 'value2' : 'UserDefB' } }
cb55111b 97
68d07839
EB
98{ 'struct': 'WrapAlternate',
99 'data': { 'alt': 'UserDefAlternate' } }
ab916fad 100{ 'alternate': 'UserDefAlternate',
87adbbff 101 'data': { 'udfu': {'type': 'UserDefFlatUnion'}, 'e': 'EnumOne', 'i': 'int',
4d2d5c41 102 'n': 'null' } }
2c38b600 103
8c3f8e77
MA
104{ 'struct': 'UserDefC',
105 'data': { 'string1': 'str', 'string2': 'str' } }
106
9c51b441 107# for testing use of 'number' within alternates
8168ca8e
MA
108{ 'alternate': 'AltEnumBool', 'data': { 'e': 'EnumOne', 'b': 'bool' } }
109{ 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } }
8168ca8e
MA
110{ 'alternate': 'AltNumEnum', 'data': { 'n': 'number', 'e': 'EnumOne' } }
111{ 'alternate': 'AltEnumInt', 'data': { 'e': 'EnumOne', 'i': 'int' } }
9c51b441 112
c0644771
MA
113# for testing use of 'str' within alternates
114{ 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } }
115
b359f4b2
MA
116# for testing lists
117{ 'union': 'UserDefListUnion',
83c84667
MR
118 'data': { 'integer': ['int'],
119 's8': ['int8'],
120 's16': ['int16'],
121 's32': ['int32'],
122 's64': ['int64'],
123 'u8': ['uint8'],
124 'u16': ['uint16'],
125 'u32': ['uint32'],
126 'u64': ['uint64'],
127 'number': ['number'],
128 'boolean': ['bool'],
cb17f79e 129 'string': ['str'],
28770e05 130 'sizes': ['size'],
5e12eb98
MA
131 'any': ['any'],
132 'user': ['Status'] } } # intentional forward ref. to sub-module
83c84667 133
709395f8
MA
134# for testing sub-modules
135{ 'include': 'include/sub-module.json' }
136
501e5104
MR
137# testing commands
138{ 'command': 'user_def_cmd', 'data': {} }
139{ 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} }
ab22ad96 140{ 'command': 'user_def_cmd2',
87adbbff 141 'data': {'ud1a': {'type': 'UserDefOne'}, '*ud1b': 'UserDefOne'},
ab22ad96 142 'returns': 'UserDefTwo' }
cae95eae 143
ae6bf766
MAL
144{ 'command': 'cmd-success-response', 'data': {}, 'success-response': false }
145
cae95eae
EB
146# Returning a non-dictionary requires a name from the whitelist
147{ 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' },
c2216a8a 148 'returns': 'int' }
28770e05 149{ 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' }
c818408e 150{ 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' }
b359f4b2 151{ 'command': 'boxed-union', 'data': 'UserDefListUnion', 'boxed': true }
3953e3a5 152
c0698212 153# Smoke test on out-of-band and allow-preconfig-test
7b13f2c2 154{ 'command': 'test-flags-command', 'allow-oob': true, 'allow-preconfig': true }
1a1b11dc 155
3953e3a5
LE
156# For testing integer range flattening in opts-visitor. The following schema
157# corresponds to the option format:
158#
159# -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12
160#
161# For simplicity, this example doesn't use [type=]discriminator nor optargs
162# specific to discriminator values.
895a2a80 163{ 'struct': 'UserDefOptions',
3953e3a5
LE
164 'data': {
165 '*i64' : [ 'int' ],
166 '*u64' : [ 'uint64' ],
167 '*u16' : [ 'uint16' ],
168 '*i64x': 'int' ,
169 '*u64x': 'uint64' } }
f6dadb02
WX
170
171# testing event
895a2a80 172{ 'struct': 'EventStructOne',
87adbbff 173 'data': { 'struct1': {'type': 'UserDefOne'}, 'string': 'str', '*enum2': 'EnumOne' } }
f6dadb02
WX
174
175{ 'event': 'EVENT_A' }
176{ 'event': 'EVENT_B',
177 'data': { } }
178{ 'event': 'EVENT_C',
179 'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
180{ 'event': 'EVENT_D',
181 'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } }
c818408e
EB
182{ 'event': 'EVENT_E', 'boxed': true, 'data': 'UserDefZero' }
183{ 'event': 'EVENT_F', 'boxed': true, 'data': 'UserDefAlternate' }
fce384b8 184
c43567c1
EB
185# test that we correctly compile downstream extensions, as well as munge
186# ticklish names
fce384b8 187{ 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
83a02706
EB
188{ 'struct': '__org.qemu_x-Base',
189 'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
190{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
c43567c1 191 'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } }
bb337290 192{ 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }
857af5f0
EB
193{ 'struct': '__org.qemu_x-Struct2',
194 'data': { 'array': ['__org.qemu_x-Union1'] } }
195{ 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base',
196 'discriminator': '__org.qemu_x-member1',
197 'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
d1f07c86
EB
198{ 'alternate': '__org.qemu_x-Alt',
199 'data': { '__org.qemu_x-branch': 'str', 'b': '__org.qemu_x-Base' } }
e3c4c3d7
EB
200{ 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
201{ 'command': '__org.qemu_x-command',
202 'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'],
203 'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' },
204 'returns': '__org.qemu_x-Union1' }
967c8851
MAL
205
206# test 'if' condition handling
207
ccadd6bc
MAL
208{ 'struct': 'TestIfStruct', 'data':
209 { 'foo': 'int',
210 'bar': { 'type': 'int', 'if': 'defined(TEST_IF_STRUCT_BAR)'} },
967c8851
MAL
211 'if': 'defined(TEST_IF_STRUCT)' }
212
6cc32b0e
MAL
213{ 'enum': 'TestIfEnum', 'data':
214 [ 'foo', { 'name' : 'bar', 'if': 'defined(TEST_IF_ENUM_BAR)' } ],
967c8851
MAL
215 'if': 'defined(TEST_IF_ENUM)' }
216
a2724280
MAL
217{ 'union': 'TestIfUnion', 'data':
218 { 'foo': 'TestStruct',
219 'union_bar': { 'type': 'str', 'if': 'defined(TEST_IF_UNION_BAR)'} },
967c8851
MAL
220 'if': 'defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)' }
221
f8c4fdd6
MAL
222{ 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' },
223 'if': 'defined(TEST_IF_UNION)' }
224
3e270dca
MAL
225{ 'alternate': 'TestIfAlternate', 'data':
226 { 'foo': 'int',
227 'bar': { 'type': 'TestStruct', 'if': 'defined(TEST_IF_ALT_BAR)'} },
967c8851
MAL
228 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' }
229
f8c4fdd6
MAL
230{ 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlternate' },
231 'if': 'defined(TEST_IF_ALT)' }
232
ccadd6bc
MAL
233{ 'command': 'TestIfCmd', 'data':
234 { 'foo': 'TestIfStruct',
235 'bar': { 'type': 'TestIfEnum', 'if': 'defined(TEST_IF_CMD_BAR)' } },
967c8851
MAL
236 'returns': 'UserDefThree',
237 'if': ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] }
238
239{ 'command': 'TestCmdReturnDefThree', 'returns': 'UserDefThree' }
240
ccadd6bc
MAL
241{ 'event': 'TestIfEvent', 'data':
242 { 'foo': 'TestIfStruct',
0f20628b 243 'bar': { 'type': ['TestIfEnum'], 'if': 'defined(TEST_IF_EVT_BAR)' } },
967c8851 244 'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' }
8aa3a33e
KW
245
246# test 'features' for structs
247
248{ 'struct': 'FeatureStruct0',
249 'data': { 'foo': 'int' },
250 'features': [] }
251{ 'struct': 'FeatureStruct1',
252 'data': { 'foo': 'int' },
253 'features': [ 'feature1' ] }
254{ 'struct': 'FeatureStruct2',
255 'data': { 'foo': 'int' },
256 'features': [ { 'name': 'feature1' } ] }
257{ 'struct': 'FeatureStruct3',
258 'data': { 'foo': 'int' },
259 'features': [ 'feature1', 'feature2' ] }
260{ 'struct': 'FeatureStruct4',
261 'data': { 'namespace-test': 'int' },
262 'features': [ 'namespace-test', 'int', 'name', 'if' ] }
263
264{ 'struct': 'CondFeatureStruct1',
265 'data': { 'foo': 'int' },
266 'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'} ] }
267{ 'struct': 'CondFeatureStruct2',
268 'data': { 'foo': 'int' },
269 'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'},
270 { 'name': 'feature2', 'if': 'defined(TEST_IF_FEATURE_2)'} ] }
271{ 'struct': 'CondFeatureStruct3',
272 'data': { 'foo': 'int' },
273 'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)',
274 'defined(TEST_IF_COND_2)'] } ] }
275{ 'command': 'test-features',
276 'data': { 'fs0': 'FeatureStruct0',
277 'fs1': 'FeatureStruct1',
278 'fs2': 'FeatureStruct2',
279 'fs3': 'FeatureStruct3',
280 'fs4': 'FeatureStruct4',
281 'cfs1': 'CondFeatureStruct1',
282 'cfs2': 'CondFeatureStruct2',
283 'cfs3': 'CondFeatureStruct3' } }