This fixes one real bug in run_tests.py and a couple of other places
where we do things in a silly way.

The real bug is that we clearly want to use the current libhugetlbfs
binaries and libraries to run the test, so they should be added to the
front of the path, not the back as cmd_env() currently does.

In the same piece of code we use Python's `` operators for no good
reason, since the string formatting operation we're already using will
encode the bits value properly.

cmd_env() also takes an optional pagesize parameter.  The only time
it's not supplied is when it's used to invoke hugeadm, which doesn't
really suit use of cmd_env() anyway.  So, this patch makes that
parameter mandatory which simplifies the logic a bit (in fact that
test logic was also wrong, but it didn't really matter).

Finally, in bash() we use the dictionary's update() method instead of
the manual equivalent.

Signed-off-by: David Gibson <d...@au1.ibm.com>

Index: libhugetlbfs/tests/run_tests.py
===================================================================
--- libhugetlbfs.orig/tests/run_tests.py        2009-08-19 13:18:58.000000000 
+1000
+++ libhugetlbfs/tests/run_tests.py     2009-08-19 13:37:27.000000000 +1000
@@ -38,8 +38,7 @@ def bash(cmd, extra_env={}):
     Run 'cmd' in the shell and return the exit code and output.
     """
     local_env = os.environ.copy()
-    for key,value in extra_env.items():
-        local_env[key] = value
+    local_env.update(extra_env)
     p = subprocess.Popen(cmd, shell=True, env=local_env, \
                          stdout=subprocess.PIPE)
     try:
@@ -186,7 +185,7 @@ def clear_hpages():
         except OSError:
             pass
 
-def cmd_env(bits, pagesize=""):
+def cmd_env(bits, pagesize):
     """
     Construct test-specific environment settings.
 
@@ -194,11 +193,10 @@ def cmd_env(bits, pagesize=""):
     libhugetlbfs test or utility that is run from within the source tree can
     be found.  Additionally, tell libhugetlbfs to use the requested page size.
     """
-    str = "PATH=$PATH:./obj%s:../obj%s " \
-          "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../obj%s:obj%s " % \
-          (`bits`, `bits`, `bits`, `bits`)
-    if len(`pagesize`) > 0: str += "HUGETLB_DEFAULT_PAGE_SIZE=%s " % pagesize
-    return str
+    return "PATH=./obj%d:../obj%d:$PATH " \
+        "LD_LIBRARY_PATH=../obj%d:obj%d:$LD_LIBRARY_PATH " \
+        "HUGETLB_DEFAULT_PAGE_SIZE=%d " \
+        % (bits, bits, bits, bits, pagesize)
 
 def get_pagesizes():
     """
@@ -209,7 +207,7 @@ def get_pagesizes():
     """
     sizes = set()
     out = ""
-    (rc, out) = bash(cmd_env('') + "hugeadm --page-sizes")
+    (rc, out) = bash("../obj/hugeadm --page-sizes")
     if rc != 0 or out == "": return sizes
 
     for size in out.split("\n"): sizes.add(int(size))


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