diff mbox series

[10/13] app/test: add rte_security_set_pkt_metadata tests

Message ID 20200312151654.7218-11-l.wojciechow@partner.samsung.com (mailing list archive)
State Superseded, archived
Delegated to: akhil goyal
Headers show
Series Fixes and unit tests for librte_security | expand

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch warning coding style issues

Commit Message

Lukasz Wojciechowski March 12, 2020, 3:16 p.m. UTC
Signed-off-by: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Change-Id: Id5b4304e83a12443c62557c2a917125084e14f6b
---
 app/test/test_security.c | 204 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 204 insertions(+)
diff mbox series

Patch

diff --git a/app/test/test_security.c b/app/test/test_security.c
index dc11b96ff..fa9141f89 100644
--- a/app/test/test_security.c
+++ b/app/test/test_security.c
@@ -341,6 +341,38 @@  mock_session_destroy(void *device,
 	return mock_session_destroy_exp.ret;
 }
 
+/**
+ * set_pkt_metadata mockup
+ *
+ * Verified parameters: device, sess, m, params.
+ */
+static struct mock_set_pkt_metadata_data {
+	void *device;
+	struct rte_security_session *sess;
+	struct rte_mbuf *m;
+	void *params;
+
+	int ret;
+
+	int called;
+	int failed;
+} mock_set_pkt_metadata_exp = {NULL, NULL, NULL, NULL, 0, 0, 0};
+
+static int
+mock_set_pkt_metadata(void *device,
+		struct rte_security_session *sess,
+		struct rte_mbuf *m,
+		void *params) {
+	mock_set_pkt_metadata_exp.called++;
+
+	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, device);
+	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, sess);
+	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, m);
+	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, params);
+
+	return mock_set_pkt_metadata_exp.ret;
+}
+
 /**
  * empty_ops
  *
@@ -359,6 +391,7 @@  struct rte_security_ops mock_ops = {
 	.session_get_size = mock_session_get_size,
 	.session_stats_get = mock_session_stats_get,
 	.session_destroy = mock_session_destroy,
+	.set_pkt_metadata = mock_set_pkt_metadata,
 };
 
 
@@ -450,12 +483,14 @@  ut_setup(void) {
 	mock_session_get_size_exp.called = 0;
 	mock_session_stats_get_exp.called = 0;
 	mock_session_destroy_exp.called = 0;
+	mock_set_pkt_metadata_exp.called = 0;
 
 	mock_session_create_exp.failed = 0;
 	mock_session_update_exp.failed = 0;
 	mock_session_get_size_exp.failed = 0;
 	mock_session_stats_get_exp.failed = 0;
 	mock_session_destroy_exp.failed = 0;
+	mock_set_pkt_metadata_exp.failed = 0;
 
 	return TEST_SUCCESS;
 }
@@ -1265,6 +1300,160 @@  test_rte_security_session_destroy_success(void)
 }
 
 
+/**
+ * rte_security_set_pkt_metadata tests
+ */
+
+/**
+ * Test execution of rte_security_set_pkt_metadata with NULL instance
+ */
+static int
+test_rte_security_set_pkt_metadata_inv_param_context(void)
+{
+	struct security_unittest_params *ut_params = &unittest_params;
+	struct rte_mbuf m;
+	int params;
+
+	int ret = rte_security_set_pkt_metadata(NULL, ut_params->sess, &m,
+			&params);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
+			ret, -EINVAL, "%d");
+	TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_set_pkt_metadata with invalid
+ * security operations structure (NULL)
+ */
+static int
+test_rte_security_set_pkt_metadata_inv_param_context_ops(void)
+{
+	struct security_unittest_params *ut_params = &unittest_params;
+	struct rte_mbuf m;
+	int params;
+	ut_params->ctx.ops = NULL;
+
+	int ret = rte_security_set_pkt_metadata(&ut_params->ctx, ut_params->sess,
+			&m, &params);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
+			ret, -EINVAL, "%d");
+	TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_set_pkt_metadata with empty
+ * security operations
+ */
+static int
+test_rte_security_set_pkt_metadata_inv_param_context_ops_fun(void)
+{
+	struct security_unittest_params *ut_params = &unittest_params;
+	struct rte_mbuf m;
+	int params;
+	ut_params->ctx.ops = &empty_ops;
+
+	int ret = rte_security_set_pkt_metadata(&ut_params->ctx, ut_params->sess,
+			&m, &params);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
+			ret, -ENOTSUP, "%d");
+	TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_set_pkt_metadata with NULL sess parameter
+ */
+static int
+test_rte_security_set_pkt_metadata_inv_param_session(void)
+{
+	struct security_unittest_params *ut_params = &unittest_params;
+	struct rte_mbuf m;
+	int params;
+
+	int ret = rte_security_set_pkt_metadata(&ut_params->ctx, NULL,
+			&m, &params);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
+			ret, -EINVAL, "%d");
+	TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_set_pkt_metadata with NULL m parameter
+ */
+static int
+test_rte_security_set_pkt_metadata_inv_param_m(void)
+{
+	struct security_unittest_params *ut_params = &unittest_params;
+	int params;
+
+	int ret = rte_security_set_pkt_metadata(&ut_params->ctx, ut_params->sess,
+			NULL, &params);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
+			ret, -EINVAL, "%d");
+	TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_set_pkt_metadata when set_pkt_metadata
+ * security operation fails
+ */
+static int
+test_rte_security_set_pkt_metadata_ops_failure(void)
+{
+	struct security_unittest_params *ut_params = &unittest_params;
+	struct rte_mbuf m;
+	int params;
+
+	mock_set_pkt_metadata_exp.device = NULL;
+	mock_set_pkt_metadata_exp.sess = ut_params->sess;
+	mock_set_pkt_metadata_exp.m = &m;
+	mock_set_pkt_metadata_exp.params = &params;
+	mock_set_pkt_metadata_exp.ret = -1;
+
+	int ret = rte_security_set_pkt_metadata(&ut_params->ctx, ut_params->sess,
+			&m, &params);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
+			ret, -1, "%d");
+	TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 1);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_set_pkt_metadata in successful execution path
+ */
+static int
+test_rte_security_set_pkt_metadata_success(void)
+{
+	struct security_unittest_params *ut_params = &unittest_params;
+	struct rte_mbuf m;
+	int params;
+
+	mock_set_pkt_metadata_exp.device = NULL;
+	mock_set_pkt_metadata_exp.sess = ut_params->sess;
+	mock_set_pkt_metadata_exp.m = &m;
+	mock_set_pkt_metadata_exp.params = &params;
+	mock_set_pkt_metadata_exp.ret = 0;
+
+	int ret = rte_security_set_pkt_metadata(&ut_params->ctx, ut_params->sess,
+			&m, &params);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
+			ret, 0, "%d");
+	TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 1);
+
+	return TEST_SUCCESS;
+}
+
+
 /**
  * Declaration of testcases
  */
@@ -1342,6 +1531,21 @@  static struct unit_test_suite security_testsuite  = {
 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
 				test_rte_security_session_destroy_success),
 
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_rte_security_set_pkt_metadata_inv_param_context),
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_rte_security_set_pkt_metadata_inv_param_context_ops),
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_rte_security_set_pkt_metadata_inv_param_context_ops_fun),
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_rte_security_set_pkt_metadata_inv_param_session),
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_rte_security_set_pkt_metadata_inv_param_m),
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_rte_security_set_pkt_metadata_ops_failure),
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_rte_security_set_pkt_metadata_success),
+
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
 };