1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
7 #include <rte_memory.h>
8 #include <rte_mempool.h>
9 #include <rte_security.h>
10 #include <rte_security_driver.h>
12 /* Before including rte_test.h file you can define
13 * RTE_TEST_TRACE_FAILURE(_file, _line, _func) macro to better trace/debug test
14 * failures. Mostly useful in development phase.
16 #ifndef RTE_TEST_TRACE_FAILURE
17 #define RTE_TEST_TRACE_FAILURE(_file, _line, _func) \
18 RTE_LOG(DEBUG, EAL, "in %s:%d %s\n", _file, _line, _func)
28 * Basic unit tests of the librte_security API.
30 * Structure of the file:
31 * - macros for making tests more readable;
32 * - mockup structures and functions for rte_security_ops;
33 * - test suite and test cases setup and teardown functions;
35 * - declaration of testcases.
42 * Set of macros for making tests easier to read.
46 * Verify condition inside mocked up function.
47 * Mockup function cannot return a test error, so the failure
48 * of assertion increases counter and print logs.
49 * The counter can be verified later to check if test case should fail.
51 * @param fail_counter fail counter
52 * @param cond condition expected to be true
53 * @param msg printf style formatting string for custom message
55 #define MOCK_TEST_ASSERT(fail_counter, cond, msg, ...) do { \
58 RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: " \
59 msg "\n", __func__, __LINE__, \
61 RTE_TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__); \
66 * Verify equality condition inside mocked up function.
67 * Mockup function cannot return a test error, so the failure
68 * of assertion increases counter and print logs.
69 * The counter can be verified later to check if test case should fail.
71 * @param fail_counter fail counter
72 * @param a first value of comparison
73 * @param b second value of comparison
74 * @param msg printf style formatting string for custom message
76 #define MOCK_TEST_ASSERT_EQUAL(fail_counter, a, b, msg, ...) \
77 MOCK_TEST_ASSERT(fail_counter, (a) == (b), msg, ##__VA_ARGS__)
81 * Verify if parameter of the mocked up function matches expected value.
82 * The expected value is stored in data structure in the field matching
85 * @param data structure with expected values
86 * @param parameter name of the parameter (both field and parameter name)
87 * @param spec printf style spec for parameter
89 #define MOCK_TEST_ASSERT_PARAMETER(data, parameter, spec) \
90 MOCK_TEST_ASSERT_EQUAL(data.failed, data.parameter, parameter, \
91 "Expecting parameter %s to be " spec \
92 " but it's " spec, RTE_STR(parameter), \
93 data.parameter, parameter)
96 * Wrap for MOCK_TEST_ASSERT_PARAMETER macro for pointer type parameters.
98 * @param data structure with expected values
99 * @param parameter name of the parameter (both field and parameter name)
101 #define MOCK_TEST_ASSERT_POINTER_PARAMETER(data, parameter) \
102 MOCK_TEST_ASSERT_PARAMETER(data, parameter, "%p")
105 * Verify number of calls of the mocked up function
106 * and check if there were any fails during execution.
107 * The fails statistics inside mocked up functions are collected
108 * as "failed" field in mockup structures.
110 * @param mock_data structure with statistics (called, failed)
111 * @param exp_calls expected number of mockup function calls
113 #define TEST_ASSERT_MOCK_CALLS(mock_data, exp_calls) do { \
114 TEST_ASSERT_EQUAL(exp_calls, mock_data.called, \
115 "Expecting sub op to be called %d times, " \
116 "but it's called %d times", \
117 exp_calls, mock_data.called); \
118 TEST_ASSERT_EQUAL(0, mock_data.failed, \
119 "Expecting sub op asserts not to fail, " \
120 "but they're failed %d times", \
125 * Assert tested function result match expected value
127 * @param f_name name of tested function
128 * @param f_ret value returned by the function
129 * @param exp_ret expected returned value
130 * @param fmt printf style format for returned value
132 #define TEST_ASSERT_MOCK_FUNCTION_CALL_RET(f_name, f_ret, exp_ret, fmt) \
133 TEST_ASSERT_EQUAL(exp_ret, f_ret, "Expecting " RTE_STR(f_name) \
134 " to return " fmt ", but it returned " fmt \
135 "\n", exp_ret, f_ret)
138 * Assert tested function result is not NULL
140 * @param f_name name of tested function
141 * @param f_ret value returned by the function
143 #define TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(f_name, f_ret) \
144 TEST_ASSERT_NOT_NULL(f_ret, "Expecting " RTE_STR(f_name) \
145 " to return not NULL\n")
148 * Verify that sess_cnt counter value matches expected
150 * @param expected_sessions_count expected counter value
152 #define TEST_ASSERT_SESSION_COUNT(expected_sessions_count) do { \
153 struct security_unittest_params *ut_params = &unittest_params; \
154 TEST_ASSERT_EQUAL(expected_sessions_count, \
155 ut_params->ctx.sess_cnt, \
156 "Expecting session counter to be %u," \
157 " but it's %u", expected_sessions_count, \
158 ut_params->ctx.sess_cnt); \
162 * Verify usage of mempool by checking if number of allocated objects matches
163 * expectations. The mempool is used to manage objects for sessions data.
164 * A single object is acquired from mempool during session_create
165 * and put back in session_destroy.
167 * @param expected_mempool_usage expected number of used mempool objects
169 #define TEST_ASSERT_MEMPOOL_USAGE(expected_mempool_usage) do { \
170 struct security_testsuite_params *ts_params = &testsuite_params;\
171 unsigned int mempool_usage; \
172 mempool_usage = rte_mempool_in_use_count( \
173 ts_params->session_mpool); \
174 TEST_ASSERT_EQUAL(expected_mempool_usage, mempool_usage, \
175 "Expecting %u mempool allocations, " \
176 "but there are %u allocated objects", \
177 expected_mempool_usage, mempool_usage); \
182 * Mockup structures and functions for rte_security_ops;
184 * Set of structures for controlling mockup functions calls.
185 * Every mockup function X has its corresponding X_data structure
186 * and an instance of that structure X_exp.
187 * Structure contains parameters that a mockup function is expected
188 * to be called with, a value to return (.ret) and 2 statistics:
189 * .called (number of times the mockup function was called)
190 * and .failed (number of assertion fails during mockup function call).
192 * Mockup functions verify that the parameters they are called with match
193 * expected values. The expected values should be stored in corresponding
194 * structures prior to mockup functions call. Every failure of such
195 * verification increases .failed counter. Every call of mockup function
196 * increases .called counter. Function returns value stored in .ret field
198 * In case of some parameters in some functions the expected value is unknown
199 * and cannot be detrmined prior to call. Such parameters are stored
200 * in structure and can be compared or analyzed later in test case code.
202 * Below structures and functions follow the rules just described.
203 * Additional remarks and exceptions are added in comments.
207 * session_create mockup
209 * Verified parameters: device, conf, mp.
210 * Saved, not verified parameters: sess.
212 static struct mock_session_create_data {
214 struct rte_security_session_conf *conf;
215 struct rte_security_session *sess;
216 struct rte_mempool *mp;
222 } mock_session_create_exp = {NULL, NULL, NULL, NULL, 0, 0, 0};
225 mock_session_create(void *device,
226 struct rte_security_session_conf *conf,
227 struct rte_security_session *sess,
228 struct rte_mempool *mp)
230 mock_session_create_exp.called++;
232 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, device);
233 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, conf);
234 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, mp);
236 mock_session_create_exp.sess = sess;
238 return mock_session_create_exp.ret;
242 * session_update mockup
244 * Verified parameters: device, sess, conf.
246 static struct mock_session_update_data {
248 struct rte_security_session *sess;
249 struct rte_security_session_conf *conf;
255 } mock_session_update_exp = {NULL, NULL, NULL, 0, 0, 0};
258 mock_session_update(void *device,
259 struct rte_security_session *sess,
260 struct rte_security_session_conf *conf)
262 mock_session_update_exp.called++;
264 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, device);
265 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, sess);
266 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, conf);
268 return mock_session_update_exp.ret;
272 * session_destroy mockup
274 * Verified parameters: device, sess.
276 static struct mock_session_destroy_data {
278 struct rte_security_session *sess;
284 } mock_session_destroy_exp = {NULL, NULL, 0, 0, 0};
287 mock_session_destroy(void *device, struct rte_security_session *sess)
289 mock_session_destroy_exp.called++;
291 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_destroy_exp, device);
292 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_destroy_exp, sess);
294 return mock_session_destroy_exp.ret;
300 * is an empty security operations set (all function pointers set to NULL)
302 struct rte_security_ops empty_ops = { NULL };
307 * is a security operations set using mockup functions
309 struct rte_security_ops mock_ops = {
310 .session_create = mock_session_create,
311 .session_update = mock_session_update,
312 .session_destroy = mock_session_destroy,
317 * Test suite and test cases setup and teardown functions.
321 * struct security_testsuite_params defines parameters initialized once
322 * for whole tests suite.
323 * Currently the only stored parameter is session_mpool a mempool created
324 * once in testsuite_setup and released in testsuite_teardown.
325 * The instance of this structure is stored in testsuite_params variable.
327 static struct security_testsuite_params {
328 struct rte_mempool *session_mpool;
329 } testsuite_params = { NULL };
332 * struct security_unittest_params defines parameters initialized
333 * for every test case. The parameters are initialized in ut_setup
334 * or ut_setup_with_session (depending on the testcase)
335 * and released in ut_teardown.
336 * The instance of this structure is stored in unittest_params variable.
338 static struct security_unittest_params {
339 struct rte_security_ctx ctx;
340 struct rte_security_session_conf conf;
341 struct rte_security_session *sess;
342 } unittest_params = {
351 #define SECURITY_TEST_MEMPOOL_NAME "SecurityTestsMempoolName"
352 #define SECURITY_TEST_MEMPOOL_SIZE 15
353 #define SECURITY_TEST_SESSION_OBJECT_SIZE sizeof(struct rte_security_session)
356 * testsuite_setup initializes whole test suite parameters.
357 * It creates a new mempool used in all test cases
358 * and verifies if it properly created.
361 testsuite_setup(void)
363 struct security_testsuite_params *ts_params = &testsuite_params;
364 ts_params->session_mpool = rte_mempool_create(
365 SECURITY_TEST_MEMPOOL_NAME,
366 SECURITY_TEST_MEMPOOL_SIZE,
367 SECURITY_TEST_SESSION_OBJECT_SIZE,
368 0, 0, NULL, NULL, NULL, NULL,
370 TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
371 "Cannot create mempool %s\n", rte_strerror(rte_errno));
376 * testsuite_teardown releases test suite wide parameters.
379 testsuite_teardown(void)
381 struct security_testsuite_params *ts_params = &testsuite_params;
382 if (ts_params->session_mpool) {
383 rte_mempool_free(ts_params->session_mpool);
384 ts_params->session_mpool = NULL;
389 * ut_setup initializes test case parameters to default values.
390 * It resets also any .called and .failed statistics of mockup functions
396 struct security_unittest_params *ut_params = &unittest_params;
397 ut_params->ctx.device = NULL;
398 ut_params->ctx.ops = &mock_ops;
399 ut_params->ctx.sess_cnt = 0;
400 ut_params->sess = NULL;
402 mock_session_create_exp.called = 0;
403 mock_session_update_exp.called = 0;
404 mock_session_destroy_exp.called = 0;
406 mock_session_create_exp.failed = 0;
407 mock_session_update_exp.failed = 0;
408 mock_session_destroy_exp.failed = 0;
414 * destroy_session_with_check is a helper function releasing session
415 * created with rte_security_session_create and stored in test case parameters.
416 * It's used both to release sessions created in test cases' bodies
417 * which are assigned to ut_params->sess
418 * as well as sessions created in ut_setup_with_session.
421 destroy_session_with_check(void)
423 struct security_unittest_params *ut_params = &unittest_params;
424 if (ut_params->sess != NULL) {
425 /* Assure that mockup function for destroy operation is set. */
426 ut_params->ctx.ops = &mock_ops;
428 mock_session_destroy_exp.device = NULL;
429 mock_session_destroy_exp.sess = ut_params->sess;
430 mock_session_destroy_exp.ret = 0;
431 mock_session_destroy_exp.called = 0;
432 mock_session_destroy_exp.failed = 0;
434 int ret = rte_security_session_destroy(&ut_params->ctx,
436 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
438 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
440 ut_params->sess = NULL;
446 * ut_teardown releases test case parameters.
451 destroy_session_with_check();
455 * ut_setup_with_session initializes test case parameters by
456 * - calling standard ut_setup,
457 * - creating a session that can be used in test case.
460 ut_setup_with_session(void)
462 struct security_unittest_params *ut_params = &unittest_params;
463 struct security_testsuite_params *ts_params = &testsuite_params;
464 struct rte_security_session *sess;
466 int ret = ut_setup();
467 if (ret != TEST_SUCCESS)
470 mock_session_create_exp.device = NULL;
471 mock_session_create_exp.conf = &ut_params->conf;
472 mock_session_create_exp.mp = ts_params->session_mpool;
473 mock_session_create_exp.ret = 0;
475 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
476 ts_params->session_mpool);
477 TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(rte_security_session_create,
479 TEST_ASSERT_EQUAL(sess, mock_session_create_exp.sess,
480 "Expecting session_create to be called with %p sess"
481 " parameter, but it's called %p sess parameter",
482 sess, mock_session_create_exp.sess);
483 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
486 * Store created session in test case parameters, so it can be released
487 * after test case in ut_teardown by destroy_session_with_check.
489 ut_params->sess = sess;
498 * Each test function is related to a single test case.
499 * They are arranged by tested rte_security API function
500 * and by rte_security execution paths sequence in code.
504 * rte_security_session_create tests
508 * Test execution of rte_security_session_create with NULL instance
511 test_session_create_inv_context(void)
513 struct security_testsuite_params *ts_params = &testsuite_params;
514 struct security_unittest_params *ut_params = &unittest_params;
515 struct rte_security_session *sess;
517 sess = rte_security_session_create(NULL, &ut_params->conf,
518 ts_params->session_mpool);
519 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
521 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
522 TEST_ASSERT_MEMPOOL_USAGE(0);
523 TEST_ASSERT_SESSION_COUNT(0);
529 * Test execution of rte_security_session_create with invalid
530 * security operations structure (NULL)
533 test_session_create_inv_context_ops(void)
535 struct security_testsuite_params *ts_params = &testsuite_params;
536 struct security_unittest_params *ut_params = &unittest_params;
537 struct rte_security_session *sess;
539 ut_params->ctx.ops = NULL;
541 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
542 ts_params->session_mpool);
543 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
545 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
546 TEST_ASSERT_MEMPOOL_USAGE(0);
547 TEST_ASSERT_SESSION_COUNT(0);
553 * Test execution of rte_security_session_create with empty
554 * security operations
557 test_session_create_inv_context_ops_fun(void)
559 struct security_testsuite_params *ts_params = &testsuite_params;
560 struct security_unittest_params *ut_params = &unittest_params;
561 struct rte_security_session *sess;
563 ut_params->ctx.ops = &empty_ops;
565 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
566 ts_params->session_mpool);
567 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
569 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
570 TEST_ASSERT_MEMPOOL_USAGE(0);
571 TEST_ASSERT_SESSION_COUNT(0);
577 * Test execution of rte_security_session_create with NULL conf parameter
580 test_session_create_inv_configuration(void)
582 struct security_testsuite_params *ts_params = &testsuite_params;
583 struct security_unittest_params *ut_params = &unittest_params;
584 struct rte_security_session *sess;
586 sess = rte_security_session_create(&ut_params->ctx, NULL,
587 ts_params->session_mpool);
588 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
590 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
591 TEST_ASSERT_MEMPOOL_USAGE(0);
592 TEST_ASSERT_SESSION_COUNT(0);
598 * Test execution of rte_security_session_create with NULL mp parameter
601 test_session_create_inv_mempool(void)
603 struct security_unittest_params *ut_params = &unittest_params;
604 struct rte_security_session *sess;
606 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
608 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
610 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
611 TEST_ASSERT_MEMPOOL_USAGE(0);
612 TEST_ASSERT_SESSION_COUNT(0);
618 * Test execution of rte_security_session_create in case when mempool
619 * is fully used and no object can be got from it
622 test_session_create_mempool_empty(void)
624 struct security_testsuite_params *ts_params = &testsuite_params;
625 struct security_unittest_params *ut_params = &unittest_params;
626 struct rte_security_session *tmp[SECURITY_TEST_MEMPOOL_SIZE];
627 struct rte_security_session *sess;
629 /* Get all available objects from mempool. */
631 for (i = 0; i < SECURITY_TEST_MEMPOOL_SIZE; ++i) {
632 ret = rte_mempool_get(ts_params->session_mpool,
634 TEST_ASSERT_EQUAL(0, ret,
635 "Expect getting %d object from mempool"
638 TEST_ASSERT_MEMPOOL_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
640 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
641 ts_params->session_mpool);
642 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
644 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
645 TEST_ASSERT_MEMPOOL_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
646 TEST_ASSERT_SESSION_COUNT(0);
648 /* Put objects back to the pool. */
649 for (i = 0; i < SECURITY_TEST_MEMPOOL_SIZE; ++i)
650 rte_mempool_put(ts_params->session_mpool, (void *)(tmp[i]));
651 TEST_ASSERT_MEMPOOL_USAGE(0);
657 * Test execution of rte_security_session_create when session_create
658 * security operation fails
661 test_session_create_ops_failure(void)
663 struct security_testsuite_params *ts_params = &testsuite_params;
664 struct security_unittest_params *ut_params = &unittest_params;
665 struct rte_security_session *sess;
667 mock_session_create_exp.device = NULL;
668 mock_session_create_exp.conf = &ut_params->conf;
669 mock_session_create_exp.mp = ts_params->session_mpool;
670 mock_session_create_exp.ret = -1; /* Return failure status. */
672 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
673 ts_params->session_mpool);
674 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
676 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
677 TEST_ASSERT_MEMPOOL_USAGE(0);
678 TEST_ASSERT_SESSION_COUNT(0);
684 * Test execution of rte_security_session_create in successful execution path
687 test_session_create_success(void)
689 struct security_testsuite_params *ts_params = &testsuite_params;
690 struct security_unittest_params *ut_params = &unittest_params;
691 struct rte_security_session *sess;
693 mock_session_create_exp.device = NULL;
694 mock_session_create_exp.conf = &ut_params->conf;
695 mock_session_create_exp.mp = ts_params->session_mpool;
696 mock_session_create_exp.ret = 0; /* Return success status. */
698 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
699 ts_params->session_mpool);
700 TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(rte_security_session_create,
702 TEST_ASSERT_EQUAL(sess, mock_session_create_exp.sess,
703 "Expecting session_create to be called with %p sess"
704 " parameter, but it's called %p sess parameter",
705 sess, mock_session_create_exp.sess);
706 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
707 TEST_ASSERT_MEMPOOL_USAGE(1);
708 TEST_ASSERT_SESSION_COUNT(1);
711 * Store created session in test case parameters, so it can be released
712 * after test case in ut_teardown by destroy_session_with_check.
714 ut_params->sess = sess;
721 * rte_security_session_update tests
725 * Test execution of rte_security_session_update with NULL instance
728 test_session_update_inv_context(void)
730 struct security_unittest_params *ut_params = &unittest_params;
732 int ret = rte_security_session_update(NULL, ut_params->sess,
734 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
736 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
742 * Test execution of rte_security_session_update with invalid
743 * security operations structure (NULL)
746 test_session_update_inv_context_ops(void)
748 struct security_unittest_params *ut_params = &unittest_params;
749 ut_params->ctx.ops = NULL;
751 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
753 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
755 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
761 * Test execution of rte_security_session_update with empty
762 * security operations
765 test_session_update_inv_context_ops_fun(void)
767 struct security_unittest_params *ut_params = &unittest_params;
768 ut_params->ctx.ops = &empty_ops;
770 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
772 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
773 ret, -ENOTSUP, "%d");
774 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
780 * Test execution of rte_security_session_update with NULL conf parameter
783 test_session_update_inv_configuration(void)
785 struct security_unittest_params *ut_params = &unittest_params;
787 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
789 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
791 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
797 * Test execution of rte_security_session_update with NULL sess parameter
800 test_session_update_inv_session(void)
802 struct security_unittest_params *ut_params = &unittest_params;
804 int ret = rte_security_session_update(&ut_params->ctx, NULL,
806 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
808 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
814 * Test execution of rte_security_session_update when session_update
815 * security operation fails
818 test_session_update_ops_failure(void)
820 struct security_unittest_params *ut_params = &unittest_params;
822 mock_session_update_exp.device = NULL;
823 mock_session_update_exp.sess = ut_params->sess;
824 mock_session_update_exp.conf = &ut_params->conf;
825 mock_session_update_exp.ret = -1; /* Return failure status. */
827 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
829 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
831 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 1);
837 * Test execution of rte_security_session_update in successful execution path
840 test_session_update_success(void)
842 struct security_unittest_params *ut_params = &unittest_params;
844 mock_session_update_exp.device = NULL;
845 mock_session_update_exp.sess = ut_params->sess;
846 mock_session_update_exp.conf = &ut_params->conf;
847 mock_session_update_exp.ret = 0; /* Return success status. */
849 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
851 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
853 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 1);
860 * Declaration of testcases
862 static struct unit_test_suite security_testsuite = {
863 .suite_name = "generic security",
864 .setup = testsuite_setup,
865 .teardown = testsuite_teardown,
867 TEST_CASE_ST(ut_setup, ut_teardown,
868 test_session_create_inv_context),
869 TEST_CASE_ST(ut_setup, ut_teardown,
870 test_session_create_inv_context_ops),
871 TEST_CASE_ST(ut_setup, ut_teardown,
872 test_session_create_inv_context_ops_fun),
873 TEST_CASE_ST(ut_setup, ut_teardown,
874 test_session_create_inv_configuration),
875 TEST_CASE_ST(ut_setup, ut_teardown,
876 test_session_create_inv_mempool),
877 TEST_CASE_ST(ut_setup, ut_teardown,
878 test_session_create_mempool_empty),
879 TEST_CASE_ST(ut_setup, ut_teardown,
880 test_session_create_ops_failure),
881 TEST_CASE_ST(ut_setup, ut_teardown,
882 test_session_create_success),
884 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
885 test_session_update_inv_context),
886 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
887 test_session_update_inv_context_ops),
888 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
889 test_session_update_inv_context_ops_fun),
890 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
891 test_session_update_inv_configuration),
892 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
893 test_session_update_inv_session),
894 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
895 test_session_update_ops_failure),
896 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
897 test_session_update_success),
899 TEST_CASES_END() /**< NULL terminate unit test array */
906 rte_log_set_global_level(RTE_LOG_DEBUG);
907 rte_log_set_level(RTE_LOGTYPE_EAL, RTE_LOG_DEBUG);
909 return unit_test_suite_runner(&security_testsuite);
912 REGISTER_TEST_COMMAND(security_autotest, test_security);