On Wed, Aug 21, 2024 at 10:43 AM Michal Wajdeczko michal.wajdeczko@intel.com wrote:
Wrap uses of the static key 'kunit_running' into a helper macro to allow future checks to be placed in the code residing outside of the CONFIG_KUNIT. We will start using this in upcoming patch.
Signed-off-by: Michal Wajdeczko michal.wajdeczko@intel.com
Hello!
I am good with this. It is definitely a prettier way to access kunit_running.
Reviewed-by: Rae Moar rmoar@google.com
Thanks!
-Rae
Cc: Daniel Latypov dlatypov@google.com Cc: David Gow davidgow@google.com Cc: Lucas De Marchi lucas.demarchi@intel.com
include/kunit/test-bug.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/include/kunit/test-bug.h b/include/kunit/test-bug.h index 47aa8f21ccce..e8ea3bab7250 100644 --- a/include/kunit/test-bug.h +++ b/include/kunit/test-bug.h @@ -25,6 +25,13 @@ extern struct kunit_hooks_table { void *(*get_static_stub_address)(struct kunit *test, void *real_fn_addr); } kunit_hooks;
+/**
- kunit_is_running() - True, if KUnit test is currently running.
- If CONFIG_KUNIT is not enabled, it will compile down to a false.
- */
+#define kunit_is_running() static_branch_unlikely(&kunit_running)
/**
- kunit_get_current_test() - Return a pointer to the currently running
KUnit test.
@@ -40,7 +47,7 @@ extern struct kunit_hooks_table { */ static inline struct kunit *kunit_get_current_test(void) {
if (!static_branch_unlikely(&kunit_running))
if (!kunit_is_running()) return NULL; return current->kunit_test;
@@ -53,7 +60,7 @@ static inline struct kunit *kunit_get_current_test(void)
- If a KUnit test is running in the current task, mark that test as failed.
*/ #define kunit_fail_current_test(fmt, ...) do { \
if (static_branch_unlikely(&kunit_running)) { \
if (kunit_is_running()) { \ /* Guaranteed to be non-NULL when kunit_running true*/ \ kunit_hooks.fail_current_test(__FILE__, __LINE__, \ fmt, ##__VA_ARGS__); \
@@ -64,6 +71,7 @@ static inline struct kunit *kunit_get_current_test(void)
static inline struct kunit *kunit_get_current_test(void) { return NULL; }
+#define kunit_is_running() false #define kunit_fail_current_test(fmt, ...) do {} while (0)
#endif
2.43.0
-- You received this message because you are subscribed to the Google Groups "KUnit Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to kunit-dev+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20240821144305.1958-2-michal.waj....