hw: ccid-card-emulated: cleanup resource when realize in error path
[qemu/ar7.git] / tests / qapi-schema / qapi-schema-test.json
blobfb0316343027ce7ad47d97c08a58e5572ce0e1ea
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
7 { 'pragma': {
8     # Commands allowed to return a non-dictionary:
9     'returns-whitelist': [
10         'guest-get-time',
11         'guest-sync' ] } }
13 { 'struct': 'TestStruct',
14   'data': { 'integer': 'int', 'boolean': 'bool', 'string': 'str' } }
16 # for testing enums
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 { 'command': 'user_def_cmd0', 'data': 'Empty2', 'returns': 'Empty2' }
30 # for testing override of default naming heuristic
31 { 'enum': 'QEnumTwo',
32   'prefix': 'QENUM_TWO',
33   'data': [ 'value1', 'value2' ] }
35 # for testing nested structs
36 { 'struct': 'UserDefOne',
37   'base': 'UserDefZero',        # intentional forward reference
38   'data': { 'string': 'str',
39             '*enum1': 'EnumOne' } }   # intentional forward reference
41 { 'enum': 'EnumOne',
42   'data': [ 'value1', 'value2', 'value3', 'value4' ] }
44 { 'struct': 'UserDefZero',
45   'data': { 'integer': 'int' } }
47 { 'struct': 'UserDefTwoDictDict',
48   'data': { 'userdef': 'UserDefOne', 'string': 'str' } }
50 { 'struct': 'UserDefTwoDict',
51   'data': { 'string1': 'str',
52             'dict2': 'UserDefTwoDictDict',
53             '*dict3': 'UserDefTwoDictDict' } }
55 { 'struct': 'UserDefTwo',
56   'data': { 'string0': 'str',
57             'dict1': 'UserDefTwoDict' } }
59 { 'struct': 'UserDefThree',
60   'data': { 'string0': 'str' } }
62 # dummy struct to force generation of array types not otherwise mentioned
63 { 'struct': 'ForceArrays',
64   'data': { 'unused1':['UserDefOne'], 'unused2':['UserDefTwo'],
65             'unused3':['TestStruct'] } }
67 # for testing unions
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'
71 { 'struct': 'UserDefA',
72   'data': { 'boolean': 'bool', '*a_b': 'int' } }
74 { 'struct': 'UserDefB',
75   'data': { 'intb': 'int', '*a-b': 'bool' } }
77 { 'union': 'UserDefFlatUnion',
78   'base': 'UserDefUnionBase',   # intentional forward reference
79   'discriminator': 'enum1',
80   'data': { 'value1' : 'UserDefA',
81             'value2' : 'UserDefB',
82             'value3' : 'UserDefB'
83             # 'value4' defaults to empty
84   } }
86 { 'struct': 'UserDefUnionBase',
87   'base': 'UserDefZero',
88   'data': { 'string': 'str', 'enum1': 'EnumOne' } }
90 # this variant of UserDefFlatUnion defaults to a union that uses members with
91 # allocated types to test corner cases in the cleanup/dealloc visitor
92 { 'union': 'UserDefFlatUnion2',
93   'base': { '*integer': 'int', 'string': 'str', 'enum1': 'QEnumTwo' },
94   'discriminator': 'enum1',
95   'data': { 'value1' : 'UserDefC', # intentional forward reference
96             'value2' : 'UserDefB' } }
98 { 'struct': 'WrapAlternate',
99   'data': { 'alt': 'UserDefAlternate' } }
100 { 'alternate': 'UserDefAlternate',
101   'data': { 'udfu': 'UserDefFlatUnion', 'e': 'EnumOne', 'i': 'int',
102             'n': 'null' } }
104 { 'struct': 'UserDefC',
105   'data': { 'string1': 'str', 'string2': 'str' } }
107 # for testing use of 'number' within alternates
108 { 'alternate': 'AltEnumBool', 'data': { 'e': 'EnumOne', 'b': 'bool' } }
109 { 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } }
110 { 'alternate': 'AltNumEnum', 'data': { 'n': 'number', 'e': 'EnumOne' } }
111 { 'alternate': 'AltEnumInt', 'data': { 'e': 'EnumOne', 'i': 'int' } }
113 # for testing use of 'str' within alternates
114 { 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } }
116 # for testing native lists
117 { 'union': 'UserDefNativeListUnion',
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'],
129             'string': ['str'],
130             'sizes': ['size'],
131             'any': ['any'] } }
133 # testing commands
134 { 'command': 'user_def_cmd', 'data': {} }
135 { 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} }
136 { 'command': 'user_def_cmd2',
137   'data': {'ud1a': 'UserDefOne', '*ud1b': 'UserDefOne'},
138   'returns': 'UserDefTwo' }
140 { 'command': 'cmd-success-response', 'data': {}, 'success-response': false }
142 # Returning a non-dictionary requires a name from the whitelist
143 { 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' },
144   'returns': 'int' }
145 { 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' }
146 { 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' }
147 { 'command': 'boxed-union', 'data': 'UserDefNativeListUnion', 'boxed': true }
149 # Smoke test on out-of-band and allow-preconfig-test
150 { 'command': 'test-flags-command', 'allow-oob': true, 'allow-preconfig': true }
152 # For testing integer range flattening in opts-visitor. The following schema
153 # corresponds to the option format:
155 # -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12
157 # For simplicity, this example doesn't use [type=]discriminator nor optargs
158 # specific to discriminator values.
159 { 'struct': 'UserDefOptions',
160   'data': {
161     '*i64' : [ 'int'    ],
162     '*u64' : [ 'uint64' ],
163     '*u16' : [ 'uint16' ],
164     '*i64x':   'int'     ,
165     '*u64x':   'uint64'  } }
167 # testing event
168 { 'struct': 'EventStructOne',
169   'data': { 'struct1': 'UserDefOne', 'string': 'str', '*enum2': 'EnumOne' } }
171 { 'event': 'EVENT_A' }
172 { 'event': 'EVENT_B',
173   'data': { } }
174 { 'event': 'EVENT_C',
175   'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
176 { 'event': 'EVENT_D',
177   'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } }
178 { 'event': 'EVENT_E', 'boxed': true, 'data': 'UserDefZero' }
179 { 'event': 'EVENT_F', 'boxed': true, 'data': 'UserDefAlternate' }
181 # test that we correctly compile downstream extensions, as well as munge
182 # ticklish names
183 { 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
184 { 'struct': '__org.qemu_x-Base',
185   'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
186 { 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
187   'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } }
188 { 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }
189 { 'struct': '__org.qemu_x-Struct2',
190   'data': { 'array': ['__org.qemu_x-Union1'] } }
191 { 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base',
192   'discriminator': '__org.qemu_x-member1',
193   'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
194 { 'alternate': '__org.qemu_x-Alt',
195   'data': { '__org.qemu_x-branch': 'str', 'b': '__org.qemu_x-Base' } }
196 { 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
197 { 'command': '__org.qemu_x-command',
198   'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'],
199             'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' },
200   'returns': '__org.qemu_x-Union1' }
202 # test 'if' condition handling
204 { 'struct': 'TestIfStruct', 'data': { 'foo': 'int' },
205   'if': 'defined(TEST_IF_STRUCT)' }
207 { 'enum': 'TestIfEnum', 'data': [ 'foo', 'bar' ],
208   'if': 'defined(TEST_IF_ENUM)' }
210 { 'union': 'TestIfUnion', 'data': { 'foo': 'TestStruct' },
211   'if': 'defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)' }
213 { 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStruct' },
214   'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' }
216 { 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct' },
217   'returns': 'UserDefThree',
218   'if': ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] }
220 { 'command': 'TestCmdReturnDefThree', 'returns': 'UserDefThree' }
222 { 'event': 'TestIfEvent', 'data': { 'foo': 'TestIfStruct' },
223   'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' }