Skip to contentSkip to conversation

test: Add ut_assertnull macro

PATCH In review Ramon Fried 3 participants 5 messages Jun 21, 2018 – Jul 20, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test: Add ut_assertnull macro

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

---
 include/test/ut.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/test/ut.h +12 -0
index 59b23a25a4..fce75fd12a 100644
@@ -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);					\
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 test: Add ut_assertnull macro

Hi Simon.
Would love to get this reviewed. can you assist ?
Thanks.
Ramon.

Quoted 35 lines · Ramon Fried

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

---
 include/test/ut.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/test/ut.h +12 -1
index 59b23a25a4..fce75fd12a 100644
@@ -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);                                       \
--

2.17.1

#3 lore raw

PATCH 1/1 test: Add ut_assertnull macro

Quoted 11 lines · Simon Glass
Quoted 8 lines · Ramon Fried

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

---
 include/test/ut.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Thanks!

Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
#4 lore raw
In reply to Ramon Fried
Quoted 5 lines · Ramon Fried

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

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180720/9e5ed9fb/attachment.sig>