From patchwork Wed Sep 11 10:15:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 19955 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f69.google.com (mail-yh0-f69.google.com [209.85.213.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3D84E248D9 for ; Wed, 11 Sep 2013 10:15:35 +0000 (UTC) Received: by mail-yh0-f69.google.com with SMTP id c41sf7436311yho.4 for ; Wed, 11 Sep 2013 03:15:35 -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=F7/O9XBGVWAVi2whDYtcu79tnXQt9J8KRmKkCxeUIHg=; b=kOBRXIe66B5PesM0aowztjaZSM1bqaHKfYRZkFBhxZuh/biCAiQoUcQJ3//dVhaVjq V7jOSMCilCoH+A0IJs9+X0GTtdrNyxOuVJwFULwnNTirhrp7cYbsmJlvXRdbxJ4o3K54 TOvlckvtGAjsA9Z12ih/LYGKTV3gZoE2am3u6v79Gh8NeF5M1aUV2fBowONby4RdFAr1 Qbj8B7fAoC/bMMyoBNjgA7Ts5TjmDT/uBvCPZRyG5UdBSq2y4toZWhfSANuMF3VDrdAi Rl5GRJdXfIYC2h7fNBN/kxMWta2eYwv+l/zWJUbFY2Q46OeWtLIhw6dCPzXbVMMgJX1O sUag== X-Received: by 10.236.54.68 with SMTP id h44mr315159yhc.21.1378894535043; Wed, 11 Sep 2013 03:15:35 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.51.40 with SMTP id h8ls183744qeo.28.gmail; Wed, 11 Sep 2013 03:15:34 -0700 (PDT) X-Received: by 10.220.164.202 with SMTP id f10mr499209vcy.25.1378894534817; Wed, 11 Sep 2013 03:15:34 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id 10si5778274vcr.78.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Sep 2013 03:15:34 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id gf11so5750438vcb.25 for ; Wed, 11 Sep 2013 03:15:34 -0700 (PDT) X-Gm-Message-State: ALoCoQmz/cD8ib2awLjfUJ0OHjLqzit/OcDKFTWNa6T0fmEMTqOxhyfeVvgNaAwT3/eXJKioLoAv X-Received: by 10.220.181.136 with SMTP id by8mr514049vcb.11.1378894534673; Wed, 11 Sep 2013 03:15:34 -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 u4csp47776vcz; Wed, 11 Sep 2013 03:15:34 -0700 (PDT) X-Received: by 10.204.224.142 with SMTP id io14mr623378bkb.27.1378894533567; Wed, 11 Sep 2013 03:15:33 -0700 (PDT) Received: from mail-bk0-f45.google.com (mail-bk0-f45.google.com [209.85.214.45]) by mx.google.com with ESMTPS id qk9si2676800bkb.323.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Sep 2013 03:15:33 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.214.45 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=209.85.214.45; Received: by mail-bk0-f45.google.com with SMTP id mx11so3426520bkb.4 for ; Wed, 11 Sep 2013 03:15:33 -0700 (PDT) X-Received: by 10.205.10.200 with SMTP id pb8mr665387bkb.16.1378894532861; Wed, 11 Sep 2013 03:15:32 -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 qe6sm7112544bkb.5.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 11 Sep 2013 03:15:32 -0700 (PDT) Message-ID: <523042C2.5010805@linaro.org> Date: Wed, 11 Sep 2013 11:15:30 +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: Add pvalloc test. 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.220.180 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-16 Will Newton * malloc/Makefile: Add tst-pvalloc. * malloc/tst-pvalloc.c: New file. --- malloc/Makefile | 3 +- malloc/tst-pvalloc.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 malloc/tst-pvalloc.c Changes in v2: - Check errno for -pagesize failure case diff --git a/malloc/Makefile b/malloc/Makefile index 4903c13..17d146b 100644 --- a/malloc/Makefile +++ b/malloc/Makefile @@ -26,7 +26,8 @@ dist-headers := malloc.h headers := $(dist-headers) obstack.h mcheck.h tests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \ tst-mallocstate tst-mcheck tst-mallocfork tst-trim1 \ - tst-malloc-usable tst-realloc tst-posix_memalign + tst-malloc-usable tst-realloc tst-posix_memalign \ + tst-pvalloc test-srcs = tst-mtrace routines = malloc morecore mcheck mtrace obstack diff --git a/malloc/tst-pvalloc.c b/malloc/tst-pvalloc.c new file mode 100644 index 0000000..1126672 --- /dev/null +++ b/malloc/tst-pvalloc.c @@ -0,0 +1,91 @@ +/* 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 + +static int errors = 0; + +static void +merror (const char *msg) +{ + ++errors; + printf ("Error: %s\n", msg); +} + +static int +do_test (void) +{ + void *p; + unsigned long pagesize = getpagesize(); + unsigned long ptrval; + int save; + + errno = 0; + + p = pvalloc (-1); + + save = errno; + + if (p != NULL) + merror ("pvalloc (-1) succeeded."); + + if (p == NULL && save != ENOMEM) + merror ("pvalloc (-1) errno is not set correctly"); + + errno = 0; + + p = pvalloc (-pagesize); + + save = errno; + + if (p != NULL) + merror ("pvalloc (-pagesize) succeeded."); + + if (p == NULL && save != ENOMEM) + merror ("pvalloc (-pagesize) errno is not set correctly"); + + p = pvalloc (0); + + if (p == NULL) + merror ("pvalloc (0) failed."); + + free (p); + + p = pvalloc (32); + + if (p == NULL) + merror ("pvalloc (32) failed."); + + ptrval = (unsigned long)p; + + if (p == NULL) + merror ("pvalloc (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"