summaryrefslogtreecommitdiffstats
path: root/src/tools/vppapigen/test_vppapigen.py
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2020-11-24 23:26:06 -0500
committerOle Tr�an <otroan@employees.org>2020-12-04 09:40:27 +0000
commita51f9b3747d3e065b4bc7bb46aea8df11719b6cd (patch)
tree1f95c7a5f3c46f7741c836e183ec3d8dda937da7 /src/tools/vppapigen/test_vppapigen.py
parent86ffb6b232d5ebce03cf53249fa1514384f31cce (diff)
vppapigen: add parser support for enumflags
Type: improvement Change-Id: I0f15862cc8399a4f7c8a81fe44ba8b27d8772278 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com> Signed-off-by: Ole Troan <ot@cisco.com> (cherry picked from commit e15523297bb3905f2e0eef4272fc69a8a92463cc)
Diffstat (limited to 'src/tools/vppapigen/test_vppapigen.py')
-rwxr-xr-xsrc/tools/vppapigen/test_vppapigen.py101
1 files changed, 98 insertions, 3 deletions
diff --git a/src/tools/vppapigen/test_vppapigen.py b/src/tools/vppapigen/test_vppapigen.py
index 999addfccd2..c454ffc8638 100755
--- a/src/tools/vppapigen/test_vppapigen.py
+++ b/src/tools/vppapigen/test_vppapigen.py
@@ -1,9 +1,11 @@
#!/usr/bin/env python3
import unittest
-from vppapigen import VPPAPI, Option, ParseError, Union, foldup_crcs, global_types
+from vppapigen import VPPAPI, Option, ParseError, Union, foldup_crcs, \
+ global_types
import vppapigen
+
# TODO
# - test parsing of options, typedefs, enums, defines
# - test JSON, C output
@@ -19,6 +21,7 @@ class TestVersion(unittest.TestCase):
r = self.parser.parse_string(version_string)
self.assertTrue(isinstance(r[0], Option))
+
class TestUnion(unittest.TestCase):
@classmethod
def setUpClass(cls):
@@ -49,7 +52,6 @@ class TestUnion(unittest.TestCase):
self.assertTrue(r[0].vla)
s = self.parser.process(r)
-
test_string2 = '''
union foo_union_vla2 {
u32 a;
@@ -74,6 +76,7 @@ class TestUnion(unittest.TestCase):
'''
self.assertRaises(ValueError, self.parser.parse_string, test_string3)
+
class TestTypedef(unittest.TestCase):
@classmethod
def setUpClass(cls):
@@ -169,7 +172,7 @@ class TestCRC(unittest.TestCase):
'''
crc = get_crc(test_string, 'foo')
- # modify underlaying type
+ # modify underlying type
test_string = '''
typedef list { u8 foo2; };
autoreply define foo { u8 foo; vl_api_list_t l;};
@@ -255,5 +258,97 @@ autoreply define sr_policy_add
self.assertNotEqual(crc, crc2)
+
+class TestEnum(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.parser = VPPAPI()
+
+ def test_enum_as_enum(self):
+ test_string = """\
+enum tunnel_mode : u8
+{
+ /** point-to-point */
+ TUNNEL_API_MODE_P2P = 0,
+ /** multi-point */
+ TUNNEL_API_MODE_MP,
+};
+"""
+ r = self.parser.parse_string(test_string)
+ self.assertIsNotNone(r)
+ s = self.parser.process(r)
+ for o in s['types']:
+ if o.type == 'Enum':
+ self.assertEqual(o.name, "tunnel_mode")
+ break
+ else:
+ self.fail()
+
+ def test_enumflag_as_enum(self):
+ test_string = """\
+enum virtio_flags {
+ VIRTIO_API_FLAG_GSO = 1, /* enable gso on the interface */
+ VIRTIO_API_FLAG_CSUM_OFFLOAD = 2, /* enable checksum offload without gso on the interface */
+ VIRTIO_API_FLAG_GRO_COALESCE = 4, /* enable packet coalescing on tx side, provided gso enabled */
+ VIRTIO_API_FLAG_PACKED = 8, /* enable packed ring support, provided it is available from backend */
+ VIRTIO_API_FLAG_IN_ORDER = 16, /* enable in order support, provided it is available from backend */
+ VIRTIO_API_FLAG_BUFFERING = 32 [backwards_compatible], /* enable buffering to handle backend jitter/delays */
+};"""
+ r = self.parser.parse_string(test_string)
+ self.assertIsNotNone(r)
+ s = self.parser.process(r)
+ for o in s['types']:
+ if o.type == 'Enum':
+ self.assertEqual(o.name, "virtio_flags")
+ break
+ else:
+ self.fail()
+
+
+class TestEnumFlag(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.parser = VPPAPI()
+
+ def test_enum_as_enumflag(self):
+ test_string = """\
+enumflag tunnel_mode_ef : u8
+{
+ /** point-to-point */
+ TUNNEL_API_MODE_P2P = 0,
+ /** multi-point */
+ TUNNEL_API_MODE_MP,
+ TUNNEL_API_MODE_FOO,
+ TUNNEL_API_MODE_BAR,
+};"""
+ with self.assertRaises(TypeError) as ctx:
+ r = self.parser.parse_string(test_string)
+
+ self.assertTrue(str(ctx.exception).startswith(
+ 'tunnel_mode_ef is not a flag enum.'))
+
+ def test_enumflag_as_enumflag(self):
+ test_string = """\
+enumflag virtio_flags_ef {
+ VIRTIO_API_FLAG_GSO = 1, /* enable gso on the interface */
+ VIRTIO_API_FLAG_CSUM_OFFLOAD = 2, /* enable checksum offload without gso on the interface */
+ VIRTIO_API_FLAG_GRO_COALESCE = 4, /* enable packet coalescing on tx side, provided gso enabled */
+ VIRTIO_API_FLAG_PACKED = 8, /* enable packed ring support, provided it is available from backend */
+ VIRTIO_API_FLAG_IN_ORDER = 16, /* enable in order support, provided it is available from backend */
+ VIRTIO_API_FLAG_BUFFERING = 32 [backwards_compatible], /* enable buffering to handle backend jitter/delays */
+};"""
+ r = self.parser.parse_string(test_string)
+ self.assertIsNotNone(r)
+ s = self.parser.process(r)
+ for o in s['types']:
+ if o.type == 'EnumFlag':
+ self.assertEqual(o.name, "virtio_flags_ef")
+ break
+ else:
+ self.fail()
+
+
if __name__ == '__main__':
unittest.main(verbosity=2)