summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-10-22 15:16:57 -0700
committerLei Zhang <thestig@chromium.org>2015-10-22 15:16:57 -0700
commit61fe6edb3f789feefa4bd0c8475b9645fae0d09e (patch)
treefe37d6faf6d3f948b26617669591f1011c137ec4 /testing
parent338805f1366dcdf9a5b48cf591541cf98d7490f1 (diff)
downloadpdfium-61fe6edb3f789feefa4bd0c8475b9645fae0d09e.tar.xz
Make parallelized run_corpus_tests.py handle ctrl-c.
Thanks Stack Overflow! R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1421623002 .
Diffstat (limited to 'testing')
-rwxr-xr-xtesting/tools/run_corpus_tests.py53
1 files changed, 32 insertions, 21 deletions
diff --git a/testing/tools/run_corpus_tests.py b/testing/tools/run_corpus_tests.py
index 3441da3a17..b6cbff7537 100755
--- a/testing/tools/run_corpus_tests.py
+++ b/testing/tools/run_corpus_tests.py
@@ -17,6 +17,8 @@ import common
import pngdiffer
import suppressor
+class KeyboardInterruptError(Exception): pass
+
# Nomenclature:
# x_root - "x"
# x_filename - "x.ext"
@@ -49,17 +51,20 @@ def test_one_file(input_filename, source_dir, working_dir,
def test_one_file_parallel(working_dir, pdfium_test_path, image_differ,
test_case):
"""Wrapper function to call test_one_file() and redirect output to stdout."""
- old_stdout = sys.stdout
- old_stderr = sys.stderr
- sys.stdout = cStringIO.StringIO()
- sys.stderr = sys.stdout
- input_filename, source_dir = test_case
- result = test_one_file(input_filename, source_dir, working_dir,
- pdfium_test_path, image_differ, True);
- output = sys.stdout
- sys.stdout = old_stdout
- sys.stderr = old_stderr
- return (result, output.getvalue(), input_filename, source_dir)
+ try:
+ old_stdout = sys.stdout
+ old_stderr = sys.stderr
+ sys.stdout = cStringIO.StringIO()
+ sys.stderr = sys.stdout
+ input_filename, source_dir = test_case
+ result = test_one_file(input_filename, source_dir, working_dir,
+ pdfium_test_path, image_differ, True);
+ output = sys.stdout
+ sys.stdout = old_stdout
+ sys.stderr = old_stderr
+ return (result, output.getvalue(), input_filename, source_dir)
+ except KeyboardInterrupt:
+ raise KeyboardInterruptError()
def handle_result(test_suppressor, input_filename, input_path, result,
@@ -107,16 +112,22 @@ def main():
test_cases.append((input_filename, source_dir))
if options.num_workers > 1:
- pool = multiprocessing.Pool(options.num_workers)
- worker_func = functools.partial(test_one_file_parallel, working_dir,
- pdfium_test_path, image_differ)
- worker_results = pool.imap(worker_func, test_cases)
- for worker_result in worker_results:
- result, output, input_filename, source_dir = worker_result
- input_path = os.path.join(source_dir, input_filename)
- sys.stdout.write(output)
- handle_result(test_suppressor, input_filename, input_path, result,
- surprises, failures)
+ try:
+ pool = multiprocessing.Pool(options.num_workers)
+ worker_func = functools.partial(test_one_file_parallel, working_dir,
+ pdfium_test_path, image_differ)
+ worker_results = pool.imap(worker_func, test_cases)
+ for worker_result in worker_results:
+ result, output, input_filename, source_dir = worker_result
+ input_path = os.path.join(source_dir, input_filename)
+ sys.stdout.write(output)
+ handle_result(test_suppressor, input_filename, input_path, result,
+ surprises, failures)
+ pool.close()
+ except KeyboardInterrupt:
+ pool.terminate()
+ finally:
+ pool.join()
else:
for test_case in test_cases:
input_filename, source_dir = test_case