qapi-schema-test.json 3.7 KB
Newer Older
1 2 3 4 5
# *-*- Mode: Python -*-*

# for testing enums
{ 'enum': 'EnumOne',
  'data': [ 'value1', 'value2', 'value3' ] }
6
{ 'struct': 'NestedEnumsOne',
7 8 9
  'data': { 'enum1': 'EnumOne', '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } }

# for testing nested structs
10
{ 'struct': 'UserDefZero',
11 12
  'data': { 'integer': 'int' } }

13
{ 'struct': 'UserDefOne',
14 15
  'base': 'UserDefZero',
  'data': { 'string': 'str', '*enum1': 'EnumOne' } }
16

17 18 19 20 21 22 23 24
{ 'struct': 'UserDefTwoDictDict',
  'data': { 'userdef': 'UserDefOne', 'string': 'str' } }

{ 'struct': 'UserDefTwoDict',
  'data': { 'string1': 'str',
            'dict2': 'UserDefTwoDictDict',
            '*dict3': 'UserDefTwoDictDict' } }

25
{ 'struct': 'UserDefTwo',
26
  'data': { 'string0': 'str',
27
            'dict1': 'UserDefTwoDict' } }
28

29
# for testing unions
30
{ 'struct': 'UserDefA',
31 32
  'data': { 'boolean': 'bool' } }

33
{ 'struct': 'UserDefB',
34 35
  'data': { 'integer': 'int' } }

36
{ 'struct': 'UserDefC',
37 38
  'data': { 'string1': 'str', 'string2': 'str' } }

39
{ 'struct': 'UserDefUnionBase',
40 41
  'data': { 'string': 'str', 'enum1': 'EnumOne' } }

42
{ 'union': 'UserDefFlatUnion',
43 44 45
  'base': 'UserDefUnionBase',
  'discriminator': 'enum1',
  'data': { 'value1' : 'UserDefA', 'value2' : 'UserDefB', 'value3' : 'UserDefB' } }
46 47 48
# FIXME generated struct UserDefFlatUnion has members for direct base
# UserDefOne, but lacks members for indirect base UserDefZero

49 50 51 52 53 54 55
# this variant of UserDefFlatUnion defaults to a union that uses fields with
# allocated types to test corner cases in the cleanup/dealloc visitor
{ 'union': 'UserDefFlatUnion2',
  'base': 'UserDefUnionBase',
  'discriminator': 'enum1',
  'data': { 'value1' : 'UserDefC', 'value2' : 'UserDefB', 'value3' : 'UserDefA' } }

56
{ 'alternate': 'UserDefAlternate',
57 58
  'data': { 'uda': 'UserDefA', 's': 'str', 'i': 'int' } }

59 60 61 62 63 64 65 66 67 68 69 70 71
# for testing native lists
{ 'union': 'UserDefNativeListUnion',
  'data': { 'integer': ['int'],
            's8': ['int8'],
            's16': ['int16'],
            's32': ['int32'],
            's64': ['int64'],
            'u8': ['uint8'],
            'u16': ['uint16'],
            'u32': ['uint32'],
            'u64': ['uint64'],
            'number': ['number'],
            'boolean': ['bool'],
72 73
            'string': ['str'],
            'sizes': ['size'] } }
74

75 76 77
# testing commands
{ 'command': 'user_def_cmd', 'data': {} }
{ 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} }
78 79 80
{ 'command': 'user_def_cmd2',
  'data': {'ud1a': 'UserDefOne', '*ud1b': 'UserDefOne'},
  'returns': 'UserDefTwo' }
81 82
{ 'command': 'user_def_cmd3', 'data': {'a': 'int', '*b': 'int' },
  'returns': 'int' }
83 84 85 86 87 88 89 90

# For testing integer range flattening in opts-visitor. The following schema
# corresponds to the option format:
#
# -userdef i64=3-6,i64=-5--1,u64=2,u16=1,u16=7-12
#
# For simplicity, this example doesn't use [type=]discriminator nor optargs
# specific to discriminator values.
91
{ 'struct': 'UserDefOptions',
92 93 94 95 96 97
  'data': {
    '*i64' : [ 'int'    ],
    '*u64' : [ 'uint64' ],
    '*u16' : [ 'uint16' ],
    '*i64x':   'int'     ,
    '*u64x':   'uint64'  } }
98 99

# testing event
100
{ 'struct': 'EventStructOne',
101 102 103 104 105 106 107 108 109
  'data': { 'struct1': 'UserDefOne', 'string': 'str', '*enum2': 'EnumOne' } }

{ 'event': 'EVENT_A' }
{ 'event': 'EVENT_B',
  'data': { } }
{ 'event': 'EVENT_C',
  'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
{ 'event': 'EVENT_D',
  'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } }
E
Eric Blake 已提交
110 111 112

# test that we correctly compile downstream extensions
{ 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
E
Eric Blake 已提交
113 114 115 116
{ 'struct': '__org.qemu_x-Base',
  'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
  'data': { '__org.qemu_x-member2': 'str' } }
117
{ 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }