From patchwork Wed Sep 11 10:15:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 19953 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f197.google.com (mail-ve0-f197.google.com [209.85.128.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BA685248D9 for ; Wed, 11 Sep 2013 10:15:21 +0000 (UTC) Received: by mail-ve0-f197.google.com with SMTP id jy13sf9363040veb.0 for ; Wed, 11 Sep 2013 03:15:21 -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=NgqITKb/pBwNAZhZeLo9MCX7YY4L02DjQvLEELP0B9I=; b=TeVzIVEVmUKouPATXDCBYPlobT8jn2TNEO0IOm4if8mLh0LXV0HWlBeuWAJV6MQI31 +3u/LwHpaoeTjpcx/wADdNPq1skvGl3sisasrCJv0W6uQsgQnXoDygGWqMh8R5/AgWND x6AsefG/Wmxet2Ew13gUqsM4u7IDEkds4IGIewEdM09Ua7eI8MkSybNJJbbk62VxJ4y4 tO2Xdr1mv6ntXavTK9OU2SJ8yoRfaH/P7CykMDVvms0snpHV9L0yQ1dUR4zXbOUs7Omc 0KAINK8oo0r7Z3zLtQO+Ve5xg1lbeP3iTsAyCNB+TQldQIne59cStHPmPQeN/17S+Q8A 8bDQ== X-Received: by 10.236.0.232 with SMTP id 68mr350955yhb.16.1378894521315; Wed, 11 Sep 2013 03:15:21 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.121.231 with SMTP id ln7ls162445qeb.57.gmail; Wed, 11 Sep 2013 03:15:21 -0700 (PDT) X-Received: by 10.52.157.134 with SMTP id wm6mr443447vdb.26.1378894521118; Wed, 11 Sep 2013 03:15:21 -0700 (PDT) Received: from mail-vb0-f50.google.com (mail-vb0-f50.google.com [209.85.212.50]) by mx.google.com with ESMTPS id zw10si5772109vdb.44.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Sep 2013 03:15:21 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.50 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.50; Received: by mail-vb0-f50.google.com with SMTP id x14so5829173vbb.23 for ; Wed, 11 Sep 2013 03:15:21 -0700 (PDT) X-Gm-Message-State: ALoCoQmRhyfctT4nK7Zy/ASMGevX15xlMTYRYYwIegpD7uhS+JEGuJ2QdEkygxKu1bEcEsOiBoW8 X-Received: by 10.220.16.73 with SMTP id n9mr524024vca.24.1378894520931; Wed, 11 Sep 2013 03:15:20 -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 u4csp47761vcz; Wed, 11 Sep 2013 03:15:20 -0700 (PDT) X-Received: by 10.204.64.78 with SMTP id d14mr659495bki.40.1378894519726; Wed, 11 Sep 2013 03:15:19 -0700 (PDT) Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com [209.85.214.53]) by mx.google.com with ESMTPS id u7si2675836bkh.348.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Sep 2013 03:15:19 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.214.53 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=209.85.214.53; Received: by mail-bk0-f53.google.com with SMTP id d7so3527997bkh.12 for ; Wed, 11 Sep 2013 03:15:19 -0700 (PDT) X-Received: by 10.204.66.133 with SMTP id n5mr655402bki.38.1378894518910; Wed, 11 Sep 2013 03:15:18 -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 qx2sm7133153bkb.16.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 11 Sep 2013 03:15:18 -0700 (PDT) Message-ID: <523042B4.90602@linaro.org> Date: Wed, 11 Sep 2013 11:15:16 +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 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.212.50 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"