From patchwork Mon Aug 19 19:47:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 19335 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f70.google.com (mail-yh0-f70.google.com [209.85.213.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1E4812469E for ; Mon, 19 Aug 2013 19:47:07 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id i72sf4259720yha.9 for ; Mon, 19 Aug 2013 12:47:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; 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=NgqITKb/pBwNAZhZeLo9MCX7YY4L02DjQvLEELP0B9I=; b=SMowW85WkcIvPyFwIYoJJgNS1ubOFKfWFZG2aHopiMpqbgLx96D7c1maq73x+38UeO IdIWPoWsktmlC+rJ5/YUpOgXODK5buM9NsS/ef5NVZbI3GY0cK/P5m2l2wy0dGQFYU6K 8W5mCbJoV/wonMtTEE+atN+/nChUFLTFLqVyMKUecBsLYhdAVaQeZuZsrM5tYko/vuBa YkCJpUwjVPac2xhBaxvlCkUlWmTq2kSRinw86sJkl9cdvu1OZQlHaLjrbhtWUi7cme6h CUvPLRHCAI3dwZ3UJldh6tTDBMgdOBJINKakNbeFKKLgKuT5VZnyB7dRLOuwi0nT9RbE I0+A== X-Received: by 10.236.108.233 with SMTP id q69mr997523yhg.11.1376941626865; Mon, 19 Aug 2013 12:47:06 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.121.163 with SMTP id ll3ls1074330qeb.33.gmail; Mon, 19 Aug 2013 12:47:06 -0700 (PDT) X-Received: by 10.58.75.41 with SMTP id z9mr15029847vev.4.1376941626745; Mon, 19 Aug 2013 12:47:06 -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 xe6si2714600vdb.139.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 19 Aug 2013 12:47:06 -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 gf11so3225255vcb.25 for ; Mon, 19 Aug 2013 12:47:06 -0700 (PDT) X-Gm-Message-State: ALoCoQnZhtLJIAL5dzgiZxFd2BK+6N4g8QJxFVvUMWZNTfwc4DF1OR2CqWuaj0XKEhbC91x/NxEB X-Received: by 10.58.235.69 with SMTP id uk5mr15101167vec.17.1376941626644; Mon, 19 Aug 2013 12:47:06 -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 u4csp114187vcz; Mon, 19 Aug 2013 12:47:06 -0700 (PDT) X-Received: by 10.14.5.78 with SMTP id 54mr6094669eek.55.1376941625728; Mon, 19 Aug 2013 12:47:05 -0700 (PDT) Received: from mail-ee0-f50.google.com (mail-ee0-f50.google.com [74.125.83.50]) by mx.google.com with ESMTPS id o6si11082134eea.9.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 19 Aug 2013 12:47:05 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.83.50 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=74.125.83.50; Received: by mail-ee0-f50.google.com with SMTP id d51so2354542eek.37 for ; Mon, 19 Aug 2013 12:47:05 -0700 (PDT) X-Received: by 10.14.210.8 with SMTP id t8mr25013939eeo.39.1376941625195; Mon, 19 Aug 2013 12:47:05 -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 a6sm19496393eei.10.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 19 Aug 2013 12:47:04 -0700 (PDT) Message-ID: <52127636.5000705@linaro.org> Date: Mon, 19 Aug 2013 20:47:02 +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 4/7] malloc: Add posix_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.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-12 Will Newton * malloc/Makefile: Add tst-posix_memalign. * malloc/tst-posix_memalign.c: New file. --- malloc/Makefile | 2 +- malloc/tst-posix_memalign.c | 98 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 malloc/tst-posix_memalign.c diff --git a/malloc/Makefile b/malloc/Makefile index b16dac8..4903c13 100644 --- a/malloc/Makefile +++ b/malloc/Makefile @@ -26,7 +26,7 @@ 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-malloc-usable tst-realloc tst-posix_memalign test-srcs = tst-mtrace routines = malloc morecore mcheck mtrace obstack diff --git a/malloc/tst-posix_memalign.c b/malloc/tst-posix_memalign.c new file mode 100644 index 0000000..9d9d1bf --- /dev/null +++ b/malloc/tst-posix_memalign.c @@ -0,0 +1,98 @@ +/* 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; + int ret; + unsigned long pagesize = getpagesize(); + unsigned long ptrval; + + p = NULL; + + ret = posix_memalign (&p, sizeof (void *), -1); + + if (ret != ENOMEM) + merror ("posix_memalign (&p, sizeof (void *), -1) succeeded."); + + if (ret == ENOMEM && p != NULL) + merror ("returned an error but pointer was modified"); + + p = NULL; + + ret = posix_memalign (&p, pagesize, -pagesize); + + if (ret != ENOMEM) + merror ("posix_memalign (&p, pagesize, -pagesize) succeeded."); + + p = NULL; + + ret = posix_memalign (&p, sizeof (void *), 0); + + if (ret != 0 || p == NULL) + merror ("posix_memalign (&p, sizeof (void *), 0) failed."); + + free (p); + + ret = posix_memalign (&p, 0x300, 10); + + if (ret != EINVAL) + merror ("posix_memalign (&p, 0x300, 10) succeeded."); + + ret = posix_memalign (&p, 0, 10); + + if (ret != EINVAL) + merror ("posix_memalign (&p, 0, 10) succeeded."); + + p = NULL; + + ret = posix_memalign (&p, 0x100, 10); + + if (ret != 0) + merror ("posix_memalign (&p, 0x100, 10) failed."); + + if (ret == 0 && p == NULL) + merror ("returned success but pointer is NULL"); + + ptrval = (unsigned long)p; + + if (ret == 0 && (ptrval & 0xff)) + merror ("pointer is not aligned to 0x100"); + + free (p); + + return errors != 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c"