summaryrefslogtreecommitdiff
path: root/lib/list-test.c
diff options
context:
space:
mode:
authorDavid Gow <davidgow@google.com>2022-02-25 10:52:49 +0800
committerShuah Khan <skhan@linuxfoundation.org>2022-02-25 08:39:01 -0700
commit5debe5bfa02c4c8922bd2d0f82c9c3a70bec8944 (patch)
treef04a199a6de8a8c29361c3209459df8ea1c2870b /lib/list-test.c
parent37dc573c0a547e1aed0c9abb480fab797bd3833f (diff)
downloadlinux-starfive-5debe5bfa02c4c8922bd2d0f82c9c3a70bec8944.tar.gz
linux-starfive-5debe5bfa02c4c8922bd2d0f82c9c3a70bec8944.tar.bz2
linux-starfive-5debe5bfa02c4c8922bd2d0f82c9c3a70bec8944.zip
list: test: Add a test for list_entry_is_head()
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> Acked-by: Brendan Higgins <brendanhiggins@google.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'lib/list-test.c')
-rw-r--r--lib/list-test.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/list-test.c b/lib/list-test.c
index 3870ebfd84aa..035ef6597640 100644
--- a/lib/list-test.c
+++ b/lib/list-test.c
@@ -549,6 +549,26 @@ 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_MSG(test,
+ list_entry_is_head((&test_struct1), &test_struct1.list, list),
+ "Head element of same list");
+ KUNIT_EXPECT_FALSE_MSG(test,
+ list_entry_is_head((&test_struct2), &test_struct1.list, list),
+ "Non-head element of same list");
+ KUNIT_EXPECT_FALSE_MSG(test,
+ list_entry_is_head((&test_struct3), &test_struct1.list, list),
+ "Head element of different list");
+}
+
static void list_test_list_first_entry(struct kunit *test)
{
struct list_test_struct test_struct1, test_struct2;
@@ -764,6 +784,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),