From patchwork Thu Oct 3 12:23:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 20782 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f70.google.com (mail-qa0-f70.google.com [209.85.216.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B230525CAB for ; Thu, 3 Oct 2013 12:23:54 +0000 (UTC) Received: by mail-qa0-f70.google.com with SMTP id i13sf4726209qae.9 for ; Thu, 03 Oct 2013 05:23:54 -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=RlILgDb5tZJLsksvcsO04U9n3hFNeuXw79ttpKa2CK0=; b=cUipYDy2FM3AJ6RSt43UIfT4jGPScGou+q8wfzAlib7ROUgQoxzIE36gB1TLIbSnxD PSZ8nlZVVr3gz0IlZhYwiHVLX9azdWAJNyrWNaOtPOrcQyUxtz5cfi59iGfinEwHmMZV y3fCVxnJp6Rkqgmun7xSEHDlwcA0wjcPF6ddVDgJcTQMSR4ILaijtSusps2biQ3s7Rk3 qOG257JUp1dQ/AjmojGDSGPraADqNNdzv3nDUuKllhaKiGVf3ZEReA9ZogGnUf9nORdm q0x1w1StyXHNCYp3inX0lmLj3C+82xPeW5wxOXfzNL6PNeSpNg+mJQwSQ8fT+T7BUYSD o9+w== X-Received: by 10.236.20.114 with SMTP id o78mr6845036yho.8.1380803033944; Thu, 03 Oct 2013 05:23:53 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.99.10 with SMTP id em10ls946195qeb.82.gmail; Thu, 03 Oct 2013 05:23:53 -0700 (PDT) X-Received: by 10.52.64.143 with SMTP id o15mr6058628vds.16.1380803033793; Thu, 03 Oct 2013 05:23:53 -0700 (PDT) Received: from mail-vb0-f52.google.com (mail-vb0-f52.google.com [209.85.212.52]) by mx.google.com with ESMTPS id fx4si1662259vdc.13.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 03 Oct 2013 05:23:53 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.52 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.52; Received: by mail-vb0-f52.google.com with SMTP id f12so1449001vbg.25 for ; Thu, 03 Oct 2013 05:23:53 -0700 (PDT) X-Gm-Message-State: ALoCoQkRBShkRcAOICcqqZzIOD2yfoxpaqvbu6hhsEQ8qdzzAHmlKI4JzxqH9oR/iDbBmPm83R7g X-Received: by 10.52.103.35 with SMTP id ft3mr6129630vdb.5.1380803033467; Thu, 03 Oct 2013 05:23:53 -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 u4csp173937vcz; Thu, 3 Oct 2013 05:23:52 -0700 (PDT) X-Received: by 10.180.160.240 with SMTP id xn16mr2242402wib.62.1380803032042; Thu, 03 Oct 2013 05:23:52 -0700 (PDT) Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com [209.85.212.175]) by mx.google.com with ESMTPS id op2si2866987wjc.59.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 03 Oct 2013 05:23:52 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.175 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=209.85.212.175; Received: by mail-wi0-f175.google.com with SMTP id ez12so8815535wid.2 for ; Thu, 03 Oct 2013 05:23:51 -0700 (PDT) X-Received: by 10.194.19.5 with SMTP id a5mr1611261wje.48.1380803031391; Thu, 03 Oct 2013 05:23:51 -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 e5sm26208967wiy.2.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 03 Oct 2013 05:23:50 -0700 (PDT) Message-ID: <524D61D4.2040001@linaro.org> Date: Thu, 03 Oct 2013 13:23:48 +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 v3] 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.212.52 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 | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 malloc/tst-memalign.c Changes in v3: - Add comments - Add calls to free - Coding style 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..ca90507 --- /dev/null +++ b/malloc/tst-memalign.c @@ -0,0 +1,99 @@ +/* Test for memalign. + 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; + + /* An attempt to allocate a huge value should return NULL and set + errno to ENOMEM. */ + 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"); + + free (p); + + errno = 0; + + /* Test to expose integer overflow in malloc internals from BZ #15857. */ + 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"); + + free (p); + + /* A zero-sized allocation should succeed with glibc, returning a + non-NULL value. */ + p = memalign (sizeof (void *), 0); + + if (p == NULL) + merror ("memalign (sizeof (void *), 0) failed."); + + free (p); + + /* Check the alignment of the returned pointer is correct. */ + p = memalign (0x100, 10); + + if (p == NULL) + merror ("memalign (0x100, 10) failed."); + + ptrval = (unsigned long) p; + + if ((ptrval & 0xff) != 0) + merror ("pointer is not aligned to 0x100"); + + free (p); + + return errors != 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c"