From patchwork Wed Jun 10 18:55:18 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: 1307138 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=jYijOef1; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49hx5R6hWFz9sRN for ; Thu, 11 Jun 2020 04:55:39 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3228E383F851; Wed, 10 Jun 2020 18:55:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3228E383F851 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1591815334; bh=l6pRAWWrhHXeU/fcb48idY+ZQuwLQkaUA/QaK6v78Ds=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=jYijOef1ATZ+vaXxneaMNh/rYJkS/YKXzgXpfCGOeQBxp/eVeyf2f4m/7RWp3b43n xhmuPQJgpKvzc5iBaIGTs4IIhIT3XP6tSd7WRmsOlkUsYwoMnxcdxWrbV0/BVXN6r1 SxZiUkJI/mjhfVobRD/RQNP9FNrpst+CGWtbXyGw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 39F50385DC14 for ; Wed, 10 Jun 2020 18:55:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 39F50385DC14 Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05AIXJiE102830; Wed, 10 Jun 2020 14:55:30 -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 31k026hbqc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jun 2020 14:55:30 -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 05AIf3vP016200; Wed, 10 Jun 2020 18:55:29 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma01wdc.us.ibm.com with ESMTP id 31g2s90bb8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jun 2020 18:55:29 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 05AItRSx9175332 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jun 2020 18:55:27 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6B91DC6059; Wed, 10 Jun 2020 18:55:28 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 04830C6055; Wed, 10 Jun 2020 18:55:27 +0000 (GMT) Received: from localhost (unknown [9.163.20.207]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 10 Jun 2020 18:55:27 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [PATCH v4] string: Adds tests for test-strncasecmp and test-strncpy Date: Wed, 10 Jun 2020 15:55:18 -0300 Message-Id: <20200610185518.15281-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-10_11:2020-06-10, 2020-06-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=1 adultscore=0 clxscore=1011 bulkscore=0 phishscore=0 malwarescore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 cotscore=-2147483648 mlxlogscore=971 spamscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006100139 X-Spam-Status: No, score=-11.6 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: Raphael Moreira Zinsly Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" A couple more changes based on Adhemerval's review, thanks. Changes since v3: - Using a cache line size of 64 if the system doesn't have meaningful information on _SC_LEVEL1_DCACHE_LINESIZE. - Using buf2 instead of a buf1 copy for s2 at string/test-strncasecmp.c. --- >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 | 43 +++++++++++++++++++++++++++++++++++++++ string/test-strncpy.c | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/string/test-strncasecmp.c b/string/test-strncasecmp.c index 6a9c27beae..63f6d59ef2 100644 --- a/string/test-strncasecmp.c +++ b/string/test-strncasecmp.c @@ -137,6 +137,48 @@ 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; + s2 = (char *) buf2; + memset (s1, '\1', offset); + memset (s2, '\1', offset); + s1[offset] = '\0'; + s2[offset] = '\0'; + + /* s2 has a fixed offset, half page long. + page_size is actually 2 * getpagesize. */ + offset = page_size / 4; + s2 += 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); + /* Use 64 as default. */ + if(cacheline_size == 0) + cacheline_size = 64; + 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 +376,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..051257f200 100644 --- a/string/test-strncpy.c +++ b/string/test-strncpy.c @@ -155,6 +155,46 @@ 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); + /* Use 64 as default. */ + if(cacheline_size == 0) + cacheline_size = 64; + 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 +357,7 @@ test_main (void) } do_random_tests (); + do_page_tests (); return ret; }