Re: [PATCH] kunit: memcpy: Split slow memcpy tests into MEMCPY_SLOW_KUNIT_TEST

From: Daniel Latypov
Date: Fri Jan 13 2023 - 20:38:42 EST


On Fri, Jan 13, 2023 at 4:54 PM Kees Cook <keescook@xxxxxxxxxxxx> wrote:
> diff --git a/lib/memcpy_kunit.c b/lib/memcpy_kunit.c
> index 89128551448d..5a545e1b5dbb 100644
> --- a/lib/memcpy_kunit.c
> +++ b/lib/memcpy_kunit.c
> @@ -307,8 +307,12 @@ static void set_random_nonzero(struct kunit *test, u8 *byte)
> }
> }
>
> -static void init_large(struct kunit *test)
> +static int init_large(struct kunit *test)
> {
> + if (!IS_ENABLED(CONFIG_MEMCPY_SLOW_KUNIT_TEST)) {
> + kunit_skip(test, "Slow test skipped. Enable with CONFIG_MEMCPY_SLOW_KUNIT_TEST=y");
> + return -EBUSY;

Note: kunit_skip() here means you don't need explicit returns in the test cases.
kunit_skip() is basically
kunit_mark_skipped(test, "reason");
kthread_complete_and_exit(...);

So the diff in this file could be reduced down to just these 2 lines
if (!IS_ENABLED(...))
kunit_skip(test, "...")

But I can see the appeal of being more explicit about the control flow.
In that case, you could switch kunit_mark_skipped(), which just sets
the status and doesn't affect control flow at all.

Daniel