Re: [PATCH] lib/atomic64_test.c: convert to use KUnit

David Gow
2022-06-17T08:03:33Z

On Fri, Jun 17, 2022 at 2:04 AM Daniel Latypov <dlatypov@google.com> wrote:
>
> The test currently is a bunch of checks (implemented using BUG_ON())
> that can be built into the kernel or as a module.
>
> Convert it to a KUnit test, which can also run in both modes.
> From a user's perspective, this change adds a CONFIG_KUNIT=y dep and
> changes the output format of the test [1] and makes it less destructive
> on failure. The test itself is the same.
>
> This hopefully makes the test easier to run and more consistent with
> similar tests in lib/.
> Since it has no dependencies, it can be run without explicitly setting
> up a .kunitconfig via
> $ ./tools/testing/kunit/kunit.py run atomic
> ...
> [13:53:44] Starting KUnit Kernel (1/1)...
> [13:53:44] ============================================================
> [13:53:47] =================== atomic (2 subtests) ====================
> [13:53:47] [PASSED] test_atomic
> [13:53:47] [PASSED] test_atomic64
> [13:53:47] ===================== [PASSED] atomic ======================
> [13:53:47] ============================================================
> [13:53:47] Testing complete. Passed: 2, Failed: 0, Crashed: 0, Skipped: 0, Errors: 0
> [13:53:47] Elapsed time: 13.902s total, 1.629s configuring, 9.331s building, 2.852s running
>
> It can be run on ARCH=x86_64 (and others) via:
> $ ./tools/testing/kunit/kunit.py run --arch=x86_64 atomic
>
> The message about which platform the test ran on won't show up in
> kunit.py, but still gets printed out in dmesg, e.g.
> > TAP version 14
> > 1..1
> > # Subtest: atomic
> > 1..2
> > ok 1 - test_atomic
> > ok 2 - test_atomic64
> > # atomic: ran on x86-64 platform with CX8 and with SSE
> > # atomic: pass:2 fail:0 skip:0 total:2
> > # Totals: pass:2 fail:0 skip:0 total:2
> > ok 1 - atomic
>
> [1] https://www.kernel.org/doc/html/latest/dev-tools/ktap.html
>
> Signed-off-by: Daniel Latypov <dlatypov@google.com>
> Reviewed-by: David Gow <davidgow@google.com>
> Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
> Tested-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
> ---
> Meta: this is a resend of https://lore.kernel.org/linux-kselftest/20220502192327.81153-1-dlatypov@google.com/
> Michael kindly pointed me to the right MAINTAINERS entry (this test file
> isn't covered by it, and it slipped my mind to check the non-test code).
>
> I've waited until 5.19-rc1 so that the relevant KUnit patches this
> depended on have been merged.
> Rebasing and tweaking the commit message a bit are the only changes.
> ---

Tested this again just to be sure, and it still builds, runs, and
passes for me on:

- UML (x86_64)
- x86_64 + qemu
- i386 + qemu
- arm64 + qemu + clang/LLVM

Cheers,
-- David