Re: [PATCH] lib: overflow: Convert to Kunit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Feb 17, 2022 at 9:09 AM Kees Cook <keescook@xxxxxxxxxxxx> wrote:
>
> On Wed, Feb 16, 2022 at 02:57:12PM -0800, Daniel Latypov wrote:
> > On Wed, Feb 16, 2022 at 2:42 PM Kees Cook <keescook@xxxxxxxxxxxx> wrote:
> > >
> > > Convert overflow unit tests to KUnit, for better integration into the
> > > kernel self test framework. Includes a rename of test_overflow.c to
> > > overflow_kunit.c, and CONFIG_TEST_OVERFLOW to CONFIG_OVERFLOW_KUNIT_TEST.
> > >
> > > $ ./tools/testing/kunit/kunit.py config
> > > ...
> > > $ ./tools/testing/kunit/kunit.py run overflow
> >
> > JFYI, you can run this as a one-liner via
> >
> > $ ./tools/testing/kunit/kunit.py run --kunitconfig /dev/stdin <<EOF
> > CONFIG_KUNIT=y
> > CONFIG_TEST_OVERFLOW=y
> > EOF
> >
> > The above is taken from my own duplicate version of this patch
> > [1] https://lore.kernel.org/linux-kselftest/20210503211536.1384578-1-dlatypov@xxxxxxxxxx/
>
> Ah-ha! I thought I remembered this conversion being proposed before but
> I totally failed to find it. Thank you! I'll compare/adjust this patch
> and add you as Co-developed-by.

There's a lot that's already identical line for line.
I think I pointed to all the places where they differed in any
meaningful way down below.
So you can probably save yourself the time of looking over.

And yeah, I vaguely remembered that Vitor had worked on it, but
somehow failed to find that as well.
Something about this test :)

>
> > > ...
> > > [14:33:51] Starting KUnit Kernel (1/1)...
> > > [14:33:51] ============================================================
> > > [14:33:51] ================== overflow (11 subtests) ==================
> > > [14:33:51] [PASSED] u8_overflow_test
> > > [14:33:51] [PASSED] s8_overflow_test
> > > [14:33:51] [PASSED] u16_overflow_test
> > > [14:33:51] [PASSED] s16_overflow_test
> > > [14:33:51] [PASSED] u32_overflow_test
> > > [14:33:51] [PASSED] s32_overflow_test
> > > [14:33:51] [PASSED] u64_overflow_test
> > > [14:33:51] [PASSED] s64_overflow_test
> > > [14:33:51] [PASSED] overflow_shift_test
> > > [14:33:51] [PASSED] overflow_allocation_test
> > > [14:33:51] [PASSED] overflow_size_helpers_test
> > > [14:33:51] ==================== [PASSED] overflow =====================
> > > [14:33:51] ============================================================
> > > [14:33:51] Testing complete. Passed: 11, Failed: 0, Crashed: 0, Skipped: 0, Errors: 0
> > > [14:33:51] Elapsed time: 12.525s total, 0.001s configuring, 12.402s building, 0.101s running
> > >
> > > Cc: David Gow <davidgow@xxxxxxxxxx>
> > > Cc: Vitor Massaru Iha <vitor@xxxxxxxxxxx>
> > > Cc: Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx>
> > > Cc: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>
> > > Co-developed-by: Vitor Massaru Iha <vitor@xxxxxxxxxxx>
> > > Signed-off-by: Vitor Massaru Iha <vitor@xxxxxxxxxxx>
> > > Link: https://lore.kernel.org/lkml/20200720224418.200495-1-vitor@xxxxxxxxxxx/
> > > Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>
> >
> > Reviewed-by: Daniel Latypov <dlatypov@xxxxxxxxxx>
> >
> > Looks good to me, some minor nits/suggestions wrt KUnit usage.
> > Nice to see this test converted over!
>
> Thanks!
>
> > [...]
> > > index f6530fce799d..4cc27b9926a1 100644
> > > --- a/lib/test_overflow.c
> > > +++ b/lib/overflow_kunit.c
> > > @@ -1,9 +1,13 @@
> > >  // SPDX-License-Identifier: GPL-2.0 OR MIT
> > >  /*
> > > - * Test cases for arithmetic overflow checks.
> > > + * Test cases for arithmetic overflow checks. See:
> > > + * https://www.kernel.org/doc/html/latest/dev-tools/kunit/kunit-tool.html#configuring-building-and-running-tests
> > > + *     ./tools/testing/kunit/kunit.py config
> > > + *     ./tools/testing/kunit/kunit.py run overflow [--raw_output]
> > >   */
> > >  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> >
> > We can drop the pr_fmt now, I think
>
> My instinct is to leave these in place just so that anything weird that
> gets inlined and sneaks a pr_*() call into the code will have a
> meaningful prefix.

Ack, sounds good.
We've historically dropped it and assumed we'd use kunit_info() for
all the pr_*()'s we cared about.

But there's definitely concern that some macro might use it to print
an important and relevant message, hmm.



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux