Re: [PATCH 1/2] test: Wrap assert macros in ({ ... }) and fix missing semicolons

2023-03-06 Thread Simon Glass
On Wed, 1 Mar 2023 at 20:05, Marek Vasut
 wrote:
>
> Wrap the assert macros in ({ ... }) so they can be safely used both as
> right side argument as well as in conditionals without curly brackets
> around them. In the process, find a bunch of missing semicolons, fix
> them.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Heinrich Schuchardt 
> Cc: Simon Glass 
> Cc: Tom Rini 
> ---
>  include/test/ut.h  | 152 ++---
>  test/cmd/pwm.c |   4 +-
>  test/dm/acpigen.c  |   2 +-
>  test/dm/misc.c |   4 +-
>  test/dm/phy.c  |   8 +--
>  test/dm/scmi.c |   4 +-
>  test/lib/kconfig.c |  10 +--
>  test/unicode_ut.c  |   6 +-
>  8 files changed, 121 insertions(+), 69 deletions(-)
>

Gosh. That was pretty bad. Thanks for fixing.

Reviewed-by: Simon Glass 


[PATCH 1/2] test: Wrap assert macros in ({ ... }) and fix missing semicolons

2023-03-01 Thread Marek Vasut
Wrap the assert macros in ({ ... }) so they can be safely used both as
right side argument as well as in conditionals without curly brackets
around them. In the process, find a bunch of missing semicolons, fix
them.

Signed-off-by: Marek Vasut 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
 include/test/ut.h  | 152 ++---
 test/cmd/pwm.c |   4 +-
 test/dm/acpigen.c  |   2 +-
 test/dm/misc.c |   4 +-
 test/dm/phy.c  |   8 +--
 test/dm/scmi.c |   4 +-
 test/lib/kconfig.c |  10 +--
 test/unicode_ut.c  |   6 +-
 8 files changed, 121 insertions(+), 69 deletions(-)

diff --git a/include/test/ut.h b/include/test/ut.h
index 2b0dab32f68..dddf9ad241f 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -125,36 +125,47 @@ int ut_check_console_dump(struct unit_test_state *uts, 
int total_bytes);
 fmt, ##args)
 
 /* Assert that a condition is non-zero */
-#define ut_assert(cond)
\
+#define ut_assert(cond) ({ \
+   int __ret = 0;  \
+   \
if (!(cond)) {  \
ut_fail(uts, __FILE__, __LINE__, __func__, #cond);  \
-   return CMD_RET_FAILURE; \
-   }
+   __ret = CMD_RET_FAILURE;\
+   }   \
+   __ret;  \
+})
 
 /* Assert that a condition is non-zero, with printf() string */
-#define ut_assertf(cond, fmt, args...) \
+#define ut_assertf(cond, fmt, args...) ({  \
+   int __ret = 0;  \
+   \
if (!(cond)) {  \
ut_failf(uts, __FILE__, __LINE__, __func__, #cond,  \
 fmt, ##args);  \
-   return CMD_RET_FAILURE; \
-   }
+   __ret = CMD_RET_FAILURE;\
+   }   \
+   __ret;  \
+})
 
 /* Assert that two int expressions are equal */
-#define ut_asserteq(expr1, expr2) {\
+#define ut_asserteq(expr1, expr2) ({   \
unsigned int _val1 = (expr1), _val2 = (expr2);  \
+   int __ret = 0;  \
\
if (_val1 != _val2) {   \
ut_failf(uts, __FILE__, __LINE__, __func__, \
 #expr1 " == " #expr2,  \
 "Expected %#x (%d), got %#x (%d)", \
 _val1, _val1, _val2, _val2);   \
-   return CMD_RET_FAILURE; \
+   __ret = CMD_RET_FAILURE;\
}   \
-}
+   __ret;  \
+})
 
 /* Assert that two 64 int expressions are equal */
-#define ut_asserteq_64(expr1, expr2) { \
+#define ut_asserteq_64(expr1, expr2) ({
\
u64 _val1 = (expr1), _val2 = (expr2);   \
+   int __ret = 0;  \
\
if (_val1 != _val2) {   \
ut_failf(uts, __FILE__, __LINE__, __func__, \
@@ -164,43 +175,49 @@ int ut_check_console_dump(struct unit_test_state *uts, 
int total_bytes);
 (unsigned long long)_val1, \
 (unsigned long long)_val2, \
 (unsigned long long)_val2);\
-   return CMD_RET_FAILURE; \
+   __ret = CMD_RET_FAILURE;\
}   \
-}
+   __ret;  \
+})
 
 /* Assert that two string expressions are equal */
-#define ut_asserteq_str(expr1, expr2) {