Currently, run_tests.py attempts to run each test case for each
available page size and word size.  It does this by setting the
HUGETLB_DEFAULT_PAGE_SIZE environment variable to instruct the
testcase's instance of libhugetlbfs to use the specified pagesize.

However some of the testcases use shmget() with the SHM_HUGETLB flag
to obtain hugepage backed memory, rather than mmap() or the
libhugetlbfs interfaces.  This means of obtaining hugepage memory has
no way to specify the pagesize, and will always use the system default
huge page size.

Therefore, running the test multiple times when it won't actually use
a different pagesize is silly.  Furthermore in some of the cases,
using the non-default sizes results in test failures (because we don't
allocate as much memory as we expect) which have to be suppressed with
a wrapper script which turns them into expected failures.

This patch, therefore, alters run_tests.py to run the shm only tests
with only the default page size.  This is accomplished with a new
helper function 'do_shm_test', which also folds in the setting and
restoring of the shmmax limit for added convenience.  The no longer
necessary wrappers for shm-fork and shm-getraw are removed.

Signed-off-by: David Gibson <da...@gibson.dropbear.id.au>

Index: libhugetlbfs/tests/run_tests.py
===================================================================
--- libhugetlbfs.orig/tests/run_tests.py        2009-11-19 15:05:11.352192251 
+1100
+++ libhugetlbfs/tests/run_tests.py     2009-11-19 18:56:28.400193095 +1100
@@ -460,6 +460,20 @@ def restore_shm_sysctl(sysctls):
         fh.write(val)
         fh.close()
 
