LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2 1/3] list: test: Add test for list_del_init_careful()
@ 2022-02-08  4:01 David Gow
  2022-02-08  4:01 ` [PATCH v2 2/3] list: test: Add a test for list_is_head() David Gow
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: David Gow @ 2022-02-08  4:01 UTC (permalink / raw)
  To: Shuah Khan, Andy Shevchenko, Linus Torvalds, Brendan Higgins
  Cc: David Gow, Daniel Latypov, linux-kernel, linux-kselftest, kunit-dev

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 2/3] list: test: Add a test for list_is_head()
  2022-02-08  4:01 [PATCH v2 1/3] list: test: Add test for list_del_init_careful() David Gow
@ 2022-02-08  4:01 ` David Gow
  2022-02-08 20:40   ` Daniel Latypov
  2022-02-08 21:46   ` Brendan Higgins
  2022-02-08  4:01 ` [PATCH v2 3/3] list: test: Add a test for list_entry_is_head() David Gow
  2022-02-08 20:32 ` [PATCH v2 1/3] list: test: Add test for list_del_init_careful() Daniel Latypov
  2 siblings, 2 replies; 8+ messages in thread
From: David Gow @ 2022-02-08  4:01 UTC (permalink / raw)
  To: Shuah Khan, Andy Shevchenko, Linus Torvalds, Brendan Higgins
  Cc: David Gow, Daniel Latypov, linux-kernel, linux-kselftest, kunit-dev

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

Changes since v1:
https://lore.kernel.org/linux-kselftest/20220205061539.273330-2-davidgow@google.com/
- Test both non-head elements of the same list and head elements of
  different lists.

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

diff --git a/lib/list-test.c b/lib/list-test.c
index 976e9ae1f3c5..1960615d1a9f 100644
--- a/lib/list-test.c
+++ b/lib/list-test.c
@@ -252,6 +252,23 @@ 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, c;
+
+	/* Two lists: [a] -> b, [c] */
+	INIT_LIST_HEAD(&a);
+	INIT_LIST_HEAD(&c);
+	list_add_tail(&b, &a);
+
+	KUNIT_EXPECT_TRUE(test, list_is_head(&a, &a));
+	/* Non-head element of same list */
+	KUNIT_EXPECT_FALSE(test, list_is_head(&a, &b));
+	/* Head element of different list */
+	KUNIT_EXPECT_FALSE(test, list_is_head(&a, &c));
+}
+
+
 static void list_test_list_is_first(struct kunit *test)
 {
 	struct list_head a, b;
@@ -729,6 +746,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),
-- 
2.35.0.263.gb82422642f-goog


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 3/3] list: test: Add a test for list_entry_is_head()
  2022-02-08  4:01 [PATCH v2 1/3] list: test: Add test for list_del_init_careful() David Gow
  2022-02-08  4:01 ` [PATCH v2 2/3] list: test: Add a test for list_is_head() David Gow
@ 2022-02-08  4:01 ` David Gow
  2022-02-08 20:44   ` Daniel Latypov
  2022-02-08 21:52   ` Brendan Higgins
  2022-02-08 20:32 ` [PATCH v2 1/3] list: test: Add test for list_del_init_careful() Daniel Latypov
  2 siblings, 2 replies; 8+ messages in thread
From: David Gow @ 2022-02-08  4:01 UTC (permalink / raw)
  To: Shuah Khan, Andy Shevchenko, Linus Torvalds, Brendan Higgins
  Cc: David Gow, Daniel Latypov, linux-kernel, linux-kselftest, kunit-dev

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/?id=e130816164e244b692921de49771eeb28205152d

Signed-off-by: David Gow <davidgow@google.com>
---

Changes since v1:
https://lore.kernel.org/linux-kselftest/20220205061539.273330-3-davidgow@google.com/
- Rework the test entirely to better match the improved list_is_head()
  test.

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

diff --git a/lib/list-test.c b/lib/list-test.c
index 1960615d1a9f..80dd14c4ca1f 100644
--- a/lib/list-test.c
+++ b/lib/list-test.c
@@ -546,6 +546,22 @@ 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, test_struct3;
+
+	INIT_LIST_HEAD(&test_struct1.list);
+	INIT_LIST_HEAD(&test_struct3.list);
+
+	list_add_tail(&test_struct2.list, &test_struct1.list);
+
+	KUNIT_EXPECT_TRUE(test, list_entry_is_head((&test_struct1), &test_struct1.list, list));
+	/* Non-head element of same list */
+	KUNIT_EXPECT_FALSE(test, list_entry_is_head((&test_struct2), &test_struct1.list, list));
+	/* Head element of different list */
+	KUNIT_EXPECT_FALSE(test, list_entry_is_head((&test_struct3), &test_struct1.list, list));
+}
+
 static void list_test_list_first_entry(struct kunit *test)
 {
 	struct list_test_struct test_struct1, test_struct2;
@@ -761,6 +777,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),
-- 
2.35.0.263.gb82422642f-goog


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/3] list: test: Add test for list_del_init_careful()
  2022-02-08  4:01 [PATCH v2 1/3] list: test: Add test for list_del_init_careful() David Gow
  2022-02-08  4:01 ` [PATCH v2 2/3] list: test: Add a test for list_is_head() David Gow
  2022-02-08  4:01 ` [PATCH v2 3/3] list: test: Add a test for list_entry_is_head() David Gow
@ 2022-02-08 20:32 ` Daniel Latypov
  2 siblings, 0 replies; 8+ messages in thread
