From patchwork Fri Mar 11 07:15:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 12777516 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 762B6C433EF for ; Fri, 11 Mar 2022 07:15:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2A6A8D0002; Fri, 11 Mar 2022 02:15:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EB3308D0001; Fri, 11 Mar 2022 02:15:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D54958D0002; Fri, 11 Mar 2022 02:15:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0094.hostedemail.com [216.40.44.94]) by kanga.kvack.org (Postfix) with ESMTP id C5C658D0001 for ; Fri, 11 Mar 2022 02:15:48 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 6143598C17 for ; Fri, 11 Mar 2022 07:15:48 +0000 (UTC) X-FDA: 79231245576.24.E380703 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf26.hostedemail.com (Postfix) with ESMTP id E65D514001B for ; Fri, 11 Mar 2022 07:15:47 +0000 (UTC) Received: by mail-yb1-f202.google.com with SMTP id h16-20020a056902009000b00628a70584b2so6672509ybs.6 for ; Thu, 10 Mar 2022 23:15:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=kehSp/poBksAvN+ookLna3p1CLAB/x6vQemcHHjE9ck=; b=fegh3z766K7XxTtoebS427NIXVyVt0vELknatpspBcD93w7b4yKgCM8VTOA/JwonRG rA+XIToLf/q5jYCMKU1PttLZHvXYU8b3DL9xmEEz/UqE6uODJg+dymzXp38PNK1zNgJk 6IGNpHaVAoKQYdyVZf5VzJoz+Yr03u9BIOws5FX/6piicMFh62mjwW9YawDLz9EcXjFR scPRFOv064kITQRykgdBz+yWBFfc7/wl4WNjXVlMmHTG6SCjAZheE5gqCCPSl0gH0Of5 bqpRfI2LWAl4P0Bo06c4vhnC89KL6IYzks34DnptJpsluZQIszC276vQBxiEzAjhH5Mu SekA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=kehSp/poBksAvN+ookLna3p1CLAB/x6vQemcHHjE9ck=; b=EuIr6PVyfhawRSzXEbkPuX8s07NMBAi1MFjMAxk6xEf/v87Jzc4JWT8/aCtXi3mzaS 9agBMlCc6kZIWZseRn8hw5Ny8zJkg7c42ryScElQGU54uJ+W65HjhXdVS12i+zF5RQeN zW1m/WuVXWk0zs2y3ZbNme991j8flVBpUSmZrlV+fA9O67YVUUqA/uoT4Xz/Ypo8KFst Z0qLTuQxcGyPU6dWMZ6DqTEGGkxXR3eWd2FRZ/PxVuqXYRUDi2dZCnM6DWeh0XSO2MLH fA4GB9owOyRhGG2/6j+SWXZTzcyocHCu1OcmEZfU7BPPk3PGSP91kN57OoAG0K/FNbGb q/Ug== X-Gm-Message-State: AOAM531TeaSMWVCxH+ufYXdVkLKO+LqNWMnyinyAP9UanzZODKI/vcEN 2wrse8r6mUd2dcFsKZNiL0NgehJsS/fCxQ== X-Google-Smtp-Source: ABdhPJxmCB7rj2KPICFIlO7jQTEBEIX3UJqMDu1xzucTtM+H9C5+zwsTdAQHebuflHkEJq4xsHVsGn3TSZXY/A== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a25:8684:0:b0:629:917:c5c with SMTP id z4-20020a258684000000b0062909170c5cmr6701419ybk.403.1646982946981; Thu, 10 Mar 2022 23:15:46 -0800 (PST) Date: Fri, 11 Mar 2022 15:15:29 +0800 In-Reply-To: Message-Id: <20220311071529.1836818-1-davidgow@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [RFC PATCH] list: test: Add a test for list_traverse From: David Gow To: Linus Torvalds Cc: Arnd Bergmann , Greg Kroah-Hartman , Jakob Koschel , Jann Horn , Kees Cook , Linux Kbuild mailing list , Linux Kernel Mailing List , Linux-MM , Netdev , kunit-dev@googlegroups.com, David Gow X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: E65D514001B X-Stat-Signature: 5wchgux7wum7omdyq43mbcfd11u7kykh X-Rspam-User: Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=fegh3z76; spf=pass (imf26.hostedemail.com: domain of 3IvcqYggKCNM2zK725DL5DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--davidgow.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3IvcqYggKCNM2zK725DL5DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--davidgow.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1646982947-413155 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- 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), {},