• Daniel Latypov's avatar
    kunit: move check if assertion passed into the macros · 4fdacef8
    Daniel Latypov authored
    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: default avatarDaniel Latypov <dlatypov@google.com>
    Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
    Reviewed-by: default avatarDavid Gow <davidgow@google.com>
    Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
    4fdacef8
test.h 63.6 KB