qapi-schema-test.json 8.5 KB
Newer Older
1 2
# *-*- Mode: Python -*-*

3 4 5
# This file is a stress test of supported qapi constructs that must
# parse and compile correctly.

6 7 8 9 10 11 12
# Whitelists to permit QAPI rule violations
{ 'pragma': {
    # Commands allowed to return a non-dictionary:
    'returns-whitelist': [
        'guest-get-time',
        'guest-sync' ] } }

13
{ 'struct': 'TestStruct',
14
  'data': { 'integer': {'type': 'int'}, 'boolean': 'bool', 'string': 'str' } }
15

16
# for testing enums
17
{ 'struct': 'NestedEnumsOne',
18 19
  'data': { 'enum1': 'EnumOne',   # Intentional forward reference
            '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } }
20

21 22 23
# An empty enum, although unusual, is currently acceptable
{ 'enum': 'MyEnum', 'data': [ ] }

24 25 26 27
# Likewise for an empty struct, including an empty base
{ 'struct': 'Empty1', 'data': { } }
{ 'struct': 'Empty2', 'base': 'Empty1', 'data': { } }

28 29
{ 'command': 'user_def_cmd0', 'data': 'Empty2', 'returns': 'Empty2' }

30 31 32 33 34
# for testing override of default naming heuristic
{ 'enum': 'QEnumTwo',
  'prefix': 'QENUM_TWO',
  'data': [ 'value1', 'value2' ] }

35
# for testing nested structs
36
{ 'struct': 'UserDefOne',
37
  'base': 'UserDefZero',        # intentional forward reference
38 39 40 41
  'data': { 'string': 'str',
            '*enum1': 'EnumOne' } }   # intentional forward reference

{ 'enum': 'EnumOne',
42
  'data': [ 'value1', 'value2', 'value3', 'value4' ] }
43

44 45 46
{ 'struct': 'UserDefZero',
  'data': { 'integer': 'int' } }

47 48 49 50 51 52 53 54
{ 'struct': 'UserDefTwoDictDict',
  'data': { 'userdef': 'UserDefOne', 'string': 'str' } }

{ 'struct': 'UserDefTwoDict',
  'data': { 'string1': 'str',
            'dict2': 'UserDefTwoDictDict',
            '*dict3': 'UserDefTwoDictDict' } }

55
{ 'struct': 'UserDefTwo',
56
  'data': { 'string0': 'str',
57
            'dict1': 'UserDefTwoDict' } }
58

59 60 61
{ 'struct': 'UserDefThree',
  'data': { 'string0': 'str' } }

E
Eric Blake 已提交
62 63
# dummy struct to force generation of array types not otherwise mentioned
{ 'struct': 'ForceArrays',
64 65
  'data': { 'unused1':['UserDefOne'], 'unused2':['UserDefTwo'],
            'unused3':['TestStruct'] } }
E
Eric Blake 已提交
66

67
# for testing unions
68 69 70
# Among other things, test that a name collision between branches does
# not cause any problems (since only one branch can be in use at a time),
# 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 83 84
            'value3' : 'UserDefB'
            # 'value4' defaults to empty
  } }
85

86
{ 'struct': 'UserDefUnionBase',
87
  'base': 'UserDefZero',
88 89
  'data': { 'string': 'str', 'enum1': 'EnumOne' } }

90
# this variant of UserDefFlatUnion defaults to a union that uses members with
91 92
# allocated types to test corner cases in the cleanup/dealloc visitor
{ '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 99
{ 'struct': 'WrapAlternate',
  'data': { 'alt': 'UserDefAlternate' } }
100
{ 'alternate': 'UserDefAlternate',
101
  'data': { 'udfu': {'type': 'UserDefFlatUnion'}, 'e': 'EnumOne', 'i': 'int',
102
            'n': 'null' } }
103

104 105 106
{ 'struct': 'UserDefC',
  'data': { 'string1': 'str', 'string2': 'str' } }

107
# for testing use of 'number' within alternates
108 109 110 111
{ 'alternate': 'AltEnumBool', 'data': { 'e': 'EnumOne', 'b': 'bool' } }
{ 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } }
{ 'alternate': 'AltNumEnum', 'data': { 'n': 'number', 'e': 'EnumOne' } }
{ 'alternate': 'AltEnumInt', 'data': { 'e': 'EnumOne', 'i': 'int' } }
112

113 114 115
# for testing use of 'str' within alternates
{ 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } }

116 117 118 119 120 121 122 123 124 125 126 127 128
# for testing native lists
{ 'union': 'UserDefNativeListUnion',
  'data': { 'integer': ['int'],
            's8': ['int8'],
            's16': ['int16'],
            's32': ['int32'],
            's64': ['int64'],
            'u8': ['uint8'],
            'u16': ['uint16'],
            'u32': ['uint32'],
            'u64': ['uint64'],
            'number': ['number'],
            'boolean': ['bool'],
129
            'string': ['str'],
130 131
            'sizes': ['size'],
            'any': ['any'] } }
132

