diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-01-29 15:08:58 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-01-31 23:23:26 +0000 |
commit | 54d4694f328a4ae07955aa68dcb6d3c183ed2edd (patch) | |
tree | 889ae89d6de707f1da3736e19c44065db5a0db88 /meta/lib | |
parent | 3731033435b6a432b9a67da54f09761288c211e4 (diff) | |
download | poky-54d4694f328a4ae07955aa68dcb6d3c183ed2edd.tar.gz |
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>
Diffstat (limited to 'meta/lib')
-rw-r--r-- | meta/lib/oeqa/runtime/cases/ptest.py | 14 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/logparser.py | 45 |
2 files changed, 19 insertions, 40 deletions
diff --git a/meta/lib/oeqa/runtime/cases/ptest.py b/meta/lib/oeqa/runtime/cases/ptest.py index 3cfd7af7e2..2843953b38 100644 --- a/meta/lib/oeqa/runtime/cases/ptest.py +++ b/meta/lib/oeqa/runtime/cases/ptest.py | |||
@@ -49,8 +49,9 @@ class PtestRunnerTest(OERuntimeTestCase): | |||
49 | extras['ptestresult.rawlogs'] = {'log': output} | 49 | extras['ptestresult.rawlogs'] = {'log': output} |
50 | 50 | ||
51 | # Parse and save results | 51 | # Parse and save results |
52 | parse_result, sections = PtestParser().parse(ptest_runner_log) | 52 | parser = PtestParser() |
53 | parse_result.log_as_files(ptest_log_dir, test_status = ['pass','fail', 'skip']) | 53 | results, sections = parser.parse(ptest_runner_log) |
54 | parser.results_as_files(ptest_log_dir, test_status = ['pass','fail', 'skip']) | ||
54 | if os.path.exists(ptest_log_dir_link): | 55 | if os.path.exists(ptest_log_dir_link): |
55 | # Remove the old link to create a new one | 56 | # Remove the old link to create a new one |
56 | os.remove(ptest_log_dir_link) | 57 | os.remove(ptest_log_dir_link) |
@@ -60,14 +61,15 @@ class PtestRunnerTest(OERuntimeTestCase): | |||
60 | 61 | ||
61 | trans = str.maketrans("()", "__") | 62 | trans = str.maketrans("()", "__") |
62 | resmap = {'pass': 'PASSED', 'skip': 'SKIPPED', 'fail': 'FAILED'} | 63 | resmap = {'pass': 'PASSED', 'skip': 'SKIPPED', 'fail': 'FAILED'} |
63 | for section in parse_result.result_dict: | 64 | for section in results: |
64 | for test, result in parse_result.result_dict[section]: | 65 | for test in results[section]: |
66 | result = results[section][test] | ||
65 | testname = "ptestresult." + (section or "No-section") + "." + "_".join(test.translate(trans).split()) | 67 | testname = "ptestresult." + (section or "No-section") + "." + "_".join(test.translate(trans).split()) |
66 | extras[testname] = {'status': resmap[result]} | 68 | extras[testname] = {'status': resmap[result]} |
67 | 69 | ||
68 | failed_tests = {} | 70 | failed_tests = {} |
69 | for section in parse_result.result_dict: | 71 | for section in results: |
70 | failed_testcases = [ "_".join(test.translate(trans).split()) for test, result in parse_result.result_dict[section] if result == 'fail' ] | 72 | failed_testcases = [ "_".join(test.translate(trans).split()) for test in results[section] if results[section][test] == 'fail' ] |
71 | if failed_testcases: | 73 | if failed_testcases: |
72 | failed_tests[section] = failed_testcases | 74 | failed_tests[section] = failed_testcases |
73 | 75 | ||
diff --git a/meta/lib/oeqa/utils/logparser.py b/meta/lib/oeqa/utils/logparser.py index dddea14fc9..8585c195c4 100644 --- a/meta/lib/oeqa/utils/logparser.py +++ b/meta/lib/oeqa/utils/logparser.py | |||
@@ -8,7 +8,7 @@ from . import ftools | |||
8 | # A parser that can be used to identify weather a line is a test result or a section statement. | 8 | # A parser that can be used to identify weather a line is a test result or a section statement. |
9 | class PtestParser(object): | 9 | class PtestParser(object): |
10 | def __init__(self): | 10 | def __init__(self): |
11 | self.results = Result() | 11 | self.results = {} |
12 | self.sections = {} | 12 | self.sections = {} |
13 | 13 | ||
14 | def parse(self, logfile): | 14 | def parse(self, logfile): |
@@ -65,52 +65,29 @@ class PtestParser(object): | |||
65 | for t in test_regex: | 65 | for t in test_regex: |
66 | result = test_regex[t].search(line) | 66 | result = test_regex[t].search(line) |
67 | if result: | 67 | if result: |
68 | self.results.store(current_section['name'], result.group(1), t) | 68 | if current_section['name'] not in self.results: |
69 | self.results[current_section['name']] = {} | ||
70 | self.results[current_section['name']][result.group(1)] = t | ||
69 | 71 | ||
70 | self.results.sort_tests() | ||
71 | return self.results, self.sections | 72 | return self.results, self.sections |
72 | 73 | ||
73 | class Result(object): | ||
74 | |||
75 | def __init__(self): | ||
76 | self.result_dict = {} | ||
77 | |||
78 | def store(self, section, test, status): | ||
79 | if not section in self.result_dict: | ||
80 | self.result_dict[section] = [] | ||
81 | |||
82 | self.result_dict[section].append((test, status)) | ||
83 | |||
84 | # 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. | ||
85 | def sort_tests(self): | ||
86 | for package in self.result_dict: | ||
87 | sorted_results = sorted(self.result_dict[package], key=lambda tup: tup[0]) | ||
88 | self.result_dict[package] = sorted_results | ||
89 | |||
90 | # Log the results as files. The file name is the section name and the contents are the tests in that section. | 74 | # Log the results as files. The file name is the section name and the contents are the tests in that section. |
91 | def log_as_files(self, target_dir, test_status): | 75 | def results_as_files(self, target_dir, test_status): |
92 | status_regex = re.compile('|'.join(map(str, test_status))) | ||
93 | if not type(test_status) == type([]): | 76 | if not type(test_status) == type([]): |
94 | raise Exception("test_status should be a list. Got " + str(test_status) + " instead.") | 77 | raise Exception("test_status should be a list. Got " + str(test_status) + " instead.") |
95 | if not os.path.exists(target_dir): | 78 | if not os.path.exists(target_dir): |
96 | raise Exception("Target directory does not exist: %s" % target_dir) | 79 | raise Exception("Target directory does not exist: %s" % target_dir) |
97 | 80 | ||
98 | for section, test_results in self.result_dict.items(): | 81 | for section in self.results: |
99 | prefix = '' | 82 | prefix = 'No-section' |
100 | for x in test_status: | ||
101 | prefix +=x+'.' | ||
102 | if section: | 83 | if section: |
103 | prefix += section | 84 | prefix = section |
104 | section_file = os.path.join(target_dir, prefix) | 85 | section_file = os.path.join(target_dir, prefix) |
105 | # purge the file contents if it exists | 86 | # purge the file contents if it exists |
106 | open(section_file, 'w').close() | 87 | open(section_file, 'w').close() |
107 | for test_result in test_results: | 88 | for test_name in sorted(self.results[section]): |
108 | (test_name, status) = test_result | 89 | status = self.results[section][test_name] |
109 | # we log only the tests with status in the test_status list | 90 | # we log only the tests with status in the test_status list |
110 | match_status = status_regex.search(status) | 91 | if status in test_status: |
111 | if match_status: | ||
112 | ftools.append_file(section_file, status + ": " + test_name) | 92 | ftools.append_file(section_file, status + ": " + test_name) |
113 | 93 | ||
114 | # Not yet implemented! | ||
115 | def log_to_lava(self): | ||
116 | pass | ||