diff options
author | David Gow <davidgow@google.com> | 2022-02-25 10:52:46 +0800 |
---|---|---|
committer | Shuah Khan <skhan@linuxfoundation.org> | 2022-02-25 08:38:48 -0700 |
commit | d7fd696c12605b1666e9a2051e2ac896af103bfe (patch) | |
tree | d762e4387afcca174528a3752be59c9dbf087a1e /lib/list-test.c | |
parent | c2741453478badf571ef020d160053e8d5e1ba94 (diff) | |
download | lwn-d7fd696c12605b1666e9a2051e2ac896af103bfe.tar.gz lwn-d7fd696c12605b1666e9a2051e2ac896af103bfe.zip |
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().
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c6fe44d96fc1536af5b11cd859686453d1b7bfd1
Signed-off-by: David Gow <davidgow@google.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'lib/list-test.c')
-rw-r--r-- | lib/list-test.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/list-test.c b/lib/list-test.c index ee09505df16f..302b7382bff4 100644 --- a/lib/list-test.c +++ b/lib/list-test.c @@ -161,6 +161,26 @@ 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) +{ + /* NOTE: This test only checks the behaviour of this function in + * isolation. It does not verify memory model guarantees. + */ + 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_careful(&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 +727,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), |