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