This patch adds code to the run_tests.py script to check the state of all the hugepage pools before and after each testcase. When turned on (with the new '-c' option to run_tests.py), it will report an error if the pool sizes are different after the test than before.
Obviously this can report bogus errors if other programs are using hugepages on the system, or if dynamic pools are enabled. Nonetheless it can be useful it can be useful for detecting and tracking down subtle kernel bugs which result in misaccounting of the pool state (I've used it to debug such problems in a new hugepage port). Signed-off-by: David Gibson <da...@gibson.dropbear.id.au> Index: libhugetlbfs/tests/run_tests.py =================================================================== --- libhugetlbfs.orig/tests/run_tests.py 2009-10-02 13:18:48.000000000 +1000 +++ libhugetlbfs/tests/run_tests.py 2009-10-02 16:45:37.000000000 +1000 @@ -48,7 +48,19 @@ def bash(cmd): out = p.stdout.read().strip() return (rc, out) +def snapshot_pool_state(): + l = [] + for d in os.listdir("/sys/kernel/mm/hugepages"): + substate = [(f, int(open("/sys/kernel/mm/hugepages/%s/%s" % (d, f)).read())) + for f in os.listdir("/sys/kernel/mm/hugepages/%s" % d)] + l.append((d, tuple(substate))) + return tuple(l) + def run_test_prog(bits, pagesize, cmd, **env): + if paranoid_pool_check: + beforepool = snapshot_pool_state() + print "Pool state: %s" % str(beforepool) + local_env = os.environ.copy() local_env.update(env) local_env["PATH"] = "./obj%d:../obj%d:%s" \ @@ -64,6 +76,15 @@ def run_test_prog(bits, pagesize, cmd, * # Abort and mark this a strange test result return (None, "") out = p.stdout.read().strip() + + if paranoid_pool_check: + afterpool = snapshot_pool_state() + if afterpool != beforepool: + print >>sys.stderr, "Hugepage pool state not preserved!" + print >>sys.stderr, "BEFORE: %s" % str(beforepool) + print >>sys.stderr, "AFTER: %s" % str(afterpool) + sys.exit(98) + return (rc, out) def setup_env(override, defaults): @@ -584,15 +605,16 @@ def stress_tests(): def main(): - global wordsizes, pagesizes, dangerous + global wordsizes, pagesizes, dangerous, paranoid_pool_check testsets = set() env_override = {"QUIET_TEST": "1", "HUGETLBFS_MOUNTS": "", "HUGETLB_ELFMAP": None, "HUGETLB_MORECORE": None} env_defaults = {"HUGETLB_VERBOSE": "0"} dangerous = 0 + paranoid_pool_check = False try: - opts, args = getopt.getopt(sys.argv[1:], "vVfdt:b:p:") + opts, args = getopt.getopt(sys.argv[1:], "vVfdt:b:p:c") except getopt.GetoptError, err: print str(err) sys.exit(1) @@ -610,6 +632,8 @@ def main(): for b in arg.split(): wordsizes.add(int(b)) elif opt == "-p": for p in arg.split(): pagesizes.add(int(p)) + elif opt == '-c': + paranoid_pool_check = True else: assert False, "unhandled option" if len(testsets) == 0: testsets = set(["func", "stress"]) -- 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