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.py83
1 files changed, 78 insertions, 5 deletions
diff --git a/meta/lib/oeqa/utils/logparser.py b/meta/lib/oeqa/utils/logparser.py
index 32fde14a7d..879aefca33 100644
--- a/meta/lib/oeqa/utils/logparser.py
+++ b/meta/lib/oeqa/utils/logparser.py
@@ -1,4 +1,6 @@
-#!/usr/bin/env python
+#
+# SPDX-License-Identifier: MIT
+#
import sys
import os
@@ -13,7 +15,7 @@ class PtestParser(object):
def parse(self, logfile):
test_regex = {}
test_regex['PASSED'] = re.compile(r"^PASS:(.+)")
- test_regex['FAILED'] = re.compile(r"^FAIL:(.+)")
+ test_regex['FAILED'] = re.compile(r"^FAIL:([^(]+)")
test_regex['SKIPPED'] = re.compile(r"^SKIP:(.+)")
section_regex = {}
@@ -23,13 +25,20 @@ class PtestParser(object):
section_regex['exitcode'] = re.compile(r"^ERROR: Exit status is (.+)")
section_regex['timeout'] = re.compile(r"^TIMEOUT: .*/(.+)/ptest")
+ # Cache markers so we don't take the re.search() hit all the time.
+ markers = ("PASS:", "FAIL:", "SKIP:", "BEGIN:", "END:", "DURATION:", "ERROR: Exit", "TIMEOUT:")
+
def newsection():
- return { 'name': "No-section", 'log': "" }
+ return { 'name': "No-section", 'log': [] }
current_section = newsection()
with open(logfile, errors='replace') as f:
for line in f:
+ if not line.startswith(markers):
+ current_section['log'].append(line)
+ continue
+
result = section_regex['begin'].search(line)
if result:
current_section['name'] = result.group(1)
@@ -59,14 +68,19 @@ class PtestParser(object):
current_section[t] = result.group(1)
continue
- current_section['log'] = current_section['log'] + line
+ current_section['log'].append(line)
for t in test_regex:
result = test_regex[t].search(line)
if result:
if current_section['name'] not in self.results:
self.results[current_section['name']] = {}
- self.results[current_section['name']][result.group(1)] = t
+ self.results[current_section['name']][result.group(1).strip()] = t
+
+ # Python performance for repeatedly joining long strings is poor, do it all at once at the end.
+ # For 2.1 million lines in a log this reduces 18 hours to 12s.
+ for section in self.sections:
+ self.sections[section]['log'] = "".join(self.sections[section]['log'])
return self.results, self.sections
@@ -86,3 +100,62 @@ class PtestParser(object):
status = self.results[section][test_name]
f.write(status + ": " + test_name + "\n")
+
+# ltp log parsing
+class LtpParser(object):
+ def __init__(self):
+ self.results = {}
+ self.section = {'duration': "", 'log': ""}
+
+ def parse(self, logfile):
+ test_regex = {}
+ test_regex['PASSED'] = re.compile(r"PASS")
+ test_regex['FAILED'] = re.compile(r"FAIL")
+ test_regex['SKIPPED'] = re.compile(r"SKIP")
+
+ with open(logfile, errors='replace') as f:
+ for line in f:
+ for t in test_regex:
+ result = test_regex[t].search(line)
+ if result:
+ self.results[line.split()[0].strip()] = t
+
+ for test in self.results:
+ result = self.results[test]
+ self.section['log'] = self.section['log'] + ("%s: %s\n" % (result.strip()[:-2], test.strip()))
+
+ return self.results, self.section
+
+
+# ltp Compliance log parsing
+class LtpComplianceParser(object):
+ def __init__(self):
+ self.results = {}
+ self.section = {'duration': "", 'log': ""}
+
+ def parse(self, logfile):
+ test_regex = {}
+ test_regex['FAILED'] = re.compile(r"FAIL")
+
+ section_regex = {}
+ section_regex['test'] = re.compile(r"^Executing")
+
+ with open(logfile, errors='replace') as f:
+ name = logfile
+ result = "PASSED"
+ for line in f:
+ regex_result = section_regex['test'].search(line)
+ if regex_result:
+ name = line.split()[1].strip()
+
+ regex_result = test_regex['FAILED'].search(line)
+ if regex_result:
+ result = "FAILED"
+ self.results[name] = result
+
+ for test in self.results:
+ result = self.results[test]
+ print (self.results)
+ self.section['log'] = self.section['log'] + ("%s: %s\n" % (result.strip()[:-2], test.strip()))
+
+ return self.results, self.section