浏览代码

test: Add ut_assertnull macro

Add ut_assertnull macro to include/test/ut.h
For testing of functions that returns NULL on errors.

Signed-off-by: Ramon Fried <ramon.fried@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Ramon Fried 7 年之前
父节点
当前提交
8d54579072
共有 1 个文件被更改,包括 12 次插入0 次删除
  1. 12 0
      include/test/ut.h

+ 12 - 0
include/test/ut.h

@@ -90,6 +90,18 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 	}								\
 }
 
+/* Assert that a pointer is NULL */
+#define ut_assertnull(expr) {					\
+	const void *val = (expr);					\
+									\
+	if (val != NULL) {						\
+		ut_failf(uts, __FILE__, __LINE__, __func__,		\
+			 #expr " != NULL",				\
+			 "Expected NULL, got %p", val);		\
+		return CMD_RET_FAILURE;					\
+	}								\
+}
+
 /* Assert that a pointer is not NULL */
 #define ut_assertnonnull(expr) {					\
 	const void *val = (expr);					\