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>
10 #include <rte_security.h>
11 #include <rte_security_driver.h>
13 /* Before including rte_test.h file you can define
14 * RTE_TEST_TRACE_FAILURE(_file, _line, _func) macro to better trace/debug test
15 * failures. Mostly useful in development phase.
17 #ifndef RTE_TEST_TRACE_FAILURE
18 #define RTE_TEST_TRACE_FAILURE(_file, _line, _func) \
19 RTE_LOG(DEBUG, EAL, "in %s:%d %s\n", _file, _line, _func)
29 * Basic unit tests of the librte_security API.
31 * Structure of the file:
32 * - macros for making tests more readable;
33 * - mockup structures and functions for rte_security_ops;
34 * - test suite and test cases setup and teardown functions;
36 * - declaration of testcases.
43 * Set of macros for making tests easier to read.
47 * Verify condition inside mocked up function.
48 * Mockup function cannot return a test error, so the failure
49 * of assertion increases counter and print logs.
50 * The counter can be verified later to check if test case should fail.
52 * @param fail_counter fail counter
53 * @param cond condition expected to be true
54 * @param msg printf style formatting string for custom message
56 #define MOCK_TEST_ASSERT(fail_counter, cond, msg, ...) do { \
59 RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: " \
60 msg "\n", __func__, __LINE__, \
62 RTE_TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__); \
67 * Verify equality condition inside mocked up function.
68 * Mockup function cannot return a test error, so the failure
69 * of assertion increases counter and print logs.
70 * The counter can be verified later to check if test case should fail.
72 * @param fail_counter fail counter
73 * @param a first value of comparison
74 * @param b second value of comparison
75 * @param msg printf style formatting string for custom message
77 #define MOCK_TEST_ASSERT_EQUAL(fail_counter, a, b, msg, ...) \
78 MOCK_TEST_ASSERT(fail_counter, (a) == (b), msg, ##__VA_ARGS__)
81 * Verify not null condition inside mocked up function.
82 * Mockup function cannot return a test error, so the failure
83 * of assertion increases counter and print logs.
84 * The counter can be verified later to check if test case should fail.
86 * @param fail_counter fail counter
87 * @param val value expected not to be NULL
88 * @param msg printf style formatting string for custom message
90 #define MOCK_TEST_ASSERT_NOT_NULL(fail_counter, val, msg, ...) \
91 MOCK_TEST_ASSERT(fail_counter, (val) != NULL, msg, ##__VA_ARGS__)
95 * Verify if parameter of the mocked up function matches expected value.
96 * The expected value is stored in data structure in the field matching
99 * @param data structure with expected values
100 * @param parameter name of the parameter (both field and parameter name)
101 * @param spec printf style spec for parameter
103 #define MOCK_TEST_ASSERT_PARAMETER(data, parameter, spec) \
104 MOCK_TEST_ASSERT_EQUAL(data.failed, data.parameter, parameter, \
105 "Expecting parameter %s to be " spec \
106 " but it's " spec, RTE_STR(parameter), \
107 data.parameter, parameter)
110 * Wrap for MOCK_TEST_ASSERT_PARAMETER macro for pointer type parameters.
112 * @param data structure with expected values
113 * @param parameter name of the parameter (both field and parameter name)
115 #define MOCK_TEST_ASSERT_POINTER_PARAMETER(data, parameter) \
116 MOCK_TEST_ASSERT_PARAMETER(data, parameter, "%p")
119 * Wrap for MOCK_TEST_ASSERT_PARAMETER macro for uint64_t type parameters.
121 * @param data structure with expected values
122 * @param parameter name of the parameter (both field and parameter name)
124 #define MOCK_TEST_ASSERT_U64_PARAMETER(data, parameter) \
125 MOCK_TEST_ASSERT_PARAMETER(data, parameter, "%" PRIu64)
128 * Verify number of calls of the mocked up function
129 * and check if there were any fails during execution.
130 * The fails statistics inside mocked up functions are collected
131 * as "failed" field in mockup structures.
133 * @param mock_data structure with statistics (called, failed)
134 * @param exp_calls expected number of mockup function calls
136 #define TEST_ASSERT_MOCK_CALLS(mock_data, exp_calls) do { \
137 TEST_ASSERT_EQUAL(exp_calls, mock_data.called, \
138 "Expecting sub op to be called %d times, " \
139 "but it's called %d times", \
140 exp_calls, mock_data.called); \
141 TEST_ASSERT_EQUAL(0, mock_data.failed, \
142 "Expecting sub op asserts not to fail, " \
143 "but they're failed %d times", \
148 * Assert tested function result match expected value
150 * @param f_name name of tested function
151 * @param f_ret value returned by the function
152 * @param exp_ret expected returned value
153 * @param fmt printf style format for returned value
155 #define TEST_ASSERT_MOCK_FUNCTION_CALL_RET(f_name, f_ret, exp_ret, fmt) \
156 TEST_ASSERT_EQUAL(exp_ret, f_ret, "Expecting " RTE_STR(f_name) \
157 " to return " fmt ", but it returned " fmt \
158 "\n", exp_ret, f_ret)
161 * Assert tested function result is not NULL
163 * @param f_name name of tested function
164 * @param f_ret value returned by the function
166 #define TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(f_name, f_ret) \
167 TEST_ASSERT_NOT_NULL(f_ret, "Expecting " RTE_STR(f_name) \
168 " to return not NULL\n")
171 * Verify that sess_cnt counter value matches expected
173 * @param expected_sessions_count expected counter value
175 #define TEST_ASSERT_SESSION_COUNT(expected_sessions_count) do { \
176 struct security_unittest_params *ut_params = &unittest_params; \
177 TEST_ASSERT_EQUAL(expected_sessions_count, \
178 ut_params->ctx.sess_cnt, \
179 "Expecting session counter to be %u," \
180 " but it's %u", expected_sessions_count, \
181 ut_params->ctx.sess_cnt); \
185 * Verify usage of mempool by checking if number of allocated objects matches
186 * expectations. The mempool is used to manage objects for sessions data.
187 * A single object is acquired from mempool during session_create
188 * and put back in session_destroy.
190 * @param expected_mempool_usage expected number of used mempool objects
192 #define TEST_ASSERT_MEMPOOL_USAGE(expected_mempool_usage) do { \
193 struct security_testsuite_params *ts_params = &testsuite_params;\
194 unsigned int mempool_usage; \
195 mempool_usage = rte_mempool_in_use_count( \
196 ts_params->session_mpool); \
197 TEST_ASSERT_EQUAL(expected_mempool_usage, mempool_usage, \
198 "Expecting %u mempool allocations, " \
199 "but there are %u allocated objects", \
200 expected_mempool_usage, mempool_usage); \
204 * Verify usage of mempool by checking if number of allocated objects matches
205 * expectations. The mempool is used to manage objects for sessions priv data.
206 * A single object is acquired from mempool during session_create
207 * and put back in session_destroy.
209 * @param expected_priv_mp_usage expected number of used priv mp objects
211 #define TEST_ASSERT_PRIV_MP_USAGE(expected_priv_mp_usage) do { \
212 struct security_testsuite_params *ts_params = &testsuite_params;\
213 unsigned int priv_mp_usage; \
214 priv_mp_usage = rte_mempool_in_use_count( \
215 ts_params->session_priv_mpool); \
216 TEST_ASSERT_EQUAL(expected_priv_mp_usage, priv_mp_usage, \
217 "Expecting %u priv mempool allocations, " \
218 "but there are %u allocated objects", \
219 expected_priv_mp_usage, priv_mp_usage); \
223 * Mockup structures and functions for rte_security_ops;
225 * Set of structures for controlling mockup functions calls.
226 * Every mockup function X has its corresponding X_data structure
227 * and an instance of that structure X_exp.
228 * Structure contains parameters that a mockup function is expected
229 * to be called with, a value to return (.ret) and 2 statistics:
230 * .called (number of times the mockup function was called)
231 * and .failed (number of assertion fails during mockup function call).
233 * Mockup functions verify that the parameters they are called with match
234 * expected values. The expected values should be stored in corresponding
235 * structures prior to mockup functions call. Every failure of such
236 * verification increases .failed counter. Every call of mockup function
237 * increases .called counter. Function returns value stored in .ret field
239 * In case of some parameters in some functions the expected value is unknown
240 * and cannot be detrmined prior to call. Such parameters are stored
241 * in structure and can be compared or analyzed later in test case code.
243 * Below structures and functions follow the rules just described.
244 * Additional remarks and exceptions are added in comments.
248 * session_create mockup
250 * Verified parameters: device, conf, mp.
251 * Saved, not verified parameters: sess.
253 static struct mock_session_create_data {
255 struct rte_security_session_conf *conf;
256 struct rte_security_session *sess;
257 struct rte_mempool *mp;
258 struct rte_mempool *priv_mp;
264 } mock_session_create_exp = {NULL, NULL, NULL, NULL, NULL, 0, 0, 0};
267 mock_session_create(void *device,
268 struct rte_security_session_conf *conf,
269 struct rte_security_session *sess,
270 struct rte_mempool *priv_mp)
275 mock_session_create_exp.called++;
277 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, device);
278 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, conf);
279 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, priv_mp);
281 if (mock_session_create_exp.ret == 0) {
282 ret = rte_mempool_get(priv_mp, &sess_priv);
283 TEST_ASSERT_EQUAL(0, ret,
284 "priv mempool does not have enough objects");
286 set_sec_session_private_data(sess, sess_priv);
287 mock_session_create_exp.sess = sess;
290 return mock_session_create_exp.ret;
294 * session_update mockup
296 * Verified parameters: device, sess, conf.
298 static struct mock_session_update_data {
300 struct rte_security_session *sess;
301 struct rte_security_session_conf *conf;
307 } mock_session_update_exp = {NULL, NULL, NULL, 0, 0, 0};
310 mock_session_update(void *device,
311 struct rte_security_session *sess,
312 struct rte_security_session_conf *conf)
314 mock_session_update_exp.called++;
316 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, device);
317 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, sess);
318 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, conf);
320 return mock_session_update_exp.ret;
324 * session_get_size mockup
326 * Verified parameters: device.
328 static struct mock_session_get_size_data {
335 } mock_session_get_size_exp = {NULL, 0U, 0, 0};
338 mock_session_get_size(void *device)
340 mock_session_get_size_exp.called++;
342 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_get_size_exp, device);
344 return mock_session_get_size_exp.ret;
348 * session_stats_get mockup
350 * Verified parameters: device, sess, stats.
352 static struct mock_session_stats_get_data {
354 struct rte_security_session *sess;
355 struct rte_security_stats *stats;
361 } mock_session_stats_get_exp = {NULL, NULL, NULL, 0, 0, 0};
364 mock_session_stats_get(void *device,
365 struct rte_security_session *sess,
366 struct rte_security_stats *stats)
368 mock_session_stats_get_exp.called++;
370 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_stats_get_exp, device);
371 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_stats_get_exp, sess);
372 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_stats_get_exp, stats);
374 return mock_session_stats_get_exp.ret;
378 * session_destroy mockup
380 * Verified parameters: device, sess.
382 static struct mock_session_destroy_data {
384 struct rte_security_session *sess;
390 } mock_session_destroy_exp = {NULL, NULL, 0, 0, 0};
393 mock_session_destroy(void *device, struct rte_security_session *sess)
395 void *sess_priv = get_sec_session_private_data(sess);
397 mock_session_destroy_exp.called++;
398 if ((mock_session_destroy_exp.ret == 0) && (sess_priv != NULL)) {
399 rte_mempool_put(rte_mempool_from_obj(sess_priv), sess_priv);
400 set_sec_session_private_data(sess, NULL);
402 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_destroy_exp, device);
403 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_destroy_exp, sess);
405 return mock_session_destroy_exp.ret;
409 * set_pkt_metadata mockup
411 * Verified parameters: device, sess, m, params.
413 static struct mock_set_pkt_metadata_data {
415 struct rte_security_session *sess;
423 } mock_set_pkt_metadata_exp = {NULL, NULL, NULL, NULL, 0, 0, 0};
426 mock_set_pkt_metadata(void *device,
427 struct rte_security_session *sess,
431 mock_set_pkt_metadata_exp.called++;
433 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, device);
434 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, sess);
435 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, m);
436 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, params);
438 return mock_set_pkt_metadata_exp.ret;
442 * get_userdata mockup
444 * Verified parameters: device, md.
445 * The userdata parameter works as an output parameter, so a passed address
446 * is verified not to be NULL and filled with userdata stored in structure.
448 static struct mock_get_userdata_data {
457 } mock_get_userdata_exp = {NULL, 0UL, NULL, 0, 0, 0};
460 mock_get_userdata(void *device,
464 mock_get_userdata_exp.called++;
466 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_get_userdata_exp, device);
467 MOCK_TEST_ASSERT_U64_PARAMETER(mock_get_userdata_exp, md);
469 MOCK_TEST_ASSERT_NOT_NULL(mock_get_userdata_exp.failed,
471 "Expecting parameter userdata not to be NULL but it's %p",
473 *userdata = mock_get_userdata_exp.userdata;
475 return mock_get_userdata_exp.ret;
479 * capabilities_get mockup
481 * Verified parameters: device.
483 static struct mock_capabilities_get_data {
486 struct rte_security_capability *ret;
490 } mock_capabilities_get_exp = {NULL, NULL, 0, 0};
492 static const struct rte_security_capability *
493 mock_capabilities_get(void *device)
495 mock_capabilities_get_exp.called++;
497 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_capabilities_get_exp, device);
499 return mock_capabilities_get_exp.ret;
505 * is an empty security operations set (all function pointers set to NULL)
507 struct rte_security_ops empty_ops = { NULL };
512 * is a security operations set using mockup functions
514 struct rte_security_ops mock_ops = {
515 .session_create = mock_session_create,
516 .session_update = mock_session_update,
517 .session_get_size = mock_session_get_size,
518 .session_stats_get = mock_session_stats_get,
519 .session_destroy = mock_session_destroy,
520 .set_pkt_metadata = mock_set_pkt_metadata,
521 .get_userdata = mock_get_userdata,
522 .capabilities_get = mock_capabilities_get,
527 * Test suite and test cases setup and teardown functions.
531 * struct security_testsuite_params defines parameters initialized once
532 * for whole tests suite.
533 * Currently the only stored parameter is session_mpool a mempool created
534 * once in testsuite_setup and released in testsuite_teardown.
535 * The instance of this structure is stored in testsuite_params variable.
537 static struct security_testsuite_params {
538 struct rte_mempool *session_mpool;
539 struct rte_mempool *session_priv_mpool;
540 } testsuite_params = { NULL };
543 * struct security_unittest_params defines parameters initialized
544 * for every test case. The parameters are initialized in ut_setup
545 * or ut_setup_with_session (depending on the testcase)
546 * and released in ut_teardown.
547 * The instance of this structure is stored in unittest_params variable.
549 static struct security_unittest_params {
550 struct rte_security_ctx ctx;
551 struct rte_security_session_conf conf;
552 struct rte_security_session *sess;
553 } unittest_params = {
562 #define SECURITY_TEST_MEMPOOL_NAME "SecurityTestMp"
563 #define SECURITY_TEST_PRIV_MEMPOOL_NAME "SecurityTestPrivMp"
564 #define SECURITY_TEST_MEMPOOL_SIZE 15
565 #define SECURITY_TEST_SESSION_OBJ_SZ sizeof(struct rte_security_session)
566 #define SECURITY_TEST_SESSION_PRIV_OBJ_SZ 64
569 * testsuite_setup initializes whole test suite parameters.
570 * It creates a new mempool used in all test cases
571 * and verifies if it properly created.
574 testsuite_setup(void)
576 struct security_testsuite_params *ts_params = &testsuite_params;
577 ts_params->session_mpool = rte_mempool_create(
578 SECURITY_TEST_MEMPOOL_NAME,
579 SECURITY_TEST_MEMPOOL_SIZE,
580 SECURITY_TEST_SESSION_OBJ_SZ,
581 0, 0, NULL, NULL, NULL, NULL,
583 TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
584 "Cannot create mempool %s\n", rte_strerror(rte_errno));
586 ts_params->session_priv_mpool = rte_mempool_create(
587 SECURITY_TEST_PRIV_MEMPOOL_NAME,
588 SECURITY_TEST_MEMPOOL_SIZE,
589 SECURITY_TEST_SESSION_PRIV_OBJ_SZ,
590 0, 0, NULL, NULL, NULL, NULL,
592 if (ts_params->session_priv_mpool == NULL) {
593 RTE_LOG(ERR, USER1, "TestCase %s() line %d failed (null): "
594 "Cannot create priv mempool %s\n",
595 __func__, __LINE__, rte_strerror(rte_errno));
596 rte_mempool_free(ts_params->session_mpool);
597 ts_params->session_mpool = NULL;
605 * testsuite_teardown releases test suite wide parameters.
608 testsuite_teardown(void)
610 struct security_testsuite_params *ts_params = &testsuite_params;
611 if (ts_params->session_mpool) {
612 rte_mempool_free(ts_params->session_mpool);
613 ts_params->session_mpool = NULL;
615 if (ts_params->session_priv_mpool) {
616 rte_mempool_free(ts_params->session_priv_mpool);
617 ts_params->session_priv_mpool = NULL;
622 * ut_setup initializes test case parameters to default values.
623 * It resets also any .called and .failed statistics of mockup functions
629 struct security_unittest_params *ut_params = &unittest_params;
630 ut_params->ctx.device = NULL;
631 ut_params->ctx.ops = &mock_ops;
632 ut_params->ctx.sess_cnt = 0;
633 ut_params->sess = NULL;
635 mock_session_create_exp.called = 0;
636 mock_session_update_exp.called = 0;
637 mock_session_get_size_exp.called = 0;
638 mock_session_stats_get_exp.called = 0;
639 mock_session_destroy_exp.called = 0;
640 mock_set_pkt_metadata_exp.called = 0;
641 mock_get_userdata_exp.called = 0;
642 mock_capabilities_get_exp.called = 0;
644 mock_session_create_exp.failed = 0;
645 mock_session_update_exp.failed = 0;
646 mock_session_get_size_exp.failed = 0;
647 mock_session_stats_get_exp.failed = 0;
648 mock_session_destroy_exp.failed = 0;
649 mock_set_pkt_metadata_exp.failed = 0;
650 mock_get_userdata_exp.failed = 0;
651 mock_capabilities_get_exp.failed = 0;
657 * destroy_session_with_check is a helper function releasing session
658 * created with rte_security_session_create and stored in test case parameters.
659 * It's used both to release sessions created in test cases' bodies
660 * which are assigned to ut_params->sess
661 * as well as sessions created in ut_setup_with_session.
664 destroy_session_with_check(void)
666 struct security_unittest_params *ut_params = &unittest_params;
667 if (ut_params->sess != NULL) {
668 /* Assure that mockup function for destroy operation is set. */
669 ut_params->ctx.ops = &mock_ops;
671 mock_session_destroy_exp.device = NULL;
672 mock_session_destroy_exp.sess = ut_params->sess;
673 mock_session_destroy_exp.ret = 0;
674 mock_session_destroy_exp.called = 0;
675 mock_session_destroy_exp.failed = 0;
677 int ret = rte_security_session_destroy(&ut_params->ctx,
679 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
681 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
683 ut_params->sess = NULL;
689 * ut_teardown releases test case parameters.
694 destroy_session_with_check();
698 * ut_setup_with_session initializes test case parameters by
699 * - calling standard ut_setup,
700 * - creating a session that can be used in test case.
703 ut_setup_with_session(void)
705 struct security_unittest_params *ut_params = &unittest_params;
706 struct security_testsuite_params *ts_params = &testsuite_params;
707 struct rte_security_session *sess;
709 int ret = ut_setup();
710 if (ret != TEST_SUCCESS)
713 mock_session_create_exp.device = NULL;
714 mock_session_create_exp.conf = &ut_params->conf;
715 mock_session_create_exp.mp = ts_params->session_mpool;
716 mock_session_create_exp.priv_mp = ts_params->session_priv_mpool;
717 mock_session_create_exp.ret = 0;
719 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
720 ts_params->session_mpool,
721 ts_params->session_priv_mpool);
722 TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(rte_security_session_create,
724 TEST_ASSERT_EQUAL(sess, mock_session_create_exp.sess,
725 "Expecting session_create to be called with %p sess"
726 " parameter, but it's called %p sess parameter",
727 sess, mock_session_create_exp.sess);
728 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
731 * Store created session in test case parameters, so it can be released
732 * after test case in ut_teardown by destroy_session_with_check.
734 ut_params->sess = sess;
743 * Each test function is related to a single test case.
744 * They are arranged by tested rte_security API function
745 * and by rte_security execution paths sequence in code.
749 * rte_security_session_create tests
753 * Test execution of rte_security_session_create with NULL instance
756 test_session_create_inv_context(void)
758 struct security_testsuite_params *ts_params = &testsuite_params;
759 struct security_unittest_params *ut_params = &unittest_params;
760 struct rte_security_session *sess;
762 sess = rte_security_session_create(NULL, &ut_params->conf,
763 ts_params->session_mpool,
764 ts_params->session_priv_mpool);
765 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
767 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
768 TEST_ASSERT_MEMPOOL_USAGE(0);
769 TEST_ASSERT_PRIV_MP_USAGE(0);
770 TEST_ASSERT_SESSION_COUNT(0);
776 * Test execution of rte_security_session_create with invalid
777 * security operations structure (NULL)
780 test_session_create_inv_context_ops(void)
782 struct security_testsuite_params *ts_params = &testsuite_params;
783 struct security_unittest_params *ut_params = &unittest_params;
784 struct rte_security_session *sess;
786 ut_params->ctx.ops = NULL;
788 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
789 ts_params->session_mpool,
790 ts_params->session_priv_mpool);
791 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
793 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
794 TEST_ASSERT_MEMPOOL_USAGE(0);
795 TEST_ASSERT_PRIV_MP_USAGE(0);
796 TEST_ASSERT_SESSION_COUNT(0);
802 * Test execution of rte_security_session_create with empty
803 * security operations
806 test_session_create_inv_context_ops_fun(void)
808 struct security_testsuite_params *ts_params = &testsuite_params;
809 struct security_unittest_params *ut_params = &unittest_params;
810 struct rte_security_session *sess;
812 ut_params->ctx.ops = &empty_ops;
814 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
815 ts_params->session_mpool,
816 ts_params->session_priv_mpool);
817 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
819 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
820 TEST_ASSERT_MEMPOOL_USAGE(0);
821 TEST_ASSERT_PRIV_MP_USAGE(0);
822 TEST_ASSERT_SESSION_COUNT(0);
828 * Test execution of rte_security_session_create with NULL conf parameter
831 test_session_create_inv_configuration(void)
833 struct security_testsuite_params *ts_params = &testsuite_params;
834 struct security_unittest_params *ut_params = &unittest_params;
835 struct rte_security_session *sess;
837 sess = rte_security_session_create(&ut_params->ctx, NULL,
838 ts_params->session_mpool,
839 ts_params->session_priv_mpool);
840 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
842 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
843 TEST_ASSERT_MEMPOOL_USAGE(0);
844 TEST_ASSERT_PRIV_MP_USAGE(0);
845 TEST_ASSERT_SESSION_COUNT(0);
851 * Test execution of rte_security_session_create with NULL session
855 test_session_create_inv_mempool(void)
857 struct security_unittest_params *ut_params = &unittest_params;
858 struct security_testsuite_params *ts_params = &testsuite_params;
859 struct rte_security_session *sess;
861 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
862 NULL, ts_params->session_priv_mpool);
863 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
865 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
866 TEST_ASSERT_MEMPOOL_USAGE(0);
867 TEST_ASSERT_PRIV_MP_USAGE(0);
868 TEST_ASSERT_SESSION_COUNT(0);
874 * Test execution of rte_security_session_create with NULL session
878 test_session_create_inv_sess_priv_mempool(void)
880 struct security_unittest_params *ut_params = &unittest_params;
881 struct security_testsuite_params *ts_params = &testsuite_params;
882 struct rte_security_session *sess;
884 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
885 ts_params->session_mpool, NULL);
886 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
888 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
889 TEST_ASSERT_MEMPOOL_USAGE(0);
890 TEST_ASSERT_PRIV_MP_USAGE(0);
891 TEST_ASSERT_SESSION_COUNT(0);
897 * Test execution of rte_security_session_create in case when mempool
898 * is fully used and no object can be got from it
901 test_session_create_mempool_empty(void)
903 struct security_testsuite_params *ts_params = &testsuite_params;
904 struct security_unittest_params *ut_params = &unittest_params;
905 struct rte_security_session *tmp[SECURITY_TEST_MEMPOOL_SIZE];
906 void *tmp1[SECURITY_TEST_MEMPOOL_SIZE];
907 struct rte_security_session *sess;
909 /* Get all available objects from mempool. */
911 for (i = 0; i < SECURITY_TEST_MEMPOOL_SIZE; ++i) {
912 ret = rte_mempool_get(ts_params->session_mpool,
914 TEST_ASSERT_EQUAL(0, ret,
915 "Expect getting %d object from mempool"
917 ret = rte_mempool_get(ts_params->session_priv_mpool,
918 (void **)(&tmp1[i]));
919 TEST_ASSERT_EQUAL(0, ret,
920 "Expect getting %d object from priv mempool"
923 TEST_ASSERT_MEMPOOL_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
924 TEST_ASSERT_PRIV_MP_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
926 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
927 ts_params->session_mpool,
928 ts_params->session_priv_mpool);
929 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
931 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
932 TEST_ASSERT_MEMPOOL_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
933 TEST_ASSERT_PRIV_MP_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
934 TEST_ASSERT_SESSION_COUNT(0);
936 /* Put objects back to the pool. */
937 for (i = 0; i < SECURITY_TEST_MEMPOOL_SIZE; ++i) {
938 rte_mempool_put(ts_params->session_mpool,
940 rte_mempool_put(ts_params->session_priv_mpool,
943 TEST_ASSERT_MEMPOOL_USAGE(0);
944 TEST_ASSERT_PRIV_MP_USAGE(0);
950 * Test execution of rte_security_session_create when session_create
951 * security operation fails
954 test_session_create_ops_failure(void)
956 struct security_testsuite_params *ts_params = &testsuite_params;
957 struct security_unittest_params *ut_params = &unittest_params;
958 struct rte_security_session *sess;
960 mock_session_create_exp.device = NULL;
961 mock_session_create_exp.conf = &ut_params->conf;
962 mock_session_create_exp.mp = ts_params->session_mpool;
963 mock_session_create_exp.priv_mp = ts_params->session_priv_mpool;
964 mock_session_create_exp.ret = -1; /* Return failure status. */
966 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
967 ts_params->session_mpool,
968 ts_params->session_priv_mpool);
969 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
971 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
972 TEST_ASSERT_MEMPOOL_USAGE(0);
973 TEST_ASSERT_PRIV_MP_USAGE(0);
974 TEST_ASSERT_SESSION_COUNT(0);
980 * Test execution of rte_security_session_create in successful execution path
983 test_session_create_success(void)
985 struct security_testsuite_params *ts_params = &testsuite_params;
986 struct security_unittest_params *ut_params = &unittest_params;
987 struct rte_security_session *sess;
989 mock_session_create_exp.device = NULL;
990 mock_session_create_exp.conf = &ut_params->conf;
991 mock_session_create_exp.mp = ts_params->session_mpool;
992 mock_session_create_exp.priv_mp = ts_params->session_priv_mpool;
993 mock_session_create_exp.ret = 0; /* Return success status. */
995 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
996 ts_params->session_mpool,
997 ts_params->session_priv_mpool);
998 TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(rte_security_session_create,
1000 TEST_ASSERT_EQUAL(sess, mock_session_create_exp.sess,
1001 "Expecting session_create to be called with %p sess"
1002 " parameter, but it's called %p sess parameter",
1003 sess, mock_session_create_exp.sess);
1004 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
1005 TEST_ASSERT_MEMPOOL_USAGE(1);
1006 TEST_ASSERT_PRIV_MP_USAGE(1);
1007 TEST_ASSERT_SESSION_COUNT(1);
1010 * Store created session in test case parameters, so it can be released
1011 * after test case in ut_teardown by destroy_session_with_check.
1013 ut_params->sess = sess;
1015 return TEST_SUCCESS;
1020 * rte_security_session_update tests
1024 * Test execution of rte_security_session_update with NULL instance
1027 test_session_update_inv_context(void)
1029 struct security_unittest_params *ut_params = &unittest_params;
1031 int ret = rte_security_session_update(NULL, ut_params->sess,
1033 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1034 ret, -EINVAL, "%d");
1035 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
1037 return TEST_SUCCESS;
1041 * Test execution of rte_security_session_update with invalid
1042 * security operations structure (NULL)
1045 test_session_update_inv_context_ops(void)
1047 struct security_unittest_params *ut_params = &unittest_params;
1048 ut_params->ctx.ops = NULL;
1050 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
1052 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1053 ret, -EINVAL, "%d");
1054 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
1056 return TEST_SUCCESS;
1060 * Test execution of rte_security_session_update with empty
1061 * security operations
1064 test_session_update_inv_context_ops_fun(void)
1066 struct security_unittest_params *ut_params = &unittest_params;
1067 ut_params->ctx.ops = &empty_ops;
1069 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
1071 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1072 ret, -ENOTSUP, "%d");
1073 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
1075 return TEST_SUCCESS;
1079 * Test execution of rte_security_session_update with NULL conf parameter
1082 test_session_update_inv_configuration(void)
1084 struct security_unittest_params *ut_params = &unittest_params;
1086 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
1088 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1089 ret, -EINVAL, "%d");
1090 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
1092 return TEST_SUCCESS;
1096 * Test execution of rte_security_session_update with NULL sess parameter
1099 test_session_update_inv_session(void)
1101 struct security_unittest_params *ut_params = &unittest_params;
1103 int ret = rte_security_session_update(&ut_params->ctx, NULL,
1105 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1106 ret, -EINVAL, "%d");
1107 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
1109 return TEST_SUCCESS;
1113 * Test execution of rte_security_session_update when session_update
1114 * security operation fails
1117 test_session_update_ops_failure(void)
1119 struct security_unittest_params *ut_params = &unittest_params;
1121 mock_session_update_exp.device = NULL;
1122 mock_session_update_exp.sess = ut_params->sess;
1123 mock_session_update_exp.conf = &ut_params->conf;
1124 mock_session_update_exp.ret = -1; /* Return failure status. */
1126 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
1128 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1130 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 1);
1132 return TEST_SUCCESS;
1136 * Test execution of rte_security_session_update in successful execution path
1139 test_session_update_success(void)
1141 struct security_unittest_params *ut_params = &unittest_params;
1143 mock_session_update_exp.device = NULL;
1144 mock_session_update_exp.sess = ut_params->sess;
1145 mock_session_update_exp.conf = &ut_params->conf;
1146 mock_session_update_exp.ret = 0; /* Return success status. */
1148 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
1150 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1152 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 1);
1154 return TEST_SUCCESS;
1159 * rte_security_session_get_size tests
1163 * Test execution of rte_security_session_get_size with NULL instance
1166 test_session_get_size_inv_context(void)
1168 unsigned int ret = rte_security_session_get_size(NULL);
1169 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1171 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
1173 return TEST_SUCCESS;
1177 * Test execution of rte_security_session_get_size with invalid
1178 * security operations structure (NULL)
1181 test_session_get_size_inv_context_ops(void)
1183 struct security_unittest_params *ut_params = &unittest_params;
1184 ut_params->ctx.ops = NULL;
1186 unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1187 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1189 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
1191 return TEST_SUCCESS;
1195 * Test execution of rte_security_session_get_size with empty
1196 * security operations
1199 test_session_get_size_inv_context_ops_fun(void)
1201 struct security_unittest_params *ut_params = &unittest_params;
1202 ut_params->ctx.ops = &empty_ops;
1204 unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1205 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1207 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
1209 return TEST_SUCCESS;
1213 * Test execution of rte_security_session_get_size when session_get_size
1214 * security operation fails
1217 test_session_get_size_ops_failure(void)
1219 struct security_unittest_params *ut_params = &unittest_params;
1221 mock_session_get_size_exp.device = NULL;
1222 mock_session_get_size_exp.ret = 0;
1224 unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1225 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1227 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 1);
1229 return TEST_SUCCESS;
1233 * Test execution of rte_security_session_get_size in successful execution path
1236 test_session_get_size_success(void)
1238 struct security_unittest_params *ut_params = &unittest_params;
1240 mock_session_get_size_exp.device = NULL;
1241 mock_session_get_size_exp.ret = 1024;
1243 unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1244 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1246 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 1);
1248 return TEST_SUCCESS;
1253 * rte_security_session_stats_get tests
1257 * Test execution of rte_security_session_stats_get with NULL instance
1260 test_session_stats_get_inv_context(void)
1262 struct security_unittest_params *ut_params = &unittest_params;
1263 struct rte_security_stats stats;
1265 int ret = rte_security_session_stats_get(NULL, ut_params->sess, &stats);
1266 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1267 ret, -EINVAL, "%d");
1268 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1270 return TEST_SUCCESS;
1274 * Test execution of rte_security_session_stats_get with invalid
1275 * security operations structure (NULL)
1278 test_session_stats_get_inv_context_ops(void)
1280 struct security_unittest_params *ut_params = &unittest_params;
1281 struct rte_security_stats stats;
1282 ut_params->ctx.ops = NULL;
1284 int ret = rte_security_session_stats_get(&ut_params->ctx,
1285 ut_params->sess, &stats);
1286 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1287 ret, -EINVAL, "%d");
1288 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1290 return TEST_SUCCESS;
1294 * Test execution of rte_security_session_stats_get with empty
1295 * security operations
1298 test_session_stats_get_inv_context_ops_fun(void)
1300 struct security_unittest_params *ut_params = &unittest_params;
1301 struct rte_security_stats stats;
1302 ut_params->ctx.ops = &empty_ops;
1304 int ret = rte_security_session_stats_get(&ut_params->ctx,
1305 ut_params->sess, &stats);
1306 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1307 ret, -ENOTSUP, "%d");
1308 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1310 return TEST_SUCCESS;
1314 * Test execution of rte_security_session_stats_get with NULL stats parameter
1317 test_session_stats_get_inv_stats(void)
1319 struct security_unittest_params *ut_params = &unittest_params;
1321 int ret = rte_security_session_stats_get(&ut_params->ctx,
1322 ut_params->sess, NULL);
1323 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1324 ret, -EINVAL, "%d");
1325 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1327 return TEST_SUCCESS;
1331 * Test execution of rte_security_session_stats_get when session_stats_get
1332 * security operation fails
1335 test_session_stats_get_ops_failure(void)
1337 struct security_unittest_params *ut_params = &unittest_params;
1338 struct rte_security_stats stats;
1340 mock_session_stats_get_exp.device = NULL;
1341 mock_session_stats_get_exp.sess = ut_params->sess;
1342 mock_session_stats_get_exp.stats = &stats;
1343 mock_session_stats_get_exp.ret = -1;
1345 int ret = rte_security_session_stats_get(&ut_params->ctx,
1346 ut_params->sess, &stats);
1347 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1349 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 1);
1351 return TEST_SUCCESS;
1355 * Test execution of rte_security_session_stats_get in successful execution
1359 test_session_stats_get_success(void)
1361 struct security_unittest_params *ut_params = &unittest_params;
1362 struct rte_security_stats stats;
1364 mock_session_stats_get_exp.device = NULL;
1365 mock_session_stats_get_exp.sess = ut_params->sess;
1366 mock_session_stats_get_exp.stats = &stats;
1367 mock_session_stats_get_exp.ret = 0;
1369 int ret = rte_security_session_stats_get(&ut_params->ctx,
1370 ut_params->sess, &stats);
1371 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1373 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 1);
1375 return TEST_SUCCESS;
1380 * rte_security_session_destroy tests
1384 * Test execution of rte_security_session_destroy with NULL instance
1387 test_session_destroy_inv_context(void)
1389 struct security_unittest_params *ut_params = &unittest_params;
1391 TEST_ASSERT_MEMPOOL_USAGE(1);
1392 TEST_ASSERT_PRIV_MP_USAGE(1);
1393 TEST_ASSERT_SESSION_COUNT(1);
1395 int ret = rte_security_session_destroy(NULL, ut_params->sess);
1396 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1397 ret, -EINVAL, "%d");
1398 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1399 TEST_ASSERT_MEMPOOL_USAGE(1);
1400 TEST_ASSERT_PRIV_MP_USAGE(1);
1401 TEST_ASSERT_SESSION_COUNT(1);
1403 return TEST_SUCCESS;
1407 * Test execution of rte_security_session_destroy with invalid
1408 * security operations structure (NULL)
1411 test_session_destroy_inv_context_ops(void)
1413 struct security_unittest_params *ut_params = &unittest_params;
1414 ut_params->ctx.ops = NULL;
1416 TEST_ASSERT_MEMPOOL_USAGE(1);
1417 TEST_ASSERT_PRIV_MP_USAGE(1);
1418 TEST_ASSERT_SESSION_COUNT(1);
1420 int ret = rte_security_session_destroy(&ut_params->ctx,
1422 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1423 ret, -EINVAL, "%d");
1424 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1425 TEST_ASSERT_MEMPOOL_USAGE(1);
1426 TEST_ASSERT_PRIV_MP_USAGE(1);
1427 TEST_ASSERT_SESSION_COUNT(1);
1429 return TEST_SUCCESS;
1433 * Test execution of rte_security_session_destroy with empty
1434 * security operations
1437 test_session_destroy_inv_context_ops_fun(void)
1439 struct security_unittest_params *ut_params = &unittest_params;
1440 ut_params->ctx.ops = &empty_ops;
1442 TEST_ASSERT_MEMPOOL_USAGE(1);
1443 TEST_ASSERT_PRIV_MP_USAGE(1);
1444 TEST_ASSERT_SESSION_COUNT(1);
1446 int ret = rte_security_session_destroy(&ut_params->ctx,
1448 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1449 ret, -ENOTSUP, "%d");
1450 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1451 TEST_ASSERT_MEMPOOL_USAGE(1);
1452 TEST_ASSERT_PRIV_MP_USAGE(1);
1453 TEST_ASSERT_SESSION_COUNT(1);
1455 return TEST_SUCCESS;
1459 * Test execution of rte_security_session_destroy with NULL sess parameter
1462 test_session_destroy_inv_session(void)
1464 struct security_unittest_params *ut_params = &unittest_params;
1466 TEST_ASSERT_MEMPOOL_USAGE(1);
1467 TEST_ASSERT_PRIV_MP_USAGE(1);
1468 TEST_ASSERT_SESSION_COUNT(1);
1470 int ret = rte_security_session_destroy(&ut_params->ctx, NULL);
1471 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1472 ret, -EINVAL, "%d");
1473 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1474 TEST_ASSERT_MEMPOOL_USAGE(1);
1475 TEST_ASSERT_PRIV_MP_USAGE(1);
1476 TEST_ASSERT_SESSION_COUNT(1);
1478 return TEST_SUCCESS;
1482 * Test execution of rte_security_session_destroy when session_destroy
1483 * security operation fails
1486 test_session_destroy_ops_failure(void)
1488 struct security_unittest_params *ut_params = &unittest_params;
1490 mock_session_destroy_exp.device = NULL;
1491 mock_session_destroy_exp.sess = ut_params->sess;
1492 mock_session_destroy_exp.ret = -1;
1494 TEST_ASSERT_MEMPOOL_USAGE(1);
1495 TEST_ASSERT_PRIV_MP_USAGE(1);
1496 TEST_ASSERT_SESSION_COUNT(1);
1498 int ret = rte_security_session_destroy(&ut_params->ctx,
1500 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1502 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
1503 TEST_ASSERT_MEMPOOL_USAGE(1);
1504 TEST_ASSERT_PRIV_MP_USAGE(1);
1505 TEST_ASSERT_SESSION_COUNT(1);
1507 return TEST_SUCCESS;
1511 * Test execution of rte_security_session_destroy in successful execution path
1514 test_session_destroy_success(void)
1516 struct security_unittest_params *ut_params = &unittest_params;
1518 mock_session_destroy_exp.device = NULL;
1519 mock_session_destroy_exp.sess = ut_params->sess;
1520 mock_session_destroy_exp.ret = 0;
1521 TEST_ASSERT_MEMPOOL_USAGE(1);
1522 TEST_ASSERT_PRIV_MP_USAGE(1);
1523 TEST_ASSERT_SESSION_COUNT(1);
1525 int ret = rte_security_session_destroy(&ut_params->ctx,
1527 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1529 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
1530 TEST_ASSERT_MEMPOOL_USAGE(0);
1531 TEST_ASSERT_PRIV_MP_USAGE(0);
1532 TEST_ASSERT_SESSION_COUNT(0);
1535 * Remove session from test case parameters, so it won't be destroyed
1536 * during test case teardown.
1538 ut_params->sess = NULL;
1540 return TEST_SUCCESS;
1545 * rte_security_set_pkt_metadata tests
1549 * Test execution of rte_security_set_pkt_metadata with NULL instance
1552 test_set_pkt_metadata_inv_context(void)
1555 struct security_unittest_params *ut_params = &unittest_params;
1559 int ret = rte_security_set_pkt_metadata(NULL, ut_params->sess, &m,
1561 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1562 ret, -EINVAL, "%d");
1563 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1565 return TEST_SUCCESS;
1567 return TEST_SKIPPED;
1572 * Test execution of rte_security_set_pkt_metadata with invalid
1573 * security operations structure (NULL)
1576 test_set_pkt_metadata_inv_context_ops(void)
1579 struct security_unittest_params *ut_params = &unittest_params;
1582 ut_params->ctx.ops = NULL;
1584 int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1585 ut_params->sess, &m, ¶ms);
1586 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1587 ret, -EINVAL, "%d");
1588 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1590 return TEST_SUCCESS;
1592 return TEST_SKIPPED;
1597 * Test execution of rte_security_set_pkt_metadata with empty
1598 * security operations
1601 test_set_pkt_metadata_inv_context_ops_fun(void)
1603 struct security_unittest_params *ut_params = &unittest_params;
1606 ut_params->ctx.ops = &empty_ops;
1608 int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1609 ut_params->sess, &m, ¶ms);
1610 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1611 ret, -ENOTSUP, "%d");
1612 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1614 return TEST_SUCCESS;
1618 * Test execution of rte_security_set_pkt_metadata with NULL sess parameter
1621 test_set_pkt_metadata_inv_session(void)
1624 struct security_unittest_params *ut_params = &unittest_params;
1628 int ret = rte_security_set_pkt_metadata(&ut_params->ctx, NULL,
1630 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1631 ret, -EINVAL, "%d");
1632 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1634 return TEST_SUCCESS;
1636 return TEST_SKIPPED;
1641 * Test execution of rte_security_set_pkt_metadata when set_pkt_metadata
1642 * security operation fails
1645 test_set_pkt_metadata_ops_failure(void)
1647 struct security_unittest_params *ut_params = &unittest_params;
1651 mock_set_pkt_metadata_exp.device = NULL;
1652 mock_set_pkt_metadata_exp.sess = ut_params->sess;
1653 mock_set_pkt_metadata_exp.m = &m;
1654 mock_set_pkt_metadata_exp.params = ¶ms;
1655 mock_set_pkt_metadata_exp.ret = -1;
1657 int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1658 ut_params->sess, &m, ¶ms);
1659 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1661 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 1);
1663 return TEST_SUCCESS;
1667 * Test execution of rte_security_set_pkt_metadata in successful execution path
1670 test_set_pkt_metadata_success(void)
1672 struct security_unittest_params *ut_params = &unittest_params;
1676 mock_set_pkt_metadata_exp.device = NULL;
1677 mock_set_pkt_metadata_exp.sess = ut_params->sess;
1678 mock_set_pkt_metadata_exp.m = &m;
1679 mock_set_pkt_metadata_exp.params = ¶ms;
1680 mock_set_pkt_metadata_exp.ret = 0;
1682 int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1683 ut_params->sess, &m, ¶ms);
1684 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1686 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 1);
1688 return TEST_SUCCESS;
1693 * rte_security_get_userdata tests
1697 * Test execution of rte_security_get_userdata with NULL instance
1700 test_get_userdata_inv_context(void)
1703 uint64_t md = 0xDEADBEEF;
1705 void *ret = rte_security_get_userdata(NULL, md);
1706 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1708 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0);
1710 return TEST_SUCCESS;
1712 return TEST_SKIPPED;
1717 * Test execution of rte_security_get_userdata with invalid
1718 * security operations structure (NULL)
1721 test_get_userdata_inv_context_ops(void)
1724 struct security_unittest_params *ut_params = &unittest_params;
1725 uint64_t md = 0xDEADBEEF;
1726 ut_params->ctx.ops = NULL;
1728 void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1729 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1731 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0);
1733 return TEST_SUCCESS;
1735 return TEST_SKIPPED;
1740 * Test execution of rte_security_get_userdata with empty
1741 * security operations
1744 test_get_userdata_inv_context_ops_fun(void)
1746 struct security_unittest_params *ut_params = &unittest_params;
1747 uint64_t md = 0xDEADBEEF;
1748 ut_params->ctx.ops = &empty_ops;
1750 void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1751 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1753 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0);
1755 return TEST_SUCCESS;
1759 * Test execution of rte_security_get_userdata when get_userdata
1760 * security operation fails
1763 test_get_userdata_ops_failure(void)
1765 struct security_unittest_params *ut_params = &unittest_params;
1766 uint64_t md = 0xDEADBEEF;
1767 void *userdata = (void *)0x7E577E57;
1769 mock_get_userdata_exp.device = NULL;
1770 mock_get_userdata_exp.md = md;
1771 mock_get_userdata_exp.userdata = userdata;
1772 mock_get_userdata_exp.ret = -1;
1774 void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1775 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1777 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 1);
1779 return TEST_SUCCESS;
1783 * Test execution of rte_security_get_userdata in successful execution path
1786 test_get_userdata_success(void)
1788 struct security_unittest_params *ut_params = &unittest_params;
1789 uint64_t md = 0xDEADBEEF;
1790 void *userdata = (void *)0x7E577E57;
1792 mock_get_userdata_exp.device = NULL;
1793 mock_get_userdata_exp.md = md;
1794 mock_get_userdata_exp.userdata = userdata;
1795 mock_get_userdata_exp.ret = 0;
1797 void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1798 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1799 ret, userdata, "%p");
1800 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 1);
1802 return TEST_SUCCESS;
1807 * rte_security_capabilities_get tests
1811 * Test execution of rte_security_capabilities_get with NULL instance
1814 test_capabilities_get_inv_context(void)
1816 const struct rte_security_capability *ret;
1817 ret = rte_security_capabilities_get(NULL);
1818 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1820 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1822 return TEST_SUCCESS;
1826 * Test execution of rte_security_capabilities_get with invalid
1827 * security operations structure (NULL)
1830 test_capabilities_get_inv_context_ops(void)
1832 struct security_unittest_params *ut_params = &unittest_params;
1833 ut_params->ctx.ops = NULL;
1835 const struct rte_security_capability *ret;
1836 ret = rte_security_capabilities_get(&ut_params->ctx);
1837 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1839 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1841 return TEST_SUCCESS;
1845 * Test execution of rte_security_capabilities_get with empty
1846 * security operations
1849 test_capabilities_get_inv_context_ops_fun(void)
1851 struct security_unittest_params *ut_params = &unittest_params;
1852 ut_params->ctx.ops = &empty_ops;
1854 const struct rte_security_capability *ret;
1855 ret = rte_security_capabilities_get(&ut_params->ctx);
1856 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1858 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1860 return TEST_SUCCESS;
1864 * Test execution of rte_security_capabilities_get when capabilities_get
1865 * security operation fails
1868 test_capabilities_get_ops_failure(void)
1870 struct security_unittest_params *ut_params = &unittest_params;
1872 mock_capabilities_get_exp.device = NULL;
1873 mock_capabilities_get_exp.ret = NULL;
1875 const struct rte_security_capability *ret;
1876 ret = rte_security_capabilities_get(&ut_params->ctx);
1877 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1879 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
1881 return TEST_SUCCESS;
1885 * Test execution of rte_security_capabilities_get in successful execution path
1888 test_capabilities_get_success(void)
1890 struct security_unittest_params *ut_params = &unittest_params;
1891 struct rte_security_capability capabilities;
1893 mock_capabilities_get_exp.device = NULL;
1894 mock_capabilities_get_exp.ret = &capabilities;
1896 const struct rte_security_capability *ret;
1897 ret = rte_security_capabilities_get(&ut_params->ctx);
1898 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1899 ret, &capabilities, "%p");
1900 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
1902 return TEST_SUCCESS;
1907 * rte_security_capability_get tests
1911 * Test execution of rte_security_capability_get with NULL instance
1914 test_capability_get_inv_context(void)
1916 struct rte_security_capability_idx idx;
1918 const struct rte_security_capability *ret;
1919 ret = rte_security_capability_get(NULL, &idx);
1920 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
1922 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1924 return TEST_SUCCESS;
1928 * Test execution of rte_security_capability_get with invalid
1929 * security operations structure (NULL)
1932 test_capability_get_inv_context_ops(void)
1934 struct security_unittest_params *ut_params = &unittest_params;
1935 struct rte_security_capability_idx idx;
1936 ut_params->ctx.ops = NULL;
1938 const struct rte_security_capability *ret;
1939 ret = rte_security_capability_get(&ut_params->ctx, &idx);
1940 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
1942 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1944 return TEST_SUCCESS;
1948 * Test execution of rte_security_capability_get with empty
1949 * security operations
1952 test_capability_get_inv_context_ops_fun(void)
1954 struct security_unittest_params *ut_params = &unittest_params;
1955 struct rte_security_capability_idx idx;
1956 ut_params->ctx.ops = &empty_ops;
1958 const struct rte_security_capability *ret;
1959 ret = rte_security_capability_get(&ut_params->ctx, &idx);
1960 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
1962 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1964 return TEST_SUCCESS;
1968 * Test execution of rte_security_capability_get with NULL idx parameter
1971 test_capability_get_inv_idx(void)
1973 struct security_unittest_params *ut_params = &unittest_params;
1975 const struct rte_security_capability *ret;
1976 ret = rte_security_capability_get(&ut_params->ctx, NULL);
1977 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
1979 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1981 return TEST_SUCCESS;
1985 * Test execution of rte_security_capability_get when capabilities_get
1986 * security operation fails
1989 test_capability_get_ops_failure(void)
1991 struct security_unittest_params *ut_params = &unittest_params;
1992 struct rte_security_capability_idx idx;
1994 mock_capabilities_get_exp.device = NULL;
1995 mock_capabilities_get_exp.ret = NULL;
1997 const struct rte_security_capability *ret;
1998 ret = rte_security_capability_get(&ut_params->ctx, &idx);
1999 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2001 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2003 return TEST_SUCCESS;
2007 * Test execution of rte_security_capability_get when capabilities table
2008 * is empty (contains only RTE_SECURITY_ACTION_TYPE_NONE ending entry)
2011 test_capability_get_empty_table(void)
2013 struct security_unittest_params *ut_params = &unittest_params;
2014 struct rte_security_capability_idx idx;
2015 struct rte_security_capability capabilities[] = {
2017 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2021 mock_capabilities_get_exp.device = NULL;
2022 mock_capabilities_get_exp.ret = capabilities;
2024 const struct rte_security_capability *ret;
2025 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2026 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2028 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2030 return TEST_SUCCESS;
2034 * Test execution of rte_security_capability_get when capabilities table
2035 * does not contain entry with matching action
2038 test_capability_get_no_matching_action(void)
2040 struct security_unittest_params *ut_params = &unittest_params;
2041 struct rte_security_capability_idx idx = {
2042 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2044 struct rte_security_capability capabilities[] = {
2046 .action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
2049 .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
2052 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2056 mock_capabilities_get_exp.device = NULL;
2057 mock_capabilities_get_exp.ret = capabilities;
2059 const struct rte_security_capability *ret;
2060 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2061 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2063 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2065 return TEST_SUCCESS;
2069 * Test execution of rte_security_capability_get when capabilities table
2070 * does not contain entry with matching protocol
2073 test_capability_get_no_matching_protocol(void)
2075 struct security_unittest_params *ut_params = &unittest_params;
2076 struct rte_security_capability_idx idx = {
2077 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2078 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2080 struct rte_security_capability capabilities[] = {
2082 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2083 .protocol = RTE_SECURITY_PROTOCOL_MACSEC,
2086 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2087 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
2090 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2094 mock_capabilities_get_exp.device = NULL;
2095 mock_capabilities_get_exp.ret = capabilities;
2097 const struct rte_security_capability *ret;
2098 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2099 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2101 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2103 return TEST_SUCCESS;
2107 * Test execution of rte_security_capability_get when macsec protocol
2108 * is searched and capabilities table contain proper entry.
2109 * However macsec records search is not supported in rte_security.
2112 test_capability_get_no_support_for_macsec(void)
2114 struct security_unittest_params *ut_params = &unittest_params;
2115 struct rte_security_capability_idx idx = {
2116 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2117 .protocol = RTE_SECURITY_PROTOCOL_MACSEC,
2119 struct rte_security_capability capabilities[] = {
2121 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2122 .protocol = RTE_SECURITY_PROTOCOL_MACSEC,
2125 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2129 mock_capabilities_get_exp.device = NULL;
2130 mock_capabilities_get_exp.ret = capabilities;
2132 const struct rte_security_capability *ret;
2133 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2134 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2136 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2138 return TEST_SUCCESS;
2142 * Test execution of rte_security_capability_get when capabilities table
2143 * does not contain entry with matching ipsec proto field
2146 test_capability_get_ipsec_mismatch_proto(void)
2148 struct security_unittest_params *ut_params = &unittest_params;
2149 struct rte_security_capability_idx idx = {
2150 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2151 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2153 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2156 struct rte_security_capability capabilities[] = {
2158 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2159 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2161 .proto = RTE_SECURITY_IPSEC_SA_PROTO_AH,
2165 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2169 mock_capabilities_get_exp.device = NULL;
2170 mock_capabilities_get_exp.ret = capabilities;
2172 const struct rte_security_capability *ret;
2173 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2174 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2176 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2178 return TEST_SUCCESS;
2182 * Test execution of rte_security_capability_get when capabilities table
2183 * does not contain entry with matching ipsec mode field
2186 test_capability_get_ipsec_mismatch_mode(void)
2188 struct security_unittest_params *ut_params = &unittest_params;
2189 struct rte_security_capability_idx idx = {
2190 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2191 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2193 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2194 .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
2197 struct rte_security_capability capabilities[] = {
2199 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2200 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2202 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2203 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
2207 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2211 mock_capabilities_get_exp.device = NULL;
2212 mock_capabilities_get_exp.ret = capabilities;
2214 const struct rte_security_capability *ret;
2215 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2216 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2218 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2220 return TEST_SUCCESS;
2224 * Test execution of rte_security_capability_get when capabilities table
2225 * does not contain entry with matching ipsec direction field
2228 test_capability_get_ipsec_mismatch_dir(void)
2230 struct security_unittest_params *ut_params = &unittest_params;
2231 struct rte_security_capability_idx idx = {
2232 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2233 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2235 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2236 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
2237 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
2240 struct rte_security_capability capabilities[] = {
2242 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2243 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2245 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2246 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
2247 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
2251 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2255 mock_capabilities_get_exp.device = NULL;
2256 mock_capabilities_get_exp.ret = capabilities;
2258 const struct rte_security_capability *ret;
2259 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2260 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2262 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2264 return TEST_SUCCESS;
2268 * Test execution of rte_security_capability_get when capabilities table
2269 * contains matching ipsec entry
2272 test_capability_get_ipsec_match(void)
2274 struct security_unittest_params *ut_params = &unittest_params;
2275 struct rte_security_capability_idx idx = {
2276 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2277 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2279 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2280 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
2281 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
2284 struct rte_security_capability capabilities[] = {
2286 .action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
2289 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2290 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2292 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2293 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
2294 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
2298 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2302 mock_capabilities_get_exp.device = NULL;
2303 mock_capabilities_get_exp.ret = capabilities;
2305 const struct rte_security_capability *ret;
2306 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2307 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2308 ret, &capabilities[1], "%p");
2309 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2311 return TEST_SUCCESS;
2315 * Test execution of rte_security_capability_get when capabilities table
2316 * does not contain entry with matching pdcp domain field
2319 test_capability_get_pdcp_mismatch_domain(void)
2321 struct security_unittest_params *ut_params = &unittest_params;
2322 struct rte_security_capability_idx idx = {
2323 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2324 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
2326 .domain = RTE_SECURITY_PDCP_MODE_CONTROL,
2329 struct rte_security_capability capabilities[] = {
2331 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2332 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
2334 .domain = RTE_SECURITY_PDCP_MODE_DATA,
2338 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2342 mock_capabilities_get_exp.device = NULL;
2343 mock_capabilities_get_exp.ret = capabilities;
2345 const struct rte_security_capability *ret;
2346 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2347 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2349 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2351 return TEST_SUCCESS;
2355 * Test execution of rte_security_capability_get when capabilities table
2356 * contains matching pdcp entry
2359 test_capability_get_pdcp_match(void)
2361 struct security_unittest_params *ut_params = &unittest_params;
2362 struct rte_security_capability_idx idx = {
2363 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2364 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
2366 .domain = RTE_SECURITY_PDCP_MODE_CONTROL,
2369 struct rte_security_capability capabilities[] = {
2371 .action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
2374 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2375 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
2377 .domain = RTE_SECURITY_PDCP_MODE_CONTROL,
2381 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2385 mock_capabilities_get_exp.device = NULL;
2386 mock_capabilities_get_exp.ret = capabilities;
2388 const struct rte_security_capability *ret;
2389 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2390 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2391 ret, &capabilities[1], "%p");
2392 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2394 return TEST_SUCCESS;
2398 * Test execution of rte_security_capability_get when capabilities table
2399 * does not contain entry with matching DOCSIS direction field
2402 test_capability_get_docsis_mismatch_direction(void)
2404 struct security_unittest_params *ut_params = &unittest_params;
2405 struct rte_security_capability_idx idx = {
2406 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2407 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
2409 .direction = RTE_SECURITY_DOCSIS_DOWNLINK
2412 struct rte_security_capability capabilities[] = {
2414 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2415 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
2417 .direction = RTE_SECURITY_DOCSIS_UPLINK
2421 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2425 mock_capabilities_get_exp.device = NULL;
2426 mock_capabilities_get_exp.ret = capabilities;
2428 const struct rte_security_capability *ret;
2429 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2430 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2432 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2434 return TEST_SUCCESS;
2438 * Test execution of rte_security_capability_get when capabilities table
2439 * contains matching DOCSIS entry
2442 test_capability_get_docsis_match(void)
2444 struct security_unittest_params *ut_params = &unittest_params;
2445 struct rte_security_capability_idx idx = {
2446 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2447 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
2449 .direction = RTE_SECURITY_DOCSIS_UPLINK
2452 struct rte_security_capability capabilities[] = {
2454 .action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
2457 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2458 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
2460 .direction = RTE_SECURITY_DOCSIS_UPLINK
2464 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2468 mock_capabilities_get_exp.device = NULL;
2469 mock_capabilities_get_exp.ret = capabilities;
2471 const struct rte_security_capability *ret;
2472 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2473 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2474 ret, &capabilities[1], "%p");
2475 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2477 return TEST_SUCCESS;
2481 * Declaration of testcases
2483 static struct unit_test_suite security_testsuite = {
2484 .suite_name = "generic security",
2485 .setup = testsuite_setup,
2486 .teardown = testsuite_teardown,
2487 .unit_test_cases = {
2488 TEST_CASE_ST(ut_setup, ut_teardown,
2489 test_session_create_inv_context),
2490 TEST_CASE_ST(ut_setup, ut_teardown,
2491 test_session_create_inv_context_ops),
2492 TEST_CASE_ST(ut_setup, ut_teardown,
2493 test_session_create_inv_context_ops_fun),
2494 TEST_CASE_ST(ut_setup, ut_teardown,
2495 test_session_create_inv_configuration),
2496 TEST_CASE_ST(ut_setup, ut_teardown,
2497 test_session_create_inv_mempool),
2498 TEST_CASE_ST(ut_setup, ut_teardown,
2499 test_session_create_inv_sess_priv_mempool),
2500 TEST_CASE_ST(ut_setup, ut_teardown,
2501 test_session_create_mempool_empty),
2502 TEST_CASE_ST(ut_setup, ut_teardown,
2503 test_session_create_ops_failure),
2504 TEST_CASE_ST(ut_setup, ut_teardown,
2505 test_session_create_success),
2507 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2508 test_session_update_inv_context),
2509 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2510 test_session_update_inv_context_ops),
2511 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2512 test_session_update_inv_context_ops_fun),
2513 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2514 test_session_update_inv_configuration),
2515 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2516 test_session_update_inv_session),
2517 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2518 test_session_update_ops_failure),
2519 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2520 test_session_update_success),
2522 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2523 test_session_get_size_inv_context),
2524 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2525 test_session_get_size_inv_context_ops),
2526 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2527 test_session_get_size_inv_context_ops_fun),
2528 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2529 test_session_get_size_ops_failure),
2530 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2531 test_session_get_size_success),
2533 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2534 test_session_stats_get_inv_context),
2535 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2536 test_session_stats_get_inv_context_ops),
2537 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2538 test_session_stats_get_inv_context_ops_fun),
2539 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2540 test_session_stats_get_inv_stats),
2541 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2542 test_session_stats_get_ops_failure),
2543 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2544 test_session_stats_get_success),
2546 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2547 test_session_destroy_inv_context),
2548 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2549 test_session_destroy_inv_context_ops),
2550 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2551 test_session_destroy_inv_context_ops_fun),
2552 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2553 test_session_destroy_inv_session),
2554 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2555 test_session_destroy_ops_failure),
2556 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2557 test_session_destroy_success),
2559 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2560 test_set_pkt_metadata_inv_context),
2561 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2562 test_set_pkt_metadata_inv_context_ops),
2563 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2564 test_set_pkt_metadata_inv_context_ops_fun),
2565 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2566 test_set_pkt_metadata_inv_session),
2567 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2568 test_set_pkt_metadata_ops_failure),
2569 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2570 test_set_pkt_metadata_success),
2572 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2573 test_get_userdata_inv_context),
2574 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2575 test_get_userdata_inv_context_ops),
2576 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2577 test_get_userdata_inv_context_ops_fun),
2578 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2579 test_get_userdata_ops_failure),
2580 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2581 test_get_userdata_success),
2583 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2584 test_capabilities_get_inv_context),
2585 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2586 test_capabilities_get_inv_context_ops),
2587 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2588 test_capabilities_get_inv_context_ops_fun),
2589 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2590 test_capabilities_get_ops_failure),
2591 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2592 test_capabilities_get_success),
2594 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2595 test_capability_get_inv_context),
2596 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2597 test_capability_get_inv_context_ops),
2598 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2599 test_capability_get_inv_context_ops_fun),
2600 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2601 test_capability_get_inv_idx),
2602 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2603 test_capability_get_ops_failure),
2604 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2605 test_capability_get_empty_table),
2606 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2607 test_capability_get_no_matching_action),
2608 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2609 test_capability_get_no_matching_protocol),
2610 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2611 test_capability_get_no_support_for_macsec),
2612 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2613 test_capability_get_ipsec_mismatch_proto),
2614 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2615 test_capability_get_ipsec_mismatch_mode),
2616 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2617 test_capability_get_ipsec_mismatch_dir),
2618 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2619 test_capability_get_ipsec_match),
2620 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2621 test_capability_get_pdcp_mismatch_domain),
2622 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2623 test_capability_get_pdcp_match),
2624 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2625 test_capability_get_docsis_mismatch_direction),
2626 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2627 test_capability_get_docsis_match),
2629 TEST_CASES_END() /**< NULL terminate unit test array */
2636 rte_log_set_global_level(RTE_LOG_DEBUG);
2637 rte_log_set_level(RTE_LOGTYPE_EAL, RTE_LOG_DEBUG);
2639 return unit_test_suite_runner(&security_testsuite);
2642 REGISTER_TEST_COMMAND(security_autotest, test_security);