From patchwork Wed Jun 3 20:06:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael M Zinsly X-Patchwork-Id: 39469 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 CEECC388E837; Wed, 3 Jun 2020 20:07:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CEECC388E837 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1591214827; bh=Ee7a2BpX5c3UOltbo0cY4y13pb86SO5QjDfvcG6pztQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=vCG0FMjVcqcRoH13SYKr+j7BQ+tnc5zpIcoHt247J2/xM9/GYJUCb30X1dk3MYhwj aWZbytyISdCcl3NePBM7C731bdOfL6EceBCpJbbjprB8dT+I4exqBy8Iw29dTd5qQ8 GAyCY698e3/Cqv/cTXb++BCcHupXyuGcJ3QjyESg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id CF755388C032 for ; Wed, 3 Jun 2020 20:07:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CF755388C032 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 053K38kN061358 for ; Wed, 3 Jun 2020 16:07:03 -0400 Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com with ESMTP id 31dr0jrpxg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 03 Jun 2020 16:07:02 -0400 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 053K6BxN027383 for ; Wed, 3 Jun 2020 20:07:02 GMT Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by ppma03dal.us.ibm.com with ESMTP id 31bf4a2v11-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 03 Jun 2020 20:07:02 +0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 053K719t53215490 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 3 Jun 2020 20:07:01 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 432BC112067; Wed, 3 Jun 2020 20:07:01 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AF869112061; Wed, 3 Jun 2020 20:07:00 +0000 (GMT) Received: from localhost (unknown [9.163.0.53]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 3 Jun 2020 20:07:00 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [PATCH v2] string: Add page tests for test-strncasecmp and test-strncpy Date: Wed, 3 Jun 2020 17:06:45 -0300 Message-Id: <20200603200645.478668-1-rzinsly@linux.ibm.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-06-03_13:2020-06-02, 2020-06-03 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxscore=0 bulkscore=0 adultscore=0 impostorscore=0 cotscore=-2147483648 phishscore=0 mlxlogscore=831 spamscore=0 priorityscore=1501 suspectscore=1 lowpriorityscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006030150 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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: Raphael Moreira Zinsly via Libc-alpha From: Raphael M Zinsly Reply-To: Raphael Moreira Zinsly Cc: pc@us.ibm.com, Raphael Moreira Zinsly Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Adds tests to check if strings placed at page bondaries are handled correctly by strncasecmp and strncpy similar to tests for strncmp and strnlen. This should catch regressions in the optmized functions. --- string/test-strncasecmp.c | 37 +++++++++++++++++++++++++++++++++++++ string/test-strncpy.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/string/test-strncasecmp.c b/string/test-strncasecmp.c index 6a9c27beae..bf9838dacb 100644 --- a/string/test-strncasecmp.c +++ b/string/test-strncasecmp.c @@ -137,6 +137,42 @@ do_test (size_t align1, size_t align2, size_t n, size_t len, int max_char, do_one_test (impl, s1, s2, n, exp_result); } +static void +do_page_tests (void) +{ + size_t i, offset, cacheline_size; + char *s1, *s2; + int exp_result; + + offset = page_size - 1; + s1 = (char *) buf1; + memset (s1, '\1', offset); + s1[offset] = '\0'; + + /* s2 has a fixed offset, almost one page long. + page_size is actually 2 * getpagesize. */ + offset = (page_size / 2) - 10; + s2 = strdup (s1) + offset; + /* Start offset for s1. */ + offset = 3 * page_size / 4; + s1 += offset; + + /* Try to cross the page boundary at every offset of a cache line. */ + cacheline_size = sysconf (_SC_LEVEL1_DCACHE_LINESIZE); + for (i = 0; i < cacheline_size; ++i) + { + exp_result = *s1; + + FOR_EACH_IMPL (impl, 0) + { + check_result (impl, s1, s2, page_size, -exp_result); + check_result (impl, s2, s1, page_size, exp_result); + } + + s1++; + } +} + static void do_random_tests (void) { @@ -334,6 +370,7 @@ test_locale (const char *locale) } do_random_tests (); + do_page_tests (); } int diff --git a/string/test-strncpy.c b/string/test-strncpy.c index c978753ad8..fb3332cbac 100644 --- a/string/test-strncpy.c +++ b/string/test-strncpy.c @@ -155,6 +155,40 @@ do_test (size_t align1, size_t align2, size_t len, size_t n, int max_char) do_one_test (impl, s2, s1, len, n); } +static void +do_page_tests (void) +{ + size_t i, small_len, big_len, short_offset, long_offset; + CHAR *s1, *s2; + /* Calculate the null character offset. */ + size_t last_offset = (page_size / sizeof (CHAR)) - 1; + + s2 = (CHAR *) buf1; + s1 = (CHAR *) buf2; + MEMSET (s1, '\1', last_offset); + s1[last_offset] = '\0'; + + long_offset = (last_offset + 1) / 2; + short_offset = last_offset; + for (i = 0; i < 128; i++) + { + /* Place long strings ending at page boundary. */ + long_offset++; + big_len = last_offset - long_offset; + /* Place short strings ending at page boundary. */ + short_offset--; + small_len = last_offset - short_offset; + + FOR_EACH_IMPL (impl, 0) + { + do_one_test (impl, s2, (CHAR *) (s1 + short_offset), small_len, + small_len); + do_one_test (impl, s2, (CHAR *) (s1 + long_offset), page_size, + big_len); + } + } +} + static void do_random_tests (void) { @@ -317,6 +351,7 @@ test_main (void) } do_random_tests (); + do_page_tests (); return ret; }