diff mbox series

[07/13] app/test: add rte_security_session_get_size tests

Message ID 20200312151654.7218-8-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: I1d1238d38c0cca5ba9c14c8ba395a16d686ae110
---
 app/test/test_security.c | 131 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 131 insertions(+)
diff mbox series

Patch

diff --git a/app/test/test_security.c b/app/test/test_security.c
index cf13b8080..d4b3e9515 100644
--- a/app/test/test_security.c
+++ b/app/test/test_security.c
@@ -263,6 +263,29 @@  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
  *
@@ -304,6 +327,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,
 };
 
@@ -393,10 +417,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;
@@ -839,6 +865,100 @@  test_rte_security_session_update_success(void)
 }
 
 
+/**
+ * rte_security_session_get_size tests
+ */
+
+/**
+ * Test execution of rte_security_session_get_size with NULL instance
+ */
+static int
+test_rte_security_session_get_size_inv_param_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_rte_security_session_get_size_inv_param_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_rte_security_session_get_size_inv_param_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_rte_security_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_rte_security_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
  */
@@ -879,6 +999,17 @@  static struct unit_test_suite security_testsuite  = {
 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
 				test_rte_security_session_update_success),
 
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_rte_security_session_get_size_inv_param_context),
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_rte_security_session_get_size_inv_param_context_ops),
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_rte_security_session_get_size_inv_param_context_ops_fun),
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_rte_security_session_get_size_ops_failure),
+		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
+				test_rte_security_session_get_size_success),
+
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
 };