summaryrefslogtreecommitdiffstats
path: root/lib/librte_eal/common/include/rte_test.h
diff options
context:
space:
mode:
authorLuca Boccassi <luca.boccassi@gmail.com>2018-02-19 11:16:57 +0000
committerLuca Boccassi <luca.boccassi@gmail.com>2018-02-19 11:17:28 +0000
commitca33590b6af032bff57d9cc70455660466a654b2 (patch)
tree0b68b090bd9b4a78a3614b62400b29279d76d553 /lib/librte_eal/common/include/rte_test.h
parent169a9de21e263aa6599cdc2d87a45ae158d9f509 (diff)
New upstream version 18.02upstream/18.02
Change-Id: I89ed24cb2a49b78fe5be6970b99dd46c1499fcc3 Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
Diffstat (limited to 'lib/librte_eal/common/include/rte_test.h')
-rw-r--r--lib/librte_eal/common/include/rte_test.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/librte_eal/common/include/rte_test.h b/lib/librte_eal/common/include/rte_test.h
new file mode 100644
index 00000000..89e47f47
--- /dev/null
+++ b/lib/librte_eal/common/include/rte_test.h
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2015 Cavium, Inc
+ */
+
+#ifndef _RTE_TEST_H_
+#define _RTE_TEST_H_
+
+#include <rte_log.h>
+
+/* Before including rte_test.h file you can define
+ * RTE_TEST_TRACE_FAILURE(_file, _line, _func) macro to better trace/debug test
+ * failures. Mostly useful in development phase.
+ */
+#ifndef RTE_TEST_TRACE_FAILURE
+#define RTE_TEST_TRACE_FAILURE(_file, _line, _func)
+#endif
+
+
+#define RTE_TEST_ASSERT(cond, msg, ...) do { \
+ if (!(cond)) { \
+ RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: " \
+ msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
+ RTE_TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__); \
+ return -1; \
+ } \
+} while (0)
+
+#define RTE_TEST_ASSERT_EQUAL(a, b, msg, ...) \
+ RTE_TEST_ASSERT(a == b, msg, ##__VA_ARGS__)
+
+#define RTE_TEST_ASSERT_NOT_EQUAL(a, b, msg, ...) \
+ RTE_TEST_ASSERT(a != b, msg, ##__VA_ARGS__)
+
+#define RTE_TEST_ASSERT_SUCCESS(val, msg, ...) \
+ RTE_TEST_ASSERT(val == 0, msg, ##__VA_ARGS__)
+
+#define RTE_TEST_ASSERT_FAIL(val, msg, ...) \
+ RTE_TEST_ASSERT(val != 0, msg, ##__VA_ARGS__)
+
+#define RTE_TEST_ASSERT_NULL(val, msg, ...) \
+ RTE_TEST_ASSERT(val == NULL, msg, ##__VA_ARGS__)
+
+#define RTE_TEST_ASSERT_NOT_NULL(val, msg, ...) \
+ RTE_TEST_ASSERT(val != NULL, msg, ##__VA_ARGS__)
+
+#endif /* _RTE_TEST_H_ */