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