kunit: cleanup assertion macro internal variables
authorDaniel Latypov <dlatypov@google.com>
Thu, 27 Jan 2022 21:52:22 +0000 (13:52 -0800)
committerShuah Khan <skhan@linuxfoundation.org>
Mon, 31 Jan 2022 18:55:48 +0000 (11:55 -0700)
All the operands should be tagged `const`.
We're only assigning them to variables so that we can compare them (e.g.
check if left == right, etc.) and avoid evaluating expressions multiple
times.

There's no need for them to be mutable.

Also rename the helper variable `loc` to `__loc` like we do with
`__assertion` and `__strs` to avoid potential name collisions with user
code.

Signed-off-by: Daniel Latypov <dlatypov@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
include/kunit/test.h

index 088ff394ae944ba475d0e16da6a989a5976ee0d0..00b9ff7783ab801004bfdcc8f3f3ea027ea1a222 100644 (file)
@@ -779,10 +779,10 @@ void kunit_do_failed_assertion(struct kunit *test,
 
 #define KUNIT_ASSERTION(test, assert_type, pass, assert_class, INITIALIZER, fmt, ...) do { \
        if (unlikely(!(pass))) {                                               \
-               static const struct kunit_loc loc = KUNIT_CURRENT_LOC;         \
+               static const struct kunit_loc __loc = KUNIT_CURRENT_LOC;       \
                struct assert_class __assertion = INITIALIZER;                 \
                kunit_do_failed_assertion(test,                                \
-                                         &loc,                                \
+                                         &__loc,                              \
                                          assert_type,                         \
                                          &__assertion.assert,                 \
                                          fmt,                                 \
@@ -872,8 +872,8 @@ void kunit_do_failed_assertion(struct kunit *test,
                                    fmt,                                       \
                                    ...)                                       \
 do {                                                                          \
-       typeof(left) __left = (left);                                          \
-       typeof(right) __right = (right);                                       \
+       const typeof(left) __left = (left);                                    \
+       const typeof(right) __right = (right);                                 \
        static const struct kunit_binary_assert_text __text = {                \
                .operation = #op,                                              \
                .left_text = #left,                                            \
@@ -956,7 +956,7 @@ do {                                                                               \
                                                fmt,                           \
                                                ...)                           \
 do {                                                                          \
-       typeof(ptr) __ptr = (ptr);                                             \
+       const typeof(ptr) __ptr = (ptr);                                       \
                                                                               \
        KUNIT_ASSERTION(test,                                                  \
                        assert_type,                                           \