9
9
from __future__ import absolute_import
10
10
import os
11
11
import platform
12
- import random
13
12
import sys
14
13
import time
15
- import tempfile
16
- import shutil
17
- from xml .sax .saxutils import quoteattr
18
14
19
15
import lit .cl_arguments
20
16
import lit .discovery
@@ -32,6 +28,7 @@ def main(builtinParameters = {}):
32
28
# the buildbot level.
33
29
lit_tmp = None
34
30
if 'LIT_PRESERVES_TMP' not in os .environ :
31
+ import tempfile
35
32
lit_tmp = tempfile .mkdtemp (prefix = "lit_tmp_" )
36
33
os .environ .update ({
37
34
'TMPDIR' : lit_tmp ,
@@ -48,6 +45,7 @@ def main(builtinParameters = {}):
48
45
finally :
49
46
if lit_tmp :
50
47
try :
48
+ import shutil
51
49
shutil .rmtree (lit_tmp )
52
50
except :
53
51
# FIXME: Re-try after timeout on Windows.
@@ -142,23 +140,7 @@ def main_with_tmp(builtinParameters):
142
140
# Don't create more workers than tests.
143
141
opts .numWorkers = min (len (run .tests ), opts .numWorkers )
144
142
145
- increase_process_limit (litConfig , opts )
146
-
147
- display = lit .display .create_display (opts , len (run .tests ),
148
- numTotalTests , opts .numWorkers )
149
- def progress_callback (test ):
150
- display .update (test )
151
- if opts .incremental :
152
- update_incremental_cache (test )
153
-
154
- startTime = time .time ()
155
- try :
156
- run .execute_tests (progress_callback , opts .numWorkers , opts .maxTime )
157
- except KeyboardInterrupt :
158
- sys .exit (2 )
159
- testing_time = time .time () - startTime
160
-
161
- display .finish ()
143
+ testing_time = run_tests (run , litConfig , opts , numTotalTests )
162
144
163
145
if not opts .quiet :
164
146
print ('Testing Time: %.2fs' % (testing_time ,))
@@ -231,7 +213,6 @@ def progress_callback(test):
231
213
232
214
if hasFailures :
233
215
sys .exit (1 )
234
- sys .exit (0 )
235
216
236
217
237
218
def create_user_parameters (builtinParameters , opts ):
@@ -273,11 +254,9 @@ def print_suites_or_tests(run, opts):
273
254
for test in ts_tests :
274
255
print (' %s' % (test .getFullName (),))
275
256
276
- # Exit.
277
- sys .exit (0 )
278
-
279
257
def order_tests (run , opts ):
280
258
if opts .shuffle :
259
+ import random
281
260
random .shuffle (run .tests )
282
261
elif opts .incremental :
283
262
run .tests .sort (key = by_mtime , reverse = True )
@@ -320,6 +299,26 @@ def increase_process_limit(litConfig, opts):
320
299
except :
321
300
pass
322
301
302
+ def run_tests (run , litConfig , opts , numTotalTests ):
303
+ increase_process_limit (litConfig , opts )
304
+
305
+ display = lit .display .create_display (opts , len (run .tests ),
306
+ numTotalTests , opts .numWorkers )
307
+ def progress_callback (test ):
308
+ display .update (test )
309
+ if opts .incremental :
310
+ update_incremental_cache (test )
311
+
312
+ startTime = time .time ()
313
+ try :
314
+ run .execute_tests (progress_callback , opts .numWorkers , opts .maxTime )
315
+ except KeyboardInterrupt :
316
+ sys .exit (2 )
317
+ testing_time = time .time () - startTime
318
+
319
+ display .finish ()
320
+ return testing_time
321
+
323
322
def write_test_results (run , lit_config , testing_time , output_path ):
324
323
try :
325
324
import json
@@ -379,6 +378,7 @@ def write_test_results(run, lit_config, testing_time, output_path):
379
378
f .close ()
380
379
381
380
def write_test_results_xunit (run , opts ):
381
+ from xml .sax .saxutils import quoteattr
382
382
# Collect the tests, indexed by test suite
383
383
by_suite = {}
384
384
for result_test in run .tests :
0 commit comments