]>
git.proxmox.com Git - mirror_qemu.git/blob - tests/qapi-schema/test-qapi.py
2 # QAPI parser test harness
4 # Copyright (c) 2013 Red Hat Inc.
7 # Markus Armbruster <armbru@redhat.com>
9 # This work is licensed under the terms of the GNU GPL, version 2 or later.
10 # See the COPYING file in the top-level directory.
13 from __future__
import print_function
15 from qapi
.common
import QAPIError
, QAPISchema
, QAPISchemaVisitor
18 class QAPISchemaTestVisitor(QAPISchemaVisitor
):
20 def visit_module(self
, name
):
21 print('module %s' % name
)
23 def visit_include(self
, name
, info
):
24 print('include %s' % name
)
26 def visit_enum_type(self
, name
, info
, ifcond
, values
, prefix
):
27 print('enum %s %s' % (name
, values
))
29 print(' prefix %s' % prefix
)
30 self
._print
_if
(ifcond
)
32 def visit_object_type(self
, name
, info
, ifcond
, base
, members
, variants
):
33 print('object %s' % name
)
35 print(' base %s' % base
.name
)
37 print(' member %s: %s optional=%s' % \
38 (m
.name
, m
.type.name
, m
.optional
))
39 self
._print
_variants
(variants
)
40 self
._print
_if
(ifcond
)
42 def visit_alternate_type(self
, name
, info
, ifcond
, variants
):
43 print('alternate %s' % name
)
44 self
._print
_variants
(variants
)
45 self
._print
_if
(ifcond
)
47 def visit_command(self
, name
, info
, ifcond
, arg_type
, ret_type
, gen
,
48 success_response
, boxed
, allow_oob
, allow_preconfig
):
49 print('command %s %s -> %s' % \
50 (name
, arg_type
and arg_type
.name
, ret_type
and ret_type
.name
))
51 print(' gen=%s success_response=%s boxed=%s oob=%s preconfig=%s' % \
52 (gen
, success_response
, boxed
, allow_oob
, allow_preconfig
))
53 self
._print
_if
(ifcond
)
55 def visit_event(self
, name
, info
, ifcond
, arg_type
, boxed
):
56 print('event %s %s' % (name
, arg_type
and arg_type
.name
))
57 print(' boxed=%s' % boxed
)
58 self
._print
_if
(ifcond
)
61 def _print_variants(variants
):
63 print(' tag %s' % variants
.tag_member
.name
)
64 for v
in variants
.variants
:
65 print(' case %s: %s' % (v
.name
, v
.type.name
))
68 def _print_if(ifcond
, indent
=4):
70 print('%sif %s' % (' ' * indent
, ifcond
))
74 schema
= QAPISchema(sys
.argv
[1])
75 except QAPIError
as err
:
76 print(err
, file=sys
.stderr
)
79 schema
.visit(QAPISchemaTestVisitor())
81 for doc
in schema
.docs
:
83 print('doc symbol=%s' % doc
.symbol
)
86 print(' body=\n%s' % doc
.body
.text
)
87 for arg
, section
in doc
.args
.items():
88 print(' arg=%s\n%s' % (arg
, section
.text
))
89 for section
in doc
.sections
:
90 print(' section=%s\n%s' % (section
.name
, section
.text
))