Re: [PATCH 2/2] kunit: Reset test->priv after each param iteration

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

 



On Fri, 15 Dec 2023 at 23:13, Michal Wajdeczko
<michal.wajdeczko@xxxxxxxxx> wrote:
>
> If we run parameterized test that uses test->priv to prepare some
> custom data, then value of test->priv will leak to the next param
> iteration and may be unexpected.  This could be easily seen if
> we promote example_priv_test to parameterized test as then only
> first test iteration will be successful:
>
> $ ./tools/testing/kunit/kunit.py run \
>         --kunitconfig ./lib/kunit/.kunitconfig *.example_priv*
>
> [ ] Starting KUnit Kernel (1/1)...
> [ ] ============================================================
> [ ] =================== example (1 subtest) ====================
> [ ] ==================== example_priv_test  ====================
> [ ] [PASSED] example value 3
> [ ] # example_priv_test: initializing
> [ ] # example_priv_test: ASSERTION FAILED at lib/kunit/kunit-example-test.c:230
> [ ] Expected test->priv == ((void *)0), but
> [ ]     test->priv == 0000000060dfe290
> [ ]     ((void *)0) == 0000000000000000
> [ ] # example_priv_test: cleaning up
> [ ] [FAILED] example value 2
> [ ] # example_priv_test: initializing
> [ ] # example_priv_test: ASSERTION FAILED at lib/kunit/kunit-example-test.c:230
> [ ] Expected test->priv == ((void *)0), but
> [ ]     test->priv == 0000000060dfe290
> [ ]     ((void *)0) == 0000000000000000
> [ ] # example_priv_test: cleaning up
> [ ] [FAILED] example value 1
> [ ] # example_priv_test: initializing
> [ ] # example_priv_test: ASSERTION FAILED at lib/kunit/kunit-example-test.c:230
> [ ] Expected test->priv == ((void *)0), but
> [ ]     test->priv == 0000000060dfe290
> [ ]     ((void *)0) == 0000000000000000
> [ ] # example_priv_test: cleaning up
> [ ] [FAILED] example value 0
> [ ] # example_priv_test: initializing
> [ ] # example_priv_test: cleaning up
> [ ] # example_priv_test: pass:1 fail:3 skip:0 total:4
> [ ] ================ [FAILED] example_priv_test ================
> [ ]     # example: initializing suite
> [ ]     # module: kunit_example_test
> [ ]     # example: exiting suite
> [ ] # Totals: pass:1 fail:3 skip:0 total:4
> [ ] ===================== [FAILED] example =====================
>
> Fix that by resetting test->priv after each param iteration, in
> similar way what we did for the test->status.
>
> Signed-off-by: Michal Wajdeczko <michal.wajdeczko@xxxxxxxxx>
> Cc: David Gow <davidgow@xxxxxxxxxx>
> Cc: Rae Moar <rmoar@xxxxxxxxxx>
> ---

Looks good to me. I'd vaguely assumed we'd treat test.priv as having
an undefined value on test start, but thinking about it, I like making
it explicitly NULL better.

Reviewed-by: David Gow <davidgow@xxxxxxxxxx>

Cheers,
-- David

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