diff mbox series

[4/5] kunit: assert: export non-static functions

Message ID 20240604123204.10412-5-ivan.orlov0322@gmail.com
State New
Headers show
Series Reorganize string-stream and assert tests | expand

Commit Message

Ivan Orlov June 4, 2024, 12:32 p.m. UTC
Export non-static functions from the assert.c file into the KUnit
namespace in order to be able to access them from the tests if
they are compiled as modules.

Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
---
 lib/kunit/assert.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

David Gow June 8, 2024, 9:20 a.m. UTC | #1
On Tue, 4 Jun 2024 at 20:32, Ivan Orlov <ivan.orlov0322@gmail.com> wrote:
>
> Export non-static functions from the assert.c file into the KUnit
> namespace in order to be able to access them from the tests if
> they are compiled as modules.
>
> Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
> ---

I think this could be merged with patch 5, as it's not useful on its
own. Also, a few of the symbol names might be a little too generic to
be exported: maybe we should give them a 'kunit_assert' prefix?

Cheers,
-- David

>  lib/kunit/assert.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c
> index 867aa5c4bccf..f394e4b8482f 100644
> --- a/lib/kunit/assert.c
> +++ b/lib/kunit/assert.c
> @@ -38,6 +38,7 @@ void kunit_assert_print_msg(const struct va_format *message,
>         if (message->fmt)
>                 string_stream_add(stream, "\n%pV", message);
>  }
> +EXPORT_SYMBOL_IF_KUNIT(kunit_assert_print_msg);
>
>  void kunit_fail_assert_format(const struct kunit_assert *assert,
>                               const struct va_format *message,
> @@ -112,6 +113,7 @@ VISIBLE_IF_KUNIT bool is_literal(const char *text, long long value)
>
>         return ret;
>  }
> +EXPORT_SYMBOL_IF_KUNIT(is_literal);

I'm a bit worried about having such a generic name exported, even
conditionally and to a namespace. Maybe we could give this a
'kunit_assert' prefix, or put it in a separate, more specific
namespace?

>
>  void kunit_binary_assert_format(const struct kunit_assert *assert,
>                                 const struct va_format *message,
> @@ -180,6 +182,7 @@ VISIBLE_IF_KUNIT bool is_str_literal(const char *text, const char *value)
>
>         return strncmp(text + 1, value, len - 2) == 0;
>  }
> +EXPORT_SYMBOL_IF_KUNIT(is_str_literal);

I'm a bit worried about having such a generic name exported, even
conditionally and to a namespace. Maybe we could give this a
'kunit_assert' prefix, or put it in a separate, more specific
namespace?




