Michael Roth | 501e510 | 2011-07-19 14:50:43 -0500 | [diff] [blame] | 1 | # *-*- Mode: Python -*-* |
| 2 | |
Eric Blake | 625b251 | 2015-10-12 22:22:24 -0600 | [diff] [blame] | 3 | # This file is a stress test of supported qapi constructs that must |
| 4 | # parse and compile correctly. |
| 5 | |
Markus Armbruster | 1554a8f | 2017-03-15 13:56:54 +0100 | [diff] [blame] | 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 | |
Eric Blake | 748053c | 2015-11-05 23:35:25 -0700 | [diff] [blame] | 13 | { 'struct': 'TestStruct', |
| 14 | 'data': { 'integer': 'int', 'boolean': 'bool', 'string': 'str' } } |
| 15 | |
Michael Roth | 501e510 | 2011-07-19 14:50:43 -0500 | [diff] [blame] | 16 | # for testing enums |
Eric Blake | 895a2a8 | 2015-05-04 09:05:27 -0600 | [diff] [blame] | 17 | { 'struct': 'NestedEnumsOne', |
Eric Blake | 70478ce | 2015-10-12 22:22:26 -0600 | [diff] [blame] | 18 | 'data': { 'enum1': 'EnumOne', # Intentional forward reference |
| 19 | '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } } |
Michael Roth | 501e510 | 2011-07-19 14:50:43 -0500 | [diff] [blame] | 20 | |
Eric Blake | 625b251 | 2015-10-12 22:22:24 -0600 | [diff] [blame] | 21 | # An empty enum, although unusual, is currently acceptable |
| 22 | { 'enum': 'MyEnum', 'data': [ ] } |
| 23 | |
Eric Blake | 1976708 | 2015-10-26 16:34:40 -0600 | [diff] [blame] | 24 | # Likewise for an empty struct, including an empty base |
| 25 | { 'struct': 'Empty1', 'data': { } } |
| 26 | { 'struct': 'Empty2', 'base': 'Empty1', 'data': { } } |
| 27 | |
Eric Blake | 972a110 | 2016-03-17 16:48:27 -0600 | [diff] [blame] | 28 | { 'command': 'user_def_cmd0', 'data': 'Empty2', 'returns': 'Empty2' } |
| 29 | |
Daniel P. Berrange | 351d36e | 2015-08-26 14:21:20 +0100 | [diff] [blame] | 30 | # for testing override of default naming heuristic |
| 31 | { 'enum': 'QEnumTwo', |
| 32 | 'prefix': 'QENUM_TWO', |
| 33 | 'data': [ 'value1', 'value2' ] } |
| 34 | |
Michael Roth | 501e510 | 2011-07-19 14:50:43 -0500 | [diff] [blame] | 35 | # for testing nested structs |
Markus Armbruster | 8c3f8e7 | 2015-06-26 10:19:11 +0200 | [diff] [blame] | 36 | { 'struct': 'UserDefOne', |
| 37 | 'base': 'UserDefZero', # intentional forward reference |
Eric Blake | 70478ce | 2015-10-12 22:22:26 -0600 | [diff] [blame] | 38 | 'data': { 'string': 'str', |
| 39 | '*enum1': 'EnumOne' } } # intentional forward reference |
| 40 | |
| 41 | { 'enum': 'EnumOne', |
| 42 | 'data': [ 'value1', 'value2', 'value3' ] } |
Markus Armbruster | 8c3f8e7 | 2015-06-26 10:19:11 +0200 | [diff] [blame] | 43 | |
Eric Blake | 895a2a8 | 2015-05-04 09:05:27 -0600 | [diff] [blame] | 44 | { 'struct': 'UserDefZero', |
Markus Armbruster | aabbd47 | 2014-03-01 08:40:31 +0100 | [diff] [blame] | 45 | 'data': { 'integer': 'int' } } |
| 46 | |
Eric Blake | 6446a59 | 2015-05-04 09:05:30 -0600 | [diff] [blame] | 47 | { 'struct': 'UserDefTwoDictDict', |
| 48 | 'data': { 'userdef': 'UserDefOne', 'string': 'str' } } |
| 49 | |
| 50 | { 'struct': 'UserDefTwoDict', |
| 51 | 'data': { 'string1': 'str', |
| 52 | 'dict2': 'UserDefTwoDictDict', |
| 53 | '*dict3': 'UserDefTwoDictDict' } } |
| 54 | |
Eric Blake | 895a2a8 | 2015-05-04 09:05:27 -0600 | [diff] [blame] | 55 | { 'struct': 'UserDefTwo', |
Luiz Capitulino | f294f82 | 2011-11-14 19:05:29 -0200 | [diff] [blame] | 56 | 'data': { 'string0': 'str', |
Eric Blake | 6446a59 | 2015-05-04 09:05:30 -0600 | [diff] [blame] | 57 | 'dict1': 'UserDefTwoDict' } } |
Luiz Capitulino | f294f82 | 2011-11-14 19:05:29 -0200 | [diff] [blame] | 58 | |
Eric Blake | 9f08c8e | 2015-10-12 22:22:28 -0600 | [diff] [blame] | 59 | # dummy struct to force generation of array types not otherwise mentioned |
| 60 | { 'struct': 'ForceArrays', |
Eric Blake | 748053c | 2015-11-05 23:35:25 -0700 | [diff] [blame] | 61 | 'data': { 'unused1':['UserDefOne'], 'unused2':['UserDefTwo'], |
| 62 | 'unused3':['TestStruct'] } } |
Eric Blake | 9f08c8e | 2015-10-12 22:22:28 -0600 | [diff] [blame] | 63 | |
Paolo Bonzini | dc8fb6d | 2012-03-06 18:55:56 +0100 | [diff] [blame] | 64 | # for testing unions |
Eric Blake | d220fbc | 2015-09-29 16:21:03 -0600 | [diff] [blame] | 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' |
Eric Blake | 895a2a8 | 2015-05-04 09:05:27 -0600 | [diff] [blame] | 68 | { 'struct': 'UserDefA', |
Eric Blake | d220fbc | 2015-09-29 16:21:03 -0600 | [diff] [blame] | 69 | 'data': { 'boolean': 'bool', '*a_b': 'int' } } |
Paolo Bonzini | dc8fb6d | 2012-03-06 18:55:56 +0100 | [diff] [blame] | 70 | |
Eric Blake | 895a2a8 | 2015-05-04 09:05:27 -0600 | [diff] [blame] | 71 | { 'struct': 'UserDefB', |
Eric Blake | d220fbc | 2015-09-29 16:21:03 -0600 | [diff] [blame] | 72 | 'data': { 'intb': 'int', '*a-b': 'bool' } } |
Paolo Bonzini | dc8fb6d | 2012-03-06 18:55:56 +0100 | [diff] [blame] | 73 | |
Markus Armbruster | 8c3f8e7 | 2015-06-26 10:19:11 +0200 | [diff] [blame] | 74 | { 'union': 'UserDefFlatUnion', |
| 75 | 'base': 'UserDefUnionBase', # intentional forward reference |
| 76 | 'discriminator': 'enum1', |
| 77 | 'data': { 'value1' : 'UserDefA', |
| 78 | 'value2' : 'UserDefB', |
| 79 | 'value3' : 'UserDefB' } } |
Michael Roth | cb55111 | 2014-09-18 15:36:42 -0500 | [diff] [blame] | 80 | |
Eric Blake | 895a2a8 | 2015-05-04 09:05:27 -0600 | [diff] [blame] | 81 | { 'struct': 'UserDefUnionBase', |
Markus Armbruster | 80e60a1 | 2015-06-26 13:21:10 +0200 | [diff] [blame] | 82 | 'base': 'UserDefZero', |
Wenchao Xia | 5223070 | 2014-03-04 18:44:39 -0800 | [diff] [blame] | 83 | 'data': { 'string': 'str', 'enum1': 'EnumOne' } } |
| 84 | |
Eric Blake | 14f00c6 | 2016-03-03 09:16:43 -0700 | [diff] [blame] | 85 | # this variant of UserDefFlatUnion defaults to a union that uses members with |
Michael Roth | cb55111 | 2014-09-18 15:36:42 -0500 | [diff] [blame] | 86 | # allocated types to test corner cases in the cleanup/dealloc visitor |
| 87 | { 'union': 'UserDefFlatUnion2', |
Eric Blake | ac4338f | 2016-03-17 16:48:39 -0600 | [diff] [blame] | 88 | 'base': { '*integer': 'int', 'string': 'str', 'enum1': 'QEnumTwo' }, |
Michael Roth | cb55111 | 2014-09-18 15:36:42 -0500 | [diff] [blame] | 89 | 'discriminator': 'enum1', |
Markus Armbruster | 8c3f8e7 | 2015-06-26 10:19:11 +0200 | [diff] [blame] | 90 | 'data': { 'value1' : 'UserDefC', # intentional forward reference |
Eric Blake | 9d3524b | 2016-02-16 16:39:25 -0700 | [diff] [blame] | 91 | 'value2' : 'UserDefB' } } |
Michael Roth | cb55111 | 2014-09-18 15:36:42 -0500 | [diff] [blame] | 92 | |
Eric Blake | 68d0783 | 2016-02-17 23:48:18 -0700 | [diff] [blame] | 93 | { 'struct': 'WrapAlternate', |
| 94 | 'data': { 'alt': 'UserDefAlternate' } } |
Eric Blake | ab916fa | 2015-05-04 09:05:13 -0600 | [diff] [blame] | 95 | { 'alternate': 'UserDefAlternate', |
Markus Armbruster | 4d2d5c4 | 2017-06-26 19:25:14 +0200 | [diff] [blame] | 96 | 'data': { 'udfu': 'UserDefFlatUnion', 'e': 'EnumOne', 'i': 'int', |
| 97 | 'n': 'null' } } |
Markus Armbruster | 2c38b60 | 2014-03-01 08:40:30 +0100 | [diff] [blame] | 98 | |
Markus Armbruster | 8c3f8e7 | 2015-06-26 10:19:11 +0200 | [diff] [blame] | 99 | { 'struct': 'UserDefC', |
| 100 | 'data': { 'string1': 'str', 'string2': 'str' } } |
| 101 | |
Eric Blake | 9c51b44 | 2015-09-29 16:21:06 -0600 | [diff] [blame] | 102 | # for testing use of 'number' within alternates |
Markus Armbruster | 8168ca8 | 2017-05-22 18:42:14 +0200 | [diff] [blame] | 103 | { 'alternate': 'AltEnumBool', 'data': { 'e': 'EnumOne', 'b': 'bool' } } |
| 104 | { 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } } |
Markus Armbruster | 8168ca8 | 2017-05-22 18:42:14 +0200 | [diff] [blame] | 105 | { 'alternate': 'AltNumEnum', 'data': { 'n': 'number', 'e': 'EnumOne' } } |
| 106 | { 'alternate': 'AltEnumInt', 'data': { 'e': 'EnumOne', 'i': 'int' } } |
Eric Blake | 9c51b44 | 2015-09-29 16:21:06 -0600 | [diff] [blame] | 107 | |
Markus Armbruster | c064477 | 2017-05-22 18:42:15 +0200 | [diff] [blame] | 108 | # for testing use of 'str' within alternates |
| 109 | { 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } } |
| 110 | |
Michael Roth | 83c8466 | 2013-05-10 17:46:09 -0500 | [diff] [blame] | 111 | # 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 Blake | cb17f79 | 2015-05-04 09:05:01 -0600 | [diff] [blame] | 124 | 'string': ['str'], |
Markus Armbruster | 28770e0 | 2015-09-16 13:06:24 +0200 | [diff] [blame] | 125 | 'sizes': ['size'], |
| 126 | 'any': ['any'] } } |
Michael Roth | 83c8466 | 2013-05-10 17:46:09 -0500 | [diff] [blame] | 127 | |
Michael Roth | 501e510 | 2011-07-19 14:50:43 -0500 | [diff] [blame] | 128 | # testing commands |
| 129 | { 'command': 'user_def_cmd', 'data': {} } |
| 130 | { 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} } |
Markus Armbruster | ab22ad9 | 2014-03-01 08:40:28 +0100 | [diff] [blame] | 131 | { 'command': 'user_def_cmd2', |
| 132 | 'data': {'ud1a': 'UserDefOne', '*ud1b': 'UserDefOne'}, |
| 133 | 'returns': 'UserDefTwo' } |
Eric Blake | cae95ea | 2015-10-12 22:22:25 -0600 | [diff] [blame] | 134 | |
| 135 | # Returning a non-dictionary requires a name from the whitelist |
| 136 | { 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' }, |
Markus Armbruster | c2216a8 | 2014-03-01 08:40:29 +0100 | [diff] [blame] | 137 | 'returns': 'int' } |
Markus Armbruster | 28770e0 | 2015-09-16 13:06:24 +0200 | [diff] [blame] | 138 | { 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' } |
Eric Blake | c818408 | 2016-07-13 21:50:20 -0600 | [diff] [blame] | 139 | { 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' } |
| 140 | { 'command': 'boxed-union', 'data': 'UserDefNativeListUnion', 'boxed': true } |
Laszlo Ersek | 3953e3a | 2013-08-20 00:35:40 +0200 | [diff] [blame] | 141 | |
| 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 Blake | 895a2a8 | 2015-05-04 09:05:27 -0600 | [diff] [blame] | 149 | { 'struct': 'UserDefOptions', |
Laszlo Ersek | 3953e3a | 2013-08-20 00:35:40 +0200 | [diff] [blame] | 150 | 'data': { |
| 151 | '*i64' : [ 'int' ], |
| 152 | '*u64' : [ 'uint64' ], |
| 153 | '*u16' : [ 'uint16' ], |
| 154 | '*i64x': 'int' , |
| 155 | '*u64x': 'uint64' } } |
Wenchao Xia | f6dadb0 | 2014-06-18 08:43:29 +0200 | [diff] [blame] | 156 | |
| 157 | # testing event |
Eric Blake | 895a2a8 | 2015-05-04 09:05:27 -0600 | [diff] [blame] | 158 | { 'struct': 'EventStructOne', |
Wenchao Xia | f6dadb0 | 2014-06-18 08:43:29 +0200 | [diff] [blame] | 159 | '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 Blake | c818408 | 2016-07-13 21:50:20 -0600 | [diff] [blame] | 168 | { 'event': 'EVENT_E', 'boxed': true, 'data': 'UserDefZero' } |
| 169 | { 'event': 'EVENT_F', 'boxed': true, 'data': 'UserDefAlternate' } |
Eric Blake | fce384b | 2015-05-14 06:50:56 -0600 | [diff] [blame] | 170 | |
Eric Blake | c43567c | 2015-11-18 01:52:52 -0700 | [diff] [blame] | 171 | # test that we correctly compile downstream extensions, as well as munge |
| 172 | # ticklish names |
Eric Blake | fce384b | 2015-05-14 06:50:56 -0600 | [diff] [blame] | 173 | { 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] } |
Eric Blake | 83a0270 | 2015-05-14 06:50:57 -0600 | [diff] [blame] | 174 | { '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 Blake | c43567c | 2015-11-18 01:52:52 -0700 | [diff] [blame] | 177 | 'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } } |
Eric Blake | bb33729 | 2015-05-14 06:50:58 -0600 | [diff] [blame] | 178 | { 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } } |
Eric Blake | 857af5f | 2015-05-14 06:50:59 -0600 | [diff] [blame] | 179 | { '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 Blake | d1f07c8 | 2015-05-14 06:51:00 -0600 | [diff] [blame] | 184 | { 'alternate': '__org.qemu_x-Alt', |
| 185 | 'data': { '__org.qemu_x-branch': 'str', 'b': '__org.qemu_x-Base' } } |
Eric Blake | e3c4c3d | 2015-05-14 06:51:01 -0600 | [diff] [blame] | 186 | { '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' } |