From patchwork Wed Sep 11 10:15:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 19954 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f72.google.com (mail-qe0-f72.google.com [209.85.128.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E09F3248D9 for ; Wed, 11 Sep 2013 10:15:28 +0000 (UTC) Received: by mail-qe0-f72.google.com with SMTP id 6sf10618528qea.3 for ; Wed, 11 Sep 2013 03:15:28 -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=6j4J57Em3UmovOzRP8cvrkr1ec4nXWQwbQH6soPAHzo=; b=V0GW1RfWXUrG65nBIPd8nBuVJxIQPfokXCfejAw2pTYIMKmM8VGcNyCtaHcET65Feg GiMRkxSiJSTwMYozwYdlMV4AHncC+ZQKgUnnjdeQTV/7LIkGgUwraNyW6BE5mFORIM9/ W/64W7bIoVZaKmuobE9ssOQ01bqfOKeOeJrQQsXM3H2yR6UAuzwAodWnS3FDiyjD2tWm bbLki4/fMXYv+nZee2nIY3JdppcnT8vaFxze/fX7C4+LpfAWIzJgLWzh6XKMGOazTQCC 2D+2el2/uO13CPui+gs0rZrspyJ06Qytd6bNprHKSCM6JD1aIaQjgFrr866S+Qd2oOGG bi9g== X-Received: by 10.236.163.67 with SMTP id z43mr312532yhk.27.1378894528560; Wed, 11 Sep 2013 03:15:28 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.74.69 with SMTP id r5ls177943qev.1.gmail; Wed, 11 Sep 2013 03:15:28 -0700 (PDT) X-Received: by 10.52.64.143 with SMTP id o15mr449807vds.16.1378894528324; Wed, 11 Sep 2013 03:15:28 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id ee5si5792849vec.2.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Sep 2013 03:15:28 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.172 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.172; Received: by mail-vc0-f172.google.com with SMTP id m17so5888359vca.17 for ; Wed, 11 Sep 2013 03:15:28 -0700 (PDT) X-Gm-Message-State: ALoCoQl2jYJgclC4RtEBRrPWnQ2SSLenNUIksW+jM1olXrV69LgA/DLuJbSWGGAz7mN3VGPf9lEi X-Received: by 10.220.164.70 with SMTP id d6mr497020vcy.19.1378894528032; Wed, 11 Sep 2013 03:15:28 -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 u4csp47769vcz; Wed, 11 Sep 2013 03:15:27 -0700 (PDT) X-Received: by 10.205.35.15 with SMTP id su15mr626160bkb.21.1378894527059; Wed, 11 Sep 2013 03:15:27 -0700 (PDT) Received: from mail-bk0-f46.google.com (mail-bk0-f46.google.com [209.85.214.46]) by mx.google.com with ESMTPS id kr4si2679309bkb.234.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Sep 2013 03:15:27 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.214.46 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=209.85.214.46; Received: by mail-bk0-f46.google.com with SMTP id 6so3424744bkj.19 for ; Wed, 11 Sep 2013 03:15:26 -0700 (PDT) X-Received: by 10.204.224.142 with SMTP id io14mr622734bkb.27.1378894526350; Wed, 11 Sep 2013 03:15:26 -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 pn6sm7123117bkb.14.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 11 Sep 2013 03:15:25 -0700 (PDT) Message-ID: <523042BB.5010502@linaro.org> Date: Wed, 11 Sep 2013 11:15:23 +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 memalign 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.172 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-memalign. * malloc/tst-memalign.c: New file. --- malloc/Makefile | 2 +- malloc/tst-memalign.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 malloc/tst-memalign.c Changes in v2: - Check errno in -pagesize failure case diff --git a/malloc/Makefile b/malloc/Makefile index 17d146b..d482879 100644 --- a/malloc/Makefile +++ b/malloc/Makefile @@ -27,7 +27,7 @@ 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-pvalloc + tst-pvalloc tst-memalign test-srcs = tst-mtrace routines = malloc morecore mcheck mtrace obstack diff --git a/malloc/tst-memalign.c b/malloc/tst-memalign.c new file mode 100644 index 0000000..d46a2ef --- /dev/null +++ b/malloc/tst-memalign.c @@ -0,0 +1,88 @@ +/* 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 = memalign (sizeof (void *), -1); + + save = errno; + + if (p != NULL) + merror ("memalign (sizeof (void *), -1) succeeded."); + + if (p == NULL && save != ENOMEM) + merror ("memalign (sizeof (void *), -1) errno is not set correctly"); + + errno = 0; + + p = memalign (pagesize, -pagesize); + + save = errno; + + if (p != NULL) + merror ("memalign (pagesize, -pagesize) succeeded."); + + if (p == NULL && save != ENOMEM) + merror ("memalign (pagesize, -pagesize) errno is not set correctly"); + + p = memalign (sizeof (void *), 0); + + if (p == NULL) + merror ("memalign (sizeof (void *), 0) failed."); + + free (p); + + p = memalign (0x100, 10); + + if (p == NULL) + merror ("memalign (0x100, 10) failed."); + + ptrval = (unsigned long)p; + + if (ptrval & 0xff) + merror ("pointer is not aligned to 0x100"); + + free (p); + + return errors != 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c"