From patchwork Fri Feb 25 02:52:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 12759560 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 1E87DC433EF for ; Fri, 25 Feb 2022 02:53:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236588AbiBYCxq (ORCPT ); Thu, 24 Feb 2022 21:53:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234435AbiBYCxq (ORCPT ); Thu, 24 Feb 2022 21:53:46 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E0EE278CAF for ; Thu, 24 Feb 2022 18:53:15 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id g19-20020aa796b3000000b004e136dcec34so2313939pfk.23 for ; Thu, 24 Feb 2022 18:53:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=2puWIl3IcpbmEtDoBGd8mpwWXz/flgK5gtzvJt22Ibg=; b=V7A8Rb2FXvpOWQfWfzts5uMpUAXDUD+M3X+h/q51ZiFHnsqw6bhHOmPnaoE/ZY5iOQ C8orkMrqUIiLMxOLijz28b1G+810z04aGpYpY4X0pI3wqm7P/t7sWYKk1aXduo9gdbhw 1RyDvYEIhp+V2Sa8MxaG/5Ur286JFCurw2fjxoe8oAj4IeSjVCCKYjadlmyL25pI9aNo SApjixcEDESi3VEHQZ6r++HehdafCfN2K3xj1eXCQ1+cM6e3EgyVe5mecBCKCOaQi8ut d8F+eBLvh2qcv4lPsWt+D65gG3/e8tGPx77ArCe2k0ONFiJ65/xXlcROmNm4FaBDWBfy Qtew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=2puWIl3IcpbmEtDoBGd8mpwWXz/flgK5gtzvJt22Ibg=; b=SvIYatDKP24erhVnlGoUzCnCFCDq9tyRBEF7b7aBd8n3u0iN4CBzsCsy9hKAShcKJi 3zNv1H8OedhwBx4ZGYqvMLVgzCMR8ZIbBqwTmnxLYL9KLyBIMKxw1xMvBbkWpE8oVjN1 GqKmVwSeH/t0+NXsX6GBeUzAAwl2LjnmUWOzsa3ghqICK0pKGYofsCOtbUZ/5yWhVuxv 7XUnDH2PFTX8rbSt84A7Tp1LvJ0hYc0b9YeqkYdSgSN/WH9GJFsEpPvNOpDcZNnjkS7q px2lIuDO7cuWqlXg3gBOH71wGPbJ1/AVVVRo2aLIMrWIzzdZrjcGfmSYkcsNYKtLiIAl liSw== X-Gm-Message-State: AOAM532c3NrHZSrBMB7rxNx58+jDzyesF8oQl9YKjR5x0UJcOlLDspIR rKFrDiwXV4UIyQIfv8nQV8vLxiTTnJknFg== X-Google-Smtp-Source: ABdhPJyAVL+KVNuKKmj4OCwnf0mb2V2caveapLa1ZAGZW4xhwAdHDu2wqfAIMOl8UrftyjkEAcI9bMuubXYhJw== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a17:90b:4b52:b0:1bc:b208:dc5c with SMTP id mi18-20020a17090b4b5200b001bcb208dc5cmr139771pjb.1.1645757594543; Thu, 24 Feb 2022 18:53:14 -0800 (PST) Date: Fri, 25 Feb 2022 10:52:46 +0800 Message-Id: <20220225025247.1888244-1-davidgow@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 1/3] list: test: Add test for list_del_init_careful() 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 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The list_del_init_careful() function was added[1] after the list KUnit test. Add a very basic test to cover it. Note that this test only covers the single-threaded behaviour (which matches list_del_init()), as is already the case with the test for list_empty_careful(). [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c6fe44d96fc1536af5b11cd859686453d1b7bfd1 Signed-off-by: David Gow Reviewed-by: Andy Shevchenko --- Changes since v3: https://lore.kernel.org/lkml/20220209052813.854014-1-davidgow@google.com/ - Fix a comment style issue. - Add Reviewed-by tags. Changes since v2: https://lore.kernel.org/linux-kselftest/20220208040122.695258-1-davidgow@google.com/ - Fix the test calling list_del_init() instead of list_del_init_careful() - Improve the comment noting we only test single-threaded behaviour. Changes since v1: https://lore.kernel.org/linux-kselftest/20220205061539.273330-1-davidgow@google.com/ - Patch 1/3 unchanged --- lib/list-test.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/list-test.c b/lib/list-test.c index ee09505df16f..302b7382bff4 100644 --- a/lib/list-test.c +++ b/lib/list-test.c @@ -161,6 +161,26 @@ static void list_test_list_del_init(struct kunit *test) KUNIT_EXPECT_TRUE(test, list_empty_careful(&a)); } +static void list_test_list_del_init_careful(struct kunit *test) +{ + /* NOTE: This test only checks the behaviour of this function in + * isolation. It does not verify memory model guarantees. + */ + struct list_head a, b; + LIST_HEAD(list); + + list_add_tail(&a, &list); + list_add_tail(&b, &list); + + /* before: [list] -> a -> b */ + list_del_init_careful(&a); + /* after: [list] -> b, a initialised */ + + KUNIT_EXPECT_PTR_EQ(test, list.next, &b); + KUNIT_EXPECT_PTR_EQ(test, b.prev, &list); + KUNIT_EXPECT_TRUE(test, list_empty_careful(&a)); +} + static void list_test_list_move(struct kunit *test) { struct list_head a, b; @@ -707,6 +727,7 @@ static struct kunit_case list_test_cases[] = { KUNIT_CASE(list_test_list_replace_init), KUNIT_CASE(list_test_list_swap), KUNIT_CASE(list_test_list_del_init), + KUNIT_CASE(list_test_list_del_init_careful), KUNIT_CASE(list_test_list_move), KUNIT_CASE(list_test_list_move_tail), KUNIT_CASE(list_test_list_bulk_move_tail), From patchwork Fri Feb 25 02:52:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 12759561 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 38533C433F5 for ; Fri, 25 Feb 2022 02:53:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236855AbiBYCyJ (ORCPT ); Thu, 24 Feb 2022 21:54:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230265AbiBYCyJ (ORCPT ); Thu, 24 Feb 2022 21:54:09 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99BAA278CB4 for ; Thu, 24 Feb 2022 18:53:38 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id k7-20020a255607000000b00621afc793b8so1940159ybb.1 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=LMYAfmt0R6s5yrcYOiRVI3voTcpR0d6yan0VKROMaineF1k7AApnqeuM551fW16M56 HcYh6ugHXUpKm7qmsYJt4BKmbRoMNyl/yYJolYPt3x0kQ76C3DVyal6YfdymY22zbqJk o9Mt0DB5OpVSXUXTbh4TOUl+6KrdW3mBMqCvi1AIqOsZTOGJEQO2/qRrBasP2jRaomkn a6FpRDfo+nP+2k2e7HQwSgubGoCXLPfg7aMqDZ0SYJhZBy367GDRhZQhj+t4LotpqfEb QesK9U28WF+lj6M/7tcZ5y2GVLaLcW1EyuilTNaNLI/t5Y8goHBd4FShqTstOOKNglG2 df9w== X-Gm-Message-State: AOAM530ujrHiSfjDytW6tePtVAlq3SSJZqATCMIJRxAE2SHc6xJj9+Jc mrulgwW0C0MMhUs8j6NbWHLsWu5M3VPpmA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@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), From patchwork Fri Feb 25 02:52:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 12759562 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 2591FC433EF for ; Fri, 25 Feb 2022 02:53:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236865AbiBYCyX (ORCPT ); Thu, 24 Feb 2022 21:54:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236856AbiBYCyX (ORCPT ); Thu, 24 Feb 2022 21:54:23 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BB27278CB1 for ; Thu, 24 Feb 2022 18:53:52 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id j10-20020a17090a7e8a00b001bbef243093so4708766pjl.1 for ; Thu, 24 Feb 2022 18:53:52 -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=V1rQ4nquNp18jfgzfW9vZ+glyyMNehUDY2htsrduhLY=; b=BZmWVijfvQImtZ6KfmIcvMhyC1etJR7CWjsko9mlIe0tq5RLpWAsjNcMKR8wyzqXJR nYTEMgzfFeB9SJ3lQjC9u7f+7tBAVYHLsAdLY8Mb4qEJLDV0iXBhpws9Mqq5LEHWyRWb K6KUA5ClL5grlHnjFsu44kuWjMedffDqmxIh52krhWg2RqIL+/4wpKXmwhVFfProTrHY xNoJANmXL4yJ/MkDTXTCrgGhiHpwbpEwtCiCa/WlIZgRVopwIzgfPgFPacQch7tyMgLj S4KuD69r+6hpk4LOtKFSbzLBDV59eKDCfuVGZdmgA5maLkIfBry6mSulKZYFYN/x5NHs /8IA== 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=V1rQ4nquNp18jfgzfW9vZ+glyyMNehUDY2htsrduhLY=; b=OUTOkbUN2dD7FDksKpH9DKLHKBFfSwjo9Jcq+0e6cMzSByWVHFtCmgjssN1ehkeNpK g2UOR4/MHgX8ltPENiV7PzWIuIP6jiIP2Cop7VfSkXzWYktKSowTHdSJLX5t/7IFL/k6 MDafW+qkcsPp68AnegyFABhIIiHTQuwGfDdS46f7nXNC1tpqkGMJqhF+AwwoAo2sQFyB GV1T5f5aRUqC1TKkknF5WVDncweSIz3s2O6Awk1t/hSlykxR8rs5L/dKZWj4EI1YjCnH PF+7S0ySpX7fdKqMD1dxBYJ9e2a6ZXpuZQCv5YMr1dGj9g7emcmqnr7zkyozqXE30Tip l4Iw== X-Gm-Message-State: AOAM530XGYeiFcWQpEY9cpe8Tt6CgLRfr8a7QWrA8sRxbqSJ4saV5yvB qB0MzVQ7kxTv4SKALt3XHknNGBJWOJ0l/Q== X-Google-Smtp-Source: ABdhPJyET4zKPHUz257ncAUxuaxKKi7dMHrY4HWUqKL5zPsnxifIleo7FNHDaCAiF1dwtX2n/rX/AdH+KX3BTQ== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a17:90a:6001:b0:1bb:83e8:1694 with SMTP id y1-20020a17090a600100b001bb83e81694mr1078322pji.127.1645757632007; Thu, 24 Feb 2022 18:53:52 -0800 (PST) Date: Fri, 25 Feb 2022 10:52:49 +0800 In-Reply-To: <20220225025247.1888244-1-davidgow@google.com> Message-Id: <20220225025247.1888244-3-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 3/3] list: test: Add a test for list_entry_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 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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 Acked-by: Daniel Latypov Acked-by: Brendan Higgins Reviewed-by: Andy Shevchenko --- Changes since v3: https://lore.kernel.org/lkml/20220209052813.854014-3-davidgow@google.com/ - Add Reviewed-by tags. Changes since v2: https://lore.kernel.org/linux-kselftest/20220208040122.695258-3-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-3-davidgow@google.com/ - Rework the test entirely to better match the improved list_is_head() test. --- lib/list-test.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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),