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().
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
Signed-off-by: David Gow davidgow@google.com --- lib/list-test.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
diff --git a/lib/list-test.c b/lib/list-test.c index ee09505df16f..976e9ae1f3c5 100644 --- a/lib/list-test.c +++ b/lib/list-test.c @@ -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),
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/in...
Signed-off-by: David Gow davidgow@google.com --- lib/list-test.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
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),
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.
...
+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.
...
+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@goo...
(I've also updated patch 3 for list_entry_is_head() similarly, which was even worse before.)
+}
Cheers, -- David
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/?i...
Signed-off-by: David Gow davidgow@google.com --- lib/list-test.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
diff --git a/lib/list-test.c b/lib/list-test.c index 7ce7eaebe060..4cd06a9fc73c 100644 --- a/lib/list-test.c +++ b/lib/list-test.c @@ -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),
linux-kselftest-mirror@lists.linaro.org