linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Gow <davidgow@google.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 Jakob Koschel <jakobkoschel@gmail.com>,
	Jann Horn <jannh@google.com>,  Kees Cook <keescook@chromium.org>,
	 Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
	 Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux-MM <linux-mm@kvack.org>,  Netdev <netdev@vger.kernel.org>,
	kunit-dev@googlegroups.com,  David Gow <davidgow@google.com>
Subject: [RFC PATCH] list: test: Add a test for list_traverse
Date: Fri, 11 Mar 2022 15:15:29 +0800	[thread overview]
Message-ID: <20220311071529.1836818-1-davidgow@google.com> (raw)
In-Reply-To: <CAHk-=wiacQM76xec=Hr7cLchVZ8Mo9VDHmXRJzJ_EX4sOsApEA@mail.gmail.com>

Update the list KUnit test to include a test for the new list_traverse()
macro. This adds a new 'head' member to the list_test_struct to use as a
list head, using the list_traverse_head macro.

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

If, as seems likely, we're going to introduce new list traversal macros,
it'd be nice to update the linked list KUnit tests in lib/list-test.c to
test them. :-)

This patch works against the proposed list_traverse() macro posted here:
https://lore.kernel.org/all/CAHk-=wiacQM76xec=Hr7cLchVZ8Mo9VDHmXRJzJ_EX4sOsApEA@mail.gmail.com/

Feel free to use and/or adapt it if this or a similar macro is
introduced.

Cheers,
-- David

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

diff --git a/lib/list-test.c b/lib/list-test.c
index ee09505df16f..7fa2622ff9c7 100644
--- a/lib/list-test.c
+++ b/lib/list-test.c
@@ -12,6 +12,7 @@
 struct list_test_struct {
 	int data;
 	struct list_head list;
+	list_traversal_head(struct list_test_struct, head, list);
 };
 
 static void list_test_list_init(struct kunit *test)
@@ -656,6 +657,28 @@ static void list_test_list_for_each_prev_safe(struct kunit *test)
 	KUNIT_EXPECT_TRUE(test, list_empty(&list));
 }
 
+static void list_test_list_traverse(struct kunit *test)
+{
+	struct list_test_struct entries[5], head;
+	int i = 0;
+
+	INIT_LIST_HEAD(&head.head);
+
+	for (i = 0; i < 5; ++i) {
+		entries[i].data = i;
+		list_add_tail(&entries[i].list, &head.head);
+	}
+
+	i = 0;
+
+	list_traverse(cur, &head.head, list) {
+		KUNIT_EXPECT_EQ(test, cur->data, i);
+		i++;
+	}
+
+	KUNIT_EXPECT_EQ(test, i, 5);
+}
+
 static void list_test_list_for_each_entry(struct kunit *test)
 {
 	struct list_test_struct entries[5], *cur;
@@ -733,6 +756,7 @@ static struct kunit_case list_test_cases[] = {
 	KUNIT_CASE(list_test_list_for_each_prev),
 	KUNIT_CASE(list_test_list_for_each_safe),
 	KUNIT_CASE(list_test_list_for_each_prev_safe),
+	KUNIT_CASE(list_test_list_traverse),
 	KUNIT_CASE(list_test_list_for_each_entry),
 	KUNIT_CASE(list_test_list_for_each_entry_reverse),
 	{},
-- 
2.35.1.723.g4982287a31-goog



  parent reply	other threads:[~2022-03-11  7:15 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-01  7:58 [PATCH 0/6] list_for_each_entry*: make iterator invisiable outside the loop Xiaomeng Tong
2022-03-01  7:58 ` [PATCH 1/6] Kbuild: compile kernel with gnu11 std Xiaomeng Tong
2022-03-01 17:59   ` kernel test robot
2022-03-01 20:16     ` Linus Torvalds
2022-03-01 20:54       ` Arnd Bergmann
2022-03-01 21:04         ` Linus Torvalds
2022-03-01 21:15           ` Linus Torvalds
2022-03-01 21:43             ` Xiaomeng Tong
2022-03-01  7:58 ` [PATCH 2/6] list: add new MACROs to make iterator invisiable outside the loop Xiaomeng Tong
2022-03-02  2:52   ` kernel test robot
2022-03-02 13:02   ` James Bottomley
2022-03-03  3:31     ` Xiaomeng Tong
2022-03-06 14:33       ` James Bottomley
2022-03-03 20:02   ` Linus Torvalds
2022-03-04  2:51     ` Xiaomeng Tong
2022-03-05 21:09       ` Linus Torvalds
2022-03-06  0:35         ` Linus Torvalds
2022-03-06 12:19           ` Jakob Koschel
2022-03-06 18:57             ` Linus Torvalds
2022-03-06 14:06           ` Xiaomeng Tong
2022-03-10 23:54           ` [PATCH 2/6] list: add new MACROs to make iterator invisiable Michał Mirosław
2022-03-11  0:46             ` Linus Torvalds
2022-03-12 10:24               ` Michał Mirosław
2022-03-12 21:43                 ` Linus Torvalds
2022-03-11  7:15           ` David Gow [this message]
2022-03-11 14:27           ` [PATCH 2/6] list: add new MACROs to make iterator invisiable outside the loop Daniel Thompson
2022-03-11 18:41             ` Linus Torvalds
2022-03-16 15:45               ` Daniel Thompson
2022-03-01  7:58 ` [PATCH 3/6] kernel: remove iterator use " Xiaomeng Tong
2022-03-01 10:41   ` Greg KH
2022-03-01 11:34     ` Xiaomeng Tong
2022-03-01 11:48       ` Xiaomeng Tong
2022-03-01  7:58 ` [PATCH 4/6] mm: " Xiaomeng Tong
2022-03-01 12:19   ` Xiaomeng Tong
2022-03-01  7:58 ` [PATCH 5/6] net/core: " Xiaomeng Tong
2022-03-01 12:23   ` Xiaomeng Tong
2022-03-01  7:58 ` [PATCH 6/6] drivers/dma: " Xiaomeng Tong
2022-03-01 12:25   ` Xiaomeng Tong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220311071529.1836818-1-davidgow@google.com \
    --to=davidgow@google.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=jakobkoschel@gmail.com \
    --cc=jannh@google.com \
    --cc=keescook@chromium.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=netdev@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox