[PATCH v3 2/6] kunit: Add macro to conditionally expose declarations to tests

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

 



The DECLARE_IF_KUNIT macro will introduces identifiers only if
CONFIG_KUNIT is enabled. Otherwise if CONFIG_KUNIT is not enabled
no identifiers from the param list will be defined.

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@xxxxxxxxx>
Reviewed-by: Rae Moar <rmoar@xxxxxxxxxx>
Reviewed-by: David Gow <davidgow@xxxxxxxxxx>
---
Cc: Lucas De Marchi <lucas.demarchi@xxxxxxxxx>
---
v2: include struct example in macro comment (Lucas)
    reformat kernel-doc for better output (Michal)
---
 include/kunit/visibility.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/include/kunit/visibility.h b/include/kunit/visibility.h
index 0dfe35feeec6..c1825381adfc 100644
--- a/include/kunit/visibility.h
+++ b/include/kunit/visibility.h
@@ -11,6 +11,25 @@
 #define _KUNIT_VISIBILITY_H
 
 #if IS_ENABLED(CONFIG_KUNIT)
+    /**
+     * DECLARE_IF_KUNIT - Conditionally introduce identifiers
+     * @body: identifiers to be introduced conditionally
+     *
+     * This macro introduces identifiers only if CONFIG_KUNIT is enabled.
+     * Otherwise if CONFIG_KUNIT is not enabled no identifiers will be defined.
+     *
+     * .. code-block:: C
+     *
+     *     struct example {
+     *         // @foo: regular data
+     *         int foo;
+     *
+     *         // private: data available only for CONFIG_KUNIT
+     *         DECLARE_IF_KUNIT(int bar);
+     *     };
+     */
+    #define DECLARE_IF_KUNIT(body...)	body
+
     /**
      * VISIBLE_IF_KUNIT - A macro that sets symbols to be static if
      * CONFIG_KUNIT is not enabled. Otherwise if CONFIG_KUNIT is enabled
@@ -26,6 +45,7 @@
     #define EXPORT_SYMBOL_IF_KUNIT(symbol) EXPORT_SYMBOL_NS(symbol, \
 	    EXPORTED_FOR_KUNIT_TESTING)
 #else
+    #define DECLARE_IF_KUNIT(body...)
     #define VISIBLE_IF_KUNIT static
     #define EXPORT_SYMBOL_IF_KUNIT(symbol)
 #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