From patchwork Fri Oct 21 06:03:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Willy Tarreau X-Patchwork-Id: 6521 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp510917wrr; Thu, 20 Oct 2022 23:05:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4UD/wxDRvn15LNJWBbcYG6VAuU3pl17etYWxwCTPmC032mSABmw3gHjx5r+Cv1JM+DkJy7 X-Received: by 2002:a05:6402:51d0:b0:45d:5ba4:c3d2 with SMTP id r16-20020a05640251d000b0045d5ba4c3d2mr15753554edd.132.1666332331840; Thu, 20 Oct 2022 23:05:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666332331; cv=none; d=google.com; s=arc-20160816; b=ruEaUjn6jisR5OPPTz59iJINat2rDNMbA7CexwnpSKOd2kAX8gBnjK0pLAenyB2DMl nM2Fq+bjgnBv24QoSHxVVc31SOBMq+BJmYCpRPRrwueLV4mqHoRrTiVFWJc/7rD3N/VM m0zmiUR9DoPSTGz6Sl7wQkCN9AR411h3xHMj3UOmeXqoLaA/H4ADfMED+nKR1dkRVRaC elaq0HGZXyc8WmrWz3dD65boTrFeNnkeiCRNJ4jl+XGjPO52z3Z0h2lrLHp+3HdqgzZc F01OnV6pke414N0Wt8oNXRih8NiOMBSiOoRmFvtP4zYUFUDxatp8YJmun7WBUrMR/nOY WHzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=mmWwhB//0OihH0AdNFpfSU1VgaDHwTHK0QwuSbroabc=; b=YnGJp9LbqWAqncG/g3syAitCF46kU2LFDRjWhyC/u5ptwJou8w6BDSHLzx7lm0/Ucu xZr19mw8UjwwrnnXhCSxscenvPb4JHlF4MkQMBdJW5PUNFoMUHYe8qsZFJTxv7nDQ0BD b1qN7dxtyd764OPImrIo+vxXXlQFq4i80sLZZozdKsoaSZFvnb59Icf9hrNpup6tUjjP 7Z3j6RWODj7rBWl3A2Wj6MqjvhvIyHXAluQReL910BxzuWNHon+7Jg3gp7Oso8T9wigH 8YP8bYpL4g3E6Js920qMjZqFrNYMlb61EXiojDIFe6HWF7yNZTxaKwSaazVQR5JXS73U ckAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y3-20020a50bb03000000b0046013b7e7efsi3774887ede.631.2022.10.20.23.05.07; Thu, 20 Oct 2022 23:05:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229959AbiJUGEH (ORCPT + 99 others); Fri, 21 Oct 2022 02:04:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230055AbiJUGD6 (ORCPT ); Fri, 21 Oct 2022 02:03:58 -0400 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4978D4521E; Thu, 20 Oct 2022 23:03:56 -0700 (PDT) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 29L63lSF007564; Fri, 21 Oct 2022 08:03:47 +0200 From: Willy Tarreau To: "Paul E. McKenney" Cc: Rasmus Villemoes , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH] selftests/nolibc: add 7 tests for memcmp() Date: Fri, 21 Oct 2022 08:03:40 +0200 Message-Id: <20221021060340.7515-1-w@1wt.eu> X-Mailer: git-send-email 2.17.5 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747276091243376598?= X-GMAIL-MSGID: =?utf-8?q?1747276091243376598?= This adds 7 combinations of input values for memcmp() using signed and unsigned bytes, which will trigger on the original code before Rasmus' fix. This is mostly aimed at helping backporters verify their work, and showing how tests for corner cases can be added to the selftests suite. Before the fix it reports: 12 memcmp_20_20 = 0 [OK] 13 memcmp_20_60 = -64 [OK] 14 memcmp_60_20 = 64 [OK] 15 memcmp_20_e0 = 64 [FAIL] 16 memcmp_e0_20 = -64 [FAIL] 17 memcmp_80_e0 = -96 [OK] 18 memcmp_e0_80 = 96 [OK] And after: 12 memcmp_20_20 = 0 [OK] 13 memcmp_20_60 = -64 [OK] 14 memcmp_60_20 = 64 [OK] 15 memcmp_20_e0 = -192 [OK] 16 memcmp_e0_20 = 192 [OK] 17 memcmp_80_e0 = -96 [OK] 18 memcmp_e0_80 = 96 [OK] Cc: Rasmus Villemoes Signed-off-by: Willy Tarreau --- tools/testing/selftests/nolibc/nolibc-test.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 78bced95ac63..f14f5076fb6d 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -565,6 +565,13 @@ int run_stdlib(int min, int max) CASE_TEST(strchr_foobar_z); EXPECT_STRZR(1, strchr("foobar", 'z')); break; CASE_TEST(strrchr_foobar_o); EXPECT_STREQ(1, strrchr("foobar", 'o'), "obar"); break; CASE_TEST(strrchr_foobar_z); EXPECT_STRZR(1, strrchr("foobar", 'z')); break; + CASE_TEST(memcmp_20_20); EXPECT_EQ(1, memcmp("aaa\x20", "aaa\x20", 4), 0); break; + CASE_TEST(memcmp_20_60); EXPECT_LT(1, memcmp("aaa\x20", "aaa\x60", 4), 0); break; + CASE_TEST(memcmp_60_20); EXPECT_GT(1, memcmp("aaa\x60", "aaa\x20", 4), 0); break; + CASE_TEST(memcmp_20_e0); EXPECT_LT(1, memcmp("aaa\x20", "aaa\xe0", 4), 0); break; + CASE_TEST(memcmp_e0_20); EXPECT_GT(1, memcmp("aaa\xe0", "aaa\x20", 4), 0); break; + CASE_TEST(memcmp_80_e0); EXPECT_LT(1, memcmp("aaa\x80", "aaa\xe0", 4), 0); break; + CASE_TEST(memcmp_e0_80); EXPECT_GT(1, memcmp("aaa\xe0", "aaa\x80", 4), 0); break; case __LINE__: return ret; /* must be last */ /* note: do not set any defaults so as to permit holes above */