From 85586ce1ba3ceaabd160882a922994125efba79b Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Sun, 16 Nov 2014 17:11:00 +0000 Subject: Signal handling for run_tests.py SIGINT and SIGTERM are handled, causing further test execution to stop and the results to be printed immediately. Also cleans up prebuilt objects --- run_tests.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'run_tests.py') diff --git a/run_tests.py b/run_tests.py index 8ed0f69..671289b 100755 --- a/run_tests.py +++ b/run_tests.py @@ -15,7 +15,7 @@ # limitations under the License. from glob import glob -import os, subprocess, shutil, sys, platform +import os, subprocess, shutil, sys, platform, signal import environment from environment import is_windows @@ -27,6 +27,17 @@ test_build_dir = 'work area' install_dir = os.path.join(os.path.split(os.path.abspath(__file__))[0], 'install dir') meson_command = './meson.py' +class StopException(Exception): + def __init__(self): + super(Exception, self).__init__('Stopped by user') + +stop = False +def stop_handler(signal, frame): + global stop + stop = True +signal.signal(signal.SIGINT, stop_handler) +signal.signal(signal.SIGTERM, stop_handler) + #unity_flags = ['--unity'] unity_flags = [] msbuild_exe = shutil.which('msbuild') @@ -93,7 +104,7 @@ def validate_install(srcdir, installdir): return '' def run_and_log(logfile, testdir, should_succeed=True): - global passing_tests, failing_tests + global passing_tests, failing_tests, stop (msg, stdo, stde) = run_test(testdir, should_succeed) if msg != '': print('Fail:', msg) @@ -109,6 +120,8 @@ def run_and_log(logfile, testdir, should_succeed=True): if print_debug: print(stdo) print(stde, file=sys.stderr) + if stop: + raise StopException() def run_test(testdir, should_succeed): global compile_commands @@ -309,7 +322,10 @@ if __name__ == '__main__': os.chdir(script_dir) check_format() pbfile = generate_prebuilt_object() - run_tests() + try: + run_tests() + except StopException: + pass os.unlink(pbfile) print('\nTotal passed tests:', passing_tests) print('Total failed tests:', failing_tests) -- cgit v1.1