From patchwork Mon Jun 8 14:17:00 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: 39516 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 A6F3F3851C1E; Mon, 8 Jun 2020 14:17:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6F3F3851C1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1591625831; bh=Pb0exoZ6/PHrHZ0ukFtm3TLPZnyADhdCoVbbpUq5Xvk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=HD1j3cREMc3RJkS8MrpiSTekMMyvROfZ8h5dxcQ1ddz6GmsIRJnbuVOAWC3p98kCa J6zB0MAnukyDPcChqoWSHI6xdyGj6gJcmKmaCDFgCkffnaZWSMCGq1Sg0mUoABqPs0 jmxhON/HLn656nNhJXCWAku6SVNGl7023N+aV2gU= 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 D765E3851C12 for ; Mon, 8 Jun 2020 14:17:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D765E3851C12 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 058E2ms2044327 for ; Mon, 8 Jun 2020 10:17:08 -0400 Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com with ESMTP id 31geq70kv9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 08 Jun 2020 10:17:07 -0400 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 058EEm3F001357 for ; Mon, 8 Jun 2020 14:17:06 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma01wdc.us.ibm.com with ESMTP id 31g2s8khdv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 08 Jun 2020 14:17:06 +0000 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 058EH5am20644304 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 8 Jun 2020 14:17:05 GMT Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 50353BE053; Mon, 8 Jun 2020 14:17:05 +0000 (GMT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD135BE04F; Mon, 8 Jun 2020 14:17:04 +0000 (GMT) Received: from localhost (unknown [9.163.8.88]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Mon, 8 Jun 2020 14:17:04 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [PATCH v3] string: Adds tests for test-strncasecmp and test-strncpy Date: Mon, 8 Jun 2020 11:17:00 -0300 Message-Id: <20200608141700.9485-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-08_12:2020-06-08, 2020-06-08 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 spamscore=0 impostorscore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 suspectscore=1 mlxlogscore=787 cotscore=-2147483648 phishscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006080100 X-Spam-Status: No, score=-11.7 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" Changes since v2: string/test-strncasecmp.c - Offset of s2 is now at half of a page. - Described the offset of s1 in the comment. string/test-strncpy.c - Queries for the cache line size and added a comment. --- >8 --- Adds tests to check if strings placed at page bondaries are handled correctly by strncasecmp and strncpy similar to tests for strncmp and strnlen. --- string/test-strncasecmp.c | 37 +++++++++++++++++++++++++++++++++++++ string/test-strncpy.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/string/test-strncasecmp.c b/string/test-strncasecmp.c index 6a9c27beae..508441f7e1 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, half page long. + page_size is actually 2 * getpagesize. */ + offset = page_size / 4; + s2 = strdup (s1) + offset; + /* Start offset for s1 at half of the second page. */ + 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..ba46670546 100644 --- a/string/test-strncpy.c +++ b/string/test-strncpy.c @@ -155,6 +155,43 @@ 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, cacheline_size; + 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; + + /* 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++) + { + /* 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 +354,7 @@ test_main (void) } do_random_tests (); + do_page_tests (); return ret; }