Message ID | 20240821144305.1958-3-michal.wajdeczko@intel.com (mailing list archive) |
---|---|
State | New |
Delegated to: | Brendan Higgins |
Headers | show |
Series | kunit: Add macros to help write more complex tests | expand |
On Wed, Aug 21, 2024 at 10:43 AM Michal Wajdeczko <michal.wajdeczko@intel.com> wrote: > > 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@intel.com> Hello! I like this macro. I think it could definitely be useful in declaring static functions for KUnit testing in the header files. So I am happy to add it. We should also add this to the documentation at some point. I've been wanting to revamp the visibility.h macros documentation anyways. Reviewed-by: Rae Moar <rmoar@google.com> Thanks! -Rae > --- > Cc: Rae Moar <rmoar@google.com> > Cc: David Gow <davidgow@google.com> > Cc: Lucas De Marchi <lucas.demarchi@intel.com> > --- > include/kunit/visibility.h | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/include/kunit/visibility.h b/include/kunit/visibility.h > index 0dfe35feeec6..1c23773f826c 100644 > --- a/include/kunit/visibility.h > +++ b/include/kunit/visibility.h > @@ -11,6 +11,13 @@ > #define _KUNIT_VISIBILITY_H > > #if IS_ENABLED(CONFIG_KUNIT) > + /** > + * DECLARE_IF_KUNIT - A macro that introduces identifiers only if > + * CONFIG_KUNIT is enabled. Otherwise if CONFIG_KUNIT is not enabled > + * no identifiers will be defined. > + * @body: identifiers to be introduced conditionally > + */ > + #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 +33,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 >
On Wed, 21 Aug 2024 at 22:43, Michal Wajdeczko <michal.wajdeczko@intel.com> wrote: > > 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@intel.com> > --- > Cc: Rae Moar <rmoar@google.com> > Cc: David Gow <davidgow@google.com> > Cc: Lucas De Marchi <lucas.demarchi@intel.com> > --- I like this, thanks! Reviewed-by: David Gow <davidgow@google.com> > include/kunit/visibility.h | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/include/kunit/visibility.h b/include/kunit/visibility.h > index 0dfe35feeec6..1c23773f826c 100644 > --- a/include/kunit/visibility.h > +++ b/include/kunit/visibility.h > @@ -11,6 +11,13 @@ > #define _KUNIT_VISIBILITY_H > > #if IS_ENABLED(CONFIG_KUNIT) > + /** > + * DECLARE_IF_KUNIT - A macro that introduces identifiers only if > + * CONFIG_KUNIT is enabled. Otherwise if CONFIG_KUNIT is not enabled > + * no identifiers will be defined. > + * @body: identifiers to be introduced conditionally > + */ > + #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 +33,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 >
diff --git a/include/kunit/visibility.h b/include/kunit/visibility.h index 0dfe35feeec6..1c23773f826c 100644 --- a/include/kunit/visibility.h +++ b/include/kunit/visibility.h @@ -11,6 +11,13 @@ #define _KUNIT_VISIBILITY_H #if IS_ENABLED(CONFIG_KUNIT) + /** + * DECLARE_IF_KUNIT - A macro that introduces identifiers only if + * CONFIG_KUNIT is enabled. Otherwise if CONFIG_KUNIT is not enabled + * no identifiers will be defined. + * @body: identifiers to be introduced conditionally + */ + #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 +33,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
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@intel.com> --- Cc: Rae Moar <rmoar@google.com> Cc: David Gow <davidgow@google.com> Cc: Lucas De Marchi <lucas.demarchi@intel.com> --- include/kunit/visibility.h | 8 ++++++++ 1 file changed, 8 insertions(+)