aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_string.py
diff options
context:
space:
mode:
authorSteven <sluong@cisco.com>2018-10-24 21:15:45 -0700
committerDave Barach <dave@barachs.net>2018-12-02 08:47:46 -0500
commitb0598497afde60146fe8480331c9f96e7a79475a (patch)
treea3d9f454195cb9317fceb29efe62f5b62de89dea /test/test_string.py
parente7f61d1db511b9b09c7771c5851eaaf95a2fc7fe (diff)
vppinfra: c11 safe string functions
Add memcmp_s, strcmp_s, strncmp_s, strcpy_s, strncpy_s, strcat_s, strncat_s, strtok_s, strnlen_s, and strstr_s C11 safe string API. For migrating extant unsafe API, add also the corresponding macro version of each safe API, clib_memcmp, clib_strcmp, etc. In general, the benefits of the safe string APIs are to provide null pointer checks, add additional argument to specify the string length of the passed string rather than relying on the null terminated character, and src/dest overlap checking for the the string copy operations. The macro version of the API takes the same number of arguments as the unsafe API to provide easy migration. However, it does not usually provide the full aformentioned benefits. In some cases, it is necessary to move to the safe API rather than using the macro in order to avoid some unpredictable problems such as accessing memory beyond what it is intended due to the lack of the passed string length. dbarach: add a "make test" vector, and a doxygen file header cookie. Change-Id: I5cd79b8928dcf76a79bf3f0b8cbc1a8f24942f4c Signed-off-by: Steven <sluong@cisco.com> Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'test/test_string.py')
-rw-r--r--test/test_string.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/test_string.py b/test/test_string.py
new file mode 100644
index 00000000000..b44489e3038
--- /dev/null
+++ b/test/test_string.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+
+import unittest
+
+from framework import VppTestCase, VppTestRunner
+from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
+
+
+class TestString(VppTestCase):
+ """ String Test Cases """
+
+ @classmethod
+ def setUpClass(cls):
+ super(TestString, cls).setUpClass()
+
+ def setUp(self):
+ super(TestString, self).setUp()
+
+ def tearDown(self):
+ super(TestString, self).tearDown()
+
+ def test_string_unittest(self):
+ """ String unit tests """
+ names = ["memcpy_s",
+ "clib_memcmp", "clib_memcpy", "clib_memset",
+ "clib_strcat", "clib_strcmp", "clib_strcpy",
+ "clib_strncat", "clib_strncmp", "clib_strncpy",
+ "clib_strnlen", "clib_strstr", "clib_strtok",
+ "memcmp_s", "memcpy_s", "memset_s ",
+ "strcat_s", "strcmp_s", "strcpy_s",
+ "strncat_s", "strncmp_s", "strncpy_s",
+ "strnlen_s", "strstr_s", "strtok_s"]
+
+ for name in names:
+ error = self.vapi.cli("test string " + name)
+ if error.find("failed") != -1:
+ self.logger.critical("FAILURE in the " + name + " test")
+ self.assertEqual(error.find("failed"), -1)
+
+if __name__ == '__main__':
+ unittest.main(testRunner=VppTestRunner)