blob: c72dbd805092ebe008e932f20b956b5bc0fbdf4c [file] [log] [blame]
Michael Roth501e5102011-07-19 14:50:43 -05001# *-*- Mode: Python -*-*
2
Eric Blake625b2512015-10-12 22:22:24 -06003# This file is a stress test of supported qapi constructs that must
4# parse and compile correctly.
5
Markus Armbruster1554a8f2017-03-15 13:56:54 +01006# 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
Eric Blake748053c2015-11-05 23:35:25 -070013{ 'struct': 'TestStruct',
14 'data': { 'integer': 'int', 'boolean': 'bool', 'string': 'str' } }
15
Michael Roth501e5102011-07-19 14:50:43 -050016# for testing enums
Eric Blake895a2a82015-05-04 09:05:27 -060017{ 'struct': 'NestedEnumsOne',
Eric Blake70478ce2015-10-12 22:22:26 -060018 'data': { 'enum1': 'EnumOne', # Intentional forward reference
19 '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } }
Michael Roth501e5102011-07-19 14:50:43 -050020
Eric Blake625b2512015-10-12 22:22:24 -060021# An empty enum, although unusual, is currently acceptable
22{ 'enum': 'MyEnum', 'data': [ ] }
23
Eric Blake19767082015-10-26 16:34:40 -060024# Likewise for an empty struct, including an empty base
25{ 'struct': 'Empty1', 'data': { } }
26{ 'struct': 'Empty2', 'base': 'Empty1', 'data': { } }
27
Eric Blake972a1102016-03-17 16:48:27 -060028{ 'command': 'user_def_cmd0', 'data': 'Empty2', 'returns': 'Empty2' }
29
Daniel P. Berrange351d36e2015-08-26 14:21:20 +010030# for testing override of default naming heuristic
31{ 'enum': 'QEnumTwo',
32 'prefix': 'QENUM_TWO',
33 'data': [ 'value1', 'value2' ] }
34
Michael Roth501e5102011-07-19 14:50:43 -050035# for testing nested structs
Markus Armbruster8c3f8e72015-06-26 10:19:11 +020036{ 'struct': 'UserDefOne',
37 'base': 'UserDefZero', # intentional forward reference
Eric Blake70478ce2015-10-12 22:22:26 -060038 'data': { 'string': 'str',
39 '*enum1': 'EnumOne' } } # intentional forward reference
40
41{ 'enum': 'EnumOne',
42 'data': [ 'value1', 'value2', 'value3' ] }
Markus Armbruster8c3f8e72015-06-26 10:19:11 +020043
Eric Blake895a2a82015-05-04 09:05:27 -060044{ 'struct': 'UserDefZero',
Markus Armbrusteraabbd472014-03-01 08:40:31 +010045 'data': { 'integer': 'int' } }
46
Eric Blake6446a592015-05-04 09:05:30 -060047{ 'struct': 'UserDefTwoDictDict',
48 'data': { 'userdef': 'UserDefOne', 'string': 'str' } }
49
50{ 'struct': 'UserDefTwoDict',
51 'data': { 'string1': 'str',
52 'dict2': 'UserDefTwoDictDict',
53 '*dict3': 'UserDefTwoDictDict' } }
54
Eric Blake895a2a82015-05-04 09:05:27 -060055{ 'struct': 'UserDefTwo',
Luiz Capitulinof294f822011-11-14 19:05:29 -020056 'data': { 'string0': 'str',
Eric Blake6446a592015-05-04 09:05:30 -060057 'dict1': 'UserDefTwoDict' } }
Luiz Capitulinof294f822011-11-14 19:05:29 -020058
Eric Blake9f08c8e2015-10-12 22:22:28 -060059# dummy struct to force generation of array types not otherwise mentioned
60{ 'struct': 'ForceArrays',
Eric Blake748053c2015-11-05 23:35:25 -070061 'data': { 'unused1':['UserDefOne'], 'unused2':['UserDefTwo'],
62 'unused3':['TestStruct'] } }
Eric Blake9f08c8e2015-10-12 22:22:28 -060063
Paolo Bonzinidc8fb6d2012-03-06 18:55:56 +010064# for testing unions
Eric Blaked220fbc2015-09-29 16:21:03 -060065# 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'
Eric Blake895a2a82015-05-04 09:05:27 -060068{ 'struct': 'UserDefA',
Eric Blaked220fbc2015-09-29 16:21:03 -060069 'data': { 'boolean': 'bool', '*a_b': 'int' } }
Paolo Bonzinidc8fb6d2012-03-06 18:55:56 +010070
Eric Blake895a2a82015-05-04 09:05:27 -060071{ 'struct': 'UserDefB',
Eric Blaked220fbc2015-09-29 16:21:03 -060072 'data': { 'intb': 'int', '*a-b': 'bool' } }
Paolo Bonzinidc8fb6d2012-03-06 18:55:56 +010073
Markus Armbruster8c3f8e72015-06-26 10:19:11 +020074{ 'union': 'UserDefFlatUnion',
75 'base': 'UserDefUnionBase', # intentional forward reference
76 'discriminator': 'enum1',
77 'data': { 'value1' : 'UserDefA',
78 'value2' : 'UserDefB',
79 'value3' : 'UserDefB' } }
Michael Rothcb551112014-09-18 15:36:42 -050080
Eric Blake895a2a82015-05-04 09:05:27 -060081{ 'struct': 'UserDefUnionBase',
Markus Armbruster80e60a12015-06-26 13:21:10 +020082 'base': 'UserDefZero',
Wenchao Xia52230702014-03-04 18:44:39 -080083 'data': { 'string': 'str', 'enum1': 'EnumOne' } }
84
Eric Blake14f00c62016-03-03 09:16:43 -070085# this variant of UserDefFlatUnion defaults to a union that uses members with
Michael Rothcb551112014-09-18 15:36:42 -050086# allocated types to test corner cases in the cleanup/dealloc visitor
87{ 'union': 'UserDefFlatUnion2',
Eric Blakeac4338f2016-03-17 16:48:39 -060088 'base': { '*integer': 'int', 'string': 'str', 'enum1': 'QEnumTwo' },
Michael Rothcb551112014-09-18 15:36:42 -050089 'discriminator': 'enum1',
Markus Armbruster8c3f8e72015-06-26 10:19:11 +020090 'data': { 'value1' : 'UserDefC', # intentional forward reference
Eric Blake9d3524b2016-02-16 16:39:25 -070091 'value2' : 'UserDefB' } }
Michael Rothcb551112014-09-18 15:36:42 -050092
Eric Blake68d07832016-02-17 23:48:18 -070093{ 'struct': 'WrapAlternate',
94 'data': { 'alt': 'UserDefAlternate' } }
Eric Blakeab916fa2015-05-04 09:05:13 -060095{ 'alternate': 'UserDefAlternate',
Markus Armbruster4d2d5c42017-06-26 19:25:14 +020096 'data': { 'udfu': 'UserDefFlatUnion', 'e': 'EnumOne', 'i': 'int',
97 'n': 'null' } }
Markus Armbruster2c38b602014-03-01 08:40:30 +010098
Markus Armbruster8c3f8e72015-06-26 10:19:11 +020099{ 'struct': 'UserDefC',
100 'data': { 'string1': 'str', 'string2': 'str' } }
101
Eric Blake9c51b442015-09-29 16:21:06 -0600102# for testing use of 'number' within alternates
Markus Armbruster8168ca82017-05-22 18:42:14 +0200103{ 'alternate': 'AltEnumBool', 'data': { 'e': 'EnumOne', 'b': 'bool' } }
104{ 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } }
Markus Armbruster8168ca82017-05-22 18:42:14 +0200105{ 'alternate': 'AltNumEnum', 'data': { 'n': 'number', 'e': 'EnumOne' } }
106{ 'alternate': 'AltEnumInt', 'data': { 'e': 'EnumOne', 'i': 'int' } }
Eric Blake9c51b442015-09-29 16:21:06 -0600107
Markus Armbrusterc0644772017-05-22 18:42:15 +0200108# for testing use of 'str' within alternates
109{ 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } }
110
Michael Roth83c84662013-05-10 17:46:09 -0500111# for testing native lists
112{ 'union': 'UserDefNativeListUnion',
113 'data': { 'integer': ['int'],
114 's8': ['int8'],
115 's16': ['int16'],
116 's32': ['int32'],
117 's64': ['int64'],
118 'u8': ['uint8'],
119 'u16': ['uint16'],
120 'u32': ['uint32'],
121 'u64': ['uint64'],
122 'number': ['number'],
123 'boolean': ['bool'],
Eric Blakecb17f792015-05-04 09:05:01 -0600124 'string': ['str'],
Markus Armbruster28770e02015-09-16 13:06:24 +0200125 'sizes': ['size'],
126 'any': ['any'] } }
Michael Roth83c84662013-05-10 17:46:09 -0500127
Michael Roth501e5102011-07-19 14:50:43 -0500128# testing commands
129{ 'command': 'user_def_cmd', 'data': {} }
130{ 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} }
Markus Armbrusterab22ad92014-03-01 08:40:28 +0100131{ 'command': 'user_def_cmd2',
132 'data': {'ud1a': 'UserDefOne', '*ud1b': 'UserDefOne'},
133 'returns': 'UserDefTwo' }
Eric Blakecae95ea2015-10-12 22:22:25 -0600134
135# Returning a non-dictionary requires a name from the whitelist
136{ 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' },
Markus Armbrusterc2216a82014-03-01 08:40:29 +0100137 'returns': 'int' }
Markus Armbruster28770e02015-09-16 13:06:24 +0200138{ 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' }
Eric Blakec8184082016-07-13 21:50:20 -0600139{ 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' }
140{ 'command': 'boxed-union', 'data': 'UserDefNativeListUnion', 'boxed': true }
Laszlo Ersek3953e3a2013-08-20 00:35:40 +0200141
142# For testing integer range flattening in opts-visitor. The following schema
143# corresponds to the option format:
144#
145# -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12
146#
147# For simplicity, this example doesn't use [type=]discriminator nor optargs
148# specific to discriminator values.
Eric Blake895a2a82015-05-04 09:05:27 -0600149{ 'struct': 'UserDefOptions',
Laszlo Ersek3953e3a2013-08-20 00:35:40 +0200150 'data': {
151 '*i64' : [ 'int' ],
152 '*u64' : [ 'uint64' ],
153 '*u16' : [ 'uint16' ],
154 '*i64x': 'int' ,
155 '*u64x': 'uint64' } }
Wenchao Xiaf6dadb02014-06-18 08:43:29 +0200156
157# testing event
Eric Blake895a2a82015-05-04 09:05:27 -0600158{ 'struct': 'EventStructOne',
Wenchao Xiaf6dadb02014-06-18 08:43:29 +0200159 'data': { 'struct1': 'UserDefOne', 'string': 'str', '*enum2': 'EnumOne' } }
160
161{ 'event': 'EVENT_A' }
162{ 'event': 'EVENT_B',
163 'data': { } }
164{ 'event': 'EVENT_C',
165 'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
166{ 'event': 'EVENT_D',
167 'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } }
Eric Blakec8184082016-07-13 21:50:20 -0600168{ 'event': 'EVENT_E', 'boxed': true, 'data': 'UserDefZero' }
169{ 'event': 'EVENT_F', 'boxed': true, 'data': 'UserDefAlternate' }
Eric Blakefce384b2015-05-14 06:50:56 -0600170
Eric Blakec43567c2015-11-18 01:52:52 -0700171# test that we correctly compile downstream extensions, as well as munge
172# ticklish names
Eric Blakefce384b2015-05-14 06:50:56 -0600173{ 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
Eric Blake83a02702015-05-14 06:50:57 -0600174{ 'struct': '__org.qemu_x-Base',
175 'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
176{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
Eric Blakec43567c2015-11-18 01:52:52 -0700177 'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } }
Eric Blakebb337292015-05-14 06:50:58 -0600178{ 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }
Eric Blake857af5f2015-05-14 06:50:59 -0600179{ 'struct': '__org.qemu_x-Struct2',
180 'data': { 'array': ['__org.qemu_x-Union1'] } }
181{ 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base',
182 'discriminator': '__org.qemu_x-member1',
183 'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
Eric Blaked1f07c82015-05-14 06:51:00 -0600184{ 'alternate': '__org.qemu_x-Alt',
185 'data': { '__org.qemu_x-branch': 'str', 'b': '__org.qemu_x-Base' } }
Eric Blakee3c4c3d2015-05-14 06:51:01 -0600186{ 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
187{ 'command': '__org.qemu_x-command',
188 'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'],
189 'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' },
190 'returns': '__org.qemu_x-Union1' }