diff mbox series

[v2,1/3] list: test: Add test for list_del_init_careful()

Message ID 20220208040122.695258-1-davidgow@google.com (mailing list archive)
State New
Headers show
Series [v2,1/3] list: test: Add test for list_del_init_careful() | expand

Commit Message

David Gow Feb. 8, 2022, 4:01 a.m. UTC
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>
---

Changes since v1:
https://lore.kernel.org/linux-kselftest/20220205061539.273330-1-davidgow@google.com/
- Patch 1/3 unchanged

---
 lib/list-test.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Daniel Latypov Feb. 8, 2022, 8:32 p.m. UTC | #1
On Mon, Feb 7, 2022 at 8:01 PM David Gow <davidgow@google.com> wrote:
>
> 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>
> ---
>
> Changes since v1:
> https://lore.kernel.org/linux-kselftest/20220205061539.273330-1-davidgow@google.com/
> - Patch 1/3 unchanged
>
> ---
>  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 */

nit: I personally didn't read this comment in the intended way at first.
I'd personally find something like

NOTE: this doesn't test for concurrency/memory
ordering/however-you-want-to-word-it issues

a bit more readable.

> +       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);

Is this supposed to use list_del_init_careful(&a)?
That would make it match the name of the test case.

> +       /* 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),
> --
> 2.35.0.263.gb82422642f-goog
>
diff mbox series

Patch

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),