* [PATCH 1/3] list: test: Add test for list_del_init_careful()
@ 2022-02-05 6:15 David Gow
2022-02-05 6:15 ` [PATCH 2/3] list: test: Add a test for list_is_head() David Gow
2022-02-05 6:15 ` [PATCH 3/3] list: test: Add a test for list_entry_is_head() David Gow
0 siblings, 2 replies; 5+ messages in thread
From: David Gow @ 2022-02-05 6:15 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>
---
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 related [flat|nested] 5+ messages in thread
* [PATCH 2/3] list: test: Add a test for list_is_head()
2022-02-05 6:15 [PATCH 1/3] list: test: Add test for list_del_init_careful() David Gow
@ 2022-02-05 6:15 ` David Gow
2022-02-05 13:06 ` Andy Shevchenko
2022-02-05 6:15 ` [PATCH 3/3] list: test: Add a test for list_entry_is_head() David Gow
1 sibling, 1 reply; 5+ messages in thread
From: David Gow @ 2022-02-05 6:15 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>
---
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),
--
2.35.0.263.gb82422642f-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] list: test: Add a test for list_entry_is_head()
2022-02-05 6:15 [PATCH 1/3] list: test: Add test for list_del_init_careful() David Gow
2022-02-05 6:15 ` [PATCH 2/3] list: test: Add a test for list_is_head() David Gow
@ 2022-02-05 6:15 ` David Gow
1 sibling, 0 replies; 5+ messages in thread
From: David Gow @ 2022-02-05 6:15 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>
---
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),
--
2.35.0.263.gb82422642f-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/3] list: test: Add a test for list_is_head()
2022-02-05 6:15 ` [PATCH 2/3] list: test: Add a test for list_is_head() David Gow
@ 2022-02-05 13:06 ` Andy Shevchenko
2022-02-08 4:08 ` David Gow
0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2022-02-05 13:06 UTC (permalink / raw)
To: David Gow
Cc: Shuah Khan, Linus Torvalds, Brendan Higgins, Daniel Latypov,
linux-kernel, linux-kselftest, kunit-dev
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.
>
> [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/list.h?id=0425473037db40d9e322631f2d4dc6ef51f97e88
...
> +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.
> +}
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/3] list: test: Add a test for list_is_head()
2022-02-05 13:06 ` Andy Shevchenko
@ 2022-02-08 4:08 ` David Gow
0 siblings, 0 replies; 5+ messages in thread
From: David Gow @ 2022-02-08 4:08 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Shuah Khan, Linus Torvalds, Brendan Higgins, Daniel Latypov,
Linux Kernel Mailing List, open list:KERNEL SELFTEST FRAMEWORK,
KUnit Development
[-- Attachment #1: Type: text/plain, Size: 1220 bytes --]
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.
> >
> > [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/list.h?id=0425473037db40d9e322631f2d4dc6ef51f97e88
>
> ...
>
> > +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@google.com/T/#u
(I've also updated patch 3 for list_entry_is_head() similarly, which
was even worse before.)
> > +}
>
Cheers,
-- David
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4003 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-02-08 4:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-05 6:15 [PATCH 1/3] list: test: Add test for list_del_init_careful() David Gow
2022-02-05 6:15 ` [PATCH 2/3] list: test: Add a test for list_is_head() David Gow
2022-02-05 13:06 ` Andy Shevchenko
2022-02-08 4:08 ` David Gow
2022-02-05 6:15 ` [PATCH 3/3] list: test: Add a test for list_entry_is_head() David Gow
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.