oeqa/logparser: Improve results handling

Merge the results handling into the ptest log parser as a seperate
method.

Drop the weird "pass.skip.fail." prefix to the results filename, its
just bizarre.

Drop the code turning a list into a regex then searching the regex for
an item, "x in y" is perfectly capable.

Use a dict, sort the keys as needed and drop the list sorting code.

(From OE-Core rev: f317800e950b4a37b4034133bc52e0c47f04dc29)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie 2019-01-29 15:08:58 +00:00
parent 3731033435
commit 54d4694f32
2 changed files with 19 additions and 40 deletions

View File

@ -49,8 +49,9 @@ class PtestRunnerTest(OERuntimeTestCase):
extras['ptestresult.rawlogs'] = {'log': output}
# Parse and save results
parse_result, sections = PtestParser().parse(ptest_runner_log)
parse_result.log_as_files(ptest_log_dir, test_status = ['pass','fail', 'skip'])
parser = PtestParser()
results, sections = parser.parse(ptest_runner_log)
parser.results_as_files(ptest_log_dir, test_status = ['pass','fail', 'skip'])
if os.path.exists(ptest_log_dir_link):
# Remove the old link to create a new one
os.remove(ptest_log_dir_link)
@ -60,14 +61,15 @@ class PtestRunnerTest(OERuntimeTestCase):
trans = str.maketrans("()", "__")
resmap = {'pass': 'PASSED', 'skip': 'SKIPPED', 'fail': 'FAILED'}
for section in parse_result.result_dict:
for test, result in parse_result.result_dict[section]:
for section in results:
for test in results[section]:
result = results[section][test]
testname = "ptestresult." + (section or "No-section") + "." + "_".join(test.translate(trans).split())
extras[testname] = {'status': resmap[result]}
failed_tests = {}
for section in parse_result.result_dict:
failed_testcases = [ "_".join(test.translate(trans).split()) for test, result in parse_result.result_dict[section] if result == 'fail' ]
for section in results:
failed_testcases = [ "_".join(test.translate(trans).split()) for test in results[section] if results[section][test] == 'fail' ]
if failed_testcases:
failed_tests[section] = failed_testcases

View File

@ -8,7 +8,7 @@ from . import ftools
# A parser that can be used to identify weather a line is a test result or a section statement.
class PtestParser(object):
def __init__(self):
self.results = Result()
self.results = {}
self.sections = {}
def parse(self, logfile):
@ -65,52 +65,29 @@ class PtestParser(object):
for t in test_regex:
result = test_regex[t].search(line)
if result:
self.results.store(current_section['name'], result.group(1), t)
if current_section['name'] not in self.results:
self.results[current_section['name']] = {}
self.results[current_section['name']][result.group(1)] = t
self.results.sort_tests()
return self.results, self.sections
class Result(object):
def __init__(self):
self.result_dict = {}
def store(self, section, test, status):
if not section in self.result_dict:
self.result_dict[section] = []
self.result_dict[section].append((test, status))
# sort tests by the test name(the first element of the tuple), for each section. This can be helpful when using git to diff for changes by making sure they are always in the same order.
def sort_tests(self):
for package in self.result_dict:
sorted_results = sorted(self.result_dict[package], key=lambda tup: tup[0])
self.result_dict[package] = sorted_results
# Log the results as files. The file name is the section name and the contents are the tests in that section.
def log_as_files(self, target_dir, test_status):
status_regex = re.compile('|'.join(map(str, test_status)))
def results_as_files(self, target_dir, test_status):
if not type(test_status) == type([]):
raise Exception("test_status should be a list. Got " + str(test_status) + " instead.")
if not os.path.exists(target_dir):
raise Exception("Target directory does not exist: %s" % target_dir)
for section, test_results in self.result_dict.items():
prefix = ''
for x in test_status:
prefix +=x+'.'
for section in self.results:
prefix = 'No-section'
if section:
prefix += section
prefix = section
section_file = os.path.join(target_dir, prefix)
# purge the file contents if it exists
open(section_file, 'w').close()
for test_result in test_results:
(test_name, status) = test_result
for test_name in sorted(self.results[section]):
status = self.results[section][test_name]
# we log only the tests with status in the test_status list
match_status = status_regex.search(status)
if match_status:
if status in test_status:
ftools.append_file(section_file, status + ": " + test_name)
# Not yet implemented!
def log_to_lava(self):
pass