list: test: Add a test for list_is_head()
authorDavid Gow <davidgow@google.com>
Fri, 25 Feb 2022 02:52:48 +0000 (10:52 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Jun 2022 08:23:31 +0000 (10:23 +0200)
commit 37dc573c0a547e1aed0c9abb480fab797bd3833f upstream.

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>
Acked-by: Brendan Higgins <brendanhiggins@google.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
lib/list-test.c

index ee09505df16f17161dd3d906a3cedb8d5dda8af0..994ea4e3fc1b908d5540e42410a5b16bcedeccfb 100644 (file)
@@ -234,6 +234,24 @@ 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_MSG(test, list_is_head(&a, &a),
+               "Head element of same list");
+       KUNIT_EXPECT_FALSE_MSG(test, list_is_head(&a, &b),
+               "Non-head element of same list");
+       KUNIT_EXPECT_FALSE_MSG(test, list_is_head(&a, &c),
+               "Head element of different list");
+}
+
+
 static void list_test_list_is_first(struct kunit *test)
 {
        struct list_head a, b;
@@ -710,6 +728,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),