[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGS_qxpYuXPavOVOvp07UUhBcrPYH7P5EZKrVOP5WN2s8t3mSA@mail.gmail.com>
Date: Tue, 8 Feb 2022 12:44:56 -0800
From: Daniel Latypov <dlatypov@...gle.com>
To: David Gow <davidgow@...gle.com>
Cc: Shuah Khan <skhan@...uxfoundation.org>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Brendan Higgins <brendanhiggins@...gle.com>,
linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
kunit-dev@...glegroups.com
Subject: Re: [PATCH v2 3/3] list: test: Add a test for list_entry_is_head()
On Mon, Feb 7, 2022 at 8:02 PM David Gow <davidgow@...gle.com> wrote:
>
> The list_entry_is_head() macro was added[1] after the list KUnit tests,
> so wasn't tested. Add a new KUnit test to complete the set.
>
> [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e130816164e244b692921de49771eeb28205152d
>
> Signed-off-by: David Gow <davidgow@...gle.com>
Acked-by: Daniel Latypov <dlatypov@...gle.com>
Similar to the previous patch, we can maybe consider using the _MSG
variants here
> ---
>
> Changes since v1:
> https://lore.kernel.org/linux-kselftest/20220205061539.273330-3-davidgow@google.com/
> - Rework the test entirely to better match the improved list_is_head()
> test.
>
> ---
> lib/list-test.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/lib/list-test.c b/lib/list-test.c
> index 1960615d1a9f..80dd14c4ca1f 100644
> --- a/lib/list-test.c
> +++ b/lib/list-test.c
> @@ -546,6 +546,22 @@ static void list_test_list_entry(struct kunit *test)
> struct list_test_struct, list));
> }
>
> +static void list_test_list_entry_is_head(struct kunit *test)
> +{
> + struct list_test_struct test_struct1, test_struct2, test_struct3;
> +
> + INIT_LIST_HEAD(&test_struct1.list);
> + INIT_LIST_HEAD(&test_struct3.list);
> +
> + list_add_tail(&test_struct2.list, &test_struct1.list);
> +
> + KUNIT_EXPECT_TRUE(test, list_entry_is_head((&test_struct1), &test_struct1.list, list));
> + /* Non-head element of same list */
> + KUNIT_EXPECT_FALSE(test, list_entry_is_head((&test_struct2), &test_struct1.list, list));
> + /* Head element of different list */
> + KUNIT_EXPECT_FALSE(test, list_entry_is_head((&test_struct3), &test_struct1.list, list));
Unlike the list_is_head()
* this macro is marginally more complicated (barely).
* these lines already go over 80 chars.
* macros in EXPECT's get printed out in expanded form (less legible on
their own than a func call is)
So perhaps
KUNIT_EXPECT_FALSE_MSG(test, ..., "Head element of different list")
?
> +}
> +
> static void list_test_list_first_entry(struct kunit *test)
> {
> struct list_test_struct test_struct1, test_struct2;
> @@ -761,6 +777,7 @@ static struct kunit_case list_test_cases[] = {
> KUNIT_CASE(list_test_list_splice_init),
> KUNIT_CASE(list_test_list_splice_tail_init),
> KUNIT_CASE(list_test_list_entry),
> + KUNIT_CASE(list_test_list_entry_is_head),
> KUNIT_CASE(list_test_list_first_entry),
> KUNIT_CASE(list_test_list_last_entry),
> KUNIT_CASE(list_test_list_first_entry_or_null),
> --
> 2.35.0.263.gb82422642f-goog
>
Powered by blists - more mailing lists