]> Git Repo - qemu.git/blob - tests/qapi-schema/qapi-schema-test.json
qapi: Add tests of complex objects within alternate
[qemu.git] / tests / qapi-schema / qapi-schema-test.json
1 # *-*- Mode: Python -*-*
2
3 # This file is a stress test of supported qapi constructs that must
4 # parse and compile correctly.
5
6 { 'struct': 'TestStruct',
7   'data': { 'integer': 'int', 'boolean': 'bool', 'string': 'str' } }
8
9 # for testing enums
10 { 'struct': 'NestedEnumsOne',
11   'data': { 'enum1': 'EnumOne',   # Intentional forward reference
12             '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } }
13
14 # An empty enum, although unusual, is currently acceptable
15 { 'enum': 'MyEnum', 'data': [ ] }
16
17 # Likewise for an empty struct, including an empty base
18 { 'struct': 'Empty1', 'data': { } }
19 { 'struct': 'Empty2', 'base': 'Empty1', 'data': { } }
20
21 # for testing override of default naming heuristic
22 { 'enum': 'QEnumTwo',
23   'prefix': 'QENUM_TWO',
24   'data': [ 'value1', 'value2' ] }
25
26 # for testing nested structs
27 { 'struct': 'UserDefOne',
28   'base': 'UserDefZero',        # intentional forward reference
29   'data': { 'string': 'str',
30             '*enum1': 'EnumOne' } }   # intentional forward reference
31
32 { 'enum': 'EnumOne',
33   'data': [ 'value1', 'value2', 'value3' ] }
34
35 { 'struct': 'UserDefZero',
36   'data': { 'integer': 'int' } }
37
38 { 'struct': 'UserDefTwoDictDict',
39   'data': { 'userdef': 'UserDefOne', 'string': 'str' } }
40
41 { 'struct': 'UserDefTwoDict',
42   'data': { 'string1': 'str',
43             'dict2': 'UserDefTwoDictDict',
44             '*dict3': 'UserDefTwoDictDict' } }
45
46 { 'struct': 'UserDefTwo',
47   'data': { 'string0': 'str',
48             'dict1': 'UserDefTwoDict' } }
49
50 # dummy struct to force generation of array types not otherwise mentioned
51 { 'struct': 'ForceArrays',
52   'data': { 'unused1':['UserDefOne'], 'unused2':['UserDefTwo'],
53             'unused3':['TestStruct'] } }
54
55 # for testing unions
56 # Among other things, test that a name collision between branches does
57 # not cause any problems (since only one branch can be in use at a time),
58 # by intentionally using two branches that both have a C member 'a_b'
59 { 'struct': 'UserDefA',
60   'data': { 'boolean': 'bool', '*a_b': 'int' } }
61
62 { 'struct': 'UserDefB',
63   'data': { 'intb': 'int', '*a-b': 'bool' } }
64
65 { 'union': 'UserDefFlatUnion',
66   'base': 'UserDefUnionBase',   # intentional forward reference
67   'discriminator': 'enum1',
68   'data': { 'value1' : 'UserDefA',
69             'value2' : 'UserDefB',
70             'value3' : 'UserDefB' } }
71
72 { 'struct': 'UserDefUnionBase',
73   'base': 'UserDefZero',
74   'data': { 'string': 'str', 'enum1': 'EnumOne' } }
75
76 { 'struct': 'UserDefUnionBase2',
77   'base': 'UserDefZero',
78   'data': { 'string': 'str', 'enum1': 'QEnumTwo' } }
79
80 # this variant of UserDefFlatUnion defaults to a union that uses fields with
81 # allocated types to test corner cases in the cleanup/dealloc visitor
82 { 'union': 'UserDefFlatUnion2',
83   'base': 'UserDefUnionBase2',
84   'discriminator': 'enum1',
85   'data': { 'value1' : 'UserDefC', # intentional forward reference
86             'value2' : 'UserDefB' } }
87
88 { 'struct': 'WrapAlternate',
89   'data': { 'alt': 'UserDefAlternate' } }
90 { 'alternate': 'UserDefAlternate',
91   'data': { 'udfu': 'UserDefFlatUnion', 's': 'str', 'i': 'int' } }
92
93 { 'struct': 'UserDefC',
94   'data': { 'string1': 'str', 'string2': 'str' } }
95
96 # for testing use of 'number' within alternates
97 { 'alternate': 'AltStrBool', 'data': { 's': 'str', 'b': 'bool' } }
98 { 'alternate': 'AltStrNum', 'data': { 's': 'str', 'n': 'number' } }
99 { 'alternate': 'AltNumStr', 'data': { 'n': 'number', 's': 'str' } }
100 { 'alternate': 'AltStrInt', 'data': { 's': 'str', 'i': 'int' } }
101 { 'alternate': 'AltIntNum', 'data': { 'i': 'int', 'n': 'number' } }
102 { 'alternate': 'AltNumInt', 'data': { 'n': 'number', 'i': 'int' } }
103
104 # for testing native lists
105 { 'union': 'UserDefNativeListUnion',
106   'data': { 'integer': ['int'],
107             's8': ['int8'],
108             's16': ['int16'],
109             's32': ['int32'],
110             's64': ['int64'],
111             'u8': ['uint8'],
112             'u16': ['uint16'],
113             'u32': ['uint32'],
114             'u64': ['uint64'],
115             'number': ['number'],
116             'boolean': ['bool'],
117             'string': ['str'],
118             'sizes': ['size'],
119             'any': ['any'] } }
120
121 # testing commands
122 { 'command': 'user_def_cmd', 'data': {} }
123 { 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} }
124 { 'command': 'user_def_cmd2',
125   'data': {'ud1a': 'UserDefOne', '*ud1b': 'UserDefOne'},
126   'returns': 'UserDefTwo' }
127
128 # Returning a non-dictionary requires a name from the whitelist
129 { 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' },
130   'returns': 'int' }
131 { 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' }
132
133 # For testing integer range flattening in opts-visitor. The following schema
134 # corresponds to the option format:
135 #
136 # -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12
137 #
138 # For simplicity, this example doesn't use [type=]discriminator nor optargs
139 # specific to discriminator values.
140 { 'struct': 'UserDefOptions',
141   'data': {
142     '*i64' : [ 'int'    ],
143     '*u64' : [ 'uint64' ],
144     '*u16' : [ 'uint16' ],
145     '*i64x':   'int'     ,
146     '*u64x':   'uint64'  } }
147
148 # testing event
149 { 'struct': 'EventStructOne',
150   'data': { 'struct1': 'UserDefOne', 'string': 'str', '*enum2': 'EnumOne' } }
151
152 { 'event': 'EVENT_A' }
153 { 'event': 'EVENT_B',
154   'data': { } }
155 { 'event': 'EVENT_C',
156   'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
157 { 'event': 'EVENT_D',
158   'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } }
159
160 # test that we correctly compile downstream extensions, as well as munge
161 # ticklish names
162 { 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
163 { 'struct': '__org.qemu_x-Base',
164   'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
165 { 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
166   'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } }
167 { 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }
168 { 'struct': '__org.qemu_x-Struct2',
169   'data': { 'array': ['__org.qemu_x-Union1'] } }
170 { 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base',
171   'discriminator': '__org.qemu_x-member1',
172   'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
173 { 'alternate': '__org.qemu_x-Alt',
174   'data': { '__org.qemu_x-branch': 'str', 'b': '__org.qemu_x-Base' } }
175 { 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
176 { 'command': '__org.qemu_x-command',
177   'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'],
178             'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' },
179   'returns': '__org.qemu_x-Union1' }
This page took 0.035272 seconds and 4 git commands to generate.