]> git.proxmox.com Git - mirror_qemu.git/blame - tests/qapi-schema/test-qapi.py
qapi-gen: New common driver for code and doc generators
[mirror_qemu.git] / tests / qapi-schema / test-qapi.py
CommitLineData
98626572
MA
1#
2# QAPI parser test harness
3#
4# Copyright (c) 2013 Red Hat Inc.
5#
6# Authors:
7# Markus Armbruster <armbru@redhat.com>
8#
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.
11#
12
ef9d9108 13from __future__ import print_function
98626572 14import sys
fb0bc835 15from qapi.common import QAPISchema, QAPISchemaVisitor
98626572 16
156402e5
MA
17
18class QAPISchemaTestVisitor(QAPISchemaVisitor):
19 def visit_enum_type(self, name, info, values, prefix):
ef9d9108 20 print('enum %s %s' % (name, values))
156402e5 21 if prefix:
ef9d9108 22 print(' prefix %s' % prefix)
156402e5
MA
23
24 def visit_object_type(self, name, info, base, members, variants):
ef9d9108 25 print('object %s' % name)
156402e5 26 if base:
ef9d9108 27 print(' base %s' % base.name)
156402e5 28 for m in members:
ef9d9108
DB
29 print(' member %s: %s optional=%s' % \
30 (m.name, m.type.name, m.optional))
156402e5
MA
31 self._print_variants(variants)
32
33 def visit_alternate_type(self, name, info, variants):
ef9d9108 34 print('alternate %s' % name)
156402e5
MA
35 self._print_variants(variants)
36
37 def visit_command(self, name, info, arg_type, ret_type,
48825ca4 38 gen, success_response, boxed):
ef9d9108
DB
39 print('command %s %s -> %s' % \
40 (name, arg_type and arg_type.name, ret_type and ret_type.name))
41 print(' gen=%s success_response=%s boxed=%s' % \
42 (gen, success_response, boxed))
156402e5 43
48825ca4 44 def visit_event(self, name, info, arg_type, boxed):
ef9d9108
DB
45 print('event %s %s' % (name, arg_type and arg_type.name))
46 print(' boxed=%s' % boxed)
156402e5
MA
47
48 @staticmethod
49 def _print_variants(variants):
50 if variants:
ef9d9108 51 print(' tag %s' % variants.tag_member.name)
156402e5 52 for v in variants.variants:
ef9d9108 53 print(' case %s: %s' % (v.name, v.type.name))
156402e5
MA
54
55schema = QAPISchema(sys.argv[1])
56schema.visit(QAPISchemaTestVisitor())
818c3318
MA
57
58for doc in schema.docs:
59 if doc.symbol:
ef9d9108 60 print('doc symbol=%s' % doc.symbol)
818c3318 61 else:
ef9d9108
DB
62 print('doc freeform')
63 print(' body=\n%s' % doc.body.text)
2f848044 64 for arg, section in doc.args.items():
ef9d9108 65 print(' arg=%s\n%s' % (arg, section.text))
818c3318 66 for section in doc.sections:
ef9d9108 67 print(' section=%s\n%s' % (section.name, section.text))