aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ext/vapi_c_test.c67
-rw-r--r--test/test_punt.py2
2 files changed, 69 insertions, 0 deletions
diff --git a/test/ext/vapi_c_test.c b/test/ext/vapi_c_test.c
index a9572ae8716..51fc572746f 100644
--- a/test/ext/vapi_c_test.c
+++ b/test/ext/vapi_c_test.c
@@ -29,6 +29,9 @@
#include <vapi/l2.api.vapi.h>
#include <fake.api.vapi.h>
+#include <vppinfra/vec.h>
+#include <vppinfra/mem.h>
+
DEFINE_VAPI_MSG_IDS_VPE_API_JSON;
DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON;
DEFINE_VAPI_MSG_IDS_L2_API_JSON;
@@ -911,6 +914,66 @@ START_TEST (test_unsupported)
END_TEST;
+START_TEST (test_api_strings)
+{
+ printf ("--- Invalid api strings ---\n");
+
+ /* test string 'TEST'
+ * size = 5
+ * length = 4
+ */
+ const char str[] = "TEST";
+ u8 *vec_str = 0, *vstr = 0;
+ char *cstr;
+
+ vapi_msg_sw_interface_dump *dump =
+ malloc (sizeof (vapi_msg_sw_interface_dump) + strlen (str));
+ clib_mem_init (0, 1 << 20);
+
+ vl_api_c_string_to_api_string (str, &dump->payload.name_filter);
+ /* Assert nul terminator NOT present */
+ ck_assert_int_eq (vl_api_string_len (&dump->payload.name_filter),
+ strlen (str));
+
+ cstr = vl_api_from_api_to_new_c_string (&dump->payload.name_filter);
+ ck_assert_ptr_ne (cstr, NULL);
+ /* Assert nul terminator present */
+ ck_assert_int_eq (vec_len (cstr), sizeof (str));
+ ck_assert_int_eq (strlen (str), strlen (cstr));
+ vec_free (cstr);
+
+ vstr = vl_api_from_api_to_new_vec (&dump->payload.name_filter);
+ ck_assert_ptr_ne (vstr, NULL);
+ /* Assert nul terminator NOT present */
+ ck_assert_int_eq (vec_len (vstr), strlen (str));
+ vec_free (vstr);
+
+ /* vector conaining NON nul terminated string 'TEST' */
+ vec_add (vec_str, str, strlen (str));
+ clib_memset (dump->payload.name_filter.buf, 0, strlen (str));
+ dump->payload.name_filter.length = 0;
+
+ vl_api_vec_to_api_string (vec_str, &dump->payload.name_filter);
+ /* Assert nul terminator NOT present */
+ ck_assert_int_eq (vl_api_string_len (&dump->payload.name_filter),
+ vec_len (vec_str));
+
+ cstr = vl_api_from_api_to_new_c_string (&dump->payload.name_filter);
+ ck_assert_ptr_ne (cstr, NULL);
+ /* Assert nul terminator present */
+ ck_assert_int_eq (vec_len (cstr), sizeof (str));
+ ck_assert_int_eq (strlen (str), strlen (cstr));
+ vec_free (cstr);
+
+ vstr = vl_api_from_api_to_new_vec (&dump->payload.name_filter);
+ ck_assert_ptr_ne (vstr, NULL);
+ /* Assert nul terminator NOT present */
+ ck_assert_int_eq (vec_len (vstr), strlen (str));
+ vec_free (vstr);
+}
+
+END_TEST;
+
Suite *
test_suite (void)
{
@@ -957,6 +1020,10 @@ test_suite (void)
tcase_add_test (tc_unsupported, test_unsupported);
suite_add_tcase (s, tc_unsupported);
+ TCase *tc_dynamic = tcase_create ("Dynamic message size");
+ tcase_add_test (tc_dynamic, test_api_strings);
+ suite_add_tcase (s, tc_dynamic);
+
return s;
}
diff --git a/test/test_punt.py b/test/test_punt.py
index 8ebf44767f3..ecd34f6eea7 100644
--- a/test/test_punt.py
+++ b/test/test_punt.py
@@ -811,6 +811,8 @@ class TestExceptionPuntSocket(TestPuntSocket):
rs = self.vapi.punt_reason_dump()
for key in cfgs:
for r in rs:
+ print(r.reason.name)
+ print(key)
if r.reason.name == key:
cfgs[key]['id'] = r.reason.id
cfgs[key]['vpp'] = copy.deepcopy(