Bug 638219 - Pass jit-test script options around as an argument. r=terrence

This commit is contained in:
Dirkjan Ochtman 2013-01-23 18:17:08 +01:00
parent 31e3e8b6f0
commit 62d88391a4

View File

@ -237,7 +237,7 @@ def run_cmd_avoid_stdio(cmdline, env, timeout):
_, __, code = run_timeout_cmd(cmdline, { 'env': env }, timeout) _, __, code = run_timeout_cmd(cmdline, { 'env': env }, timeout)
return read_and_unlink(stdoutPath), read_and_unlink(stderrPath), code return read_and_unlink(stdoutPath), read_and_unlink(stderrPath), code
def run_test(test, lib_dir, shell_args): def run_test(test, lib_dir, shell_args, options):
cmd = get_test_cmd(test.path, test.jitflags, lib_dir, shell_args) cmd = get_test_cmd(test.path, test.jitflags, lib_dir, shell_args)
if (test.valgrind and if (test.valgrind and
@ -254,10 +254,10 @@ def run_test(test, lib_dir, shell_args):
valgrind_prefix += ['--dsymutil=yes'] valgrind_prefix += ['--dsymutil=yes']
cmd = valgrind_prefix + cmd cmd = valgrind_prefix + cmd
if OPTIONS.show_cmd: if options.show_cmd:
print(subprocess.list2cmdline(cmd)) print(subprocess.list2cmdline(cmd))
if OPTIONS.avoid_stdio: if options.avoid_stdio:
run = run_cmd_avoid_stdio run = run_cmd_avoid_stdio
else: else:
run = run_cmd run = run_cmd
@ -266,9 +266,9 @@ def run_test(test, lib_dir, shell_args):
if test.tz_pacific: if test.tz_pacific:
env['TZ'] = 'PST8PDT' env['TZ'] = 'PST8PDT'
out, err, code, timed_out = run(cmd, env, OPTIONS.timeout) out, err, code, timed_out = run(cmd, env, options.timeout)
if OPTIONS.show_output: if options.show_output:
sys.stdout.write(out) sys.stdout.write(out)
sys.stdout.write(err) sys.stdout.write(err)
sys.stdout.write('Exit code: %s\n' % code) sys.stdout.write('Exit code: %s\n' % code)
@ -310,19 +310,17 @@ def print_tinderbox(label, test, message=None):
def wrap_parallel_run_test(test, lib_dir, shell_args, resultQueue, options, js): def wrap_parallel_run_test(test, lib_dir, shell_args, resultQueue, options, js):
# This is necessary because on Windows global variables are not automatically # This is necessary because on Windows global variables are not automatically
# available in the children, while on Linux and OSX this is the case (because of fork). # available in the children, while on Linux and OSX this is the case (because of fork).
global OPTIONS
global JS global JS
OPTIONS = options
JS = js JS = js
# Ignore SIGINT in the child # Ignore SIGINT in the child
signal.signal(signal.SIGINT, signal.SIG_IGN) signal.signal(signal.SIGINT, signal.SIG_IGN)
result = run_test(test, lib_dir, shell_args) + (test,) result = run_test(test, lib_dir, shell_args, options) + (test,)
resultQueue.put(result) resultQueue.put(result)
return result return result
def run_tests_parallel(tests, test_dir, lib_dir, shell_args): def run_tests_parallel(tests, test_dir, lib_dir, shell_args, options):
# This queue will contain the results of the various tests run. # This queue will contain the results of the various tests run.
# We could make this queue a global variable instead of using # We could make this queue a global variable instead of using
# a manager to share, but this will not work on Windows. # a manager to share, but this will not work on Windows.
@ -340,7 +338,7 @@ def run_tests_parallel(tests, test_dir, lib_dir, shell_args):
result_process_return_queue = queue_manager.Queue() result_process_return_queue = queue_manager.Queue()
result_process = Process(target=process_test_results_parallel, result_process = Process(target=process_test_results_parallel,
args=(async_test_result_queue, result_process_return_queue, args=(async_test_result_queue, result_process_return_queue,
notify_queue, len(tests), OPTIONS, JS, lib_dir, shell_args)) notify_queue, len(tests), options, JS, lib_dir, shell_args))
result_process.start() result_process.start()
# Ensure that a SIGTERM is handled the same way as SIGINT # Ensure that a SIGTERM is handled the same way as SIGINT
@ -362,7 +360,7 @@ def run_tests_parallel(tests, test_dir, lib_dir, shell_args):
try: try:
testcnt = 0 testcnt = 0
# Initially start as many jobs as allowed to run parallel # Initially start as many jobs as allowed to run parallel
for i in range(min(OPTIONS.max_jobs,len(tests))): for i in range(min(options.max_jobs,len(tests))):
notify_queue.put(True) notify_queue.put(True)
# For every item in the notify queue, start one new worker. # For every item in the notify queue, start one new worker.
@ -370,7 +368,7 @@ def run_tests_parallel(tests, test_dir, lib_dir, shell_args):
while notify_queue.get(): while notify_queue.get():
if (testcnt < len(tests)): if (testcnt < len(tests)):
# Start one new worker # Start one new worker
worker_process = Process(target=wrap_parallel_run_test, args=(tests[testcnt], lib_dir, shell_args, async_test_result_queue, OPTIONS, JS)) worker_process = Process(target=wrap_parallel_run_test, args=(tests[testcnt], lib_dir, shell_args, async_test_result_queue, options, JS))
worker_processes.append(worker_process) worker_processes.append(worker_process)
worker_process.start() worker_process.start()
testcnt += 1 testcnt += 1
@ -519,19 +517,19 @@ def process_test_results(results, num_tests, options, js, lib_dir, shell_args):
return print_test_summary(failures, complete, doing, options, lib_dir, shell_args) return print_test_summary(failures, complete, doing, options, lib_dir, shell_args)
def get_serial_results(tests, lib_dir, shell_args): def get_serial_results(tests, lib_dir, shell_args, options):
for test in tests: for test in tests:
result = run_test(test, lib_dir, shell_args) result = run_test(test, lib_dir, shell_args, options)
yield result + (test,) yield result + (test,)
def run_tests(tests, test_dir, lib_dir, shell_args): def run_tests(tests, test_dir, lib_dir, shell_args, options):
gen = get_serial_results(tests, lib_dir, shell_args) gen = get_serial_results(tests, lib_dir, shell_args, options)
ok = process_test_results(gen, len(tests), OPTIONS, JS, lib_dir, shell_args) ok = process_test_results(gen, len(tests), options, JS, lib_dir, shell_args)
return ok return ok
def parse_jitflags(): def parse_jitflags(options):
jitflags = [ [ '-' + flag for flag in flags ] jitflags = [ [ '-' + flag for flag in flags ]
for flags in OPTIONS.jitflags.split(',') ] for flags in options.jitflags.split(',') ]
for flags in jitflags: for flags in jitflags:
for flag in flags: for flag in flags:
if flag not in ('-m', '-a', '-p', '-d', '-n'): if flag not in ('-m', '-a', '-p', '-d', '-n'):
@ -554,9 +552,8 @@ def stdio_might_be_broken():
return platform_might_be_android() return platform_might_be_android()
JS = None JS = None
OPTIONS = None
def main(argv): def main(argv):
global JS, OPTIONS global JS
script_path = os.path.abspath(sys.modules['__main__'].__file__) script_path = os.path.abspath(sys.modules['__main__'].__file__)
script_dir = os.path.dirname(script_path) script_dir = os.path.dirname(script_path)
@ -620,7 +617,7 @@ def main(argv):
op.add_option('-j', '--worker-count', dest='max_jobs', type=int, default=max_jobs_default, op.add_option('-j', '--worker-count', dest='max_jobs', type=int, default=max_jobs_default,
help='Number of tests to run in parallel (default %default)') help='Number of tests to run in parallel (default %default)')
(OPTIONS, args) = op.parse_args(argv) options, args = op.parse_args(argv)
if len(args) < 1: if len(args) < 1:
op.error('missing JS_SHELL argument') op.error('missing JS_SHELL argument')
# We need to make sure we are using backslashes on Windows. # We need to make sure we are using backslashes on Windows.
@ -634,11 +631,11 @@ def main(argv):
# #
# XXX technically we could check for broken stdio, but it # XXX technically we could check for broken stdio, but it
# really seems like overkill. # really seems like overkill.
OPTIONS.avoid_stdio = True options.avoid_stdio = True
if OPTIONS.retest: if options.retest:
OPTIONS.read_tests = OPTIONS.retest options.read_tests = options.retest
OPTIONS.write_failures = OPTIONS.retest options.write_failures = options.retest
test_list = [] test_list = []
read_all = True read_all = True
@ -648,28 +645,28 @@ def main(argv):
for arg in test_args: for arg in test_args:
test_list += find_tests(test_dir, arg) test_list += find_tests(test_dir, arg)
if OPTIONS.read_tests: if options.read_tests:
read_all = False read_all = False
try: try:
f = open(OPTIONS.read_tests) f = open(options.read_tests)
for line in f: for line in f:
test_list.append(os.path.join(test_dir, line.strip('\n'))) test_list.append(os.path.join(test_dir, line.strip('\n')))
f.close() f.close()
except IOError: except IOError:
if OPTIONS.retest: if options.retest:
read_all = True read_all = True
else: else:
sys.stderr.write("Exception thrown trying to read test file '%s'\n"% sys.stderr.write("Exception thrown trying to read test file '%s'\n"%
OPTIONS.read_tests) options.read_tests)
traceback.print_exc() traceback.print_exc()
sys.stderr.write('---\n') sys.stderr.write('---\n')
if read_all: if read_all:
test_list = find_tests(test_dir) test_list = find_tests(test_dir)
if OPTIONS.exclude: if options.exclude:
exclude_list = [] exclude_list = []
for exclude in OPTIONS.exclude: for exclude in options.exclude:
exclude_list += find_tests(test_dir, exclude) exclude_list += find_tests(test_dir, exclude)
test_list = [ test for test in test_list if test not in set(exclude_list) ] test_list = [ test for test in test_list if test not in set(exclude_list) ]
@ -677,14 +674,14 @@ def main(argv):
print("No tests found matching command line arguments.", file=sys.stderr) print("No tests found matching command line arguments.", file=sys.stderr)
sys.exit(0) sys.exit(0)
test_list = [ Test.from_file(_, OPTIONS) for _ in test_list ] test_list = [ Test.from_file(_, options) for _ in test_list ]
if not OPTIONS.run_slow: if not options.run_slow:
test_list = [ _ for _ in test_list if not _.slow ] test_list = [ _ for _ in test_list if not _.slow ]
# The full test list is ready. Now create copies for each JIT configuration. # The full test list is ready. Now create copies for each JIT configuration.
job_list = [] job_list = []
if OPTIONS.tbpl: if options.tbpl:
# Running all bits would take forever. Instead, we test a few interesting combinations. # Running all bits would take forever. Instead, we test a few interesting combinations.
flags = [ flags = [
['--no-jm'], ['--no-jm'],
@ -704,7 +701,7 @@ def main(argv):
new_test = test.copy() new_test = test.copy()
new_test.jitflags.extend(variant) new_test.jitflags.extend(variant)
job_list.append(new_test) job_list.append(new_test)
elif OPTIONS.ion: elif options.ion:
flags = [['--no-jm'], ['--ion-eager']] flags = [['--no-jm'], ['--ion-eager']]
for test in test_list: for test in test_list:
for variant in flags: for variant in flags:
@ -712,16 +709,16 @@ def main(argv):
new_test.jitflags.extend(variant) new_test.jitflags.extend(variant)
job_list.append(new_test) job_list.append(new_test)
else: else:
jitflags_list = parse_jitflags() jitflags_list = parse_jitflags(options)
for test in test_list: for test in test_list:
for jitflags in jitflags_list: for jitflags in jitflags_list:
new_test = test.copy() new_test = test.copy()
new_test.jitflags.extend(jitflags) new_test.jitflags.extend(jitflags)
job_list.append(new_test) job_list.append(new_test)
shell_args = shlex.split(OPTIONS.shell_args) shell_args = shlex.split(options.shell_args)
if OPTIONS.debug: if options.debug:
if len(job_list) > 1: if len(job_list) > 1:
print('Multiple tests match command line arguments, debugger can only run one') print('Multiple tests match command line arguments, debugger can only run one')
for tc in job_list: for tc in job_list:
@ -735,10 +732,10 @@ def main(argv):
try: try:
ok = None ok = None
if OPTIONS.max_jobs > 1 and HAVE_MULTIPROCESSING: if options.max_jobs > 1 and HAVE_MULTIPROCESSING:
ok = run_tests_parallel(job_list, test_dir, lib_dir, shell_args) ok = run_tests_parallel(job_list, test_dir, lib_dir, shell_args, options)
else: else:
ok = run_tests(job_list, test_dir, lib_dir, shell_args) ok = run_tests(job_list, test_dir, lib_dir, shell_args, options)
if not ok: if not ok:
sys.exit(2) sys.exit(2)
except OSError: except OSError: