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)/%))
 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 
+
 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;
+       }
+
+       return -1;
+}
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index ce97206..07e9683 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -13,16 +13,16 @@ function free_hpages() {
        echo "$H"
 }
 
-function hugetlbfs_path() {
-    if [ -n "$HUGETLB_PATH" ]; then
-       echo "$HUGETLB_PATH"
-    else
-       grep hugetlbfs /proc/mounts | cut -f2 -d' '
-    fi
+function get_and_set_hugetlbfs_path() {
+       HUGETLB_PATH=$(PATH="obj32:obj64:$PATH" 
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:../obj32:../obj64" get_hugetlbfs_path)
+       if [ $? != 0 ]; then
+               echo "run_tests.sh: unable to find hugetlbfs mountpoint"
+               exit 1
+       fi
 }
 
 function clear_hpages() {
-    rm -rf "`hugetlbfs_path`"/elflink-uid-`id -u`
+    rm -rf "$HUGETLB_PATH"/elflink-uid-`id -u`
 }
 
 TOTAL_HPAGES=$(grep 'HugePages_Total:' /proc/meminfo | cut -f2 -d:)
@@ -217,6 +217,8 @@ if [ -z "$WORDSIZES" ]; then
     WORDSIZES="32 64"
 fi
 
+get_and_set_hugetlbfs_path
+
 for set in $TESTSETS; do
     case $set in
        "func")

-- 
Nishanth Aravamudan <[EMAIL PROTECTED]>
IBM Linux Technology Center

-------------------------------------------------------------------------
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