summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2019-01-29 12:08:26 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-01-31 23:23:26 +0000
commit95427c47ab3a81d671f478aca1d920ebedabf611 (patch)
tree8b3812f1ae1573ef7675a6b4151562c4e80c2bd1 /meta/lib/oeqa/utils
parentfa2db6a72a11bc541d1e1698394dc1fe2d319eb9 (diff)
downloadpoky-95427c47ab3a81d671f478aca1d920ebedabf611.tar.gz
oeqa/utils/logparser: Simplify ptest log parsing code
logparser is only used by ptest. Its slightly overcomplicated as it was intended to be reusable but wasn't. Simplify it as a dedicated parser is likely to me more readable and maintainable. (From OE-Core rev: c7478345b2b4a85cb1fec40e762633871f0e94cb) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/utils')
-rw-r--r--meta/lib/oeqa/utils/logparser.py62
1 files changed, 10 insertions, 52 deletions
diff --git a/meta/lib/oeqa/utils/logparser.py b/meta/lib/oeqa/utils/logparser.py
index 0670627c3c..328baeefaf 100644
--- a/meta/lib/oeqa/utils/logparser.py
+++ b/meta/lib/oeqa/utils/logparser.py
@@ -5,66 +5,24 @@ import os
5import re 5import re
6from . import ftools 6from . import ftools
7 7
8
9# 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.
10class Lparser(object): 9class Lparser(object):
11 10
12 def __init__(self, test_0_pass_regex, test_0_fail_regex, test_0_skip_regex, section_0_begin_regex=None, section_0_end_regex=None, **kwargs): 11 def __init__(self, **kwargs):
13 # Initialize the arguments dictionary
14 if kwargs:
15 self.args = kwargs
16 else:
17 self.args = {}
18
19 # Add the default args to the dictionary
20 self.args['test_0_pass_regex'] = test_0_pass_regex
21 self.args['test_0_fail_regex'] = test_0_fail_regex
22 self.args['test_0_skip_regex'] = test_0_skip_regex
23 if section_0_begin_regex:
24 self.args['section_0_begin_regex'] = section_0_begin_regex
25 if section_0_end_regex:
26 self.args['section_0_end_regex'] = section_0_end_regex
27
28 self.test_possible_status = ['pass', 'fail', 'error', 'skip']
29 self.section_possible_status = ['begin', 'end']
30
31 self.initialized = False
32 12
33
34 # Initialize the parser with the current configuration
35 def init(self):
36
37 # extra arguments can be added by the user to define new test and section categories. They must follow a pre-defined pattern: <type>_<category_name>_<status>_regex
38 self.test_argument_pattern = "^test_(.+?)_(%s)_regex" % '|'.join(map(str, self.test_possible_status))
39 self.section_argument_pattern = "^section_(.+?)_(%s)_regex" % '|'.join(map(str, self.section_possible_status))
40
41 # Initialize the test and section regex dictionaries
42 self.test_regex = {} 13 self.test_regex = {}
43 self.section_regex ={} 14 self.test_regex[0] = {}
44 15 self.test_regex[0]['pass'] = re.compile(r"^PASS:(.+)")
45 for arg, value in self.args.items(): 16 self.test_regex[0]['fail'] = re.compile(r"^FAIL:(.+)")
46 if not value: 17 self.test_regex[0]['skip'] = re.compile(r"^SKIP:(.+)")
47 raise Exception('The value of provided argument %s is %s. Should have a valid value.' % (key, value)) 18
48 is_test = re.search(self.test_argument_pattern, arg) 19 self.section_regex = {}
49 is_section = re.search(self.section_argument_pattern, arg) 20 self.section_regex[0] = {}
50 if is_test: 21 self.section_regex[0]['begin'] = re.compile(r"^BEGIN: .*/(.+)/ptest")
51 if not is_test.group(1) in self.test_regex: 22 self.section_regex[0]['end'] = re.compile(r"^END: .*/(.+)/ptest")
52 self.test_regex[is_test.group(1)] = {}
53 self.test_regex[is_test.group(1)][is_test.group(2)] = re.compile(value)
54 elif is_section:
55 if not is_section.group(1) in self.section_regex:
56 self.section_regex[is_section.group(1)] = {}
57 self.section_regex[is_section.group(1)][is_section.group(2)] = re.compile(value)
58 else:
59 # TODO: Make these call a traceback instead of a simple exception..
60 raise Exception("The provided argument name does not correspond to any valid type. Please give one of the following types:\nfor tests: %s\nfor sections: %s" % (self.test_argument_pattern, self.section_argument_pattern))
61
62 self.initialized = True
63 23
64 # Parse a line and return a tuple containing the type of result (test/section) and its category, status and name 24 # Parse a line and return a tuple containing the type of result (test/section) and its category, status and name
65 def parse_line(self, line): 25 def parse_line(self, line):
66 if not self.initialized:
67 raise Exception("The parser is not initialized..")
68 26
69 for test_category, test_status_list in self.test_regex.items(): 27 for test_category, test_status_list in self.test_regex.items():
70 for test_status, status_regex in test_status_list.items(): 28 for test_status, status_regex in test_status_list.items():