Re: [PATCH] kunit: Reset suite counter right before running tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 5 Oct 2023 at 04:57, Michal Wajdeczko
<michal.wajdeczko@xxxxxxxxx> wrote:
>
> Today we reset the suite counter as part of the suite cleanup,
> called from the module exit callback, but it might not work that
> well as one can try to collect results without unloading a previous
> test (either unintentionally or due to dependencies).
>
> For easy reproduction try to load the kunit-test.ko and then
> collect and parse results from the kunit-example-test.ko load.
> Parser will complain about mismatch of expected test number:
>
> [ ] KTAP version 1
> [ ] 1..1
> [ ]     # example: initializing suite
> [ ]     KTAP version 1
> [ ]     # Subtest: example
> ..
> [ ] # example: pass:5 fail:0 skip:4 total:9
> [ ] # Totals: pass:6 fail:0 skip:6 total:12
> [ ] ok 7 example
>
> [ ] [ERROR] Test: example: Expected test number 1 but found 7
> [ ] ===================== [PASSED] example =====================
> [ ] ============================================================
> [ ] Testing complete. Ran 12 tests: passed: 6, skipped: 6, errors: 1
>
> Since we are now printing suite test plan on every module load,
> right before running suite tests, we should make sure that suite
> counter will also start from 1. Easiest solution seems to be move
> counter reset to the __kunit_test_suites_init() function.
>
> Signed-off-by: Michal Wajdeczko <michal.wajdeczko@xxxxxxxxx>
> Cc: David Gow <davidgow@xxxxxxxxxx>
> Cc: Rae Moar <rmoar@xxxxxxxxxx>
> ---

This looks good to me. Thanks. Originally the suite counter was a
static variable in __kunit_test_suites_exit(), before we had to deal
with modules properly.

This seems much better, though.

Reviewed-by: David Gow <davidgow@xxxxxxxxxx>

Cheers,
-- David


>  lib/kunit/test.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/kunit/test.c b/lib/kunit/test.c
> index f2eb71f1a66c..9325d309ed82 100644
> --- a/lib/kunit/test.c
> +++ b/lib/kunit/test.c
> @@ -670,6 +670,8 @@ int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_
>                 return 0;
>         }
>
> +       kunit_suite_counter = 1;
> +
>         static_branch_inc(&kunit_running);
>
>         for (i = 0; i < num_suites; i++) {
> @@ -696,8 +698,6 @@ void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites)
>
>         for (i = 0; i < num_suites; i++)
>                 kunit_exit_suite(suites[i]);
> -
> -       kunit_suite_counter = 1;
>  }
>  EXPORT_SYMBOL_GPL(__kunit_test_suites_exit);
>
> --
> 2.25.1
>

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux