linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH 3/4] kunit: Add support for suite initialization and cleanup
       [not found] ` <20210723212353.896343-4-bvanassche@acm.org>
@ 2021-07-27 21:26   ` Brendan Higgins
  2021-07-29  3:33     ` Bart Van Assche
  0 siblings, 1 reply; 2+ messages in thread
From: Brendan Higgins @ 2021-07-27 21:26 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Christoph Hellwig, Joel Becker, linux-kernel, Bodo Stroesser,
	Martin K . Petersen, Yanko Kaneti, KUnit Development,
	open list:KERNEL SELFTEST FRAMEWORK

On Fri, Jul 23, 2021 at 2:24 PM Bart Van Assche <bvanassche@acm.org> wrote:
>
> Cc: Brendan Higgins <brendanhiggins@google.com>
> Cc: Bodo Stroesser <bostroesser@gmail.com>
> Cc: Martin K. Petersen <martin.petersen@oracle.com>
> Cc: Yanko Kaneti <yaneti@declera.com>

Please also CC davidgow@google.com, skhan@linuxfoundation.org,
kunit-dev@googlegroups.com, and linux-kselftest@vger.kernel.org for
KUnit changes in the future.

> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

This seems pretty sensible.

Reviewed-by: Brendan Higgins <brendanhiggins@google.com>

> ---
>  include/kunit/test.h |  4 ++++
>  lib/kunit/test.c     | 14 ++++++++++++++
>  2 files changed, 18 insertions(+)
>
> diff --git a/include/kunit/test.h b/include/kunit/test.h
> index 24b40e5c160b..a6eef96a409c 100644
> --- a/include/kunit/test.h
> +++ b/include/kunit/test.h
> @@ -215,6 +215,8 @@ static inline char *kunit_status_to_ok_not_ok(enum kunit_status status)
>   * struct kunit_suite - describes a related collection of &struct kunit_case
>   *
>   * @name:      the name of the test. Purely informational.
> + * @init_suite:        called once per test suite before the test cases.
> + * @exit_suite:        called once per test suite after all test cases.
>   * @init:      called before every test case.
>   * @exit:      called after every test case.
>   * @test_cases:        a null terminated array of test cases.
> @@ -229,6 +231,8 @@ static inline char *kunit_status_to_ok_not_ok(enum kunit_status status)
>   */
>  struct kunit_suite {
>         const char name[256];
> +       int (*init_suite)(void);
> +       void (*exit_suite)(void);

I like this idea. Many other unit testing libraries in other languages
have something similar.

I think it probably makes sense to not use any kind of context object
here (as you have done); nevertheless, I still think it is an
appropriate question for the list.

>         int (*init)(struct kunit *test);
>         void (*exit)(struct kunit *test);
>         struct kunit_case *test_cases;
> diff --git a/lib/kunit/test.c b/lib/kunit/test.c
> index d79ecb86ea57..c271692ced93 100644
> --- a/lib/kunit/test.c
> +++ b/lib/kunit/test.c
> @@ -397,9 +397,19 @@ int kunit_run_tests(struct kunit_suite *suite)
>  {
>         char param_desc[KUNIT_PARAM_DESC_SIZE];
>         struct kunit_case *test_case;
> +       int res = 0;
>
>         kunit_print_subtest_start(suite);
>
> +       if (suite->init_suite)
> +               res = suite->init_suite();
> +
> +       if (res < 0) {
> +               kunit_log(KERN_INFO, suite, KUNIT_SUBTEST_INDENT
> +                         "# Suite initialization failed (%d)\n", res);
> +               goto end;
> +       }
> +
>         kunit_suite_for_each_test_case(suite, test_case) {
>                 struct kunit test = { .param_value = NULL, .param_index = 0 };
>                 test_case->status = KUNIT_SKIPPED;
> @@ -439,6 +449,10 @@ int kunit_run_tests(struct kunit_suite *suite)
>                                       test.status_comment);
>         }
>
> +       if (suite->exit_suite)
> +               suite->exit_suite();
> +
> +end:
>         kunit_print_subtest_end(suite);
>
>         return 0;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 3/4] kunit: Add support for suite initialization and cleanup
  2021-07-27 21:26   ` [PATCH 3/4] kunit: Add support for suite initialization and cleanup Brendan Higgins
@ 2021-07-29  3:33     ` Bart Van Assche
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Van Assche @ 2021-07-29  3:33 UTC (permalink / raw)
  To: Brendan Higgins
  Cc: Christoph Hellwig, Joel Becker, linux-kernel, Bodo Stroesser,
	Martin K . Petersen, Yanko Kaneti, KUnit Development,
	open list:KERNEL SELFTEST FRAMEWORK

On 7/27/21 2:26 PM, Brendan Higgins wrote:
> On Fri, Jul 23, 2021 at 2:24 PM Bart Van Assche <bvanassche@acm.org> wrote:
>>
>> Cc: Brendan Higgins <brendanhiggins@google.com>
>> Cc: Bodo Stroesser <bostroesser@gmail.com>
>> Cc: Martin K. Petersen <martin.petersen@oracle.com>
>> Cc: Yanko Kaneti <yaneti@declera.com>
> 
> Please also CC davidgow@google.com, skhan@linuxfoundation.org,
> kunit-dev@googlegroups.com, and linux-kselftest@vger.kernel.org for
> KUnit changes in the future.

Will do.

>> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> 
> This seems pretty sensible.
> 
> Reviewed-by: Brendan Higgins <brendanhiggins@google.com>

Thanks for the review!

Bart.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-29  3:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20210723212353.896343-1-bvanassche@acm.org>
     [not found] ` <20210723212353.896343-4-bvanassche@acm.org>
2021-07-27 21:26   ` [PATCH 3/4] kunit: Add support for suite initialization and cleanup Brendan Higgins
2021-07-29  3:33     ` Bart Van Assche

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).