From: Vitor Massaru Iha <vitor@massaru.org>
To: peterz@infradead.org
Cc: irogers@google.com, Brendan Higgins <brendanhiggins@google.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
"open list:KERNEL SELFTEST FRAMEWORK"
<linux-kselftest@vger.kernel.org>,
linux-kernel-mentees@lists.linuxfoundation.org, mingo@kernel.org,
KUnit Development <kunit-dev@googlegroups.com>
Subject: Re: [Linux-kernel-mentees] [PATCH] lib: kunit: add test_min_heap test conversion to KUnit
Date: Wed, 29 Jul 2020 18:57:17 -0300 [thread overview]
Message-ID: <CADQ6JjW-=SNjV-abGpGA9NfHD4yGG_bD5FmvW99W-Vo06twkbw@mail.gmail.com> (raw)
In-Reply-To: <20200729203908.GD2655@hirez.programming.kicks-ass.net>
Hi Peter,
On Wed, Jul 29, 2020 at 5:39 PM <peterz@infradead.org> wrote:
>
> On Wed, Jul 29, 2020 at 05:11:46PM -0300, Vitor Massaru Iha wrote:
> > This adds the conversion of the runtime tests of test_min_heap,
> > from `lib/test_min_heap.c` to KUnit tests.
> >
> > Please apply this commit first (linux-kselftest/kunit-fixes):
> > 3f37d14b8a3152441f36b6bc74000996679f0998 kunit: kunit_config: Fix parsing of CONFIG options with space
> >
> > Signed-off-by: Vitor Massaru Iha <vitor@massaru.org>
> > ---
> > lib/Kconfig.debug | 29 ++++--
> > lib/Makefile | 2 +-
> > lib/{test_min_heap.c => min_heap_kunit.c} | 117 ++++++++++++----------
> > 3 files changed, 83 insertions(+), 65 deletions(-)
> > rename lib/{test_min_heap.c => min_heap_kunit.c} (60%)
>
> So where's the win? What's KUnit, why should I care and more lines.
KUnit is a unit testing and mocking framework for the Linux kernel. [0]
In Kconfig.debug you only have some more information about KUnit.
If the number of lines is a parameter that should be considered, I can
change sections like this
- if (last > values[0]) {
- pr_err("error: expected %d <= %d\n", last,
- values[0]);
- err++;
- }
+ KUNIT_EXPECT_FALSE_MSG(context,
+ last > values[0],
+ "expected %d <= %d\n",
+ last, values[0]);
To this:
- if (last > values[0]) {
- pr_err("error: expected %d <= %d\n", last,
- values[0]);
- err++;
- }
+ KUNIT_EXPECT_FALSE_MSG(context, last >
values[0], "expected %d <= %d\n", last, values[0]);
And from this:
+static struct kunit_case __refdata min_heap_test_cases[] = {
+ KUNIT_CASE(test_heapify_all_true),
+ KUNIT_CASE(test_heapify_all_false),
+ KUNIT_CASE(test_heap_push_true),
+ KUNIT_CASE(test_heap_push_false),
+ KUNIT_CASE(test_heap_pop_push_true),
+ KUNIT_CASE(test_heap_pop_push_false),
+ {}
To this:
+static struct kunit_case __refdata min_heap_test_cases[] = {
+ KUNIT_CASE(test_min_heap),
+ {}
I did the latter this way to be more informative, but if the goal is
to reduce lines of code, this is possible.
The results can be seen this way:
This is an excerpt from the test.log with the result in TAP format:
[snip]
ok 5 - example
# Subtest: min-heap
1..6
ok 1 - test_heapify_all_true
ok 2 - test_heapify_all_false
ok 3 - test_heap_push_true
ok 4 - test_heap_push_false
ok 5 - test_heap_pop_push_true
ok 6 - test_heap_pop_push_false
[snip]
And this from kunit-tool:
[snip]
[18:43:32] ============================================================
[18:43:32] ======== [PASSED] min-heap ========
[18:43:32] [PASSED] test_heapify_all_true
[18:43:32] [PASSED] test_heapify_all_false
[18:43:32] [PASSED] test_heap_push_true
[18:43:32] [PASSED] test_heap_push_false
[18:43:32] [PASSED] test_heap_pop_push_true
[18:43:32] [PASSED] test_heap_pop_push_false
[18:43:32] ============================================================
[18:43:32] Testing complete. 20 tests run. 0 failed. 0 crashed.
[18:43:32] Elapsed time: 9.758s total, 0.001s configuring, 6.012s
building, 0.000s running
[snip]
BR,
Vitor
[0] https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html#what-is-kunit
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
next prev parent reply other threads:[~2020-07-29 21:57 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-29 20:11 [Linux-kernel-mentees] [PATCH] lib: kunit: add test_min_heap test conversion to KUnit Vitor Massaru Iha
2020-07-29 20:39 ` peterz
2020-07-29 21:57 ` Vitor Massaru Iha [this message]
2020-08-04 13:25 ` peterz
2020-08-04 13:46 ` Vitor Massaru Iha
2020-08-04 14:23 ` peterz
2020-08-04 16:22 ` Vitor Massaru Iha
2020-10-12 21:02 ` Brendan Higgins via Linux-kernel-mentees
2020-10-14 18:16 ` Ian Rogers via Linux-kernel-mentees
2020-10-14 19:59 ` Peter Zijlstra
2020-10-14 20:03 ` Vitor Massaru Iha
2020-07-29 22:56 ` Ian Rogers via Linux-kernel-mentees
2020-07-29 23:12 ` Vitor Massaru Iha
2020-10-14 23:49 ` Vitor Massaru Iha
2020-10-15 16:30 ` Ian Rogers via Linux-kernel-mentees
2020-10-15 16:56 ` Vitor Massaru Iha
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='CADQ6JjW-=SNjV-abGpGA9NfHD4yGG_bD5FmvW99W-Vo06twkbw@mail.gmail.com' \
--to=vitor@massaru.org \
--cc=brendanhiggins@google.com \
--cc=irogers@google.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).