From 908d0c177bbc7c34ab9129c6f2bcd87487115632 Mon Sep 17 00:00:00 2001 From: David Gow Date: Fri, 25 Nov 2022 16:43:04 +0800 Subject: kunit: Provide a static key to check if KUnit is actively running tests 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: David Gow Reviewed-by: Daniel Latypov Signed-off-by: Shuah Khan --- include/kunit/test.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include/kunit') diff --git a/include/kunit/test.h b/include/kunit/test.h index 4666a4d199ea..87ea90576b50 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,9 @@ #include +/* Static key: true if any KUnit tests are currently running */ +DECLARE_STATIC_KEY_FALSE(kunit_running); + struct kunit; /* Size of log associated with test. */ -- cgit v1.2.3