From: Daniel Latypov @ 2022-02-08 20:32 UTC (permalink / raw)
  To: David Gow
  Cc: Shuah Khan, Andy Shevchenko, Linus Torvalds, Brendan Higgins,
	linux-kernel, linux-kselftest, kunit-dev

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
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/3] list: test: Add a test for list_is_head()
  2022-02-08  4:01 ` [PATCH v2 2/3] list: test: Add a test for list_is_head() David Gow
@ 2022-02-08 20:40   ` Daniel Latypov
  2022-02-08 21:46   ` Brendan Higgins
  1 sibling, 0 replies; 8+ messages in thread
From: Daniel Latypov @ 2022-02-08 20:40 UTC (permalink / raw)
  To: David Gow
  Cc: Shuah Khan, Andy Shevchenko, Linus Torvalds, Brendan Higgins,
	linux-kernel, linux-kselftest, kunit-dev

On Mon, Feb 7, 2022 at 8:02 PM David Gow <davidgow@google.com> 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
>
> Signed-off-by: David Gow <davidgow@google.com>

Acked-by: Daniel Latypov <dlatypov@google.com>

One very optional suggestion below.

> ---
>
> Changes since v1:
> https://lore.kernel.org/linux-kselftest/20220205061539.273330-2-davidgow@google.com/
> - Test both non-head elements of the same list and head elements of
>   different lists.
>
> ---
>  lib/list-test.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/lib/list-test.c b/lib/list-test.c
> index 976e9ae1f3c5..1960615d1a9f 100644
> --- a/lib/list-test.c
> +++ b/lib/list-test.c
> @@ -252,6 +252,23 @@ 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, c;
> +
> +       /* Two lists: [a] -> b, [c] */
> +       INIT_LIST_HEAD(&a);
> +       INIT_LIST_HEAD(&c);
> +       list_add_tail(&b, &a);
> +
> +       KUNIT_EXPECT_TRUE(test, list_is_head(&a, &a));
> +       /* Non-head element of same list */
> +       KUNIT_EXPECT_FALSE(test, list_is_head(&a, &b));
> +       /* Head element of different list */
> +       KUNIT_EXPECT_FALSE(test, list_is_head(&a, &c));

very optional,
  KUNIT_EXPECT_FALSE_MSG(test, list_is_head(&a, &c), "Head of a
different list");
It goes over 80 char, so probably needs to be line-wrapped, and thus
doesn't reduce # of lines.

Given the simplicity of this function (checks that its args are
equal), I highly doubt it should ever fail, and so better error
messages aren't really much of a bonus.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 3/3] list: test: Add a test for list_entry_is_head()
  2022-02-08  4:01 ` [PATCH v2 3/3] list: test: Add a test for list_entry_is_head() David Gow
@ 2022-02-08 20:44   ` Daniel Latypov
  2022-02-08 21:52   ` Brendan Higgins
  1 sibling, 0 replies; 8+ messages in thread
From: Daniel Latypov @ 2022-02-08 20:44 UTC (permalink / raw)
  To: David Gow
  Cc: Shuah Khan, Andy Shevchenko, Linus Torvalds, Brendan Higgins,
	linux-kernel, linux-kselftest, kunit-dev

On Mon, Feb 7, 2022 at 8:02 PM David Gow <davidgow@google.com> wrote:
>
> 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/?id=e130816164e244b692921de49771eeb28205152d
>
> Signed-off-by: David Gow <davidgow@google.com>

