From: Kees Cook <keescook@chromium.org>
To: Vitor Massaru Iha <vitor@massaru.org>
Cc: linux-kselftest@vger.kernel.org, brendanhiggins@google.com,
linux-kernel@vger.kernel.org, davidgow@google.com,
linux-kernel-mentees@lists.linuxfoundation.org,
kunit-dev@googlegroups.com
Subject: Re: [Linux-kernel-mentees] [RFC 3/3] lib: Convert test_user_copy to KUnit test
Date: Wed, 15 Jul 2020 19:34:06 -0700 [thread overview]
Message-ID: <202007151929.7A4E04E@keescook> (raw)
In-Reply-To: <20200715031120.1002016-4-vitor@massaru.org>
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@massaru.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; \
})
--
Kees Cook
_______________________________________________
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-16 2:34 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-15 3:11 [Linux-kernel-mentees] [RFC 0/3] kunit: add support to use modules Vitor Massaru Iha
2020-07-15 3:11 ` [Linux-kernel-mentees] [RFC 1/3] kunit: tool: Add support root filesystem in kunit-tool Vitor Massaru Iha
2020-07-16 0:29 ` Brendan Higgins via Linux-kernel-mentees
2020-07-16 16:34 ` Vitor Massaru Iha
2020-07-15 3:11 ` [Linux-kernel-mentees] [RFC 2/3] lib: Allows to borrow mm in userspace on KUnit Vitor Massaru Iha
2020-07-16 0:37 ` Brendan Higgins via Linux-kernel-mentees
2020-07-16 16:35 ` Vitor Massaru Iha
2020-07-16 16:35 ` Vitor Massaru Iha
2020-07-15 3:11 ` [Linux-kernel-mentees] [RFC 3/3] lib: Convert test_user_copy to KUnit test Vitor Massaru Iha
2020-07-16 0:40 ` Brendan Higgins via Linux-kernel-mentees
2020-07-16 16:40 ` Vitor Massaru Iha
2020-07-16 2:34 ` Kees Cook [this message]
2020-07-16 16:42 ` Vitor Massaru Iha
2020-07-15 3:47 ` [Linux-kernel-mentees] [RFC 0/3] kunit: add support to use modules David Gow via Linux-kernel-mentees
2020-07-16 2:41 ` Kees Cook
2020-07-16 16:32 ` Vitor Massaru Iha
2020-07-16 16:21 ` 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=202007151929.7A4E04E@keescook \
--to=keescook@chromium.org \
--cc=brendanhiggins@google.com \
--cc=davidgow@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=vitor@massaru.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).