1# *-*- Mode: Python -*-* 2 3# This file is a stress test of supported qapi constructs that must 4# parse and compile correctly. 5 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 13{ 'struct': 'TestStruct', 14 'data': { 'integer': {'type': 'int'}, 'boolean': 'bool', 'string': 'str' } } 15 16# for testing enums 17{ 'struct': 'NestedEnumsOne', 18 'data': { 'enum1': 'EnumOne', # Intentional forward reference 19 '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } } 20 21# An empty enum, although unusual, is currently acceptable 22{ 'enum': 'MyEnum', 'data': [ ] } 23 24# Likewise for an empty struct, including an empty base 25{ 'struct': 'Empty1', 'data': { } } 26{ 'struct': 'Empty2', 'base': 'Empty1', 'data': { } } 27 28{ 'command': 'user_def_cmd0', 'data': 'Empty2', 'returns': 'Empty2' } 29 30# for testing override of default naming heuristic 31{ 'enum': 'QEnumTwo', 32 'prefix': 'QENUM_TWO', 33 'data': [ 'value1', 'value2' ] } 34 35# for testing nested structs 36{ 'struct': 'UserDefOne', 37 'base': 'UserDefZero', # intentional forward reference 38 'data': { 'string': 'str', 39 '*enum1': 'EnumOne' } } # intentional forward reference 40 41{ 'enum': 'EnumOne', 42 'data': [ 'value1', 'value2', 'value3', 'value4' ] } 43 44{ 'struct': 'UserDefZero', 45 'data': { 'integer': 'int' } } 46 47{ 'struct': 'UserDefTwoDictDict', 48 'data': { 'userdef': 'UserDefOne', 'string': 'str' } } 49 50{ 'struct': 'UserDefTwoDict', 51 'data': { 'string1': 'str', 52 'dict2': 'UserDefTwoDictDict', 53 '*dict3': 'UserDefTwoDictDict' } } 54 55{ 'struct': 'UserDefTwo', 56 'data': { 'string0': 'str', 57 'dict1': 'UserDefTwoDict' } } 58 59{ 'struct': 'UserDefThree', 60 'data': { 'string0': 'str' } } 61 62# dummy struct to force generation of array types not otherwise mentioned 63{ 'struct': 'ForceArrays', 64 'data': { 'unused1':['UserDefOne'], 'unused2':['UserDefTwo'], 65 'unused3':['TestStruct'] } } 66 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' } } 73 74{ 'struct': 'UserDefB', 75 'data': { 'intb': 'int', '*a-b': 'bool' } } 76 77{ 'union': 'UserDefFlatUnion', 78 'base': 'UserDefUnionBase', # intentional forward reference 79 'discriminator': 'enum1', 80 'data': { 'value1' : {'type': 'UserDefA'}, 81 'value2' : 'UserDefB', 82 'value3' : 'UserDefB' 83 # 'value4' defaults to empty 84 } } 85 86{ 'struct': 'UserDefUnionBase', 87 'base': 'UserDefZero', 88 'data': { 'string': 'str', 'enum1': 'EnumOne' } } 89 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' } } 97 98{ 'struct': 'WrapAlternate', 99 'data': { 'alt': 'UserDefAlternate' } } 100{ 'alternate': 'UserDefAlternate', 101 'data': { 'udfu': {'type': 'UserDefFlatUnion'}, 'e': 'EnumOne', 'i': 'int', 102 'n': 'null' } } 103 104{ 'struct': 'UserDefC', 105 'data': { 'string1': 'str', 'string2': 'str' } } 106 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' } } 112 113# for testing use of 'str' within alternates 114{ 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } } 115 116# for testing lists 117{ 'union': 'UserDefListUnion', 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'], 132 'user': ['Status'] } } # intentional forward ref. to sub-module 133 134# for testing sub-modules 135{ 'include': 'include/sub-module.json' } 136 137# testing commands 138{ 'command': 'user_def_cmd', 'data': {} } 139{ 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} } 140{ 'command': 'user_def_cmd2', 141 'data': {'ud1a': {'type': 'UserDefOne'}, '*ud1b': 'UserDefOne'}, 142 'returns': 'UserDefTwo' } 143 144{ 'command': 'cmd-success-response', 'data': {}, 'success-response': false } 145 146# Returning a non-dictionary requires a name from the whitelist 147{ 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' }, 148 'returns': 'int' } 149{ 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' } 150{ 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' } 151{ 'command': 'boxed-union', 'data': 'UserDefListUnion', 'boxed': true } 152{ 'command': 'boxed-empty', 'boxed': true, 'data': 'Empty1' } 153 154# Smoke test on out-of-band and allow-preconfig-test 155{ 'command': 'test-flags-command', 'allow-oob': true, 'allow-preconfig': true } 156 157# For testing integer range flattening in opts-visitor. The following schema 158# corresponds to the option format: 159# 160# -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12 161# 162# For simplicity, this example doesn't use [type=]discriminator nor optargs 163# specific to discriminator values. 164{ 'struct': 'UserDefOptions', 165 'data': { 166 '*i64' : [ 'int' ], 167 '*u64' : [ 'uint64' ], 168 '*u16' : [ 'uint16' ], 169 '*i64x': 'int' , 170 '*u64x': 'uint64' } } 171 172# testing event 173{ 'struct': 'EventStructOne', 174 'data': { 'struct1': {'type': 'UserDefOne'}, 'string': 'str', '*enum2': 'EnumOne' } } 175 176{ 'event': 'EVENT_A' } 177{ 'event': 'EVENT_B', 178 'data': { } } 179{ 'event': 'EVENT_C', 180 'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } } 181{ 'event': 'EVENT_D', 182 'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } } 183{ 'event': 'EVENT_E', 'boxed': true, 'data': 'UserDefZero' } 184{ 'event': 'EVENT_F', 'boxed': true, 'data': 'UserDefFlatUnion' } 185{ 'event': 'EVENT_G', 'boxed': true, 'data': 'Empty1' } 186 187# test that we correctly compile downstream extensions, as well as munge 188# ticklish names 189# also test union and alternate with just one branch 190{ 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] } 191{ 'struct': '__org.qemu_x-Base', 192 'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } } 193{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base', 194 'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } } 195{ 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } } 196{ 'alternate': '__org.qemu_x-Alt1', 'data': { '__org.qemu_x-branch': 'str' } } 197{ 'struct': '__org.qemu_x-Struct2', 198 'data': { 'array': ['__org.qemu_x-Union1'] } } 199{ 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base', 200 'discriminator': '__org.qemu_x-member1', 201 'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } } 202{ 'alternate': '__org.qemu_x-Alt', 203 'data': { '__org.qemu_x-branch': '__org.qemu_x-Base' } } 204{ 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' } 205{ 'command': '__org.qemu_x-command', 206 'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'], 207 'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' }, 208 'returns': '__org.qemu_x-Union1' } 209 210# test 'if' condition handling 211 212{ 'struct': 'TestIfStruct', 'data': 213 { 'foo': 'int', 214 'bar': { 'type': 'int', 'if': 'defined(TEST_IF_STRUCT_BAR)'} }, 215 'if': 'defined(TEST_IF_STRUCT)' } 216 217{ 'enum': 'TestIfEnum', 'data': 218 [ 'foo', { 'name' : 'bar', 'if': 'defined(TEST_IF_ENUM_BAR)' } ], 219 'if': 'defined(TEST_IF_ENUM)' } 220 221{ 'union': 'TestIfUnion', 'data': 222 { 'foo': 'TestStruct', 223 'union_bar': { 'type': 'str', 'if': 'defined(TEST_IF_UNION_BAR)'} }, 224 'if': 'defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)' } 225 226{ 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' }, 227 'if': 'defined(TEST_IF_UNION)' } 228 229{ 'alternate': 'TestIfAlternate', 'data': 230 { 'foo': 'int', 231 'bar': { 'type': 'TestStruct', 'if': 'defined(TEST_IF_ALT_BAR)'} }, 232 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' } 233 234{ 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlternate' }, 235 'if': 'defined(TEST_IF_ALT)' } 236 237{ 'command': 'TestIfCmd', 'data': 238 { 'foo': 'TestIfStruct', 239 'bar': { 'type': 'TestIfEnum', 'if': 'defined(TEST_IF_CMD_BAR)' } }, 240 'returns': 'UserDefThree', 241 'if': ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] } 242 243{ 'command': 'TestCmdReturnDefThree', 'returns': 'UserDefThree' } 244 245{ 'event': 'TestIfEvent', 'data': 246 { 'foo': 'TestIfStruct', 247 'bar': { 'type': ['TestIfEnum'], 'if': 'defined(TEST_IF_EVT_BAR)' } }, 248 'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' } 249 250# test 'features' for structs 251 252{ 'struct': 'FeatureStruct0', 253 'data': { 'foo': 'int' }, 254 'features': [] } 255{ 'struct': 'FeatureStruct1', 256 'data': { 'foo': 'int' }, 257 'features': [ 'feature1' ] } 258{ 'struct': 'FeatureStruct2', 259 'data': { 'foo': 'int' }, 260 'features': [ { 'name': 'feature1' } ] } 261{ 'struct': 'FeatureStruct3', 262 'data': { 'foo': 'int' }, 263 'features': [ 'feature1', 'feature2' ] } 264{ 'struct': 'FeatureStruct4', 265 'data': { 'namespace-test': 'int' }, 266 'features': [ 'namespace-test', 'int', 'name', 'if' ] } 267 268{ 'struct': 'CondFeatureStruct1', 269 'data': { 'foo': 'int' }, 270 'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'} ] } 271{ 'struct': 'CondFeatureStruct2', 272 'data': { 'foo': 'int' }, 273 'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'}, 274 { 'name': 'feature2', 'if': 'defined(TEST_IF_FEATURE_2)'} ] } 275{ 'struct': 'CondFeatureStruct3', 276 'data': { 'foo': 'int' }, 277 'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)', 278 'defined(TEST_IF_COND_2)'] } ] } 279{ 'command': 'test-features', 280 'data': { 'fs0': 'FeatureStruct0', 281 'fs1': 'FeatureStruct1', 282 'fs2': 'FeatureStruct2', 283 'fs3': 'FeatureStruct3', 284 'fs4': 'FeatureStruct4', 285 'cfs1': 'CondFeatureStruct1', 286 'cfs2': 'CondFeatureStruct2', 287 'cfs3': 'CondFeatureStruct3' } } 288