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
pull/24/head
Robin McCorkell 10 years ago
parent 46773e75a8
commit 85586ce1ba
  1. 22
      run_tests.py

@ -15,7 +15,7 @@
# limitations under the License. # limitations under the License.
from glob import glob from glob import glob
import os, subprocess, shutil, sys, platform import os, subprocess, shutil, sys, platform, signal
import environment import environment
from environment import is_windows 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') install_dir = os.path.join(os.path.split(os.path.abspath(__file__))[0], 'install dir')
meson_command = './meson.py' 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 = ['--unity']
unity_flags = [] unity_flags = []
msbuild_exe = shutil.which('msbuild') msbuild_exe = shutil.which('msbuild')
@ -93,7 +104,7 @@ def validate_install(srcdir, installdir):
return '' return ''
def run_and_log(logfile, testdir, should_succeed=True): 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) (msg, stdo, stde) = run_test(testdir, should_succeed)
if msg != '': if msg != '':
print('Fail:', msg) print('Fail:', msg)
@ -109,6 +120,8 @@ def run_and_log(logfile, testdir, should_succeed=True):
if print_debug: if print_debug:
print(stdo) print(stdo)
print(stde, file=sys.stderr) print(stde, file=sys.stderr)
if stop:
raise StopException()
def run_test(testdir, should_succeed): def run_test(testdir, should_succeed):
global compile_commands global compile_commands
@ -309,7 +322,10 @@ if __name__ == '__main__':
os.chdir(script_dir) os.chdir(script_dir)
check_format() check_format()
pbfile = generate_prebuilt_object() pbfile = generate_prebuilt_object()
run_tests() try:
run_tests()
except StopException:
pass
os.unlink(pbfile) os.unlink(pbfile)
print('\nTotal passed tests:', passing_tests) print('\nTotal passed tests:', passing_tests)
print('Total failed tests:', failing_tests) print('Total failed tests:', failing_tests)

Loading…
Cancel
Save