qemu-img: fix error reporting for -object
[qemu/ar7.git] / tests / qapi-schema / test-qapi.py
blobd5928546011c4cf1d5da352336446246b028b829
2 # QAPI parser test harness
4 # Copyright (c) 2013 Red Hat Inc.
6 # Authors:
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
14 import sys
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, members, prefix):
27 print('enum %s' % name)
28 if prefix:
29 print(' prefix %s' % prefix)
30 for m in members:
31 print(' member %s' % m.name)
32 self._print_if(m.ifcond, indent=8)
33 self._print_if(ifcond)
35 def visit_object_type(self, name, info, ifcond, base, members, variants):
36 print('object %s' % name)
37 if base:
38 print(' base %s' % base.name)
39 for m in members:
40 print(' member %s: %s optional=%s'
41 % (m.name, m.type.name, m.optional))
42 self._print_if(m.ifcond, 8)
43 self._print_variants(variants)
44 self._print_if(ifcond)
46 def visit_alternate_type(self, name, info, ifcond, variants):
47 print('alternate %s' % name)
48 self._print_variants(variants)
49 self._print_if(ifcond)
51 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen,
52 success_response, boxed, allow_oob, allow_preconfig):
53 print('command %s %s -> %s'
54 % (name, arg_type and arg_type.name,
55 ret_type and ret_type.name))
56 print(' gen=%s success_response=%s boxed=%s oob=%s preconfig=%s'
57 % (gen, success_response, boxed, allow_oob, allow_preconfig))
58 self._print_if(ifcond)
60 def visit_event(self, name, info, ifcond, arg_type, boxed):
61 print('event %s %s' % (name, arg_type and arg_type.name))
62 print(' boxed=%s' % boxed)
63 self._print_if(ifcond)
65 @staticmethod
66 def _print_variants(variants):
67 if variants:
68 print(' tag %s' % variants.tag_member.name)
69 for v in variants.variants:
70 print(' case %s: %s' % (v.name, v.type.name))
71 QAPISchemaTestVisitor._print_if(v.ifcond, indent=8)
73 @staticmethod
74 def _print_if(ifcond, indent=4):
75 if ifcond:
76 print('%sif %s' % (' ' * indent, ifcond))
79 try:
80 schema = QAPISchema(sys.argv[1])
81 except QAPIError as err:
82 print(err, file=sys.stderr)
83 exit(1)
85 schema.visit(QAPISchemaTestVisitor())
87 for doc in schema.docs:
88 if doc.symbol:
89 print('doc symbol=%s' % doc.symbol)
90 else:
91 print('doc freeform')
92 print(' body=\n%s' % doc.body.text)
93 for arg, section in doc.args.items():
94 print(' arg=%s\n%s' % (arg, section.text))
95 for section in doc.sections:
96 print(' section=%s\n%s' % (section.name, section.text))