1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
7 #include <rte_memory.h>
8 #include <rte_mempool.h>
9 #include <rte_security.h>
10 #include <rte_security_driver.h>
12 /* Before including rte_test.h file you can define
13 * RTE_TEST_TRACE_FAILURE(_file, _line, _func) macro to better trace/debug test
14 * failures. Mostly useful in development phase.
16 #ifndef RTE_TEST_TRACE_FAILURE
17 #define RTE_TEST_TRACE_FAILURE(_file, _line, _func) \
18 RTE_LOG(DEBUG, EAL, "in %s:%d %s\n", _file, _line, _func)
28 * Basic unit tests of the librte_security API.
30 * Structure of the file:
31 * - macros for making tests more readable;
32 * - mockup structures and functions for rte_security_ops;
33 * - test suite and test cases setup and teardown functions;
35 * - declaration of testcases.
42 * Set of macros for making tests easier to read.
46 * Verify condition inside mocked up function.
47 * Mockup function cannot return a test error, so the failure
48 * of assertion increases counter and print logs.
49 * The counter can be verified later to check if test case should fail.
51 * @param fail_counter fail counter
52 * @param cond condition expected to be true
53 * @param msg printf style formatting string for custom message
55 #define MOCK_TEST_ASSERT(fail_counter, cond, msg, ...) do { \
58 RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: " \
59 msg "\n", __func__, __LINE__, \
61 RTE_TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__); \
66 * Verify equality condition inside mocked up function.
67 * Mockup function cannot return a test error, so the failure
68 * of assertion increases counter and print logs.
69 * The counter can be verified later to check if test case should fail.
71 * @param fail_counter fail counter
72 * @param a first value of comparison
73 * @param b second value of comparison
74 * @param msg printf style formatting string for custom message
76 #define MOCK_TEST_ASSERT_EQUAL(fail_counter, a, b, msg, ...) \
77 MOCK_TEST_ASSERT(fail_counter, (a) == (b), msg, ##__VA_ARGS__)
80 * Verify not null condition inside mocked up function.
81 * Mockup function cannot return a test error, so the failure
82 * of assertion increases counter and print logs.
83 * The counter can be verified later to check if test case should fail.
85 * @param fail_counter fail counter
86 * @param val value expected not to be NULL
87 * @param msg printf style formatting string for custom message
89 #define MOCK_TEST_ASSERT_NOT_NULL(fail_counter, val, msg, ...) \
90 MOCK_TEST_ASSERT(fail_counter, (val) != NULL, msg, ##__VA_ARGS__)
94 * Verify if parameter of the mocked up function matches expected value.
95 * The expected value is stored in data structure in the field matching
98 * @param data structure with expected values
99 * @param parameter name of the parameter (both field and parameter name)
100 * @param spec printf style spec for parameter
102 #define MOCK_TEST_ASSERT_PARAMETER(data, parameter, spec) \
103 MOCK_TEST_ASSERT_EQUAL(data.failed, data.parameter, parameter, \
104 "Expecting parameter %s to be " spec \
105 " but it's " spec, RTE_STR(parameter), \
106 data.parameter, parameter)
109 * Wrap for MOCK_TEST_ASSERT_PARAMETER macro for pointer type parameters.
111 * @param data structure with expected values
112 * @param parameter name of the parameter (both field and parameter name)
114 #define MOCK_TEST_ASSERT_POINTER_PARAMETER(data, parameter) \
115 MOCK_TEST_ASSERT_PARAMETER(data, parameter, "%p")
118 * Wrap for MOCK_TEST_ASSERT_PARAMETER macro for uint64_t type parameters.
120 * @param data structure with expected values
121 * @param parameter name of the parameter (both field and parameter name)
123 #define MOCK_TEST_ASSERT_U64_PARAMETER(data, parameter) \
124 MOCK_TEST_ASSERT_PARAMETER(data, parameter, "%" PRIu64)
127 * Verify number of calls of the mocked up function
128 * and check if there were any fails during execution.
129 * The fails statistics inside mocked up functions are collected
130 * as "failed" field in mockup structures.
132 * @param mock_data structure with statistics (called, failed)
133 * @param exp_calls expected number of mockup function calls
135 #define TEST_ASSERT_MOCK_CALLS(mock_data, exp_calls) do { \
136 TEST_ASSERT_EQUAL(exp_calls, mock_data.called, \
137 "Expecting sub op to be called %d times, " \
138 "but it's called %d times", \
139 exp_calls, mock_data.called); \
140 TEST_ASSERT_EQUAL(0, mock_data.failed, \
141 "Expecting sub op asserts not to fail, " \
142 "but they're failed %d times", \
147 * Assert tested function result match expected value
149 * @param f_name name of tested function
150 * @param f_ret value returned by the function
151 * @param exp_ret expected returned value
152 * @param fmt printf style format for returned value
154 #define TEST_ASSERT_MOCK_FUNCTION_CALL_RET(f_name, f_ret, exp_ret, fmt) \
155 TEST_ASSERT_EQUAL(exp_ret, f_ret, "Expecting " RTE_STR(f_name) \
156 " to return " fmt ", but it returned " fmt \
157 "\n", exp_ret, f_ret)
160 * Assert tested function result is not NULL
162 * @param f_name name of tested function
163 * @param f_ret value returned by the function
165 #define TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(f_name, f_ret) \
166 TEST_ASSERT_NOT_NULL(f_ret, "Expecting " RTE_STR(f_name) \
167 " to return not NULL\n")
170 * Verify that sess_cnt counter value matches expected
172 * @param expected_sessions_count expected counter value
174 #define TEST_ASSERT_SESSION_COUNT(expected_sessions_count) do { \
175 struct security_unittest_params *ut_params = &unittest_params; \
176 TEST_ASSERT_EQUAL(expected_sessions_count, \
177 ut_params->ctx.sess_cnt, \
178 "Expecting session counter to be %u," \
179 " but it's %u", expected_sessions_count, \
180 ut_params->ctx.sess_cnt); \
184 * Verify usage of mempool by checking if number of allocated objects matches
185 * expectations. The mempool is used to manage objects for sessions data.
186 * A single object is acquired from mempool during session_create
187 * and put back in session_destroy.
189 * @param expected_mempool_usage expected number of used mempool objects
191 #define TEST_ASSERT_MEMPOOL_USAGE(expected_mempool_usage) do { \
192 struct security_testsuite_params *ts_params = &testsuite_params;\
193 unsigned int mempool_usage; \
194 mempool_usage = rte_mempool_in_use_count( \
195 ts_params->session_mpool); \
196 TEST_ASSERT_EQUAL(expected_mempool_usage, mempool_usage, \
197 "Expecting %u mempool allocations, " \
198 "but there are %u allocated objects", \
199 expected_mempool_usage, mempool_usage); \
204 * Mockup structures and functions for rte_security_ops;
206 * Set of structures for controlling mockup functions calls.
207 * Every mockup function X has its corresponding X_data structure
208 * and an instance of that structure X_exp.
209 * Structure contains parameters that a mockup function is expected
210 * to be called with, a value to return (.ret) and 2 statistics:
211 * .called (number of times the mockup function was called)
212 * and .failed (number of assertion fails during mockup function call).
214 * Mockup functions verify that the parameters they are called with match
215 * expected values. The expected values should be stored in corresponding
216 * structures prior to mockup functions call. Every failure of such
217 * verification increases .failed counter. Every call of mockup function
218 * increases .called counter. Function returns value stored in .ret field
220 * In case of some parameters in some functions the expected value is unknown
221 * and cannot be detrmined prior to call. Such parameters are stored
222 * in structure and can be compared or analyzed later in test case code.
224 * Below structures and functions follow the rules just described.
225 * Additional remarks and exceptions are added in comments.
229 * session_create mockup
231 * Verified parameters: device, conf, mp.
232 * Saved, not verified parameters: sess.
234 static struct mock_session_create_data {
236 struct rte_security_session_conf *conf;
237 struct rte_security_session *sess;
238 struct rte_mempool *mp;
244 } mock_session_create_exp = {NULL, NULL, NULL, NULL, 0, 0, 0};
247 mock_session_create(void *device,
248 struct rte_security_session_conf *conf,
249 struct rte_security_session *sess,
250 struct rte_mempool *mp)
252 mock_session_create_exp.called++;
254 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, device);
255 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, conf);
256 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, mp);
258 mock_session_create_exp.sess = sess;
260 return mock_session_create_exp.ret;
264 * session_update mockup
266 * Verified parameters: device, sess, conf.
268 static struct mock_session_update_data {
270 struct rte_security_session *sess;
271 struct rte_security_session_conf *conf;
277 } mock_session_update_exp = {NULL, NULL, NULL, 0, 0, 0};
280 mock_session_update(void *device,
281 struct rte_security_session *sess,
282 struct rte_security_session_conf *conf)
284 mock_session_update_exp.called++;
286 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, device);
287 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, sess);
288 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, conf);
290 return mock_session_update_exp.ret;
294 * session_get_size mockup
296 * Verified parameters: device.
298 static struct mock_session_get_size_data {
305 } mock_session_get_size_exp = {NULL, 0U, 0, 0};
308 mock_session_get_size(void *device)
310 mock_session_get_size_exp.called++;
312 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_get_size_exp, device);
314 return mock_session_get_size_exp.ret;
318 * session_stats_get mockup
320 * Verified parameters: device, sess, stats.
322 static struct mock_session_stats_get_data {
324 struct rte_security_session *sess;
325 struct rte_security_stats *stats;
331 } mock_session_stats_get_exp = {NULL, NULL, NULL, 0, 0, 0};
334 mock_session_stats_get(void *device,
335 struct rte_security_session *sess,
336 struct rte_security_stats *stats)
338 mock_session_stats_get_exp.called++;
340 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_stats_get_exp, device);
341 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_stats_get_exp, sess);
342 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_stats_get_exp, stats);
344 return mock_session_stats_get_exp.ret;
348 * session_destroy mockup
350 * Verified parameters: device, sess.
352 static struct mock_session_destroy_data {
354 struct rte_security_session *sess;
360 } mock_session_destroy_exp = {NULL, NULL, 0, 0, 0};
363 mock_session_destroy(void *device, struct rte_security_session *sess)
365 mock_session_destroy_exp.called++;
367 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_destroy_exp, device);
368 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_destroy_exp, sess);
370 return mock_session_destroy_exp.ret;
374 * set_pkt_metadata mockup
376 * Verified parameters: device, sess, m, params.
378 static struct mock_set_pkt_metadata_data {
380 struct rte_security_session *sess;
388 } mock_set_pkt_metadata_exp = {NULL, NULL, NULL, NULL, 0, 0, 0};
391 mock_set_pkt_metadata(void *device,
392 struct rte_security_session *sess,
396 mock_set_pkt_metadata_exp.called++;
398 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, device);
399 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, sess);
400 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, m);
401 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, params);
403 return mock_set_pkt_metadata_exp.ret;
407 * get_userdata mockup
409 * Verified parameters: device, md.
410 * The userdata parameter works as an output parameter, so a passed address
411 * is verified not to be NULL and filled with userdata stored in structure.
413 static struct mock_get_userdata_data {
422 } mock_get_userdata_exp = {NULL, 0UL, NULL, 0, 0, 0};
425 mock_get_userdata(void *device,
429 mock_get_userdata_exp.called++;
431 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_get_userdata_exp, device);
432 MOCK_TEST_ASSERT_U64_PARAMETER(mock_get_userdata_exp, md);
434 MOCK_TEST_ASSERT_NOT_NULL(mock_get_userdata_exp.failed,
436 "Expecting parameter userdata not to be NULL but it's %p",
438 *userdata = mock_get_userdata_exp.userdata;
440 return mock_get_userdata_exp.ret;
444 * capabilities_get mockup
446 * Verified parameters: device.
448 static struct mock_capabilities_get_data {
451 struct rte_security_capability *ret;
455 } mock_capabilities_get_exp = {NULL, NULL, 0, 0};
457 static const struct rte_security_capability *
458 mock_capabilities_get(void *device)
460 mock_capabilities_get_exp.called++;
462 MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_capabilities_get_exp, device);
464 return mock_capabilities_get_exp.ret;
470 * is an empty security operations set (all function pointers set to NULL)
472 struct rte_security_ops empty_ops = { NULL };
477 * is a security operations set using mockup functions
479 struct rte_security_ops mock_ops = {
480 .session_create = mock_session_create,
481 .session_update = mock_session_update,
482 .session_get_size = mock_session_get_size,
483 .session_stats_get = mock_session_stats_get,
484 .session_destroy = mock_session_destroy,
485 .set_pkt_metadata = mock_set_pkt_metadata,
486 .get_userdata = mock_get_userdata,
487 .capabilities_get = mock_capabilities_get,
492 * Test suite and test cases setup and teardown functions.
496 * struct security_testsuite_params defines parameters initialized once
497 * for whole tests suite.
498 * Currently the only stored parameter is session_mpool a mempool created
499 * once in testsuite_setup and released in testsuite_teardown.
500 * The instance of this structure is stored in testsuite_params variable.
502 static struct security_testsuite_params {
503 struct rte_mempool *session_mpool;
504 } testsuite_params = { NULL };
507 * struct security_unittest_params defines parameters initialized
508 * for every test case. The parameters are initialized in ut_setup
509 * or ut_setup_with_session (depending on the testcase)
510 * and released in ut_teardown.
511 * The instance of this structure is stored in unittest_params variable.
513 static struct security_unittest_params {
514 struct rte_security_ctx ctx;
515 struct rte_security_session_conf conf;
516 struct rte_security_session *sess;
517 } unittest_params = {
526 #define SECURITY_TEST_MEMPOOL_NAME "SecurityTestsMempoolName"
527 #define SECURITY_TEST_MEMPOOL_SIZE 15
528 #define SECURITY_TEST_SESSION_OBJECT_SIZE sizeof(struct rte_security_session)
531 * testsuite_setup initializes whole test suite parameters.
532 * It creates a new mempool used in all test cases
533 * and verifies if it properly created.
536 testsuite_setup(void)
538 struct security_testsuite_params *ts_params = &testsuite_params;
539 ts_params->session_mpool = rte_mempool_create(
540 SECURITY_TEST_MEMPOOL_NAME,
541 SECURITY_TEST_MEMPOOL_SIZE,
542 SECURITY_TEST_SESSION_OBJECT_SIZE,
543 0, 0, NULL, NULL, NULL, NULL,
545 TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
546 "Cannot create mempool %s\n", rte_strerror(rte_errno));
551 * testsuite_teardown releases test suite wide parameters.
554 testsuite_teardown(void)
556 struct security_testsuite_params *ts_params = &testsuite_params;
557 if (ts_params->session_mpool) {
558 rte_mempool_free(ts_params->session_mpool);
559 ts_params->session_mpool = NULL;
564 * ut_setup initializes test case parameters to default values.
565 * It resets also any .called and .failed statistics of mockup functions
571 struct security_unittest_params *ut_params = &unittest_params;
572 ut_params->ctx.device = NULL;
573 ut_params->ctx.ops = &mock_ops;
574 ut_params->ctx.sess_cnt = 0;
575 ut_params->sess = NULL;
577 mock_session_create_exp.called = 0;
578 mock_session_update_exp.called = 0;
579 mock_session_get_size_exp.called = 0;
580 mock_session_stats_get_exp.called = 0;
581 mock_session_destroy_exp.called = 0;
582 mock_set_pkt_metadata_exp.called = 0;
583 mock_get_userdata_exp.called = 0;
584 mock_capabilities_get_exp.called = 0;
586 mock_session_create_exp.failed = 0;
587 mock_session_update_exp.failed = 0;
588 mock_session_get_size_exp.failed = 0;
589 mock_session_stats_get_exp.failed = 0;
590 mock_session_destroy_exp.failed = 0;
591 mock_set_pkt_metadata_exp.failed = 0;
592 mock_get_userdata_exp.failed = 0;
593 mock_capabilities_get_exp.failed = 0;
599 * destroy_session_with_check is a helper function releasing session
600 * created with rte_security_session_create and stored in test case parameters.
601 * It's used both to release sessions created in test cases' bodies
602 * which are assigned to ut_params->sess
603 * as well as sessions created in ut_setup_with_session.
606 destroy_session_with_check(void)
608 struct security_unittest_params *ut_params = &unittest_params;
609 if (ut_params->sess != NULL) {
610 /* Assure that mockup function for destroy operation is set. */
611 ut_params->ctx.ops = &mock_ops;
613 mock_session_destroy_exp.device = NULL;
614 mock_session_destroy_exp.sess = ut_params->sess;
615 mock_session_destroy_exp.ret = 0;
616 mock_session_destroy_exp.called = 0;
617 mock_session_destroy_exp.failed = 0;
619 int ret = rte_security_session_destroy(&ut_params->ctx,
621 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
623 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
625 ut_params->sess = NULL;
631 * ut_teardown releases test case parameters.
636 destroy_session_with_check();
640 * ut_setup_with_session initializes test case parameters by
641 * - calling standard ut_setup,
642 * - creating a session that can be used in test case.
645 ut_setup_with_session(void)
647 struct security_unittest_params *ut_params = &unittest_params;
648 struct security_testsuite_params *ts_params = &testsuite_params;
649 struct rte_security_session *sess;
651 int ret = ut_setup();
652 if (ret != TEST_SUCCESS)
655 mock_session_create_exp.device = NULL;
656 mock_session_create_exp.conf = &ut_params->conf;
657 mock_session_create_exp.mp = ts_params->session_mpool;
658 mock_session_create_exp.ret = 0;
660 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
661 ts_params->session_mpool);
662 TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(rte_security_session_create,
664 TEST_ASSERT_EQUAL(sess, mock_session_create_exp.sess,
665 "Expecting session_create to be called with %p sess"
666 " parameter, but it's called %p sess parameter",
667 sess, mock_session_create_exp.sess);
668 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
671 * Store created session in test case parameters, so it can be released
672 * after test case in ut_teardown by destroy_session_with_check.
674 ut_params->sess = sess;
683 * Each test function is related to a single test case.
684 * They are arranged by tested rte_security API function
685 * and by rte_security execution paths sequence in code.
689 * rte_security_session_create tests
693 * Test execution of rte_security_session_create with NULL instance
696 test_session_create_inv_context(void)
698 struct security_testsuite_params *ts_params = &testsuite_params;
699 struct security_unittest_params *ut_params = &unittest_params;
700 struct rte_security_session *sess;
702 sess = rte_security_session_create(NULL, &ut_params->conf,
703 ts_params->session_mpool);
704 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
706 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
707 TEST_ASSERT_MEMPOOL_USAGE(0);
708 TEST_ASSERT_SESSION_COUNT(0);
714 * Test execution of rte_security_session_create with invalid
715 * security operations structure (NULL)
718 test_session_create_inv_context_ops(void)
720 struct security_testsuite_params *ts_params = &testsuite_params;
721 struct security_unittest_params *ut_params = &unittest_params;
722 struct rte_security_session *sess;
724 ut_params->ctx.ops = NULL;
726 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
727 ts_params->session_mpool);
728 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
730 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
731 TEST_ASSERT_MEMPOOL_USAGE(0);
732 TEST_ASSERT_SESSION_COUNT(0);
738 * Test execution of rte_security_session_create with empty
739 * security operations
742 test_session_create_inv_context_ops_fun(void)
744 struct security_testsuite_params *ts_params = &testsuite_params;
745 struct security_unittest_params *ut_params = &unittest_params;
746 struct rte_security_session *sess;
748 ut_params->ctx.ops = &empty_ops;
750 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
751 ts_params->session_mpool);
752 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
754 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
755 TEST_ASSERT_MEMPOOL_USAGE(0);
756 TEST_ASSERT_SESSION_COUNT(0);
762 * Test execution of rte_security_session_create with NULL conf parameter
765 test_session_create_inv_configuration(void)
767 struct security_testsuite_params *ts_params = &testsuite_params;
768 struct security_unittest_params *ut_params = &unittest_params;
769 struct rte_security_session *sess;
771 sess = rte_security_session_create(&ut_params->ctx, NULL,
772 ts_params->session_mpool);
773 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
775 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
776 TEST_ASSERT_MEMPOOL_USAGE(0);
777 TEST_ASSERT_SESSION_COUNT(0);
783 * Test execution of rte_security_session_create with NULL mp parameter
786 test_session_create_inv_mempool(void)
788 struct security_unittest_params *ut_params = &unittest_params;
789 struct rte_security_session *sess;
791 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
793 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
795 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
796 TEST_ASSERT_MEMPOOL_USAGE(0);
797 TEST_ASSERT_SESSION_COUNT(0);
803 * Test execution of rte_security_session_create in case when mempool
804 * is fully used and no object can be got from it
807 test_session_create_mempool_empty(void)
809 struct security_testsuite_params *ts_params = &testsuite_params;
810 struct security_unittest_params *ut_params = &unittest_params;
811 struct rte_security_session *tmp[SECURITY_TEST_MEMPOOL_SIZE];
812 struct rte_security_session *sess;
814 /* Get all available objects from mempool. */
816 for (i = 0; i < SECURITY_TEST_MEMPOOL_SIZE; ++i) {
817 ret = rte_mempool_get(ts_params->session_mpool,
819 TEST_ASSERT_EQUAL(0, ret,
820 "Expect getting %d object from mempool"
823 TEST_ASSERT_MEMPOOL_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
825 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
826 ts_params->session_mpool);
827 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
829 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
830 TEST_ASSERT_MEMPOOL_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
831 TEST_ASSERT_SESSION_COUNT(0);
833 /* Put objects back to the pool. */
834 for (i = 0; i < SECURITY_TEST_MEMPOOL_SIZE; ++i)
835 rte_mempool_put(ts_params->session_mpool, (void *)(tmp[i]));
836 TEST_ASSERT_MEMPOOL_USAGE(0);
842 * Test execution of rte_security_session_create when session_create
843 * security operation fails
846 test_session_create_ops_failure(void)
848 struct security_testsuite_params *ts_params = &testsuite_params;
849 struct security_unittest_params *ut_params = &unittest_params;
850 struct rte_security_session *sess;
852 mock_session_create_exp.device = NULL;
853 mock_session_create_exp.conf = &ut_params->conf;
854 mock_session_create_exp.mp = ts_params->session_mpool;
855 mock_session_create_exp.ret = -1; /* Return failure status. */
857 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
858 ts_params->session_mpool);
859 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
861 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
862 TEST_ASSERT_MEMPOOL_USAGE(0);
863 TEST_ASSERT_SESSION_COUNT(0);
869 * Test execution of rte_security_session_create in successful execution path
872 test_session_create_success(void)
874 struct security_testsuite_params *ts_params = &testsuite_params;
875 struct security_unittest_params *ut_params = &unittest_params;
876 struct rte_security_session *sess;
878 mock_session_create_exp.device = NULL;
879 mock_session_create_exp.conf = &ut_params->conf;
880 mock_session_create_exp.mp = ts_params->session_mpool;
881 mock_session_create_exp.ret = 0; /* Return success status. */
883 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
884 ts_params->session_mpool);
885 TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(rte_security_session_create,
887 TEST_ASSERT_EQUAL(sess, mock_session_create_exp.sess,
888 "Expecting session_create to be called with %p sess"
889 " parameter, but it's called %p sess parameter",
890 sess, mock_session_create_exp.sess);
891 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
892 TEST_ASSERT_MEMPOOL_USAGE(1);
893 TEST_ASSERT_SESSION_COUNT(1);
896 * Store created session in test case parameters, so it can be released
897 * after test case in ut_teardown by destroy_session_with_check.
899 ut_params->sess = sess;
906 * rte_security_session_update tests
910 * Test execution of rte_security_session_update with NULL instance
913 test_session_update_inv_context(void)
915 struct security_unittest_params *ut_params = &unittest_params;
917 int ret = rte_security_session_update(NULL, ut_params->sess,
919 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
921 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
927 * Test execution of rte_security_session_update with invalid
928 * security operations structure (NULL)
931 test_session_update_inv_context_ops(void)
933 struct security_unittest_params *ut_params = &unittest_params;
934 ut_params->ctx.ops = NULL;
936 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
938 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
940 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
946 * Test execution of rte_security_session_update with empty
947 * security operations
950 test_session_update_inv_context_ops_fun(void)
952 struct security_unittest_params *ut_params = &unittest_params;
953 ut_params->ctx.ops = &empty_ops;
955 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
957 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
958 ret, -ENOTSUP, "%d");
959 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
965 * Test execution of rte_security_session_update with NULL conf parameter
968 test_session_update_inv_configuration(void)
970 struct security_unittest_params *ut_params = &unittest_params;
972 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
974 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
976 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
982 * Test execution of rte_security_session_update with NULL sess parameter
985 test_session_update_inv_session(void)
987 struct security_unittest_params *ut_params = &unittest_params;
989 int ret = rte_security_session_update(&ut_params->ctx, NULL,
991 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
993 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
999 * Test execution of rte_security_session_update when session_update
1000 * security operation fails
1003 test_session_update_ops_failure(void)
1005 struct security_unittest_params *ut_params = &unittest_params;
1007 mock_session_update_exp.device = NULL;
1008 mock_session_update_exp.sess = ut_params->sess;
1009 mock_session_update_exp.conf = &ut_params->conf;
1010 mock_session_update_exp.ret = -1; /* Return failure status. */
1012 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
1014 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1016 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 1);
1018 return TEST_SUCCESS;
1022 * Test execution of rte_security_session_update in successful execution path
1025 test_session_update_success(void)
1027 struct security_unittest_params *ut_params = &unittest_params;
1029 mock_session_update_exp.device = NULL;
1030 mock_session_update_exp.sess = ut_params->sess;
1031 mock_session_update_exp.conf = &ut_params->conf;
1032 mock_session_update_exp.ret = 0; /* Return success status. */
1034 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
1036 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1038 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 1);
1040 return TEST_SUCCESS;
1045 * rte_security_session_get_size tests
1049 * Test execution of rte_security_session_get_size with NULL instance
1052 test_session_get_size_inv_context(void)
1054 unsigned int ret = rte_security_session_get_size(NULL);
1055 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1057 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
1059 return TEST_SUCCESS;
1063 * Test execution of rte_security_session_get_size with invalid
1064 * security operations structure (NULL)
1067 test_session_get_size_inv_context_ops(void)
1069 struct security_unittest_params *ut_params = &unittest_params;
1070 ut_params->ctx.ops = NULL;
1072 unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1073 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1075 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
1077 return TEST_SUCCESS;
1081 * Test execution of rte_security_session_get_size with empty
1082 * security operations
1085 test_session_get_size_inv_context_ops_fun(void)
1087 struct security_unittest_params *ut_params = &unittest_params;
1088 ut_params->ctx.ops = &empty_ops;
1090 unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1091 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1093 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
1095 return TEST_SUCCESS;
1099 * Test execution of rte_security_session_get_size when session_get_size
1100 * security operation fails
1103 test_session_get_size_ops_failure(void)
1105 struct security_unittest_params *ut_params = &unittest_params;
1107 mock_session_get_size_exp.device = NULL;
1108 mock_session_get_size_exp.ret = 0;
1110 unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1111 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1113 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 1);
1115 return TEST_SUCCESS;
1119 * Test execution of rte_security_session_get_size in successful execution path
1122 test_session_get_size_success(void)
1124 struct security_unittest_params *ut_params = &unittest_params;
1126 mock_session_get_size_exp.device = NULL;
1127 mock_session_get_size_exp.ret = 1024;
1129 unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1130 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1132 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 1);
1134 return TEST_SUCCESS;
1139 * rte_security_session_stats_get tests
1143 * Test execution of rte_security_session_stats_get with NULL instance
1146 test_session_stats_get_inv_context(void)
1148 struct security_unittest_params *ut_params = &unittest_params;
1149 struct rte_security_stats stats;
1151 int ret = rte_security_session_stats_get(NULL, ut_params->sess, &stats);
1152 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1153 ret, -EINVAL, "%d");
1154 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1156 return TEST_SUCCESS;
1160 * Test execution of rte_security_session_stats_get with invalid
1161 * security operations structure (NULL)
1164 test_session_stats_get_inv_context_ops(void)
1166 struct security_unittest_params *ut_params = &unittest_params;
1167 struct rte_security_stats stats;
1168 ut_params->ctx.ops = NULL;
1170 int ret = rte_security_session_stats_get(&ut_params->ctx,
1171 ut_params->sess, &stats);
1172 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1173 ret, -EINVAL, "%d");
1174 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1176 return TEST_SUCCESS;
1180 * Test execution of rte_security_session_stats_get with empty
1181 * security operations
1184 test_session_stats_get_inv_context_ops_fun(void)
1186 struct security_unittest_params *ut_params = &unittest_params;
1187 struct rte_security_stats stats;
1188 ut_params->ctx.ops = &empty_ops;
1190 int ret = rte_security_session_stats_get(&ut_params->ctx,
1191 ut_params->sess, &stats);
1192 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1193 ret, -ENOTSUP, "%d");
1194 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1196 return TEST_SUCCESS;
1200 * Test execution of rte_security_session_stats_get with NULL stats parameter
1203 test_session_stats_get_inv_stats(void)
1205 struct security_unittest_params *ut_params = &unittest_params;
1207 int ret = rte_security_session_stats_get(&ut_params->ctx,
1208 ut_params->sess, NULL);
1209 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1210 ret, -EINVAL, "%d");
1211 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1213 return TEST_SUCCESS;
1217 * Test execution of rte_security_session_stats_get when session_stats_get
1218 * security operation fails
1221 test_session_stats_get_ops_failure(void)
1223 struct security_unittest_params *ut_params = &unittest_params;
1224 struct rte_security_stats stats;
1226 mock_session_stats_get_exp.device = NULL;
1227 mock_session_stats_get_exp.sess = ut_params->sess;
1228 mock_session_stats_get_exp.stats = &stats;
1229 mock_session_stats_get_exp.ret = -1;
1231 int ret = rte_security_session_stats_get(&ut_params->ctx,
1232 ut_params->sess, &stats);
1233 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1235 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 1);
1237 return TEST_SUCCESS;
1241 * Test execution of rte_security_session_stats_get in successful execution
1245 test_session_stats_get_success(void)
1247 struct security_unittest_params *ut_params = &unittest_params;
1248 struct rte_security_stats stats;
1250 mock_session_stats_get_exp.device = NULL;
1251 mock_session_stats_get_exp.sess = ut_params->sess;
1252 mock_session_stats_get_exp.stats = &stats;
1253 mock_session_stats_get_exp.ret = 0;
1255 int ret = rte_security_session_stats_get(&ut_params->ctx,
1256 ut_params->sess, &stats);
1257 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1259 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 1);
1261 return TEST_SUCCESS;
1266 * rte_security_session_destroy tests
1270 * Test execution of rte_security_session_destroy with NULL instance
1273 test_session_destroy_inv_context(void)
1275 struct security_unittest_params *ut_params = &unittest_params;
1277 TEST_ASSERT_MEMPOOL_USAGE(1);
1278 TEST_ASSERT_SESSION_COUNT(1);
1280 int ret = rte_security_session_destroy(NULL, ut_params->sess);
1281 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1282 ret, -EINVAL, "%d");
1283 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1284 TEST_ASSERT_MEMPOOL_USAGE(1);
1285 TEST_ASSERT_SESSION_COUNT(1);
1287 return TEST_SUCCESS;
1291 * Test execution of rte_security_session_destroy with invalid
1292 * security operations structure (NULL)
1295 test_session_destroy_inv_context_ops(void)
1297 struct security_unittest_params *ut_params = &unittest_params;
1298 ut_params->ctx.ops = NULL;
1300 TEST_ASSERT_MEMPOOL_USAGE(1);
1301 TEST_ASSERT_SESSION_COUNT(1);
1303 int ret = rte_security_session_destroy(&ut_params->ctx,
1305 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1306 ret, -EINVAL, "%d");
1307 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1308 TEST_ASSERT_MEMPOOL_USAGE(1);
1309 TEST_ASSERT_SESSION_COUNT(1);
1311 return TEST_SUCCESS;
1315 * Test execution of rte_security_session_destroy with empty
1316 * security operations
1319 test_session_destroy_inv_context_ops_fun(void)
1321 struct security_unittest_params *ut_params = &unittest_params;
1322 ut_params->ctx.ops = &empty_ops;
1324 TEST_ASSERT_MEMPOOL_USAGE(1);
1325 TEST_ASSERT_SESSION_COUNT(1);
1327 int ret = rte_security_session_destroy(&ut_params->ctx,
1329 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1330 ret, -ENOTSUP, "%d");
1331 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1332 TEST_ASSERT_MEMPOOL_USAGE(1);
1333 TEST_ASSERT_SESSION_COUNT(1);
1335 return TEST_SUCCESS;
1339 * Test execution of rte_security_session_destroy with NULL sess parameter
1342 test_session_destroy_inv_session(void)
1344 struct security_unittest_params *ut_params = &unittest_params;
1346 TEST_ASSERT_MEMPOOL_USAGE(1);
1347 TEST_ASSERT_SESSION_COUNT(1);
1349 int ret = rte_security_session_destroy(&ut_params->ctx, NULL);
1350 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1351 ret, -EINVAL, "%d");
1352 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1353 TEST_ASSERT_MEMPOOL_USAGE(1);
1354 TEST_ASSERT_SESSION_COUNT(1);
1356 return TEST_SUCCESS;
1360 * Test execution of rte_security_session_destroy when session_destroy
1361 * security operation fails
1364 test_session_destroy_ops_failure(void)
1366 struct security_unittest_params *ut_params = &unittest_params;
1368 mock_session_destroy_exp.device = NULL;
1369 mock_session_destroy_exp.sess = ut_params->sess;
1370 mock_session_destroy_exp.ret = -1;
1372 TEST_ASSERT_MEMPOOL_USAGE(1);
1373 TEST_ASSERT_SESSION_COUNT(1);
1375 int ret = rte_security_session_destroy(&ut_params->ctx,
1377 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1379 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
1380 TEST_ASSERT_MEMPOOL_USAGE(1);
1381 TEST_ASSERT_SESSION_COUNT(1);
1383 return TEST_SUCCESS;
1387 * Test execution of rte_security_session_destroy in successful execution path
1390 test_session_destroy_success(void)
1392 struct security_unittest_params *ut_params = &unittest_params;
1394 mock_session_destroy_exp.device = NULL;
1395 mock_session_destroy_exp.sess = ut_params->sess;
1396 mock_session_destroy_exp.ret = 0;
1397 TEST_ASSERT_MEMPOOL_USAGE(1);
1398 TEST_ASSERT_SESSION_COUNT(1);
1400 int ret = rte_security_session_destroy(&ut_params->ctx,
1402 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1404 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
1405 TEST_ASSERT_MEMPOOL_USAGE(0);
1406 TEST_ASSERT_SESSION_COUNT(0);
1409 * Remove session from test case parameters, so it won't be destroyed
1410 * during test case teardown.
1412 ut_params->sess = NULL;
1414 return TEST_SUCCESS;
1419 * rte_security_set_pkt_metadata tests
1423 * Test execution of rte_security_set_pkt_metadata with NULL instance
1426 test_set_pkt_metadata_inv_context(void)
1429 struct security_unittest_params *ut_params = &unittest_params;
1433 int ret = rte_security_set_pkt_metadata(NULL, ut_params->sess, &m,
1435 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1436 ret, -EINVAL, "%d");
1437 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1439 return TEST_SUCCESS;
1441 return TEST_SKIPPED;
1446 * Test execution of rte_security_set_pkt_metadata with invalid
1447 * security operations structure (NULL)
1450 test_set_pkt_metadata_inv_context_ops(void)
1453 struct security_unittest_params *ut_params = &unittest_params;
1456 ut_params->ctx.ops = NULL;
1458 int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1459 ut_params->sess, &m, ¶ms);
1460 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1461 ret, -EINVAL, "%d");
1462 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1464 return TEST_SUCCESS;
1466 return TEST_SKIPPED;
1471 * Test execution of rte_security_set_pkt_metadata with empty
1472 * security operations
1475 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;
1491 return TEST_SKIPPED;
1496 * Test execution of rte_security_set_pkt_metadata with NULL sess parameter
1499 test_set_pkt_metadata_inv_session(void)
1502 struct security_unittest_params *ut_params = &unittest_params;
1506 int ret = rte_security_set_pkt_metadata(&ut_params->ctx, NULL,
1508 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1509 ret, -EINVAL, "%d");
1510 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1512 return TEST_SUCCESS;
1514 return TEST_SKIPPED;
1519 * Test execution of rte_security_set_pkt_metadata when set_pkt_metadata
1520 * security operation fails
1523 test_set_pkt_metadata_ops_failure(void)
1525 struct security_unittest_params *ut_params = &unittest_params;
1529 mock_set_pkt_metadata_exp.device = NULL;
1530 mock_set_pkt_metadata_exp.sess = ut_params->sess;
1531 mock_set_pkt_metadata_exp.m = &m;
1532 mock_set_pkt_metadata_exp.params = ¶ms;
1533 mock_set_pkt_metadata_exp.ret = -1;
1535 int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1536 ut_params->sess, &m, ¶ms);
1537 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1539 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 1);
1541 return TEST_SUCCESS;
1545 * Test execution of rte_security_set_pkt_metadata in successful execution path
1548 test_set_pkt_metadata_success(void)
1550 struct security_unittest_params *ut_params = &unittest_params;
1554 mock_set_pkt_metadata_exp.device = NULL;
1555 mock_set_pkt_metadata_exp.sess = ut_params->sess;
1556 mock_set_pkt_metadata_exp.m = &m;
1557 mock_set_pkt_metadata_exp.params = ¶ms;
1558 mock_set_pkt_metadata_exp.ret = 0;
1560 int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1561 ut_params->sess, &m, ¶ms);
1562 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1564 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 1);
1566 return TEST_SUCCESS;
1571 * rte_security_get_userdata tests
1575 * Test execution of rte_security_get_userdata with NULL instance
1578 test_get_userdata_inv_context(void)
1581 uint64_t md = 0xDEADBEEF;
1583 void *ret = rte_security_get_userdata(NULL, md);
1584 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1586 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0);
1588 return TEST_SUCCESS;
1590 return TEST_SKIPPED;
1595 * Test execution of rte_security_get_userdata with invalid
1596 * security operations structure (NULL)
1599 test_get_userdata_inv_context_ops(void)
1602 struct security_unittest_params *ut_params = &unittest_params;
1603 uint64_t md = 0xDEADBEEF;
1604 ut_params->ctx.ops = NULL;
1606 void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1607 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1609 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0);
1611 return TEST_SUCCESS;
1613 return TEST_SKIPPED;
1618 * Test execution of rte_security_get_userdata with empty
1619 * security operations
1622 test_get_userdata_inv_context_ops_fun(void)
1625 struct security_unittest_params *ut_params = &unittest_params;
1626 uint64_t md = 0xDEADBEEF;
1627 ut_params->ctx.ops = &empty_ops;
1629 void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1630 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1632 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0);
1634 return TEST_SUCCESS;
1636 return TEST_SKIPPED;
1641 * Test execution of rte_security_get_userdata when get_userdata
1642 * security operation fails
1645 test_get_userdata_ops_failure(void)
1647 struct security_unittest_params *ut_params = &unittest_params;
1648 uint64_t md = 0xDEADBEEF;
1649 void *userdata = (void *)0x7E577E57;
1651 mock_get_userdata_exp.device = NULL;
1652 mock_get_userdata_exp.md = md;
1653 mock_get_userdata_exp.userdata = userdata;
1654 mock_get_userdata_exp.ret = -1;
1656 void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1657 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1659 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 1);
1661 return TEST_SUCCESS;
1665 * Test execution of rte_security_get_userdata in successful execution path
1668 test_get_userdata_success(void)
1670 struct security_unittest_params *ut_params = &unittest_params;
1671 uint64_t md = 0xDEADBEEF;
1672 void *userdata = (void *)0x7E577E57;
1674 mock_get_userdata_exp.device = NULL;
1675 mock_get_userdata_exp.md = md;
1676 mock_get_userdata_exp.userdata = userdata;
1677 mock_get_userdata_exp.ret = 0;
1679 void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1680 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1681 ret, userdata, "%p");
1682 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 1);
1684 return TEST_SUCCESS;
1689 * rte_security_capabilities_get tests
1693 * Test execution of rte_security_capabilities_get with NULL instance
1696 test_capabilities_get_inv_context(void)
1698 const struct rte_security_capability *ret;
1699 ret = rte_security_capabilities_get(NULL);
1700 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1702 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1704 return TEST_SUCCESS;
1708 * Test execution of rte_security_capabilities_get with invalid
1709 * security operations structure (NULL)
1712 test_capabilities_get_inv_context_ops(void)
1714 struct security_unittest_params *ut_params = &unittest_params;
1715 ut_params->ctx.ops = NULL;
1717 const struct rte_security_capability *ret;
1718 ret = rte_security_capabilities_get(&ut_params->ctx);
1719 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1721 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1723 return TEST_SUCCESS;
1727 * Test execution of rte_security_capabilities_get with empty
1728 * security operations
1731 test_capabilities_get_inv_context_ops_fun(void)
1733 struct security_unittest_params *ut_params = &unittest_params;
1734 ut_params->ctx.ops = &empty_ops;
1736 const struct rte_security_capability *ret;
1737 ret = rte_security_capabilities_get(&ut_params->ctx);
1738 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1740 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1742 return TEST_SUCCESS;
1746 * Test execution of rte_security_capabilities_get when capabilities_get
1747 * security operation fails
1750 test_capabilities_get_ops_failure(void)
1752 struct security_unittest_params *ut_params = &unittest_params;
1754 mock_capabilities_get_exp.device = NULL;
1755 mock_capabilities_get_exp.ret = NULL;
1757 const struct rte_security_capability *ret;
1758 ret = rte_security_capabilities_get(&ut_params->ctx);
1759 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1761 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
1763 return TEST_SUCCESS;
1767 * Test execution of rte_security_capabilities_get in successful execution path
1770 test_capabilities_get_success(void)
1772 struct security_unittest_params *ut_params = &unittest_params;
1773 struct rte_security_capability capabilities;
1775 mock_capabilities_get_exp.device = NULL;
1776 mock_capabilities_get_exp.ret = &capabilities;
1778 const struct rte_security_capability *ret;
1779 ret = rte_security_capabilities_get(&ut_params->ctx);
1780 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1781 ret, &capabilities, "%p");
1782 TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
1784 return TEST_SUCCESS;
1789 * Declaration of testcases
1791 static struct unit_test_suite security_testsuite = {
1792 .suite_name = "generic security",
1793 .setup = testsuite_setup,
1794 .teardown = testsuite_teardown,
1795 .unit_test_cases = {
1796 TEST_CASE_ST(ut_setup, ut_teardown,
1797 test_session_create_inv_context),
1798 TEST_CASE_ST(ut_setup, ut_teardown,
1799 test_session_create_inv_context_ops),
1800 TEST_CASE_ST(ut_setup, ut_teardown,
1801 test_session_create_inv_context_ops_fun),
1802 TEST_CASE_ST(ut_setup, ut_teardown,
1803 test_session_create_inv_configuration),
1804 TEST_CASE_ST(ut_setup, ut_teardown,
1805 test_session_create_inv_mempool),
1806 TEST_CASE_ST(ut_setup, ut_teardown,
1807 test_session_create_mempool_empty),
1808 TEST_CASE_ST(ut_setup, ut_teardown,
1809 test_session_create_ops_failure),
1810 TEST_CASE_ST(ut_setup, ut_teardown,
1811 test_session_create_success),
1813 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1814 test_session_update_inv_context),
1815 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1816 test_session_update_inv_context_ops),
1817 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1818 test_session_update_inv_context_ops_fun),
1819 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1820 test_session_update_inv_configuration),
1821 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1822 test_session_update_inv_session),
1823 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1824 test_session_update_ops_failure),
1825 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1826 test_session_update_success),
1828 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1829 test_session_get_size_inv_context),
1830 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1831 test_session_get_size_inv_context_ops),
1832 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1833 test_session_get_size_inv_context_ops_fun),
1834 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1835 test_session_get_size_ops_failure),
1836 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1837 test_session_get_size_success),
1839 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1840 test_session_stats_get_inv_context),
1841 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1842 test_session_stats_get_inv_context_ops),
1843 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1844 test_session_stats_get_inv_context_ops_fun),
1845 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1846 test_session_stats_get_inv_stats),
1847 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1848 test_session_stats_get_ops_failure),
1849 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1850 test_session_stats_get_success),
1852 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1853 test_session_destroy_inv_context),
1854 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1855 test_session_destroy_inv_context_ops),
1856 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1857 test_session_destroy_inv_context_ops_fun),
1858 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1859 test_session_destroy_inv_session),
1860 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1861 test_session_destroy_ops_failure),
1862 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1863 test_session_destroy_success),
1865 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1866 test_set_pkt_metadata_inv_context),
1867 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1868 test_set_pkt_metadata_inv_context_ops),
1869 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1870 test_set_pkt_metadata_inv_context_ops_fun),
1871 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1872 test_set_pkt_metadata_inv_session),
1873 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1874 test_set_pkt_metadata_ops_failure),
1875 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1876 test_set_pkt_metadata_success),
1878 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1879 test_get_userdata_inv_context),
1880 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1881 test_get_userdata_inv_context_ops),
1882 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1883 test_get_userdata_inv_context_ops_fun),
1884 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1885 test_get_userdata_ops_failure),
1886 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1887 test_get_userdata_success),
1889 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1890 test_capabilities_get_inv_context),
1891 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1892 test_capabilities_get_inv_context_ops),
1893 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1894 test_capabilities_get_inv_context_ops_fun),
1895 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1896 test_capabilities_get_ops_failure),
1897 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1898 test_capabilities_get_success),
1900 TEST_CASES_END() /**< NULL terminate unit test array */
1907 rte_log_set_global_level(RTE_LOG_DEBUG);
1908 rte_log_set_level(RTE_LOGTYPE_EAL, RTE_LOG_DEBUG);
1910 return unit_test_suite_runner(&security_testsuite);
1913 REGISTER_TEST_COMMAND(security_autotest, test_security);