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