[cfe-commits] r77058 - /cfe/trunk/utils/test/TestRunner.py

Daniel Dunbar daniel at zuster.org
Sat Jul 25 02:43:02 PDT 2009


Author: ddunbar
Date: Sat Jul 25 04:42:24 2009
New Revision: 77058

URL: http://llvm.org/viewvc/llvm-project?rev=77058&view=rev
Log:
MultiTestRunner.py improvements.
 - Not improved: the horribly lousy name. :)

 - Suppress stderr when capturing output.

 - Rewrite which() to do the right PATH search instead of being lazy and
   shelling out to 'which'.

 - On Windows, run scripts as batch files (via 'cmd /c ...').

Modified:
    cfe/trunk/utils/test/TestRunner.py

Modified: cfe/trunk/utils/test/TestRunner.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/test/TestRunner.py?rev=77058&r1=77057&r2=77058&view=diff

==============================================================================
--- cfe/trunk/utils/test/TestRunner.py (original)
+++ cfe/trunk/utils/test/TestRunner.py Sat Jul 25 04:42:24 2009
@@ -16,7 +16,9 @@
 #
 
 import errno
+import hashlib
 import os
+import platform
 import re
 import signal
 import subprocess
@@ -27,6 +29,8 @@
 # FIXME: Find a better place for this hack.
 os.environ['COLUMNS'] = '0'
 
+kSystemName = platform.system()
+
 class TestStatus:
     Pass = 0 
     XFail = 1
@@ -109,6 +113,8 @@
 
     FILENAME = os.path.abspath(FILENAME)
     SCRIPT = OUTPUT + '.script'
+    if kSystemName == 'Windows':
+        SCRIPT += '.bat'
     TEMPOUTPUT = OUTPUT + '.tmp'
 
     substitutions = [('%s',SUBST),
@@ -149,7 +155,12 @@
     outputFile = open(OUTPUT,'w')
     p = None
     try:
-        p = subprocess.Popen(["/bin/sh",SCRIPT],
+        if kSystemName == 'Windows':
+            command = ['cmd','/c', SCRIPT]
+        else:
+            command = ['/bin/sh', SCRIPT]
+        
+        p = subprocess.Popen(command,
                              cwd=os.path.dirname(FILENAME),
                              stdin=subprocess.PIPE,
                              stdout=subprocess.PIPE,
@@ -170,7 +181,10 @@
         SCRIPT_STATUS = not SCRIPT_STATUS
 
     if useValgrind:
-        VG_OUTPUT = capture(['/bin/sh','-c','cat %s.*'%(VG_OUTPUT)])
+        if kSystemName == 'Windows':
+            raise NotImplementedError,'Cannot run valgrind on windows'
+        else:
+            VG_OUTPUT = capture(['/bin/sh','-c','cat %s.*'%(VG_OUTPUT)])
         VG_STATUS = len(VG_OUTPUT)
     else:
         VG_STATUS = 0
@@ -200,16 +214,30 @@
         return TestStatus.Pass
 
 def capture(args):
-    p = subprocess.Popen(args, stdout=subprocess.PIPE)
+    p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     out,_ = p.communicate()
     return out
 
 def which(command):
+    # Check for absolute match first.
+    if os.path.exists(command):
+        return command
+
     # Would be nice if Python had a lib function for this.
-    res = capture(['which',command])
-    res = res.strip()
-    if res and os.path.exists(res):
-        return res
+    paths = os.environ.get('PATH')
+    if not paths:
+        paths = os.defpath
+
+    # Get suffixes to search.
+    pathext = os.environ.get('PATHEXT', '').split(os.pathsep)
+
+    # Search the paths...
+    for path in paths.split(os.pathsep):
+        for ext in pathext:
+            p = os.path.join(path, command + ext)
+            if os.path.exists(p):
+                return p
+
     return None
 
 def inferClang():
@@ -240,7 +268,11 @@
 
     # Otherwise try adding -cc since we expect to be looking in a build
     # directory.
-    clangcc = which(clang + '-cc')
+    if clang.endswith('.exe'):
+        clangccName = clang[:-4] + '-cc.exe'
+    else:
+        clangccName = clang + '-cc'
+    clangcc = which(clangccName)
     if not clangcc:
         # Otherwise ask clang.
         res = capture([clang, '-print-prog-name=clang-cc'])





More information about the cfe-commits mailing list