CNDP  22.08.0
cne_test.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2015 Cavium, Inc
3  * Copyright (c) 2019-2022 Intel Corporation
4  */
5 
6 #ifndef _CNE_TEST_H_
7 #define _CNE_TEST_H_
8 
9 #include <cne_log.h>
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 /* Before including cne_test.h file you can define
16  * CNE_TEST_TRACE_FAILURE(_file, _line, _func) macro to better trace/debug test
17  * failures. Mostly useful in development phase.
18  */
19 #ifndef CNE_TEST_TRACE_FAILURE
20 #define CNE_TEST_TRACE_FAILURE(_file, _line, _func)
21 #endif
22 
26 #define CNE_TEST_ASSERT(cond, msg, ...) \
27  do { \
28  if (!(cond)) { \
29  CNE_ERR("Test assert %s line %d failed: " msg "\n", __func__, __LINE__, \
30  ##__VA_ARGS__); \
31  CNE_TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__); \
32  return -1; \
33  } \
34  } while (0)
35 
46 #define CNE_TEST_ASSERT_EQUAL(a, b, msg, ...) CNE_TEST_ASSERT(a == b, msg, ##__VA_ARGS__)
47 
58 #define CNE_TEST_ASSERT_NOT_EQUAL(a, b, msg, ...) CNE_TEST_ASSERT(a != b, msg, ##__VA_ARGS__)
59 
68 #define CNE_TEST_ASSERT_SUCCESS(val, msg, ...) CNE_TEST_ASSERT(val == 0, msg, ##__VA_ARGS__)
69 
78 #define CNE_TEST_ASSERT_FAIL(val, msg, ...) CNE_TEST_ASSERT(val != 0, msg, ##__VA_ARGS__)
79 
88 #define CNE_TEST_ASSERT_NULL(val, msg, ...) CNE_TEST_ASSERT(val == NULL, msg, ##__VA_ARGS__)
89 
98 #define CNE_TEST_ASSERT_NOT_NULL(val, msg, ...) CNE_TEST_ASSERT(val != NULL, msg, ##__VA_ARGS__)
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #endif /* _CNE_TEST_H_ */