Thread (9 messages) 9 messages, 2 authors, 2022-08-12

Re: [PATCH v4 1/5] kunit: unify module and builtin suite definitions

From: Geert Uytterhoeven <geert@linux-m68k.org>
Date: 2022-08-12 08:08:41
Also in: linux-aspeed, linux-kselftest, linux-mmc, linux-usb, lkml, openbmc

Hi David,

On Thu, Aug 11, 2022 at 6:56 PM David Gow [off-list ref] wrote:
On Thu, Aug 11, 2022 at 9:49 PM Geert Uytterhoeven [off-list ref] wrote:
quoted
On Sat, Jul 9, 2022 at 5:21 AM David Gow [off-list ref] wrote:
quoted
From: Jeremy Kerr <jk@codeconstruct.com.au>

Currently, KUnit runs built-in tests and tests loaded from modules
differently. For built-in tests, the kunit_test_suite{,s}() macro adds a
list of suites in the .kunit_test_suites linker section. However, for
kernel modules, a module_init() function is used to run the test suites.

This causes problems if tests are included in a module which already
defines module_init/exit_module functions, as they'll conflict with the
kunit-provided ones.

This change removes the kunit-defined module inits, and instead parses
the kunit tests from their own section in the module. After module init,
we call __kunit_test_suites_init() on the contents of that section,
which prepares and runs the suite.

This essentially unifies the module- and non-module kunit init formats.

Tested-by: Maíra Canal <redacted>
Reviewed-by: Brendan Higgins <redacted>
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Signed-off-by: Daniel Latypov <redacted>
Signed-off-by: David Gow <redacted>
Thanks for your patch, which is now commit 3d6e44623841c8b8 ("kunit:
unify module and builtin suite definitions") upstream.

Since this commit, modular kunit tests are no longer run at all.

Before:

    # insmod lib/kunit/kunit.ko
    # insmod lib/test_hash.ko
    test_hash: loading test module taints kernel.
        # Subtest: hash
        1..2
        ok 1 - test_string_or
        ok 2 - test_hash_or
    # hash: pass:2 fail:0 skip:0 total:2
    # Totals: pass:2 fail:0 skip:0 total:2
    ok 1 - hash

After:

    # insmod lib/kunit/kunit.ko
    # insmod lib/test_hash.ko
    test_hash: loading test module taints kernel.

The actual test code (and test init code, if it exists) is not run.

Reverting commits e5857d396f35e59e ("kunit: flatten kunit_suite***
to kunit_suite** in .kunit_test_suites") and 3d6e44623841c8b8 ("kunit:
unify module and builtin suite definitions") fixes the issue.
Thanks Geert,

This is a known issue. There's a patch to fix it here, which just
missed the pull request:
https://patchwork.kernel.org/project/linux-kselftest/patch/20220713005221.1926290-1-davidgow@google.com/

We'll try to get it merged as soon as possible.
Thanks for the pointer. I can confirm it fixes the issue, so I provided
my Tb tag.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help