aboutsummaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi/tests
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2020-12-03 21:06:28 -0500
committerOle Tr�an <otroan@employees.org>2020-12-04 12:14:34 +0000
commit3825d93afeed42e62e41f743df69058511c51079 (patch)
tree5affb734a1f5750c085c74df20ee07c61a87a676 /src/vpp-api/python/vpp_papi/tests
parenta51f9b3747d3e065b4bc7bb46aea8df11719b6cd (diff)
papi: add support for enumflag part 1 of 2
Allow for papi to accept the new enumflag type. Change-Id: I8d8dc8fdb122e9a1b1881f5b2558635c75e4a299 Type: feature Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com> (cherry picked from commit 299abebe2942b4c78b85f9f3b8843f8213bf1efe)
Diffstat (limited to 'src/vpp-api/python/vpp_papi/tests')
-rw-r--r--src/vpp-api/python/vpp_papi/tests/test_vpp_papi.py121
-rwxr-xr-xsrc/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py5
2 files changed, 122 insertions, 4 deletions
diff --git a/src/vpp-api/python/vpp_papi/tests/test_vpp_papi.py b/src/vpp-api/python/vpp_papi/tests/test_vpp_papi.py
index 7effe68692b..99acb7c7469 100644
--- a/src/vpp-api/python/vpp_papi/tests/test_vpp_papi.py
+++ b/src/vpp-api/python/vpp_papi/tests/test_vpp_papi.py
@@ -23,7 +23,6 @@ from vpp_papi import vpp_transport_shmem
class TestVppPapiVPPApiClient(unittest.TestCase):
-
def test_getcontext(self):
vpp_papi.VPPApiClient.apidir = '.'
c = vpp_papi.VPPApiClient(testmode=True, use_socket=True)
@@ -57,7 +56,6 @@ class TestVppPapiVPPApiClientMp(unittest.TestCase):
class TestVppTypes(unittest.TestCase):
-
def test_enum_from_json(self):
json_api = """\
{
@@ -114,9 +112,126 @@ class TestVppTypes(unittest.TestCase):
self.assertTrue(str(t).startswith("VPPEnumType"))
self.assertEqual(t.name, type_name)
+ def test_enumflagmixed_from_json(self):
+ json_api = """\
+{
+ "enums": [
-class TestVppPapiLogging(unittest.TestCase):
+ [
+ "address_family",
+ [
+ "ADDRESS_IP4",
+ 0
+ ],
+ [
+ "ADDRESS_IP6",
+ 1
+ ],
+ {
+ "enumtype": "u8"
+ }
+ ]
+ ],
+ "enumflags": [
+
+ [
+ "if_type",
+ [
+ "IF_API_TYPE_HARDWARE",
+ 0
+ ],
+ [
+ "IF_API_TYPE_SUB",
+ 1
+ ],
+ [
+ "IF_API_TYPE_P2P",
+ 2
+ ],
+ [
+ "IF_API_TYPE_PIPE",
+ 3
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ]
+ ]
+}
+"""
+
+ processor = vpp_papi.VPPApiJSONFiles()
+
+ # add the types to vpp_serializer
+ processor.process_json_str(json_api)
+
+ vpp_transport_shmem.VppTransport = mock.MagicMock()
+ ac = vpp_papi.VPPApiClient(apifiles=[], testmode=True)
+ print(ac)
+ type_name = "vl_api_if_type_t"
+ t = ac.get_type(type_name)
+ print(t)
+ self.assertTrue(str(t).startswith("VPPEnumType"))
+ self.assertEqual(t.name, type_name)
+
+ def test_enumflag_from_json(self):
+ json_api = """\
+{
+ "enumflags": [
+ [
+ "address_family",
+ [
+ "ADDRESS_IP4",
+ 0
+ ],
+ [
+ "ADDRESS_IP6",
+ 1
+ ],
+ {
+ "enumtype": "u8"
+ }
+ ],
+ [
+ "if_type",
+ [
+ "IF_API_TYPE_HARDWARE",
+ 0
+ ],
+ [
+ "IF_API_TYPE_SUB",
+ 1
+ ],
+ [
+ "IF_API_TYPE_P2P",
+ 2
+ ],
+ [
+ "IF_API_TYPE_PIPE",
+ 3
+ ],
+ {
+ "enumtype": "u32"
+ }
+ ]
+ ]
+}
+"""
+ processor = vpp_papi.VPPApiJSONFiles()
+
+ # add the types to vpp_serializer
+ processor.process_json_str(json_api)
+
+ vpp_transport_shmem.VppTransport = mock.MagicMock()
+ ac = vpp_papi.VPPApiClient(apifiles=[], testmode=True)
+ type_name = "vl_api_if_type_t"
+ t = ac.get_type(type_name)
+ self.assertTrue(str(t).startswith("VPPEnumType"))
+ self.assertEqual(t.name, type_name)
+
+
+class TestVppPapiLogging(unittest.TestCase):
def test_logger(self):
class Transport:
connected = True
diff --git a/src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py b/src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py
index 21b23bdf6c2..c9b3d672d6a 100755
--- a/src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py
+++ b/src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
import unittest
-from vpp_papi.vpp_serializer import VPPType, VPPEnumType
+from vpp_papi.vpp_serializer import VPPType, VPPEnumType, VPPEnumFlagType
from vpp_papi.vpp_serializer import VPPUnionType, VPPMessage
from vpp_papi.vpp_serializer import VPPTypeAlias, VPPSerializerValueError
from vpp_papi import MACAddress
@@ -122,6 +122,9 @@ class TestAddType(unittest.TestCase):
af = VPPEnumType('vl_api_address_family_t', [["ADDRESS_IP4", 0],
["ADDRESS_IP6", 1],
{"enumtype": "u32"}])
+ aff = VPPEnumFlagType('vl_api_address_family_flag_t', [["ADDRESS_IP4", 0],
+ ["ADDRESS_IP6", 1],
+ {"enumtype": "u32"}])
ip4 = VPPTypeAlias('vl_api_ip4_address_t', {'type': 'u8',
'length': 4})
ip6 = VPPTypeAlias('vl_api_ip6_address_t', {'type': 'u8',