DPDK patches and discussions
 help / color / mirror / Atom feed
From: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 05/13] app/test: introduce librte_security tests
Date: Thu, 12 Mar 2020 16:16:46 +0100	[thread overview]
Message-ID: <20200312151654.7218-6-l.wojciechow@partner.samsung.com> (raw)
In-Reply-To: <20200312151654.7218-1-l.wojciechow@partner.samsung.com>

This patch introduces set of unit tests of librte_security API functions.
Tests are added to dpdk-test application and can be run with
"security_autotest" runtime command.

This is the first patch in the series of patches as adding all test cases
for all API functions in a single patch would make it unreadable.

This patch defines structure of the file and necessary test framework
initialization. It also contains first subset of unit tests for
rte_security_session_create API function.

Structure of the tests file is following:
- macros for making tests more readable;
- mockup structures and functions for rte_security_ops;
- test suite and test cases setup and teardown functions;
- tests functions;
- declaration of testcases.

Signed-off-by: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Change-Id: I3a4585f56ef1a75b2984fcea3a3e4a30e4c2d8a6
---
 app/test/Makefile        |   2 +
 app/test/meson.build     |   3 +
 app/test/test_security.c | 670 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 675 insertions(+)
 create mode 100644 app/test/test_security.c

diff --git a/app/test/Makefile b/app/test/Makefile
index 1f080d162..153610a32 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -231,6 +231,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_BPF) += test_bpf.c
 
 SRCS-$(CONFIG_RTE_LIBRTE_RCU) += test_rcu_qsbr.c test_rcu_qsbr_perf.c
 
+SRCS-$(CONFIG_RTE_LIBRTE_SECURITY) += test_security.c
+
 SRCS-$(CONFIG_RTE_LIBRTE_IPSEC) += test_ipsec.c
 SRCS-$(CONFIG_RTE_LIBRTE_IPSEC) += test_ipsec_sad.c
 ifeq ($(CONFIG_RTE_LIBRTE_IPSEC),y)
