4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <sys/queue.h>
39 #define TEST_ASSERT(cond, msg, ...) do { \
41 printf("TestCase %s() line %d failed: " \
42 msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
47 #define TEST_ASSERT_EQUAL(a, b, msg, ...) { \
49 printf("TestCase %s() line %d failed: " \
50 msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
55 #define TEST_ASSERT_NOT_EQUAL(a, b, msg, ...) do { \
57 printf("TestCase %s() line %d failed: " \
58 msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
63 #define TEST_ASSERT_SUCCESS(val, msg, ...) do { \
65 printf("TestCase %s() line %d failed: " \
66 msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
71 #define TEST_ASSERT_FAIL(val, msg, ...) do { \
73 printf("TestCase %s() line %d failed: " \
74 msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
80 #define TEST_ASSERT_NULL(val, msg, ...) do { \
81 if (!(val == NULL)) { \
82 printf("TestCase %s() line %d failed: " \
83 msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
88 #define TEST_ASSERT_NOT_NULL(val, msg, ...) do { \
89 if (!(val != NULL)) { \
90 printf("TestCase %s() line %d failed: " \
91 msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
96 struct unit_test_case {
98 int (*teardown)(void);
99 int (*testcase)(void);
100 const char *success_msg;
101 const char *fail_msg;
104 #define TEST_CASE(fn) { NULL, NULL, fn, #fn " succeeded", #fn " failed"}
106 #define TEST_CASE_ST(setup, teardown, testcase) \
107 { setup, teardown, testcase, #testcase " succeeded", \
108 #testcase " failed "}
110 #define TEST_CASES_END() { NULL, NULL, NULL, NULL, NULL }
112 struct unit_test_suite {
113 const char *suite_name;
115 int (*teardown)(void);
116 struct unit_test_case unit_test_cases[];
119 int unit_test_suite_runner(struct unit_test_suite *suite);
121 /* icc on baremetal gives us troubles with function named 'main' */
122 #ifdef RTE_EXEC_ENV_BAREMETAL
126 #define RECURSIVE_ENV_VAR "RTE_TEST_RECURSIVE"
128 extern const char *prgname;
130 int commands_init(void);
132 int main(int argc, char **argv);
135 int test_memory(void);
136 int test_per_lcore(void);
137 int test_spinlock(void);
138 int test_rwlock(void);
139 int test_atomic(void);
140 int test_byteorder(void);
141 int test_prefetch(void);
142 int test_cycles(void);
144 int test_memzone(void);
146 int test_table(void);
147 int test_ring_perf(void);
148 int test_mempool(void);
149 int test_mempool_perf(void);
151 int test_timer(void);
152 int test_timer_perf(void);
153 int test_malloc(void);
154 int test_memcpy(void);
155 int test_memcpy_perf(void);
157 int test_hash_perf(void);
160 int test_debug(void);
161 int test_errno(void);
162 int test_tailq(void);
163 int test_string_fns(void);
164 int test_mp_secondary(void);
165 int test_cpuflags(void);
166 int test_eal_flags(void);
167 int test_alarm(void);
168 int test_interrupt(void);
169 int test_version(void);
170 int test_eal_fs(void);
171 int test_cmdline(void);
172 int test_func_reentrancy(void);
174 int test_sched(void);
175 int test_meter(void);
178 int test_power(void);
179 int test_common(void);
180 int test_pmd_ring(void);
181 int test_ivshmem(void);
182 int test_distributor(void);
183 int test_distributor_perf(void);
184 int test_kvargs(void);
185 int test_devargs(void);
186 int test_link_bonding(void);
190 typedef int (test_callback)(void);
191 TAILQ_HEAD(test_commands_list, test_command);
192 struct test_command {
193 TAILQ_ENTRY(test_command) next;
195 test_callback *callback;
198 void add_test_command(struct test_command *t);
200 #define REGISTER_TEST_COMMAND(t) \
201 static void testfn_##t(void);\
202 void __attribute__((constructor, used)) testfn_##t(void)\
204 add_test_command(&t);\