Re: [PATCH v2] lib/test: convert test_overflow.c to use KUnit

From: Brendan Higgins
Date: Tue May 18 2021 - 17:29:04 EST


On Tue, May 11, 2021 at 3:05 PM Daniel Latypov <dlatypov@xxxxxxxxxx> wrote:
>
> This largely consists of:
> * replacing `err |= test_func(...)` calls with `test_func(test, ...)`.
> * changing pr_warn to KUNIT_*_MSG() macros to mark the failed test
> while printing a diagnostic message
> * dropping __init as there are concerns of this causing issues w/ KUnit
> when running on some other arches.
>
> With the exception of now needing to set CONFIG_KUNIT=y, the test can
> still be run as before, at boot time or as a test module.
> But now the output of the test will be TAP (Test Anything Protocol),
> the format used by kselftest instead of just warnings and printing
> "FAIL!" , see [1].
>
> But now the test can also be run more quickly via kunit.py
>
> $ ./tools/testing/kunit/kunit.py run --kunitconfig /dev/stdin <<EOF
> CONFIG_KUNIT=y
> CONFIG_TEST_OVERFLOW=y
> EOF
>
> Note: after a mrproper this took
> > Elapsed time: 38.683s total, 3.598s configuring, 32.141s building, 0.000s running
>
> (Normally would be less clunky as you wouldn't use a heredoc).
>
> [1] Here's an example failure message after tweaking the test array:
> TAP version 14
> 1..1
> # Subtest: lib_overflow
> 1..10
> # test_u8_overflow: u8 : 18 arithmetic tests
> # test_u8_overflow: EXPECTATION FAILED at lib/test_overflow.c:251
> Expected _got == p->sum, but
> _got == 0
> p->sum == 1
> wrong result for 0 + 0 (type u8)
> ...
> not ok 1 - test_u8_overflow
> # test_s8_overflow: s8 : 19 arithmetic tests
> ok 2 - test_s8_overflow
> ...
> # test_overflow_shift: ok: (s32)(0 << 31) == 0
> # test_overflow_shift: ok: (s64)(0 << 63) == 0
> ok 9 - test_overflow_shift
>
> Signed-off-by: Daniel Latypov <dlatypov@xxxxxxxxxx>
> Tested-by: David Gow <davidgow@xxxxxxxxxx>

Looks good to me.

Acked-by: Brendan Higgins <brendanhiggins@xxxxxxxxxx>