Message ID | 20220205061539.273330-2-davidgow@google.com |
---|---|
State | New |
Headers | show |
Series | [1/3] list: test: Add test for list_del_init_careful() | expand |
On Sat, Feb 05, 2022 at 02:15:37PM +0800, David Gow wrote: > list_is_head() was added recently[1], and didn't have a KUnit test. The > implementation is trivial, so it's not a particularly exciting test, but > it'd be nice to get back to full coverage of the list functions. > > [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/list.h?id=0425473037db40d9e322631f2d4dc6ef51f97e88 ... > +static void list_test_list_is_head(struct kunit *test) > +{ > + struct list_head a, b; > + > + KUNIT_EXPECT_TRUE(test, list_is_head(&a, &a)); OK. > + KUNIT_EXPECT_FALSE(test, list_is_head(&a, &b)); Perhaps OK, but the main case here is to test an (arbitrary) member of the existing list. > +}
On Sat, Feb 5, 2022 at 9:09 PM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > On Sat, Feb 05, 2022 at 02:15:37PM +0800, David Gow wrote: > > list_is_head() was added recently[1], and didn't have a KUnit test. The > > implementation is trivial, so it's not a particularly exciting test, but > > it'd be nice to get back to full coverage of the list functions. > > > > [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/list.h?id=0425473037db40d9e322631f2d4dc6ef51f97e88 > > ... > > > +static void list_test_list_is_head(struct kunit *test) > > +{ > > + struct list_head a, b; > > + > > + KUNIT_EXPECT_TRUE(test, list_is_head(&a, &a)); > > OK. > > > + KUNIT_EXPECT_FALSE(test, list_is_head(&a, &b)); > > Perhaps OK, but the main case here is to test an (arbitrary) member of the existing list. > That makes sense. I've updated the test to verify both the case where the elements are from the same list and where it's from a different list: https://lore.kernel.org/linux-kselftest/20220208040122.695258-2-davidgow@google.com/T/#u (I've also updated patch 3 for list_entry_is_head() similarly, which was even worse before.) > > +} > Cheers, -- David
diff --git a/lib/list-test.c b/lib/list-test.c index 976e9ae1f3c5..7ce7eaebe060 100644 --- a/lib/list-test.c +++ b/lib/list-test.c @@ -252,6 +252,15 @@ static void list_test_list_bulk_move_tail(struct kunit *test) KUNIT_EXPECT_EQ(test, i, 2); } +static void list_test_list_is_head(struct kunit *test) +{ + struct list_head a, b; + + KUNIT_EXPECT_TRUE(test, list_is_head(&a, &a)); + KUNIT_EXPECT_FALSE(test, list_is_head(&a, &b)); +} + + static void list_test_list_is_first(struct kunit *test) { struct list_head a, b; @@ -729,6 +738,7 @@ static struct kunit_case list_test_cases[] = { KUNIT_CASE(list_test_list_move), KUNIT_CASE(list_test_list_move_tail), KUNIT_CASE(list_test_list_bulk_move_tail), + KUNIT_CASE(list_test_list_is_head), KUNIT_CASE(list_test_list_is_first), KUNIT_CASE(list_test_list_is_last), KUNIT_CASE(list_test_list_empty),
list_is_head() was added recently[1], and didn't have a KUnit test. The implementation is trivial, so it's not a particularly exciting test, but it'd be nice to get back to full coverage of the list functions. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/list.h?id=0425473037db40d9e322631f2d4dc6ef51f97e88 Signed-off-by: David Gow <davidgow@google.com> --- lib/list-test.c | 10 ++++++++++ 1 file changed, 10 insertions(+)