diff options
author | Simon Glass | 2020-01-27 08:49:41 -0700 |
---|---|---|
committer | Simon Glass | 2020-02-05 19:33:45 -0700 |
commit | ba8444a06623b4f9af051aec47247c202937ec00 (patch) | |
tree | 001864ea8ca3fe725d0bc8ec3eed9a3e671ab1ba /include | |
parent | 88b3a37eaab4004cd3d26976dc3ee875bdba0b63 (diff) |
test: Add underscore prefix to macro parameters
If a test happens to use the same variable as the macro parameter the
macro does not work as intended. Add an underscore to guard against this.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/test/ut.h | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/include/test/ut.h b/include/test/ut.h index f616c202f35..c9fc9cc8395 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -56,39 +56,39 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line, /* Assert that two int expressions are equal */ #define ut_asserteq(expr1, expr2) { \ - unsigned int val1 = (expr1), val2 = (expr2); \ + unsigned int _val1 = (expr1), _val2 = (expr2); \ \ - if (val1 != val2) { \ + if (_val1 != _val2) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr1 " == " #expr2, \ - "Expected %#x (%d), got %#x (%d)", val1, val1, \ - val2, val2); \ + "Expected %#x (%d), got %#x (%d)", \ + _val1, _val1, _val2, _val2); \ return CMD_RET_FAILURE; \ } \ } /* Assert that two string expressions are equal */ #define ut_asserteq_str(expr1, expr2) { \ - const char *val1 = (expr1), *val2 = (expr2); \ + const char *_val1 = (expr1), *_val2 = (expr2); \ \ - if (strcmp(val1, val2)) { \ + if (strcmp(_val1, _val2)) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \ - "Expected \"%s\", got \"%s\"", val1, val2); \ + "Expected \"%s\", got \"%s\"", _val1, _val2); \ return CMD_RET_FAILURE; \ } \ } /* Assert that two memory areas are equal */ #define ut_asserteq_mem(expr1, expr2, len) { \ - const u8 *val1 = (u8 *)(expr1), *val2 = (u8 *)(expr2); \ + const u8 *_val1 = (u8 *)(expr1), *_val2 = (u8 *)(expr2); \ const uint __len = len; \ \ - if (memcmp(val1, val2, __len)) { \ + if (memcmp(_val1, _val2, __len)) { \ char __buf1[64 + 1] = "\0"; \ char __buf2[64 + 1] = "\0"; \ - bin2hex(__buf1, val1, min(__len, (uint)32)); \ - bin2hex(__buf2, val2, min(__len, (uint)32)); \ + bin2hex(__buf1, _val1, min(__len, (uint)32)); \ + bin2hex(__buf2, _val2, min(__len, (uint)32)); \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \ "Expected \"%s\", got \"%s\"", \ @@ -99,33 +99,33 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line, /* Assert that two pointers are equal */ #define ut_asserteq_ptr(expr1, expr2) { \ - const void *val1 = (expr1), *val2 = (expr2); \ + const void *_val1 = (expr1), *_val2 = (expr2); \ \ - if (val1 != val2) { \ + if (_val1 != _val2) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \ - "Expected %p, got %p", val1, val2); \ + "Expected %p, got %p", _val1, _val2); \ return CMD_RET_FAILURE; \ } \ } /* Assert that a pointer is NULL */ #define ut_assertnull(expr) { \ - const void *val = (expr); \ + const void *_val = (expr); \ \ - if (val != NULL) { \ + if (_val) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr " != NULL", \ - "Expected NULL, got %p", val); \ + "Expected NULL, got %p", _val); \ return CMD_RET_FAILURE; \ } \ } /* Assert that a pointer is not NULL */ #define ut_assertnonnull(expr) { \ - const void *val = (expr); \ + const void *_val = (expr); \ \ - if (val == NULL) { \ + if (!_val) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr " = NULL", \ "Expected non-null, got NULL"); \ @@ -135,13 +135,13 @@ 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); \ + const void *_val = (expr); \ \ - if (IS_ERR(val)) { \ + if (IS_ERR(_val)) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr " = NULL", \ "Expected pointer, got error %ld", \ - PTR_ERR(val)); \ + PTR_ERR(_val)); \ return CMD_RET_FAILURE; \ } \ } |