]> git.baikalelectronics.ru Git - kernel.git/commit
kunit: move check if assertion passed into the macros
authorDaniel Latypov <dlatypov@google.com>
Thu, 13 Jan 2022 16:59:27 +0000 (08:59 -0800)
committerShuah Khan <skhan@linuxfoundation.org>
Tue, 25 Jan 2022 19:49:40 +0000 (12:49 -0700)
commit33f07de11d46306e4557867a4b7a3e581f1937d6
tree899ab17bd2a34dce25d6dae4ce3030b309e51d4e
parentc5cc5ff7faa6bb6ef36909b8562deb9a9afb43d9
kunit: move check if assertion passed into the macros

Currently the code always calls kunit_do_assertion() even though it does
nothing when `pass` is true.

This change moves the `if(!(pass))` check into the macro instead
and renames the function to kunit_do_failed_assertion().
I feel this a bit easier to read and understand.

This has the potential upside of avoiding a function call that does
nothing most of the time (assuming your tests are passing) but comes
with the downside of generating a bit more code and branches. We try to
mitigate the branches by tagging them with `unlikely()`.

This also means we don't have to initialize structs that we don't need,
which will become a tiny bit more expensive if we switch over to using
static variables to try and reduce stack usage. (There's runtime code
to check if the variable has been initialized yet or not).

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