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); \
205 * Mockup structures and functions for rte_security_ops;
207 * Set of structures for controlling mockup functions calls.
208 * Every mockup function X has its corresponding X_data structure
209 * and an instance of that structure X_exp.
210 * Structure contains parameters that a mockup function is expected
211 * to be called with, a value to return (.ret) and 2 statistics:
212 * .called (number of times the mockup function was called)
213 * and .failed (number of assertion fails during mockup function call).
215 * Mockup functions verify that the parameters they are called with match
216 * expected values. The expected values should be stored in corresponding
217 * structures prior to mockup functions call. Every failure of such
218 * verification increases .failed counter. Every call of mockup function
219 * increases .called counter. Function returns value stored in .ret field
221 * In case of some parameters in some functions the expected value is unknown
222 * and cannot be detrmined prior to call. Such parameters are stored
223 * in structure and can be compared or analyzed later in test case code.
225 * Below structures and functions follow the rules just described.
226 * Additional remarks and exceptions are added in comments.
230 * session_create mockup
232 * Verified parameters: device, conf, mp.
233 * Saved, not verified parameters: sess.
235 static struct mock_session_create_data {
237 struct rte_security_session_conf *conf;
238 struct rte_security_session *sess;
239 struct rte_mempool *mp;
245 } mock_session_create_exp = {NULL, NULL, NULL, NULL, 0, 0, 0};
248 mock_session_create(void *device,
249 struct rte_security_session_conf *conf,
250 struct rte_security_session *sess,
251 struct rte_mempool *mp)
253 mock_session_create_exp.called++;
255 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, device);
256 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, conf);
257 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, mp);
259 mock_session_create_exp.sess = sess;
261 return mock_session_create_exp.ret;
265 * session_update mockup
267 * Verified parameters: device, sess, conf.
269 static struct mock_session_update_data {
271 struct rte_security_session *sess;
272 struct rte_security_session_conf *conf;
278 } mock_session_update_exp = {NULL, NULL, NULL, 0, 0, 0};
281 mock_session_update(void *device,
282 struct rte_security_session *sess,
283 struct rte_security_session_conf *conf)
285 mock_session_update_exp.called++;
287 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, device);
288 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, sess);
289 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, conf);
291 return mock_session_update_exp.ret;
295 * session_get_size mockup
297 * Verified parameters: device.
299 static struct mock_session_get_size_data {
306 } mock_session_get_size_exp = {NULL, 0U, 0, 0};
309 mock_session_get_size(void *device)
311 mock_session_get_size_exp.called++;
313 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_get_size_exp, device);
315 return mock_session_get_size_exp.ret;
319 * session_stats_get mockup
321 * Verified parameters: device, sess, stats.
323 static struct mock_session_stats_get_data {
325 struct rte_security_session *sess;
326 struct rte_security_stats *stats;
332 } mock_session_stats_get_exp = {NULL, NULL, NULL, 0, 0, 0};
335 mock_session_stats_get(void *device,
336 struct rte_security_session *sess,
337 struct rte_security_stats *stats)
339 mock_session_stats_get_exp.called++;
341 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_stats_get_exp, device);
342 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_stats_get_exp, sess);
343 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_stats_get_exp, stats);
345 return mock_session_stats_get_exp.ret;
349 * session_destroy mockup
351 * Verified parameters: device, sess.
353 static struct mock_session_destroy_data {
355 struct rte_security_session *sess;
361 } mock_session_destroy_exp = {NULL, NULL, 0, 0, 0};
364 mock_session_destroy(void *device, struct rte_security_session *sess)
366 mock_session_destroy_exp.called++;
368 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_destroy_exp, device);
369 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_destroy_exp, sess);
371 return mock_session_destroy_exp.ret;
375 * set_pkt_metadata mockup
377 * Verified parameters: device, sess, m, params.
379 static struct mock_set_pkt_metadata_data {
381 struct rte_security_session *sess;
389 } mock_set_pkt_metadata_exp = {NULL, NULL, NULL, NULL, 0, 0, 0};
392 mock_set_pkt_metadata(void *device,
393 struct rte_security_session *sess,
397 mock_set_pkt_metadata_exp.called++;
399 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, device);
400 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, sess);
401 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, m);
402 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, params);
404 return mock_set_pkt_metadata_exp.ret;
408 * get_userdata mockup
410 * Verified parameters: device, md.
411 * The userdata parameter works as an output parameter, so a passed address
412 * is verified not to be NULL and filled with userdata stored in structure.
414 static struct mock_get_userdata_data {
423 } mock_get_userdata_exp = {NULL, 0UL, NULL, 0, 0, 0};
426 mock_get_userdata(void *device,
430 mock_get_userdata_exp.called++;
432 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_get_userdata_exp, device);
433 MOCK_TEST_ASSERT_U64_PARAMETER(mock_get_userdata_exp, md);
435 MOCK_TEST_ASSERT_NOT_NULL(mock_get_userdata_exp.failed,
437 "Expecting parameter userdata not to be NULL but it's %p",
439 *userdata = mock_get_userdata_exp.userdata;
441 return mock_get_userdata_exp.ret;
445 * capabilities_get mockup
447 * Verified parameters: device.
449 static struct mock_capabilities_get_data {
452 struct rte_security_capability *ret;
456 } mock_capabilities_get_exp = {NULL, NULL, 0, 0};
458 static const struct rte_security_capability *
459 mock_capabilities_get(void *device)
461 mock_capabilities_get_exp.called++;
463 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_capabilities_get_exp, device);
465 return mock_capabilities_get_exp.ret;
471 * is an empty security operations set (all function pointers set to NULL)
473 struct rte_security_ops empty_ops = { NULL };
478 * is a security operations set using mockup functions
480 struct rte_security_ops mock_ops = {
481 .session_create = mock_session_create,
482 .session_update = mock_session_update,
483 .session_get_size = mock_session_get_size,
484 .session_stats_get = mock_session_stats_get,
485 .session_destroy = mock_session_destroy,
486 .set_pkt_metadata = mock_set_pkt_metadata,
487 .get_userdata = mock_get_userdata,
488 .capabilities_get = mock_capabilities_get,
493 * Test suite and test cases setup and teardown functions.
497 * struct security_testsuite_params defines parameters initialized once
498 * for whole tests suite.
499 * Currently the only stored parameter is session_mpool a mempool created
500 * once in testsuite_setup and released in testsuite_teardown.
501 * The instance of this structure is stored in testsuite_params variable.
503 static struct security_testsuite_params {
504 struct rte_mempool *session_mpool;
505 } testsuite_params = { NULL };
508 * struct security_unittest_params defines parameters initialized
509 * for every test case. The parameters are initialized in ut_setup
510 * or ut_setup_with_session (depending on the testcase)
511 * and released in ut_teardown.
512 * The instance of this structure is stored in unittest_params variable.
514 static struct security_unittest_params {
515 struct rte_security_ctx ctx;
516 struct rte_security_session_conf conf;
517 struct rte_security_session *sess;
518 } unittest_params = {
527 #define SECURITY_TEST_MEMPOOL_NAME "SecurityTestsMempoolName"
528 #define SECURITY_TEST_MEMPOOL_SIZE 15
529 #define SECURITY_TEST_SESSION_OBJECT_SIZE sizeof(struct rte_security_session)
532 * testsuite_setup initializes whole test suite parameters.
533 * It creates a new mempool used in all test cases
534 * and verifies if it properly created.
537 testsuite_setup(void)
539 struct security_testsuite_params *ts_params = &testsuite_params;
540 ts_params->session_mpool = rte_mempool_create(
541 SECURITY_TEST_MEMPOOL_NAME,
542 SECURITY_TEST_MEMPOOL_SIZE,
543 SECURITY_TEST_SESSION_OBJECT_SIZE,
544 0, 0, NULL, NULL, NULL, NULL,
546 TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
547 "Cannot create mempool %s\n", rte_strerror(rte_errno));
552 * testsuite_teardown releases test suite wide parameters.
555 testsuite_teardown(void)
557 struct security_testsuite_params *ts_params = &testsuite_params;
558 if (ts_params->session_mpool) {
559 rte_mempool_free(ts_params->session_mpool);
560 ts_params->session_mpool = NULL;
565 * ut_setup initializes test case parameters to default values.
566 * It resets also any .called and .failed statistics of mockup functions
572 struct security_unittest_params *ut_params = &unittest_params;
573 ut_params->ctx.device = NULL;
574 ut_params->ctx.ops = &mock_ops;
575 ut_params->ctx.sess_cnt = 0;
576 ut_params->sess = NULL;
578 mock_session_create_exp.called = 0;
579 mock_session_update_exp.called = 0;
580 mock_session_get_size_exp.called = 0;
581 mock_session_stats_get_exp.called = 0;
582 mock_session_destroy_exp.called = 0;
583 mock_set_pkt_metadata_exp.called = 0;
584 mock_get_userdata_exp.called = 0;
585 mock_capabilities_get_exp.called = 0;
587 mock_session_create_exp.failed = 0;
588 mock_session_update_exp.failed = 0;
589 mock_session_get_size_exp.failed = 0;
590 mock_session_stats_get_exp.failed = 0;
591 mock_session_destroy_exp.failed = 0;
592 mock_set_pkt_metadata_exp.failed = 0;
593 mock_get_userdata_exp.failed = 0;
594 mock_capabilities_get_exp.failed = 0;
600 * destroy_session_with_check is a helper function releasing session
601 * created with rte_security_session_create and stored in test case parameters.
602 * It's used both to release sessions created in test cases' bodies
603 * which are assigned to ut_params->sess
604 * as well as sessions created in ut_setup_with_session.
607 destroy_session_with_check(void)
609 struct security_unittest_params *ut_params = &unittest_params;
610 if (ut_params->sess != NULL) {
611 /* Assure that mockup function for destroy operation is set. */
612 ut_params->ctx.ops = &mock_ops;
614 mock_session_destroy_exp.device = NULL;
615 mock_session_destroy_exp.sess = ut_params->sess;
616 mock_session_destroy_exp.ret = 0;
617 mock_session_destroy_exp.called = 0;
618 mock_session_destroy_exp.failed = 0;
620 int ret = rte_security_session_destroy(&ut_params->ctx,
622 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
624 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
626 ut_params->sess = NULL;
632 * ut_teardown releases test case parameters.
637 destroy_session_with_check();
641 * ut_setup_with_session initializes test case parameters by
642 * - calling standard ut_setup,
643 * - creating a session that can be used in test case.
646 ut_setup_with_session(void)
648 struct security_unittest_params *ut_params = &unittest_params;
649 struct security_testsuite_params *ts_params = &testsuite_params;
650 struct rte_security_session *sess;
652 int ret = ut_setup();
653 if (ret != TEST_SUCCESS)
656 mock_session_create_exp.device = NULL;
657 mock_session_create_exp.conf = &ut_params->conf;
658 mock_session_create_exp.mp = ts_params->session_mpool;
659 mock_session_create_exp.ret = 0;
661 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
662 ts_params->session_mpool);
663 TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(rte_security_session_create,
665 TEST_ASSERT_EQUAL(sess, mock_session_create_exp.sess,
666 "Expecting session_create to be called with %p sess"
667 " parameter, but it's called %p sess parameter",
668 sess, mock_session_create_exp.sess);
669 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
672 * Store created session in test case parameters, so it can be released
673 * after test case in ut_teardown by destroy_session_with_check.
675 ut_params->sess = sess;
684 * Each test function is related to a single test case.
685 * They are arranged by tested rte_security API function
686 * and by rte_security execution paths sequence in code.
690 * rte_security_session_create tests
694 * Test execution of rte_security_session_create with NULL instance
697 test_session_create_inv_context(void)
699 struct security_testsuite_params *ts_params = &testsuite_params;
700 struct security_unittest_params *ut_params = &unittest_params;
701 struct rte_security_session *sess;
703 sess = rte_security_session_create(NULL, &ut_params->conf,
704 ts_params->session_mpool);
705 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
707 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
708 TEST_ASSERT_MEMPOOL_USAGE(0);
709 TEST_ASSERT_SESSION_COUNT(0);
715 * Test execution of rte_security_session_create with invalid
716 * security operations structure (NULL)
719 test_session_create_inv_context_ops(void)
721 struct security_testsuite_params *ts_params = &testsuite_params;
722 struct security_unittest_params *ut_params = &unittest_params;
723 struct rte_security_session *sess;
725 ut_params->ctx.ops = NULL;
727 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
728 ts_params->session_mpool);
729 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
731 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
732 TEST_ASSERT_MEMPOOL_USAGE(0);
733 TEST_ASSERT_SESSION_COUNT(0);
739 * Test execution of rte_security_session_create with empty
740 * security operations
743 test_session_create_inv_context_ops_fun(void)
745 struct security_testsuite_params *ts_params = &testsuite_params;
746 struct security_unittest_params *ut_params = &unittest_params;
747 struct rte_security_session *sess;
749 ut_params->ctx.ops = &empty_ops;
751 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
752 ts_params->session_mpool);
753 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
755 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
756 TEST_ASSERT_MEMPOOL_USAGE(0);
757 TEST_ASSERT_SESSION_COUNT(0);
763 * Test execution of rte_security_session_create with NULL conf parameter
766 test_session_create_inv_configuration(void)
768 struct security_testsuite_params *ts_params = &testsuite_params;
769 struct security_unittest_params *ut_params = &unittest_params;
770 struct rte_security_session *sess;
772 sess = rte_security_session_create(&ut_params->ctx, NULL,
773 ts_params->session_mpool);
774 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
776 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
777 TEST_ASSERT_MEMPOOL_USAGE(0);
778 TEST_ASSERT_SESSION_COUNT(0);
784 * Test execution of rte_security_session_create with NULL mp parameter
787 test_session_create_inv_mempool(void)
789 struct security_unittest_params *ut_params = &unittest_params;
790 struct rte_security_session *sess;
792 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
794 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
796 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
797 TEST_ASSERT_MEMPOOL_USAGE(0);
798 TEST_ASSERT_SESSION_COUNT(0);
804 * Test execution of rte_security_session_create in case when mempool
805 * is fully used and no object can be got from it
808 test_session_create_mempool_empty(void)
810 struct security_testsuite_params *ts_params = &testsuite_params;
811 struct security_unittest_params *ut_params = &unittest_params;
812 struct rte_security_session *tmp[SECURITY_TEST_MEMPOOL_SIZE];
813 struct rte_security_session *sess;
815 /* Get all available objects from mempool. */
817 for (i = 0; i < SECURITY_TEST_MEMPOOL_SIZE; ++i) {
818 ret = rte_mempool_get(ts_params->session_mpool,
820 TEST_ASSERT_EQUAL(0, ret,
821 "Expect getting %d object from mempool"
824 TEST_ASSERT_MEMPOOL_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
826 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
827 ts_params->session_mpool);
828 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
830 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
831 TEST_ASSERT_MEMPOOL_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
832 TEST_ASSERT_SESSION_COUNT(0);
834 /* Put objects back to the pool. */
835 for (i = 0; i < SECURITY_TEST_MEMPOOL_SIZE; ++i)
836 rte_mempool_put(ts_params->session_mpool, (void *)(tmp[i]));
837 TEST_ASSERT_MEMPOOL_USAGE(0);
843 * Test execution of rte_security_session_create when session_create
844 * security operation fails
847 test_session_create_ops_failure(void)
849 struct security_testsuite_params *ts_params = &testsuite_params;
850 struct security_unittest_params *ut_params = &unittest_params;
851 struct rte_security_session *sess;
853 mock_session_create_exp.device = NULL;
854 mock_session_create_exp.conf = &ut_params->conf;
855 mock_session_create_exp.mp = ts_params->session_mpool;
856 mock_session_create_exp.ret = -1; /* Return failure status. */
858 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
859 ts_params->session_mpool);
860 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
862 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
863 TEST_ASSERT_MEMPOOL_USAGE(0);
864 TEST_ASSERT_SESSION_COUNT(0);
870 * Test execution of rte_security_session_create in successful execution path
873 test_session_create_success(void)
875 struct security_testsuite_params *ts_params = &testsuite_params;
876 struct security_unittest_params *ut_params = &unittest_params;
877 struct rte_security_session *sess;
879 mock_session_create_exp.device = NULL;
880 mock_session_create_exp.conf = &ut_params->conf;
881 mock_session_create_exp.mp = ts_params->session_mpool;
882 mock_session_create_exp.ret = 0; /* Return success status. */
884 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
885 ts_params->session_mpool);
886 TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(rte_security_session_create,
888 TEST_ASSERT_EQUAL(sess, mock_session_create_exp.sess,
889 "Expecting session_create to be called with %p sess"
890 " parameter, but it's called %p sess parameter",
891 sess, mock_session_create_exp.sess);
892 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
893 TEST_ASSERT_MEMPOOL_USAGE(1);
894 TEST_ASSERT_SESSION_COUNT(1);
897 * Store created session in test case parameters, so it can be released
898 * after test case in ut_teardown by destroy_session_with_check.
900 ut_params->sess = sess;
907 * rte_security_session_update tests
911 * Test execution of rte_security_session_update with NULL instance
914 test_session_update_inv_context(void)
916 struct security_unittest_params *ut_params = &unittest_params;
918 int ret = rte_security_session_update(NULL, ut_params->sess,
920 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
922 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
928 * Test execution of rte_security_session_update with invalid
929 * security operations structure (NULL)
932 test_session_update_inv_context_ops(void)
934 struct security_unittest_params *ut_params = &unittest_params;
935 ut_params->ctx.ops = NULL;
937 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
939 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
941 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
947 * Test execution of rte_security_session_update with empty
948 * security operations
951 test_session_update_inv_context_ops_fun(void)
953 struct security_unittest_params *ut_params = &unittest_params;
954 ut_params->ctx.ops = &empty_ops;
956 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
958 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
959 ret, -ENOTSUP, "%d");
960 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
966 * Test execution of rte_security_session_update with NULL conf parameter
969 test_session_update_inv_configuration(void)
971 struct security_unittest_params *ut_params = &unittest_params;
973 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
975 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
977 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
983 * Test execution of rte_security_session_update with NULL sess parameter
986 test_session_update_inv_session(void)
988 struct security_unittest_params *ut_params = &unittest_params;
990 int ret = rte_security_session_update(&ut_params->ctx, NULL,
992 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
994 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
1000 * Test execution of rte_security_session_update when session_update
1001 * security operation fails
1004 test_session_update_ops_failure(void)
1006 struct security_unittest_params *ut_params = &unittest_params;
1008 mock_session_update_exp.device = NULL;
1009 mock_session_update_exp.sess = ut_params->sess;
1010 mock_session_update_exp.conf = &ut_params->conf;
1011 mock_session_update_exp.ret = -1; /* Return failure status. */
1013 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
1015 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1017 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 1);
1019 return TEST_SUCCESS;
1023 * Test execution of rte_security_session_update in successful execution path
1026 test_session_update_success(void)
1028 struct security_unittest_params *ut_params = &unittest_params;
1030 mock_session_update_exp.device = NULL;
1031 mock_session_update_exp.sess = ut_params->sess;
1032 mock_session_update_exp.conf = &ut_params->conf;
1033 mock_session_update_exp.ret = 0; /* Return success status. */
1035 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
1037 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1039 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 1);
1041 return TEST_SUCCESS;
1046 * rte_security_session_get_size tests
1050 * Test execution of rte_security_session_get_size with NULL instance
1053 test_session_get_size_inv_context(void)
1055 unsigned int ret = rte_security_session_get_size(NULL);
1056 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1058 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
1060 return TEST_SUCCESS;
1064 * Test execution of rte_security_session_get_size with invalid
1065 * security operations structure (NULL)
1068 test_session_get_size_inv_context_ops(void)
1070 struct security_unittest_params *ut_params = &unittest_params;
1071 ut_params->ctx.ops = NULL;
1073 unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1074 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1076 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
1078 return TEST_SUCCESS;
1082 * Test execution of rte_security_session_get_size with empty
1083 * security operations
1086 test_session_get_size_inv_context_ops_fun(void)
1088 struct security_unittest_params *ut_params = &unittest_params;
1089 ut_params->ctx.ops = &empty_ops;
1091 unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1092 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1094 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
1096 return TEST_SUCCESS;
1100 * Test execution of rte_security_session_get_size when session_get_size
1101 * security operation fails
1104 test_session_get_size_ops_failure(void)
1106 struct security_unittest_params *ut_params = &unittest_params;
1108 mock_session_get_size_exp.device = NULL;
1109 mock_session_get_size_exp.ret = 0;
1111 unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1112 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1114 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 1);
1116 return TEST_SUCCESS;
1120 * Test execution of rte_security_session_get_size in successful execution path
1123 test_session_get_size_success(void)
1125 struct security_unittest_params *ut_params = &unittest_params;
1127 mock_session_get_size_exp.device = NULL;
1128 mock_session_get_size_exp.ret = 1024;
1130 unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1131 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1133 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 1);
1135 return TEST_SUCCESS;
1140 * rte_security_session_stats_get tests
1144 * Test execution of rte_security_session_stats_get with NULL instance
1147 test_session_stats_get_inv_context(void)
1149 struct security_unittest_params *ut_params = &unittest_params;
1150 struct rte_security_stats stats;
1152 int ret = rte_security_session_stats_get(NULL, ut_params->sess, &stats);
1153 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1154 ret, -EINVAL, "%d");
1155 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1157 return TEST_SUCCESS;
1161 * Test execution of rte_security_session_stats_get with invalid
1162 * security operations structure (NULL)
1165 test_session_stats_get_inv_context_ops(void)
1167 struct security_unittest_params *ut_params = &unittest_params;
1168 struct rte_security_stats stats;
1169 ut_params->ctx.ops = NULL;
1171 int ret = rte_security_session_stats_get(&ut_params->ctx,
1172 ut_params->sess, &stats);
1173 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1174 ret, -EINVAL, "%d");
1175 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1177 return TEST_SUCCESS;
1181 * Test execution of rte_security_session_stats_get with empty
1182 * security operations
1185 test_session_stats_get_inv_context_ops_fun(void)
1187 struct security_unittest_params *ut_params = &unittest_params;
1188 struct rte_security_stats stats;
1189 ut_params->ctx.ops = &empty_ops;
1191 int ret = rte_security_session_stats_get(&ut_params->ctx,
1192 ut_params->sess, &stats);
1193 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1194 ret, -ENOTSUP, "%d");
1195 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1197 return TEST_SUCCESS;
1201 * Test execution of rte_security_session_stats_get with NULL stats parameter
1204 test_session_stats_get_inv_stats(void)
1206 struct security_unittest_params *ut_params = &unittest_params;
1208 int ret = rte_security_session_stats_get(&ut_params->ctx,
1209 ut_params->sess, NULL);
1210 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1211 ret, -EINVAL, "%d");
1212 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1214 return TEST_SUCCESS;
1218 * Test execution of rte_security_session_stats_get when session_stats_get
1219 * security operation fails
1222 test_session_stats_get_ops_failure(void)
1224 struct security_unittest_params *ut_params = &unittest_params;
1225 struct rte_security_stats stats;
1227 mock_session_stats_get_exp.device = NULL;
1228 mock_session_stats_get_exp.sess = ut_params->sess;
1229 mock_session_stats_get_exp.stats = &stats;
1230 mock_session_stats_get_exp.ret = -1;
1232 int ret = rte_security_session_stats_get(&ut_params->ctx,
1233 ut_params->sess, &stats);
1234 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1236 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 1);
1238 return TEST_SUCCESS;
1242 * Test execution of rte_security_session_stats_get in successful execution
1246 test_session_stats_get_success(void)
1248 struct security_unittest_params *ut_params = &unittest_params;
1249 struct rte_security_stats stats;
1251 mock_session_stats_get_exp.device = NULL;
1252 mock_session_stats_get_exp.sess = ut_params->sess;
1253 mock_session_stats_get_exp.stats = &stats;
1254 mock_session_stats_get_exp.ret = 0;
1256 int ret = rte_security_session_stats_get(&ut_params->ctx,
1257 ut_params->sess, &stats);
1258 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1260 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 1);
1262 return TEST_SUCCESS;
1267 * rte_security_session_destroy tests
1271 * Test execution of rte_security_session_destroy with NULL instance
1274 test_session_destroy_inv_context(void)
1276 struct security_unittest_params *ut_params = &unittest_params;
1278 TEST_ASSERT_MEMPOOL_USAGE(1);
1279 TEST_ASSERT_SESSION_COUNT(1);
1281 int ret = rte_security_session_destroy(NULL, ut_params->sess);
1282 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1283 ret, -EINVAL, "%d");
1284 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1285 TEST_ASSERT_MEMPOOL_USAGE(1);
1286 TEST_ASSERT_SESSION_COUNT(1);
1288 return TEST_SUCCESS;
1292 * Test execution of rte_security_session_destroy with invalid
1293 * security operations structure (NULL)
1296 test_session_destroy_inv_context_ops(void)
1298 struct security_unittest_params *ut_params = &unittest_params;
1299 ut_params->ctx.ops = NULL;
1301 TEST_ASSERT_MEMPOOL_USAGE(1);
1302 TEST_ASSERT_SESSION_COUNT(1);
1304 int ret = rte_security_session_destroy(&ut_params->ctx,
1306 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1307 ret, -EINVAL, "%d");
1308 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1309 TEST_ASSERT_MEMPOOL_USAGE(1);
1310 TEST_ASSERT_SESSION_COUNT(1);
1312 return TEST_SUCCESS;
1316 * Test execution of rte_security_session_destroy with empty
1317 * security operations
1320 test_session_destroy_inv_context_ops_fun(void)
1322 struct security_unittest_params *ut_params = &unittest_params;
1323 ut_params->ctx.ops = &empty_ops;
1325 TEST_ASSERT_MEMPOOL_USAGE(1);
1326 TEST_ASSERT_SESSION_COUNT(1);
1328 int ret = rte_security_session_destroy(&ut_params->ctx,
1330 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1331 ret, -ENOTSUP, "%d");
1332 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1333 TEST_ASSERT_MEMPOOL_USAGE(1);
1334 TEST_ASSERT_SESSION_COUNT(1);
1336 return TEST_SUCCESS;
1340 * Test execution of rte_security_session_destroy with NULL sess parameter
1343 test_session_destroy_inv_session(void)
1345 struct security_unittest_params *ut_params = &unittest_params;
1347 TEST_ASSERT_MEMPOOL_USAGE(1);
1348 TEST_ASSERT_SESSION_COUNT(1);
1350 int ret = rte_security_session_destroy(&ut_params->ctx, NULL);
1351 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1352 ret, -EINVAL, "%d");
1353 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1354 TEST_ASSERT_MEMPOOL_USAGE(1);
1355 TEST_ASSERT_SESSION_COUNT(1);
1357 return TEST_SUCCESS;
1361 * Test execution of rte_security_session_destroy when session_destroy
1362 * security operation fails
1365 test_session_destroy_ops_failure(void)
1367 struct security_unittest_params *ut_params = &unittest_params;
1369 mock_session_destroy_exp.device = NULL;
1370 mock_session_destroy_exp.sess = ut_params->sess;
1371 mock_session_destroy_exp.ret = -1;
1373 TEST_ASSERT_MEMPOOL_USAGE(1);
1374 TEST_ASSERT_SESSION_COUNT(1);
1376 int ret = rte_security_session_destroy(&ut_params->ctx,
1378 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1380 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
1381 TEST_ASSERT_MEMPOOL_USAGE(1);
1382 TEST_ASSERT_SESSION_COUNT(1);
1384 return TEST_SUCCESS;
1388 * Test execution of rte_security_session_destroy in successful execution path
1391 test_session_destroy_success(void)
1393 struct security_unittest_params *ut_params = &unittest_params;
1395 mock_session_destroy_exp.device = NULL;
1396 mock_session_destroy_exp.sess = ut_params->sess;
1397 mock_session_destroy_exp.ret = 0;
1398 TEST_ASSERT_MEMPOOL_USAGE(1);
1399 TEST_ASSERT_SESSION_COUNT(1);
1401 int ret = rte_security_session_destroy(&ut_params->ctx,
1403 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1405 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
1406 TEST_ASSERT_MEMPOOL_USAGE(0);
1407 TEST_ASSERT_SESSION_COUNT(0);
1410 * Remove session from test case parameters, so it won't be destroyed
1411 * during test case teardown.
1413 ut_params->sess = NULL;
1415 return TEST_SUCCESS;
1420 * rte_security_set_pkt_metadata tests
1424 * Test execution of rte_security_set_pkt_metadata with NULL instance
1427 test_set_pkt_metadata_inv_context(void)
1430 struct security_unittest_params *ut_params = &unittest_params;
1434 int ret = rte_security_set_pkt_metadata(NULL, ut_params->sess, &m,
1436 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1437 ret, -EINVAL, "%d");
1438 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1440 return TEST_SUCCESS;
1442 return TEST_SKIPPED;
1447 * Test execution of rte_security_set_pkt_metadata with invalid
1448 * security operations structure (NULL)
1451 test_set_pkt_metadata_inv_context_ops(void)
1454 struct security_unittest_params *ut_params = &unittest_params;
1457 ut_params->ctx.ops = NULL;
1459 int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1460 ut_params->sess, &m, ¶ms);
1461 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1462 ret, -EINVAL, "%d");
1463 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1465 return TEST_SUCCESS;
1467 return TEST_SKIPPED;
1472 * Test execution of rte_security_set_pkt_metadata with empty
1473 * security operations
1476 test_set_pkt_metadata_inv_context_ops_fun(void)
1478 struct security_unittest_params *ut_params = &unittest_params;
1481 ut_params->ctx.ops = &empty_ops;
1483 int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1484 ut_params->sess, &m, ¶ms);
1485 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1486 ret, -ENOTSUP, "%d");
1487 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1489 return TEST_SUCCESS;
1493 * Test execution of rte_security_set_pkt_metadata with NULL sess parameter
1496 test_set_pkt_metadata_inv_session(void)
1499 struct security_unittest_params *ut_params = &unittest_params;
1503 int ret = rte_security_set_pkt_metadata(&ut_params->ctx, NULL,
1505 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1506 ret, -EINVAL, "%d");
1507 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1509 return TEST_SUCCESS;
1511 return TEST_SKIPPED;
1516 * Test execution of rte_security_set_pkt_metadata when set_pkt_metadata
1517 * security operation fails
1520 test_set_pkt_metadata_ops_failure(void)
1522 struct security_unittest_params *ut_params = &unittest_params;
1526 mock_set_pkt_metadata_exp.device = NULL;
1527 mock_set_pkt_metadata_exp.sess = ut_params->sess;
1528 mock_set_pkt_metadata_exp.m = &m;
1529 mock_set_pkt_metadata_exp.params = ¶ms;
1530 mock_set_pkt_metadata_exp.ret = -1;
1532 int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1533 ut_params->sess, &m, ¶ms);
1534 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1536 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 1);
1538 return TEST_SUCCESS;
1542 * Test execution of rte_security_set_pkt_metadata in successful execution path
1545 test_set_pkt_metadata_success(void)
1547 struct security_unittest_params *ut_params = &unittest_params;
1551 mock_set_pkt_metadata_exp.device = NULL;
1552 mock_set_pkt_metadata_exp.sess = ut_params->sess;
1553 mock_set_pkt_metadata_exp.m = &m;
1554 mock_set_pkt_metadata_exp.params = ¶ms;
1555 mock_set_pkt_metadata_exp.ret = 0;
1557 int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1558 ut_params->sess, &m, ¶ms);
1559 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1561 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 1);
1563 return TEST_SUCCESS;
1568 * rte_security_get_userdata tests
1572 * Test execution of rte_security_get_userdata with NULL instance
1575 test_get_userdata_inv_context(void)
1578 uint64_t md = 0xDEADBEEF;
1580 void *ret = rte_security_get_userdata(NULL, md);
1581 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1583 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0);
1585 return TEST_SUCCESS;
1587 return TEST_SKIPPED;
1592 * Test execution of rte_security_get_userdata with invalid
1593 * security operations structure (NULL)
1596 test_get_userdata_inv_context_ops(void)
1599 struct security_unittest_params *ut_params = &unittest_params;
1600 uint64_t md = 0xDEADBEEF;
1601 ut_params->ctx.ops = NULL;
1603 void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1604 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1606 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0);
1608 return TEST_SUCCESS;
1610 return TEST_SKIPPED;
1615 * Test execution of rte_security_get_userdata with empty
1616 * security operations
1619 test_get_userdata_inv_context_ops_fun(void)
1621 struct security_unittest_params *ut_params = &unittest_params;
1622 uint64_t md = 0xDEADBEEF;
1623 ut_params->ctx.ops = &empty_ops;
1625 void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1626 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1628 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0);
1630 return TEST_SUCCESS;
1634 * Test execution of rte_security_get_userdata when get_userdata
1635 * security operation fails
1638 test_get_userdata_ops_failure(void)
1640 struct security_unittest_params *ut_params = &unittest_params;
1641 uint64_t md = 0xDEADBEEF;
1642 void *userdata = (void *)0x7E577E57;
1644 mock_get_userdata_exp.device = NULL;
1645 mock_get_userdata_exp.md = md;
1646 mock_get_userdata_exp.userdata = userdata;
1647 mock_get_userdata_exp.ret = -1;
1649 void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1650 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1652 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 1);
1654 return TEST_SUCCESS;
1658 * Test execution of rte_security_get_userdata in successful execution path
1661 test_get_userdata_success(void)
1663 struct security_unittest_params *ut_params = &unittest_params;
1664 uint64_t md = 0xDEADBEEF;
1665 void *userdata = (void *)0x7E577E57;
1667 mock_get_userdata_exp.device = NULL;
1668 mock_get_userdata_exp.md = md;
1669 mock_get_userdata_exp.userdata = userdata;
1670 mock_get_userdata_exp.ret = 0;
1672 void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1673 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1674 ret, userdata, "%p");
1675 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 1);
1677 return TEST_SUCCESS;
1682 * rte_security_capabilities_get tests
1686 * Test execution of rte_security_capabilities_get with NULL instance
1689 test_capabilities_get_inv_context(void)
1691 const struct rte_security_capability *ret;
1692 ret = rte_security_capabilities_get(NULL);
1693 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1695 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1697 return TEST_SUCCESS;
1701 * Test execution of rte_security_capabilities_get with invalid
1702 * security operations structure (NULL)
1705 test_capabilities_get_inv_context_ops(void)
1707 struct security_unittest_params *ut_params = &unittest_params;
1708 ut_params->ctx.ops = NULL;
1710 const struct rte_security_capability *ret;
1711 ret = rte_security_capabilities_get(&ut_params->ctx);
1712 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1714 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1716 return TEST_SUCCESS;
1720 * Test execution of rte_security_capabilities_get with empty
1721 * security operations
1724 test_capabilities_get_inv_context_ops_fun(void)
1726 struct security_unittest_params *ut_params = &unittest_params;
1727 ut_params->ctx.ops = &empty_ops;
1729 const struct rte_security_capability *ret;
1730 ret = rte_security_capabilities_get(&ut_params->ctx);
1731 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1733 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1735 return TEST_SUCCESS;
1739 * Test execution of rte_security_capabilities_get when capabilities_get
1740 * security operation fails
1743 test_capabilities_get_ops_failure(void)
1745 struct security_unittest_params *ut_params = &unittest_params;
1747 mock_capabilities_get_exp.device = NULL;
1748 mock_capabilities_get_exp.ret = NULL;
1750 const struct rte_security_capability *ret;
1751 ret = rte_security_capabilities_get(&ut_params->ctx);
1752 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1754 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
1756 return TEST_SUCCESS;
1760 * Test execution of rte_security_capabilities_get in successful execution path
1763 test_capabilities_get_success(void)
1765 struct security_unittest_params *ut_params = &unittest_params;
1766 struct rte_security_capability capabilities;
1768 mock_capabilities_get_exp.device = NULL;
1769 mock_capabilities_get_exp.ret = &capabilities;
1771 const struct rte_security_capability *ret;
1772 ret = rte_security_capabilities_get(&ut_params->ctx);
1773 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1774 ret, &capabilities, "%p");
1775 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
1777 return TEST_SUCCESS;
1782 * rte_security_capability_get tests
1786 * Test execution of rte_security_capability_get with NULL instance
1789 test_capability_get_inv_context(void)
1791 struct rte_security_capability_idx idx;
1793 const struct rte_security_capability *ret;
1794 ret = rte_security_capability_get(NULL, &idx);
1795 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
1797 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1799 return TEST_SUCCESS;
1803 * Test execution of rte_security_capability_get with invalid
1804 * security operations structure (NULL)
1807 test_capability_get_inv_context_ops(void)
1809 struct security_unittest_params *ut_params = &unittest_params;
1810 struct rte_security_capability_idx idx;
1811 ut_params->ctx.ops = NULL;
1813 const struct rte_security_capability *ret;
1814 ret = rte_security_capability_get(&ut_params->ctx, &idx);
1815 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
1817 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1819 return TEST_SUCCESS;
1823 * Test execution of rte_security_capability_get with empty
1824 * security operations
1827 test_capability_get_inv_context_ops_fun(void)
1829 struct security_unittest_params *ut_params = &unittest_params;
1830 struct rte_security_capability_idx idx;
1831 ut_params->ctx.ops = &empty_ops;
1833 const struct rte_security_capability *ret;
1834 ret = rte_security_capability_get(&ut_params->ctx, &idx);
1835 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
1837 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1839 return TEST_SUCCESS;
1843 * Test execution of rte_security_capability_get with NULL idx parameter
1846 test_capability_get_inv_idx(void)
1848 struct security_unittest_params *ut_params = &unittest_params;
1850 const struct rte_security_capability *ret;
1851 ret = rte_security_capability_get(&ut_params->ctx, NULL);
1852 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
1854 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1856 return TEST_SUCCESS;
1860 * Test execution of rte_security_capability_get when capabilities_get
1861 * security operation fails
1864 test_capability_get_ops_failure(void)
1866 struct security_unittest_params *ut_params = &unittest_params;
1867 struct rte_security_capability_idx idx;
1869 mock_capabilities_get_exp.device = NULL;
1870 mock_capabilities_get_exp.ret = NULL;
1872 const struct rte_security_capability *ret;
1873 ret = rte_security_capability_get(&ut_params->ctx, &idx);
1874 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
1876 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
1878 return TEST_SUCCESS;
1882 * Test execution of rte_security_capability_get when capabilities table
1883 * is empty (contains only RTE_SECURITY_ACTION_TYPE_NONE ending entry)
1886 test_capability_get_empty_table(void)
1888 struct security_unittest_params *ut_params = &unittest_params;
1889 struct rte_security_capability_idx idx;
1890 struct rte_security_capability capabilities[] = {
1892 .action = RTE_SECURITY_ACTION_TYPE_NONE,
1896 mock_capabilities_get_exp.device = NULL;
1897 mock_capabilities_get_exp.ret = capabilities;
1899 const struct rte_security_capability *ret;
1900 ret = rte_security_capability_get(&ut_params->ctx, &idx);
1901 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
1903 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
1905 return TEST_SUCCESS;
1909 * Test execution of rte_security_capability_get when capabilities table
1910 * does not contain entry with matching action
1913 test_capability_get_no_matching_action(void)
1915 struct security_unittest_params *ut_params = &unittest_params;
1916 struct rte_security_capability_idx idx = {
1917 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
1919 struct rte_security_capability capabilities[] = {
1921 .action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
1924 .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
1927 .action = RTE_SECURITY_ACTION_TYPE_NONE,
1931 mock_capabilities_get_exp.device = NULL;
1932 mock_capabilities_get_exp.ret = capabilities;
1934 const struct rte_security_capability *ret;
1935 ret = rte_security_capability_get(&ut_params->ctx, &idx);
1936 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
1938 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
1940 return TEST_SUCCESS;
1944 * Test execution of rte_security_capability_get when capabilities table
1945 * does not contain entry with matching protocol
1948 test_capability_get_no_matching_protocol(void)
1950 struct security_unittest_params *ut_params = &unittest_params;
1951 struct rte_security_capability_idx idx = {
1952 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
1953 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
1955 struct rte_security_capability capabilities[] = {
1957 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
1958 .protocol = RTE_SECURITY_PROTOCOL_MACSEC,
1961 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
1962 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
1965 .action = RTE_SECURITY_ACTION_TYPE_NONE,
1969 mock_capabilities_get_exp.device = NULL;
1970 mock_capabilities_get_exp.ret = capabilities;
1972 const struct rte_security_capability *ret;
1973 ret = rte_security_capability_get(&ut_params->ctx, &idx);
1974 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
1976 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
1978 return TEST_SUCCESS;
1982 * Test execution of rte_security_capability_get when macsec protocol
1983 * is searched and capabilities table contain proper entry.
1984 * However macsec records search is not supported in rte_security.
1987 test_capability_get_no_support_for_macsec(void)
1989 struct security_unittest_params *ut_params = &unittest_params;
1990 struct rte_security_capability_idx idx = {
1991 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
1992 .protocol = RTE_SECURITY_PROTOCOL_MACSEC,
1994 struct rte_security_capability capabilities[] = {
1996 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
1997 .protocol = RTE_SECURITY_PROTOCOL_MACSEC,
2000 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2004 mock_capabilities_get_exp.device = NULL;
2005 mock_capabilities_get_exp.ret = capabilities;
2007 const struct rte_security_capability *ret;
2008 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2009 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2011 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2013 return TEST_SUCCESS;
2017 * Test execution of rte_security_capability_get when capabilities table
2018 * does not contain entry with matching ipsec proto field
2021 test_capability_get_ipsec_mismatch_proto(void)
2023 struct security_unittest_params *ut_params = &unittest_params;
2024 struct rte_security_capability_idx idx = {
2025 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2026 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2028 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2031 struct rte_security_capability capabilities[] = {
2033 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2034 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2036 .proto = RTE_SECURITY_IPSEC_SA_PROTO_AH,
2040 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2044 mock_capabilities_get_exp.device = NULL;
2045 mock_capabilities_get_exp.ret = capabilities;
2047 const struct rte_security_capability *ret;
2048 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2049 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2051 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2053 return TEST_SUCCESS;
2057 * Test execution of rte_security_capability_get when capabilities table
2058 * does not contain entry with matching ipsec mode field
2061 test_capability_get_ipsec_mismatch_mode(void)
2063 struct security_unittest_params *ut_params = &unittest_params;
2064 struct rte_security_capability_idx idx = {
2065 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2066 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2068 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2069 .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
2072 struct rte_security_capability capabilities[] = {
2074 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2075 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2077 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2078 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
2082 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2086 mock_capabilities_get_exp.device = NULL;
2087 mock_capabilities_get_exp.ret = capabilities;
2089 const struct rte_security_capability *ret;
2090 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2091 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2093 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2095 return TEST_SUCCESS;
2099 * Test execution of rte_security_capability_get when capabilities table
2100 * does not contain entry with matching ipsec direction field
2103 test_capability_get_ipsec_mismatch_dir(void)
2105 struct security_unittest_params *ut_params = &unittest_params;
2106 struct rte_security_capability_idx idx = {
2107 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2108 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2110 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2111 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
2112 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
2115 struct rte_security_capability capabilities[] = {
2117 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2118 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2120 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2121 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
2122 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
2126 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2130 mock_capabilities_get_exp.device = NULL;
2131 mock_capabilities_get_exp.ret = capabilities;
2133 const struct rte_security_capability *ret;
2134 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2135 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2137 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2139 return TEST_SUCCESS;
2143 * Test execution of rte_security_capability_get when capabilities table
2144 * contains matching ipsec entry
2147 test_capability_get_ipsec_match(void)
2149 struct security_unittest_params *ut_params = &unittest_params;
2150 struct rte_security_capability_idx idx = {
2151 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2152 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2154 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2155 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
2156 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
2159 struct rte_security_capability capabilities[] = {
2161 .action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
2164 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2165 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2167 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2168 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
2169 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
2173 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2177 mock_capabilities_get_exp.device = NULL;
2178 mock_capabilities_get_exp.ret = capabilities;
2180 const struct rte_security_capability *ret;
2181 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2182 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2183 ret, &capabilities[1], "%p");
2184 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2186 return TEST_SUCCESS;
2190 * Test execution of rte_security_capability_get when capabilities table
2191 * does not contain entry with matching pdcp domain field
2194 test_capability_get_pdcp_mismatch_domain(void)
2196 struct security_unittest_params *ut_params = &unittest_params;
2197 struct rte_security_capability_idx idx = {
2198 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2199 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
2201 .domain = RTE_SECURITY_PDCP_MODE_CONTROL,
2204 struct rte_security_capability capabilities[] = {
2206 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2207 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
2209 .domain = RTE_SECURITY_PDCP_MODE_DATA,
2213 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2217 mock_capabilities_get_exp.device = NULL;
2218 mock_capabilities_get_exp.ret = capabilities;
2220 const struct rte_security_capability *ret;
2221 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2222 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2224 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2226 return TEST_SUCCESS;
2230 * Test execution of rte_security_capability_get when capabilities table
2231 * contains matching pdcp entry
2234 test_capability_get_pdcp_match(void)
2236 struct security_unittest_params *ut_params = &unittest_params;
2237 struct rte_security_capability_idx idx = {
2238 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2239 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
2241 .domain = RTE_SECURITY_PDCP_MODE_CONTROL,
2244 struct rte_security_capability capabilities[] = {
2246 .action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
2249 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2250 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
2252 .domain = RTE_SECURITY_PDCP_MODE_CONTROL,
2256 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2260 mock_capabilities_get_exp.device = NULL;
2261 mock_capabilities_get_exp.ret = capabilities;
2263 const struct rte_security_capability *ret;
2264 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2265 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2266 ret, &capabilities[1], "%p");
2267 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2269 return TEST_SUCCESS;
2273 * Test execution of rte_security_capability_get when capabilities table
2274 * does not contain entry with matching DOCSIS direction field
2277 test_capability_get_docsis_mismatch_direction(void)
2279 struct security_unittest_params *ut_params = &unittest_params;
2280 struct rte_security_capability_idx idx = {
2281 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2282 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
2284 .direction = RTE_SECURITY_DOCSIS_DOWNLINK
2287 struct rte_security_capability capabilities[] = {
2289 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2290 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
2292 .direction = RTE_SECURITY_DOCSIS_UPLINK
2296 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2300 mock_capabilities_get_exp.device = NULL;
2301 mock_capabilities_get_exp.ret = capabilities;
2303 const struct rte_security_capability *ret;
2304 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2305 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2307 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2309 return TEST_SUCCESS;
2313 * Test execution of rte_security_capability_get when capabilities table
2314 * contains matching DOCSIS entry
2317 test_capability_get_docsis_match(void)
2319 struct security_unittest_params *ut_params = &unittest_params;
2320 struct rte_security_capability_idx idx = {
2321 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2322 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
2324 .direction = RTE_SECURITY_DOCSIS_UPLINK
2327 struct rte_security_capability capabilities[] = {
2329 .action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
2332 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2333 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
2335 .direction = RTE_SECURITY_DOCSIS_UPLINK
2339 .action = RTE_SECURITY_ACTION_TYPE_NONE,
2343 mock_capabilities_get_exp.device = NULL;
2344 mock_capabilities_get_exp.ret = capabilities;
2346 const struct rte_security_capability *ret;
2347 ret = rte_security_capability_get(&ut_params->ctx, &idx);
2348 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2349 ret, &capabilities[1], "%p");
2350 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2352 return TEST_SUCCESS;
2356 * Declaration of testcases
2358 static struct unit_test_suite security_testsuite = {
2359 .suite_name = "generic security",
2360 .setup = testsuite_setup,
2361 .teardown = testsuite_teardown,
2362 .unit_test_cases = {
2363 TEST_CASE_ST(ut_setup, ut_teardown,
2364 test_session_create_inv_context),
2365 TEST_CASE_ST(ut_setup, ut_teardown,
2366 test_session_create_inv_context_ops),
2367 TEST_CASE_ST(ut_setup, ut_teardown,
2368 test_session_create_inv_context_ops_fun),
2369 TEST_CASE_ST(ut_setup, ut_teardown,
2370 test_session_create_inv_configuration),
2371 TEST_CASE_ST(ut_setup, ut_teardown,
2372 test_session_create_inv_mempool),
2373 TEST_CASE_ST(ut_setup, ut_teardown,
2374 test_session_create_mempool_empty),
2375 TEST_CASE_ST(ut_setup, ut_teardown,
2376 test_session_create_ops_failure),
2377 TEST_CASE_ST(ut_setup, ut_teardown,
2378 test_session_create_success),
2380 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2381 test_session_update_inv_context),
2382 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2383 test_session_update_inv_context_ops),
2384 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2385 test_session_update_inv_context_ops_fun),
2386 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2387 test_session_update_inv_configuration),
2388 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2389 test_session_update_inv_session),
2390 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2391 test_session_update_ops_failure),
2392 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2393 test_session_update_success),
2395 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2396 test_session_get_size_inv_context),
2397 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2398 test_session_get_size_inv_context_ops),
2399 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2400 test_session_get_size_inv_context_ops_fun),
2401 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2402 test_session_get_size_ops_failure),
2403 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2404 test_session_get_size_success),
2406 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2407 test_session_stats_get_inv_context),
2408 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2409 test_session_stats_get_inv_context_ops),
2410 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2411 test_session_stats_get_inv_context_ops_fun),
2412 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2413 test_session_stats_get_inv_stats),
2414 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2415 test_session_stats_get_ops_failure),
2416 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2417 test_session_stats_get_success),
2419 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2420 test_session_destroy_inv_context),
2421 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2422 test_session_destroy_inv_context_ops),
2423 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2424 test_session_destroy_inv_context_ops_fun),
2425 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2426 test_session_destroy_inv_session),
2427 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2428 test_session_destroy_ops_failure),
2429 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2430 test_session_destroy_success),
2432 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2433 test_set_pkt_metadata_inv_context),
2434 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2435 test_set_pkt_metadata_inv_context_ops),
2436 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2437 test_set_pkt_metadata_inv_context_ops_fun),
2438 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2439 test_set_pkt_metadata_inv_session),
2440 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2441 test_set_pkt_metadata_ops_failure),
2442 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2443 test_set_pkt_metadata_success),
2445 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2446 test_get_userdata_inv_context),
2447 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2448 test_get_userdata_inv_context_ops),
2449 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2450 test_get_userdata_inv_context_ops_fun),
2451 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2452 test_get_userdata_ops_failure),
2453 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2454 test_get_userdata_success),
2456 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2457 test_capabilities_get_inv_context),
2458 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2459 test_capabilities_get_inv_context_ops),
2460 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2461 test_capabilities_get_inv_context_ops_fun),
2462 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2463 test_capabilities_get_ops_failure),
2464 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2465 test_capabilities_get_success),
2467 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2468 test_capability_get_inv_context),
2469 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2470 test_capability_get_inv_context_ops),
2471 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2472 test_capability_get_inv_context_ops_fun),
2473 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2474 test_capability_get_inv_idx),
2475 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2476 test_capability_get_ops_failure),
2477 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2478 test_capability_get_empty_table),
2479 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2480 test_capability_get_no_matching_action),
2481 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2482 test_capability_get_no_matching_protocol),
2483 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2484 test_capability_get_no_support_for_macsec),
2485 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2486 test_capability_get_ipsec_mismatch_proto),
2487 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2488 test_capability_get_ipsec_mismatch_mode),
2489 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2490 test_capability_get_ipsec_mismatch_dir),
2491 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2492 test_capability_get_ipsec_match),
2493 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2494 test_capability_get_pdcp_mismatch_domain),
2495 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2496 test_capability_get_pdcp_match),
2497 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2498 test_capability_get_docsis_mismatch_direction),
2499 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2500 test_capability_get_docsis_match),
2502 TEST_CASES_END() /**< NULL terminate unit test array */
2509 rte_log_set_global_level(RTE_LOG_DEBUG);
2510 rte_log_set_level(RTE_LOGTYPE_EAL, RTE_LOG_DEBUG);
2512 return unit_test_suite_runner(&security_testsuite);
2515 REGISTER_TEST_COMMAND(security_autotest, test_security);