Skip to content

Commit e6475f1

Browse files
committed
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 ...'). llvm-svn: 77058
1 parent 6bdd19a commit e6475f1

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

clang/utils/test/TestRunner.py

+40-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
#
1717

1818
import errno
19+
import hashlib
1920
import os
21+
import platform
2022
import re
2123
import signal
2224
import subprocess
@@ -27,6 +29,8 @@
2729
# FIXME: Find a better place for this hack.
2830
os.environ['COLUMNS'] = '0'
2931

32+
kSystemName = platform.system()
33+
3034
class TestStatus:
3135
Pass = 0
3236
XFail = 1
@@ -109,6 +113,8 @@ def runOneTest(FILENAME, SUBST, OUTPUT, TESTNAME, CLANG, CLANGCC,
109113

110114
FILENAME = os.path.abspath(FILENAME)
111115
SCRIPT = OUTPUT + '.script'
116+
if kSystemName == 'Windows':
117+
SCRIPT += '.bat'
112118
TEMPOUTPUT = OUTPUT + '.tmp'
113119

114120
substitutions = [('%s',SUBST),
@@ -149,7 +155,12 @@ def runOneTest(FILENAME, SUBST, OUTPUT, TESTNAME, CLANG, CLANGCC,
149155
outputFile = open(OUTPUT,'w')
150156
p = None
151157
try:
152-
p = subprocess.Popen(["/bin/sh",SCRIPT],
158+
if kSystemName == 'Windows':
159+
command = ['cmd','/c', SCRIPT]
160+
else:
161+
command = ['/bin/sh', SCRIPT]
162+
163+
p = subprocess.Popen(command,
153164
cwd=os.path.dirname(FILENAME),
154165
stdin=subprocess.PIPE,
155166
stdout=subprocess.PIPE,
@@ -170,7 +181,10 @@ def runOneTest(FILENAME, SUBST, OUTPUT, TESTNAME, CLANG, CLANGCC,
170181
SCRIPT_STATUS = not SCRIPT_STATUS
171182

172183
if useValgrind:
173-
VG_OUTPUT = capture(['/bin/sh','-c','cat %s.*'%(VG_OUTPUT)])
184+
if kSystemName == 'Windows':
185+
raise NotImplementedError,'Cannot run valgrind on windows'
186+
else:
187+
VG_OUTPUT = capture(['/bin/sh','-c','cat %s.*'%(VG_OUTPUT)])
174188
VG_STATUS = len(VG_OUTPUT)
175189
else:
176190
VG_STATUS = 0
@@ -200,16 +214,30 @@ def runOneTest(FILENAME, SUBST, OUTPUT, TESTNAME, CLANG, CLANGCC,
200214
return TestStatus.Pass
201215

202216
def capture(args):
203-
p = subprocess.Popen(args, stdout=subprocess.PIPE)
217+
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
204218
out,_ = p.communicate()
205219
return out
206220

207221
def which(command):
222+
# Check for absolute match first.
223+
if os.path.exists(command):
224+
return command
225+
208226
# Would be nice if Python had a lib function for this.
209-
res = capture(['which',command])
210-
res = res.strip()
211-
if res and os.path.exists(res):
212-
return res
227+
paths = os.environ.get('PATH')
228+
if not paths:
229+
paths = os.defpath
230+
231+
# Get suffixes to search.
232+
pathext = os.environ.get('PATHEXT', '').split(os.pathsep)
233+
234+
# Search the paths...
235+
for path in paths.split(os.pathsep):
236+
for ext in pathext:
237+
p = os.path.join(path, command + ext)
238+
if os.path.exists(p):
239+
return p
240+
213241
return None
214242

215243
def inferClang():
@@ -240,7 +268,11 @@ def inferClangCC(clang):
240268

241269
# Otherwise try adding -cc since we expect to be looking in a build
242270
# directory.
243-
clangcc = which(clang + '-cc')
271+
if clang.endswith('.exe'):
272+
clangccName = clang[:-4] + '-cc.exe'
273+
else:
274+
clangccName = clang + '-cc'
275+
clangcc = which(clangccName)
244276
if not clangcc:
245277
# Otherwise ask clang.
246278
res = capture([clang, '-print-prog-name=clang-cc'])

0 commit comments

Comments
 (0)