+def do_shm_test(cmd, limit=None, bits=None, **env):
+    """
+    Run a test case with temporarily expanded SysV shm limits, testing
+    each indicated word size.
+    """
+    if bits == None:
+        bits = wordsizes
+    if limit != None:
+        tmp = setup_shm_sysctl(limit)
+    for b in bits:
+        run_test(system_default_hpage_size, b, cmd, **env)
+    if limit != None:
+        restore_shm_sysctl(tmp)
+
 def functional_tests():
     """
     Run the set of functional tests.
@@ -510,9 +524,7 @@ def functional_tests():
         do_test("readahead_reserve.sh")
         do_test("madvise_reserve.sh")
         do_test("fadvise_reserve.sh")
-    sysctls = setup_shm_sysctl(64*1048576)
-    do_test("shm-perms")
-    restore_shm_sysctl(sysctls)
+    do_shm_test("shm-perms", 64*1024*1024)
 
     # Tests requiring an active mount and hugepage COW
     do_test("private")
@@ -562,8 +574,8 @@ def functional_tests():
     do_test("get_huge_pages")
 
     # Test overriding of shmget()
-    do_test("shmoverride_linked")
-    do_test("shmoverride_unlinked", LD_PRELOAD="libhugetlbfs.so")
+    do_shm_test("shmoverride_linked")
+    do_shm_test("shmoverride_unlinked", LD_PRELOAD="libhugetlbfs.so")
 
     # Test hugetlbfs filesystem quota accounting
     do_test("quota.sh")
@@ -589,23 +601,20 @@ def stress_tests():
     do_test(("mmap-cow", repr(nr_pages-1), repr(nr_pages)))
 
     (rc, tot_pages) = total_hpages()
-    (rc, size) = hpage_size()
-    sysctls = setup_shm_sysctl(tot_pages * size)
+    limit = system_default_hpage_size * tot_pages
     threads = 10       # Number of threads for shm-fork
+
     # Run shm-fork once using half available hugepages, then once using all
     # This is to catch off-by-ones or races in the kernel allocated that
     # can make allocating all hugepages a problem
     if nr_pages > 1:
-        do_test(("shm-fork.sh", repr(threads), repr(nr_pages / 2)))
-    do_test(("shm-fork.sh", repr(threads), repr(nr_pages)))
-
-    do_test(("shm-getraw.sh", repr(nr_pages), "/dev/full"))
-    restore_shm_sysctl(sysctls)
-
+        do_shm_test(("shm-fork", repr(threads), repr(nr_pages / 2)), limit)
+    do_shm_test(("shm-fork", repr(threads), repr(nr_pages)), limit)
 
+    do_shm_test(("shm-getraw", repr(nr_pages), "/dev/full"), limit)
 
 def main():
-    global wordsizes, pagesizes, dangerous, paranoid_pool_check
+    global wordsizes, pagesizes, dangerous, paranoid_pool_check, 
system_default_hpage_size
     testsets = set()
     env_override = {"QUIET_TEST": "1", "HUGETLBFS_MOUNTS": "",
                     "HUGETLB_ELFMAP": None, "HUGETLB_MORECORE": None}
@@ -647,6 +656,13 @@ def main():
 
     setup_env(env_override, env_defaults)
     init_results()
+
+    (rc, system_default_hpage_size) = hpage_size()
+    if rc != 0:
+        print "Unable to find system default hugepage size."
+        print "Is hugepage supported included in this kernel?"
+        return 1
+
     check_hugetlbfs_path()
 
     if "func" in testsets: functional_tests()
Index: libhugetlbfs/tests/shm-getraw.sh
===================================================================
--- libhugetlbfs.orig/tests/shm-getraw.sh       2009-11-19 15:32:09.780173400 
+1100
+++ /dev/null   1970-01-01 00:00:00.000000000 +0000
@@ -1,18 +0,0 @@
-#!/bin/bash
-
-. wrapper-utils.sh
-
-#shm-getraw will fail if the hugepage size is different from the system default
-
-def_hpage_size=`grep 'Hugepagesize:' /proc/meminfo | awk '{print $2}'`
-let "def_hpage_size *= 1024"
-
-if [ -z "$HUGETLB_DEFAULT_PAGE_SIZE" ]; then
-       EXP_RC=$RC_PASS
-elif [ "$def_hpage_size" -eq "$HUGETLB_DEFAULT_PAGE_SIZE" ]; then
-       EXP_RC=$RC_PASS
-else
-       EXP_RC=$RC_FAIL
-fi
-
-exec_and_check $EXP_RC shm-getraw "$@"
Index: libhugetlbfs/tests/shm-fork.sh
===================================================================
--- libhugetlbfs.orig/tests/shm-fork.sh 2009-11-19 15:32:55.541172982 +1100
+++ /dev/null   1970-01-01 00:00:00.000000000 +0000
@@ -1,18 +0,0 @@
-#!/bin/bash
-
-. wrapper-utils.sh
-
-#shm-fork will fail if the hugepage size is different from the system default
-
-def_hpage_size=`grep 'Hugepagesize:' /proc/meminfo | awk '{print $2}'`
-let "def_hpage_size *= 1024"
-
-if [ -z "$HUGETLB_DEFAULT_PAGE_SIZE" ]; then
-       EXP_RC=$RC_PASS
-elif [ "$def_hpage_size" -eq "$HUGETLB_DEFAULT_PAGE_SIZE" ]; then
-       EXP_RC=$RC_PASS
-else
-       EXP_RC=$RC_FAIL
-fi
-
-exec_and_check $EXP_RC shm-fork "$@"
Index: libhugetlbfs/tests/Makefile
===================================================================
--- libhugetlbfs.orig/tests/Makefile    2009-11-19 18:12:35.617172369 +1100
+++ libhugetlbfs/tests/Makefile 2009-11-19 18:12:58.384175383 +1100
@@ -18,7 +18,7 @@ LDSCRIPT_TESTS = zero_filesize_segment
 HUGELINK_TESTS = linkhuge linkhuge_nofd linkshare
 HUGELINK_RW_TESTS = linkhuge_rw
 STRESS_TESTS = mmap-gettest mmap-cow shm-gettest shm-getraw shm-fork
-WRAPPERS = quota shm-fork shm-getraw counters madvise_reserve fadvise_reserve \
+WRAPPERS = quota counters madvise_reserve fadvise_reserve \
        readahead_reserve
 HELPERS = get_hugetlbfs_path compare_kvers
 HELPER_LIBS = libheapshrink.so


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

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Libhugetlbfs-devel mailing list
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to