summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils/logparser.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/utils/logparser.py')
-rw-r--r--meta/lib/oeqa/utils/logparser.py45
1 files changed, 11 insertions, 34 deletions
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.
9class PtestParser(object): 9class 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
73class 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