From 9d42087149a6870965896be74dc6260f72d2cac9 Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Thu, 12 Oct 2017 13:06:35 +0200 Subject: VPPAPIGEN: vppapigen replacement in Python PLY. This is a version of the VPP API generator in Python PLY. It supports the existing language, and has a plugin architecture for generators. Currently C and JSON are supported. Changes: - vl_api_version to option version = "major.minor.patch" - enum support - Added error checking and reporting - import support (removed the C pre-processor) - services (tying request/reply together) Version: option version = "1.0.0"; Enum: enum colours { RED, BLUE = 50, }; define foo { vl_api_colours_t colours; }; Services: service { rpc foo returns foo_reply; rpc foo_dump returns stream foo_details; rpc want_stats returns want_stats_reply events ip4_counters, ip6_counters; }; Future planned features: - unions - bool, text - array support (including length) - proto3 output plugin - Refactor C/C++ generator as a plugin - Refactor Java generator as a plugin Change-Id: Ifa289966c790e1b1a8e2938a91e69331e3a58bdf Signed-off-by: Ole Troan --- src/tools/vppapigen/test_vppapigen.py | 80 +++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 src/tools/vppapigen/test_vppapigen.py (limited to 'src/tools/vppapigen/test_vppapigen.py') diff --git a/src/tools/vppapigen/test_vppapigen.py b/src/tools/vppapigen/test_vppapigen.py new file mode 100755 index 00000000000..09187f4c965 --- /dev/null +++ b/src/tools/vppapigen/test_vppapigen.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python + +import unittest +from vppapigen import VPPAPI, Option, ParseError + +# TODO +# - test parsing of options, typedefs, enums, defines, CRC +# - test JSON, C output + + +class TestVersion(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.parser = VPPAPI() + + def test_version(self): + version_string = 'option version = "1.0.0";' + r = self.parser.parse_string(version_string) + self.assertTrue(isinstance(r[0], Option)) + + +class TestTypedef(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.parser = VPPAPI() + + def test_duplicatetype(self): + test_string = ''' + typeonly define foo1 { u8 dummy; }; + typeonly define foo1 { u8 dummy; }; + ''' + self.assertRaises(KeyError, self.parser.parse_string, test_string) + + +class TestDefine(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.parser = VPPAPI() + + def test_unknowntype(self): + test_string = 'define foo { foobar foo;};' + self.assertRaises(ParseError, self.parser.parse_string, test_string) + test_string = 'define { u8 foo;};' + self.assertRaises(ParseError, self.parser.parse_string, test_string) + + def test_flags(self): + test_string = ''' + manual_print dont_trace manual_endian define foo { u8 foo; }; + ''' + r = self.parser.parse_string(test_string) + self.assertIsNotNone(r) + s = self.parser.process(r) + self.assertIsNotNone(s) + for d in s['defines']: + self.assertTrue(d.dont_trace) + self.assertTrue(d.manual_endian) + self.assertTrue(d.manual_print) + self.assertFalse(d.autoreply) + + test_string = ''' + nonexisting_flag define foo { u8 foo; }; + ''' + self.assertRaises(ParseError, self.parser.parse_string, test_string) + + +class TestService(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.parser = VPPAPI() + + def test_service(self): + test_string = ''' + service foo { rpc foo (show_version) returns (show_version) }; + ''' + r = self.parser.parse_string(test_string) + print('R', r) + + +if __name__ == '__main__': + unittest.main() -- cgit 1.2.3-korg