133 134 135
# testing commands
{ 'command': 'user_def_cmd', 'data': {} }
{ 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} }
136
{ 'command': 'user_def_cmd2',
137
  'data': {'ud1a': {'type': 'UserDefOne'}, '*ud1b': 'UserDefOne'},
138
  'returns': 'UserDefTwo' }
E
Eric Blake 已提交
139

140 141
{ 'command': 'cmd-success-response', 'data': {}, 'success-response': false }

E
Eric Blake 已提交
142 143
# Returning a non-dictionary requires a name from the whitelist
{ 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' },
144
  'returns': 'int' }
145
{ 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' }
146 147
{ 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' }
{ 'command': 'boxed-union', 'data': 'UserDefNativeListUnion', 'boxed': true }
148

149
# Smoke test on out-of-band and allow-preconfig-test
150
{ 'command': 'test-flags-command', 'allow-oob': true, 'allow-preconfig': true }
P
Peter Xu 已提交
151

152 153 154 155 156 157 158
# For testing integer range flattening in opts-visitor. The following schema
# corresponds to the option format:
#
# -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12
#
# For simplicity, this example doesn't use [type=]discriminator nor optargs
# specific to discriminator values.
159
{ 'struct': 'UserDefOptions',
160 161 162 163 164 165
  'data': {
    '*i64' : [ 'int'    ],
    '*u64' : [ 'uint64' ],
    '*u16' : [ 'uint16' ],
    '*i64x':   'int'     ,
    '*u64x':   'uint64'  } }
166 167

# testing event
168
{ 'struct': 'EventStructOne',
169
  'data': { 'struct1': {'type': 'UserDefOne'}, 'string': 'str', '*enum2': 'EnumOne' } }
170 171 172 173 174 175 176 177

{ 'event': 'EVENT_A' }
{ 'event': 'EVENT_B',
  'data': { } }
{ 'event': 'EVENT_C',
  'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
{ 'event': 'EVENT_D',
  'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } }
178 179
{ 'event': 'EVENT_E', 'boxed': true, 'data': 'UserDefZero' }
{ 'event': 'EVENT_F', 'boxed': true, 'data': 'UserDefAlternate' }
E
Eric Blake 已提交
180

E
Eric Blake 已提交
181 182
# test that we correctly compile downstream extensions, as well as munge
# ticklish names
E
Eric Blake 已提交
183
{ 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
E
Eric Blake 已提交
184 185 186
{ 'struct': '__org.qemu_x-Base',
  'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
E
Eric Blake 已提交
187
  'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } }
188
{ 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }
189 190 191 192 193
{ 'struct': '__org.qemu_x-Struct2',
  'data': { 'array': ['__org.qemu_x-Union1'] } }
{ 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base',
  'discriminator': '__org.qemu_x-member1',
  'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
E
Eric Blake 已提交
194 195
{ 'alternate': '__org.qemu_x-Alt',
  'data': { '__org.qemu_x-branch': 'str', 'b': '__org.qemu_x-Base' } }
196 197 198 199 200
{ 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
{ 'command': '__org.qemu_x-command',
  'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'],
            'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' },
  'returns': '__org.qemu_x-Union1' }
201 202 203

# test 'if' condition handling

204 205 206
{ 'struct': 'TestIfStruct', 'data':
  { 'foo': 'int',
    'bar': { 'type': 'int', 'if': 'defined(TEST_IF_STRUCT_BAR)'} },
207 208
  'if': 'defined(TEST_IF_STRUCT)' }

209 210
{ 'enum': 'TestIfEnum', 'data':
  [ 'foo', { 'name' : 'bar', 'if': 'defined(TEST_IF_ENUM_BAR)' } ],
211 212
  'if': 'defined(TEST_IF_ENUM)' }

213 214 215
{ 'union': 'TestIfUnion', 'data':
  { 'foo': 'TestStruct',
    'union_bar': { 'type': 'str', 'if': 'defined(TEST_IF_UNION_BAR)'} },
216 217
  'if': 'defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)' }

218 219 220
{ 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' },
  'if': 'defined(TEST_IF_UNION)' }

221 222 223
{ 'alternate': 'TestIfAlternate', 'data':
  { 'foo': 'int',
    'bar': { 'type': 'TestStruct', 'if': 'defined(TEST_IF_ALT_BAR)'} },
224 225
  'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' }

226 227 228
{ 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlternate' },
  'if': 'defined(TEST_IF_ALT)' }

229 230 231
{ 'command': 'TestIfCmd', 'data':
  { 'foo': 'TestIfStruct',
    'bar': { 'type': 'TestIfEnum', 'if': 'defined(TEST_IF_CMD_BAR)' } },
232 233 234 235 236
  'returns': 'UserDefThree',
  'if': ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] }

{ 'command': 'TestCmdReturnDefThree', 'returns': 'UserDefThree' }

237 238 239
{ 'event': 'TestIfEvent', 'data':
  { 'foo': 'TestIfStruct',
    'bar': { 'type': 'TestIfEnum', 'if': 'defined(TEST_IF_EVT_BAR)' } },
240
  'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' }