linux-next/Documentation/dev-tools/kunit
David Gow 91e9359221 kunit: Use the static key when retrieving the current test
In order to detect if a KUnit test is running, and to access its
context, the 'kunit_test' member of the current task_struct is used.
Usually, this is accessed directly or via the kunit_fail_current_task()
function.

In order to speed up the case where no test is running, add a wrapper,
kunit_get_current_test(), which uses the static key to fail early.
Equally, Speed up kunit_fail_current_test() by using the static key.

This should make it convenient for code to call this
unconditionally in fakes or error paths, without worrying that this will
slow the code down significantly.

If CONFIG_KUNIT=n (or m), this compiles away to nothing. If
CONFIG_KUNIT=y, it will compile down to a NOP (on most architectures) if
no KUnit test is currently running.

Note that kunit_get_current_test() does not work if KUnit is built as a
module. This mirrors the existing restriction on kunit_fail_current_test().

Note that the definition of kunit_fail_current_test() still wraps an
empty, inline function if KUnit is not built-in. This is to ensure that
the printf format string __attribute__ will still work.

Also update the documentation to suggest users use the new
kunit_get_current_test() function, update the example, and to describe
the behaviour when KUnit is disabled better.

Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Sadiya Kazi <sadiyakazi@google.com>
Signed-off-by: David Gow <davidgow@google.com>
Reviewed-by: Daniel Latypov <dlatypov@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2022-12-12 14:13:47 -07:00
..
api kunit: split resource API from test.h into new resource.h 2022-04-04 16:23:08 -06:00
architecture.rst Documentation: Kunit: Update architecture.rst for minor fixes 2022-10-27 02:32:41 -06:00
faq.rst Documentation: Kunit: Add ref for other kinds of tests 2022-09-30 13:19:11 -06:00
index.rst Documentation: kunit: Remove redundant 'tips.rst' page 2022-12-12 14:13:47 -07:00
kunit_suitememorydiagram.svg Documentation: KUnit: Added KUnit Architecture 2021-12-23 12:49:06 -07:00
run_manual.rst Documentation: kunit: Reorganize documentation related to running tests 2021-12-23 12:49:43 -07:00
run_wrapper.rst Documentation: kunit: Update description of --alltests option 2022-10-07 10:19:25 -06:00
running_tips.rst Documentation: kunit: fix example run_kunit func to allow spaces in args 2022-07-11 16:33:51 -06:00
start.rst Documentation: Kunit: Use full path to .kunitconfig 2022-09-30 13:23:06 -06:00
style.rst Documentation: KUnit: Restyle Test Style and Nomenclature page 2021-12-23 12:49:43 -07:00
usage.rst kunit: Use the static key when retrieving the current test 2022-12-12 14:13:47 -07:00