Acked-by: Daniel Latypov <dlatypov@google.com>

Similar to the previous patch, we can maybe consider using the _MSG
variants here

> ---
>
> Changes since v1:
> https://lore.kernel.org/linux-kselftest/20220205061539.273330-3-davidgow@google.com/
> - Rework the test entirely to better match the improved list_is_head()
>   test.
>
> ---
>  lib/list-test.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
>
> diff --git a/lib/list-test.c b/lib/list-test.c
> index 1960615d1a9f..80dd14c4ca1f 100644
> --- a/lib/list-test.c
> +++ b/lib/list-test.c
> @@ -546,6 +546,22 @@ 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, test_struct3;
> +
> +       INIT_LIST_HEAD(&test_struct1.list);
> +       INIT_LIST_HEAD(&test_struct3.list);
> +
> +       list_add_tail(&test_struct2.list, &test_struct1.list);
> +
> +       KUNIT_EXPECT_TRUE(test, list_entry_is_head((&test_struct1), &test_struct1.list, list));
> +       /* Non-head element of same list */
> +       KUNIT_EXPECT_FALSE(test, list_entry_is_head((&test_struct2), &test_struct1.list, list));
> +       /* Head element of different list */
> +       KUNIT_EXPECT_FALSE(test, list_entry_is_head((&test_struct3), &test_struct1.list, list));

Unlike the list_is_head()
* this macro is marginally more complicated (barely).
* these lines already go over 80 chars.
* macros in EXPECT's get printed out in expanded form (less legible on
their own than a func call is)

So perhaps

KUNIT_EXPECT_FALSE_MSG(test, ..., "Head element of different list")

?

> +}
> +
>  static void list_test_list_first_entry(struct kunit *test)
>  {
>         struct list_test_struct test_struct1, test_struct2;
> @@ -761,6 +777,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),
> --
> 2.35.0.263.gb82422642f-goog
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/3] list: test: Add a test for list_is_head()
  2022-02-08  4:01 ` [PATCH v2 2/3] list: test: Add a test for list_is_head() David Gow
  2022-02-08 20:40   ` Daniel Latypov
@ 2022-02-08 21:46   ` Brendan Higgins
  1 sibling, 0 replies; 8+ messages in thread
From: Brendan Higgins @ 2022-02-08 21:46 UTC (permalink / raw)
  To: David Gow
  Cc: Shuah Khan, Andy Shevchenko, Linus Torvalds, Daniel Latypov,
	linux-kernel, linux-kselftest, kunit-dev

On Mon, Feb 7, 2022 at 11:02 PM David Gow <davidgow@google.com> 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
>
> Signed-off-by: David Gow <davidgow@google.com>

Acked-by: Brendan Higgins <brendanhiggins@google.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 3/3] list: test: Add a test for list_entry_is_head()
  2022-02-08  4:01 ` [PATCH v2 3/3] list: test: Add a test for list_entry_is_head() David Gow
  2022-02-08 20:44   ` Daniel Latypov
@ 2022-02-08 21:52   ` Brendan Higgins
  1 sibling, 0 replies; 8+ messages in thread
From: Brendan Higgins @ 2022-02-08 21:52 UTC (permalink / raw)
  To: David Gow
  Cc: Shuah Khan, Andy Shevchenko, Linus Torvalds, Daniel Latypov,
	linux-kernel, linux-kselftest, kunit-dev

On Mon, Feb 7, 2022 at 11:02 PM David Gow <davidgow@google.com> wrote:
>
> 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/?id=e130816164e244b692921de49771eeb28205152d
>
> Signed-off-by: David Gow <davidgow@google.com>

Acked-by: Brendan Higgins <brendanhiggins@google.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-02-08 22:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-08  4:01 [PATCH v2 1/3] list: test: Add test for list_del_init_careful() David Gow
2022-02-08  4:01 ` [PATCH v2 2/3] list: test: Add a test for list_is_head() David Gow
2022-02-08 20:40   ` Daniel Latypov
2022-02-08 21:46   ` Brendan Higgins
2022-02-08  4:01 ` [PATCH v2 3/3] list: test: Add a test for list_entry_is_head() David Gow
2022-02-08 20:44   ` Daniel Latypov
2022-02-08 21:52   ` Brendan Higgins
2022-02-08 20:32 ` [PATCH v2 1/3] list: test: Add test for list_del_init_careful() Daniel Latypov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).