diff --git a/app/test/meson.build b/app/test/meson.build
index 0a2ce710f..89e4299fd 100644
--- a/app/test/meson.build
+++ b/app/test/meson.build
@@ -103,6 +103,7 @@ test_sources = files('commands.c',
 	'test_ring_perf.c',
 	'test_rwlock.c',
 	'test_sched.c',
+	'test_security.c',
 	'test_service_cores.c',
 	'test_spinlock.c',
 	'test_stack.c',
@@ -150,6 +151,7 @@ test_deps = ['acl',
 	'reorder',
 	'rib',
 	'ring',
+	'security',
 	'stack',
 	'timer'
 ]
@@ -209,6 +211,7 @@ fast_test_names = [
         'rwlock_rds_wrm_autotest',
         'rwlock_rde_wro_autotest',
         'sched_autotest',
+        'security_autotest',
         'spinlock_autotest',
         'stack_autotest',
         'stack_lf_autotest',
diff --git a/app/test/test_security.c b/app/test/test_security.c
new file mode 100644
index 000000000..885281703
--- /dev/null
+++ b/app/test/test_security.c
@@ -0,0 +1,670 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ */
+
+#include <rte_errno.h>
+#include <rte_log.h>
+#include <rte_memory.h>
+#include <rte_mempool.h>
+#include <rte_security.h>
+#include <rte_security_driver.h>
+
+/* Before including rte_test.h file you can define
+ * RTE_TEST_TRACE_FAILURE(_file, _line, _func) macro to better trace/debug test
+ * failures. Mostly useful in development phase.
+ */
+#ifndef RTE_TEST_TRACE_FAILURE
+#define RTE_TEST_TRACE_FAILURE(_file, _line, _func) \
+	RTE_LOG(DEBUG, EAL, "in %s:%d %s\n", _file, _line, _func)
+#endif
+
+#include <rte_test.h>
+#include "test.h"
+
+/**
+ * Security
+ * =======
+ *
+ * Basic unit tests of the librte_security API.
+ *
+ * Structure of the file:
+ * - macros for making tests more readable;
+ * - mockup structures and functions for rte_security_ops;
+ * - test suite and test cases setup and teardown functions;
+ * - tests functions;
+ * - declaration of testcases.
+ */
+
+
+/**
+ * Macros
+ *
+ * Set of macros for making tests easier to read.
+ */
+
+/**
+ * Verify condition inside mocked up function.
+ * Mockup function cannot return a test error, so the failure
+ * of assertion increases counter and print logs.
+ * The counter can be verified later to check if test case should fail.
+ *
+ * @param   fail_counter	fail counter
+ * @param   cond	condition expected to be true
+ * @param   msg	printf style formatting string for custom message
+ */
+#define MOCK_TEST_ASSERT(fail_counter, cond, msg, ...) do {			\
+	if (!(cond)) {								\
+		fail_counter++;							\
+		RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: "		\
+				msg "\n", __func__, __LINE__, ##__VA_ARGS__);	\
+		RTE_TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__);		\
+	}									\
+} while (0)
+
+/**
+ * Verify equality condition inside mocked up function.
+ * Mockup function cannot return a test error, so the failure
+ * of assertion increases counter and print logs.
+ * The counter can be verified later to check if test case should fail.
+ *
+ * @param   fail_counter	fail counter
+ * @param   a	first value of comparison
+ * @param   b	second value of comparison
+ * @param   msg	printf style formatting string for custom message
+ */
+#define MOCK_TEST_ASSERT_EQUAL(fail_counter, a, b, msg, ...)	\
+	MOCK_TEST_ASSERT(fail_counter, (a) == (b), msg, ##__VA_ARGS__)
+
+
+/**
+ * Verify if parameter of the mocked up function matches expected value.
+ * The expected value is stored in data structure in the field matching
+ * parameter name.
+ *
+ * @param   data	structure with expected values
+ * @param   parameter	name of the parameter (both field and parameter name)
+ * @param   spec	printf style spec for parameter
+ */
+#define MOCK_TEST_ASSERT_PARAMETER(data, parameter, spec)			\
+	MOCK_TEST_ASSERT_EQUAL(data.failed, data.parameter, parameter,		\
+			"Expecting parameter %s to be " spec " but it's " spec,	\
+			RTE_STR(parameter), data.parameter, parameter)
+
+/**
+ * Wrap for MOCK_TEST_ASSERT_PARAMETER macro for pointer type parameters.
+ *
+ * @param   data	structure with expected values
+ * @param   parameter	name of the parameter (both field and parameter name)
+ */
+#define MOCK_TEST_ASSERT_POINTER_PARAMETER(data, parameter)	\
+	MOCK_TEST_ASSERT_PARAMETER(data, parameter, "%p")
+
+/**
+ * Verify number of calls of the mocked up function
+ * and check if there were any fails during execution.
+ * The fails statistics inside mocked up functions are collected
+ * as "failed" field in mockup structures.
+ *
+ * @param   mock_data	structure with statistics (called, failed)
+ * @param   exp_calls	expected number of mockup function calls
+ */
+#define TEST_ASSERT_MOCK_CALLS(mock_data, exp_calls) do {		\
+	TEST_ASSERT_EQUAL(exp_calls, mock_data.called,			\
+			"Expecting sub op to be called %d times, "	\
+			"but it's called %d times",			\
+			exp_calls, mock_data.called);			\
+	TEST_ASSERT_EQUAL(0, mock_data.failed,				\
+			"Expecting sub op asserts not to fail, "	\
+			"but they're failed %d times",			\
+			mock_data.failed);				\
+} while (0)
+
+/**
+ * Assert tested function result match expected value
+ *
+ * @param   f_name	name of tested function
+ * @param   f_ret	value returned by the function
+ * @param   exp_ret	expected returned value
+ */
+#define TEST_ASSERT_MOCK_FUNCTION_CALL_RET(f_name, f_ret, exp_ret,			\
+		ret_spec) do {								\
+	TEST_ASSERT_EQUAL(exp_ret, f_ret, "Expecting " RTE_STR(f_name)			\
+			" to return " ret_spec ", but it returned " ret_spec "\n",	\
+			exp_ret, f_ret);						\
+} while (0)
+
+/**
+ * Assert tested function result is not NULL
+ *
+ * @param   f_name	name of tested function
+ * @param   f_ret	value returned by the function
+ */
+#define TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(f_name, f_ret) do {	\
+	TEST_ASSERT_NOT_NULL(f_ret, "Expecting " RTE_STR(f_name)	\
+			" to return not NULL\n");			\
+} while (0)
+
+/**
+ * Verify that sess_cnt counter value matches expected
+ *
+ * @param   expected_sessions_count	expected counter value
+ */
+#define TEST_ASSERT_SESSION_COUNT(expected_sessions_count) do {			\
+	struct security_unittest_params *ut_params = &unittest_params;		\
+	TEST_ASSERT_EQUAL(expected_sessions_count, ut_params->ctx.sess_cnt,	\
+			"Expecting session counter to be %u but it's %u",	\
+			expected_sessions_count, ut_params->ctx.sess_cnt);	\
+} while (0)
+
+/**
+ * Verify usage of mempool by checking if number of allocated objects matches
+ * expectations. The mempool is used to manage objects for sessions data.
+ * A single object is acquired from mempool during session_create
+ * and put back in session_destroy.
+ *
+ * @param   expected_mempool_usage	expected number of mempool objects in use
+ */
+#define TEST_ASSERT_MEMPOOL_USAGE(expected_mempool_usage) do {			\
+	struct security_testsuite_params *ts_params = &testsuite_params;	\
+	unsigned int mempool_usage;						\
+	mempool_usage = rte_mempool_in_use_count(ts_params->session_mpool);	\
+	TEST_ASSERT_EQUAL(expected_mempool_usage, mempool_usage,		\
+			"Expecting %u mempool allocations, "			\
+			"but there are %u allocated objects",			\
+			expected_mempool_usage, mempool_usage);			\
+} while (0)
+
+
+/**
+ * Mockup structures and functions for rte_security_ops;
+ *
+ * Set of structures for controlling mockup functions calls.
+ * Every mockup function X has its corresponding X_data structure
+ * and an instance of that structure X_exp.
+ * Structure contains parameters that a mockup function is expected
+ * to be called with, a value to return (.ret) and 2 statistics:
+ * .called (number of times the mockup function was called)
+ * and .failed (number of assertion fails during mockup function call).
+ *
+ * Mockup functions verify that the parameters they are called with match
+ * expected values. The expected values should be stored in corresponding
+ * structures prior to mockup functions call. Every failure of such
+ * verification increases .failed counter. Every call of mockup function
+ * increases .called counter. Function returns value stored in .ret field
+ * of the structure.
+ * In case of some parameters in some functions the expected value is unknown
+ * and cannot be detrmined prior to call. Such parameters are stored
+ * in structure and can be compared or analyzed later in test case code.
+ *
+ * Below structures and functions follow the rules just described.
+ * Additional remarks and exceptions are added in comments.
+ */
+
+/**
+ * session_create mockup
+ *
+ * Verified parameters: device, conf, mp.
+ * Saved, not verified parameters: sess.
+ */
+static struct mock_session_create_data {
+	void *device;
+	struct rte_security_session_conf *conf;
+	struct rte_security_session *sess;
+	struct rte_mempool *mp;
+
+	int ret;
+
+	int called;
+	int failed;
+} mock_session_create_exp = {NULL, NULL, NULL, NULL, 0, 0, 0};
+
+static int
+mock_session_create(void *device,
+		struct rte_security_session_conf *conf,
+		struct rte_security_session *sess,
+		struct rte_mempool *mp) {
+	mock_session_create_exp.called++;
+
+	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, device);
+	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, conf);
+	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, mp);
+
+	mock_session_create_exp.sess = sess;
+
+	return mock_session_create_exp.ret;
+}
+
+/**
+ * session_destroy mockup
+ *
+ * Verified parameters: device, sess.
+ */
+static struct mock_session_destroy_data {
+	void *device;
+	struct rte_security_session *sess;
+
+	int ret;
+
+	int called;
+	int failed;
+} mock_session_destroy_exp = {NULL, NULL, 0, 0, 0};
+
+static int
+mock_session_destroy(void *device,
+		struct rte_security_session *sess) {
+	mock_session_destroy_exp.called++;
+
+	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_destroy_exp, device);
+	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_destroy_exp, sess);
+
+	return mock_session_destroy_exp.ret;
+}
+
+/**
+ * empty_ops
+ *
+ * is an empty security operations set (all function pointers set to NULL)
+ */
+struct rte_security_ops empty_ops = { NULL };
+
+/**
+ * mock_ops
+ *
+ * is a security operations set using mockup functions
+ */
+struct rte_security_ops mock_ops = {
+	.session_create = mock_session_create,
+	.session_destroy = mock_session_destroy,
+};
+
+
+/**
+ * Test suite and test cases setup and teardown functions.
+ */
+
+/**
+ * struct security_testsuite_params defines parameters initialized once
+ * for whole tests suite.
+ * Currently the only stored parameter is session_mpool a mempool created
+ * once in testsuite_setup and released in testsuite_teardown.
+ * The instance of this structure is stored in testsuite_params variable.
+ */
+static struct security_testsuite_params {
+	struct rte_mempool *session_mpool;
+} testsuite_params = { NULL };
+
+/**
+ * struct security_unittest_params defines parameters initialized
+ * for every test case. The parameters are initialized in ut_setup
+ * and released in ut_teardown.
+ * The instance of this structure is stored in unittest_params variable.
+ */
+static struct security_unittest_params {
+	struct rte_security_ctx ctx;
+	struct rte_security_session_conf conf;
+	struct rte_security_session *sess;
+} unittest_params = {
+	.ctx = {
+		.device = NULL,
+		.ops = &mock_ops,
+		.sess_cnt = 0,
+	},
+	.sess = NULL,
+};
+
+#define SECURITY_TEST_MEMPOOL_NAME "SecurityTestsMempoolName"
+#define SECURITY_TEST_MEMPOOL_SIZE 15
+#define SECURITY_TEST_SESSION_OBJECT_SIZE sizeof(struct rte_security_session)
+
+/**
+ * testsuite_setup initializes whole test suite parameters.
+ * It creates a new mempool used in all test cases
+ * and verifies if it properly created.
+ */
+static int
+testsuite_setup(void) {
+	struct security_testsuite_params *ts_params = &testsuite_params;
+	ts_params->session_mpool = rte_mempool_create(
+			SECURITY_TEST_MEMPOOL_NAME,
+			SECURITY_TEST_MEMPOOL_SIZE,
+			SECURITY_TEST_SESSION_OBJECT_SIZE,
+			0, 0, NULL, NULL, NULL, NULL,
+			SOCKET_ID_ANY, 0);
+	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
+			"Cannot create mempool %s\n", rte_strerror(rte_errno));
+	return TEST_SUCCESS;
+}
+
+/**
+ * testsuite_teardown releases test suite wide parameters.
+ */
+static void
+testsuite_teardown(void) {
+	struct security_testsuite_params *ts_params = &testsuite_params;
+	if (ts_params->session_mpool) {
+		rte_mempool_free(ts_params->session_mpool);
+		ts_params->session_mpool = NULL;
+	}
+}
+
+/**
+ * ut_setup initializes test case parameters to default values.
+ * It resets alse any .called and .failed statistics of mockup functions
+ * usage.
+ */
+static int
+ut_setup(void) {
+	struct security_unittest_params *ut_params = &unittest_params;
+	ut_params->ctx.device = NULL;
+	ut_params->ctx.ops = &mock_ops;
+	ut_params->ctx.sess_cnt = 0;
+	ut_params->sess = NULL;
+
+	mock_session_create_exp.called = 0;
+	mock_session_destroy_exp.called = 0;
+
+	mock_session_create_exp.failed = 0;
+	mock_session_destroy_exp.failed = 0;
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * destroy_session_with_check is a helper function releasing session
+ * created with rte_security_session_create and stored in test case parameters.
+ * It's used both to release sessions created in test cases' bodies
+ * which are assigned to ut_params->sess
+ */
+static int
+destroy_session_with_check(void) {
+	struct security_unittest_params *ut_params = &unittest_params;
+	if (ut_params->sess != NULL) {
+		//assure that mockup function for destroy operation is set.
+		ut_params->ctx.ops = &mock_ops;
+
+		mock_session_destroy_exp.device = NULL;
+		mock_session_destroy_exp.sess = ut_params->sess;
+		mock_session_destroy_exp.ret = 0;
+		mock_session_destroy_exp.called = 0;
+		mock_session_destroy_exp.failed = 0;
+
+		int ret = rte_security_session_destroy(&ut_params->ctx,
+				ut_params->sess);
+		TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
+				ret, 0, "%d");
+		TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
+
+		ut_params->sess = NULL;
+	}
+	return TEST_SUCCESS;
+}
+
+/**
+ * ut_teardown releases test case parameters.
+ */
+static void
+ut_teardown(void) {
+	destroy_session_with_check();
+}
+
+
+/**
+ * Test functions
+ *
+ * Each test function is related to a single test case.
+ * They are arranged by tested rte_security API function
+ * and by rte_security execution paths sequence in code.
+ */
+
+/**
+ * rte_security_session_create tests
+ */
+
+/**
+ * Test execution of rte_security_session_create with NULL instance
+ */
+static int
+test_rte_security_session_create_inv_param_context(void)
+{
+	struct security_testsuite_params *ts_params = &testsuite_params;
+	struct security_unittest_params *ut_params = &unittest_params;
+	struct rte_security_session *sess;
+
+	sess = rte_security_session_create(NULL, &ut_params->conf,
+			ts_params->session_mpool);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
+			sess, NULL, "%p");
+	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
+	TEST_ASSERT_MEMPOOL_USAGE(0);
+	TEST_ASSERT_SESSION_COUNT(0);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_session_create with invalid
+ * security operations structure (NULL)
+ */
+static int
+test_rte_security_session_create_inv_param_context_ops(void)
+{
+	struct security_testsuite_params *ts_params = &testsuite_params;
+	struct security_unittest_params *ut_params = &unittest_params;
+	struct rte_security_session *sess;
+
+	ut_params->ctx.ops = NULL;
+
+	sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
+			ts_params->session_mpool);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
+			sess, NULL, "%p");
+	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
+	TEST_ASSERT_MEMPOOL_USAGE(0);
+	TEST_ASSERT_SESSION_COUNT(0);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_session_create with empty
+ * security operations
+ */
+static int
+test_rte_security_session_create_inv_param_context_ops_fun(void)
+{
+	struct security_testsuite_params *ts_params = &testsuite_params;
+	struct security_unittest_params *ut_params = &unittest_params;
+	struct rte_security_session *sess;
+
+	ut_params->ctx.ops = &empty_ops;
+
+	sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
+			ts_params->session_mpool);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
+			sess, NULL, "%p");
+	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
+	TEST_ASSERT_MEMPOOL_USAGE(0);
+	TEST_ASSERT_SESSION_COUNT(0);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_session_create with NULL conf parameter
+ */
+static int
+test_rte_security_session_create_inv_param_configuration(void)
+{
+	struct security_testsuite_params *ts_params = &testsuite_params;
+	struct security_unittest_params *ut_params = &unittest_params;
+	struct rte_security_session *sess;
+
+	sess = rte_security_session_create(&ut_params->ctx, NULL,
+			ts_params->session_mpool);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
+			sess, NULL, "%p");
+	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
+	TEST_ASSERT_MEMPOOL_USAGE(0);
+	TEST_ASSERT_SESSION_COUNT(0);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_session_create with NULL mp parameter
+ */
+static int
+test_rte_security_session_create_inv_param_mempool(void)
+{
+	struct security_unittest_params *ut_params = &unittest_params;
+	struct rte_security_session *sess;
+
+	sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
+			NULL);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
+			sess, NULL, "%p");
+	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
+	TEST_ASSERT_MEMPOOL_USAGE(0);
+	TEST_ASSERT_SESSION_COUNT(0);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_session_create in case when mempool
+ * is fully used and no object can be got from it
+ */
+static int
+test_rte_security_session_create_mempool_empty(void)
+{
+	struct security_testsuite_params *ts_params = &testsuite_params;
+	struct security_unittest_params *ut_params = &unittest_params;
+	struct rte_security_session *tmp[SECURITY_TEST_MEMPOOL_SIZE];
+	struct rte_security_session *sess;
+
+	// Get all available objects from mempool
+	int i, ret;
+	for (i = 0; i < SECURITY_TEST_MEMPOOL_SIZE; ++i) {
+		ret = rte_mempool_get(ts_params->session_mpool, (void **)(&tmp[i]));
+		TEST_ASSERT_EQUAL(0, ret,
+				"Expect getting %d object from mempool to succeed", i);
+	}
+	TEST_ASSERT_MEMPOOL_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
+
+	sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
+			ts_params->session_mpool);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
+			sess, NULL, "%p");
+	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
+	TEST_ASSERT_MEMPOOL_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
+	TEST_ASSERT_SESSION_COUNT(0);
+
+	// Put objects back to the pool.
+	for (i = 0; i < SECURITY_TEST_MEMPOOL_SIZE; ++i) {
+		rte_mempool_put(ts_params->session_mpool, (void *)(tmp[i]));
+	}
+	TEST_ASSERT_MEMPOOL_USAGE(0);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_session_create when session_create
+ * security operation fails
+ */
+static int
+test_rte_security_session_create_ops_failure(void)
+{
+	struct security_testsuite_params *ts_params = &testsuite_params;
+	struct security_unittest_params *ut_params = &unittest_params;
+	struct rte_security_session *sess;
+
+	mock_session_create_exp.device = NULL;
+	mock_session_create_exp.conf = &ut_params->conf;
+	mock_session_create_exp.mp = ts_params->session_mpool;
+	mock_session_create_exp.ret = -1;	// return failure status
+
+	sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
+			ts_params->session_mpool);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
+			sess, NULL, "%p");
+	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
+	TEST_ASSERT_MEMPOOL_USAGE(0);
+	TEST_ASSERT_SESSION_COUNT(0);
+
+	return TEST_SUCCESS;
+}
+
+/**
+ * Test execution of rte_security_session_create in successful execution path
+ */
+static int
+test_rte_security_session_create_success(void)
+{
+	struct security_testsuite_params *ts_params = &testsuite_params;
+	struct security_unittest_params *ut_params = &unittest_params;
+	struct rte_security_session *sess;
+
+	mock_session_create_exp.device = NULL;
+	mock_session_create_exp.conf = &ut_params->conf;
+	mock_session_create_exp.mp = ts_params->session_mpool;
+	mock_session_create_exp.ret = 0;	// return success status
+
+	sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
+			ts_params->session_mpool);
+	TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(rte_security_session_create, sess);
+	TEST_ASSERT_EQUAL(sess, mock_session_create_exp.sess,
+			"Expecting session_create to be called with %p sess parameter, "
+			"but it's called %p sess parameter",
+			sess, mock_session_create_exp.sess);
+	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
+	TEST_ASSERT_MEMPOOL_USAGE(1);
+	TEST_ASSERT_SESSION_COUNT(1);
+
+	// Store created session in test case parameters, so it can be released
+	// after test case in ut_teardown by destroy_session_with_check.
+	ut_params->sess = sess;
+
+	return TEST_SUCCESS;
+}
+
+
+/**
+ * Declaration of testcases
+ */
+static struct unit_test_suite security_testsuite  = {
+	.suite_name = "generic security",
+	.setup = testsuite_setup,
+	.teardown = testsuite_teardown,
+	.unit_test_cases = {
+		TEST_CASE_ST(ut_setup, ut_teardown,
+				test_rte_security_session_create_inv_param_context),
+		TEST_CASE_ST(ut_setup, ut_teardown,
+				test_rte_security_session_create_inv_param_context_ops),
+		TEST_CASE_ST(ut_setup, ut_teardown,
+				test_rte_security_session_create_inv_param_context_ops_fun),
+		TEST_CASE_ST(ut_setup, ut_teardown,
+				test_rte_security_session_create_inv_param_configuration),
+		TEST_CASE_ST(ut_setup, ut_teardown,
+				test_rte_security_session_create_inv_param_mempool),
+		TEST_CASE_ST(ut_setup, ut_teardown,
+				test_rte_security_session_create_mempool_empty),
+		TEST_CASE_ST(ut_setup, ut_teardown,
+				test_rte_security_session_create_ops_failure),
+		TEST_CASE_ST(ut_setup, ut_teardown,
+				test_rte_security_session_create_success),
+
+		TEST_CASES_END() /**< NULL terminate unit test array */
+	}
+};
+
+static int
+test_security(void)
+{
+	rte_log_set_global_level(RTE_LOG_DEBUG);
+	rte_log_set_level(RTE_LOGTYPE_EAL, RTE_LOG_DEBUG);
+
+	return unit_test_suite_runner(&security_testsuite);
+}
+
+REGISTER_TEST_COMMAND(security_autotest, test_security);
-- 
2.17.1


  parent reply	other threads:[~2020-03-12 15:18 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20200312151708eucas1p2a80bb2ac0556c7d7efb3aedd83923e52@eucas1p2.samsung.com>
2020-03-12 15:16 ` [dpdk-dev] [PATCH 00/13] Fixes and unit tests for librte_security Lukasz Wojciechowski
     [not found]   ` <CGME20200312151708eucas1p2acee543b5f9d236b8e43cd4d1fbed489@eucas1p2.samsung.com>
2020-03-12 15:16     ` [dpdk-dev] [PATCH 01/13] librte_security: fix verification of parameters Lukasz Wojciechowski
2020-03-17 12:59       ` Anoob Joseph
2020-04-03 18:36         ` Lukasz Wojciechowski
2020-04-05 12:54           ` [dpdk-dev] [EXT] " Anoob Joseph
2020-04-06 18:49             ` Lukasz Wojciechowski
2020-04-07  6:20               ` Anoob Joseph
2020-04-08  3:25                 ` Lukasz Wojciechowski
     [not found]   ` <CGME20200312151708eucas1p12db7c8e402be03dd255d53114217dabd@eucas1p1.samsung.com>
2020-03-12 15:16     ` [dpdk-dev] [PATCH 02/13] librte_security: fix return types in documentation Lukasz Wojciechowski
2020-03-17 16:34       ` Anoob Joseph
     [not found]   ` <CGME20200312151708eucas1p2536ef1df74b35ead436db85f8a5628b4@eucas1p2.samsung.com>
2020-03-12 15:16     ` [dpdk-dev] [PATCH 03/13] librte_security: fix session counter Lukasz Wojciechowski
2020-03-17 17:08       ` Anoob Joseph
     [not found]   ` <CGME20200312151708eucas1p18d3cde72ccadf22d43b8907ab9de6d97@eucas1p1.samsung.com>
2020-03-12 15:16     ` [dpdk-dev] [PATCH 04/13] app/test: fix macro definition Lukasz Wojciechowski
     [not found]   ` <CGME20200312151709eucas1p2df38aed23b7445d3db7d4d3ea8fe3222@eucas1p2.samsung.com>
2020-03-12 15:16     ` Lukasz Wojciechowski [this message]
2020-04-01 17:09       ` [dpdk-dev] [PATCH 05/13] app/test: introduce librte_security tests Akhil Goyal
2020-04-01 17:51         ` Thomas Monjalon
2020-04-02 19:49           ` Lukasz Wojciechowski
2020-04-02 20:51             ` Thomas Monjalon
2020-04-03 19:24         ` Lukasz Wojciechowski
     [not found]   ` <CGME20200312151709eucas1p1a01f789059de888cb2d719526434e4f9@eucas1p1.samsung.com>
2020-03-12 15:16     ` [dpdk-dev] [PATCH 06/13] app/test: add rte_security_session_update tests Lukasz Wojciechowski
     [not found]   ` <CGME20200312151709eucas1p139311cecb925f566cbbf1444d14c31b1@eucas1p1.samsung.com>
2020-03-12 15:16     ` [dpdk-dev] [PATCH 07/13] app/test: add rte_security_session_get_size tests Lukasz Wojciechowski
     [not found]   ` <CGME20200312151709eucas1p15263f75e2ad73aa9b8d2fb2d4cf51439@eucas1p1.samsung.com>
2020-03-12 15:16     ` [dpdk-dev] [PATCH 08/13] app/test: add rte_security_session_stats_get tests Lukasz Wojciechowski
     [not found]   ` <CGME20200312151710eucas1p22f051449e6e7edeadefe65b66ffaed32@eucas1p2.samsung.com>
2020-03-12 15:16     ` [dpdk-dev] [PATCH 09/13] app/test: add rte_security_session_destroy tests Lukasz Wojciechowski
     [not found]   ` <CGME20200312151710eucas1p10124737620ec6414aa593e7fa67ee56b@eucas1p1.samsung.com>
2020-03-12 15:16     ` [dpdk-dev] [PATCH 10/13] app/test: add rte_security_set_pkt_metadata tests Lukasz Wojciechowski
     [not found]   ` <CGME20200312151710eucas1p1c3590b55d00bea25b26539a560199b96@eucas1p1.samsung.com>
2020-03-12 15:16     ` [dpdk-dev] [PATCH 11/13] app/test: add rte_security_get_userdata tests Lukasz Wojciechowski
     [not found]   ` <CGME20200312151710eucas1p21882b138d4fd79753f993c30c997e615@eucas1p2.samsung.com>
2020-03-12 15:16     ` [dpdk-dev] [PATCH 12/13] app/test: add rte_security_capabilities_get tests Lukasz Wojciechowski
     [not found]   ` <CGME20200312151710eucas1p1fd5b1484c9ee807327d2d34511a47a12@eucas1p1.samsung.com>
2020-03-12 15:16     ` [dpdk-dev] [PATCH 13/13] app/test: add rte_security_capability_get tests Lukasz Wojciechowski
     [not found]   ` <CGME20200408031435eucas1p23b452d748e39e46c626f695b7f55096a@eucas1p2.samsung.com>
2020-04-08  3:13     ` [dpdk-dev] [PATCH v2 00/13] Fixes and unit tests for librte_security Lukasz Wojciechowski
     [not found]       ` <CGME20200408031447eucas1p1376332353faa0d217e7be8c32271405f@eucas1p1.samsung.com>
2020-04-08  3:13         ` [dpdk-dev] [PATCH v2 01/13] security: fix verification of parameters Lukasz Wojciechowski
2020-04-08 12:54           ` Thomas Monjalon
2020-04-08 13:02             ` Anoob Joseph
2020-04-08 13:26               ` Thomas Monjalon
2020-04-08 14:44                 ` [dpdk-dev] [EXT] " Anoob Joseph
2020-04-08 15:49                   ` Lukasz Wojciechowski
2020-04-08 17:51                     ` Thomas Monjalon
2020-04-09 10:14                       ` Bruce Richardson
2020-04-09 10:54                         ` Thomas Monjalon
2020-04-09 11:13                           ` Bruce Richardson
2020-04-09 14:07                             ` Lukasz Wojciechowski
2020-04-09 14:21                               ` Lukasz Wojciechowski
2020-04-09 15:22                                 ` Thomas Monjalon
2020-04-09 16:10                                   ` Lukasz Wojciechowski
2020-04-10  8:45                                     ` Bruce Richardson
     [not found]       ` <CGME20200408031448eucas1p2b36997fc73f5b5e2aadb6e4bb965063b@eucas1p2.samsung.com>
2020-04-08  3:13         ` [dpdk-dev] [PATCH v2 02/13] security: fix return types in documentation Lukasz Wojciechowski
     [not found]       ` <CGME20200408031448eucas1p2d6df7ff419bb093606a2f9115297f45a@eucas1p2.samsung.com>
2020-04-08  3:13         ` [dpdk-dev] [PATCH v2 03/13] security: fix session counter Lukasz Wojciechowski
     [not found]       ` <CGME20200408031449eucas1p1ca89719463cbaf29e9f7c81beaec88c2@eucas1p1.samsung.com>
2020-04-08  3:13         ` [dpdk-dev] [PATCH v2 04/13] app/test: fix macro definition Lukasz Wojciechowski
2020-04-08 12:53           ` Thomas Monjalon
2020-04-08 16:15             ` Lukasz Wojciechowski
2020-04-08 17:47               ` Thomas Monjalon
2020-04-09 14:10                 ` Lukasz Wojciechowski
     [not found]       ` <CGME20200408031450eucas1p1a0b6ca84cbac2f7542212e185de1ddf5@eucas1p1.samsung.com>
2020-04-08  3:13         ` [dpdk-dev] [PATCH v2 05/13] app/test: introduce librte security tests Lukasz Wojciechowski
     [not found]       ` <CGME20200408031451eucas1p2769ae9d814ef1ccd286407767054e117@eucas1p2.samsung.com>
2020-04-08  3:13         ` [dpdk-dev] [PATCH v2 06/13] app/test: add rte security session update tests Lukasz Wojciechowski
     [not found]       ` <CGME20200408031451eucas1p2313bee1d227e5966fb37c5326aa72529@eucas1p2.samsung.com>
2020-04-08  3:13         ` [dpdk-dev] [PATCH v2 07/13] app/test: add rte security session get size tests Lukasz Wojciechowski
     [not found]       ` <CGME20200408031452eucas1p2f75a75363e148c54f38b01b9a9a0ea47@eucas1p2.samsung.com>
2020-04-08  3:13         ` [dpdk-dev] [PATCH v2 08/13] app/test: add rte security session stats get tests Lukasz Wojciechowski
     [not found]       ` <CGME20200408031452eucas1p1b4de173fadca62824b472b8a3dd69e32@eucas1p1.samsung.com>
2020-04-08  3:13         ` [dpdk-dev] [PATCH v2 09/13] app/test: add rte security session destroy tests Lukasz Wojciechowski
     [not found]       ` <CGME20200408031453eucas1p15bf7f54b1a5b1ae7810a72c71bd6271c@eucas1p1.samsung.com>
2020-04-08  3:13         ` [dpdk-dev] [PATCH v2 10/13] app/test: add rte security set pkt metadata tests Lukasz Wojciechowski
     [not found]       ` <CGME20200408031453eucas1p1b26ad6b1f924b817e83fc2d2d61a0b0b@eucas1p1.samsung.com>
2020-04-08  3:13         ` [dpdk-dev] [PATCH v2 11/13] app/test: add rte security get userdata tests Lukasz Wojciechowski
     [not found]       ` <CGME20200408031454eucas1p112c6eded420bdcfdb09fad83bf485afb@eucas1p1.samsung.com>
2020-04-08  3:13         ` [dpdk-dev] [PATCH v2 12/13] app/test: add rte security capabilities get tests Lukasz Wojciechowski
     [not found]       ` <CGME20200408031454eucas1p2e09e0ab0a1ffa5c657bcf35d89c40a55@eucas1p2.samsung.com>
2020-04-08  3:13         ` [dpdk-dev] [PATCH v2 13/13] app/test: add rte security capability " Lukasz Wojciechowski
     [not found]       ` <CGME20200409172528eucas1p1186911653001cab0e69f10fc42790023@eucas1p1.samsung.com>
2020-04-09 17:24         ` [dpdk-dev] [PATCH v3 00/13] Fixes and unit tests for librte_security Lukasz Wojciechowski
     [not found]           ` <CGME20200409172529eucas1p1f02aaf66052f45ac75ba9e9f63ef1c3a@eucas1p1.samsung.com>
2020-04-09 17:24             ` [dpdk-dev] [PATCH v3 01/13] security: fix verification of parameters Lukasz Wojciechowski
2020-04-13 15:42               ` Anoob Joseph
     [not found]           ` <CGME20200409172530eucas1p27297a83a9d7508e3f8a8f88850cbe37c@eucas1p2.samsung.com>
2020-04-09 17:24             ` [dpdk-dev] [PATCH v3 02/13] security: fix return types in documentation Lukasz Wojciechowski
2020-04-13 15:43               ` Anoob Joseph
     [not found]           ` <CGME20200409172531eucas1p1c3ec21532e5e232ff2d68d56f096e71c@eucas1p1.samsung.com>
2020-04-09 17:24             ` [dpdk-dev] [PATCH v3 03/13] security: fix session counter Lukasz Wojciechowski
2020-04-13 15:48               ` Anoob Joseph
     [not found]           ` <CGME20200409172532eucas1p285bc6767be1d62a0098d177a7757169f@eucas1p2.samsung.com>
2020-04-09 17:24             ` [dpdk-dev] [PATCH v3 04/13] app/test: remove macro definition Lukasz Wojciechowski
     [not found]           ` <CGME20200409172533eucas1p1f4363aa89cfbda87e5d20da1006e21c0@eucas1p1.samsung.com>
2020-04-09 17:24             ` [dpdk-dev] [PATCH v3 05/13] app/test: introduce librte security tests Lukasz Wojciechowski
     [not found]           ` <CGME20200409172533eucas1p252ed0cac1689b067a83589a0665c9033@eucas1p2.samsung.com>
2020-04-09 17:24             ` [dpdk-dev] [PATCH v3 06/13] app/test: add rte security session update tests Lukasz Wojciechowski
     [not found]           ` <CGME20200409172534eucas1p2ee383bc5d8efd40ea8b883b78126ed9f@eucas1p2.samsung.com>
2020-04-09 17:24             ` [dpdk-dev] [PATCH v3 07/13] app/test: add rte security session get size tests Lukasz Wojciechowski
     [not found]           ` <CGME20200409172534eucas1p2852ae56687fd5bae343437b07198c070@eucas1p2.samsung.com>
2020-04-09 17:24             ` [dpdk-dev] [PATCH v3 08/13] app/test: add rte security session stats get tests Lukasz Wojciechowski
     [not found]           ` <CGME20200409172535eucas1p152b3d17bd9d2194f9f2669116130331d@eucas1p1.samsung.com>
2020-04-09 17:24             ` [dpdk-dev] [PATCH v3 09/13] app/test: add rte security session destroy tests Lukasz Wojciechowski
     [not found]           ` <CGME20200409172535eucas1p2c215489de77c708fc0bec6b9e2e3dd6d@eucas1p2.samsung.com>
2020-04-09 17:24             ` [dpdk-dev] [PATCH v3 10/13] app/test: add rte security set pkt metadata tests Lukasz Wojciechowski
     [not found]           ` <CGME20200409172536eucas1p282854dae8a3b6cceafdea5e2f4fa0896@eucas1p2.samsung.com>
2020-04-09 17:25             ` [dpdk-dev] [PATCH v3 11/13] app/test: add rte security get userdata tests Lukasz Wojciechowski
     [not found]           ` <CGME20200409172536eucas1p1396c04fb7a9fb80db2a5670f8f3453bb@eucas1p1.samsung.com>
2020-04-09 17:25             ` [dpdk-dev] [PATCH v3 12/13] app/test: add rte security capabilities get tests Lukasz Wojciechowski
     [not found]           ` <CGME20200409172538eucas1p1dcd99eeedf6fca44c2e2e53e94b08d91@eucas1p1.samsung.com>
2020-04-09 17:25             ` [dpdk-dev] [PATCH v3 13/13] app/test: add rte security capability " Lukasz Wojciechowski
2020-04-17 19:46           ` [dpdk-dev] [PATCH v3 00/13] Fixes and unit tests for librte_security Akhil Goyal
2020-04-17 20:14             ` Lukasz Wojciechowski
2020-04-17 20:21               ` Akhil Goyal
2020-04-17 20:39                 ` Lukasz Wojciechowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200312151654.7218-6-l.wojciechow@partner.samsung.com \
    --to=l.wojciechow@partner.samsung.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).