Skip to content

Commit e51f90d

Browse files
joaocgreisrvagg
authored andcommitted
test: option to run a subset of tests
With this option, tests can be divided in groups and only one is run from each group. This enables us to parallelize the tests across multiple machines. PR-URL: #2260 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Rod Vagg <[email protected]> Reviewed-By: Alexis Campailla <[email protected]>
1 parent ccf12df commit e51f90d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tools/test.py

+30
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,9 @@ def BuildOptions():
12721272
result.add_option("--no-store-unexpected-output",
12731273
help="Deletes the temporary JS files from tests that fails",
12741274
dest="store_unexpected_output", action="store_false")
1275+
result.add_option("-r", "--run",
1276+
help="Divide the tests in m groups (interleaved) and run tests from group n (--run=n,m with n < m)",
1277+
default="")
12751278
return result
12761279

12771280

@@ -1280,6 +1283,24 @@ def ProcessOptions(options):
12801283
VERBOSE = options.verbose
12811284
options.arch = options.arch.split(',')
12821285
options.mode = options.mode.split(',')
1286+
options.run = options.run.split(',')
1287+
if options.run == [""]:
1288+
options.run = None
1289+
elif len(options.run) != 2:
1290+
print "The run argument must be two comma-separated integers."
1291+
return False
1292+
else:
1293+
try:
1294+
options.run = map(int, options.run)
1295+
except ValueError:
1296+
print "Could not parse the integers from the run argument."
1297+
return False
1298+
if options.run[0] < 0 or options.run[1] < 0:
1299+
print "The run argument cannot have negative integers."
1300+
return False
1301+
if options.run[0] >= options.run[1]:
1302+
print "The test group to run (n) must be smaller than number of groups (m)."
1303+
return False
12831304
if options.J:
12841305
options.j = multiprocessing.cpu_count()
12851306
return True
@@ -1486,6 +1507,15 @@ def Main():
14861507
def DoSkip(case):
14871508
return SKIP in case.outcomes or SLOW in case.outcomes
14881509
cases_to_run = [ c for c in all_cases if not DoSkip(c) ]
1510+
if options.run is not None:
1511+
# Must ensure the list of tests is sorted before selecting, to avoid
1512+
# silent errors if this file is changed to list the tests in a way that
1513+
# can be different in different machines
1514+
cases_to_run.sort(key=lambda c: (c.case.arch, c.case.mode, c.case.file))
1515+
cases_to_run = [ cases_to_run[i] for i
1516+
in xrange(options.run[0],
1517+
len(cases_to_run),
1518+
options.run[1]) ]
14891519
if len(cases_to_run) == 0:
14901520
print "No tests to run."
14911521
return 1

0 commit comments

Comments
 (0)