test/security: add DOCSIS capability checks
authorDavid Coyle <david.coyle@intel.com>
Fri, 3 Jul 2020 12:39:32 +0000 (13:39 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 8 Jul 2020 16:16:16 +0000 (18:16 +0200)
Add unit tests for DOCSIS capabilitity checks.

Signed-off-by: David Coyle <david.coyle@intel.com>
Signed-off-by: Mairtin o Loingsigh <mairtin.oloingsigh@intel.com>
Acked-by: Akhil Goyal <akhil.goyal@nxp.com>
app/test/test_security.c

index 3076a4c..77fd5ad 100644 (file)
@@ -6,6 +6,7 @@
 #include <rte_log.h>
 #include <rte_memory.h>
 #include <rte_mempool.h>
+#include <rte_ether.h>
 #include <rte_security.h>
 #include <rte_security_driver.h>
 
@@ -2268,6 +2269,89 @@ test_capability_get_pdcp_match(void)
        return TEST_SUCCESS;
 }
 
+/**
+ * Test execution of rte_security_capability_get when capabilities table
+ * does not contain entry with matching DOCSIS direction field
+ */
+static int
+test_capability_get_docsis_mismatch_direction(void)
+{
+       struct security_unittest_params *ut_params = &unittest_params;
+       struct rte_security_capability_idx idx = {
+               .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
+               .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
+               .docsis = {
+                       .direction = RTE_SECURITY_DOCSIS_DOWNLINK
+               },
+       };
+       struct rte_security_capability capabilities[] = {
+               {
+                       .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
+                       .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
+                       .docsis = {
+                               .direction = RTE_SECURITY_DOCSIS_UPLINK
+                       },
+               },
+               {
+                       .action = RTE_SECURITY_ACTION_TYPE_NONE,
+               },
+       };
+
+       mock_capabilities_get_exp.device = NULL;
+       mock_capabilities_get_exp.ret = capabilities;
+
+       const struct rte_security_capability *ret;
+       ret = rte_security_capability_get(&ut_params->ctx, &idx);
+       TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
+                       ret, NULL, "%p");
+       TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
+
+       return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_capability_get when capabilities table
+ * contains matching DOCSIS entry
+ */
+static int
+test_capability_get_docsis_match(void)
+{
+       struct security_unittest_params *ut_params = &unittest_params;
+       struct rte_security_capability_idx idx = {
+               .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
+               .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
+               .docsis = {
+                       .direction = RTE_SECURITY_DOCSIS_UPLINK
+               },
+       };
+       struct rte_security_capability capabilities[] = {
+               {
+                       .action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
+               },
+               {
+                       .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
+                       .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
+                       .docsis = {
+                               .direction = RTE_SECURITY_DOCSIS_UPLINK
+                       },
+               },
+               {
+                       .action = RTE_SECURITY_ACTION_TYPE_NONE,
+               },
+       };
+
+       mock_capabilities_get_exp.device = NULL;
+       mock_capabilities_get_exp.ret = capabilities;
+
+       const struct rte_security_capability *ret;
+       ret = rte_security_capability_get(&ut_params->ctx, &idx);
+       TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
+                       ret, &capabilities[1], "%p");
+       TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
+
+       return TEST_SUCCESS;
+}
+
 /**
  * Declaration of testcases
  */
@@ -2410,6 +2494,10 @@ static struct unit_test_suite security_testsuite  = {
                                test_capability_get_pdcp_mismatch_domain),
                TEST_CASE_ST(ut_setup_with_session, ut_teardown,
                                test_capability_get_pdcp_match),
+               TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+                               test_capability_get_docsis_mismatch_direction),
+               TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+                               test_capability_get_docsis_match),
 
                TEST_CASES_END() /**< NULL terminate unit test array */
        }