Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>,
	Daniel Latypov <dlatypov@google.com>,
	David Gow <davidgow@google.com>,
	Lucas De Marchi <lucas.demarchi@intel.com>
Subject: [PATCH 1/4] kunit: Introduce kunit_is_running()
Date: Wed, 21 Aug 2024 16:43:02 +0200	[thread overview]
Message-ID: <20240821144305.1958-2-michal.wajdeczko@intel.com> (raw)
In-Reply-To: <20240821144305.1958-1-michal.wajdeczko@intel.com>

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>
---
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


  reply	other threads:[~2024-08-21 14:43 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-21 14:43 [PATCH 0/4] kunit: Add macros to help write more complex tests Michal Wajdeczko
2024-08-21 14:43 ` Michal Wajdeczko [this message]
2024-08-21 21:21   ` [PATCH 1/4] kunit: Introduce kunit_is_running() Rae Moar
2024-08-21 21:24   ` Lucas De Marchi
2024-08-22  6:13   ` David Gow
2024-08-21 14:43 ` [PATCH 2/4] kunit: Add macro to conditionally expose declarations to tests Michal Wajdeczko
2024-08-21 21:21   ` Rae Moar
2024-08-22  6:13   ` David Gow
2024-08-21 14:43 ` [PATCH 3/4] kunit: Allow function redirection outside of the KUnit thread Michal Wajdeczko
2024-08-21 21:32   ` Rae Moar
2024-08-21 21:47     ` Michal Wajdeczko
2024-08-21 21:38   ` Lucas De Marchi
2024-08-21 22:34     ` Michal Wajdeczko
2024-08-22  6:14   ` David Gow
2024-08-27 10:53     ` Michal Wajdeczko
2024-08-21 14:43 ` [PATCH 4/4] kunit: Add example with alternate function redirection method Michal Wajdeczko
2024-08-21 21:22   ` Rae Moar
2024-08-21 22:00     ` Michal Wajdeczko
2024-08-22 20:44       ` Rae Moar
2024-08-22  6:14   ` David Gow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240821144305.1958-2-michal.wajdeczko@intel.com \
    --to=michal.wajdeczko@intel.com \
    --cc=davidgow@google.com \
    --cc=dlatypov@google.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=lucas.demarchi@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox