From patchwork Thu May 27 23:34:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil Pandey X-Patchwork-Id: 43622 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 BFC00385381F; Thu, 27 May 2021 23:34:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BFC00385381F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1622158494; bh=rLH9zj/ZwjHVe5N98lgEwK8DpKOYgAe0pClkzVhnw4M=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=nqPrfvZR3jQED2qPDyAYADhycAdmjMXWYamIFoo25jJ7vupxdd8MgS99JY6YhsW0j 1r+KKmcj2mvrW/mlpiq7AQLoIPWOUqdGUkJJtxjgE8ynT7fuChJS1goPs9EI+WrYw1 KYPq2+5Tm5h7CVqeUtA589HSEBS2pmLehfv1h/ic= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by sourceware.org (Postfix) with ESMTPS id 8AE9F3853805 for ; Thu, 27 May 2021 23:34:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8AE9F3853805 IronPort-SDR: mme+hK+uMNl+/9gxBB3Pc/r3I99/bpKLjdW0PndM7rrlRjZGyKz82J+K4Kn9kGlSWUbV9O14M4 JHNeG6E9escw== X-IronPort-AV: E=McAfee;i="6200,9189,9997"; a="182516709" X-IronPort-AV: E=Sophos;i="5.83,228,1616482800"; d="scan'208";a="182516709" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2021 16:34:46 -0700 IronPort-SDR: HIbdykOfKNzQHHs4JFT7bHHeihm4uZdGpKqFFeUCaSakkEIJVlqduSpXLtvvKjJufcaS86qmYv /OhRz645fI7w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,228,1616482800"; d="scan'208";a="465587513" Received: from scymds01.sc.intel.com ([10.148.94.138]) by fmsmga004.fm.intel.com with ESMTP; 27 May 2021 16:34:46 -0700 Received: from gskx-1.sc.intel.com (gskx-1.sc.intel.com [172.25.149.211]) by scymds01.sc.intel.com with ESMTP id 14RNYieL032561; Thu, 27 May 2021 16:34:44 -0700 To: libc-alpha@sourceware.org Subject: [PATCH] Improve test coverage of strlen function Date: Thu, 27 May 2021 16:34:44 -0700 Message-Id: <20210527233444.3492534-1-skpgkp2@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, HK_RANDOM_ENVFROM, HK_RANDOM_FROM, KAM_DMARC_NONE, KAM_DMARC_STATUS, NML_ADSP_CUSTOM_MED, SPF_HELO_PASS, SPF_SOFTFAIL, SPOOFED_FREEMAIL, SPOOF_GMAIL_MID, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Sunil K Pandey via Libc-alpha From: Sunil Pandey Reply-To: Sunil K Pandey Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" This patch covers following test condition. - String starts with different alignment and ends at the page boundary with less than 32 byte length. - String starts with different alignment and cross page boundary with 31 byte fixed length. --- string/test-strlen.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/string/test-strlen.c b/string/test-strlen.c index 6e67d1f1f1..5f4ce9eafd 100644 --- a/string/test-strlen.c +++ b/string/test-strlen.c @@ -132,6 +132,51 @@ do_random_tests (void) } } +/* Test page cross boundary logic but string stay on same page. String + start position and length both change. */ + +static void +do_test2 (void) +{ + size_t i; + + CHAR *buf = (CHAR *) (buf1 + page_size - 32); + + size_t maxlength = 32 / sizeof (CHAR) - 1; + buf[maxlength] = 0; + + for (size_t pos = 0; pos < maxlength - 1; pos++) + { + for (i = pos; i < maxlength; i++) + buf[i] = 1 + 11111 * i % MAX_CHAR; + + FOR_EACH_IMPL (impl, 0) + do_one_test (impl, (CHAR *) (buf + pos), maxlength - pos); + } +} + +/* Test page cross boundary logic and string do cross the page. String + start position get adjusted but length remains constant. */ + +static void +do_test3 (void) +{ + size_t i; + + CHAR *buf = (CHAR *) (buf1 + getpagesize() - 32); + + size_t maxlength = 32 / sizeof (CHAR) - 1; + + for (size_t pos = 0; pos < maxlength; pos++) + { + for (i = pos; i < pos + maxlength; i++) + buf[i] = 1 + 11111 * i % MAX_CHAR; + buf[i] = 0; + FOR_EACH_IMPL (impl, 0) + do_one_test (impl, (CHAR *) (buf + pos), maxlength); + } +} + int test_main (void) { @@ -161,6 +206,8 @@ test_main (void) } do_random_tests (); + do_test2 (); + do_test3 (); return ret; }