On Mon, Dec 04, 2006 at 03:39:09PM -0800, Nishanth Aravamudan wrote:
> It was noted recently that checking for a hugetlbfs mountpoint in the
> run_tests.sh can lead to a few issues (spaces in /proc/mounts, for
> instance), which are hard to work around. Instead, make use of the
> library's utilities via a small helper program which should provide
> greater safety.
> 
> Signed-off-by: Nishanth Aravamudan <[EMAIL PROTECTED]>
> 
> ---
> 
>  tests/Makefile             |   14 ++++++++++++--
>  tests/get_hugetlbfs_path.c |   43 +++++++++++++++++++++++++++++++++++++++++++
>  tests/run_tests.sh         |   16 +++++++++-------
>  3 files changed, 64 insertions(+), 9 deletions(-)
> 
> diff --git a/tests/Makefile b/tests/Makefile
> index b4dcb75..8ca7d19 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -13,6 +13,7 @@ NOLIB_TESTS = malloc malloc_manysmall du
>  LDSCRIPT_TESTS = zero_filesize_segment
>  HUGELINK_TESTS = linkhuge linkhuge_nofd linkshare
>  STRESS_TESTS = mmap-gettest mmap-cow shm-gettest shm-getraw shm-fork
> +HELPERS = get_hugetlbfs_path
>  
>  CFLAGS = -O2 -Wall -g
>  CPPFLAGS = -I..
> @@ -44,14 +45,15 @@ VECHO = echo "    "
>  endif
>  
>  DEPFILES = $(LIB_TESTS:%=%.d) $(NOLIB_TESTS:%=%.d) $(HUGELINK_TESTS:%=%.d) \
> -     testutils.d
> +     $(HELPERS:%=%.d) testutils.d
>  
>  ALLTESTS = $(foreach DIR,$(OBJDIRS),$(TESTS:%=$(DIR)/%))
> +ALLHELPERS = $(foreach DIR,$(OBJDIRS),$(HELPERS:%=$(DIR)/%))

Building both 32-bit and 64-bit versions of this is a bit yucky, but I
guess it's not worth the Makefile infrastructure (introducing things
for building "native" objects) to avoid it.

>  ifdef CC64
>  ALLTESTS += $(TESTS_64:%=obj64/%)
>  endif
>  
> -all: $(ALLTESTS)
> +all: $(ALLTESTS) $(ALLHELPERS)
>  
>  obj32/%.o: %.c
>       @$(VECHO) CC32 $@
> @@ -127,6 +129,14 @@ obj64/xBDT.%: $(SCRIPTS64).xBDT $(HUGETL
>       @ln -sf ../$(HUGETLBFS_LD) obj64/ld
>       $(CC64) -B./obj64 $(LDFLAGS) $(LDFLAGS64) -o $@ $(LDLIBS) 
> -Wl,--hugetlbfs-link=BDT $(filter %.o,$^)
>  
> +$(HELPERS:%=obj32/%): %: %.o obj32/testutils.o
> +     @$(VECHO) LD32 "(helper)" $@
> +     $(CC32) $(LDFLAGS) $(LDFLAGS32) -o $@ $^ $(LDLIBS) -lhugetlbfs 
> +
> +$(HELPERS:%=obj64/%): %: %.o obj64/testutils.o
> +     @$(VECHO) LD64 "(helper)" $@
> +     $(CC64) $(LDFLAGS) $(LDFLAGS64) -o $@ $^ $(LDLIBS) -lhugetlbfs 
> +

These don't actually need testutils.o

>  clean:
>       @$(VECHO) CLEAN "(tests)"
>       rm -f *~ *.o *.so *.a *.d core a.out
> diff --git a/tests/get_hugetlbfs_path.c b/tests/get_hugetlbfs_path.c
> new file mode 100644
> index 0000000..895135b
> --- /dev/null
> +++ b/tests/get_hugetlbfs_path.c
> @@ -0,0 +1,43 @@
> +/*
> + * libhugetlbfs - Easy use of Linux hugepages
> + * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
> + * Copyright (C) 2006 Nishanth Aravamudan, IBM Corporation.
> + *
> + * This 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.
> + *
> + * This 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 this library; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +
> +#include <hugetlbfs.h>
> +
> +#include "hugetests.h"
> +
> +int main(int argc, char *argv[])
> +{
> +     const char *dir;
> +
> +     dir = hugetlbfs_find_path();
> +
> +     if (!dir)
> +             return -1;
> +
> +     if (hugetlbfs_test_path(dir) == 1) {
> +             printf("%s\n", dir);
> +             return 0;
> +     }

This test is redundant, hugetlbfs_find_path() already checks that the
path is hugetlbfs.

-- 
David Gibson                    | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
                                | _way_ _around_!
http://www.ozlabs.org/~dgibson

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Libhugetlbfs-devel mailing list
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to