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': '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# dummy struct to force generation of array types not otherwise mentioned
60{ 'struct': 'ForceArrays',
61  'data': { 'unused1':['UserDefOne'], 'unused2':['UserDefTwo'],
62            'unused3':['TestStruct'] } }
63
64# for testing unions
65# Among other things, test that a name collision between branches does
66# not cause any problems (since only one branch can be in use at a time),
67# by intentionally using two branches that both have a C member 'a_b'
68{ 'struct': 'UserDefA',
69  'data': { 'boolean': 'bool', '*a_b': 'int' } }
70
71{ 'struct': 'UserDefB',
72  'data': { 'intb': 'int', '*a-b': 'bool' } }
73
74{ 'union': 'UserDefFlatUnion',
75  'base': 'UserDefUnionBase',   # intentional forward reference
76  'discriminator': 'enum1',
77  'data': { 'value1' : 'UserDefA',
78            'value2' : 'UserDefB',
79            'value3' : 'UserDefB'
80            # 'value4' defaults to empty
81  } }
82
83{ 'struct': 'UserDefUnionBase',
84  'base': 'UserDefZero',
85  'data': { 'string': 'str', 'enum1': 'EnumOne' } }
86
87# this variant of UserDefFlatUnion defaults to a union that uses members with
88# allocated types to test corner cases in the cleanup/dealloc visitor
89{ 'union': 'UserDefFlatUnion2',
90  'base': { '*integer': 'int', 'string': 'str', 'enum1': 'QEnumTwo' },
91  'discriminator': 'enum1',
92  'data': { 'value1' : 'UserDefC', # intentional forward reference
93            'value2' : 'UserDefB' } }
94
95{ 'struct': 'WrapAlternate',
96  'data': { 'alt': 'UserDefAlternate' } }
97{ 'alternate': 'UserDefAlternate',
98  'data': { 'udfu': 'UserDefFlatUnion', 'e': 'EnumOne', 'i': 'int',
99            'n': 'null' } }
100
101{ 'struct': 'UserDefC',
102  'data': { 'string1': 'str', 'string2': 'str' } }
103
104# for testing use of 'number' within alternates
105{ 'alternate': 'AltEnumBool', 'data': { 'e': 'EnumOne', 'b': 'bool' } }
106{ 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } }
107{ 'alternate': 'AltNumEnum', 'data': { 'n': 'number', 'e': 'EnumOne' } }
108{ 'alternate': 'AltEnumInt', 'data': { 'e': 'EnumOne', 'i': 'int' } }
109
110# for testing use of 'str' within alternates
111{ 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } }
112
113# for testing native lists
114{ 'union': 'UserDefNativeListUnion',
115  'data': { 'integer': ['int'],
116            's8': ['int8'],
117            's16': ['int16'],
118            's32': ['int32'],
119            's64': ['int64'],
120            'u8': ['uint8'],
121            'u16': ['uint16'],
122            'u32': ['uint32'],
123            'u64': ['uint64'],
124            'number': ['number'],
125            'boolean': ['bool'],
126            'string': ['str'],
127            'sizes': ['size'],
128            'any': ['any'] } }
129
130# testing commands
131{ 'command': 'user_def_cmd', 'data': {} }
132{ 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} }
133{ 'command': 'user_def_cmd2',
134  'data': {'ud1a': 'UserDefOne', '*ud1b': 'UserDefOne'},
135  'returns': 'UserDefTwo' }
136
137# Returning a non-dictionary requires a name from the whitelist
138{ 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' },
139  'returns': 'int' }
140{ 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' }
141{ 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' }
142{ 'command': 'boxed-union', 'data': 'UserDefNativeListUnion', 'boxed': true }
143
144# Smoke test on out-of-band and allow-preconfig-test
145{ 'command': 'test-flags-command', 'allow-oob': true, 'allow-preconfig': true }
146
147# For testing integer range flattening in opts-visitor. The following schema
148# corresponds to the option format:
149#
150# -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12
151#
152# For simplicity, this example doesn't use [type=]discriminator nor optargs
153# specific to discriminator values.
154{ 'struct': 'UserDefOptions',
155  'data': {
156    '*i64' : [ 'int'    ],
157    '*u64' : [ 'uint64' ],
158    '*u16' : [ 'uint16' ],
159    '*i64x':   'int'     ,
160    '*u64x':   'uint64'  } }
161
162# testing event
163{ 'struct': 'EventStructOne',
164  'data': { 'struct1': 'UserDefOne', 'string': 'str', '*enum2': 'EnumOne' } }
165
166{ 'event': 'EVENT_A' }
167{ 'event': 'EVENT_B',
168  'data': { } }
169{ 'event': 'EVENT_C',
170  'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
171{ 'event': 'EVENT_D',
172  'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } }
173{ 'event': 'EVENT_E', 'boxed': true, 'data': 'UserDefZero' }
174{ 'event': 'EVENT_F', 'boxed': true, 'data': 'UserDefAlternate' }
175
176# test that we correctly compile downstream extensions, as well as munge
177# ticklish names
178{ 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
179{ 'struct': '__org.qemu_x-Base',
180  'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
181{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
182  'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } }
183{ 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }
184{ 'struct': '__org.qemu_x-Struct2',
185  'data': { 'array': ['__org.qemu_x-Union1'] } }
186{ 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base',
187  'discriminator': '__org.qemu_x-member1',
188  'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
189{ 'alternate': '__org.qemu_x-Alt',
190  'data': { '__org.qemu_x-branch': 'str', 'b': '__org.qemu_x-Base' } }
191{ 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
192{ 'command': '__org.qemu_x-command',
193  'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'],
194            'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' },
195  'returns': '__org.qemu_x-Union1' }
196