From patchwork Wed Sep 11 10:15:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 19956 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f200.google.com (mail-vc0-f200.google.com [209.85.220.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A95B4248D9 for ; Wed, 11 Sep 2013 10:15:44 +0000 (UTC) Received: by mail-vc0-f200.google.com with SMTP id hf12sf10127640vcb.7 for ; Wed, 11 Sep 2013 03:15:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:user-agent :mime-version:to:cc:subject:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=7pzeThedbG/gdEPuKpQLYBMqmREvleBhevsjb5eRd5U=; b=kDd1QIZSEyFrV22IC/EbIV7ZV9aq37D34PWFmTxCJ1DzitktkCUhqY6V3f6vYJfRY1 bMXl0U9ohYVzLPY5knJ9RSKnwfQK7Eo4CP5KE1dwBe31rEQzAIZaY35EuTUBGSzcjtQo 7+/xeLkDDZm7x/yKUHRiVOB+oQ9mUn+AqNvteiZHbjQc5YFUjZhjqjUx/alJzkmQ8Rm8 +VobskDezdO7BdO2UDWqLygOV0FxzG1l3qNqbNvbXxTwXth7rTqVU2akNlxGr8UlarxA 5pZ5v/790GlHICqNdFeN4z/rzFM1uG+IQE8AjCEi1jScBWq8DtEprKb/BPyKwp5CdmSR 0aww== X-Received: by 10.236.115.198 with SMTP id e46mr342268yhh.33.1378894544521; Wed, 11 Sep 2013 03:15:44 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.6.73 with SMTP id y9ls177591qey.60.gmail; Wed, 11 Sep 2013 03:15:44 -0700 (PDT) X-Received: by 10.52.230.74 with SMTP id sw10mr431762vdc.6.1378894544263; Wed, 11 Sep 2013 03:15:44 -0700 (PDT) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by mx.google.com with ESMTPS id st7si5019303vdc.94.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Sep 2013 03:15:44 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.182; Received: by mail-ve0-f182.google.com with SMTP id oy12so5632013veb.13 for ; Wed, 11 Sep 2013 03:15:44 -0700 (PDT) X-Gm-Message-State: ALoCoQma7avhfIv0uPDyLux4eMoKZYTc+LLerl1cDafTWUvWTVbcuuK5Mfg5pAnS0fT4rW6mvV2H X-Received: by 10.52.116.74 with SMTP id ju10mr449469vdb.20.1378894544146; Wed, 11 Sep 2013 03:15:44 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp47781vcz; Wed, 11 Sep 2013 03:15:43 -0700 (PDT) X-Received: by 10.204.66.133 with SMTP id n5mr657522bki.38.1378894543085; Wed, 11 Sep 2013 03:15:43 -0700 (PDT) Received: from mail-bk0-f48.google.com (mail-bk0-f48.google.com [209.85.214.48]) by mx.google.com with ESMTPS id at5si2686133bkc.8.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Sep 2013 03:15:43 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.214.48 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=209.85.214.48; Received: by mail-bk0-f48.google.com with SMTP id my13so3425991bkb.21 for ; Wed, 11 Sep 2013 03:15:42 -0700 (PDT) X-Received: by 10.204.232.207 with SMTP id jv15mr630244bkb.39.1378894542318; Wed, 11 Sep 2013 03:15:42 -0700 (PDT) Received: from localhost.localdomain (cpc6-seac21-2-0-cust453.7-2.cable.virginmedia.com. [82.1.113.198]) by mx.google.com with ESMTPSA id pk7sm7111450bkb.2.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 11 Sep 2013 03:15:41 -0700 (PDT) Message-ID: <523042CC.5010305@linaro.org> Date: Wed, 11 Sep 2013 11:15:40 +0100 From: Will Newton User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130805 Thunderbird/17.0.8 MIME-Version: 1.0 To: libc-alpha@sourceware.org CC: patches@linaro.org Subject: [PATCH v2] malloc/tst-valloc.c: Improve test coverage and use test-skeleton.c. X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: will.newton@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , ChangeLog: 2013-08-12 Will Newton * malloc/tst-valloc.c: Rewrite to use test-skeleton.c and improve test coverage. --- malloc/tst-valloc.c | 100 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 84 insertions(+), 16 deletions(-) Changes in v2: - Check errno for -pagesize failure case diff --git a/malloc/tst-valloc.c b/malloc/tst-valloc.c index 643a0dd..3648f2f 100644 --- a/malloc/tst-valloc.c +++ b/malloc/tst-valloc.c @@ -1,23 +1,91 @@ -/* Test case by Stephen Tweedie . */ -#include -#include +/* Copyright (C) 2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include #include +#include +#include +#include -int -main (void) +static int errors = 0; + +static void +merror (const char *msg) +{ + ++errors; + printf ("Error: %s\n", msg); +} + +static int +do_test (void) { - char *p; - int pagesize = getpagesize (); - int i; + void *p; + unsigned long pagesize = getpagesize(); + unsigned long ptrval; + int save; + + errno = 0; + + p = valloc (-1); + + save = errno; - p = valloc (pagesize); - i = (long int) p; + if (p != NULL) + merror ("valloc (-1) succeeded."); - if ((i & (pagesize-1)) != 0) - { - fprintf (stderr, "Alignment problem: valloc returns %p\n", p); - exit (1); - } + if (p == NULL && save != ENOMEM) + merror ("valloc (-1) errno is not set correctly"); - return 0; + errno = 0; + + p = valloc (-pagesize); + + save = errno; + + if (p != NULL) + merror ("valloc (-pagesize) succeeded."); + + if (p == NULL && save != ENOMEM) + merror ("valloc (-pagesize) errno is not set correctly"); + + p = valloc (0); + + if (p == NULL) + merror ("valloc (0) failed."); + + free (p); + + p = valloc (32); + + if (p == NULL) + merror ("valloc (32) failed."); + + ptrval = (unsigned long)p; + + if (p == NULL) + merror ("valloc (32) failed."); + + if ((ptrval & (pagesize - 1)) != 0) + merror ("returned pointer is not page aligned."); + + free (p); + + return errors != 0; } + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c"