diff mbox series

[U-Boot] test: Add ut_assertnull macro

Message ID 20180621144716.27976-1-ramon.fried@gmail.com
State Accepted
Commit 8d545790729434f4ba718dd9a6a1b55dcf7e94c4
Delegated to: Tom Rini
Headers show
Series [U-Boot] test: Add ut_assertnull macro | expand

Commit Message

Ramon Fried June 21, 2018, 2:47 p.m. UTC
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>
---
 include/test/ut.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Ramon Fried July 7, 2018, 11:46 a.m. UTC | #1
Hi Simon.
Would love to get this reviewed. can you assist ?
Thanks.
Ramon.

On Fri, Jun 22, 2018 at 12:47 AM Ramon Fried <ramon.fried@gmail.com> wrote:
>
> 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>
> ---
>  include/test/ut.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/include/test/ut.h b/include/test/ut.h
> index 59b23a25a4..fce75fd12a 100644
> --- a/include/test/ut.h
> +++ b/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);                                       \
> --
> 2.17.1
>
Simon Glass July 10, 2018, 8:49 p.m. UTC | #2
On 21 June 2018 at 08:47, Ramon Fried <ramon.fried@gmail.com> wrote:
> 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>
> ---
>  include/test/ut.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>

Reviewed-by: Simon Glass <sjg@chromium.org>
Ramon Fried July 11, 2018, 5:44 a.m. UTC | #3
On July 10, 2018 11:49:31 PM GMT+03:00, Simon Glass <sjg@chromium.org> wrote:
>On 21 June 2018 at 08:47, Ramon Fried <ramon.fried@gmail.com> wrote:
>> 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>
>> ---
>>  include/test/ut.h | 12 ++++++++++++
>>  1 file changed, 12 insertions(+)
>>
>
>Reviewed-by: Simon Glass <sjg@chromium.org>
Thanks!
Tom Rini July 20, 2018, 12:34 p.m. UTC | #4
On Thu, Jun 21, 2018 at 05:47:16PM +0300, Ramon Fried wrote:

> 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>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/include/test/ut.h b/include/test/ut.h
index 59b23a25a4..fce75fd12a 100644
--- a/include/test/ut.h
+++ b/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);					\