]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/dpdk/app/test-bbdev/main.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / seastar / dpdk / app / test-bbdev / main.h
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 DEFAULT_BURST 32U
21 #define DEFAULT_OPS 64U
22
23 #define TEST_ASSERT(cond, msg, ...) do { \
24 if (!(cond)) { \
25 printf("TestCase %s() line %d failed: " \
26 msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
27 return TEST_FAILED; \
28 } \
29 } while (0)
30
31 /* Compare two buffers (length in bytes) */
32 #define TEST_ASSERT_BUFFERS_ARE_EQUAL(a, b, len, msg, ...) do { \
33 if (memcmp((a), (b), len)) { \
34 printf("TestCase %s() line %d failed: " \
35 msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
36 rte_memdump(stdout, "Buffer A", (a), len); \
37 rte_memdump(stdout, "Buffer B", (b), len); \
38 return TEST_FAILED; \
39 } \
40 } while (0)
41
42 #define TEST_ASSERT_SUCCESS(val, msg, ...) do { \
43 typeof(val) _val = (val); \
44 if (!(_val == 0)) { \
45 printf("TestCase %s() line %d failed (err %d): " \
46 msg "\n", __func__, __LINE__, _val, \
47 ##__VA_ARGS__); \
48 return TEST_FAILED; \
49 } \
50 } while (0)
51
52 #define TEST_ASSERT_FAIL(val, msg, ...) \
53 TEST_ASSERT_SUCCESS(!(val), msg, ##__VA_ARGS__)
54
55 #define TEST_ASSERT_NOT_NULL(val, msg, ...) do { \
56 if ((val) == NULL) { \
57 printf("TestCase %s() line %d failed (null): " \
58 msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
59 return TEST_FAILED; \
60 } \
61 } while (0)
62
63 struct unit_test_case {
64 int (*setup)(void);
65 void (*teardown)(void);
66 int (*testcase)(void);
67 const char *name;
68 };
69
70 #define TEST_CASE(testcase) {NULL, NULL, testcase, #testcase}
71
72 #define TEST_CASE_ST(setup, teardown, testcase) \
73 {setup, teardown, testcase, #testcase}
74
75 #define TEST_CASES_END() {NULL, NULL, NULL, NULL}
76
77 struct unit_test_suite {
78 const char *suite_name;
79 int (*setup)(void);
80 void (*teardown)(void);
81 struct unit_test_case unit_test_cases[];
82 };
83
84 int unit_test_suite_runner(struct unit_test_suite *suite);
85
86 typedef int (test_callback)(void);
87 TAILQ_HEAD(test_commands_list, test_command);
88 struct test_command {
89 TAILQ_ENTRY(test_command) next;
90 const char *command;
91 test_callback *callback;
92 };
93
94 void add_test_command(struct test_command *t);
95
96 /* Register a test function */
97 #define REGISTER_TEST_COMMAND(name, testsuite) \
98 static int test_func_##name(void) \
99 { \
100 return unit_test_suite_runner(&testsuite); \
101 } \
102 static struct test_command test_struct_##name = { \
103 .command = RTE_STR(name), \
104 .callback = test_func_##name, \
105 }; \
106 RTE_INIT(test_register_##name) \
107 { \
108 add_test_command(&test_struct_##name); \
109 }
110
111 const char *get_vector_filename(void);
112
113 unsigned int get_num_ops(void);
114
115 unsigned int get_burst_sz(void);
116
117 unsigned int get_num_lcores(void);
118
119 #endif