LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: David Gow <davidgow@google.com>
To: Shuah Khan <skhan@linuxfoundation.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Brendan Higgins <brendanhiggins@google.com>
Cc: David Gow <davidgow@google.com>,
	Daniel Latypov <dlatypov@google.com>,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	kunit-dev@googlegroups.com
Subject: [PATCH v2 2/3] list: test: Add a test for list_is_head()
Date: Tue,  8 Feb 2022 12:01:23 +0800	[thread overview]
Message-ID: <20220208040122.695258-2-davidgow@google.com> (raw)
In-Reply-To: <20220208040122.695258-1-davidgow@google.com>

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


  reply	other threads:[~2022-02-08  4:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2022-02-08 20:40   ` [PATCH v2 2/3] list: test: Add a test for list_is_head() 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

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=20220208040122.695258-2-davidgow@google.com \
    --to=davidgow@google.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=brendanhiggins@google.com \
    --cc=dlatypov@google.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=torvalds@linux-foundation.org \
    --subject='Re: [PATCH v2 2/3] list: test: Add a test for list_is_head()' \
    /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

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