Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kunit: cleanup assertion macro internal variables

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>

authored by

Daniel Latypov and committed by
Shuah Khan
c2741453 2b6861e2

+5 -5
+5 -5
include/kunit/test.h
··· 779 779 780 780 #define KUNIT_ASSERTION(test, assert_type, pass, assert_class, INITIALIZER, fmt, ...) do { \ 781 781 if (unlikely(!(pass))) { \ 782 - static const struct kunit_loc loc = KUNIT_CURRENT_LOC; \ 782 + static const struct kunit_loc __loc = KUNIT_CURRENT_LOC; \ 783 783 struct assert_class __assertion = INITIALIZER; \ 784 784 kunit_do_failed_assertion(test, \ 785 - &loc, \ 785 + &__loc, \ 786 786 assert_type, \ 787 787 &__assertion.assert, \ 788 788 fmt, \ ··· 872 872 fmt, \ 873 873 ...) \ 874 874 do { \ 875 - typeof(left) __left = (left); \ 876 - typeof(right) __right = (right); \ 875 + const typeof(left) __left = (left); \ 876 + const typeof(right) __right = (right); \ 877 877 static const struct kunit_binary_assert_text __text = { \ 878 878 .operation = #op, \ 879 879 .left_text = #left, \ ··· 956 956 fmt, \ 957 957 ...) \ 958 958 do { \ 959 - typeof(ptr) __ptr = (ptr); \ 959 + const typeof(ptr) __ptr = (ptr); \ 960 960 \ 961 961 KUNIT_ASSERTION(test, \ 962 962 assert_type, \