[PATCH v3 1/6] kunit: Introduce kunit_is_running()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
Reviewed-by: Rae Moar <rmoar@xxxxxxxxxx>
Reviewed-by: Lucas De Marchi <lucas.demarchi@xxxxxxxxx>
Reviewed-by: David Gow <davidgow@xxxxxxxxxx>
---
 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





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux