test-qapi.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. from qapi import *
  13. from pprint import pprint
  14. import os
  15. import sys
  16. class QAPISchemaTestVisitor(QAPISchemaVisitor):
  17. def visit_enum_type(self, name, info, values, prefix):
  18. print 'enum %s %s' % (name, values)
  19. if prefix:
  20. print ' prefix %s' % prefix
  21. def visit_object_type(self, name, info, base, members, variants):
  22. print 'object %s' % name
  23. if base:
  24. print ' base %s' % base.name
  25. for m in members:
  26. print ' member %s: %s optional=%s' % \
  27. (m.name, m.type.name, m.optional)
  28. self._print_variants(variants)
  29. def visit_alternate_type(self, name, info, variants):
  30. print 'alternate %s' % name
  31. self._print_variants(variants)
  32. def visit_command(self, name, info, arg_type, ret_type,
  33. gen, success_response, boxed):
  34. print 'command %s %s -> %s' % \
  35. (name, arg_type and arg_type.name, ret_type and ret_type.name)
  36. print ' gen=%s success_response=%s boxed=%s' % \
  37. (gen, success_response, boxed)
  38. def visit_event(self, name, info, arg_type, boxed):
  39. print 'event %s %s' % (name, arg_type and arg_type.name)
  40. print ' boxed=%s' % boxed
  41. @staticmethod
  42. def _print_variants(variants):
  43. if variants:
  44. print ' tag %s' % variants.tag_member.name
  45. for v in variants.variants:
  46. print ' case %s: %s' % (v.name, v.type.name)
  47. schema = QAPISchema(sys.argv[1])
  48. schema.visit(QAPISchemaTestVisitor())