From patchwork Tue Feb 8 04:01:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 12738132 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 956CCC433F5 for ; Tue, 8 Feb 2022 04:01:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244086AbiBHEBy (ORCPT ); Mon, 7 Feb 2022 23:01:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230298AbiBHEBw (ORCPT ); Mon, 7 Feb 2022 23:01:52 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E56FC0401E5 for ; Mon, 7 Feb 2022 20:01:52 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 2-20020a251302000000b006118f867dadso32938314ybt.12 for ; Mon, 07 Feb 2022 20:01:52 -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=+XmkWwkxZcBFnXp1LdOSslc7SXE79cZcwWCdKQ9aqB4=; b=gSLrSscicf63WBa+QXt1YmMRgTK6zeN7sj8vXSXPqm8QQDHA5o4Pn5sppkBMWCH2eQ Ruj5q8AhdYfY4Pzjm0atw94gM0suZOdIi57BejTDhRusGZjpOV7qYBDLQDUb3xlG5OaD 0v0/+OOHd+0x2CiJjghNA05UypTxJQEdkyGgn/QEogTVLfuUMOoBaJEwwlvuwkdNGyXK AsAiIYZK35QUJJZJcYJhVu9qUmuAHvtoJp1CEqk7yBo9VemL9+27adqz0fFzWQNCD90e aN0glTYOxjsZB05tCF8QJxs4HYoDJBogN3K1bNhOLoPmeo6Y4VR9K74ittvA6qjtyRZm whkw== 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=+XmkWwkxZcBFnXp1LdOSslc7SXE79cZcwWCdKQ9aqB4=; b=UM1KK0YbHq1KfmV5twP5a0672Ryx9PNbHRKfcWx26CcgLf3YE3SJ2583g37HONBdkA XHBwzj5nRCoZBhAbk1HnFspOyf0Bg7d4TN2B2NDOG5mq7Y29EWxBDTdxDKVUU54WxkQP 9eVHd6/vWG+09qDB4Fwh1hOtbUMj3rUKklbN1Pl03AjZoBRTBuQ0ToM3gvQHvcFEGZdW bx27X05+EHu+dB9LEBomdfmJ7+TZoNyHw2b/9p0rNkmiImcw921aJHVOYVC5OEDfqeDE txQ2Qszlci+24HLfArYmrxPeJaVLwcD0uraHhzMIgK4W9/CvpYqP7nzHONL8Czgiikej acYA== X-Gm-Message-State: AOAM530uJ0dKi9hjleQNWhCR3lCoQSwXw/ZuM2DCGfRYF3RlENmDRPKe aM238Mln4Dr99AAza9pglz5aT/QqGL7DUQ== X-Google-Smtp-Source: ABdhPJyMSA7NqD/FfD+yoNwPC4NdA4qhKUSPsVLL0GuhwkM7srn7XZfjhx0wpkMMlUdEj7GZsheX7uc3sfImCA== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a81:34d0:: with SMTP id b199mr3143034ywa.385.1644292911231; Mon, 07 Feb 2022 20:01:51 -0800 (PST) Date: Tue, 8 Feb 2022 12:01:21 +0800 Message-Id: <20220208040122.695258-1-davidgow@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v2 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 --- Changes since v1: https://lore.kernel.org/linux-kselftest/20220205061539.273330-1-davidgow@google.com/ - Patch 1/3 unchanged --- lib/list-test.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/list-test.c b/lib/list-test.c index ee09505df16f..976e9ae1f3c5 100644 --- a/lib/list-test.c +++ b/lib/list-test.c @@ -161,6 +161,24 @@ 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) +{ + /* This test doesn't check correctness under concurrent access */ + 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(&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 +725,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 Tue Feb 8 04:01:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 12738133 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 77F72C433EF for ; Tue, 8 Feb 2022 04:02:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242791AbiBHECJ (ORCPT ); Mon, 7 Feb 2022 23:02:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346068AbiBHECI (ORCPT ); Mon, 7 Feb 2022 23:02:08 -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 B399AC0401E9 for ; Mon, 7 Feb 2022 20:02:07 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id a88-20020a25a1e1000000b00615c588ab22so33047066ybi.3 for ; Mon, 07 Feb 2022 20:02:07 -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=CxJP9WmKdhJPvihmm8sG8RGI+nXykzjS6eG2g1fovU8=; b=aTpA7d/2qmOZO32QUtSD6yTG0RdY1y10sUxuy8DAdgV6jsUvpRmy7giwqlY9hzgAAP MiAnm8NGbh8wBX3VGPsvZg07SVm4BZ2zN3qL5IV4Kkueqg7I4u725AahOYSvKlq8gG6w mdsNR53kxuZ8L/iRe/BVZuVKVcjCFvEatuVODOxrHcY8l5GT6VcmrgLM9Wjo0Z60DHBl Exn94S5UeSd37P1RDdYOmEGS7jHjq7Q/YXC3/VkPmP1HTp9zudjsyV3KJ390qNB+IQMN n1+UqVxzxhHsofrPK8ScBj9gNKPkFOWyw5d//CIFZqpje2C5WQOILtqsx5bdYTb8WLeK U0zw== 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=CxJP9WmKdhJPvihmm8sG8RGI+nXykzjS6eG2g1fovU8=; b=cmJKbxsDLksEhyHSkm9wvMojsyQWKQdJk74ejSt8IWmHxHgviq3fxvfY0yFfIj2IUU zWqU8pgZBrVIEx/tFFJWqqOtBhM7oTZnRHNT3MDlJKMFM+SVPoJSdgjbp1PSjEmk2zGi COs3aHU5w0whsltgYztEsHRS30Fbe+GuFRNDWixCAHPep1rhp/foykCb540ojI6FrR7S e5OqnY+pQGwt6wQ8wOfK0TocfpMvccyBRRERDPtFyp5R1jf+vmk/+MvT6g5Khl5lZvCl ddJop6invsW/S441Kh0Oox31au7S5+cXFCTu7rH3RfW7t1zu/AdDkdP4S1TS+sa7CW5U M33w== X-Gm-Message-State: AOAM533vnIBOoEUhm+EFchZJ8hDDyYsLsFu3LQqkfOZRStOYcZIqSQu5 nEM1Y+tFzZCaGAU8d4bu33WVHxA3RVtYPQ== X-Google-Smtp-Source: ABdhPJwfi9JlOMGPBk60WOI+gsv4Ug5ydFhcY73dbYBp19AibO1J+5xomc8gqDsUHdJyhCe/D9hiPBlo6ORobQ== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a05:6902:100a:: with SMTP id w10mr3120727ybt.668.1644292926851; Mon, 07 Feb 2022 20:02:06 -0800 (PST) Date: Tue, 8 Feb 2022 12:01:23 +0800 In-Reply-To: <20220208040122.695258-1-davidgow@google.com> Message-Id: <20220208040122.695258-2-davidgow@google.com> Mime-Version: 1.0 References: <20220208040122.695258-1-davidgow@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v2 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 --- 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 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/list-test.c b/lib/list-test.c index 976e9ae1f3c5..1960615d1a9f 100644 --- a/lib/list-test.c +++ b/lib/list-test.c @@ -252,6 +252,23 @@ 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(test, list_is_head(&a, &a)); + /* Non-head element of same list */ + KUNIT_EXPECT_FALSE(test, list_is_head(&a, &b)); + /* Head element of different list */ + KUNIT_EXPECT_FALSE(test, list_is_head(&a, &c)); +} + + static void list_test_list_is_first(struct kunit *test) { struct list_head a, b; @@ -729,6 +746,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 Tue Feb 8 04:01:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 12738134 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 86561C433EF for ; Tue, 8 Feb 2022 04:02:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346641AbiBHECT (ORCPT ); Mon, 7 Feb 2022 23:02:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346163AbiBHECT (ORCPT ); Mon, 7 Feb 2022 23:02:19 -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 8C664C0401F2 for ; Mon, 7 Feb 2022 20:02:18 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id 68-20020a621547000000b004c74bbd2819so8711432pfv.18 for ; Mon, 07 Feb 2022 20:02:18 -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=bOOyAGeDCfZ5ARPFOfUdicpQjmM40zAiAN4IAXCAr1w=; b=Qe9jHwp67T/2rtU3YnWRGt23KuxYuhClrpZS/9iEuqVpfhFbv0LU/Whse5mKOonQtp 5BJAgro1lSUXcuajv/2iCIGNDqNOU9ju+Jk1ocaWvN8uVcu9iUohh12uKaOBbQ8tAIvG I3F3ygIhBC3BTW55WTyV7ooZ46zy/Ia3wFUoJvlHejD+Sjluo/lxtN4Tk+B/u0j0vtbH BQ62gmReBl/flHQWLc9xgF65HjOX+4q4I8kelAVbZUj9xn84ow9gbC0se2fiWKNL+Tz0 jvuqqc+99wXowg1SpuWj0lv/614wK7MxL1VjlFnVvqlT8iDEnw051rw0lptj7qvyRiUB LcVA== 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=bOOyAGeDCfZ5ARPFOfUdicpQjmM40zAiAN4IAXCAr1w=; b=NbyPLKSdJ1mZP1w4dfFi9zlPYzvYFrT1En1jcM8awP3ScoD0qJgWk4KfgapJGA3OV6 q/opB8wCwpP7rBVpOKwRw3zsXOfLaycpHNnsyWzc6b7MKZBNPpXde4KK/u48kyA1vWT9 sSWFhaHjeoqsY/VEDYKfnCBZx2xb1SmsnAHN3V2Hb5xKGAQg9N5JDpcShWr75og33NfP ATtYcTk5ZSGZ0ehM3gqviXNW5pIeqvL0wyvlDeDs93JxlE/MRV3Ez9mOe8j+kUS6Etlo 0X5ajtyxyMFFvIFjqjT+uL3p7NcASCPKApzUK7+WschJIFM1v9NORHNQZNCYICXLyzcG UxRA== X-Gm-Message-State: AOAM5316MuMXb1xxW5j6EbX/kYQ+OC40h44MpwgE9/l1+5kS5uPIYbFI mXrSdcW6jT/lBfLr7UJeO84tdCKVlvkYwQ== X-Google-Smtp-Source: ABdhPJwQX7dVSP0gMLBZgYP13J+vjOvNbh4RSr0wLnEiLAEFWdMT+ZtFLOBZcsSPlyL8pBBIsNgxs3AV+TH99w== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a17:90a:5503:: with SMTP id b3mr2328282pji.187.1644292937742; Mon, 07 Feb 2022 20:02:17 -0800 (PST) Date: Tue, 8 Feb 2022 12:01:24 +0800 In-Reply-To: <20220208040122.695258-1-davidgow@google.com> Message-Id: <20220208040122.695258-3-davidgow@google.com> Mime-Version: 1.0 References: <20220208040122.695258-1-davidgow@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v2 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 --- 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 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/list-test.c b/lib/list-test.c index 1960615d1a9f..80dd14c4ca1f 100644 --- a/lib/list-test.c +++ b/lib/list-test.c @@ -546,6 +546,22 @@ 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(test, list_entry_is_head((&test_struct1), &test_struct1.list, list)); + /* Non-head element of same list */ + KUNIT_EXPECT_FALSE(test, list_entry_is_head((&test_struct2), &test_struct1.list, list)); + /* Head element of different list */ + KUNIT_EXPECT_FALSE(test, list_entry_is_head((&test_struct3), &test_struct1.list, list)); +} + static void list_test_list_first_entry(struct kunit *test) { struct list_test_struct test_struct1, test_struct2; @@ -761,6 +777,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),