[v3,07/13] app/test: add rte security session get size tests
diff mbox series

Message ID 20200409172502.1693-8-l.wojciechow@partner.samsung.com
State Accepted, archived
Delegated to: akhil goyal
Headers show
Series
  • Fixes and unit tests for librte_security
Related show

Checks

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

Commit Message

Lukasz Wojciechowski April 9, 2020, 5:24 p.m. UTC
Add unit tests for rte_security_session_get_size function.

Signed-off-by: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
---
 app/test/test_security.c | 132 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 132 insertions(+)

Patch
diff mbox series

diff --git a/app/test/test_security.c b/app/test/test_security.c
index daaf30b62..9c5e7d0da 100644
--- a/app/test/test_security.c
+++ b/app/test/test_security.c
@@ -268,6 +268,30 @@  mock_session_update(void *device,
 	return mock_session_update_exp.ret;
 }
 
+/**
+ * session_get_size mockup
+ *
+ * Verified parameters: device.
+ */
+static struct mock_session_get_size_data {
+	void *device;
+
+	unsigned int ret;
+
+	int called;
+	int failed;
+} mock_session_get_size_exp = {NULL, 0U, 0, 0};
+
+static unsigned int
+mock_session_get_size(void *device)
+{
+	mock_session_get_size_exp.called++;
+
+	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_get_size_exp, device);
+
+	return mock_session_get_size_exp.ret;
+}
+
 /**
  * session_destroy mockup
  *
@@ -309,6 +333,7 @@  struct rte_security_ops empty_ops = { NULL };
 struct rte_security_ops mock_ops = {
 	.session_create = mock_session_create,
 	.session_update = mock_session_update,
+	.session_get_size = mock_session_get_size,
 	.session_destroy = mock_session_destroy,
 };
 
@@ -401,10 +426,12 @@  ut_setup(void)
 
 	mock_session_create_exp.called = 0;
 	mock_session_update_exp.called = 0;
+	mock_session_get_size_exp.called = 0;
 	mock_session_destroy_exp.called = 0;
 
 	mock_session_create_exp.failed = 0;
 	mock_session_update_exp.failed = 0;
+	mock_session_get_size_exp.failed = 0;
 	mock_session_destroy_exp.failed = 0;
 
 	return TEST_SUCCESS;
@@ -856,6 +883,100 @@  test_session_update_success(void)
 }
 
 
+/**
+ * rte_security_session_get_size tests
+ */
+
+/**
+ * Test execution of rte_security_session_get_size with NULL instance
+ */
+static int
+test_session_get_size_inv_context(void)
+{
+	unsigned int ret = rte_security_session_get_size(NULL);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
+			ret, 0, "%u");
+	TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_session_get_size with invalid
+ * security operations structure (NULL)
+ */
+static int
+test_session_get_size_inv_context_ops(void)
+{
+	struct security_unittest_params *ut_params = &unittest_params;
+	ut_params->ctx.ops = NULL;
+
+	unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
+			ret, 0, "%u");
+	TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_session_get_size with empty
+ * security operations
+ */
+static int
+test_session_get_size_inv_context_ops_fun(void)
+{
+	struct security_unittest_params *ut_params = &unittest_params;
+	ut_params->ctx.ops = &empty_ops;
+
+	unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
+			ret, 0, "%u");
+	TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_session_get_size when session_get_size
+ * security operation fails
+ */
+static int
+test_session_get_size_ops_failure(void)
+{
+	struct security_unittest_params *ut_params = &unittest_params;
+
+	mock_session_get_size_exp.device = NULL;
+	mock_session_get_size_exp.ret = 0;
+
+	unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
+			ret, 0, "%u");
+	TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 1);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_session_get_size in successful execution path
+ */
+static int
+test_session_get_size_success(void)
+{
+	struct security_unittest_params *ut_params = &unittest_params;
+
+	mock_session_get_size_exp.device = NULL;
+	mock_session_get_size_exp.ret = 1024;
+
+	unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
+			ret, 1024U, "%u");
+	TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 1);
+
+	return TEST_SUCCESS;
+}
+
+
 /**
  * Declaration of testcases
  */
@@ -896,6 +1017,17 @@  static struct unit_test_suite security_testsuite  = {
 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
 				test_session_update_success),
 
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_session_get_size_inv_context),
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_session_get_size_inv_context_ops),
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_session_get_size_inv_context_ops_fun),
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_session_get_size_ops_failure),
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_session_get_size_success),
+
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
 };