summaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/vpp-api/python/vpp_papi/tests')
-rwxr-xr-xsrc/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py64
1 files changed, 62 insertions, 2 deletions
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 4e8a417c6fd..4b47e1eca7d 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
@@ -3,6 +3,7 @@
import unittest
from vpp_papi.vpp_serializer import VPPType, VPPEnumType
from vpp_papi.vpp_serializer import VPPUnionType, VPPMessage
+from vpp_papi.vpp_format import VPPFormat
from socket import inet_pton, AF_INET, AF_INET6
import logging
import sys
@@ -89,6 +90,65 @@ class TestAddType(unittest.TestCase):
nt, size = message_with_va_address_list.unpack(b)
self.assertEqual(nt.is_cool, 100)
+ def test_recursive_address(self):
+ af = VPPEnumType('vl_api_address_family_t', [["ADDRESS_IP4", 0],
+ ["ADDRESS_IP6", 1],
+ {"enumtype": "u32"}])
+ ip4 = VPPType('vl_api_ip4_address_t', [['u8', 'address', 4]])
+ ip6 = VPPType('vl_api_ip6_address_t', [['u8', 'address', 16]])
+ VPPUnionType('vl_api_address_union_t',
+ [["vl_api_ip4_address_t", "ip4"],
+ ["vl_api_ip6_address_t", "ip6"]])
+
+ address = VPPType('vl_api_address_t',
+ [['vl_api_address_family_t', 'af'],
+ ['vl_api_address_union_t', 'un']])
+
+ prefix = VPPType('vl_api_prefix_t',
+ [['vl_api_address_t', 'address'],
+ ['u8', 'address_length']])
+ message = VPPMessage('svs',
+ [['vl_api_prefix_t', 'prefix']])
+ message_addr = VPPMessage('svs_address',
+ [['vl_api_address_t', 'address']])
+
+
+ b = message_addr.pack({'address': "1::1"})
+ self.assertEqual(len(b), 20)
+ nt, size = message_addr.unpack(b)
+ self.assertEqual("1::1", VPPFormat.unformat(nt.address))
+ b = message_addr.pack({'address': "1.1.1.1"})
+ self.assertEqual(len(b), 20)
+ nt, size = message_addr.unpack(b)
+ self.assertEqual("1.1.1.1", VPPFormat.unformat(nt.address))
+
+ b = message.pack({'prefix': "1.1.1.1/24"})
+ self.assertEqual(len(b), 21)
+ nt, size = message.unpack(b)
+ self.assertEqual("1.1.1.1/24", VPPFormat.unformat(nt.prefix))
+
+ def test_zero_vla(self):
+ '''Default zero'ed out for VLAs'''
+ list = VPPType('vl_api_list_t',
+ [['u8', 'count', 10]])
+
+ # Define an embedded VLA type
+ valist = VPPType('vl_api_valist_t',
+ [['u8', 'count'],
+ ['u8', 'string', 0, 'count']])
+ # Define a message
+ vamessage = VPPMessage('vamsg',
+ [['vl_api_valist_t', 'valist'],
+ ['u8', 'is_something']])
+
+ message = VPPMessage('msg',
+ [['vl_api_list_t', 'list'],
+ ['u8', 'is_something']])
+
+ # Pack message without VLA specified
+ b = message.pack({'is_something': 1})
+ b = vamessage.pack({'is_something': 1})
+
def test_arrays(self):
# Test cases
# 1. Fixed list
@@ -133,7 +193,7 @@ class TestAddType(unittest.TestCase):
inet_pton(AF_INET, '2.2.2.2'))
string = 'foobar foobar'
- b = s.pack({'length': len(string), 'string': string})
+ b = s.pack({'length': len(string), 'string': string.encode()})
nt, size = s.unpack(b)
self.assertEqual(len(b), size)
@@ -142,7 +202,7 @@ class TestAddType(unittest.TestCase):
['u8', 'string', 0, 'length']])
string = ''
- b = s.pack({'length': len(string), 'string': string})
+ b = s.pack({'length': len(string), 'string': string.encode()})
nt, size = s.unpack(b)
self.assertEqual(len(b), size)