From patchwork Wed Mar 23 21:57:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 52283 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0FD73388883F for ; Wed, 23 Mar 2022 22:09:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0FD73388883F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1648073375; bh=xS6pBgr8C5TR1gvn0W9p3fGAfn3nWzU9nFg7JW+Hr9c=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=GERKONKFSACaUHTkrNJBlN37pdHaG8f9UrF6123EaJTQ5TmVprBeLy62265LncvC7 cmC7oAU/VBcIqRgPwh9emjEidz4EgD3C0Kso3qQvHKIV1Jj1lcRbYZZ9laLVIx4+sh M969NLZBwWe6Tx6ZY16QPtwKWNdEMegxuBfkxyT8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 837EC388703A for ; Wed, 23 Mar 2022 22:01:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 837EC388703A Received: by mail-il1-x12a.google.com with SMTP id n16so1969201ile.11 for ; Wed, 23 Mar 2022 15:01:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xS6pBgr8C5TR1gvn0W9p3fGAfn3nWzU9nFg7JW+Hr9c=; b=FTdPztuLdMvawkR/HNSvG5IobyL7fY9fsZketRbXqkdhgxW861R/CCK2yGNTv2YLxj eN2u86COcum0yj3i0oJcA9+ocAHhkNQhUvF+/QySaeS35kpsKdr9a83Od2WJ17gJsPmy AvrzVgD26O4RZKMeEGsfyI6LIBclJQofOv2cH52TG1fr/oZzxE2CVbpGLBjQsUgsuqqd KqEb+UyUWs+EPWkQXsJ7Qw58dp59dtoQwN/8o2AHk1XXbMG7BaFgIj8QUp1u9Vsij5mR LNcJfW9rdk2qVDAefR9lBqmC/hjN/eRMoxQw/cCKmmSSQXxLX82shkeZcHwzZ8qBciUP y8vg== X-Gm-Message-State: AOAM531aJl1pIA3jdG2R7xCgYs1nc/BSFLz2aTKufQKtwQ0odcd71FxD bFrnCmc49+q9iyxMAH1lp7/i42D+XiY= X-Google-Smtp-Source: ABdhPJykrHxAi6qTCxhyyHTOmQou5yh9DNzNEGau9i01KN9LLf2YVfv1Xl1MXLaynVnv30Ka9pVXWA== X-Received: by 2002:a05:6e02:15ca:b0:2bf:ad58:4a6d with SMTP id q10-20020a056e0215ca00b002bfad584a6dmr1152779ilu.13.1648072874573; Wed, 23 Mar 2022 15:01:14 -0700 (PDT) Received: from localhost.localdomain (node-17-161.flex.volo.net. [76.191.17.161]) by smtp.googlemail.com with ESMTPSA id c22-20020a5ea816000000b00649d360663asm529227ioa.40.2022.03.23.15.01.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 15:01:14 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v1 16/23] string: Expand page cross tests in test-strncasecmp.c Date: Wed, 23 Mar 2022 16:57:34 -0500 Message-Id: <20220323215734.3927131-16-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220323215734.3927131-1-goldstein.w.n@gmail.com> References: <20220323215734.3927131-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Noah Goldstein via Libc-alpha From: Noah Goldstein Reply-To: Noah Goldstein Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Add more robust tests that cover all the page cross edge cases. Reviewed-by: H.J. Lu --- string/test-strncasecmp.c | 166 +++++++++++++++++++++++++++++++++++--- 1 file changed, 154 insertions(+), 12 deletions(-) diff --git a/string/test-strncasecmp.c b/string/test-strncasecmp.c index a3c848165a..b86c630bf6 100644 --- a/string/test-strncasecmp.c +++ b/string/test-strncasecmp.c @@ -18,6 +18,10 @@ #include #include + +#define TEST_LEN (getpagesize () * 3) +#define MIN_PAGE_SIZE (TEST_LEN + 2 * getpagesize ()) + #define TEST_MAIN #define TEST_NAME "strncasecmp" #include "test-string.h" @@ -106,14 +110,15 @@ do_test (size_t align1, size_t align2, size_t n, size_t len, int max_char, if (len == 0) return; - align1 &= 7; - if (align1 + len + 1 >= page_size) + align1 &= getpagesize () - 1; + if (align1 + (len + 2) >= page_size) return; - align2 &= 7; - if (align2 + len + 1 >= page_size) + align2 &= getpagesize () - 1; + if (align2 + (len + 2) >= page_size) return; + s1 = (char *) (buf1 + align1); s2 = (char *) (buf2 + align2); @@ -126,12 +131,33 @@ do_test (size_t align1, size_t align2, size_t n, size_t len, int max_char, s1[len] = s2[len] = 0; s1[len + 1] = 23; s2[len + 1] = 24 + exp_result; + if ((s2[len - 1] == 'z' && exp_result == -1) || (s2[len - 1] == 'a' && exp_result == 1)) s1[len - 1] += exp_result; + else if ((s1[len - 1] == 'Z' + 1 && exp_result == 1) + || (s1[len - 1] == 'A' - 1 && exp_result == -1)) + s1[len - 1] = tolower (s2[len - 1]) + exp_result; else s2[len - 1] -= exp_result; + /* For some locals this is not guranteed yet. */ + if (tolower (s1[len - 1]) - tolower (s2[len - 1]) != exp_result) + { + if (exp_result == -1) + { + s1[len - 1] = tolower ('a'); + s2[len - 1] = toupper (tolower ('a') - 1); + } + else if (exp_result == 0) + s1[len - 1] = toupper (s2[len - 1]); + else + { + s1[len - 1] = tolower ('a'); + s2[len - 1] = toupper (tolower ('a') + 1); + } + } + FOR_EACH_IMPL (impl, 0) do_one_test (impl, s1, s2, n, exp_result); } @@ -299,10 +325,10 @@ bz14195 (void) } static void -test_locale (const char *locale) +test_locale (const char *locale, int extra_tests) { - size_t i; - + size_t i, j, k; + const size_t test_len = MIN(TEST_LEN, 3 * 4096); if (setlocale (LC_CTYPE, locale) == NULL) { error (0, 0, "cannot set locale \"%s\"", locale); @@ -374,6 +400,122 @@ test_locale (const char *locale) do_test (2 * i, i, (8 << i) + 100, 8 << i, 254, -1); } + for (j = 0; extra_tests && j < 160; ++j) + { + for (i = 0; i < test_len;) + { + do_test (getpagesize () - j - 1, 0, i + 1, i, 127, 0); + do_test (getpagesize () - j - 1, 0, i + 1, i, 127, 1); + do_test (getpagesize () - j - 1, 0, i + 1, i, 127, -1); + + do_test (getpagesize () - j - 1, 0, i, i, 127, 0); + do_test (getpagesize () - j - 1, 0, i - 1, i, 127, 0); + + do_test (getpagesize () - j - 1, 0, ULONG_MAX, i, 127, 0); + do_test (getpagesize () - j - 1, 0, ULONG_MAX, i, 127, 1); + do_test (getpagesize () - j - 1, 0, ULONG_MAX, i, 127, -1); + + do_test (getpagesize () - j - 1, 0, ULONG_MAX - i, i, 127, 0); + do_test (getpagesize () - j - 1, 0, ULONG_MAX - i, i, 127, 1); + do_test (getpagesize () - j - 1, 0, ULONG_MAX - i, i, 127, -1); + + do_test (getpagesize () - j - 1, j, i + 1, i, 127, 0); + do_test (getpagesize () - j - 1, j, i + 1, i, 127, 1); + do_test (getpagesize () - j - 1, j, i + 1, i, 127, -1); + + do_test (getpagesize () - j - 1, j, i, i, 127, 0); + do_test (getpagesize () - j - 1, j, i - 1, i, 127, 0); + + do_test (getpagesize () - j - 1, j, ULONG_MAX, i, 127, 0); + do_test (getpagesize () - j - 1, j, ULONG_MAX, i, 127, 1); + do_test (getpagesize () - j - 1, j, ULONG_MAX, i, 127, -1); + + do_test (getpagesize () - j - 1, j, ULONG_MAX - i, i, 127, 0); + do_test (getpagesize () - j - 1, j, ULONG_MAX - i, i, 127, 1); + do_test (getpagesize () - j - 1, j, ULONG_MAX - i, i, 127, -1); + + do_test (0, getpagesize () - j - 1, i + 1, i, 127, 0); + do_test (0, getpagesize () - j - 1, i + 1, i, 127, 1); + do_test (0, getpagesize () - j - 1, i + 1, i, 127, -1); + + do_test (0, getpagesize () - j - 1, i, i, 127, 0); + do_test (0, getpagesize () - j - 1, i - 1, i, 127, 0); + + do_test (0, getpagesize () - j - 1, ULONG_MAX, i, 127, 0); + do_test (0, getpagesize () - j - 1, ULONG_MAX, i, 127, 1); + do_test (0, getpagesize () - j - 1, ULONG_MAX, i, 127, -1); + + do_test (0, getpagesize () - j - 1, ULONG_MAX - i, i, 127, 0); + do_test (0, getpagesize () - j - 1, ULONG_MAX - i, i, 127, 1); + do_test (0, getpagesize () - j - 1, ULONG_MAX - i, i, 127, -1); + + do_test (j, getpagesize () - j - 1, i + 1, i, 127, 0); + do_test (j, getpagesize () - j - 1, i + 1, i, 127, 1); + do_test (j, getpagesize () - j - 1, i + 1, i, 127, -1); + + do_test (j, getpagesize () - j - 1, i, i, 127, 0); + do_test (j, getpagesize () - j - 1, i - 1, i, 127, 0); + + do_test (j, getpagesize () - j - 1, ULONG_MAX, i, 127, 0); + do_test (j, getpagesize () - j - 1, ULONG_MAX, i, 127, 1); + do_test (j, getpagesize () - j - 1, ULONG_MAX, i, 127, -1); + + do_test (j, getpagesize () - j - 1, ULONG_MAX - i, i, 127, 0); + do_test (j, getpagesize () - j - 1, ULONG_MAX - i, i, 127, 1); + do_test (j, getpagesize () - j - 1, ULONG_MAX - i, i, 127, -1); + + for (k = 2; k <= 128; k += k) + { + do_test (getpagesize () - k, getpagesize () - j - 1, i - 1, i, + 127, 0); + do_test (getpagesize () - k - 1, getpagesize () - j - 1, i - 1, + i, 127, 0); + do_test (getpagesize () - k, getpagesize () - j - 1, i + 1, i, + 127, 0); + do_test (getpagesize () - k - 1, getpagesize () - j - 1, i + 1, + i, 127, 0); + do_test (getpagesize () - k, getpagesize () - j - 1, i, i, 127, + 0); + do_test (getpagesize () - k - 1, getpagesize () - j - 1, i, i, + 127, 0); + do_test (getpagesize () - k, getpagesize () - j - 1, i + 1, i, + 127, -1); + do_test (getpagesize () - k - 1, getpagesize () - j - 1, i + 1, + i, 127, -1); + do_test (getpagesize () - k, getpagesize () - j - 1, i + 1, i, + 127, 1); + do_test (getpagesize () - k - 1, getpagesize () - j - 1, i + 1, + i, 127, 1); + } + if (i < 32) + { + i += 1; + } + else if (i < 161) + { + i += 7; + } + else if (i + 161 < test_len) + { + i += 31; + i *= 17; + i /= 16; + if (i + 161 > test_len) + { + i = test_len - 160; + } + } + else if (i + 32 < test_len) + { + i += 7; + } + else + { + i += 1; + } + } + } + do_random_tests (); do_page_tests (); } @@ -383,11 +525,11 @@ test_main (void) { test_init (); - test_locale ("C"); - test_locale ("en_US.ISO-8859-1"); - test_locale ("en_US.UTF-8"); - test_locale ("tr_TR.ISO-8859-9"); - test_locale ("tr_TR.UTF-8"); + test_locale ("C", 1); + test_locale ("en_US.ISO-8859-1", 0); + test_locale ("en_US.UTF-8", 0); + test_locale ("tr_TR.ISO-8859-9", 0); + test_locale ("tr_TR.UTF-8", 0); return ret; }