From: Arpitha Raghunandan <98.arpi@gmail.com>
To: Marco Elver <elver@google.com>
Cc: Brendan Higgins <brendanhiggins@google.com>,
skhan@linuxfoundation.org, Iurii Zaikin <yzaikin@google.com>,
Theodore Ts'o <tytso@mit.edu>,
Andreas Dilger <adilger.kernel@dilger.ca>,
"open list:KERNEL SELFTEST FRAMEWORK"
<linux-kselftest@vger.kernel.org>,
KUnit Development <kunit-dev@googlegroups.com>,
LKML <linux-kernel@vger.kernel.org>,
linux-kernel-mentees@lists.linuxfoundation.org,
linux-ext4@vger.kernel.org
Subject: Re: [PATCH v3 1/2] kunit: Support for Parameterized Testing
Date: Tue, 27 Oct 2020 20:09:14 +0530 [thread overview]
Message-ID: <5c38ba07-f910-ed0a-1a75-85240effaea7@gmail.com> (raw)
In-Reply-To: <CANpmjNMnkXLFeQU6xZNwj3bWqE4Ap47wQKkL3-0ENX+R1YoLOg@mail.gmail.com>
On 27/10/20 2:33 pm, Marco Elver wrote:
> I just tried to give this a spin on some of my tests and noticed some
> more things (apologies for the multiple rounds of comments):
>
> On Mon, 26 Oct 2020 at 19:36, Arpitha Raghunandan <98.arpi@gmail.com> wrote:
> [...]
>> /**
>> * struct kunit_suite - describes a related collection of &struct kunit_case
>> @@ -208,6 +217,15 @@ struct kunit {
>> const char *name; /* Read only after initialization! */
>> char *log; /* Points at case log after initialization */
>> struct kunit_try_catch try_catch;
>> + /* param_values points to test case parameters in parameterized tests */
>> + void *param_values;
>
> This should be singular, i.e. "param_value", since the generator only
> generates 1 value for each test. Whether or not that value is a
> pointer that points to more than 1 value or is an integer etc. is
> entirely test-dependent.
>
>> + /*
>> + * current_param stores the index of the parameter in
>> + * the array of parameters in parameterized tests.
>> + * current_param + 1 is printed to indicate the parameter
>> + * that causes the test to fail in case of test failure.
>> + */
>> + int current_param;
>
> I think, per your comment above, this should be named "param_index".
> Also, I would suggest removing the mention of "array" in the comment,
> because the parameters aren't dependent on use of an array.
>
>> /*
>> * success starts as true, and may only be set to false during a
>> * test case; thus, it is safe to update this across multiple
>> @@ -1742,4 +1760,18 @@ do { \
>> fmt, \
>> ##__VA_ARGS__)
>>
>> +/**
>> + * KUNIT_PARAM_GENERATOR() - Helper method for test parameter generators
>> + * required in parameterized tests.
>> + * @name: prefix of the name for the test parameter generator function.
>> + * @prev: a pointer to the previous test parameter, NULL for first parameter.
>> + * @array: a user-supplied pointer to an array of test parameters.
>> + */
>> +#define KUNIT_PARAM_GENERATOR(name, array) \
>> + static void *name##_gen_params(void *prev) \
>> + { \
>> + typeof((array)[0]) * __next = prev ? ((typeof(__next)) prev) + 1 : (array); \
>> + return __next - (array) < ARRAY_SIZE((array)) ? __next : NULL; \
>> + }
>> +
>> #endif /* _KUNIT_TEST_H */
>> diff --git a/lib/kunit/test.c b/lib/kunit/test.c
>> index 750704abe89a..b70ab9b12f3b 100644
>> --- a/lib/kunit/test.c
>> +++ b/lib/kunit/test.c
>> @@ -127,6 +127,11 @@ unsigned int kunit_test_case_num(struct kunit_suite *suite,
>> }
>> EXPORT_SYMBOL_GPL(kunit_test_case_num);
>>
>> +static void kunit_print_failed_param(struct kunit *test)
>> +{
>> + kunit_err(test, "\n\tTest failed at parameter: %d\n", test->current_param + 1);
>> +}
>
> Is this the only place where the param index is used? It might be
> helpful to show the index together with the test-case name, otherwise
> we get a series of test cases in the output which are all named the
> same which can be confusing.
>
Yes, this is the only place param index is used.
>> static void kunit_print_string_stream(struct kunit *test,
>> struct string_stream *stream)
>> {
>> @@ -168,6 +173,8 @@ static void kunit_fail(struct kunit *test, struct kunit_assert *assert)
>> assert->format(assert, stream);
>>
>> kunit_print_string_stream(test, stream);
>> + if (test->param_values)
>> + kunit_print_failed_param(test);
>>
>> WARN_ON(string_stream_destroy(stream));
>> }
>> @@ -239,7 +246,18 @@ static void kunit_run_case_internal(struct kunit *test,
>> }
>> }
>>
>> - test_case->run_case(test);
>> + if (!test_case->generate_params) {
>> + test_case->run_case(test);
>> + } else {
>> + test->param_values = test_case->generate_params(NULL);
>> + test->current_param = 0;
>> +
>> + while (test->param_values) {
>> + test_case->run_case(test);
>> + test->param_values = test_case->generate_params(test->param_values);
>> + test->current_param++;
>> + }
>> + }
>> }
>
> Looking forward to v4. :-)
>
> Thanks,
> -- Marco
>
I will make all the suggested changes.
Thanks!
prev parent reply other threads:[~2020-10-27 14:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-26 18:35 [PATCH v3 1/2] kunit: Support for Parameterized Testing Arpitha Raghunandan
2020-10-26 18:36 ` [PATCH v3 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature Arpitha Raghunandan
2020-10-27 17:33 ` Iurii Zaikin
2020-10-26 23:14 ` [PATCH v3 1/2] kunit: Support for Parameterized Testing Marco Elver
2020-10-27 5:14 ` Arpitha Raghunandan
2020-10-27 7:44 ` Marco Elver
2020-10-27 7:51 ` Arpitha Raghunandan
2020-10-27 7:55 ` Marco Elver
2020-10-27 9:03 ` Marco Elver
2020-10-27 14:39 ` Arpitha Raghunandan [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=5c38ba07-f910-ed0a-1a75-85240effaea7@gmail.com \
--to=98.arpi@gmail.com \
--cc=adilger.kernel@dilger.ca \
--cc=brendanhiggins@google.com \
--cc=elver@google.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tytso@mit.edu \
--cc=yzaikin@google.com \
/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 NNTP newsgroup(s).