From: Brendan Higgins <brendanhiggins@google.com>
To: David Gow <davidgow@google.com>
Cc: shuah@kernel.org, akpm@linux-foundation.org,
keescook@chromium.org, linux-kselftest@vger.kernel.org,
kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org,
dan.carpenter@oracle.com
Subject: Re: [PATCH linux-kselftest/test v5] lib/list-test: add a test for the 'list' doubly linked list
Date: Wed, 23 Oct 2019 15:02:48 -0700 [thread overview]
Message-ID: <20191023220248.GA55483@google.com> (raw)
In-Reply-To: <20191022221322.122788-1-davidgow@google.com>
On Tue, Oct 22, 2019 at 03:13:22PM -0700, 'David Gow' via KUnit Development wrote:
> Add a KUnit test for the kernel doubly linked list implementation in
> include/linux/list.h
>
> Each test case (list_test_x) is focused on testing the behaviour of the
> list function/macro 'x'. None of the tests pass invalid lists to these
> macros, and so should behave identically with DEBUG_LIST enabled and
> disabled.
>
> Note that, at present, it only tests the list_ types (not the
> singly-linked hlist_), and does not yet test all of the
> list_for_each_entry* macros (and some related things like
> list_prepare_entry).
>
> Signed-off-by: David Gow <davidgow@google.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Tested-by: Brendan Higgins <brendanhiggins@google.com>
I think I already had a "Reviewed-by and a Tested-by" on this patch.
Please make sure to apply the footers to subsequent versions of a patch
in the future.
> ---
> v5 replaces the use of KUNIT_ASSERT_NOT_ERR_OR_NULL() -- to check the
> return value from kzalloc() and kmalloc() -- with the __GFP_NOFAIL
> arugment. (Both in the list_test_list_init test.)
>
> Earlier versions of the test can be found:
> v4: https://lore.kernel.org/linux-kselftest/20191018215549.65000-1-davidgow@google.com/
> v3: https://lore.kernel.org/linux-kselftest/20191016215707.95317-1-davidgow@google.com/
> v2: https://lore.kernel.org/linux-kselftest/20191010185631.26541-1-davidgow@google.com/
> v1: https://lore.kernel.org/linux-kselftest/20191007213633.92565-1-davidgow@google.com/
>
>
> MAINTAINERS | 5 +
> lib/Kconfig.debug | 18 ++
> lib/Makefile | 3 +
> lib/list-test.c | 738 ++++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 764 insertions(+)
> create mode 100644 lib/list-test.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 7ef985e01457..7ced1b69a3d3 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -9504,6 +9504,11 @@ F: Documentation/misc-devices/lis3lv02d.rst
> F: drivers/misc/lis3lv02d/
> F: drivers/platform/x86/hp_accel.c
>
> +LIST KUNIT TEST
> +M: David Gow <davidgow@google.com>
> +S: Maintained
> +F: lib/list-test.c
Probably want to have a "mailing list" line. Something like:
"""
L: linux-kselftest@vger.kernel.org
L: kunit-dev@googlegroups.com
"""
> +
> LIVE PATCHING
> M: Josh Poimboeuf <jpoimboe@redhat.com>
> M: Jiri Kosina <jikos@kernel.org>
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index a3017a5dadcd..7991b78eb1f3 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -1961,6 +1961,24 @@ config SYSCTL_KUNIT_TEST
>
> If unsure, say N.
>
> +config LIST_KUNIT_TEST
> + bool "KUnit Test for Kernel Linked-list structures"
> + depends on KUNIT
> + help
> + This builds the linked list KUnit test suite.
> + It tests that the API and basic functionality of the list_head type
> + and associated macros.
> +
nit: unnecessary tab.
> + KUnit tests run during boot and output the results to the debug log
> + in TAP format (http://testanything.org/). Only useful for kernel devs
> + running the KUnit test harness, and not intended for inclusion into a
> + production build.
> +
> + For more information on KUnit and unit tests in general please refer
> + to the KUnit documentation in Documentation/dev-tools/kunit/.
> +
> + If unsure, say N.
> +
> config TEST_UDELAY
> tristate "udelay test driver"
> help
[...]
> diff --git a/lib/list-test.c b/lib/list-test.c
> new file mode 100644
> index 000000000000..a6d17647e309
> --- /dev/null
> +++ b/lib/list-test.c
[...]
> +static void list_test_list_entry(struct kunit *test)
> +{
> + struct list_test_struct test_struct;
> +
> + KUNIT_EXPECT_PTR_EQ(test, &test_struct, list_entry(&(test_struct.list), struct list_test_struct, list));
nit: here and elsewhere: over 80 chars.
> +}
> +
> +static void list_test_list_first_entry(struct kunit *test)
> +{
> + struct list_test_struct test_struct1, test_struct2;
> + LIST_HEAD(list);
> +
> + list_add_tail(&test_struct1.list, &list);
> + list_add_tail(&test_struct2.list, &list);
> +
> +
> + KUNIT_EXPECT_PTR_EQ(test, &test_struct1, list_first_entry(&list, struct list_test_struct, list));
> +}
[...]
> +static void list_test_list_for_each_entry(struct kunit *test)
> +{
> + struct list_test_struct entries[5], *cur;
> + static LIST_HEAD(list);
> + int i = 0;
> +
> + for (i = 0; i < 5; ++i) {
> + entries[i].data = i;
> + list_add_tail(&entries[i].list, &list);
> + }
> +
> + i = 0;
> +
> + list_for_each_entry(cur, &list, list) {
> + KUNIT_EXPECT_EQ(test, cur->data, i);
> + i++;
> + }
> +
nit: another unnecessary tab. Looks like you should probably run checkpatch.
> + KUNIT_EXPECT_EQ(test, i, 5);
> +}
> +
> +static void list_test_list_for_each_entry_reverse(struct kunit *test)
> +{
> + struct list_test_struct entries[5], *cur;
> + static LIST_HEAD(list);
> + int i = 0;
> +
> + for (i = 0; i < 5; ++i) {
> + entries[i].data = i;
> + list_add_tail(&entries[i].list, &list);
> + }
> +
> + i = 4;
> +
> + list_for_each_entry_reverse(cur, &list, list) {
> + KUNIT_EXPECT_EQ(test, cur->data, i);
> + i--;
> + }
> +
> + KUNIT_EXPECT_EQ(test, i, -1);
> +}
[...]
Cheers
prev parent reply other threads:[~2019-10-23 22:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-22 22:13 [PATCH linux-kselftest/test v5] lib/list-test: add a test for the 'list' doubly linked list David Gow
2019-10-23 22:02 ` Brendan Higgins [this message]
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=20191023220248.GA55483@google.com \
--to=brendanhiggins@google.com \
--cc=akpm@linux-foundation.org \
--cc=dan.carpenter@oracle.com \
--cc=davidgow@google.com \
--cc=keescook@chromium.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.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).