| 1 | # *-*- Mode: Python -*-* |
| 2 | # vim: filetype=python |
| 3 | |
| 4 | # This file is a stress test of supported qapi constructs that must |
| 5 | # parse and compile correctly. |
| 6 | |
| 7 | # Whitelists to permit QAPI rule violations |
| 8 | { 'pragma': { |
| 9 | # Types whose member names may use '_' |
| 10 | 'member-name-exceptions': [ |
| 11 | 'UserDefA' |
| 12 | ], |
| 13 | # Commands allowed to return a non-dictionary: |
| 14 | 'command-returns-exceptions': [ |
| 15 | 'guest-get-time', |
| 16 | 'guest-sync' ] } } |
| 17 | |
| 18 | { 'struct': 'TestStruct', |
| 19 | 'data': { 'integer': {'type': 'int'}, 'boolean': 'bool', 'string': 'str' } } |
| 20 | |
| 21 | # for testing enums |
| 22 | { 'struct': 'NestedEnumsOne', |
| 23 | 'data': { 'enum1': 'EnumOne', # Intentional forward reference |
| 24 | '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } } |
| 25 | |
| 26 | # An empty enum, although unusual, is currently acceptable |
| 27 | { 'enum': 'MyEnum', 'data': [ ] } |
| 28 | |
| 29 | # Likewise for an empty struct, including an empty base |
| 30 | { 'struct': 'Empty1', 'data': { } } |
| 31 | { 'struct': 'Empty2', 'base': 'Empty1', 'data': { } } |
| 32 | |
| 33 | # Likewise for an empty union |
| 34 | { 'union': 'Union', |
| 35 | 'base': { 'type': 'EnumOne' }, 'discriminator': 'type', |
| 36 | 'data': { } } |
| 37 | |
| 38 | { 'command': 'user-def-cmd0', 'data': 'Empty2', 'returns': 'Empty2' } |
| 39 | |
| 40 | # for testing override of default naming heuristic |
| 41 | { 'enum': 'QEnumTwo', |
| 42 | 'prefix': 'QENUM_TWO', |
| 43 | 'data': [ 'value1', 'value2' ] } |
| 44 | |
| 45 | # for testing nested structs |
| 46 | { 'struct': 'UserDefOne', |
| 47 | 'base': 'UserDefZero', # intentional forward reference |
| 48 | 'data': { 'string': 'str', |
| 49 | '*enum1': 'EnumOne' } } # intentional forward reference |
| 50 | |
| 51 | { 'enum': 'EnumOne', |
| 52 | 'data': [ 'value1', 'value2', 'value3', 'value4' ] } |
| 53 | |
| 54 | { 'struct': 'UserDefZero', |
| 55 | 'data': { 'integer': 'int' } } |
| 56 | |
| 57 | { 'struct': 'UserDefTwoDictDict', |
| 58 | 'data': { 'userdef': 'UserDefOne', 'string': 'str' } } |
| 59 | |
| 60 | { 'struct': 'UserDefTwoDict', |
| 61 | 'data': { 'string1': 'str', |
| 62 | 'dict2': 'UserDefTwoDictDict', |
| 63 | '*dict3': 'UserDefTwoDictDict' } } |
| 64 | |
| 65 | { 'struct': 'UserDefTwo', |
| 66 | 'data': { 'string0': 'str', |
| 67 | 'dict1': 'UserDefTwoDict' } } |
| 68 | |
| 69 | { 'struct': 'UserDefThree', |
| 70 | 'data': { 'string0': 'str' } } |
| 71 | |
| 72 | # dummy struct to force generation of array types not otherwise mentioned |
| 73 | { 'struct': 'ForceArrays', |
| 74 | 'data': { 'unused1':['UserDefOne'], 'unused2':['UserDefTwo'], |
| 75 | 'unused3':['TestStruct'] } } |
| 76 | |
| 77 | # for testing unions |
| 78 | # Among other things, test that a name collision between branches does |
| 79 | # not cause any problems (since only one branch can be in use at a time), |
| 80 | # by intentionally using two branches that both have a C member 'a_b' |
| 81 | { 'struct': 'UserDefA', |
| 82 | 'data': { 'boolean': 'bool', '*a_b': 'int' } } |
| 83 | |
| 84 | { 'struct': 'UserDefB', |
| 85 | 'data': { 'intb': 'int', '*a-b': 'bool' } } |
| 86 | |
| 87 | { 'union': 'UserDefFlatUnion', |
| 88 | 'base': 'UserDefUnionBase', # intentional forward reference |
| 89 | 'discriminator': 'enum1', |
| 90 | 'data': { 'value1' : {'type': 'UserDefA'}, |
| 91 | 'value2' : 'UserDefB', |
| 92 | 'value3' : 'UserDefB' |
| 93 | # 'value4' defaults to empty |
| 94 | } } |
| 95 | |
| 96 | { 'struct': 'UserDefUnionBase', |
| 97 | 'base': 'UserDefZero', |
| 98 | 'data': { 'string': 'str', 'enum1': 'EnumOne' } } |
| 99 | |
| 100 | # this variant of UserDefFlatUnion defaults to a union that uses members with |
| 101 | # allocated types to test corner cases in the cleanup/dealloc visitor |
| 102 | { 'union': 'UserDefFlatUnion2', |
| 103 | 'base': { '*integer': 'int', 'string': 'str', 'enum1': 'QEnumTwo' }, |
| 104 | 'discriminator': 'enum1', |
| 105 | 'data': { 'value1' : 'UserDefC', # intentional forward reference |
| 106 | 'value2' : 'UserDefB' } } |
| 107 | |
| 108 | { 'struct': 'WrapAlternate', |
| 109 | 'data': { 'alt': 'UserDefAlternate' } } |
| 110 | { 'alternate': 'UserDefAlternate', |
| 111 | 'data': { 'udfu': {'type': 'UserDefFlatUnion'}, 'e': 'EnumOne', 'i': 'int', |
| 112 | 'n': 'null' } } |
| 113 | |
| 114 | { 'struct': 'UserDefC', |
| 115 | 'data': { 'string1': 'str', 'string2': 'str' } } |
| 116 | |
| 117 | # this tests that unions can contain other unions in their branches |
| 118 | { 'enum': 'TestUnionEnum', |
| 119 | 'data': [ 'value-a', 'value-b' ] } |
| 120 | |
| 121 | { 'enum': 'TestUnionEnumA', |
| 122 | 'data': [ 'value-a1', 'value-a2' ] } |
| 123 | |
| 124 | { 'struct': 'TestUnionTypeA1', |
| 125 | 'data': { 'integer': 'int', |
| 126 | 'name': 'str'} } |
| 127 | |
| 128 | { 'struct': 'TestUnionTypeA2', |
| 129 | 'data': { 'integer': 'int', |
| 130 | 'size': 'int' } } |
| 131 | |
| 132 | { 'union': 'TestUnionTypeA', |
| 133 | 'base': { 'type-a': 'TestUnionEnumA' }, |
| 134 | 'discriminator': 'type-a', |
| 135 | 'data': { 'value-a1': 'TestUnionTypeA1', |
| 136 | 'value-a2': 'TestUnionTypeA2' } } |
| 137 | |
| 138 | { 'struct': 'TestUnionTypeB', |
| 139 | 'data': { 'integer': 'int', |
| 140 | 'onoff': 'bool' } } |
| 141 | |
| 142 | { 'union': 'TestUnionInUnion', |
| 143 | 'base': { 'type': 'TestUnionEnum' }, |
| 144 | 'discriminator': 'type', |
| 145 | 'data': { 'value-a': 'TestUnionTypeA', |
| 146 | 'value-b': 'TestUnionTypeB' } } |
| 147 | |
| 148 | |
| 149 | # for testing use of 'number' within alternates |
| 150 | { 'alternate': 'AltEnumBool', 'data': { 'e': 'EnumOne', 'b': 'bool' } } |
| 151 | { 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } } |
| 152 | { 'alternate': 'AltNumEnum', 'data': { 'n': 'number', 'e': 'EnumOne' } } |
| 153 | { 'alternate': 'AltEnumInt', 'data': { 'e': 'EnumOne', 'i': 'int' } } |
| 154 | { 'alternate': 'AltListInt', 'data': { 'l': ['int'], 'i': 'int' } } |
| 155 | |
| 156 | # for testing use of 'str' within alternates |
| 157 | { 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } } |
| 158 | |
| 159 | { 'struct': 'ArrayStruct', |
| 160 | 'data': { 'integer': ['int'], |
| 161 | 's8': ['int8'], |
| 162 | 's16': ['int16'], |
| 163 | 's32': ['int32'], |
| 164 | 's64': ['int64'], |
| 165 | 'u8': ['uint8'], |
| 166 | 'u16': ['uint16'], |
| 167 | 'u32': ['uint32'], |
| 168 | 'u64': ['uint64'], |
| 169 | 'number': ['number'], |
| 170 | 'boolean': ['bool'], |
| 171 | 'string': ['str'], |
| 172 | '*sz': ['size'], |
| 173 | '*any': ['any'], |
| 174 | '*user': ['Status'] } } # intentional forward ref. to sub-module |
| 175 | |
| 176 | # for testing sub-modules |
| 177 | { 'include': 'include/sub-module.json' } |
| 178 | |
| 179 | # testing commands |
| 180 | { 'command': 'user-def-cmd', 'data': {} } |
| 181 | { 'command': 'user-def-cmd1', 'data': {'ud1a': 'UserDefOne'} } |
| 182 | { 'command': 'user-def-cmd2', |
| 183 | 'data': {'ud1a': {'type': 'UserDefOne'}, '*ud1b': 'UserDefOne'}, |
| 184 | 'returns': 'UserDefTwo' } |
| 185 | |
| 186 | { 'command': 'cmd-success-response', 'data': {}, 'success-response': false } |
| 187 | { 'command': 'coroutine-cmd', 'data': {}, 'coroutine': true } |
| 188 | |
| 189 | # Returning a non-dictionary requires a name from the whitelist |
| 190 | { 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' }, |
| 191 | 'returns': 'int' } |
| 192 | { 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' } |
| 193 | { 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' } |
| 194 | { 'command': 'boxed-union', 'data': 'UserDefFlatUnion', 'boxed': true } |
| 195 | { 'command': 'boxed-empty', 'boxed': true, 'data': 'Empty1' } |
| 196 | |
| 197 | # Smoke test on out-of-band and allow-preconfig-test |
| 198 | { 'command': 'test-flags-command', 'allow-oob': true, 'allow-preconfig': true } |
| 199 | |
| 200 | # For testing integer range flattening in opts-visitor. The following schema |
| 201 | # corresponds to the option format: |
| 202 | # |
| 203 | # -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12 |
| 204 | # |
| 205 | # For simplicity, this example doesn't use [type=]discriminator nor optargs |
| 206 | # specific to discriminator values. |
| 207 | { 'struct': 'UserDefOptions', |
| 208 | 'data': { |
| 209 | '*i64' : [ 'int' ], |
| 210 | '*u64' : [ 'uint64' ], |
| 211 | '*u16' : [ 'uint16' ], |
| 212 | '*i64x': 'int' , |
| 213 | '*u64x': 'uint64' } } |
| 214 | |
| 215 | # testing event |
| 216 | { 'struct': 'EventStructOne', |
| 217 | 'data': { 'struct1': {'type': 'UserDefOne'}, 'string': 'str', '*enum2': 'EnumOne' } } |
| 218 | |
| 219 | { 'event': 'EVENT_A' } |
| 220 | { 'event': 'EVENT_B', |
| 221 | 'data': { } } |
| 222 | { 'event': 'EVENT_C', |
| 223 | 'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } } |
| 224 | { 'event': 'EVENT_D', |
| 225 | 'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } } |
| 226 | { 'event': 'EVENT_E', 'boxed': true, 'data': 'UserDefZero' } |
| 227 | { 'event': 'EVENT_F', 'boxed': true, 'data': 'UserDefFlatUnion' } |
| 228 | { 'event': 'EVENT_G', 'boxed': true, 'data': 'Empty1' } |
| 229 | |
| 230 | # test that we correctly compile downstream extensions, as well as munge |
| 231 | # ticklish names |
| 232 | # also test union and alternate with just one branch |
| 233 | { 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] } |
| 234 | { 'struct': '__org.qemu_x-Base', |
| 235 | 'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } } |
| 236 | { 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base', |
| 237 | 'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } } |
| 238 | { 'alternate': '__org.qemu_x-Alt1', 'data': { '__org.qemu_x-branch': 'str' } } |
| 239 | { 'struct': '__org.qemu_x-Struct2', |
| 240 | 'data': { 'array': ['__org.qemu_x-Union'] } } |
| 241 | { 'union': '__org.qemu_x-Union', 'base': '__org.qemu_x-Base', |
| 242 | 'discriminator': '__org.qemu_x-member1', |
| 243 | 'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } } |
| 244 | { 'alternate': '__org.qemu_x-Alt', |
| 245 | 'data': { '__org.qemu_x-branch': '__org.qemu_x-Base' } } |
| 246 | { 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' } |
| 247 | { 'command': '__org.qemu_x-command', |
| 248 | 'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'], |
| 249 | 'c': '__org.qemu_x-Union', 'd': '__org.qemu_x-Alt' } } |
| 250 | |
| 251 | # test 'if' condition handling |
| 252 | |
| 253 | { 'struct': 'TestIfStruct', |
| 254 | 'data': { 'foo': 'int', |
| 255 | 'bar': { 'type': 'int', 'if': 'TEST_IF_STRUCT_MEMBER'}, |
| 256 | '*baz': { 'type': 'str', 'if': 'TEST_IF_STRUCT_MEMBER'} }, |
| 257 | 'if': 'TEST_IF_STRUCT' } |
| 258 | |
| 259 | { 'enum': 'TestIfEnum', |
| 260 | 'data': [ 'foo', { 'name' : 'bar', 'if': 'TEST_IF_ENUM_MEMBER' } ], |
| 261 | 'if': 'TEST_IF_UNION' } |
| 262 | |
| 263 | { 'union': 'TestIfUnion', |
| 264 | 'base': { 'type': 'TestIfEnum' }, |
| 265 | 'discriminator': 'type', |
| 266 | 'data': { 'foo': 'TestStruct', |
| 267 | 'bar': { 'type': 'UserDefZero', 'if': 'TEST_IF_ENUM_MEMBER'} }, |
| 268 | 'if': { 'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT'] } } |
| 269 | |
| 270 | { 'command': 'test-if-union-cmd', |
| 271 | 'data': { 'union-cmd-arg': 'TestIfUnion' }, |
| 272 | 'if': { 'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT'] } } |
| 273 | |
| 274 | { 'alternate': 'TestIfAlternate', |
| 275 | 'data': { 'foo': 'int', |
| 276 | 'bar': { 'type': 'TestStruct', 'if': 'TEST_IF_ALT_MEMBER'} }, |
| 277 | 'if': { 'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT'] } } |
| 278 | |
| 279 | { 'command': 'test-if-alternate-cmd', |
| 280 | 'data': { 'alt-cmd-arg': 'TestIfAlternate' }, |
| 281 | 'if': { 'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT'] } } |
| 282 | |
| 283 | { 'command': 'test-if-cmd', |
| 284 | 'boxed': true, |
| 285 | 'data': 'TestIfStruct', |
| 286 | 'returns': 'UserDefThree', |
| 287 | 'if': { 'all': ['TEST_IF_CMD', 'TEST_IF_STRUCT'] } } |
| 288 | |
| 289 | { 'command': 'test-cmd-return-def-three', 'returns': 'UserDefThree' } |
| 290 | |
| 291 | { 'event': 'TEST_IF_EVENT', |
| 292 | 'boxed': true, |
| 293 | 'data': 'TestIfStruct', |
| 294 | 'if': { 'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT'] } } |
| 295 | |
| 296 | { 'event': 'TEST_IF_EVENT2', 'data': {}, |
| 297 | 'if': { 'not': { 'any': [ { 'not': 'TEST_IF_EVT' }, |
| 298 | { 'not': 'TEST_IF_STRUCT' } ] } } } |
| 299 | |
| 300 | # test 'features' |
| 301 | |
| 302 | { 'struct': 'FeatureStruct0', |
| 303 | 'data': { 'foo': 'int' }, |
| 304 | 'features': [] } |
| 305 | { 'struct': 'FeatureStruct1', |
| 306 | 'data': { 'foo': { 'type': 'int', 'features': [ 'deprecated' ] } }, |
| 307 | 'features': [ 'feature1' ] } |
| 308 | { 'struct': 'FeatureStruct2', |
| 309 | 'data': { 'foo': { 'type': 'int', 'features': [ 'unstable' ] } }, |
| 310 | 'features': [ { 'name': 'feature1' } ] } |
| 311 | { 'struct': 'FeatureStruct3', |
| 312 | 'data': { 'foo': 'int' }, |
| 313 | 'features': [ 'feature1', 'feature2' ] } |
| 314 | { 'struct': 'FeatureStruct4', |
| 315 | 'data': { 'namespace-test': 'int' }, |
| 316 | 'features': [ 'namespace-test', 'int', 'name', 'if' ] } |
| 317 | |
| 318 | { 'struct': 'CondFeatureStruct1', |
| 319 | 'data': { 'foo': 'int' }, |
| 320 | 'features': [ { 'name': 'feature1', 'if': 'TEST_IF_FEATURE_1'} ] } |
| 321 | { 'struct': 'CondFeatureStruct2', |
| 322 | 'data': { 'foo': 'int' }, |
| 323 | 'features': [ { 'name': 'feature1', 'if': 'TEST_IF_FEATURE_1'}, |
| 324 | { 'name': 'feature2', 'if': 'TEST_IF_FEATURE_2'} ] } |
| 325 | { 'struct': 'CondFeatureStruct3', |
| 326 | 'data': { 'foo': 'int' }, |
| 327 | 'features': [ { 'name': 'feature1', |
| 328 | 'if': { 'all': [ 'TEST_IF_COND_1', |
| 329 | 'TEST_IF_COND_2'] } } ] } |
| 330 | { 'struct': 'CondFeatureStruct4', |
| 331 | 'data': { 'foo': 'int' }, |
| 332 | 'features': [ { 'name': 'feature1', |
| 333 | 'if': {'any': ['TEST_IF_COND_1', |
| 334 | 'TEST_IF_COND_2'] } } ] } |
| 335 | |
| 336 | { 'enum': 'FeatureEnum1', |
| 337 | 'data': [ 'eins', 'zwei', |
| 338 | { 'name': 'drei', 'features': [ 'deprecated' ] } ], |
| 339 | 'features': [ 'feature1' ] } |
| 340 | |
| 341 | { 'union': 'FeatureUnion1', |
| 342 | 'base': { 'tag': 'FeatureEnum1' }, |
| 343 | 'discriminator': 'tag', |
| 344 | 'data': { 'eins': 'FeatureStruct1' }, |
| 345 | 'features': [ 'feature1' ] } |
| 346 | |
| 347 | { 'alternate': 'FeatureAlternate1', |
| 348 | 'data': { 'eins': 'FeatureStruct1' }, |
| 349 | 'features': [ 'feature1' ] } |
| 350 | |
| 351 | { 'command': 'test-features0', |
| 352 | 'data': { '*fs0': 'FeatureStruct0', |
| 353 | '*fs1': 'FeatureStruct1', |
| 354 | '*fs2': 'FeatureStruct2', |
| 355 | '*fs3': 'FeatureStruct3', |
| 356 | '*fs4': 'FeatureStruct4', |
| 357 | '*cfs1': 'CondFeatureStruct1', |
| 358 | '*cfs2': 'CondFeatureStruct2', |
| 359 | '*cfs3': 'CondFeatureStruct3', |
| 360 | '*cfs4': 'CondFeatureStruct4' }, |
| 361 | 'returns': 'FeatureStruct1', |
| 362 | 'features': [] } |
| 363 | |
| 364 | { 'command': 'test-command-features1', |
| 365 | 'features': [ 'deprecated' ] } |
| 366 | { 'command': 'test-command-features3', |
| 367 | 'features': [ 'unstable', 'feature1', 'feature2' ] } |
| 368 | |
| 369 | { 'command': 'test-command-cond-features1', |
| 370 | 'features': [ { 'name': 'feature1', 'if': 'TEST_IF_FEATURE_1'} ] } |
| 371 | { 'command': 'test-command-cond-features2', |
| 372 | 'features': [ { 'name': 'feature1', 'if': 'TEST_IF_FEATURE_1'}, |
| 373 | { 'name': 'feature2', 'if': 'TEST_IF_FEATURE_2'} ] } |
| 374 | { 'command': 'test-command-cond-features3', |
| 375 | 'features': [ { 'name': 'feature1', |
| 376 | 'if': { 'all': [ 'TEST_IF_COND_1', |
| 377 | 'TEST_IF_COND_2'] } } ] } |
| 378 | |
| 379 | { 'event': 'TEST_EVENT_FEATURES0', |
| 380 | 'data': 'FeatureStruct1' } |
| 381 | |
| 382 | { 'event': 'TEST_EVENT_FEATURES1', |
| 383 | 'features': [ 'deprecated' ] } |
| 384 | |
| 385 | { 'event': 'TEST_EVENT_FEATURES2', |
| 386 | 'features': [ 'unstable' ] } |