Added some basic test subprocess exception handling and remapped error messages to the e-mail

This commit is contained in:
Anton Mitrokhin
2014-07-04 15:19:45 +04:00
parent c2d65f7ad2
commit 4dacd7e7a2
2 changed files with 27 additions and 5 deletions

View File

@@ -473,7 +473,10 @@ def validation_run(only, only_targets, reference_branch, number, notify, update,
for i2 in range(0,len(opts)): for i2 in range(0,len(opts)):
stability.arch = arch[i1] stability.arch = arch[i1]
stability.no_opt = opts[i2] stability.no_opt = opts[i2]
execute_stability(stability, R, print_version) try:
execute_stability(stability, R, print_version)
except:
print_debug("Exception in execute_stability - maybe some test subprocess terminated before it should have\n", False, stability_log)
print_version = 0 print_version = 0
for j in range(0,len(sde_targets)): for j in range(0,len(sde_targets)):
stability.target = sde_targets[j][1] stability.target = sde_targets[j][1]
@@ -580,6 +583,8 @@ def validation_run(only, only_targets, reference_branch, number, notify, update,
f_lines = fp.readlines() f_lines = fp.readlines()
fp.close() fp.close()
line = "" line = ""
if not sys.exc_info()[0] == None:
line = line + "Last exception: " + str(sys.exc_info()) + '\n'
for i in range(0,len(f_lines)): for i in range(0,len(f_lines)):
line = line + f_lines[i][:-1] line = line + f_lines[i][:-1]
line = line + ' \n' line = line + ' \n'
@@ -664,6 +669,7 @@ from optparse import OptionParser
from optparse import OptionGroup from optparse import OptionGroup
import sys import sys
import os import os
import errno
import operator import operator
import time import time
import glob import glob

View File

@@ -59,10 +59,15 @@ def run_command(cmd):
lexer.whitespace_split = True lexer.whitespace_split = True
lexer.escape = '' lexer.escape = ''
arg_list = list(lexer) arg_list = list(lexer)
sp = subprocess.Popen(arg_list, stdin=None, try:
sp = subprocess.Popen(arg_list, stdin=None,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
except:
print_debug("ERROR: The child (%s) raised an esception: %s\n" % (cmd, sys.exc_info()[1]), s, run_tests_log)
raise
out = sp.communicate() out = sp.communicate()
output = "" output = ""
output += out[0].decode("utf-8") output += out[0].decode("utf-8")
@@ -325,7 +330,11 @@ def run_tasks_from_queue(queue, queue_ret, queue_skip, total_tests_arg, max_test
sys.exit(0) sys.exit(0)
if check_test(filename): if check_test(filename):
(compile_error, run_error) = run_test(filename) try:
(compile_error, run_error) = run_test(filename)
except:
sys.exit(-1) # This is in case the child has unexpectedly died
if compile_error != 0: if compile_error != 0:
compile_error_files += [ filename ] compile_error_files += [ filename ]
if run_error != 0: if run_error != 0:
@@ -646,8 +655,9 @@ def run_tests(options1, args, print_version):
task_threads = [0] * nthreads task_threads = [0] * nthreads
for x in range(nthreads): for x in range(nthreads):
task_threads[x] = multiprocessing.Process(target=run_tasks_from_queue, args=(q, qret, qskip, total_tests, task_threads[x] = multiprocessing.Process(target=run_tasks_from_queue, args=(q, qret, qskip, total_tests,
max_test_length, finished_tests_counter, finished_tests_counter_lock, glob_var)) max_test_length, finished_tests_counter, finished_tests_counter_lock, glob_var))
task_threads[x].start() task_threads[x].start()
# wait for them to all finish and then return the number that failed # wait for them to all finish and then return the number that failed
# (i.e. return 0 if all is ok) # (i.e. return 0 if all is ok)
for t in task_threads: for t in task_threads:
@@ -655,6 +665,12 @@ def run_tests(options1, args, print_version):
if options.non_interactive == False: if options.non_interactive == False:
print_debug("\n", s, run_tests_log) print_debug("\n", s, run_tests_log)
for jb in task_threads:
if not jb.exitcode == 0:
raise OSError(2, 'Some test subprocess has thrown an exception', '')
temp_time = (time.time() - start_time) temp_time = (time.time() - start_time)
elapsed_time = time.strftime('%Hh%Mm%Ssec.', time.gmtime(temp_time)) elapsed_time = time.strftime('%Hh%Mm%Ssec.', time.gmtime(temp_time))