From patchwork Wed Mar 8 12:48:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wainer dos Santos Moschetta X-Patchwork-Id: 736570 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vdYHd3jS8z9s8S for ; Wed, 8 Mar 2017 23:49:01 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="mP+cOX6A"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=GGXzXLMBVRbOMGbTn69o4gmh/UGxM/H/rzie1lvquUMnWKD3XAdhK 0a+GaHAA3OYntbGgBJbXTiw2+V0Gd66g/ZtXytU7g1lthEPXFTT+X5o56qlidvgO tm4djM63exEakHxPWzmetlrWo/Hg1fKm7ITHYrXM+Ssd4FYytwUSBs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=37x1Qeq0+zZn98vwuDd0a8kli34=; b=mP+cOX6A2zz1BUXIITH+y9Ec9KC/ 42J2AjEMpHp68ci2Ati3mHXkCLi9kyNnCIsD+4Z/x/zNWu9mpCel1zHoeNBCaWIB Nfy+n/MHK/2nyUWJrteekgbx5NPJVylOvw2GVwSwyOnCMfeB+D4RasBsIrfp7rSc 6JBDh4sz+5Ys9ww= Received: (qmail 1279 invoked by alias); 8 Mar 2017 12:48:52 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 1268 invoked by uid 89); 8 Mar 2017 12:48:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=unveil X-HELO: mx0a-001b2d01.pphosted.com From: Wainer dos Santos Moschetta To: libc-alpha@sourceware.org Subject: [PATCH] Add page tests to string/test-strnlen. Date: Wed, 8 Mar 2017 09:48:31 -0300 X-TM-AS-MML: disable x-cbid: 17030812-1523-0000-0000-00000287C73D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17030812-1524-0000-0000-00002A1DDAAF Message-Id: <20170308124831.11648-1-wainersm@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-08_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703080104 May be tricky for implementations to handle strings around page boundary once, for instance, it is performed unaligned loads or when maxlen is used as a hint for vectorized loops. The test cases should unveil regression bugs on these cases. To some extend do_random_tests in string/test-strnlen tests strings placed at page end but it does not cover all cases. So this change adds tests which consists of placing strings of varying sizes ending at the page boundary. It also combines with different values of maxlen. Tested on ppc64le and x86_64. 2017-03-08 Wainer dos Santos Moschetta * string/test-strnlen.c (do_page_tests): New function to check length of strings ending at the page boundary. (test_main): Added call to the do_page_tests function. --- string/test-strnlen.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/string/test-strnlen.c b/string/test-strnlen.c index 7059669..4a6fdd3 100644 --- a/string/test-strnlen.c +++ b/string/test-strnlen.c @@ -143,6 +143,56 @@ do_random_tests (void) } } +/* Tests meant to unveil fail on implementation that does not access bytes + around the page boundary accordingly. */ +static void +do_page_tests (void) +{ + size_t i, exp_len, offset; + /* Calculate the null character offset. */ + size_t last_offset = (page_size / sizeof (CHAR)) - 1; + + CHAR *s = (CHAR *) buf1; + for (i = 0; i < last_offset; i++) + s[i] = (random() & 127) + 1; + s[i] = 0; + + /* Place short strings ending at page boundary. */ + offset = last_offset; + for (i = 0; i < 128; i++) + { + offset--; + exp_len = last_offset - offset; + FOR_EACH_IMPL (impl, 0) + { + /* Varies maxlen value to cover the cases where it is: + - larger than length; + - slightly greater than length; + - equal to length; + - slightly less than length. */ + do_one_test (impl, (CHAR *) (s + offset), page_size, exp_len); + do_one_test (impl, (CHAR *) (s + offset), exp_len + 1, exp_len); + do_one_test (impl, (CHAR *) (s + offset), exp_len, exp_len); + if (exp_len > 0) + do_one_test (impl, (CHAR *) (s + offset), exp_len - 1, exp_len - 1); + } + } + + /* Place long strings ending at page boundary. */ + offset = (last_offset + 1) / 2; + for (i = 0; i < 64; ++i) + { + offset += i; + if (offset >= (last_offset + 1)) + break; + exp_len = last_offset - offset; + FOR_EACH_IMPL (impl, 0) + /* Checks only for maxlen larger than length because other cases are + already covered in do_random_tests. */ + do_one_test (impl, (CHAR *) (s + offset), page_size, exp_len); + } +} + int test_main (void) { @@ -188,6 +238,7 @@ test_main (void) } do_random_tests (); + do_page_tests (); return ret; }