xref: /dpdk/app/test-bbdev/main.h (revision 3d6063a035fa491bfe6a38d2097193e21ba79eec)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4 
5 #ifndef _MAIN_H_
6 #define _MAIN_H_
7 
8 #include <stddef.h>
9 #include <sys/queue.h>
10 
11 #include <rte_common.h>
12 #include <rte_hexdump.h>
13 #include <rte_log.h>
14 
15 #define TEST_SUCCESS    0
16 #define TEST_FAILED     -1
17 #define TEST_SKIPPED    1
18 
19 #define MAX_BURST 512U
20 #define MAX_OPS 1024U
21 #define DEFAULT_BURST 32U
22 #define DEFAULT_OPS 64U
23 #define DEFAULT_ITER 6U
24 
25 
26 
27 #define TEST_ASSERT(cond, msg, ...) do {  \
28 		if (!(cond)) {  \
29 			printf("TestCase %s() line %d failed: " \
30 				msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
31 			return TEST_FAILED;  \
32 		} \
33 } while (0)
34 
35 /* Compare two buffers (length in bytes) */
36 #define TEST_ASSERT_BUFFERS_ARE_EQUAL(a, b, len, msg, ...) do { \
37 	if (memcmp((a), (b), len)) { \
38 		printf("TestCase %s() line %d failed: " \
39 			msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
40 		rte_memdump(stdout, "Buffer A", (a), len); \
41 		rte_memdump(stdout, "Buffer B", (b), len); \
42 		return TEST_FAILED; \
43 	} \
44 } while (0)
45 
46 #define TEST_ASSERT_SUCCESS(val, msg, ...) do { \
47 		typeof(val) _val = (val); \
48 		if (!(_val == 0)) { \
49 			printf("TestCase %s() line %d failed (err %d): " \
50 				msg "\n", __func__, __LINE__, _val, \
51 				##__VA_ARGS__); \
52 			return TEST_FAILED; \
53 		} \
54 } while (0)
55 
56 #define TEST_ASSERT_FAIL(val, msg, ...) \
57 	TEST_ASSERT_SUCCESS(!(val), msg, ##__VA_ARGS__)
58 
59 #define TEST_ASSERT_NOT_NULL(val, msg, ...) do { \
60 		if ((val) == NULL) { \
61 			printf("TestCase %s() line %d failed (null): " \
62 				msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
63 			return TEST_FAILED;  \
64 		} \
65 } while (0)
66 
67 struct unit_test_case {
68 	int (*setup)(void);
69 	void (*teardown)(void);
70 	int (*testcase)(void);
71 	const char *name;
72 };
73 
74 #define TEST_CASE(testcase) {NULL, NULL, testcase, #testcase}
75 
76 #define TEST_CASE_ST(setup, teardown, testcase) \
77 		{setup, teardown, testcase, #testcase}
78 
79 #define TEST_CASES_END() {NULL, NULL, NULL, NULL}
80 
81 struct unit_test_suite {
82 	const char *suite_name;
83 	int (*setup)(void);
84 	void (*teardown)(void);
85 	struct unit_test_case unit_test_cases[];
86 };
87 
88 int unit_test_suite_runner(struct unit_test_suite *suite);
89 
90 typedef int (test_callback)(void);
91 TAILQ_HEAD(test_commands_list, test_command);
92 struct test_command {
93 	TAILQ_ENTRY(test_command) next;
94 	const char *command;
95 	test_callback *callback;
96 };
97 
98 void add_test_command(struct test_command *t);
99 
100 /* Register a test function */
101 #define REGISTER_TEST_COMMAND(name, testsuite) \
102 	static int test_func_##name(void) \
103 	{ \
104 		return unit_test_suite_runner(&testsuite); \
105 	} \
106 	static struct test_command test_struct_##name = { \
107 		.command = RTE_STR(name), \
108 		.callback = test_func_##name, \
109 	}; \
110 	RTE_INIT(test_register_##name) \
111 	{ \
112 		add_test_command(&test_struct_##name); \
113 	}
114 
115 const char *get_vector_filename(void);
116 
117 unsigned int get_num_ops(void);
118 
119 unsigned int get_burst_sz(void);
120 
121 unsigned int get_num_lcores(void);
122 
123 double get_snr(void);
124 
125 unsigned int get_iter_max(void);
126 
127 bool get_init_device(void);
128 
129 #endif
130