Linux-kselftest Archive mirror
 help / color / mirror / Atom feed
From: Ivan Orlov <ivan.orlov0322@gmail.com>
To: Rae Moar <rmoar@google.com>
Cc: brendan.higgins@linux.dev, davidgow@google.com,
	linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
	linux-kernel@vger.kernel.org, skhan@linuxfoundation.org
Subject: Re: [PATCH] kunit: Cover 'assert.c' with tests
Date: Sat, 4 May 2024 17:45:05 +0100	[thread overview]
Message-ID: <f069c4b4-e358-4eac-9780-9ca9c598f7ae@gmail.com> (raw)
In-Reply-To: <89c0f7c2-145c-4d4c-a330-f0fff5bb4098@gmail.com>

On 5/3/24 12:10, Ivan Orlov wrote:
> On 5/2/24 00:20, Rae Moar wrote:
>> On Sat, Apr 27, 2024 at 6:04 PM Ivan Orlov <ivan.orlov0322@gmail.com> 
>> wrote:
>>>
>>> There are multiple assertion formatting functions in the `assert.c`
>>> file, which are not covered with tests yet. Implement the KUnit test
>>> for these functions.
>>>
>>> The test consists of 11 test cases for the following functions:
>>>
>>> 1) 'is_literal'
>>> 2) 'is_str_literal'
>>> 3) 'kunit_assert_prologue', test case for multiple assert types
>>> 4) 'kunit_assert_print_msg'
>>> 5) 'kunit_unary_assert_format'
>>> 6) 'kunit_ptr_not_err_assert_format'
>>> 7) 'kunit_binary_assert_format'
>>> 8) 'kunit_binary_ptr_assert_format'
>>> 9) 'kunit_binary_str_assert_format'
>>> 10) 'kunit_assert_hexdump'
>>> 11) 'kunit_mem_assert_format'
>>>
>>> The test aims at maximizing the branch coverage for the assertion
>>> formatting functions. As you can see, it covers some of the static
>>> helper functions as well, so we have to import the test source in the
>>> `assert.c` file in order to be able to call and validate them.
>>>
>>> Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
>>
>> Hello!
>>
>> This is a great patch and addition of KUnit tests. Happy to see it.
>> Thank you very much!
>>
>> I do have a few comments below. But none of them are deal breakers.
> 
> 
> Hi Rae,
> 
> Thank you so much for the detailed review.
> 
>>
>>> ---
>>>   lib/kunit/assert.c      |   4 +
>>>   lib/kunit/assert_test.c | 416 ++++++++++++++++++++++++++++++++++++++++
>>>   2 files changed, 420 insertions(+)
>>>   create mode 100644 lib/kunit/assert_test.c
>>>
>>> diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c
>>> index dd1d633d0fe2..ab68c6daf546 100644
>>> --- a/lib/kunit/assert.c
>>> +++ b/lib/kunit/assert.c
>>> @@ -270,3 +270,7 @@ void kunit_mem_assert_format(const struct 
>>> kunit_assert *assert,
>>>          }
>>>   }
>>>   EXPORT_SYMBOL_GPL(kunit_mem_assert_format);
>>> +
>>> +#if IS_ENABLED(CONFIG_KUNIT_TEST)
>>> +#include "assert_test.c"
>>> +#endif
>>
>> I might consider using the macro VISIBLE_IF_KUNIT macro, found in
>> include/kunit/visibility.h, to make the static functions in assert.c
>> visible only if KUnit is enabled. To avoid having to add the include
>> here. What do you think?
>>
> 
> Wow, I haven't seen this macro before, thank you for the suggestion! 
> I'll use it in the V2 of the patch.
> 
> I assume we need to use it in combination with EXPORT_SYMBOL_IF_KUNIT, 
> otherwise GCC will complain on use of functions without definitions, right?
> 

Ah, alright, it seems like GCC is going to complain on missing 
prototypes anyway, so we have to declare these static functions in the 
header file if CONFIG_KUNIT is defined.

-- 
Kind regards,
Ivan Orlov


      parent reply	other threads:[~2024-05-04 16:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-27 22:04 [PATCH] kunit: Cover 'assert.c' with tests Ivan Orlov
2024-04-29 21:26 ` Rae Moar
2024-04-30  9:19   ` Ivan Orlov
2024-05-01 23:20 ` Rae Moar
2024-05-03 11:10   ` Ivan Orlov
2024-05-03 12:18     ` Ivan Orlov
2024-05-04 16:45     ` Ivan Orlov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f069c4b4-e358-4eac-9780-9ca9c598f7ae@gmail.com \
    --to=ivan.orlov0322@gmail.com \
    --cc=brendan.higgins@linux.dev \
    --cc=davidgow@google.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=rmoar@google.com \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).