From patchwork Tue Feb 28 18:42:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 13155124 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1F96EC64EC7 for ; Tue, 28 Feb 2023 18:43:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=M2VoBY57Vva7b7a6lDrrsnB+ibacYUGgnNGX168toLE=; b=sFZnQ2OqjaA56x h9fQ5NhDGTMuYyKWxejXWAyxaLP/+7wHUDeWIG0E+0PeE4Zp1WvDHVNqrIi7qtHlMf1a7HmVPah3/ yqaZ+KuwxdOrBGBvKpWe5y3EVc5NMRw6PpMQMXMnliE/Ur+L9p3WDqSzFalx8uZV1HJff9vzsUowr xpF2Gwn9ddW3UXpKE2njb5w65+QBrpiU+RE62etRi+Mw0inZ8TThRAEhs4Gp898pDo++lGh9vbtLK yUvrdJOAfik+h9z25EJdwz0bZ+xKJ9+RQvVuV2F9IyIAwlnJK9uF4lbMlDQPdMGDMcEp4OekvX9mO 48pW4c8u2NdLFdxyF+3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pX4wD-00E0a6-2j; Tue, 28 Feb 2023 18:42:57 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pX4wA-00E0Z5-9w for linux-riscv@lists.infradead.org; Tue, 28 Feb 2023 18:42:55 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0095BB80E69; Tue, 28 Feb 2023 18:42:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6273AC433D2; Tue, 28 Feb 2023 18:42:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677609771; bh=bxf6Na4275DAjaKN9Sr8BVZGW0gjDgYTE05rVuIhWwo=; h=From:To:Cc:Subject:Date:From; b=fsrpFMka4rEhDNttlbTgKspj87wKZKL1+GEijCxidZ09ngGHpa2+x+se6dC+QQgX6 fzKhXvYZuB5pOYUYalaQPQ5/49LTwfGl8eBVr/Br6E5sTNqM/ErsTlPRtpEwvGWyOc G4nq7wdtH+7FwJ1YICBYnQ09jhSTBt2KNXPyuhI/KjJ8HzOZNLatqJFSlT4ZGJtwS+ FMYOnlz3Hv2d0mCH2we/Aljk7NVKHs+JbsKtkgNQtgN9QhPWqje8KPPOyauFKDxpPA DUuAeRS+SKqtfrMWmdzze3dAjDxRLYQVb4oO50CJkUyn93lZFG+QL+1lBat3aWZQBy JS9bHptI/iQpQ== From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: Palmer Dabbelt , Andy Shevchenko , linux-kernel@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Heiko Stuebner , linux-riscv@lists.infradead.org Subject: [PATCH v2 1/2] lib/test_string.c: Make definition less dense Date: Tue, 28 Feb 2023 19:42:44 +0100 Message-Id: <20230228184245.1585775-1-bjorn@kernel.org> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230228_104254_514153_8406E2A1 X-CRM114-Status: GOOD ( 10.62 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Björn Töpel Checkpatch seems to have trouble making sense of the situation when struct definitions, variable definitions, and __initconst marking is done in one go. Let's be nicer to checkpatch, and move the struct definition out, which removes the error. Signed-off-by: Björn Töpel --- lib/test_string.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) base-commit: ae3419fbac845b4d3f3a9fae4cc80c68d82cdf6e diff --git a/lib/test_string.c b/lib/test_string.c index c5cb92fb710e..550229084c41 100644 --- a/lib/test_string.c +++ b/lib/test_string.c @@ -179,15 +179,17 @@ static __init int strnchr_selftest(void) return 0; } +struct strspn_test { + const char str[16]; + const char accept[16]; + const char reject[16]; + unsigned int a; + unsigned int r; +}; + static __init int strspn_selftest(void) { - static const struct strspn_test { - const char str[16]; - const char accept[16]; - const char reject[16]; - unsigned a; - unsigned r; - } tests[] __initconst = { + static const struct strspn_test tests[] __initconst = { { "foobar", "", "", 0, 6 }, { "abba", "abc", "ABBA", 4, 4 }, { "abba", "a", "b", 1, 1 }, From patchwork Tue Feb 28 18:42:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 13155125 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE85AC6FA8E for ; Tue, 28 Feb 2023 18:43:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gyohf6huQIdXReeCRkH70QZ/lIz52AeFaM6Xr3BhVw4=; b=ZMegdggu7XX+ju V8Q9YuLihQHkdBgP9YAhWogZtdFmcZ/PUXFI3lbps9DywA+sIr8ia6hGrR70cOmOugM1UUSpe8jwD UL9ntFCb+x/cLPDbg8BDyizC5ydv4H82wsQ2bybXaKACxcoVXK32W0r+oaTQ+Eq7OYNeuBSzyW+pl EVItvpgyV+28jQlC9UU0ymETMQsSigIN8MhmUzkklw83bWfzR2iJihltg+7fzRlyqEwkGEYmez6r7 o8XRhqMi9MHxBWCTiDBZLujuJHm9kSbsJhi2/o4VlTA1dVbTne8ry/PEtjZfw1ekfWX9gMvKnoWmD 2Do4VvyCy9f71X5QFeRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pX4wF-00E0ay-4P; Tue, 28 Feb 2023 18:42:59 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pX4wA-00E0ZB-Pd for linux-riscv@lists.infradead.org; Tue, 28 Feb 2023 18:42:56 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2746F6117F; Tue, 28 Feb 2023 18:42:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C2CEC433EF; Tue, 28 Feb 2023 18:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677609773; bh=pidVvllSN1IUSrHAwpFFAwnr0Xfr4NblI3c7HbGX5aI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oc+8db52928eVh7Pnnftzyj4a4Sy5e1N4sO8tPy8jVCHNx3zmiRCl0acwKxQojVWK MwtTQu99w1ZoQYaKfMOKZ7FHiP15oeYEpSQgLJdcxo/w1HwJnfodd+x0sHxkjV1QvT 3Pn+a52xCWNhRI3dMAnPw/ojXTXLRcDd2OD+sZqexcWQ1l8C7OsBFy4Ldh1Kr34w0c 2ZAl9oTcK6NjsmAjFKqLCGgh1HiM5p2LROt6xUtrlxa/e1cFXx4ek8E5AEb8D0g9U1 vif7EekWWmAE+yp2rRmezZQmwR5yEAmx2gm1K4w5wP1PlbRAmWzRAT+UYDlPmvOqxz pmZ4hjWQqOb0A== From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: Palmer Dabbelt , Andy Shevchenko , linux-kernel@vger.kernel.org Cc: Palmer Dabbelt , Heiko Stuebner , linux-riscv@lists.infradead.org, =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= Subject: [PATCH v2 2/2] lib/test_string.c: Add strncmp() tests Date: Tue, 28 Feb 2023 19:42:45 +0100 Message-Id: <20230228184245.1585775-2-bjorn@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230228184245.1585775-1-bjorn@kernel.org> References: <20230228184245.1585775-1-bjorn@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230228_104254_891964_8F27EA55 X-CRM114-Status: GOOD ( 15.81 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Palmer Dabbelt The RISC-V strncmp() fails on some inputs, see the linked thread for more details. It turns out there were no strncmp() calls in the self tests, this adds one. Link: https://lore.kernel.org/all/2801162.88bMQJbFj6@diego/ Reported-by: Heiko Stübner Signed-off-by: Palmer Dabbelt Signed-off-by: Björn Töpel --- v1->v2: Added two more tests (pos/neg). (Andy) Minor code style issues. (Andy) Fixed checkpatch errors. --- lib/test_string.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/test_string.c b/lib/test_string.c index 550229084c41..b95037eb138b 100644 --- a/lib/test_string.c +++ b/lib/test_string.c @@ -209,6 +209,44 @@ static __init int strspn_selftest(void) return 0; } +struct strncmp_test { + const char *str_a; + const char *str_b; + unsigned long count; + unsigned long max_off; + int retval; +}; + +static __init int strncmp_selftest(void) +{ + size_t i; + static const struct strncmp_test tests[] __initconst = { + { "/dev/vda", "/dev/", 5, 4, 0 }, + { "/dev/vda", "/dev/vdb", 5, 4, 0 }, + { "00000000---11111", "00000000---11112", 12, 4, 0 }, + { "ABC", "AB", 3, 0, 67 }, + { "ABA", "ABZ", 3, 0, -25 }, + { "ABC", "ABC", 3, 0, 0 }, + }; + + for (i = 0; i < ARRAY_SIZE(tests); ++i) { + const struct strncmp_test *s = tests + i; + size_t off; + + for (off = 0; off <= s->max_off; off++) { + int res = strncmp(s->str_a + off, s->str_b + off, s->count - off); + + if (res == 0 && s->retval != 0) + return 0x1000 + 0x100*off + 0x10*i + 0x0; + if (res > 0 && s->retval <= 0) + return 0x1000 + 0x100*off + 0x10*i + 0x1; + if (res < 0 && s->retval >= 0) + return 0x1000 + 0x100*off + 0x10*i + 0x2; + } + } + return 0; +} + static __exit void string_selftest_remove(void) { } @@ -247,6 +285,11 @@ static __init int string_selftest_init(void) if (subtest) goto fail; + test = 7; + subtest = strncmp_selftest(); + if (subtest) + goto fail; + pr_info("String selftests succeeded\n"); return 0; fail: