xref: /dpdk/app/test/test_security.c (revision 8809f78c7dd9f33a44a4f89c58fc91ded34296ed)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3  */
4 
5 #include <rte_errno.h>
6 #include <rte_log.h>
7 #include <rte_memory.h>
8 #include <rte_mempool.h>
9 #include <rte_ether.h>
10 #include <rte_security.h>
11 #include <rte_security_driver.h>
12 
13 /* Before including rte_test.h file you can define
14  * RTE_TEST_TRACE_FAILURE(_file, _line, _func) macro to better trace/debug test
15  * failures. Mostly useful in development phase.
16  */
17 #ifndef RTE_TEST_TRACE_FAILURE
18 #define RTE_TEST_TRACE_FAILURE(_file, _line, _func) \
19 	RTE_LOG(DEBUG, EAL, "in %s:%d %s\n", _file, _line, _func)
20 #endif
21 
22 #include <rte_test.h>
23 #include "test.h"
24 
25 /**
26  * Security
27  * =======
28  *
29  * Basic unit tests of the librte_security API.
30  *
31  * Structure of the file:
32  * - macros for making tests more readable;
33  * - mockup structures and functions for rte_security_ops;
34  * - test suite and test cases setup and teardown functions;
35  * - tests functions;
36  * - declaration of testcases.
37  */
38 
39 
40 /**
41  * Macros
42  *
43  * Set of macros for making tests easier to read.
44  */
45 
46 /**
47  * Verify condition inside mocked up function.
48  * Mockup function cannot return a test error, so the failure
49  * of assertion increases counter and print logs.
50  * The counter can be verified later to check if test case should fail.
51  *
52  * @param   fail_counter	fail counter
53  * @param   cond	condition expected to be true
54  * @param   msg	printf style formatting string for custom message
55  */
56 #define MOCK_TEST_ASSERT(fail_counter, cond, msg, ...) do {		\
57 	if (!(cond)) {							\
58 		fail_counter++;						\
59 		RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: "	\
60 				msg "\n", __func__, __LINE__,		\
61 				 ##__VA_ARGS__);			\
62 		RTE_TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__);	\
63 	}								\
64 } while (0)
65 
66 /**
67  * Verify equality condition inside mocked up function.
68  * Mockup function cannot return a test error, so the failure
69  * of assertion increases counter and print logs.
70  * The counter can be verified later to check if test case should fail.
71  *
72  * @param   fail_counter	fail counter
73  * @param   a	first value of comparison
74  * @param   b	second value of comparison
75  * @param   msg	printf style formatting string for custom message
76  */
77 #define MOCK_TEST_ASSERT_EQUAL(fail_counter, a, b, msg, ...)	\
78 	MOCK_TEST_ASSERT(fail_counter, (a) == (b), msg, ##__VA_ARGS__)
79 
80 /**
81  * Verify not null condition inside mocked up function.
82  * Mockup function cannot return a test error, so the failure
83  * of assertion increases counter and print logs.
84  * The counter can be verified later to check if test case should fail.
85  *
86  * @param   fail_counter	fail counter
87  * @param   val	value expected not to be NULL
88  * @param   msg	printf style formatting string for custom message
89  */
90 #define MOCK_TEST_ASSERT_NOT_NULL(fail_counter, val, msg, ...)	\
91 	MOCK_TEST_ASSERT(fail_counter, (val) != NULL, msg, ##__VA_ARGS__)
92 
93 
94 /**
95  * Verify if parameter of the mocked up function matches expected value.
96  * The expected value is stored in data structure in the field matching
97  * parameter name.
98  *
99  * @param   data	structure with expected values
100  * @param   parameter	name of the parameter (both field and parameter name)
101  * @param   spec	printf style spec for parameter
102  */
103 #define MOCK_TEST_ASSERT_PARAMETER(data, parameter, spec)		\
104 	MOCK_TEST_ASSERT_EQUAL(data.failed, data.parameter, parameter,	\
105 			"Expecting parameter %s to be " spec		\
106 			" but it's " spec, RTE_STR(parameter),		\
107 			data.parameter, parameter)
108 
109 /**
110  * Wrap for MOCK_TEST_ASSERT_PARAMETER macro for pointer type parameters.
111  *
112  * @param   data	structure with expected values
113  * @param   parameter	name of the parameter (both field and parameter name)
114  */
115 #define MOCK_TEST_ASSERT_POINTER_PARAMETER(data, parameter)	\
116 	MOCK_TEST_ASSERT_PARAMETER(data, parameter, "%p")
117 
118 /**
119  * Wrap for MOCK_TEST_ASSERT_PARAMETER macro for uint64_t type parameters.
120  *
121  * @param   data	structure with expected values
122  * @param   parameter	name of the parameter (both field and parameter name)
123  */
124 #define MOCK_TEST_ASSERT_U64_PARAMETER(data, parameter)	\
125 	MOCK_TEST_ASSERT_PARAMETER(data, parameter, "%" PRIu64)
126 
127 /**
128  * Verify number of calls of the mocked up function
129  * and check if there were any fails during execution.
130  * The fails statistics inside mocked up functions are collected
131  * as "failed" field in mockup structures.
132  *
133  * @param   mock_data	structure with statistics (called, failed)
134  * @param   exp_calls	expected number of mockup function calls
135  */
136 #define TEST_ASSERT_MOCK_CALLS(mock_data, exp_calls) do {		\
137 	TEST_ASSERT_EQUAL(exp_calls, mock_data.called,			\
138 			"Expecting sub op to be called %d times, "	\
139 			"but it's called %d times",			\
140 			exp_calls, mock_data.called);			\
141 	TEST_ASSERT_EQUAL(0, mock_data.failed,				\
142 			"Expecting sub op asserts not to fail, "	\
143 			"but they're failed %d times",			\
144 			mock_data.failed);				\
145 } while (0)
146 
147 /**
148  * Assert tested function result match expected value
149  *
150  * @param   f_name	name of tested function
151  * @param   f_ret	value returned by the function
152  * @param   exp_ret	expected returned value
153  * @param   fmt		printf style format for returned value
154  */
155 #define TEST_ASSERT_MOCK_FUNCTION_CALL_RET(f_name, f_ret, exp_ret, fmt)	\
156 	TEST_ASSERT_EQUAL(exp_ret, f_ret, "Expecting " RTE_STR(f_name)	\
157 			" to return " fmt ", but it returned " fmt	\
158 			"\n", exp_ret, f_ret)
159 
160 /**
161  * Assert tested function result is not NULL
162  *
163  * @param   f_name	name of tested function
164  * @param   f_ret	value returned by the function
165  */
166 #define TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(f_name, f_ret)		\
167 	TEST_ASSERT_NOT_NULL(f_ret, "Expecting " RTE_STR(f_name)	\
168 			" to return not NULL\n")
169 
170 /**
171  * Verify that sess_cnt counter value matches expected
172  *
173  * @param   expected_sessions_count	expected counter value
174  */
175 #define TEST_ASSERT_SESSION_COUNT(expected_sessions_count) do {		\
176 	struct security_unittest_params *ut_params = &unittest_params;	\
177 	TEST_ASSERT_EQUAL(expected_sessions_count,			\
178 			ut_params->ctx.sess_cnt,			\
179 			"Expecting session counter to be %u,"		\
180 			" but it's %u",	expected_sessions_count,	\
181 			ut_params->ctx.sess_cnt);			\
182 } while (0)
183 
184 /**
185  * Verify usage of mempool by checking if number of allocated objects matches
186  * expectations. The mempool is used to manage objects for sessions data.
187  * A single object is acquired from mempool during session_create
188  * and put back in session_destroy.
189  *
190  * @param   expected_mempool_usage	expected number of used mempool objects
191  */
192 #define TEST_ASSERT_MEMPOOL_USAGE(expected_mempool_usage) do {		\
193 	struct security_testsuite_params *ts_params = &testsuite_params;\
194 	unsigned int mempool_usage;					\
195 	mempool_usage = rte_mempool_in_use_count(			\
196 			ts_params->session_mpool);			\
197 	TEST_ASSERT_EQUAL(expected_mempool_usage, mempool_usage,	\
198 			"Expecting %u mempool allocations, "		\
199 			"but there are %u allocated objects",		\
200 			expected_mempool_usage, mempool_usage);		\
201 } while (0)
202 
203 /**
204  * Verify usage of mempool by checking if number of allocated objects matches
205  * expectations. The mempool is used to manage objects for sessions priv data.
206  * A single object is acquired from mempool during session_create
207  * and put back in session_destroy.
208  *
209  * @param   expected_priv_mp_usage	expected number of used priv mp objects
210  */
211 #define TEST_ASSERT_PRIV_MP_USAGE(expected_priv_mp_usage) do {		\
212 	struct security_testsuite_params *ts_params = &testsuite_params;\
213 	unsigned int priv_mp_usage;					\
214 	priv_mp_usage = rte_mempool_in_use_count(			\
215 			ts_params->session_priv_mpool);			\
216 	TEST_ASSERT_EQUAL(expected_priv_mp_usage, priv_mp_usage,	\
217 			"Expecting %u priv mempool allocations, "	\
218 			"but there are %u allocated objects",		\
219 			expected_priv_mp_usage, priv_mp_usage);		\
220 } while (0)
221 
222 /**
223  * Mockup structures and functions for rte_security_ops;
224  *
225  * Set of structures for controlling mockup functions calls.
226  * Every mockup function X has its corresponding X_data structure
227  * and an instance of that structure X_exp.
228  * Structure contains parameters that a mockup function is expected
229  * to be called with, a value to return (.ret) and 2 statistics:
230  * .called (number of times the mockup function was called)
231  * and .failed (number of assertion fails during mockup function call).
232  *
233  * Mockup functions verify that the parameters they are called with match
234  * expected values. The expected values should be stored in corresponding
235  * structures prior to mockup functions call. Every failure of such
236  * verification increases .failed counter. Every call of mockup function
237  * increases .called counter. Function returns value stored in .ret field
238  * of the structure.
239  * In case of some parameters in some functions the expected value is unknown
240  * and cannot be detrmined prior to call. Such parameters are stored
241  * in structure and can be compared or analyzed later in test case code.
242  *
243  * Below structures and functions follow the rules just described.
244  * Additional remarks and exceptions are added in comments.
245  */
246 
247 /**
248  * session_create mockup
249  *
250  * Verified parameters: device, conf, mp.
251  * Saved, not verified parameters: sess.
252  */
253 static struct mock_session_create_data {
254 	void *device;
255 	struct rte_security_session_conf *conf;
256 	struct rte_security_session *sess;
257 	struct rte_mempool *mp;
258 	struct rte_mempool *priv_mp;
259 
260 	int ret;
261 
262 	int called;
263 	int failed;
264 } mock_session_create_exp = {NULL, NULL, NULL, NULL, NULL, 0, 0, 0};
265 
266 static int
267 mock_session_create(void *device,
268 		struct rte_security_session_conf *conf,
269 		struct rte_security_session *sess,
270 		struct rte_mempool *priv_mp)
271 {
272 	void *sess_priv;
273 	int ret;
274 
275 	mock_session_create_exp.called++;
276 
277 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, device);
278 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, conf);
279 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, priv_mp);
280 
281 	if (mock_session_create_exp.ret == 0) {
282 		ret = rte_mempool_get(priv_mp, &sess_priv);
283 		TEST_ASSERT_EQUAL(0, ret,
284 			"priv mempool does not have enough objects");
285 
286 		set_sec_session_private_data(sess, sess_priv);
287 		mock_session_create_exp.sess = sess;
288 	}
289 
290 	return mock_session_create_exp.ret;
291 }
292 
293 /**
294  * session_update mockup
295  *
296  * Verified parameters: device, sess, conf.
297  */
298 static struct mock_session_update_data {
299 	void *device;
300 	struct rte_security_session *sess;
301 	struct rte_security_session_conf *conf;
302 
303 	int ret;
304 
305 	int called;
306 	int failed;
307 } mock_session_update_exp = {NULL, NULL, NULL, 0, 0, 0};
308 
309 static int
310 mock_session_update(void *device,
311 		struct rte_security_session *sess,
312 		struct rte_security_session_conf *conf)
313 {
314 	mock_session_update_exp.called++;
315 
316 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, device);
317 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, sess);
318 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, conf);
319 
320 	return mock_session_update_exp.ret;
321 }
322 
323 /**
324  * session_get_size mockup
325  *
326  * Verified parameters: device.
327  */
328 static struct mock_session_get_size_data {
329 	void *device;
330 
331 	unsigned int ret;
332 
333 	int called;
334 	int failed;
335 } mock_session_get_size_exp = {NULL, 0U, 0, 0};
336 
337 static unsigned int
338 mock_session_get_size(void *device)
339 {
340 	mock_session_get_size_exp.called++;
341 
342 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_get_size_exp, device);
343 
344 	return mock_session_get_size_exp.ret;
345 }
346 
347 /**
348  * session_stats_get mockup
349  *
350  * Verified parameters: device, sess, stats.
351  */
352 static struct mock_session_stats_get_data {
353 	void *device;
354 	struct rte_security_session *sess;
355 	struct rte_security_stats *stats;
356 
357 	int ret;
358 
359 	int called;
360 	int failed;
361 } mock_session_stats_get_exp = {NULL, NULL, NULL, 0, 0, 0};
362 
363 static int
364 mock_session_stats_get(void *device,
365 		struct rte_security_session *sess,
366 		struct rte_security_stats *stats)
367 {
368 	mock_session_stats_get_exp.called++;
369 
370 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_stats_get_exp, device);
371 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_stats_get_exp, sess);
372 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_stats_get_exp, stats);
373 
374 	return mock_session_stats_get_exp.ret;
375 }
376 
377 /**
378  * session_destroy mockup
379  *
380  * Verified parameters: device, sess.
381  */
382 static struct mock_session_destroy_data {
383 	void *device;
384 	struct rte_security_session *sess;
385 
386 	int ret;
387 
388 	int called;
389 	int failed;
390 } mock_session_destroy_exp = {NULL, NULL, 0, 0, 0};
391 
392 static int
393 mock_session_destroy(void *device, struct rte_security_session *sess)
394 {
395 	void *sess_priv = get_sec_session_private_data(sess);
396 
397 	mock_session_destroy_exp.called++;
398 	if ((mock_session_destroy_exp.ret == 0) && (sess_priv != NULL)) {
399 		rte_mempool_put(rte_mempool_from_obj(sess_priv), sess_priv);
400 		set_sec_session_private_data(sess, NULL);
401 	}
402 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_destroy_exp, device);
403 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_destroy_exp, sess);
404 
405 	return mock_session_destroy_exp.ret;
406 }
407 
408 /**
409  * set_pkt_metadata mockup
410  *
411  * Verified parameters: device, sess, m, params.
412  */
413 static struct mock_set_pkt_metadata_data {
414 	void *device;
415 	struct rte_security_session *sess;
416 	struct rte_mbuf *m;
417 	void *params;
418 
419 	int ret;
420 
421 	int called;
422 	int failed;
423 } mock_set_pkt_metadata_exp = {NULL, NULL, NULL, NULL, 0, 0, 0};
424 
425 static int
426 mock_set_pkt_metadata(void *device,
427 		struct rte_security_session *sess,
428 		struct rte_mbuf *m,
429 		void *params)
430 {
431 	mock_set_pkt_metadata_exp.called++;
432 
433 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, device);
434 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, sess);
435 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, m);
436 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, params);
437 
438 	return mock_set_pkt_metadata_exp.ret;
439 }
440 
441 /**
442  * get_userdata mockup
443  *
444  * Verified parameters: device, md.
445  * The userdata parameter works as an output parameter, so a passed address
446  * is verified not to be NULL and filled with userdata stored in structure.
447  */
448 static struct mock_get_userdata_data {
449 	void *device;
450 	uint64_t md;
451 	void *userdata;
452 
453 	int ret;
454 
455 	int called;
456 	int failed;
457 } mock_get_userdata_exp = {NULL, 0UL, NULL, 0, 0, 0};
458 
459 static int
460 mock_get_userdata(void *device,
461 		uint64_t md,
462 		void **userdata)
463 {
464 	mock_get_userdata_exp.called++;
465 
466 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_get_userdata_exp, device);
467 	MOCK_TEST_ASSERT_U64_PARAMETER(mock_get_userdata_exp, md);
468 
469 	MOCK_TEST_ASSERT_NOT_NULL(mock_get_userdata_exp.failed,
470 			userdata,
471 			"Expecting parameter userdata not to be NULL but it's %p",
472 			userdata);
473 	*userdata = mock_get_userdata_exp.userdata;
474 
475 	return mock_get_userdata_exp.ret;
476 }
477 
478 /**
479  * capabilities_get mockup
480  *
481  * Verified parameters: device.
482  */
483 static struct mock_capabilities_get_data {
484 	void *device;
485 
486 	struct rte_security_capability *ret;
487 
488 	int called;
489 	int failed;
490 } mock_capabilities_get_exp = {NULL, NULL, 0, 0};
491 
492 static const struct rte_security_capability *
493 mock_capabilities_get(void *device)
494 {
495 	mock_capabilities_get_exp.called++;
496 
497 	MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_capabilities_get_exp, device);
498 
499 	return mock_capabilities_get_exp.ret;
500 }
501 
502 /**
503  * empty_ops
504  *
505  * is an empty security operations set (all function pointers set to NULL)
506  */
507 struct rte_security_ops empty_ops = { NULL };
508 
509 /**
510  * mock_ops
511  *
512  * is a security operations set using mockup functions
513  */
514 struct rte_security_ops mock_ops = {
515 	.session_create = mock_session_create,
516 	.session_update = mock_session_update,
517 	.session_get_size = mock_session_get_size,
518 	.session_stats_get = mock_session_stats_get,
519 	.session_destroy = mock_session_destroy,
520 	.set_pkt_metadata = mock_set_pkt_metadata,
521 	.get_userdata = mock_get_userdata,
522 	.capabilities_get = mock_capabilities_get,
523 };
524 
525 
526 /**
527  * Test suite and test cases setup and teardown functions.
528  */
529 
530 /**
531  * struct security_testsuite_params defines parameters initialized once
532  * for whole tests suite.
533  * Currently the only stored parameter is session_mpool a mempool created
534  * once in testsuite_setup and released in testsuite_teardown.
535  * The instance of this structure is stored in testsuite_params variable.
536  */
537 static struct security_testsuite_params {
538 	struct rte_mempool *session_mpool;
539 	struct rte_mempool *session_priv_mpool;
540 } testsuite_params = { NULL };
541 
542 /**
543  * struct security_unittest_params defines parameters initialized
544  * for every test case. The parameters are initialized in ut_setup
545  * or ut_setup_with_session (depending on the testcase)
546  * and released in ut_teardown.
547  * The instance of this structure is stored in unittest_params variable.
548  */
549 static struct security_unittest_params {
550 	struct rte_security_ctx ctx;
551 	struct rte_security_session_conf conf;
552 	struct rte_security_session *sess;
553 } unittest_params = {
554 	.ctx = {
555 		.device = NULL,
556 		.ops = &mock_ops,
557 		.sess_cnt = 0,
558 	},
559 	.sess = NULL,
560 };
561 
562 #define SECURITY_TEST_MEMPOOL_NAME "SecurityTestMp"
563 #define SECURITY_TEST_PRIV_MEMPOOL_NAME "SecurityTestPrivMp"
564 #define SECURITY_TEST_MEMPOOL_SIZE 15
565 #define SECURITY_TEST_SESSION_OBJ_SZ sizeof(struct rte_security_session)
566 #define SECURITY_TEST_SESSION_PRIV_OBJ_SZ 64
567 
568 /**
569  * testsuite_setup initializes whole test suite parameters.
570  * It creates a new mempool used in all test cases
571  * and verifies if it properly created.
572  */
573 static int
574 testsuite_setup(void)
575 {
576 	struct security_testsuite_params *ts_params = &testsuite_params;
577 	ts_params->session_mpool = rte_mempool_create(
578 			SECURITY_TEST_MEMPOOL_NAME,
579 			SECURITY_TEST_MEMPOOL_SIZE,
580 			SECURITY_TEST_SESSION_OBJ_SZ,
581 			0, 0, NULL, NULL, NULL, NULL,
582 			SOCKET_ID_ANY, 0);
583 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
584 			"Cannot create mempool %s\n", rte_strerror(rte_errno));
585 
586 	ts_params->session_priv_mpool = rte_mempool_create(
587 			SECURITY_TEST_PRIV_MEMPOOL_NAME,
588 			SECURITY_TEST_MEMPOOL_SIZE,
589 			SECURITY_TEST_SESSION_PRIV_OBJ_SZ,
590 			0, 0, NULL, NULL, NULL, NULL,
591 			SOCKET_ID_ANY, 0);
592 	if (ts_params->session_priv_mpool == NULL) {
593 		RTE_LOG(ERR, USER1, "TestCase %s() line %d failed (null): "
594 				"Cannot create priv mempool %s\n",
595 				__func__, __LINE__, rte_strerror(rte_errno));
596 		rte_mempool_free(ts_params->session_mpool);
597 		ts_params->session_mpool = NULL;
598 		return TEST_FAILED;
599 	}
600 
601 	return TEST_SUCCESS;
602 }
603 
604 /**
605  * testsuite_teardown releases test suite wide parameters.
606  */
607 static void
608 testsuite_teardown(void)
609 {
610 	struct security_testsuite_params *ts_params = &testsuite_params;
611 	if (ts_params->session_mpool) {
612 		rte_mempool_free(ts_params->session_mpool);
613 		ts_params->session_mpool = NULL;
614 	}
615 	if (ts_params->session_priv_mpool) {
616 		rte_mempool_free(ts_params->session_priv_mpool);
617 		ts_params->session_priv_mpool = NULL;
618 	}
619 }
620 
621 /**
622  * ut_setup initializes test case parameters to default values.
623  * It resets also any .called and .failed statistics of mockup functions
624  * usage.
625  */
626 static int
627 ut_setup(void)
628 {
629 	struct security_unittest_params *ut_params = &unittest_params;
630 	ut_params->ctx.device = NULL;
631 	ut_params->ctx.ops = &mock_ops;
632 	ut_params->ctx.sess_cnt = 0;
633 	ut_params->sess = NULL;
634 
635 	mock_session_create_exp.called = 0;
636 	mock_session_update_exp.called = 0;
637 	mock_session_get_size_exp.called = 0;
638 	mock_session_stats_get_exp.called = 0;
639 	mock_session_destroy_exp.called = 0;
640 	mock_set_pkt_metadata_exp.called = 0;
641 	mock_get_userdata_exp.called = 0;
642 	mock_capabilities_get_exp.called = 0;
643 
644 	mock_session_create_exp.failed = 0;
645 	mock_session_update_exp.failed = 0;
646 	mock_session_get_size_exp.failed = 0;
647 	mock_session_stats_get_exp.failed = 0;
648 	mock_session_destroy_exp.failed = 0;
649 	mock_set_pkt_metadata_exp.failed = 0;
650 	mock_get_userdata_exp.failed = 0;
651 	mock_capabilities_get_exp.failed = 0;
652 
653 	return TEST_SUCCESS;
654 }
655 
656 /**
657  * destroy_session_with_check is a helper function releasing session
658  * created with rte_security_session_create and stored in test case parameters.
659  * It's used both to release sessions created in test cases' bodies
660  * which are assigned to ut_params->sess
661  * as well as sessions created in ut_setup_with_session.
662  */
663 static int
664 destroy_session_with_check(void)
665 {
666 	struct security_unittest_params *ut_params = &unittest_params;
667 	if (ut_params->sess != NULL) {
668 		/* Assure that mockup function for destroy operation is set. */
669 		ut_params->ctx.ops = &mock_ops;
670 
671 		mock_session_destroy_exp.device = NULL;
672 		mock_session_destroy_exp.sess = ut_params->sess;
673 		mock_session_destroy_exp.ret = 0;
674 		mock_session_destroy_exp.called = 0;
675 		mock_session_destroy_exp.failed = 0;
676 
677 		int ret = rte_security_session_destroy(&ut_params->ctx,
678 				ut_params->sess);
679 		TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
680 				ret, 0, "%d");
681 		TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
682 
683 		ut_params->sess = NULL;
684 	}
685 	return TEST_SUCCESS;
686 }
687 
688 /**
689  * ut_teardown releases test case parameters.
690  */
691 static void
692 ut_teardown(void)
693 {
694 	destroy_session_with_check();
695 }
696 
697 /**
698  * ut_setup_with_session initializes test case parameters by
699  * - calling standard ut_setup,
700  * - creating a session that can be used in test case.
701  */
702 static int
703 ut_setup_with_session(void)
704 {
705 	struct security_unittest_params *ut_params = &unittest_params;
706 	struct security_testsuite_params *ts_params = &testsuite_params;
707 	struct rte_security_session *sess;
708 
709 	int ret = ut_setup();
710 	if (ret != TEST_SUCCESS)
711 		return ret;
712 
713 	mock_session_create_exp.device = NULL;
714 	mock_session_create_exp.conf = &ut_params->conf;
715 	mock_session_create_exp.mp = ts_params->session_mpool;
716 	mock_session_create_exp.priv_mp = ts_params->session_priv_mpool;
717 	mock_session_create_exp.ret = 0;
718 
719 	sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
720 			ts_params->session_mpool,
721 			ts_params->session_priv_mpool);
722 	TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(rte_security_session_create,
723 			sess);
724 	TEST_ASSERT_EQUAL(sess, mock_session_create_exp.sess,
725 			"Expecting session_create to be called with %p sess"
726 			" parameter, but it's called %p sess parameter",
727 			sess, mock_session_create_exp.sess);
728 	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
729 
730 	/*
731 	 * Store created session in test case parameters, so it can be released
732 	 * after test case in ut_teardown by destroy_session_with_check.
733 	 */
734 	ut_params->sess = sess;
735 
736 	return TEST_SUCCESS;
737 }
738 
739 
740 /**
741  * Test functions
742  *
743  * Each test function is related to a single test case.
744  * They are arranged by tested rte_security API function
745  * and by rte_security execution paths sequence in code.
746  */
747 
748 /**
749  * rte_security_session_create tests
750  */
751 
752 /**
753  * Test execution of rte_security_session_create with NULL instance
754  */
755 static int
756 test_session_create_inv_context(void)
757 {
758 	struct security_testsuite_params *ts_params = &testsuite_params;
759 	struct security_unittest_params *ut_params = &unittest_params;
760 	struct rte_security_session *sess;
761 
762 	sess = rte_security_session_create(NULL, &ut_params->conf,
763 			ts_params->session_mpool,
764 			ts_params->session_priv_mpool);
765 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
766 			sess, NULL, "%p");
767 	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
768 	TEST_ASSERT_MEMPOOL_USAGE(0);
769 	TEST_ASSERT_PRIV_MP_USAGE(0);
770 	TEST_ASSERT_SESSION_COUNT(0);
771 
772 	return TEST_SUCCESS;
773 }
774 
775 /**
776  * Test execution of rte_security_session_create with invalid
777  * security operations structure (NULL)
778  */
779 static int
780 test_session_create_inv_context_ops(void)
781 {
782 	struct security_testsuite_params *ts_params = &testsuite_params;
783 	struct security_unittest_params *ut_params = &unittest_params;
784 	struct rte_security_session *sess;
785 
786 	ut_params->ctx.ops = NULL;
787 
788 	sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
789 			ts_params->session_mpool,
790 			ts_params->session_priv_mpool);
791 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
792 			sess, NULL, "%p");
793 	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
794 	TEST_ASSERT_MEMPOOL_USAGE(0);
795 	TEST_ASSERT_PRIV_MP_USAGE(0);
796 	TEST_ASSERT_SESSION_COUNT(0);
797 
798 	return TEST_SUCCESS;
799 }
800 
801 /**
802  * Test execution of rte_security_session_create with empty
803  * security operations
804  */
805 static int
806 test_session_create_inv_context_ops_fun(void)
807 {
808 	struct security_testsuite_params *ts_params = &testsuite_params;
809 	struct security_unittest_params *ut_params = &unittest_params;
810 	struct rte_security_session *sess;
811 
812 	ut_params->ctx.ops = &empty_ops;
813 
814 	sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
815 			ts_params->session_mpool,
816 			ts_params->session_priv_mpool);
817 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
818 			sess, NULL, "%p");
819 	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
820 	TEST_ASSERT_MEMPOOL_USAGE(0);
821 	TEST_ASSERT_PRIV_MP_USAGE(0);
822 	TEST_ASSERT_SESSION_COUNT(0);
823 
824 	return TEST_SUCCESS;
825 }
826 
827 /**
828  * Test execution of rte_security_session_create with NULL conf parameter
829  */
830 static int
831 test_session_create_inv_configuration(void)
832 {
833 	struct security_testsuite_params *ts_params = &testsuite_params;
834 	struct security_unittest_params *ut_params = &unittest_params;
835 	struct rte_security_session *sess;
836 
837 	sess = rte_security_session_create(&ut_params->ctx, NULL,
838 			ts_params->session_mpool,
839 			ts_params->session_priv_mpool);
840 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
841 			sess, NULL, "%p");
842 	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
843 	TEST_ASSERT_MEMPOOL_USAGE(0);
844 	TEST_ASSERT_PRIV_MP_USAGE(0);
845 	TEST_ASSERT_SESSION_COUNT(0);
846 
847 	return TEST_SUCCESS;
848 }
849 
850 /**
851  * Test execution of rte_security_session_create with NULL session
852  * mempool
853  */
854 static int
855 test_session_create_inv_mempool(void)
856 {
857 	struct security_unittest_params *ut_params = &unittest_params;
858 	struct security_testsuite_params *ts_params = &testsuite_params;
859 	struct rte_security_session *sess;
860 
861 	sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
862 			NULL, ts_params->session_priv_mpool);
863 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
864 			sess, NULL, "%p");
865 	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
866 	TEST_ASSERT_MEMPOOL_USAGE(0);
867 	TEST_ASSERT_PRIV_MP_USAGE(0);
868 	TEST_ASSERT_SESSION_COUNT(0);
869 
870 	return TEST_SUCCESS;
871 }
872 
873 /**
874  * Test execution of rte_security_session_create with NULL session
875  * priv mempool
876  */
877 static int
878 test_session_create_inv_sess_priv_mempool(void)
879 {
880 	struct security_unittest_params *ut_params = &unittest_params;
881 	struct security_testsuite_params *ts_params = &testsuite_params;
882 	struct rte_security_session *sess;
883 
884 	sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
885 			ts_params->session_mpool, NULL);
886 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
887 			sess, NULL, "%p");
888 	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
889 	TEST_ASSERT_MEMPOOL_USAGE(0);
890 	TEST_ASSERT_PRIV_MP_USAGE(0);
891 	TEST_ASSERT_SESSION_COUNT(0);
892 
893 	return TEST_SUCCESS;
894 }
895 
896 /**
897  * Test execution of rte_security_session_create in case when mempool
898  * is fully used and no object can be got from it
899  */
900 static int
901 test_session_create_mempool_empty(void)
902 {
903 	struct security_testsuite_params *ts_params = &testsuite_params;
904 	struct security_unittest_params *ut_params = &unittest_params;
905 	struct rte_security_session *tmp[SECURITY_TEST_MEMPOOL_SIZE];
906 	void *tmp1[SECURITY_TEST_MEMPOOL_SIZE];
907 	struct rte_security_session *sess;
908 
909 	/* Get all available objects from mempool. */
910 	int i, ret;
911 	for (i = 0; i < SECURITY_TEST_MEMPOOL_SIZE; ++i) {
912 		ret = rte_mempool_get(ts_params->session_mpool,
913 				(void **)(&tmp[i]));
914 		TEST_ASSERT_EQUAL(0, ret,
915 				"Expect getting %d object from mempool"
916 				" to succeed", i);
917 		ret = rte_mempool_get(ts_params->session_priv_mpool,
918 				(void **)(&tmp1[i]));
919 		TEST_ASSERT_EQUAL(0, ret,
920 				"Expect getting %d object from priv mempool"
921 				" to succeed", i);
922 	}
923 	TEST_ASSERT_MEMPOOL_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
924 	TEST_ASSERT_PRIV_MP_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
925 
926 	sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
927 			ts_params->session_mpool,
928 			ts_params->session_priv_mpool);
929 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
930 			sess, NULL, "%p");
931 	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0);
932 	TEST_ASSERT_MEMPOOL_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
933 	TEST_ASSERT_PRIV_MP_USAGE(SECURITY_TEST_MEMPOOL_SIZE);
934 	TEST_ASSERT_SESSION_COUNT(0);
935 
936 	/* Put objects back to the pool. */
937 	for (i = 0; i < SECURITY_TEST_MEMPOOL_SIZE; ++i) {
938 		rte_mempool_put(ts_params->session_mpool,
939 				(void *)(tmp[i]));
940 		rte_mempool_put(ts_params->session_priv_mpool,
941 				(tmp1[i]));
942 	}
943 	TEST_ASSERT_MEMPOOL_USAGE(0);
944 	TEST_ASSERT_PRIV_MP_USAGE(0);
945 
946 	return TEST_SUCCESS;
947 }
948 
949 /**
950  * Test execution of rte_security_session_create when session_create
951  * security operation fails
952  */
953 static int
954 test_session_create_ops_failure(void)
955 {
956 	struct security_testsuite_params *ts_params = &testsuite_params;
957 	struct security_unittest_params *ut_params = &unittest_params;
958 	struct rte_security_session *sess;
959 
960 	mock_session_create_exp.device = NULL;
961 	mock_session_create_exp.conf = &ut_params->conf;
962 	mock_session_create_exp.mp = ts_params->session_mpool;
963 	mock_session_create_exp.priv_mp = ts_params->session_priv_mpool;
964 	mock_session_create_exp.ret = -1;	/* Return failure status. */
965 
966 	sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
967 			ts_params->session_mpool,
968 			ts_params->session_priv_mpool);
969 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create,
970 			sess, NULL, "%p");
971 	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
972 	TEST_ASSERT_MEMPOOL_USAGE(0);
973 	TEST_ASSERT_PRIV_MP_USAGE(0);
974 	TEST_ASSERT_SESSION_COUNT(0);
975 
976 	return TEST_SUCCESS;
977 }
978 
979 /**
980  * Test execution of rte_security_session_create in successful execution path
981  */
982 static int
983 test_session_create_success(void)
984 {
985 	struct security_testsuite_params *ts_params = &testsuite_params;
986 	struct security_unittest_params *ut_params = &unittest_params;
987 	struct rte_security_session *sess;
988 
989 	mock_session_create_exp.device = NULL;
990 	mock_session_create_exp.conf = &ut_params->conf;
991 	mock_session_create_exp.mp = ts_params->session_mpool;
992 	mock_session_create_exp.priv_mp = ts_params->session_priv_mpool;
993 	mock_session_create_exp.ret = 0;	/* Return success status. */
994 
995 	sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf,
996 			ts_params->session_mpool,
997 			ts_params->session_priv_mpool);
998 	TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(rte_security_session_create,
999 			sess);
1000 	TEST_ASSERT_EQUAL(sess, mock_session_create_exp.sess,
1001 			"Expecting session_create to be called with %p sess"
1002 			" parameter, but it's called %p sess parameter",
1003 			sess, mock_session_create_exp.sess);
1004 	TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1);
1005 	TEST_ASSERT_MEMPOOL_USAGE(1);
1006 	TEST_ASSERT_PRIV_MP_USAGE(1);
1007 	TEST_ASSERT_SESSION_COUNT(1);
1008 
1009 	/*
1010 	 * Store created session in test case parameters, so it can be released
1011 	 * after test case in ut_teardown by destroy_session_with_check.
1012 	 */
1013 	ut_params->sess = sess;
1014 
1015 	return TEST_SUCCESS;
1016 }
1017 
1018 
1019 /**
1020  * rte_security_session_update tests
1021  */
1022 
1023 /**
1024  * Test execution of rte_security_session_update with NULL instance
1025  */
1026 static int
1027 test_session_update_inv_context(void)
1028 {
1029 	struct security_unittest_params *ut_params = &unittest_params;
1030 
1031 	int ret = rte_security_session_update(NULL, ut_params->sess,
1032 			&ut_params->conf);
1033 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1034 			ret, -EINVAL, "%d");
1035 	TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
1036 
1037 	return TEST_SUCCESS;
1038 }
1039 
1040 /**
1041  * Test execution of rte_security_session_update with invalid
1042  * security operations structure (NULL)
1043  */
1044 static int
1045 test_session_update_inv_context_ops(void)
1046 {
1047 	struct security_unittest_params *ut_params = &unittest_params;
1048 	ut_params->ctx.ops = NULL;
1049 
1050 	int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
1051 			&ut_params->conf);
1052 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1053 			ret, -EINVAL, "%d");
1054 	TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
1055 
1056 	return TEST_SUCCESS;
1057 }
1058 
1059 /**
1060  * Test execution of rte_security_session_update with empty
1061  * security operations
1062  */
1063 static int
1064 test_session_update_inv_context_ops_fun(void)
1065 {
1066 	struct security_unittest_params *ut_params = &unittest_params;
1067 	ut_params->ctx.ops = &empty_ops;
1068 
1069 	int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
1070 			&ut_params->conf);
1071 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1072 			ret, -ENOTSUP, "%d");
1073 	TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
1074 
1075 	return TEST_SUCCESS;
1076 }
1077 
1078 /**
1079  * Test execution of rte_security_session_update with NULL conf parameter
1080  */
1081 static int
1082 test_session_update_inv_configuration(void)
1083 {
1084 	struct security_unittest_params *ut_params = &unittest_params;
1085 
1086 	int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
1087 			NULL);
1088 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1089 			ret, -EINVAL, "%d");
1090 	TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
1091 
1092 	return TEST_SUCCESS;
1093 }
1094 
1095 /**
1096  * Test execution of rte_security_session_update with NULL sess parameter
1097  */
1098 static int
1099 test_session_update_inv_session(void)
1100 {
1101 	struct security_unittest_params *ut_params = &unittest_params;
1102 
1103 	int ret = rte_security_session_update(&ut_params->ctx, NULL,
1104 			&ut_params->conf);
1105 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1106 			ret, -EINVAL, "%d");
1107 	TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0);
1108 
1109 	return TEST_SUCCESS;
1110 }
1111 
1112 /**
1113  * Test execution of rte_security_session_update when session_update
1114  * security operation fails
1115  */
1116 static int
1117 test_session_update_ops_failure(void)
1118 {
1119 	struct security_unittest_params *ut_params = &unittest_params;
1120 
1121 	mock_session_update_exp.device = NULL;
1122 	mock_session_update_exp.sess = ut_params->sess;
1123 	mock_session_update_exp.conf = &ut_params->conf;
1124 	mock_session_update_exp.ret = -1;	/* Return failure status. */
1125 
1126 	int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
1127 			&ut_params->conf);
1128 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1129 			ret, -1, "%d");
1130 	TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 1);
1131 
1132 	return TEST_SUCCESS;
1133 }
1134 
1135 /**
1136  * Test execution of rte_security_session_update in successful execution path
1137  */
1138 static int
1139 test_session_update_success(void)
1140 {
1141 	struct security_unittest_params *ut_params = &unittest_params;
1142 
1143 	mock_session_update_exp.device = NULL;
1144 	mock_session_update_exp.sess = ut_params->sess;
1145 	mock_session_update_exp.conf = &ut_params->conf;
1146 	mock_session_update_exp.ret = 0;	/* Return success status. */
1147 
1148 	int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess,
1149 			&ut_params->conf);
1150 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update,
1151 			ret, 0, "%d");
1152 	TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 1);
1153 
1154 	return TEST_SUCCESS;
1155 }
1156 
1157 
1158 /**
1159  * rte_security_session_get_size tests
1160  */
1161 
1162 /**
1163  * Test execution of rte_security_session_get_size with NULL instance
1164  */
1165 static int
1166 test_session_get_size_inv_context(void)
1167 {
1168 	unsigned int ret = rte_security_session_get_size(NULL);
1169 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1170 			ret, 0, "%u");
1171 	TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
1172 
1173 	return TEST_SUCCESS;
1174 }
1175 
1176 /**
1177  * Test execution of rte_security_session_get_size with invalid
1178  * security operations structure (NULL)
1179  */
1180 static int
1181 test_session_get_size_inv_context_ops(void)
1182 {
1183 	struct security_unittest_params *ut_params = &unittest_params;
1184 	ut_params->ctx.ops = NULL;
1185 
1186 	unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1187 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1188 			ret, 0, "%u");
1189 	TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
1190 
1191 	return TEST_SUCCESS;
1192 }
1193 
1194 /**
1195  * Test execution of rte_security_session_get_size with empty
1196  * security operations
1197  */
1198 static int
1199 test_session_get_size_inv_context_ops_fun(void)
1200 {
1201 	struct security_unittest_params *ut_params = &unittest_params;
1202 	ut_params->ctx.ops = &empty_ops;
1203 
1204 	unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1205 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1206 			ret, 0, "%u");
1207 	TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0);
1208 
1209 	return TEST_SUCCESS;
1210 }
1211 
1212 /**
1213  * Test execution of rte_security_session_get_size when session_get_size
1214  * security operation fails
1215  */
1216 static int
1217 test_session_get_size_ops_failure(void)
1218 {
1219 	struct security_unittest_params *ut_params = &unittest_params;
1220 
1221 	mock_session_get_size_exp.device = NULL;
1222 	mock_session_get_size_exp.ret = 0;
1223 
1224 	unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1225 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1226 			ret, 0, "%u");
1227 	TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 1);
1228 
1229 	return TEST_SUCCESS;
1230 }
1231 
1232 /**
1233  * Test execution of rte_security_session_get_size in successful execution path
1234  */
1235 static int
1236 test_session_get_size_success(void)
1237 {
1238 	struct security_unittest_params *ut_params = &unittest_params;
1239 
1240 	mock_session_get_size_exp.device = NULL;
1241 	mock_session_get_size_exp.ret = 1024;
1242 
1243 	unsigned int ret = rte_security_session_get_size(&ut_params->ctx);
1244 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size,
1245 			ret, 1024U, "%u");
1246 	TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 1);
1247 
1248 	return TEST_SUCCESS;
1249 }
1250 
1251 
1252 /**
1253  * rte_security_session_stats_get tests
1254  */
1255 
1256 /**
1257  * Test execution of rte_security_session_stats_get with NULL instance
1258  */
1259 static int
1260 test_session_stats_get_inv_context(void)
1261 {
1262 	struct security_unittest_params *ut_params = &unittest_params;
1263 	struct rte_security_stats stats;
1264 
1265 	int ret = rte_security_session_stats_get(NULL, ut_params->sess, &stats);
1266 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1267 			ret, -EINVAL, "%d");
1268 	TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1269 
1270 	return TEST_SUCCESS;
1271 }
1272 
1273 /**
1274  * Test execution of rte_security_session_stats_get with invalid
1275  * security operations structure (NULL)
1276  */
1277 static int
1278 test_session_stats_get_inv_context_ops(void)
1279 {
1280 	struct security_unittest_params *ut_params = &unittest_params;
1281 	struct rte_security_stats stats;
1282 	ut_params->ctx.ops = NULL;
1283 
1284 	int ret = rte_security_session_stats_get(&ut_params->ctx,
1285 			ut_params->sess, &stats);
1286 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1287 			ret, -EINVAL, "%d");
1288 	TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1289 
1290 	return TEST_SUCCESS;
1291 }
1292 
1293 /**
1294  * Test execution of rte_security_session_stats_get with empty
1295  * security operations
1296  */
1297 static int
1298 test_session_stats_get_inv_context_ops_fun(void)
1299 {
1300 	struct security_unittest_params *ut_params = &unittest_params;
1301 	struct rte_security_stats stats;
1302 	ut_params->ctx.ops = &empty_ops;
1303 
1304 	int ret = rte_security_session_stats_get(&ut_params->ctx,
1305 			ut_params->sess, &stats);
1306 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1307 			ret, -ENOTSUP, "%d");
1308 	TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1309 
1310 	return TEST_SUCCESS;
1311 }
1312 
1313 /**
1314  * Test execution of rte_security_session_stats_get with NULL stats parameter
1315  */
1316 static int
1317 test_session_stats_get_inv_stats(void)
1318 {
1319 	struct security_unittest_params *ut_params = &unittest_params;
1320 
1321 	int ret = rte_security_session_stats_get(&ut_params->ctx,
1322 			ut_params->sess, NULL);
1323 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1324 			ret, -EINVAL, "%d");
1325 	TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0);
1326 
1327 	return TEST_SUCCESS;
1328 }
1329 
1330 /**
1331  * Test execution of rte_security_session_stats_get when session_stats_get
1332  * security operation fails
1333  */
1334 static int
1335 test_session_stats_get_ops_failure(void)
1336 {
1337 	struct security_unittest_params *ut_params = &unittest_params;
1338 	struct rte_security_stats stats;
1339 
1340 	mock_session_stats_get_exp.device = NULL;
1341 	mock_session_stats_get_exp.sess = ut_params->sess;
1342 	mock_session_stats_get_exp.stats = &stats;
1343 	mock_session_stats_get_exp.ret = -1;
1344 
1345 	int ret = rte_security_session_stats_get(&ut_params->ctx,
1346 			ut_params->sess, &stats);
1347 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1348 			ret, -1, "%d");
1349 	TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 1);
1350 
1351 	return TEST_SUCCESS;
1352 }
1353 
1354 /**
1355  * Test execution of rte_security_session_stats_get in successful execution
1356  * path
1357  */
1358 static int
1359 test_session_stats_get_success(void)
1360 {
1361 	struct security_unittest_params *ut_params = &unittest_params;
1362 	struct rte_security_stats stats;
1363 
1364 	mock_session_stats_get_exp.device = NULL;
1365 	mock_session_stats_get_exp.sess = ut_params->sess;
1366 	mock_session_stats_get_exp.stats = &stats;
1367 	mock_session_stats_get_exp.ret = 0;
1368 
1369 	int ret = rte_security_session_stats_get(&ut_params->ctx,
1370 			ut_params->sess, &stats);
1371 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get,
1372 			ret, 0, "%d");
1373 	TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 1);
1374 
1375 	return TEST_SUCCESS;
1376 }
1377 
1378 
1379 /**
1380  * rte_security_session_destroy tests
1381  */
1382 
1383 /**
1384  * Test execution of rte_security_session_destroy with NULL instance
1385  */
1386 static int
1387 test_session_destroy_inv_context(void)
1388 {
1389 	struct security_unittest_params *ut_params = &unittest_params;
1390 
1391 	TEST_ASSERT_MEMPOOL_USAGE(1);
1392 	TEST_ASSERT_PRIV_MP_USAGE(1);
1393 	TEST_ASSERT_SESSION_COUNT(1);
1394 
1395 	int ret = rte_security_session_destroy(NULL, ut_params->sess);
1396 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1397 			ret, -EINVAL, "%d");
1398 	TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1399 	TEST_ASSERT_MEMPOOL_USAGE(1);
1400 	TEST_ASSERT_PRIV_MP_USAGE(1);
1401 	TEST_ASSERT_SESSION_COUNT(1);
1402 
1403 	return TEST_SUCCESS;
1404 }
1405 
1406 /**
1407  * Test execution of rte_security_session_destroy with invalid
1408  * security operations structure (NULL)
1409  */
1410 static int
1411 test_session_destroy_inv_context_ops(void)
1412 {
1413 	struct security_unittest_params *ut_params = &unittest_params;
1414 	ut_params->ctx.ops = NULL;
1415 
1416 	TEST_ASSERT_MEMPOOL_USAGE(1);
1417 	TEST_ASSERT_PRIV_MP_USAGE(1);
1418 	TEST_ASSERT_SESSION_COUNT(1);
1419 
1420 	int ret = rte_security_session_destroy(&ut_params->ctx,
1421 			ut_params->sess);
1422 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1423 			ret, -EINVAL, "%d");
1424 	TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1425 	TEST_ASSERT_MEMPOOL_USAGE(1);
1426 	TEST_ASSERT_PRIV_MP_USAGE(1);
1427 	TEST_ASSERT_SESSION_COUNT(1);
1428 
1429 	return TEST_SUCCESS;
1430 }
1431 
1432 /**
1433  * Test execution of rte_security_session_destroy with empty
1434  * security operations
1435  */
1436 static int
1437 test_session_destroy_inv_context_ops_fun(void)
1438 {
1439 	struct security_unittest_params *ut_params = &unittest_params;
1440 	ut_params->ctx.ops = &empty_ops;
1441 
1442 	TEST_ASSERT_MEMPOOL_USAGE(1);
1443 	TEST_ASSERT_PRIV_MP_USAGE(1);
1444 	TEST_ASSERT_SESSION_COUNT(1);
1445 
1446 	int ret = rte_security_session_destroy(&ut_params->ctx,
1447 			ut_params->sess);
1448 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1449 			ret, -ENOTSUP, "%d");
1450 	TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1451 	TEST_ASSERT_MEMPOOL_USAGE(1);
1452 	TEST_ASSERT_PRIV_MP_USAGE(1);
1453 	TEST_ASSERT_SESSION_COUNT(1);
1454 
1455 	return TEST_SUCCESS;
1456 }
1457 
1458 /**
1459  * Test execution of rte_security_session_destroy with NULL sess parameter
1460  */
1461 static int
1462 test_session_destroy_inv_session(void)
1463 {
1464 	struct security_unittest_params *ut_params = &unittest_params;
1465 
1466 	TEST_ASSERT_MEMPOOL_USAGE(1);
1467 	TEST_ASSERT_PRIV_MP_USAGE(1);
1468 	TEST_ASSERT_SESSION_COUNT(1);
1469 
1470 	int ret = rte_security_session_destroy(&ut_params->ctx, NULL);
1471 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1472 			ret, -EINVAL, "%d");
1473 	TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0);
1474 	TEST_ASSERT_MEMPOOL_USAGE(1);
1475 	TEST_ASSERT_PRIV_MP_USAGE(1);
1476 	TEST_ASSERT_SESSION_COUNT(1);
1477 
1478 	return TEST_SUCCESS;
1479 }
1480 
1481 /**
1482  * Test execution of rte_security_session_destroy when session_destroy
1483  * security operation fails
1484  */
1485 static int
1486 test_session_destroy_ops_failure(void)
1487 {
1488 	struct security_unittest_params *ut_params = &unittest_params;
1489 
1490 	mock_session_destroy_exp.device = NULL;
1491 	mock_session_destroy_exp.sess = ut_params->sess;
1492 	mock_session_destroy_exp.ret = -1;
1493 
1494 	TEST_ASSERT_MEMPOOL_USAGE(1);
1495 	TEST_ASSERT_PRIV_MP_USAGE(1);
1496 	TEST_ASSERT_SESSION_COUNT(1);
1497 
1498 	int ret = rte_security_session_destroy(&ut_params->ctx,
1499 			ut_params->sess);
1500 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1501 			ret, -1, "%d");
1502 	TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
1503 	TEST_ASSERT_MEMPOOL_USAGE(1);
1504 	TEST_ASSERT_PRIV_MP_USAGE(1);
1505 	TEST_ASSERT_SESSION_COUNT(1);
1506 
1507 	return TEST_SUCCESS;
1508 }
1509 
1510 /**
1511  * Test execution of rte_security_session_destroy in successful execution path
1512  */
1513 static int
1514 test_session_destroy_success(void)
1515 {
1516 	struct security_unittest_params *ut_params = &unittest_params;
1517 
1518 	mock_session_destroy_exp.device = NULL;
1519 	mock_session_destroy_exp.sess = ut_params->sess;
1520 	mock_session_destroy_exp.ret = 0;
1521 	TEST_ASSERT_MEMPOOL_USAGE(1);
1522 	TEST_ASSERT_PRIV_MP_USAGE(1);
1523 	TEST_ASSERT_SESSION_COUNT(1);
1524 
1525 	int ret = rte_security_session_destroy(&ut_params->ctx,
1526 			ut_params->sess);
1527 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy,
1528 			ret, 0, "%d");
1529 	TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1);
1530 	TEST_ASSERT_MEMPOOL_USAGE(0);
1531 	TEST_ASSERT_PRIV_MP_USAGE(0);
1532 	TEST_ASSERT_SESSION_COUNT(0);
1533 
1534 	/*
1535 	 * Remove session from test case parameters, so it won't be destroyed
1536 	 * during test case teardown.
1537 	 */
1538 	ut_params->sess = NULL;
1539 
1540 	return TEST_SUCCESS;
1541 }
1542 
1543 
1544 /**
1545  * rte_security_set_pkt_metadata tests
1546  */
1547 
1548 /**
1549  * Test execution of rte_security_set_pkt_metadata with NULL instance
1550  */
1551 static int
1552 test_set_pkt_metadata_inv_context(void)
1553 {
1554 #ifdef RTE_DEBUG
1555 	struct security_unittest_params *ut_params = &unittest_params;
1556 	struct rte_mbuf m;
1557 	int params;
1558 
1559 	int ret = rte_security_set_pkt_metadata(NULL, ut_params->sess, &m,
1560 			&params);
1561 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1562 			ret, -EINVAL, "%d");
1563 	TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1564 
1565 	return TEST_SUCCESS;
1566 #else
1567 	return TEST_SKIPPED;
1568 #endif
1569 }
1570 
1571 /**
1572  * Test execution of rte_security_set_pkt_metadata with invalid
1573  * security operations structure (NULL)
1574  */
1575 static int
1576 test_set_pkt_metadata_inv_context_ops(void)
1577 {
1578 #ifdef RTE_DEBUG
1579 	struct security_unittest_params *ut_params = &unittest_params;
1580 	struct rte_mbuf m;
1581 	int params;
1582 	ut_params->ctx.ops = NULL;
1583 
1584 	int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1585 			ut_params->sess, &m, &params);
1586 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1587 			ret, -EINVAL, "%d");
1588 	TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1589 
1590 	return TEST_SUCCESS;
1591 #else
1592 	return TEST_SKIPPED;
1593 #endif
1594 }
1595 
1596 /**
1597  * Test execution of rte_security_set_pkt_metadata with empty
1598  * security operations
1599  */
1600 static int
1601 test_set_pkt_metadata_inv_context_ops_fun(void)
1602 {
1603 	struct security_unittest_params *ut_params = &unittest_params;
1604 	struct rte_mbuf m;
1605 	int params;
1606 	ut_params->ctx.ops = &empty_ops;
1607 
1608 	int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1609 			ut_params->sess, &m, &params);
1610 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1611 			ret, -ENOTSUP, "%d");
1612 	TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1613 
1614 	return TEST_SUCCESS;
1615 }
1616 
1617 /**
1618  * Test execution of rte_security_set_pkt_metadata with NULL sess parameter
1619  */
1620 static int
1621 test_set_pkt_metadata_inv_session(void)
1622 {
1623 #ifdef RTE_DEBUG
1624 	struct security_unittest_params *ut_params = &unittest_params;
1625 	struct rte_mbuf m;
1626 	int params;
1627 
1628 	int ret = rte_security_set_pkt_metadata(&ut_params->ctx, NULL,
1629 			&m, &params);
1630 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1631 			ret, -EINVAL, "%d");
1632 	TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0);
1633 
1634 	return TEST_SUCCESS;
1635 #else
1636 	return TEST_SKIPPED;
1637 #endif
1638 }
1639 
1640 /**
1641  * Test execution of rte_security_set_pkt_metadata when set_pkt_metadata
1642  * security operation fails
1643  */
1644 static int
1645 test_set_pkt_metadata_ops_failure(void)
1646 {
1647 	struct security_unittest_params *ut_params = &unittest_params;
1648 	struct rte_mbuf m;
1649 	int params;
1650 
1651 	mock_set_pkt_metadata_exp.device = NULL;
1652 	mock_set_pkt_metadata_exp.sess = ut_params->sess;
1653 	mock_set_pkt_metadata_exp.m = &m;
1654 	mock_set_pkt_metadata_exp.params = &params;
1655 	mock_set_pkt_metadata_exp.ret = -1;
1656 
1657 	int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1658 			ut_params->sess, &m, &params);
1659 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1660 			ret, -1, "%d");
1661 	TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 1);
1662 
1663 	return TEST_SUCCESS;
1664 }
1665 
1666 /**
1667  * Test execution of rte_security_set_pkt_metadata in successful execution path
1668  */
1669 static int
1670 test_set_pkt_metadata_success(void)
1671 {
1672 	struct security_unittest_params *ut_params = &unittest_params;
1673 	struct rte_mbuf m;
1674 	int params;
1675 
1676 	mock_set_pkt_metadata_exp.device = NULL;
1677 	mock_set_pkt_metadata_exp.sess = ut_params->sess;
1678 	mock_set_pkt_metadata_exp.m = &m;
1679 	mock_set_pkt_metadata_exp.params = &params;
1680 	mock_set_pkt_metadata_exp.ret = 0;
1681 
1682 	int ret = rte_security_set_pkt_metadata(&ut_params->ctx,
1683 			ut_params->sess, &m, &params);
1684 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata,
1685 			ret, 0, "%d");
1686 	TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 1);
1687 
1688 	return TEST_SUCCESS;
1689 }
1690 
1691 
1692 /**
1693  * rte_security_get_userdata tests
1694  */
1695 
1696 /**
1697  * Test execution of rte_security_get_userdata with NULL instance
1698  */
1699 static int
1700 test_get_userdata_inv_context(void)
1701 {
1702 #ifdef RTE_DEBUG
1703 	uint64_t md = 0xDEADBEEF;
1704 
1705 	void *ret = rte_security_get_userdata(NULL, md);
1706 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1707 			ret, NULL, "%p");
1708 	TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0);
1709 
1710 	return TEST_SUCCESS;
1711 #else
1712 	return TEST_SKIPPED;
1713 #endif
1714 }
1715 
1716 /**
1717  * Test execution of rte_security_get_userdata with invalid
1718  * security operations structure (NULL)
1719  */
1720 static int
1721 test_get_userdata_inv_context_ops(void)
1722 {
1723 #ifdef RTE_DEBUG
1724 	struct security_unittest_params *ut_params = &unittest_params;
1725 	uint64_t md = 0xDEADBEEF;
1726 	ut_params->ctx.ops = NULL;
1727 
1728 	void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1729 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1730 			ret, NULL, "%p");
1731 	TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0);
1732 
1733 	return TEST_SUCCESS;
1734 #else
1735 	return TEST_SKIPPED;
1736 #endif
1737 }
1738 
1739 /**
1740  * Test execution of rte_security_get_userdata with empty
1741  * security operations
1742  */
1743 static int
1744 test_get_userdata_inv_context_ops_fun(void)
1745 {
1746 	struct security_unittest_params *ut_params = &unittest_params;
1747 	uint64_t md = 0xDEADBEEF;
1748 	ut_params->ctx.ops = &empty_ops;
1749 
1750 	void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1751 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1752 			ret, NULL, "%p");
1753 	TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0);
1754 
1755 	return TEST_SUCCESS;
1756 }
1757 
1758 /**
1759  * Test execution of rte_security_get_userdata when get_userdata
1760  * security operation fails
1761  */
1762 static int
1763 test_get_userdata_ops_failure(void)
1764 {
1765 	struct security_unittest_params *ut_params = &unittest_params;
1766 	uint64_t md = 0xDEADBEEF;
1767 	void *userdata = (void *)0x7E577E57;
1768 
1769 	mock_get_userdata_exp.device = NULL;
1770 	mock_get_userdata_exp.md = md;
1771 	mock_get_userdata_exp.userdata = userdata;
1772 	mock_get_userdata_exp.ret = -1;
1773 
1774 	void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1775 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1776 			ret, NULL, "%p");
1777 	TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 1);
1778 
1779 	return TEST_SUCCESS;
1780 }
1781 
1782 /**
1783  * Test execution of rte_security_get_userdata in successful execution path
1784  */
1785 static int
1786 test_get_userdata_success(void)
1787 {
1788 	struct security_unittest_params *ut_params = &unittest_params;
1789 	uint64_t md = 0xDEADBEEF;
1790 	void *userdata = (void *)0x7E577E57;
1791 
1792 	mock_get_userdata_exp.device = NULL;
1793 	mock_get_userdata_exp.md = md;
1794 	mock_get_userdata_exp.userdata = userdata;
1795 	mock_get_userdata_exp.ret = 0;
1796 
1797 	void *ret = rte_security_get_userdata(&ut_params->ctx, md);
1798 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata,
1799 			ret, userdata, "%p");
1800 	TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 1);
1801 
1802 	return TEST_SUCCESS;
1803 }
1804 
1805 
1806 /**
1807  * rte_security_capabilities_get tests
1808  */
1809 
1810 /**
1811  * Test execution of rte_security_capabilities_get with NULL instance
1812  */
1813 static int
1814 test_capabilities_get_inv_context(void)
1815 {
1816 	const struct rte_security_capability *ret;
1817 	ret = rte_security_capabilities_get(NULL);
1818 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1819 			ret, NULL, "%p");
1820 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1821 
1822 	return TEST_SUCCESS;
1823 }
1824 
1825 /**
1826  * Test execution of rte_security_capabilities_get with invalid
1827  * security operations structure (NULL)
1828  */
1829 static int
1830 test_capabilities_get_inv_context_ops(void)
1831 {
1832 	struct security_unittest_params *ut_params = &unittest_params;
1833 	ut_params->ctx.ops = NULL;
1834 
1835 	const struct rte_security_capability *ret;
1836 	ret = rte_security_capabilities_get(&ut_params->ctx);
1837 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1838 			ret, NULL, "%p");
1839 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1840 
1841 	return TEST_SUCCESS;
1842 }
1843 
1844 /**
1845  * Test execution of rte_security_capabilities_get with empty
1846  * security operations
1847  */
1848 static int
1849 test_capabilities_get_inv_context_ops_fun(void)
1850 {
1851 	struct security_unittest_params *ut_params = &unittest_params;
1852 	ut_params->ctx.ops = &empty_ops;
1853 
1854 	const struct rte_security_capability *ret;
1855 	ret = rte_security_capabilities_get(&ut_params->ctx);
1856 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1857 			ret, NULL, "%p");
1858 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1859 
1860 	return TEST_SUCCESS;
1861 }
1862 
1863 /**
1864  * Test execution of rte_security_capabilities_get when capabilities_get
1865  * security operation fails
1866  */
1867 static int
1868 test_capabilities_get_ops_failure(void)
1869 {
1870 	struct security_unittest_params *ut_params = &unittest_params;
1871 
1872 	mock_capabilities_get_exp.device = NULL;
1873 	mock_capabilities_get_exp.ret = NULL;
1874 
1875 	const struct rte_security_capability *ret;
1876 	ret = rte_security_capabilities_get(&ut_params->ctx);
1877 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1878 			ret, NULL, "%p");
1879 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
1880 
1881 	return TEST_SUCCESS;
1882 }
1883 
1884 /**
1885  * Test execution of rte_security_capabilities_get in successful execution path
1886  */
1887 static int
1888 test_capabilities_get_success(void)
1889 {
1890 	struct security_unittest_params *ut_params = &unittest_params;
1891 	struct rte_security_capability capabilities;
1892 
1893 	mock_capabilities_get_exp.device = NULL;
1894 	mock_capabilities_get_exp.ret = &capabilities;
1895 
1896 	const struct rte_security_capability *ret;
1897 	ret = rte_security_capabilities_get(&ut_params->ctx);
1898 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get,
1899 			ret, &capabilities, "%p");
1900 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
1901 
1902 	return TEST_SUCCESS;
1903 }
1904 
1905 
1906 /**
1907  * rte_security_capability_get tests
1908  */
1909 
1910 /**
1911  * Test execution of rte_security_capability_get with NULL instance
1912  */
1913 static int
1914 test_capability_get_inv_context(void)
1915 {
1916 	struct rte_security_capability_idx idx;
1917 
1918 	const struct rte_security_capability *ret;
1919 	ret = rte_security_capability_get(NULL, &idx);
1920 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
1921 			ret, NULL, "%p");
1922 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1923 
1924 	return TEST_SUCCESS;
1925 }
1926 
1927 /**
1928  * Test execution of rte_security_capability_get with invalid
1929  * security operations structure (NULL)
1930  */
1931 static int
1932 test_capability_get_inv_context_ops(void)
1933 {
1934 	struct security_unittest_params *ut_params = &unittest_params;
1935 	struct rte_security_capability_idx idx;
1936 	ut_params->ctx.ops = NULL;
1937 
1938 	const struct rte_security_capability *ret;
1939 	ret = rte_security_capability_get(&ut_params->ctx, &idx);
1940 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
1941 			ret, NULL, "%p");
1942 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1943 
1944 	return TEST_SUCCESS;
1945 }
1946 
1947 /**
1948  * Test execution of rte_security_capability_get with empty
1949  * security operations
1950  */
1951 static int
1952 test_capability_get_inv_context_ops_fun(void)
1953 {
1954 	struct security_unittest_params *ut_params = &unittest_params;
1955 	struct rte_security_capability_idx idx;
1956 	ut_params->ctx.ops = &empty_ops;
1957 
1958 	const struct rte_security_capability *ret;
1959 	ret = rte_security_capability_get(&ut_params->ctx, &idx);
1960 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
1961 			ret, NULL, "%p");
1962 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1963 
1964 	return TEST_SUCCESS;
1965 }
1966 
1967 /**
1968  * Test execution of rte_security_capability_get with NULL idx parameter
1969  */
1970 static int
1971 test_capability_get_inv_idx(void)
1972 {
1973 	struct security_unittest_params *ut_params = &unittest_params;
1974 
1975 	const struct rte_security_capability *ret;
1976 	ret = rte_security_capability_get(&ut_params->ctx, NULL);
1977 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
1978 			ret, NULL, "%p");
1979 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0);
1980 
1981 	return TEST_SUCCESS;
1982 }
1983 
1984 /**
1985  * Test execution of rte_security_capability_get when capabilities_get
1986  * security operation fails
1987  */
1988 static int
1989 test_capability_get_ops_failure(void)
1990 {
1991 	struct security_unittest_params *ut_params = &unittest_params;
1992 	struct rte_security_capability_idx idx;
1993 
1994 	mock_capabilities_get_exp.device = NULL;
1995 	mock_capabilities_get_exp.ret = NULL;
1996 
1997 	const struct rte_security_capability *ret;
1998 	ret = rte_security_capability_get(&ut_params->ctx, &idx);
1999 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2000 			ret, NULL, "%p");
2001 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2002 
2003 	return TEST_SUCCESS;
2004 }
2005 
2006 /**
2007  * Test execution of rte_security_capability_get when capabilities table
2008  * is empty (contains only RTE_SECURITY_ACTION_TYPE_NONE ending entry)
2009  */
2010 static int
2011 test_capability_get_empty_table(void)
2012 {
2013 	struct security_unittest_params *ut_params = &unittest_params;
2014 	struct rte_security_capability_idx idx;
2015 	struct rte_security_capability capabilities[] = {
2016 		{
2017 			.action = RTE_SECURITY_ACTION_TYPE_NONE,
2018 		},
2019 	};
2020 
2021 	mock_capabilities_get_exp.device = NULL;
2022 	mock_capabilities_get_exp.ret = capabilities;
2023 
2024 	const struct rte_security_capability *ret;
2025 	ret = rte_security_capability_get(&ut_params->ctx, &idx);
2026 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2027 			ret, NULL, "%p");
2028 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2029 
2030 	return TEST_SUCCESS;
2031 }
2032 
2033 /**
2034  * Test execution of rte_security_capability_get when capabilities table
2035  * does not contain entry with matching action
2036  */
2037 static int
2038 test_capability_get_no_matching_action(void)
2039 {
2040 	struct security_unittest_params *ut_params = &unittest_params;
2041 	struct rte_security_capability_idx idx = {
2042 		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2043 	};
2044 	struct rte_security_capability capabilities[] = {
2045 		{
2046 			.action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
2047 		},
2048 		{
2049 			.action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
2050 		},
2051 		{
2052 			.action = RTE_SECURITY_ACTION_TYPE_NONE,
2053 		},
2054 	};
2055 
2056 	mock_capabilities_get_exp.device = NULL;
2057 	mock_capabilities_get_exp.ret = capabilities;
2058 
2059 	const struct rte_security_capability *ret;
2060 	ret = rte_security_capability_get(&ut_params->ctx, &idx);
2061 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2062 			ret, NULL, "%p");
2063 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2064 
2065 	return TEST_SUCCESS;
2066 }
2067 
2068 /**
2069  * Test execution of rte_security_capability_get when capabilities table
2070  * does not contain entry with matching protocol
2071  */
2072 static int
2073 test_capability_get_no_matching_protocol(void)
2074 {
2075 	struct security_unittest_params *ut_params = &unittest_params;
2076 	struct rte_security_capability_idx idx = {
2077 		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2078 		.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2079 	};
2080 	struct rte_security_capability capabilities[] = {
2081 		{
2082 			.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2083 			.protocol = RTE_SECURITY_PROTOCOL_MACSEC,
2084 		},
2085 		{
2086 			.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2087 			.protocol = RTE_SECURITY_PROTOCOL_PDCP,
2088 		},
2089 		{
2090 			.action = RTE_SECURITY_ACTION_TYPE_NONE,
2091 		},
2092 	};
2093 
2094 	mock_capabilities_get_exp.device = NULL;
2095 	mock_capabilities_get_exp.ret = capabilities;
2096 
2097 	const struct rte_security_capability *ret;
2098 	ret = rte_security_capability_get(&ut_params->ctx, &idx);
2099 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2100 			ret, NULL, "%p");
2101 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2102 
2103 	return TEST_SUCCESS;
2104 }
2105 
2106 /**
2107  * Test execution of rte_security_capability_get when macsec protocol
2108  * is searched and capabilities table contain proper entry.
2109  * However macsec records search is not supported in rte_security.
2110  */
2111 static int
2112 test_capability_get_no_support_for_macsec(void)
2113 {
2114 	struct security_unittest_params *ut_params = &unittest_params;
2115 	struct rte_security_capability_idx idx = {
2116 		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2117 		.protocol = RTE_SECURITY_PROTOCOL_MACSEC,
2118 	};
2119 	struct rte_security_capability capabilities[] = {
2120 		{
2121 			.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2122 			.protocol = RTE_SECURITY_PROTOCOL_MACSEC,
2123 		},
2124 		{
2125 			.action = RTE_SECURITY_ACTION_TYPE_NONE,
2126 		},
2127 	};
2128 
2129 	mock_capabilities_get_exp.device = NULL;
2130 	mock_capabilities_get_exp.ret = capabilities;
2131 
2132 	const struct rte_security_capability *ret;
2133 	ret = rte_security_capability_get(&ut_params->ctx, &idx);
2134 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2135 			ret, NULL, "%p");
2136 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2137 
2138 	return TEST_SUCCESS;
2139 }
2140 
2141 /**
2142  * Test execution of rte_security_capability_get when capabilities table
2143  * does not contain entry with matching ipsec proto field
2144  */
2145 static int
2146 test_capability_get_ipsec_mismatch_proto(void)
2147 {
2148 	struct security_unittest_params *ut_params = &unittest_params;
2149 	struct rte_security_capability_idx idx = {
2150 		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2151 		.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2152 		.ipsec = {
2153 			.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2154 		},
2155 	};
2156 	struct rte_security_capability capabilities[] = {
2157 		{
2158 			.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2159 			.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2160 			.ipsec = {
2161 				.proto = RTE_SECURITY_IPSEC_SA_PROTO_AH,
2162 			},
2163 		},
2164 		{
2165 			.action = RTE_SECURITY_ACTION_TYPE_NONE,
2166 		},
2167 	};
2168 
2169 	mock_capabilities_get_exp.device = NULL;
2170 	mock_capabilities_get_exp.ret = capabilities;
2171 
2172 	const struct rte_security_capability *ret;
2173 	ret = rte_security_capability_get(&ut_params->ctx, &idx);
2174 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2175 			ret, NULL, "%p");
2176 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2177 
2178 	return TEST_SUCCESS;
2179 }
2180 
2181 /**
2182  * Test execution of rte_security_capability_get when capabilities table
2183  * does not contain entry with matching ipsec mode field
2184  */
2185 static int
2186 test_capability_get_ipsec_mismatch_mode(void)
2187 {
2188 	struct security_unittest_params *ut_params = &unittest_params;
2189 	struct rte_security_capability_idx idx = {
2190 		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2191 		.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2192 		.ipsec = {
2193 			.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2194 			.mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
2195 		},
2196 	};
2197 	struct rte_security_capability capabilities[] = {
2198 		{
2199 			.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2200 			.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2201 			.ipsec = {
2202 				.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2203 				.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
2204 			},
2205 		},
2206 		{
2207 			.action = RTE_SECURITY_ACTION_TYPE_NONE,
2208 		},
2209 	};
2210 
2211 	mock_capabilities_get_exp.device = NULL;
2212 	mock_capabilities_get_exp.ret = capabilities;
2213 
2214 	const struct rte_security_capability *ret;
2215 	ret = rte_security_capability_get(&ut_params->ctx, &idx);
2216 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2217 			ret, NULL, "%p");
2218 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2219 
2220 	return TEST_SUCCESS;
2221 }
2222 
2223 /**
2224  * Test execution of rte_security_capability_get when capabilities table
2225  * does not contain entry with matching ipsec direction field
2226  */
2227 static int
2228 test_capability_get_ipsec_mismatch_dir(void)
2229 {
2230 	struct security_unittest_params *ut_params = &unittest_params;
2231 	struct rte_security_capability_idx idx = {
2232 		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2233 		.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2234 		.ipsec = {
2235 			.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2236 			.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
2237 			.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
2238 		},
2239 	};
2240 	struct rte_security_capability capabilities[] = {
2241 		{
2242 			.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2243 			.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2244 			.ipsec = {
2245 				.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2246 				.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
2247 				.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
2248 			},
2249 		},
2250 		{
2251 			.action = RTE_SECURITY_ACTION_TYPE_NONE,
2252 		},
2253 	};
2254 
2255 	mock_capabilities_get_exp.device = NULL;
2256 	mock_capabilities_get_exp.ret = capabilities;
2257 
2258 	const struct rte_security_capability *ret;
2259 	ret = rte_security_capability_get(&ut_params->ctx, &idx);
2260 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2261 			ret, NULL, "%p");
2262 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2263 
2264 	return TEST_SUCCESS;
2265 }
2266 
2267 /**
2268  * Test execution of rte_security_capability_get when capabilities table
2269  * contains matching ipsec entry
2270  */
2271 static int
2272 test_capability_get_ipsec_match(void)
2273 {
2274 	struct security_unittest_params *ut_params = &unittest_params;
2275 	struct rte_security_capability_idx idx = {
2276 		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2277 		.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2278 		.ipsec = {
2279 			.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2280 			.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
2281 			.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
2282 		},
2283 	};
2284 	struct rte_security_capability capabilities[] = {
2285 		{
2286 			.action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
2287 		},
2288 		{
2289 			.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2290 			.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
2291 			.ipsec = {
2292 				.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
2293 				.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
2294 				.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
2295 			},
2296 		},
2297 		{
2298 			.action = RTE_SECURITY_ACTION_TYPE_NONE,
2299 		},
2300 	};
2301 
2302 	mock_capabilities_get_exp.device = NULL;
2303 	mock_capabilities_get_exp.ret = capabilities;
2304 
2305 	const struct rte_security_capability *ret;
2306 	ret = rte_security_capability_get(&ut_params->ctx, &idx);
2307 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2308 			ret, &capabilities[1], "%p");
2309 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2310 
2311 	return TEST_SUCCESS;
2312 }
2313 
2314 /**
2315  * Test execution of rte_security_capability_get when capabilities table
2316  * does not contain entry with matching pdcp domain field
2317  */
2318 static int
2319 test_capability_get_pdcp_mismatch_domain(void)
2320 {
2321 	struct security_unittest_params *ut_params = &unittest_params;
2322 	struct rte_security_capability_idx idx = {
2323 		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2324 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
2325 		.pdcp = {
2326 			.domain = RTE_SECURITY_PDCP_MODE_CONTROL,
2327 		},
2328 	};
2329 	struct rte_security_capability capabilities[] = {
2330 		{
2331 			.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2332 			.protocol = RTE_SECURITY_PROTOCOL_PDCP,
2333 			.pdcp = {
2334 				.domain = RTE_SECURITY_PDCP_MODE_DATA,
2335 			},
2336 		},
2337 		{
2338 			.action = RTE_SECURITY_ACTION_TYPE_NONE,
2339 		},
2340 	};
2341 
2342 	mock_capabilities_get_exp.device = NULL;
2343 	mock_capabilities_get_exp.ret = capabilities;
2344 
2345 	const struct rte_security_capability *ret;
2346 	ret = rte_security_capability_get(&ut_params->ctx, &idx);
2347 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2348 			ret, NULL, "%p");
2349 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2350 
2351 	return TEST_SUCCESS;
2352 }
2353 
2354 /**
2355  * Test execution of rte_security_capability_get when capabilities table
2356  * contains matching pdcp entry
2357  */
2358 static int
2359 test_capability_get_pdcp_match(void)
2360 {
2361 	struct security_unittest_params *ut_params = &unittest_params;
2362 	struct rte_security_capability_idx idx = {
2363 		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2364 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
2365 		.pdcp = {
2366 			.domain = RTE_SECURITY_PDCP_MODE_CONTROL,
2367 		},
2368 	};
2369 	struct rte_security_capability capabilities[] = {
2370 		{
2371 			.action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
2372 		},
2373 		{
2374 			.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2375 			.protocol = RTE_SECURITY_PROTOCOL_PDCP,
2376 			.pdcp = {
2377 				.domain = RTE_SECURITY_PDCP_MODE_CONTROL,
2378 			},
2379 		},
2380 		{
2381 			.action = RTE_SECURITY_ACTION_TYPE_NONE,
2382 		},
2383 	};
2384 
2385 	mock_capabilities_get_exp.device = NULL;
2386 	mock_capabilities_get_exp.ret = capabilities;
2387 
2388 	const struct rte_security_capability *ret;
2389 	ret = rte_security_capability_get(&ut_params->ctx, &idx);
2390 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2391 			ret, &capabilities[1], "%p");
2392 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2393 
2394 	return TEST_SUCCESS;
2395 }
2396 
2397 /**
2398  * Test execution of rte_security_capability_get when capabilities table
2399  * does not contain entry with matching DOCSIS direction field
2400  */
2401 static int
2402 test_capability_get_docsis_mismatch_direction(void)
2403 {
2404 	struct security_unittest_params *ut_params = &unittest_params;
2405 	struct rte_security_capability_idx idx = {
2406 		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2407 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
2408 		.docsis = {
2409 			.direction = RTE_SECURITY_DOCSIS_DOWNLINK
2410 		},
2411 	};
2412 	struct rte_security_capability capabilities[] = {
2413 		{
2414 			.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2415 			.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
2416 			.docsis = {
2417 				.direction = RTE_SECURITY_DOCSIS_UPLINK
2418 			},
2419 		},
2420 		{
2421 			.action = RTE_SECURITY_ACTION_TYPE_NONE,
2422 		},
2423 	};
2424 
2425 	mock_capabilities_get_exp.device = NULL;
2426 	mock_capabilities_get_exp.ret = capabilities;
2427 
2428 	const struct rte_security_capability *ret;
2429 	ret = rte_security_capability_get(&ut_params->ctx, &idx);
2430 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2431 			ret, NULL, "%p");
2432 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2433 
2434 	return TEST_SUCCESS;
2435 }
2436 
2437 /**
2438  * Test execution of rte_security_capability_get when capabilities table
2439  * contains matching DOCSIS entry
2440  */
2441 static int
2442 test_capability_get_docsis_match(void)
2443 {
2444 	struct security_unittest_params *ut_params = &unittest_params;
2445 	struct rte_security_capability_idx idx = {
2446 		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2447 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
2448 		.docsis = {
2449 			.direction = RTE_SECURITY_DOCSIS_UPLINK
2450 		},
2451 	};
2452 	struct rte_security_capability capabilities[] = {
2453 		{
2454 			.action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
2455 		},
2456 		{
2457 			.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
2458 			.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
2459 			.docsis = {
2460 				.direction = RTE_SECURITY_DOCSIS_UPLINK
2461 			},
2462 		},
2463 		{
2464 			.action = RTE_SECURITY_ACTION_TYPE_NONE,
2465 		},
2466 	};
2467 
2468 	mock_capabilities_get_exp.device = NULL;
2469 	mock_capabilities_get_exp.ret = capabilities;
2470 
2471 	const struct rte_security_capability *ret;
2472 	ret = rte_security_capability_get(&ut_params->ctx, &idx);
2473 	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
2474 			ret, &capabilities[1], "%p");
2475 	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
2476 
2477 	return TEST_SUCCESS;
2478 }
2479 
2480 /**
2481  * Declaration of testcases
2482  */
2483 static struct unit_test_suite security_testsuite  = {
2484 	.suite_name = "generic security",
2485 	.setup = testsuite_setup,
2486 	.teardown = testsuite_teardown,
2487 	.unit_test_cases = {
2488 		TEST_CASE_ST(ut_setup, ut_teardown,
2489 				test_session_create_inv_context),
2490 		TEST_CASE_ST(ut_setup, ut_teardown,
2491 				test_session_create_inv_context_ops),
2492 		TEST_CASE_ST(ut_setup, ut_teardown,
2493 				test_session_create_inv_context_ops_fun),
2494 		TEST_CASE_ST(ut_setup, ut_teardown,
2495 				test_session_create_inv_configuration),
2496 		TEST_CASE_ST(ut_setup, ut_teardown,
2497 				test_session_create_inv_mempool),
2498 		TEST_CASE_ST(ut_setup, ut_teardown,
2499 				test_session_create_inv_sess_priv_mempool),
2500 		TEST_CASE_ST(ut_setup, ut_teardown,
2501 				test_session_create_mempool_empty),
2502 		TEST_CASE_ST(ut_setup, ut_teardown,
2503 				test_session_create_ops_failure),
2504 		TEST_CASE_ST(ut_setup, ut_teardown,
2505 				test_session_create_success),
2506 
2507 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2508 				test_session_update_inv_context),
2509 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2510 				test_session_update_inv_context_ops),
2511 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2512 				test_session_update_inv_context_ops_fun),
2513 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2514 				test_session_update_inv_configuration),
2515 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2516 				test_session_update_inv_session),
2517 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2518 				test_session_update_ops_failure),
2519 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2520 				test_session_update_success),
2521 
2522 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2523 				test_session_get_size_inv_context),
2524 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2525 				test_session_get_size_inv_context_ops),
2526 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2527 				test_session_get_size_inv_context_ops_fun),
2528 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2529 				test_session_get_size_ops_failure),
2530 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2531 				test_session_get_size_success),
2532 
2533 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2534 				test_session_stats_get_inv_context),
2535 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2536 				test_session_stats_get_inv_context_ops),
2537 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2538 				test_session_stats_get_inv_context_ops_fun),
2539 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2540 				test_session_stats_get_inv_stats),
2541 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2542 				test_session_stats_get_ops_failure),
2543 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2544 				test_session_stats_get_success),
2545 
2546 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2547 				test_session_destroy_inv_context),
2548 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2549 				test_session_destroy_inv_context_ops),
2550 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2551 				test_session_destroy_inv_context_ops_fun),
2552 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2553 				test_session_destroy_inv_session),
2554 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2555 				test_session_destroy_ops_failure),
2556 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2557 				test_session_destroy_success),
2558 
2559 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2560 				test_set_pkt_metadata_inv_context),
2561 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2562 				test_set_pkt_metadata_inv_context_ops),
2563 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2564 				test_set_pkt_metadata_inv_context_ops_fun),
2565 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2566 				test_set_pkt_metadata_inv_session),
2567 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2568 				test_set_pkt_metadata_ops_failure),
2569 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2570 				test_set_pkt_metadata_success),
2571 
2572 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2573 				test_get_userdata_inv_context),
2574 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2575 				test_get_userdata_inv_context_ops),
2576 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2577 				test_get_userdata_inv_context_ops_fun),
2578 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2579 				test_get_userdata_ops_failure),
2580 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2581 				test_get_userdata_success),
2582 
2583 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2584 				test_capabilities_get_inv_context),
2585 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2586 				test_capabilities_get_inv_context_ops),
2587 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2588 				test_capabilities_get_inv_context_ops_fun),
2589 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2590 				test_capabilities_get_ops_failure),
2591 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2592 				test_capabilities_get_success),
2593 
2594 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2595 				test_capability_get_inv_context),
2596 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2597 				test_capability_get_inv_context_ops),
2598 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2599 				test_capability_get_inv_context_ops_fun),
2600 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2601 				test_capability_get_inv_idx),
2602 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2603 				test_capability_get_ops_failure),
2604 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2605 				test_capability_get_empty_table),
2606 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2607 				test_capability_get_no_matching_action),
2608 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2609 				test_capability_get_no_matching_protocol),
2610 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2611 				test_capability_get_no_support_for_macsec),
2612 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2613 				test_capability_get_ipsec_mismatch_proto),
2614 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2615 				test_capability_get_ipsec_mismatch_mode),
2616 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2617 				test_capability_get_ipsec_mismatch_dir),
2618 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2619 				test_capability_get_ipsec_match),
2620 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2621 				test_capability_get_pdcp_mismatch_domain),
2622 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2623 				test_capability_get_pdcp_match),
2624 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2625 				test_capability_get_docsis_mismatch_direction),
2626 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
2627 				test_capability_get_docsis_match),
2628 
2629 		TEST_CASES_END() /**< NULL terminate unit test array */
2630 	}
2631 };
2632 
2633 static int
2634 test_security(void)
2635 {
2636 	rte_log_set_global_level(RTE_LOG_DEBUG);
2637 	rte_log_set_level(RTE_LOGTYPE_EAL, RTE_LOG_DEBUG);
2638 
2639 	return unit_test_suite_runner(&security_testsuite);
2640 }
2641 
2642 REGISTER_TEST_COMMAND(security_autotest, test_security);
2643