list: test: Add test for list_del_init_careful()
Subsystems (2)
PATCH 1/3 list: test: Add test for list_del_init_careful()
The list_del_init_careful() function was added[1] after the list KUnit test. Add a very basic test to cover it.
Note that this test only covers the single-threaded behaviour (which matches list_del_init()), as is already the case with the test for list_empty_careful().
--- lib/list-test.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
lib/list-test.c +19 -0
@@ -161,6 +161,24 @@ static void list_test_list_del_init(struct kunit *test)KUNIT_EXPECT_TRUE (test,list_empty_careful (&a)); } +static void list_test_list_del_init_careful (struct kunit *test) +{ +/* This test doesn't check correctness under concurrent access */ +struct list_head a, b; +LIST_HEAD (list); + +list_add_tail (&a, &list); +list_add_tail (&b, &list); + +/* before: [list] -> a -> b */ +list_del_init (&a); +/* after: [list] -> b, a initialised */ + +KUNIT_EXPECT_PTR_EQ (test, list.next, &b); +KUNIT_EXPECT_PTR_EQ (test, b.prev, &list); +KUNIT_EXPECT_TRUE (test,list_empty_careful (&a)); +} +static void list_test_list_move (struct kunit *test) {struct list_head a, b;
@@ -707,6 +725,7 @@ static struct kunit_case list_test_cases[] = {KUNIT_CASE (list_test_list_replace_init),KUNIT_CASE (list_test_list_swap),KUNIT_CASE (list_test_list_del_init), +KUNIT_CASE (list_test_list_del_init_careful),KUNIT_CASE (list_test_list_move),KUNIT_CASE (list_test_list_move_tail), KUNIT_CASE(list_test_list_bulk_move_tail),
Signature · 1 line
2.35.0.263.gb82422642f-goog
PATCH 2/3 list: test: Add a test for list_is_head()
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.
--- lib/list-test.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
lib/list-test.c +10 -0
@@ -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),
Signature · 1 line
2.35.0.263.gb82422642f-goog
Re: [PATCH 2/3] list: test: Add a test for list_is_head()
Quoted 5 lines · David Gow
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.
...
lib/list-test.c static void list_test_list_bulk_move_tail(struct kunit *test) · line 259
Quoted 5 lines
lib/list-test.c +5
-0+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.
lib/list-test.c static void list_test_list_bulk_move_tail(struct kunit *test) · line 260
Quoted 1 line
lib/list-test.c +1
-0+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.
Quoted 1 line
+}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/3] list: test: Add a test for list_is_head()
Quoted 18 lines · Andy Shevchenko
Quoted 5 lines · David Gow
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....
lib/list-test.c static void list_test_list_bulk_move_tail(struct kunit *test) · line 259
Quoted 5 lines
lib/list-test.c +5
-0+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.
Quoted 4 lines
Quoted 1 line
+
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/[email protected]/T/#u
(I've also updated patch 3 for list_entry_is_head() similarly, which was even worse before.)
Quoted 2 lines
Quoted 1 line
+}
Cheers,
-- David
PATCH 3/3 list: test: Add a test for list_entry_is_head()
In reply to David GowThe 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.
--- lib/list-test.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
lib/list-test.c +13 -0
@@ -538,6 +538,18 @@ 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; +LIST_HEAD (list); + +list_add_tail (&test_struct1.list, &list); +list_add_tail (&test_struct2.list, &list); + +KUNIT_EXPECT_FALSE (test,list_entry_is_head ((&test_struct1), &list, list)); +KUNIT_EXPECT_FALSE (test,list_entry_is_head ((&test_struct2), &list, list)); +} +static void list_test_list_first_entry (struct kunit *test) {struct list_test_struct test_struct1, test_struct2;
@@ -753,6 +765,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),
Signature · 1 line
2.35.0.263.gb82422642f-goog