From patchwork Thu Nov 7 17:41:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 21401 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f71.google.com (mail-qa0-f71.google.com [209.85.216.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2C2B925E16 for ; Thu, 7 Nov 2013 17:41:35 +0000 (UTC) Received: by mail-qa0-f71.google.com with SMTP id w5sf1245049qac.6 for ; Thu, 07 Nov 2013 09:41:35 -0800 (PST) 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=1rf9TAk1emOXC0SE3BtdK3mytz7lQhYbN/rUA7/wwDA=; b=GzILi3r2mELepaTP3YzJYA/5AqUfyNB5Ikw1BUtQmZ6dRuwxrb4HX7hmuRU8qd/HcE 71zRr/qU+6AQijP4O9ODAa44SE89T+gaZghapX+I+1JnNLuACl2G4h5UNRwaQi2KYF5/ Zdc9i0o1ipX0B/KuiLnz56npZCJeQznAHIVdbOuF/vHzIMnJLZZAK2wxtOOo7mg8NIMf /huyfRZX2QVm/FEJ8i+iebpiSgUqBZZRRs57/3ofqYp/LlenEiKdfstkKNB5bOEPErCA p10kfKlVyN3e7kh26nj5FsraMj48OT+6Goi7yQXlyhZZl5IxQKqQ5spb19CvhVWCLWN9 pAYw== X-Gm-Message-State: ALoCoQkJfdikYxVY8Ess1ILCnVnBhPLL9o7YHwQkKE3POvaWx8oTgZl1+qWQM0GMLr9w0PkUbkXl X-Received: by 10.236.32.74 with SMTP id n50mr635648yha.13.1383846095040; Thu, 07 Nov 2013 09:41:35 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.110.5 with SMTP id hw5ls1255200qeb.56.gmail; Thu, 07 Nov 2013 09:41:34 -0800 (PST) X-Received: by 10.220.17.131 with SMTP id s3mr447617vca.20.1383846094930; Thu, 07 Nov 2013 09:41:34 -0800 (PST) Received: from mail-vb0-f48.google.com (mail-vb0-f48.google.com [209.85.212.48]) by mx.google.com with ESMTPS id gu4si2022590vdc.124.2013.11.07.09.41.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 07 Nov 2013 09:41:34 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.48 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.48; Received: by mail-vb0-f48.google.com with SMTP id o19so597356vbm.21 for ; Thu, 07 Nov 2013 09:41:34 -0800 (PST) X-Received: by 10.220.173.134 with SMTP id p6mr1342743vcz.36.1383846094800; Thu, 07 Nov 2013 09:41:34 -0800 (PST) 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 u4csp37501vcz; Thu, 7 Nov 2013 09:41:34 -0800 (PST) X-Received: by 10.180.79.227 with SMTP id m3mr3789007wix.2.1383846093894; Thu, 07 Nov 2013 09:41:33 -0800 (PST) Received: from mail-we0-f176.google.com (mail-we0-f176.google.com [74.125.82.176]) by mx.google.com with ESMTPS id o6si7827982wib.56.2013.11.07.09.41.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 07 Nov 2013 09:41:33 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.176 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=74.125.82.176; Received: by mail-we0-f176.google.com with SMTP id w62so865380wes.7 for ; Thu, 07 Nov 2013 09:41:33 -0800 (PST) X-Received: by 10.194.187.232 with SMTP id fv8mr7604273wjc.56.1383846093428; Thu, 07 Nov 2013 09:41:33 -0800 (PST) Received: from localhost.localdomain (cpc6-seac21-2-0-cust453.7-2.cable.virginm.net. [82.1.113.198]) by mx.google.com with ESMTPSA id fr4sm36923110wib.0.2013.11.07.09.41.32 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 07 Nov 2013 09:41:32 -0800 (PST) Message-ID: <527BD0CB.6090803@linaro.org> Date: Thu, 07 Nov 2013 17:41:31 +0000 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: Patch Tracking Subject: [PATCH 2/2] malloc: Add tst-aligned_alloc. 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.48 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: , Add a test for aligned_alloc. The test is largely the same as the test for memalign but with an extra test for the restrictions on the SIZE argument to aligned_alloc. ChangeLog: 2013-11-07 Will Newton * malloc/Makefile (tests): Add tst-aligned_alloc. * malloc/tst-aligned_alloc.c: New file. --- malloc/Makefile | 2 +- malloc/tst-aligned_alloc.c | 127 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 malloc/tst-aligned_alloc.c diff --git a/malloc/Makefile b/malloc/Makefile index 84339d1..39eacb4 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-memalign + tst-pvalloc tst-memalign tst-aligned_alloc test-srcs = tst-mtrace routines = malloc morecore mcheck mtrace obstack diff --git a/malloc/tst-aligned_alloc.c b/malloc/tst-aligned_alloc.c new file mode 100644 index 0000000..34ceefe --- /dev/null +++ b/malloc/tst-aligned_alloc.c @@ -0,0 +1,127 @@ +/* Test for aligned_alloc. + 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 = aligned_alloc (sizeof (void *), -1); + + save = errno; + + if (p != NULL) + merror ("aligned_alloc (sizeof (void *), -1) succeeded."); + + if (p == NULL && save != ENOMEM) + merror ("aligned_alloc (sizeof (void *), -1) errno is not set correctly"); + + free (p); + + errno = 0; + + /* Test to expose integer overflow in malloc internals from BZ #15857. */ + p = aligned_alloc (pagesize, -pagesize); + + save = errno; + + if (p != NULL) + merror ("aligned_alloc (pagesize, -pagesize) succeeded."); + + if (p == NULL && save != ENOMEM) + merror ("aligned_alloc (pagesize, -pagesize) errno is not set correctly"); + + free (p); + + errno = 0; + + /* Test to expose integer overflow in malloc internals from BZ #16038. */ + p = aligned_alloc (-1, pagesize); + + save = errno; + + if (p != NULL) + merror ("aligned_alloc (-1, pagesize) succeeded."); + + if (p == NULL && save != EINVAL) + merror ("aligned_alloc (-1, pagesize) errno is not set correctly"); + + free (p); + + /* aligned_alloc requires that size is a multiple of alignment. */ + p = aligned_alloc (0x100, 10); + + save = errno; + + if (p != NULL) + merror ("aligned_alloc (0x100, 10) succeeded."); + + if (p == NULL && save != EINVAL) + merror ("aligned_alloc (0x100, 10) errno is not set correctly"); + + free (p); + + /* A zero-sized allocation should succeed with glibc, returning a + non-NULL value. */ + p = aligned_alloc (sizeof (void *), 0); + + if (p == NULL) + merror ("aligned_alloc (sizeof (void *), 0) failed."); + + free (p); + + /* Check the alignment of the returned pointer is correct. */ + p = aligned_alloc (0x100, 0x200); + + if (p == NULL) + merror ("aligned_alloc (0x100, 0x200) 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"