2013-07-27 19:41:53 +04:00
|
|
|
#
|
|
|
|
# QAPI parser test harness
|
|
|
|
#
|
|
|
|
# Copyright (c) 2013 Red Hat Inc.
|
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Markus Armbruster <armbru@redhat.com>
|
|
|
|
#
|
|
|
|
# This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
# See the COPYING file in the top-level directory.
|
|
|
|
#
|
|
|
|
|
2018-01-16 16:42:04 +03:00
|
|
|
from __future__ import print_function
|
2013-07-27 19:41:53 +04:00
|
|
|
import sys
|
2018-02-11 12:35:51 +03:00
|
|
|
from qapi.common import QAPIError, QAPISchema, QAPISchemaVisitor
|
2013-07-27 19:41:53 +04:00
|
|
|
|
2015-09-16 14:06:08 +03:00
|
|
|
|
|
|
|
class QAPISchemaTestVisitor(QAPISchemaVisitor):
|
2018-02-11 12:35:55 +03:00
|
|
|
|
|
|
|
def visit_module(self, name):
|
|
|
|
print('module %s' % name)
|
|
|
|
|
|
|
|
def visit_include(self, name, info):
|
|
|
|
print('include %s' % name)
|
|
|
|
|
2015-09-16 14:06:08 +03:00
|
|
|
def visit_enum_type(self, name, info, values, prefix):
|
2018-01-16 16:42:04 +03:00
|
|
|
print('enum %s %s' % (name, values))
|
2015-09-16 14:06:08 +03:00
|
|
|
if prefix:
|
2018-01-16 16:42:04 +03:00
|
|
|
print(' prefix %s' % prefix)
|
2015-09-16 14:06:08 +03:00
|
|
|
|
|
|
|
def visit_object_type(self, name, info, base, members, variants):
|
2018-01-16 16:42:04 +03:00
|
|
|
print('object %s' % name)
|
2015-09-16 14:06:08 +03:00
|
|
|
if base:
|
2018-01-16 16:42:04 +03:00
|
|
|
print(' base %s' % base.name)
|
2015-09-16 14:06:08 +03:00
|
|
|
for m in members:
|
2018-01-16 16:42:04 +03:00
|
|
|
print(' member %s: %s optional=%s' % \
|
|
|
|
(m.name, m.type.name, m.optional))
|
2015-09-16 14:06:08 +03:00
|
|
|
self._print_variants(variants)
|
|
|
|
|
|
|
|
def visit_alternate_type(self, name, info, variants):
|
2018-01-16 16:42:04 +03:00
|
|
|
print('alternate %s' % name)
|
2015-09-16 14:06:08 +03:00
|
|
|
self._print_variants(variants)
|
|
|
|
|
|
|
|
def visit_command(self, name, info, arg_type, ret_type,
|
2018-03-09 12:00:00 +03:00
|
|
|
gen, success_response, boxed, allow_oob):
|
2018-01-16 16:42:04 +03:00
|
|
|
print('command %s %s -> %s' % \
|
|
|
|
(name, arg_type and arg_type.name, ret_type and ret_type.name))
|
2018-03-26 09:38:58 +03:00
|
|
|
print(' gen=%s success_response=%s boxed=%s oob=%s' % \
|
|
|
|
(gen, success_response, boxed, allow_oob))
|
2015-09-16 14:06:08 +03:00
|
|
|
|
2016-07-14 06:50:19 +03:00
|
|
|
def visit_event(self, name, info, arg_type, boxed):
|
2018-01-16 16:42:04 +03:00
|
|
|
print('event %s %s' % (name, arg_type and arg_type.name))
|
|
|
|
print(' boxed=%s' % boxed)
|
2015-09-16 14:06:08 +03:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _print_variants(variants):
|
|
|
|
if variants:
|
2018-01-16 16:42:04 +03:00
|
|
|
print(' tag %s' % variants.tag_member.name)
|
2015-09-16 14:06:08 +03:00
|
|
|
for v in variants.variants:
|
2018-01-16 16:42:04 +03:00
|
|
|
print(' case %s: %s' % (v.name, v.type.name))
|
2015-09-16 14:06:08 +03:00
|
|
|
|
2018-02-11 12:35:51 +03:00
|
|
|
|
|
|
|
try:
|
|
|
|
schema = QAPISchema(sys.argv[1])
|
|
|
|
except QAPIError as err:
|
|
|
|
print(err, file=sys.stderr)
|
|
|
|
exit(1)
|
|
|
|
|
2015-09-16 14:06:08 +03:00
|
|
|
schema.visit(QAPISchemaTestVisitor())
|
2017-03-20 16:11:53 +03:00
|
|
|
|
|
|
|
for doc in schema.docs:
|
|
|
|
if doc.symbol:
|
2018-01-16 16:42:04 +03:00
|
|
|
print('doc symbol=%s' % doc.symbol)
|
2017-03-20 16:11:53 +03:00
|
|
|
else:
|
2018-01-16 16:42:04 +03:00
|
|
|
print('doc freeform')
|
|
|
|
print(' body=\n%s' % doc.body.text)
|
2018-01-16 16:42:05 +03:00
|
|
|
for arg, section in doc.args.items():
|
2018-01-16 16:42:04 +03:00
|
|
|
print(' arg=%s\n%s' % (arg, section.text))
|
2017-03-20 16:11:53 +03:00
|
|
|
for section in doc.sections:
|
2018-01-16 16:42:04 +03:00
|
|
|
print(' section=%s\n%s' % (section.name, section.text))
|