From patchwork Thu Mar 2 07:19:34 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: 13156774 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 5B8D9C6FA8E for ; Thu, 2 Mar 2023 07:20:09 +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=5iBld+9sCwn7qbCl4fz1ewM9wLi+HH9hRkbz5BLBJ3E=; b=i9GssvdQZp28y7 u75oa0/37371D4M/ugAdVbmWGAbLIVTPOBCvLApKYdDF6+PJ95op/dpB6cCp3BkMF/tghKLWj4Bb2 Xz7SStx92S0PT6pW5+6BeM9v3ZakvURfubSo5cp/aPG7Hl/ZJsoCERwCMqRhISZxdn1Y2DAQYRC2z vnBEWa6UZ5EZvRFNU4bItbSKB0b4xDG24vU8cAEp2723eGNt5fhkwQagmVQYMPZdUxr6iTww/8G3H Vvhy4D3svuoaTLT/W+5HzIxFG1wx8J5QLdcPo+McO+O6711+iZezXRyxfMdMZgq5+VcA9iLPRFiMy QvvNvGTymStY6vHYFraQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXdEL-0016jd-PC; Thu, 02 Mar 2023 07:19:57 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXdEH-0016i3-DY for linux-riscv@lists.infradead.org; Thu, 02 Mar 2023 07:19: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 3BA4FB80DF0; Thu, 2 Mar 2023 07:19:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82CCCC433EF; Thu, 2 Mar 2023 07:19:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677741587; bh=x+GFgv/5i/F5V9VZV9k4Y/49cV0Hpjtg26OJcDxewj8=; h=From:To:Cc:Subject:Date:From; b=Mc1t119H+fFTJ5RrU80t7GhKlmv/qjrH+mvhXlveKB67C1AQ4FMzc80kZNoe9oo94 KSa4dFTh8HI/IX/kcGJ2SfvH3QhldduBNyjJR887Ly5uPX32PBNhO9HK/p4P6syoNj nubTohYX8lJvEQI5fslphaa9UE/i4nDfrY1IXIqZ3MsO7ar1ggZDiDv9rDK28HxVHv yTPGisaq68blznooFT3VJdtIYLJuAwXpcUHQPfQM+uYcDi8aeZ7CnZet12hepRajRk GdfGhUKdkHzBuWKr6FY7LOTN7VYiRNRhL+URhyFNhyb6aLsZNdecMY52Jq3CcXc3Z5 0G/lTmkqyvTCQ== 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 v3] lib/test_string.c: Add strncmp() tests Date: Thu, 2 Mar 2023 08:19:34 +0100 Message-Id: <20230302071934.254111-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-20230301_231953_822380_A6CACC2F X-CRM114-Status: GOOD ( 16.57 ) 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. Reported-by: Heiko Stübner Link: https://lore.kernel.org/all/2801162.88bMQJbFj6@diego/ Signed-off-by: Palmer Dabbelt Signed-off-by: Björn Töpel Reviewed-by: Andy Shevchenko --- Change back to it's original form. Checkpatch still complains about __initconst, but there's a patch addressing that [1]. [1] https://lore.kernel.org/all/20230301094320.15954-1-bjorn@kernel.org/ v2->v3: Removed the "checkpatch fix" patch Added one more test v1->v2: Added two more tests (pos/neg). (Andy) Minor code style issues. (Andy) Fixed checkpatch errors. --- lib/test_string.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) base-commit: c0927a7a5391f7d8e593e5e50ead7505a23cadf9 diff --git a/lib/test_string.c b/lib/test_string.c index c5cb92fb710e..f18a34578f1f 100644 --- a/lib/test_string.c +++ b/lib/test_string.c @@ -207,6 +207,43 @@ static __init int strspn_selftest(void) return 0; } +static __init int strncmp_selftest(void) +{ + size_t i; + static const struct strncmp_test { + const char *str_a; + const char *str_b; + unsigned long count; + unsigned long max_off; + int retval; + } tests[] __initconst = { + { "/dev/vda", "/dev/", 5, 4, 0 }, + { "/dev/vda", "/dev/vdb", 5, 4, 0 }, + { "00000000---11111", "00000000---11112", 12, 4, 0 }, + { "/dev/vda", "/dev/vd\0", 8, 0, 97 }, + { "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) { } @@ -245,6 +282,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: