Refactoring of report exporter to support HTML and JUNIT: Fixed issues with non ASCII characters read from serial port in ProcessObserver. Also changed reporting for errors and failures in TestSuite JUnit class

pull/561/merge
Przemek Wirkus 2014-10-15 16:05:57 +01:00
parent 2274651892
commit 50966fdf89
2 changed files with 43 additions and 22 deletions

View File

@ -873,6 +873,34 @@ class SingleTestRunner(object):
Function also is pooling for serial port activity from process to catch all data Function also is pooling for serial port activity from process to catch all data
printed by test runner and host test during test execution printed by test runner and host test during test execution
""" """
def get_char_from_queue(obs):
""" Get character from queue safe way
"""
try:
c = obs.queue.get(block=True, timeout=0.5)
except Empty, _:
c = None
return c
def filter_queue_char(c):
""" Filters out non ASCII characters from serial port
"""
if ord(c) not in range(128):
c = ' '
return c
def get_test_result(output):
""" Parse test 'output' data
"""
result = self.TEST_RESULT_TIMEOUT
for line in "".join(output).splitlines():
search_result = self.RE_DETECT_TESTCASE_RESULT.search(line)
if search_result and len(search_result.groups()):
result = self.TEST_RESULT_MAPPING[search_result.groups(0)[0]]
break
return result
# print "{%s} port:%s disk:%s" % (name, port, disk), # print "{%s} port:%s disk:%s" % (name, port, disk),
cmd = ["python", "%s.py" % name, '-p', port, '-d', disk, '-t', str(duration)] cmd = ["python", "%s.py" % name, '-p', port, '-d', disk, '-t', str(duration)]
@ -896,15 +924,13 @@ class SingleTestRunner(object):
line = '' line = ''
output = [] output = []
while (time() - start_time) < duration: while (time() - start_time) < duration:
try: c = get_char_from_queue(obs)
c = obs.queue.get(block=True, timeout=0.5)
except Empty, _:
c = None
if c: if c:
output.append(c)
if verbose: if verbose:
sys.stdout.write(c) sys.stdout.write(c)
c = filter_queue_char(c)
output.append(c)
# Give the mbed under test a way to communicate the end of the test # Give the mbed under test a way to communicate the end of the test
if c in ['\n', '\r']: if c in ['\n', '\r']:
if '{end}' in line: if '{end}' in line:
@ -913,28 +939,20 @@ class SingleTestRunner(object):
else: else:
line += c line += c
try: c = get_char_from_queue(obs)
c = obs.queue.get(block=True, timeout=0.5)
except Empty, _:
c = None
if c: if c:
output.append(c)
if verbose: if verbose:
sys.stdout.write(c) sys.stdout.write(c)
c = filter_queue_char(c)
output.append(c)
if verbose: if verbose:
print "Test::Output::Finish" print "Test::Output::Finish"
# Stop test process # Stop test process
obs.stop() obs.stop()
# Parse test 'output' data result = get_test_result(output)
result = self.TEST_RESULT_TIMEOUT
for line in "".join(output).splitlines():
search_result = self.RE_DETECT_TESTCASE_RESULT.search(line)
if search_result and len(search_result.groups()):
result = self.TEST_RESULT_MAPPING[search_result.groups(0)[0]]
break
return result, "".join(output) return result, "".join(output)
def is_peripherals_available(self, target_mcu_name, peripherals=None): def is_peripherals_available(self, target_mcu_name, peripherals=None):

View File

@ -104,6 +104,7 @@ class ReportExporter():
tooltip_name = self.get_tooltip_name(test['toolchain_name'], test['target_name'], test['test_id'], test_no) tooltip_name = self.get_tooltip_name(test['toolchain_name'], test['target_name'], test['test_id'], test_no)
background_color = RESULT_COLORS[test['single_test_result'] if test['single_test_result'] in RESULT_COLORS else 'ERROR'] background_color = RESULT_COLORS[test['single_test_result'] if test['single_test_result'] in RESULT_COLORS else 'ERROR']
result_div_style = "background-color: %s"% background_color result_div_style = "background-color: %s"% background_color
result = """<div class="name" style="%s" onmouseover="show(%s)" onmouseout="hide(%s)"> result = """<div class="name" style="%s" onmouseover="show(%s)" onmouseout="hide(%s)">
<center>%s</center> <center>%s</center>
<div class = "tooltip" id= "%s"> <div class = "tooltip" id= "%s">
@ -121,7 +122,7 @@ class ReportExporter():
tooltip_name, tooltip_name,
test['test_description'], test['test_description'],
test['elapsed_time'], test['elapsed_time'],
unicode(test['single_test_output'], errors='ignore').replace('\n', '<br />')) test['single_test_output'].replace('\n', '<br />'))
return result return result
def get_result_tree(self, test_results): def get_result_tree(self, test_results):
@ -216,17 +217,19 @@ class ReportExporter():
name = test_result['test_description'] name = test_result['test_description']
classname = 'test.%s.%s.%s'% (target, toolchain, test_result['test_id']) classname = 'test.%s.%s.%s'% (target, toolchain, test_result['test_id'])
elapsed_sec = test_result['elapsed_time'] elapsed_sec = test_result['elapsed_time']
_stdout = unicode(test_result['single_test_output'], errors='ignore') _stdout = test_result['single_test_output']
_stderr = '' _stderr = ''
tc = TestCase(name, classname, elapsed_sec, _stdout, _stderr) tc = TestCase(name, classname, elapsed_sec, _stdout, _stderr)
# Add extra failure / error info to test case result # Add extra failure / error info to test case result
if test_result['single_test_result'] == 'FAIL': if test_result['single_test_result'] == 'FAIL':
tc.add_failure_info('Test failed', 'Test result: %s'% test_result['single_test_result']) message = test_result['single_test_result']
tc.add_failure_info(message, _stdout)
elif test_result['single_test_result'] != 'OK': elif test_result['single_test_result'] != 'OK':
tc.add_error_info('Test error', 'Test result: %s'% test_result['single_test_result']) message = test_result['single_test_result']
tc.add_error_info(message, _stdout)
test_cases.append(tc) test_cases.append(tc)
ts = TestSuite("test.suite.%s.%s"% (target, toolchain), test_cases, properties=test_suite_properties[target][toolchain]) ts = TestSuite("test.suite.%s.%s"% (target, toolchain), test_cases, properties=test_suite_properties[target][toolchain])
test_suites.append(ts) test_suites.append(ts)
return TestSuite.to_xml_string(test_suites, encoding='utf8') return TestSuite.to_xml_string(test_suites)