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;
446 * is an empty security operations set (all function pointers set to NULL)
448 struct rte_security_ops empty_ops = { NULL };
453 * is a security operations set using mockup functions
455 struct rte_security_ops mock_ops = {
456 .session_create = mock_session_create,
457 .session_update = mock_session_update,
458 .session_get_size = mock_session_get_size,
459 .session_stats_get = mock_session_stats_get,
460 .session_destroy = mock_session_destroy,
461 .set_pkt_metadata = mock_set_pkt_metadata,
462 .get_userdata = mock_get_userdata,
467 * Test suite and test cases setup and teardown functions.
471 * struct security_testsuite_params defines parameters initialized once
472 * for whole tests suite.
473 * Currently the only stored parameter is session_mpool a mempool created
474 * once in testsuite_setup and released in testsuite_teardown.
475 * The instance of this structure is stored in testsuite_params variable.
477 static struct security_testsuite_params {
478 struct rte_mempool *session_mpool;
479 } testsuite_params = { NULL };
482 * struct security_unittest_params defines parameters initialized
483 * for every test case. The parameters are initialized in ut_setup
484 * or ut_setup_with_session (depending on the testcase)
485 * and released in ut_teardown.
486 * The instance of this structure is stored in unittest_params variable.
488 static struct security_unittest_params {
489 struct rte_security_ctx ctx;
490 struct rte_security_session_conf conf;
491 struct rte_security_session *sess;
492 } unittest_params = {
501 #define SECURITY_TEST_MEMPOOL_NAME "SecurityTestsMempoolName"
502 #define SECURITY_TEST_MEMPOOL_SIZE 15
503 #define SECURITY_TEST_SESSION_OBJECT_SIZE sizeof(struct rte_security_session)
506 * testsuite_setup initializes whole test suite parameters.
507 * It creates a new mempool used in all test cases
508 * and verifies if it properly created.
511 testsuite_setup(void)
513 struct security_testsuite_params *ts_params = &testsuite_params;
514 ts_params->session_mpool = rte_mempool_create(
515 SECURITY_TEST_MEMPOOL_NAME,
516 SECURITY_TEST_MEMPOOL_SIZE,
517 SECURITY_TEST_SESSION_OBJECT_SIZE,
518 0, 0, NULL, NULL, NULL, NULL,
520 TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
521 "Cannot create mempool %s\n", rte_strerror(rte_errno));
526 * testsuite_teardown releases test suite wide parameters.
529 testsuite_teardown(void)
531 struct security_testsuite_params *ts_params = &testsuite_params;
532 if (ts_params->session_mpool) {
533 rte_mempool_free(ts_params->session_mpool);
534 ts_params->session_mpool = NULL;
539 * ut_setup initializes test case parameters to default values.
540 * It resets also any .called and .failed statistics of mockup functions
546 struct security_unittest_params *ut_params = &unittest_params;
547 ut_params->ctx.device = NULL;
548 ut_params->ctx.ops = &mock_ops;
549 ut_params->ctx.sess_cnt = 0;
550 ut_params->sess = NULL;
552 mock_session_create_exp.called = 0;
553 mock_session_update_exp.called = 0;
554 mock_session_get_size_exp.called = 0;
555 mock_session_stats_get_exp.called = 0;
556 mock_session_destroy_exp.called = 0;
557 mock_set_pkt_metadata_exp.called = 0;
558 mock_get_userdata_exp.called = 0;
560 mock_session_create_exp.failed = 0;
561 mock_session_update_exp.failed = 0;
562 mock_session_get_size_exp.failed = 0;
563 mock_session_stats_get_exp.failed = 0;
564 mock_session_destroy_exp.failed = 0;
565 mock_set_pkt_metadata_exp.failed = 0;
566 mock_get_userdata_exp.failed = 0;
572 * destroy_session_with_check is a helper function releasing session
573 * created with rte_security_session_create and stored in test case parameters.
574 * It's used both to release sessions created in test cases' bodies
575 * which are assigned to ut_params->sess
576 * as well as sessions created in ut_setup_with_session.
579 destroy_session_with_check(void)
581 struct security_unittest_params *ut_params = &unittest_params;
582 if (ut_params->sess != NULL) {
583 /* Assure that mockup function for destroy operation is set. */
584 ut_params->ctx.ops = &mock_ops;
586 mock_session_destroy_exp.device = NULL;
587 mock_session_destroy_exp.sess = ut_params->sess;
588 mock_session_destroy_exp.ret = 0;
589 mock_session_destroy_exp.called = 0;
590 mock_session_destroy_exp.failed = 0;
592 int ret = rte_security_session_destroy(&ut_params->ctx,
594 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
596 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
598 ut_params->sess = NULL;
604 * ut_teardown releases test case parameters.
609 destroy_session_with_check();
613 * ut_setup_with_session initializes test case parameters by
614 * - calling standard ut_setup,
615 * - creating a session that can be used in test case.
618 ut_setup_with_session(void)
620 struct security_unittest_params *ut_params = &unittest_params;
621 struct security_testsuite_params *ts_params = &testsuite_params;
622 struct rte_security_session *sess;
624 int ret = ut_setup();
625 if (ret != TEST_SUCCESS)
628 mock_session_create_exp.device = NULL;
629 mock_session_create_exp.conf = &ut_params->conf;
630 mock_session_create_exp.mp = ts_params->session_mpool;
631 mock_session_create_exp.ret = 0;
633 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
634 ts_params->session_mpool);
635 TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(rte_security_session_create,
637 TEST_ASSERT_EQUAL(sess, mock_session_create_exp.sess,
638 "Expecting session_create to be called with %p sess"
639 " parameter, but it's called %p sess parameter",
640 sess, mock_session_create_exp.sess);
641 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
644 * Store created session in test case parameters, so it can be released
645 * after test case in ut_teardown by destroy_session_with_check.
647 ut_params->sess = sess;
656 * Each test function is related to a single test case.
657 * They are arranged by tested rte_security API function
658 * and by rte_security execution paths sequence in code.
662 * rte_security_session_create tests
666 * Test execution of rte_security_session_create with NULL instance
669 test_session_create_inv_context(void)
671 struct security_testsuite_params *ts_params = &testsuite_params;
672 struct security_unittest_params *ut_params = &unittest_params;
673 struct rte_security_session *sess;
675 sess = rte_security_session_create(NULL, &ut_params->conf,
676 ts_params->session_mpool);
677 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
679 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
680 TEST_ASSERT_MEMPOOL_USAGE(0);
681 TEST_ASSERT_SESSION_COUNT(0);
687 * Test execution of rte_security_session_create with invalid
688 * security operations structure (NULL)
691 test_session_create_inv_context_ops(void)
693 struct security_testsuite_params *ts_params = &testsuite_params;
694 struct security_unittest_params *ut_params = &unittest_params;
695 struct rte_security_session *sess;
697 ut_params->ctx.ops = NULL;
699 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
700 ts_params->session_mpool);
701 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
703 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
704 TEST_ASSERT_MEMPOOL_USAGE(0);
705 TEST_ASSERT_SESSION_COUNT(0);
711 * Test execution of rte_security_session_create with empty
712 * security operations
715 test_session_create_inv_context_ops_fun(void)
717 struct security_testsuite_params *ts_params = &testsuite_params;
718 struct security_unittest_params *ut_params = &unittest_params;
719 struct rte_security_session *sess;
721 ut_params->ctx.ops = &empty_ops;
723 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
724 ts_params->session_mpool);
725 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
727 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
728 TEST_ASSERT_MEMPOOL_USAGE(0);
729 TEST_ASSERT_SESSION_COUNT(0);
735 * Test execution of rte_security_session_create with NULL conf parameter
738 test_session_create_inv_configuration(void)
740 struct security_testsuite_params *ts_params = &testsuite_params;
741 struct security_unittest_params *ut_params = &unittest_params;
742 struct rte_security_session *sess;
744 sess = rte_security_session_create(&ut_params->ctx, NULL,
745 ts_params->session_mpool);
746 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
748 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
749 TEST_ASSERT_MEMPOOL_USAGE(0);
750 TEST_ASSERT_SESSION_COUNT(0);
756 * Test execution of rte_security_session_create with NULL mp parameter
759 test_session_create_inv_mempool(void)
761 struct security_unittest_params *ut_params = &unittest_params;
762 struct rte_security_session *sess;
764 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
766 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
768 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
769 TEST_ASSERT_MEMPOOL_USAGE(0);
770 TEST_ASSERT_SESSION_COUNT(0);
776 * Test execution of rte_security_session_create in case when mempool
777 * is fully used and no object can be got from it
780 test_session_create_mempool_empty(void)
782 struct security_testsuite_params *ts_params = &testsuite_params;
783 struct security_unittest_params *ut_params = &unittest_params;
784 struct rte_security_session *tmp[SECURITY_TEST_MEMPOOL_SIZE];
785 struct rte_security_session *sess;
787 /* Get all available objects from mempool. */
789 for (i = 0; i < SECURITY_TEST_MEMPOOL_SIZE; ++i) {
790 ret = rte_mempool_get(ts_params->session_mpool,
792 TEST_ASSERT_EQUAL(0, ret,
793 "Expect getting %d object from mempool"
796 TEST_ASSERT_MEMPOOL_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
798 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
799 ts_params->session_mpool);
800 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
802 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
803 TEST_ASSERT_MEMPOOL_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
804 TEST_ASSERT_SESSION_COUNT(0);
806 /* Put objects back to the pool. */
807 for (i = 0; i < SECURITY_TEST_MEMPOOL_SIZE; ++i)
808 rte_mempool_put(ts_params->session_mpool, (void *)(tmp[i]));
809 TEST_ASSERT_MEMPOOL_USAGE(0);
815 * Test execution of rte_security_session_create when session_create
816 * security operation fails
819 test_session_create_ops_failure(void)
821 struct security_testsuite_params *ts_params = &testsuite_params;
822 struct security_unittest_params *ut_params = &unittest_params;
823 struct rte_security_session *sess;
825 mock_session_create_exp.device = NULL;
826 mock_session_create_exp.conf = &ut_params->conf;
827 mock_session_create_exp.mp = ts_params->session_mpool;
828 mock_session_create_exp.ret = -1; /* Return failure status. */
830 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
831 ts_params->session_mpool);
832 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
834 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
835 TEST_ASSERT_MEMPOOL_USAGE(0);
836 TEST_ASSERT_SESSION_COUNT(0);
842 * Test execution of rte_security_session_create in successful execution path
845 test_session_create_success(void)
847 struct security_testsuite_params *ts_params = &testsuite_params;
848 struct security_unittest_params *ut_params = &unittest_params;
849 struct rte_security_session *sess;
851 mock_session_create_exp.device = NULL;
852 mock_session_create_exp.conf = &ut_params->conf;
853 mock_session_create_exp.mp = ts_params->session_mpool;
854 mock_session_create_exp.ret = 0; /* Return success status. */
856 sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
857 ts_params->session_mpool);
858 TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(rte_security_session_create,
860 TEST_ASSERT_EQUAL(sess, mock_session_create_exp.sess,
861 "Expecting session_create to be called with %p sess"
862 " parameter, but it's called %p sess parameter",
863 sess, mock_session_create_exp.sess);
864 TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
865 TEST_ASSERT_MEMPOOL_USAGE(1);
866 TEST_ASSERT_SESSION_COUNT(1);
869 * Store created session in test case parameters, so it can be released
870 * after test case in ut_teardown by destroy_session_with_check.
872 ut_params->sess = sess;
879 * rte_security_session_update tests
883 * Test execution of rte_security_session_update with NULL instance
886 test_session_update_inv_context(void)
888 struct security_unittest_params *ut_params = &unittest_params;
890 int ret = rte_security_session_update(NULL, ut_params->sess,
892 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
894 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
900 * Test execution of rte_security_session_update with invalid
901 * security operations structure (NULL)
904 test_session_update_inv_context_ops(void)
906 struct security_unittest_params *ut_params = &unittest_params;
907 ut_params->ctx.ops = NULL;
909 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
911 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
913 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
919 * Test execution of rte_security_session_update with empty
920 * security operations
923 test_session_update_inv_context_ops_fun(void)
925 struct security_unittest_params *ut_params = &unittest_params;
926 ut_params->ctx.ops = &empty_ops;
928 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
930 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
931 ret, -ENOTSUP, "%d");
932 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
938 * Test execution of rte_security_session_update with NULL conf parameter
941 test_session_update_inv_configuration(void)
943 struct security_unittest_params *ut_params = &unittest_params;
945 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
947 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
949 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
955 * Test execution of rte_security_session_update with NULL sess parameter
958 test_session_update_inv_session(void)
960 struct security_unittest_params *ut_params = &unittest_params;
962 int ret = rte_security_session_update(&ut_params->ctx, NULL,
964 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
966 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
972 * Test execution of rte_security_session_update when session_update
973 * security operation fails
976 test_session_update_ops_failure(void)
978 struct security_unittest_params *ut_params = &unittest_params;
980 mock_session_update_exp.device = NULL;
981 mock_session_update_exp.sess = ut_params->sess;
982 mock_session_update_exp.conf = &ut_params->conf;
983 mock_session_update_exp.ret = -1; /* Return failure status. */
985 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
987 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
989 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 1);
995 * Test execution of rte_security_session_update in successful execution path
998 test_session_update_success(void)
1000 struct security_unittest_params *ut_params = &unittest_params;
1002 mock_session_update_exp.device = NULL;
1003 mock_session_update_exp.sess = ut_params->sess;
1004 mock_session_update_exp.conf = &ut_params->conf;
1005 mock_session_update_exp.ret = 0; /* Return success status. */
1007 int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
1009 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1011 TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 1);
1013 return TEST_SUCCESS;
1018 * rte_security_session_get_size tests
1022 * Test execution of rte_security_session_get_size with NULL instance
1025 test_session_get_size_inv_context(void)
1027 unsigned int ret = rte_security_session_get_size(NULL);
1028 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1030 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
1032 return TEST_SUCCESS;
1036 * Test execution of rte_security_session_get_size with invalid
1037 * security operations structure (NULL)
1040 test_session_get_size_inv_context_ops(void)
1042 struct security_unittest_params *ut_params = &unittest_params;
1043 ut_params->ctx.ops = NULL;
1045 unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1046 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1048 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
1050 return TEST_SUCCESS;
1054 * Test execution of rte_security_session_get_size with empty
1055 * security operations
1058 test_session_get_size_inv_context_ops_fun(void)
1060 struct security_unittest_params *ut_params = &unittest_params;
1061 ut_params->ctx.ops = &empty_ops;
1063 unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1064 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1066 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
1068 return TEST_SUCCESS;
1072 * Test execution of rte_security_session_get_size when session_get_size
1073 * security operation fails
1076 test_session_get_size_ops_failure(void)
1078 struct security_unittest_params *ut_params = &unittest_params;
1080 mock_session_get_size_exp.device = NULL;
1081 mock_session_get_size_exp.ret = 0;
1083 unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1084 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1086 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 1);
1088 return TEST_SUCCESS;
1092 * Test execution of rte_security_session_get_size in successful execution path
1095 test_session_get_size_success(void)
1097 struct security_unittest_params *ut_params = &unittest_params;
1099 mock_session_get_size_exp.device = NULL;
1100 mock_session_get_size_exp.ret = 1024;
1102 unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1103 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1105 TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 1);
1107 return TEST_SUCCESS;
1112 * rte_security_session_stats_get tests
1116 * Test execution of rte_security_session_stats_get with NULL instance
1119 test_session_stats_get_inv_context(void)
1121 struct security_unittest_params *ut_params = &unittest_params;
1122 struct rte_security_stats stats;
1124 int ret = rte_security_session_stats_get(NULL, ut_params->sess, &stats);
1125 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1126 ret, -EINVAL, "%d");
1127 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1129 return TEST_SUCCESS;
1133 * Test execution of rte_security_session_stats_get with invalid
1134 * security operations structure (NULL)
1137 test_session_stats_get_inv_context_ops(void)
1139 struct security_unittest_params *ut_params = &unittest_params;
1140 struct rte_security_stats stats;
1141 ut_params->ctx.ops = NULL;
1143 int ret = rte_security_session_stats_get(&ut_params->ctx,
1144 ut_params->sess, &stats);
1145 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1146 ret, -EINVAL, "%d");
1147 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1149 return TEST_SUCCESS;
1153 * Test execution of rte_security_session_stats_get with empty
1154 * security operations
1157 test_session_stats_get_inv_context_ops_fun(void)
1159 struct security_unittest_params *ut_params = &unittest_params;
1160 struct rte_security_stats stats;
1161 ut_params->ctx.ops = &empty_ops;
1163 int ret = rte_security_session_stats_get(&ut_params->ctx,
1164 ut_params->sess, &stats);
1165 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1166 ret, -ENOTSUP, "%d");
1167 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1169 return TEST_SUCCESS;
1173 * Test execution of rte_security_session_stats_get with NULL stats parameter
1176 test_session_stats_get_inv_stats(void)
1178 struct security_unittest_params *ut_params = &unittest_params;
1180 int ret = rte_security_session_stats_get(&ut_params->ctx,
1181 ut_params->sess, NULL);
1182 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1183 ret, -EINVAL, "%d");
1184 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1186 return TEST_SUCCESS;
1190 * Test execution of rte_security_session_stats_get when session_stats_get
1191 * security operation fails
1194 test_session_stats_get_ops_failure(void)
1196 struct security_unittest_params *ut_params = &unittest_params;
1197 struct rte_security_stats stats;
1199 mock_session_stats_get_exp.device = NULL;
1200 mock_session_stats_get_exp.sess = ut_params->sess;
1201 mock_session_stats_get_exp.stats = &stats;
1202 mock_session_stats_get_exp.ret = -1;
1204 int ret = rte_security_session_stats_get(&ut_params->ctx,
1205 ut_params->sess, &stats);
1206 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1208 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 1);
1210 return TEST_SUCCESS;
1214 * Test execution of rte_security_session_stats_get in successful execution
1218 test_session_stats_get_success(void)
1220 struct security_unittest_params *ut_params = &unittest_params;
1221 struct rte_security_stats stats;
1223 mock_session_stats_get_exp.device = NULL;
1224 mock_session_stats_get_exp.sess = ut_params->sess;
1225 mock_session_stats_get_exp.stats = &stats;
1226 mock_session_stats_get_exp.ret = 0;
1228 int ret = rte_security_session_stats_get(&ut_params->ctx,
1229 ut_params->sess, &stats);
1230 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1232 TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 1);
1234 return TEST_SUCCESS;
1239 * rte_security_session_destroy tests
1243 * Test execution of rte_security_session_destroy with NULL instance
1246 test_session_destroy_inv_context(void)
1248 struct security_unittest_params *ut_params = &unittest_params;
1250 TEST_ASSERT_MEMPOOL_USAGE(1);
1251 TEST_ASSERT_SESSION_COUNT(1);
1253 int ret = rte_security_session_destroy(NULL, ut_params->sess);
1254 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1255 ret, -EINVAL, "%d");
1256 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1257 TEST_ASSERT_MEMPOOL_USAGE(1);
1258 TEST_ASSERT_SESSION_COUNT(1);
1260 return TEST_SUCCESS;
1264 * Test execution of rte_security_session_destroy with invalid
1265 * security operations structure (NULL)
1268 test_session_destroy_inv_context_ops(void)
1270 struct security_unittest_params *ut_params = &unittest_params;
1271 ut_params->ctx.ops = NULL;
1273 TEST_ASSERT_MEMPOOL_USAGE(1);
1274 TEST_ASSERT_SESSION_COUNT(1);
1276 int ret = rte_security_session_destroy(&ut_params->ctx,
1278 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1279 ret, -EINVAL, "%d");
1280 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1281 TEST_ASSERT_MEMPOOL_USAGE(1);
1282 TEST_ASSERT_SESSION_COUNT(1);
1284 return TEST_SUCCESS;
1288 * Test execution of rte_security_session_destroy with empty
1289 * security operations
1292 test_session_destroy_inv_context_ops_fun(void)
1294 struct security_unittest_params *ut_params = &unittest_params;
1295 ut_params->ctx.ops = &empty_ops;
1297 TEST_ASSERT_MEMPOOL_USAGE(1);
1298 TEST_ASSERT_SESSION_COUNT(1);
1300 int ret = rte_security_session_destroy(&ut_params->ctx,
1302 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1303 ret, -ENOTSUP, "%d");
1304 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1305 TEST_ASSERT_MEMPOOL_USAGE(1);
1306 TEST_ASSERT_SESSION_COUNT(1);
1308 return TEST_SUCCESS;
1312 * Test execution of rte_security_session_destroy with NULL sess parameter
1315 test_session_destroy_inv_session(void)
1317 struct security_unittest_params *ut_params = &unittest_params;
1319 TEST_ASSERT_MEMPOOL_USAGE(1);
1320 TEST_ASSERT_SESSION_COUNT(1);
1322 int ret = rte_security_session_destroy(&ut_params->ctx, NULL);
1323 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1324 ret, -EINVAL, "%d");
1325 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1326 TEST_ASSERT_MEMPOOL_USAGE(1);
1327 TEST_ASSERT_SESSION_COUNT(1);
1329 return TEST_SUCCESS;
1333 * Test execution of rte_security_session_destroy when session_destroy
1334 * security operation fails
1337 test_session_destroy_ops_failure(void)
1339 struct security_unittest_params *ut_params = &unittest_params;
1341 mock_session_destroy_exp.device = NULL;
1342 mock_session_destroy_exp.sess = ut_params->sess;
1343 mock_session_destroy_exp.ret = -1;
1345 TEST_ASSERT_MEMPOOL_USAGE(1);
1346 TEST_ASSERT_SESSION_COUNT(1);
1348 int ret = rte_security_session_destroy(&ut_params->ctx,
1350 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1352 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
1353 TEST_ASSERT_MEMPOOL_USAGE(1);
1354 TEST_ASSERT_SESSION_COUNT(1);
1356 return TEST_SUCCESS;
1360 * Test execution of rte_security_session_destroy in successful execution path
1363 test_session_destroy_success(void)
1365 struct security_unittest_params *ut_params = &unittest_params;
1367 mock_session_destroy_exp.device = NULL;
1368 mock_session_destroy_exp.sess = ut_params->sess;
1369 mock_session_destroy_exp.ret = 0;
1370 TEST_ASSERT_MEMPOOL_USAGE(1);
1371 TEST_ASSERT_SESSION_COUNT(1);
1373 int ret = rte_security_session_destroy(&ut_params->ctx,
1375 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1377 TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
1378 TEST_ASSERT_MEMPOOL_USAGE(0);
1379 TEST_ASSERT_SESSION_COUNT(0);
1382 * Remove session from test case parameters, so it won't be destroyed
1383 * during test case teardown.
1385 ut_params->sess = NULL;
1387 return TEST_SUCCESS;
1392 * rte_security_set_pkt_metadata tests
1396 * Test execution of rte_security_set_pkt_metadata with NULL instance
1399 test_set_pkt_metadata_inv_context(void)
1402 struct security_unittest_params *ut_params = &unittest_params;
1406 int ret = rte_security_set_pkt_metadata(NULL, ut_params->sess, &m,
1408 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1409 ret, -EINVAL, "%d");
1410 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1412 return TEST_SUCCESS;
1414 return TEST_SKIPPED;
1419 * Test execution of rte_security_set_pkt_metadata with invalid
1420 * security operations structure (NULL)
1423 test_set_pkt_metadata_inv_context_ops(void)
1426 struct security_unittest_params *ut_params = &unittest_params;
1429 ut_params->ctx.ops = NULL;
1431 int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1432 ut_params->sess, &m, ¶ms);
1433 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1434 ret, -EINVAL, "%d");
1435 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1437 return TEST_SUCCESS;
1439 return TEST_SKIPPED;
1444 * Test execution of rte_security_set_pkt_metadata with empty
1445 * security operations
1448 test_set_pkt_metadata_inv_context_ops_fun(void)
1451 struct security_unittest_params *ut_params = &unittest_params;
1454 ut_params->ctx.ops = &empty_ops;
1456 int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1457 ut_params->sess, &m, ¶ms);
1458 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1459 ret, -ENOTSUP, "%d");
1460 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1462 return TEST_SUCCESS;
1464 return TEST_SKIPPED;
1469 * Test execution of rte_security_set_pkt_metadata with NULL sess parameter
1472 test_set_pkt_metadata_inv_session(void)
1475 struct security_unittest_params *ut_params = &unittest_params;
1479 int ret = rte_security_set_pkt_metadata(&ut_params->ctx, NULL,
1481 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1482 ret, -EINVAL, "%d");
1483 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1485 return TEST_SUCCESS;
1487 return TEST_SKIPPED;
1492 * Test execution of rte_security_set_pkt_metadata when set_pkt_metadata
1493 * security operation fails
1496 test_set_pkt_metadata_ops_failure(void)
1498 struct security_unittest_params *ut_params = &unittest_params;
1502 mock_set_pkt_metadata_exp.device = NULL;
1503 mock_set_pkt_metadata_exp.sess = ut_params->sess;
1504 mock_set_pkt_metadata_exp.m = &m;
1505 mock_set_pkt_metadata_exp.params = ¶ms;
1506 mock_set_pkt_metadata_exp.ret = -1;
1508 int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1509 ut_params->sess, &m, ¶ms);
1510 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1512 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 1);
1514 return TEST_SUCCESS;
1518 * Test execution of rte_security_set_pkt_metadata in successful execution path
1521 test_set_pkt_metadata_success(void)
1523 struct security_unittest_params *ut_params = &unittest_params;
1527 mock_set_pkt_metadata_exp.device = NULL;
1528 mock_set_pkt_metadata_exp.sess = ut_params->sess;
1529 mock_set_pkt_metadata_exp.m = &m;
1530 mock_set_pkt_metadata_exp.params = ¶ms;
1531 mock_set_pkt_metadata_exp.ret = 0;
1533 int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1534 ut_params->sess, &m, ¶ms);
1535 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1537 TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 1);
1539 return TEST_SUCCESS;
1544 * rte_security_get_userdata tests
1548 * Test execution of rte_security_get_userdata with NULL instance
1551 test_get_userdata_inv_context(void)
1554 uint64_t md = 0xDEADBEEF;
1556 void *ret = rte_security_get_userdata(NULL, md);
1557 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1559 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0);
1561 return TEST_SUCCESS;
1563 return TEST_SKIPPED;
1568 * Test execution of rte_security_get_userdata with invalid
1569 * security operations structure (NULL)
1572 test_get_userdata_inv_context_ops(void)
1575 struct security_unittest_params *ut_params = &unittest_params;
1576 uint64_t md = 0xDEADBEEF;
1577 ut_params->ctx.ops = NULL;
1579 void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1580 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1582 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0);
1584 return TEST_SUCCESS;
1586 return TEST_SKIPPED;
1591 * Test execution of rte_security_get_userdata with empty
1592 * security operations
1595 test_get_userdata_inv_context_ops_fun(void)
1598 struct security_unittest_params *ut_params = &unittest_params;
1599 uint64_t md = 0xDEADBEEF;
1600 ut_params->ctx.ops = &empty_ops;
1602 void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1603 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1605 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0);
1607 return TEST_SUCCESS;
1609 return TEST_SKIPPED;
1614 * Test execution of rte_security_get_userdata when get_userdata
1615 * security operation fails
1618 test_get_userdata_ops_failure(void)
1620 struct security_unittest_params *ut_params = &unittest_params;
1621 uint64_t md = 0xDEADBEEF;
1622 void *userdata = (void *)0x7E577E57;
1624 mock_get_userdata_exp.device = NULL;
1625 mock_get_userdata_exp.md = md;
1626 mock_get_userdata_exp.userdata = userdata;
1627 mock_get_userdata_exp.ret = -1;
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, 1);
1634 return TEST_SUCCESS;
1638 * Test execution of rte_security_get_userdata in successful execution path
1641 test_get_userdata_success(void)
1643 struct security_unittest_params *ut_params = &unittest_params;
1644 uint64_t md = 0xDEADBEEF;
1645 void *userdata = (void *)0x7E577E57;
1647 mock_get_userdata_exp.device = NULL;
1648 mock_get_userdata_exp.md = md;
1649 mock_get_userdata_exp.userdata = userdata;
1650 mock_get_userdata_exp.ret = 0;
1652 void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1653 TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1654 ret, userdata, "%p");
1655 TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 1);
1657 return TEST_SUCCESS;
1662 * Declaration of testcases
1664 static struct unit_test_suite security_testsuite = {
1665 .suite_name = "generic security",
1666 .setup = testsuite_setup,
1667 .teardown = testsuite_teardown,
1668 .unit_test_cases = {
1669 TEST_CASE_ST(ut_setup, ut_teardown,
1670 test_session_create_inv_context),
1671 TEST_CASE_ST(ut_setup, ut_teardown,
1672 test_session_create_inv_context_ops),
1673 TEST_CASE_ST(ut_setup, ut_teardown,
1674 test_session_create_inv_context_ops_fun),
1675 TEST_CASE_ST(ut_setup, ut_teardown,
1676 test_session_create_inv_configuration),
1677 TEST_CASE_ST(ut_setup, ut_teardown,
1678 test_session_create_inv_mempool),
1679 TEST_CASE_ST(ut_setup, ut_teardown,
1680 test_session_create_mempool_empty),
1681 TEST_CASE_ST(ut_setup, ut_teardown,
1682 test_session_create_ops_failure),
1683 TEST_CASE_ST(ut_setup, ut_teardown,
1684 test_session_create_success),
1686 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1687 test_session_update_inv_context),
1688 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1689 test_session_update_inv_context_ops),
1690 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1691 test_session_update_inv_context_ops_fun),
1692 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1693 test_session_update_inv_configuration),
1694 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1695 test_session_update_inv_session),
1696 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1697 test_session_update_ops_failure),
1698 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1699 test_session_update_success),
1701 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1702 test_session_get_size_inv_context),
1703 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1704 test_session_get_size_inv_context_ops),
1705 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1706 test_session_get_size_inv_context_ops_fun),
1707 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1708 test_session_get_size_ops_failure),
1709 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1710 test_session_get_size_success),
1712 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1713 test_session_stats_get_inv_context),
1714 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1715 test_session_stats_get_inv_context_ops),
1716 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1717 test_session_stats_get_inv_context_ops_fun),
1718 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1719 test_session_stats_get_inv_stats),
1720 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1721 test_session_stats_get_ops_failure),
1722 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1723 test_session_stats_get_success),
1725 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1726 test_session_destroy_inv_context),
1727 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1728 test_session_destroy_inv_context_ops),
1729 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1730 test_session_destroy_inv_context_ops_fun),
1731 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1732 test_session_destroy_inv_session),
1733 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1734 test_session_destroy_ops_failure),
1735 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1736 test_session_destroy_success),
1738 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1739 test_set_pkt_metadata_inv_context),
1740 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1741 test_set_pkt_metadata_inv_context_ops),
1742 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1743 test_set_pkt_metadata_inv_context_ops_fun),
1744 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1745 test_set_pkt_metadata_inv_session),
1746 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1747 test_set_pkt_metadata_ops_failure),
1748 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1749 test_set_pkt_metadata_success),
1751 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1752 test_get_userdata_inv_context),
1753 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1754 test_get_userdata_inv_context_ops),
1755 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1756 test_get_userdata_inv_context_ops_fun),
1757 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1758 test_get_userdata_ops_failure),
1759 TEST_CASE_ST(ut_setup_with_session, ut_teardown,
1760 test_get_userdata_success),
1762 TEST_CASES_END() /**< NULL terminate unit test array */
1769 rte_log_set_global_level(RTE_LOG_DEBUG);
1770 rte_log_set_level(RTE_LOGTYPE_EAL, RTE_LOG_DEBUG);
1772 return unit_test_suite_runner(&security_testsuite);
1775 REGISTER_TEST_COMMAND(security_autotest, test_security);