diff mbox series

[v2,3/6] kunit: Add macro to conditionally expose expressions to tests

Message ID 20240826222015.1484-4-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

Commit Message

Michal Wajdeczko Aug. 26, 2024, 10:20 p.m. UTC
The ONLY_IF_KUNIT macro will add expression statement only if the
CONFIG_KUNIT is enabled. Otherwise if CONFIG_KUNIT is not enabled
it will evaluate always to 0.

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(+)

Comments

Rae Moar Aug. 27, 2024, 7:04 p.m. UTC | #1
On Mon, Aug 26, 2024 at 3:20 PM Michal Wajdeczko
<michal.wajdeczko@intel.com> wrote:
>
> The ONLY_IF_KUNIT macro will add expression statement only if the
> CONFIG_KUNIT is enabled. Otherwise if CONFIG_KUNIT is not enabled
> it will evaluate always to 0.
>
> Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>

Hello!

Thanks for the second version of this patch series!

I definitely could see this new macro as being useful but I currently
don't see an example of its use in the rest of the patch series. How
do you see this macro as being used or do you have a current use case
for this macro?

I would be fine adding this macro without being used as long as
examples on how and why to use it are clearly documented.

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 1c23773f826c..69c71eacf368 100644
> --- a/include/kunit/visibility.h
> +++ b/include/kunit/visibility.h
> @@ -18,6 +18,13 @@
>       * @body: identifiers to be introduced conditionally
>       */
>      #define DECLARE_IF_KUNIT(body...)  body
> +    /**
> +     * ONLY_IF_KUNIT - A macro that adds expression statement only if
> +     * CONFIG_KUNIT is enabled. Otherwise if CONFIG_KUNIT is not enabled
> +     * it will evaluate always to 0.
> +     * @expr: expression to be introduced conditionally
> +     */
> +    #define ONLY_IF_KUNIT(expr...)     expr
>      /**
>       * VISIBLE_IF_KUNIT - A macro that sets symbols to be static if
>       * CONFIG_KUNIT is not enabled. Otherwise if CONFIG_KUNIT is enabled
> @@ -34,6 +41,7 @@
>             EXPORTED_FOR_KUNIT_TESTING)
>  #else
>      #define DECLARE_IF_KUNIT(body...)
> +    #define ONLY_IF_KUNIT(expr...) 0
>      #define VISIBLE_IF_KUNIT static
>      #define EXPORT_SYMBOL_IF_KUNIT(symbol)
>  #endif
> --
> 2.43.0
>
Michal Wajdeczko Aug. 27, 2024, 7:47 p.m. UTC | #2
On 27.08.2024 21:04, Rae Moar wrote:
> On Mon, Aug 26, 2024 at 3:20 PM Michal Wajdeczko
> <michal.wajdeczko@intel.com> wrote:
>>
>> The ONLY_IF_KUNIT macro will add expression statement only if the
>> CONFIG_KUNIT is enabled. Otherwise if CONFIG_KUNIT is not enabled
>> it will evaluate always to 0.
>>
>> Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
> 
> Hello!
> 
> Thanks for the second version of this patch series!
> 
> I definitely could see this new macro as being useful but I currently
> don't see an example of its use in the rest of the patch series. How
> do you see this macro as being used or do you have a current use case
> for this macro?

in Xe driver we have this macro defined as XE_TEST_ONLY [1]

[1] https://elixir.bootlin.com/linux/v6.11-rc5/A/ident/XE_TEST_ONLY

> 
> I would be fine adding this macro without being used as long as
> examples on how and why to use it are clearly documented.

sure, I'll try to add some usage in the example patch 5/6

> 
> 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 1c23773f826c..69c71eacf368 100644
>> --- a/include/kunit/visibility.h
>> +++ b/include/kunit/visibility.h
>> @@ -18,6 +18,13 @@
>>       * @body: identifiers to be introduced conditionally
>>       */
>>      #define DECLARE_IF_KUNIT(body...)  body
>> +    /**
>> +     * ONLY_IF_KUNIT - A macro that adds expression statement only if
>> +     * CONFIG_KUNIT is enabled. Otherwise if CONFIG_KUNIT is not enabled
>> +     * it will evaluate always to 0.
>> +     * @expr: expression to be introduced conditionally
>> +     */
>> +    #define ONLY_IF_KUNIT(expr...)     expr
>>      /**
>>       * VISIBLE_IF_KUNIT - A macro that sets symbols to be static if
>>       * CONFIG_KUNIT is not enabled. Otherwise if CONFIG_KUNIT is enabled
>> @@ -34,6 +41,7 @@
>>             EXPORTED_FOR_KUNIT_TESTING)
>>  #else
>>      #define DECLARE_IF_KUNIT(body...)
>> +    #define ONLY_IF_KUNIT(expr...) 0
>>      #define VISIBLE_IF_KUNIT static
>>      #define EXPORT_SYMBOL_IF_KUNIT(symbol)
>>  #endif
>> --
>> 2.43.0
>>
diff mbox series

Patch

diff --git a/include/kunit/visibility.h b/include/kunit/visibility.h
index 1c23773f826c..69c71eacf368 100644
--- a/include/kunit/visibility.h
+++ b/include/kunit/visibility.h
@@ -18,6 +18,13 @@ 
      * @body: identifiers to be introduced conditionally
      */
     #define DECLARE_IF_KUNIT(body...)	body
+    /**
+     * ONLY_IF_KUNIT - A macro that adds expression statement only if
+     * CONFIG_KUNIT is enabled. Otherwise if CONFIG_KUNIT is not enabled
+     * it will evaluate always to 0.
+     * @expr: expression to be introduced conditionally
+     */
+    #define ONLY_IF_KUNIT(expr...)	expr
     /**
      * VISIBLE_IF_KUNIT - A macro that sets symbols to be static if
      * CONFIG_KUNIT is not enabled. Otherwise if CONFIG_KUNIT is enabled
@@ -34,6 +41,7 @@ 
 	    EXPORTED_FOR_KUNIT_TESTING)
 #else
     #define DECLARE_IF_KUNIT(body...)
+    #define ONLY_IF_KUNIT(expr...) 0
     #define VISIBLE_IF_KUNIT static
     #define EXPORT_SYMBOL_IF_KUNIT(symbol)
 #endif