From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADEB1C433EF for ; Fri, 25 Feb 2022 02:53:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236863AbiBYCyL (ORCPT ); Thu, 24 Feb 2022 21:54:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236856AbiBYCyJ (ORCPT ); Thu, 24 Feb 2022 21:54:09 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5E14278CB5 for ; Thu, 24 Feb 2022 18:53:38 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2d07ae11460so18747567b3.7 for ; Thu, 24 Feb 2022 18:53:38 -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=1JSYgi+oTGL4l294PnzZ502FNsmaxeRtZnvR904tj6U=; b=mxgk6tcHgsg2Pw4mDUim3HZH9kmRTfjI4cl0J6ChHJhFGp58/j755dpPkQ7Ig5hMT5 RJWKLv74Lr2SS0UtgecaaAlvgp0uWV60nQa+5lI5vVhH7XjOa0zU0jqScTOoJMrRFLAo +NrHZ0FGQdnW2f7NKYEhlkqi01se19MNL5BUzrvp33IWcoT8lKkWZnlbKqKM0ex42P6/ eAb4tsarKkhASieo18Si3OUx1JL7oUwDuRkGZWEvXcNRtxPET5r7Bdm5MRu5A+ZwEPEz t23FQFSJYBWoMHr9uimcgcdZc9Y1NDx6IKU89vbDTqb58ikkpcTh8m32LCEfgmcjaosG iQZg== 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=1JSYgi+oTGL4l294PnzZ502FNsmaxeRtZnvR904tj6U=; b=C0Dq3Zu/F/SDnRnFvHq3PROwV3cor8DVdI9DafCGaFPtiFZak8FA1f1as7w2eol7UF lzXVhkpGcBRXILZLy3hkEtd7VgtNcau8uCXtWDo9X5lB/3xiSh9Eh20gajOnoK9s9p7R RdxXs94VXhpeJbNlfOqiFCtcQj9MNWMmSXOiMuiA0LLbomiqtySiWNUn3n0u/AYp1ZTI na3JGqFeRGUuW5jdJV23wsiNLM6/RHiWgyvoS8Tjh9NOntIjSYwXdTSjEiO7SNq7WHba dwQQ/uD/i6G2GJkOMqNCE/wi5tlKf6BiWfbpvASIvWMXA6YtaPnP6pKJKLQSJzf3gDf1 O13w== X-Gm-Message-State: AOAM532zhf1smvN/YpC52m2kRRXF4NzdZpfYEOHEk4UoHcjar5D2ZA5D DWukf09AOy5DCq3UiLj+7Ze/CP6FVr83tQ== X-Google-Smtp-Source: ABdhPJyXLhiVRmQq6TxnG5H67PgQrDXUmQO++OuwW0lLgq81reTtItb19csaR4kyWBDKHiV/rO2J9G/+LfKihQ== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a5b:9cc:0:b0:61d:f7ba:7fc with SMTP id y12-20020a5b09cc000000b0061df7ba07fcmr5113388ybq.434.1645757617802; Thu, 24 Feb 2022 18:53:37 -0800 (PST) Date: Fri, 25 Feb 2022 10:52:48 +0800 In-Reply-To: <20220225025247.1888244-1-davidgow@google.com> Message-Id: <20220225025247.1888244-2-davidgow@google.com> Mime-Version: 1.0 References: <20220225025247.1888244-1-davidgow@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 2/3] list: test: Add a test for list_is_head() From: David Gow To: Shuah Khan , Andy Shevchenko , Linus Torvalds , Brendan Higgins Cc: David Gow , Daniel Latypov , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Daniel Latypov Acked-by: Brendan Higgins Reviewed-by: Andy Shevchenko --- Changes since v3: https://lore.kernel.org/lkml/20220209052813.854014-2-davidgow@google.com/ - Add Reviewed-by tags. Changes since v2: https://lore.kernel.org/linux-kselftest/20220208040122.695258-2-davidgow@google.com/ - Use the _MSG variants of the assert macros, as suggested by Daniel Latypov. 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 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/list-test.c b/lib/list-test.c index 302b7382bff4..3870ebfd84aa 100644 --- a/lib/list-test.c +++ b/lib/list-test.c @@ -254,6 +254,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; @@ -731,6 +749,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.1.574.g5d30c73bfb-goog