>  void kunit_binary_str_assert_format(const struct kunit_assert *assert,
>                                     const struct va_format *message,
> @@ -232,6 +235,7 @@ void kunit_assert_hexdump(struct string_stream *stream,
>                         string_stream_add(stream, " %02x ", buf1[i]);
>         }
>  }
> +EXPORT_SYMBOL_IF_KUNIT(kunit_assert_hexdump);
>
>  void kunit_mem_assert_format(const struct kunit_assert *assert,
>                              const struct va_format *message,
> --
> 2.34.1
>
Ivan Orlov June 9, 2024, 7:05 p.m. UTC | #2
On 6/8/24 10:20, David Gow wrote:
> I think this could be merged with patch 5, as it's not useful on its
> own. Also, a few of the symbol names might be a little too generic to
> be exported: maybe we should give them a 'kunit_assert' prefix?
> 
> Cheers,
> -- David
> 

Hi David,

Thank you for the review and yes, I agree that it would be more useful 
in the scope of the next patch (so I'm going to squash it with the next 
patch in the V2).

>>   lib/kunit/assert.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c
>> index 867aa5c4bccf..f394e4b8482f 100644
>> --- a/lib/kunit/assert.c
>> +++ b/lib/kunit/assert.c
>> @@ -38,6 +38,7 @@ void kunit_assert_print_msg(const struct va_format *message,
>>          if (message->fmt)
>>                  string_stream_add(stream, "\n%pV", message);
>>   }
>> +EXPORT_SYMBOL_IF_KUNIT(kunit_assert_print_msg);
>>
>>   void kunit_fail_assert_format(const struct kunit_assert *assert,
>>                                const struct va_format *message,
>> @@ -112,6 +113,7 @@ VISIBLE_IF_KUNIT bool is_literal(const char *text, long long value)
>>
>>          return ret;
>>   }
>> +EXPORT_SYMBOL_IF_KUNIT(is_literal);
> 
> I'm a bit worried about having such a generic name exported, even
> conditionally and to a namespace. Maybe we could give this a
> 'kunit_assert' prefix, or put it in a separate, more specific
> namespace?
> 

Yeah, makes sense, I'll rename them in the next version of the series. 
Thank you!

>>
>>   void kunit_binary_assert_format(const struct kunit_assert *assert,
>>                                  const struct va_format *message,
>> @@ -180,6 +182,7 @@ VISIBLE_IF_KUNIT bool is_str_literal(const char *text, const char *value)
>>
>>          return strncmp(text + 1, value, len - 2) == 0;
>>   }
>> +EXPORT_SYMBOL_IF_KUNIT(is_str_literal);
> 
> I'm a bit worried about having such a generic name exported, even
> conditionally and to a namespace. Maybe we could give this a
> 'kunit_assert' prefix, or put it in a separate, more specific
> namespace?
> 
> 

Same here: will be renamed :)

Thanks!

> 
> 
>>   void kunit_binary_str_assert_format(const struct kunit_assert *assert,
>>                                      const struct va_format *message,
>> @@ -232,6 +235,7 @@ void kunit_assert_hexdump(struct string_stream *stream,
>>                          string_stream_add(stream, " %02x ", buf1[i]);
>>          }
>>   }
>> +EXPORT_SYMBOL_IF_KUNIT(kunit_assert_hexdump);
>>
>>   void kunit_mem_assert_format(const struct kunit_assert *assert,
>>                               const struct va_format *message,
>> --
>> 2.34.1
>>
diff mbox series

Patch

diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c
index 867aa5c4bccf..f394e4b8482f 100644
--- a/lib/kunit/assert.c
+++ b/lib/kunit/assert.c
@@ -38,6 +38,7 @@  void kunit_assert_print_msg(const struct va_format *message,
 	if (message->fmt)
 		string_stream_add(stream, "\n%pV", message);
 }
+EXPORT_SYMBOL_IF_KUNIT(kunit_assert_print_msg);
 
 void kunit_fail_assert_format(const struct kunit_assert *assert,
 			      const struct va_format *message,
@@ -112,6 +113,7 @@  VISIBLE_IF_KUNIT bool is_literal(const char *text, long long value)
 
 	return ret;
 }
+EXPORT_SYMBOL_IF_KUNIT(is_literal);
 
 void kunit_binary_assert_format(const struct kunit_assert *assert,
 				const struct va_format *message,
@@ -180,6 +182,7 @@  VISIBLE_IF_KUNIT bool is_str_literal(const char *text, const char *value)
 
 	return strncmp(text + 1, value, len - 2) == 0;
 }
+EXPORT_SYMBOL_IF_KUNIT(is_str_literal);
 
 void kunit_binary_str_assert_format(const struct kunit_assert *assert,
 				    const struct va_format *message,
@@ -232,6 +235,7 @@  void kunit_assert_hexdump(struct string_stream *stream,
 			string_stream_add(stream, " %02x ", buf1[i]);
 	}
 }
+EXPORT_SYMBOL_IF_KUNIT(kunit_assert_hexdump);
 
 void kunit_mem_assert_format(const struct kunit_assert *assert,
 			     const struct va_format *message,