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