[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <b3703bfd299c4156e44e5887dcc47e7dcc88dae7.camel@massaru.org>
Date: Thu, 16 Jul 2020 13:42:20 -0300
From: Vitor Massaru Iha <vitor@...saru.org>
To: Kees Cook <keescook@...omium.org>
Cc: kunit-dev@...glegroups.com, linux-kselftest@...r.kernel.org,
linux-kernel@...r.kernel.org, brendanhiggins@...gle.com,
davidgow@...gle.com, skhan@...uxfoundation.org,
linux-kernel-mentees@...ts.linuxfoundation.org
Subject: Re: [RFC 3/3] lib: Convert test_user_copy to KUnit test
On Wed, 2020-07-15 at 19:34 -0700, Kees Cook wrote:
> On Wed, Jul 15, 2020 at 12:11:20AM -0300, Vitor Massaru Iha wrote:
> > This adds the conversion of the runtime tests of test_user_copy
> > fuctions,
> > from `lib/test_user_copy.c`to KUnit tests.
> >
> > Signed-off-by: Vitor Massaru Iha <vitor@...saru.org>
> > [...]
> > @@ -16,6 +16,7 @@
> > #include <linux/slab.h>
> > #include <linux/uaccess.h>
> > #include <linux/vmalloc.h>
> > +#include <kunit/test.h>
> >
> > /*
> > * Several 32-bit architectures support 64-bit {get,put}_user()
> > calls.
> > @@ -31,26 +32,16 @@
> > # define TEST_U64
> > #endif
> >
> > -#define test(condition, msg, ...)
> > \
> > -({
> > \
> > - int cond = (condition);
> > \
> > - if (cond) \
> > - pr_warn("[%d] " msg "\n", __LINE__, ##__VA_ARGS__); \
> > - cond;
> > \
> > -})
> > -
> > static bool is_zeroed(void *from, size_t size)
> > {
> > return memchr_inv(from, 0x0, size) == NULL;
> > }
> >
> > -static int test_check_nonzero_user(char *kmem, char __user *umem,
> > size_t size)
> > +static void test_check_nonzero_user(struct kunit *test, char
> > *kmem, char __user *umem, size_t size)
> > {
> > - int ret = 0;
> > size_t start, end, i, zero_start, zero_end;
> >
> > - if (test(size < 2 * PAGE_SIZE, "buffer too small"))
> > - return -EINVAL;
> > + KUNIT_EXPECT_FALSE_MSG(test, size < 2 * PAGE_SIZE, "buffer too
> > small");
>
> I think this could be a much smaller diff if you just replaced the
> "test" macro:
>
> #define test(condition, msg, ...)
> \
> ({
> \
> int cond = !!(condition); \
> KUNIT_EXPECT_FALSE_MSG(kunit_context, cond, msg,
> ##__VA_ARGS__);\
> cond;
> \
> })
>
Sure, I'll do it.
Thanks.
Powered by blists - more mailing lists