• David Gow's avatar
    kunit: Provide a static key to check if KUnit is actively running tests · 908d0c17
    David Gow authored
    KUnit does a few expensive things when enabled. This hasn't been a
    problem because KUnit was only enabled on test kernels, but with a few
    people enabling (but not _using_) KUnit on production systems, we need a
    runtime way of handling this.
    
    Provide a 'kunit_running' static key (defaulting to false), which allows
    us to hide any KUnit code behind a static branch. This should reduce the
    performance impact (on other code) of having KUnit enabled to a single
    NOP when no tests are running.
    
    Note that, while it looks unintuitive, tests always run entirely within
    __kunit_test_suites_init(), so it's safe to decrement the static key at
    the end of this function, rather than in __kunit_test_suites_exit(),
    which is only there to clean up results in debugfs.
    Signed-off-by: default avatarDavid Gow <davidgow@google.com>
    Reviewed-by: default avatarDaniel Latypov <dlatypov@google.com>
    Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
    908d0c17
test.h 50.1 KB