summaryrefslogtreecommitdiff
path: root/include/test
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2015-07-06 12:54:37 -0600
committerSimon Glass <sjg@chromium.org>2015-07-21 17:39:33 -0600
commit85aeda4a62775326d616c7bc5876b4bd00cb1a3e (patch)
tree3c9abed084b26bd9339c55341342eb58e6f66261 /include/test
parent0503e8207c11c40bd53c41b88edbffe284a7658f (diff)
downloadu-boot-imx-85aeda4a62775326d616c7bc5876b4bd00cb1a3e.zip
u-boot-imx-85aeda4a62775326d616c7bc5876b4bd00cb1a3e.tar.gz
u-boot-imx-85aeda4a62775326d616c7bc5876b4bd00cb1a3e.tar.bz2
test: Add a macro to check that a value is not an error pointer
Some functions can return ERR_PTR(errval). Add a unit test macro to check that no error is returned in a pointer. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/test')
-rw-r--r--include/test/ut.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/test/ut.h b/include/test/ut.h
index 5e5aa6c..da7c1a9 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -9,6 +9,8 @@
#ifndef __TEST_UT_H
#define __TEST_UT_H
+#include <linux/err.h>
+
struct unit_test_state;
/**
@@ -101,6 +103,19 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
} \
}
+/* Assert that a pointer is not an error pointer */
+#define ut_assertok_ptr(expr) { \
+ const void *val = (expr); \
+ \
+ if (IS_ERR(val)) { \
+ ut_failf(uts, __FILE__, __LINE__, __func__, \
+ #expr " = NULL", \
+ "Expected pointer, got error %ld", \
+ PTR_ERR(val)); \
+ return CMD_RET_FAILURE; \
+ } \
+}
+
/* Assert that an operation succeeds (returns 0) */
#define ut_assertok(cond) ut_asserteq(0, cond)