From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Tamir Duberstein <tamird@gmail.com>
Cc: David Gow <davidgow@google.com>, Petr Mladek <pmladek@suse.com>,
Steven Rostedt <rostedt@goodmis.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Andrew Morton <akpm@linux-foundation.org>,
Shuah Khan <shuah@kernel.org>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH 0/2] printf: convert self-test to KUnit
Date: Mon, 10 Feb 2025 12:57:25 +0100 [thread overview]
Message-ID: <87y0yeqafu.fsf@prevas.dk> (raw)
In-Reply-To: <CAJ-ks9=0+fk22Dx-65a+CSYhy0dnjTJuot9PtgOCi5Th1_wARA@mail.gmail.com> (Tamir Duberstein's message of "Fri, 7 Feb 2025 06:27:57 -0500")
On Fri, Feb 07 2025, Tamir Duberstein <tamird@gmail.com> wrote:
> On Fri, Feb 7, 2025 at 5:01 AM Rasmus Villemoes
> <linux@rasmusvillemoes.dk> wrote:
>>
>> On Thu, Feb 06 2025, Tamir Duberstein <tamird@gmail.com> wrote:
>>
>>
>> I'll have to see the actual code, of course. In general, I find reading
>> code using those KUNIT macros quite hard, because I'm not familiar with
>> those macros and when I try to look up what they do they turn out to be
>> defined in terms of other KUNIT macros 10 levels deep.
>>
>> But that still leaves a few points. First, I really like that "388 test
>> cases passed" tally or some other free-form summary (so that I can see
>> that I properly hooked up, compiled, and ran a new testcase inside
>> test_number(), so any kind of aggregation on those top-level test_* is
>> too coarse).
>
> This one I'm not sure how to address. What you're calling test cases
> here would typically be referred to as assertions, and I'm not aware
> of a way to report a count of assertions.
>
I'm not sure that's accurate.
The thing is, each of the current test() instances results in four
different tests being done, which is roughly why we end up at the 4*97
== 388, but each of those tests has several assertions being done -
depending on which variant of the test we're doing (i.e. the buffer
length used or if we're passing it through kasprintf), we may do only
some of those assertions, and we do an early return in case one of those
assertions fail (because it wouldn't be safe to do the following
assertions, and the test as such has failed already). So there are far
more assertions than those 388.
OTOH, that the number reported is 388 is more a consequence of the
implementation than anything explicitly designed. I can certainly live
with 388 being replaced by 97, i.e. that each current test() invocation
would count as one KUNIT case, as that would still allow me to detect a
PEBKAC when I've added a new test() instance and failed to actually run
that.
>> The other thing I want to know is if this would make it harder for me to
>> finish up that "deterministic random testing" thing I wrote [*], but
>> never got around to actually get it upstream. It seems like something
>> that a framework like kunit could usefully provide out-of-the-box (which
>> is why I attempted to get it into kselftest), but as long as I'd still
>> be able to add in something like that, and get a "xxx failed, random
>> seed used was 0xabcdef" line printed, and run the test again setting the
>> seed explicitly to that 0xabcdef value, I'm good.
>>
>> [*] https://lore.kernel.org/lkml/20201025214842.5924-4-linux@rasmusvillemoes.dk/
>
> I can't speak for the framework, but it wouldn't be any harder to do
> in printf itself. I did it this way:
>
> +static struct rnd_state rnd_state;
> +static u64 seed;
> +
> static int printf_suite_init(struct kunit_suite *suite)
> {
> alloced_buffer = kmalloc(BUF_SIZE + 2*PAD_SIZE, GFP_KERNEL);
> if (!alloced_buffer)
> return -1;
> test_buffer = alloced_buffer + PAD_SIZE;
> +
> + seed = get_random_u64();
> + prandom_seed_state(&rnd_state, seed);
> return 0;
> }
>
> static void printf_suite_exit(struct kunit_suite *suite)
> {
> kfree(alloced_buffer);
> + if (kunit_suite_has_succeeded(suite) == KUNIT_FAILURE) {
> + pr_info("Seed: %llu\n", seed);
> + }
> }
>
> and the result (once I made one of the cases fail):
>
> printf_kunit: Seed: 11480747578984087668
> # printf: pass:27 fail:1 skip:0 total:28
> # Totals: pass:27 fail:1 skip:0 total:28
> not ok 1 printf
>
OK, that's good. I think one of the problems previously was that there
no longer was such an _init/_exit pair one could hook into to do the
seed logic and afterwards do something depending on the success/fail of
the whole thing; that was all hidden away by some KUNIT_ wrapping.
Is it still possible to trivially make that seed into a module
parameter, and do the "modprobe test_printf seed=0xabcd", or otherwise
inject a module parameter when run/loaded via the kunit framework?
Rasmus
next prev parent reply other threads:[~2025-02-10 11:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-04 19:36 [PATCH 0/2] printf: convert self-test to KUnit Tamir Duberstein
2025-02-04 19:36 ` [PATCH 1/2] " Tamir Duberstein
2025-02-05 9:32 ` Geert Uytterhoeven
2025-02-04 19:36 ` [PATCH 2/2] printf: break kunit into test cases Tamir Duberstein
2025-02-06 9:26 ` [PATCH 0/2] printf: convert self-test to KUnit Rasmus Villemoes
2025-02-06 15:42 ` Tamir Duberstein
2025-02-07 7:55 ` David Gow
2025-02-07 10:01 ` Rasmus Villemoes
2025-02-07 11:27 ` Tamir Duberstein
2025-02-10 11:57 ` Rasmus Villemoes [this message]
2025-02-11 7:15 ` David Gow
2025-02-11 8:40 ` Rasmus Villemoes
2025-02-11 11:34 ` Tamir Duberstein
2025-02-11 19:21 ` Tamir Duberstein
2025-02-12 9:25 ` David Gow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y0yeqafu.fsf@prevas.dk \
--to=linux@rasmusvillemoes.dk \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=davidgow@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=shuah@kernel.org \
--cc=tamird@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox