[oe-commits] [openembedded-core] 08/13: oeqa/utils/logparser: Simplify ptest log parsing code

git at git.openembedded.org git at git.openembedded.org
Tue Jan 29 17:45:54 UTC 2019


This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch master-next
in repository openembedded-core.

commit 36449d8e622d04b13f72cbdf01f6e405aaed762c
Author: Richard Purdie <richard.purdie at linuxfoundation.org>
AuthorDate: Tue Jan 29 12:08:26 2019 +0000

    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.
    
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 meta/lib/oeqa/runtime/cases/ptest.py |  7 +---
 meta/lib/oeqa/utils/logparser.py     | 62 ++++++------------------------------
 2 files changed, 11 insertions(+), 58 deletions(-)

diff --git a/meta/lib/oeqa/runtime/cases/ptest.py b/meta/lib/oeqa/runtime/cases/ptest.py
index 7d88493..ebef3f9 100644
--- a/meta/lib/oeqa/runtime/cases/ptest.py
+++ b/meta/lib/oeqa/runtime/cases/ptest.py
@@ -12,12 +12,7 @@ class PtestRunnerTest(OERuntimeTestCase):
 
     # a ptest log parser
     def parse_ptest(self, logfile):
-        parser = Lparser(test_0_pass_regex="^PASS:(.+)",
-                         test_0_fail_regex="^FAIL:(.+)",
-                         test_0_skip_regex="^SKIP:(.+)",
-                         section_0_begin_regex="^BEGIN: .*/(.+)/ptest",
-                         section_0_end_regex="^END: .*/(.+)/ptest")
-        parser.init()
+        parser = Lparser()
         result = Result()
 
         with open(logfile, errors='replace') as f:
diff --git a/meta/lib/oeqa/utils/logparser.py b/meta/lib/oeqa/utils/logparser.py
index 0670627..328baee 100644
--- a/meta/lib/oeqa/utils/logparser.py
+++ b/meta/lib/oeqa/utils/logparser.py
@@ -5,66 +5,24 @@ import os
 import re
 from . import ftools
 
-
 # A parser that can be used to identify weather a line is a test result or a section statement.
 class Lparser(object):
 
-    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):
-        # Initialize the arguments dictionary
-        if kwargs:
-            self.args = kwargs
-        else:
-            self.args = {}
-
-        # Add the default args to the dictionary
-        self.args['test_0_pass_regex'] = test_0_pass_regex
-        self.args['test_0_fail_regex'] = test_0_fail_regex
-        self.args['test_0_skip_regex'] = test_0_skip_regex
-        if section_0_begin_regex:
-            self.args['section_0_begin_regex'] = section_0_begin_regex
-        if section_0_end_regex:
-            self.args['section_0_end_regex'] = section_0_end_regex
-
-        self.test_possible_status = ['pass', 'fail', 'error', 'skip']
-        self.section_possible_status = ['begin', 'end']
-
-        self.initialized = False
+    def __init__(self, **kwargs):
 
-
-    # Initialize the parser with the current configuration
-    def init(self):
-
-        # 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
-        self.test_argument_pattern = "^test_(.+?)_(%s)_regex" % '|'.join(map(str, self.test_possible_status))
-        self.section_argument_pattern = "^section_(.+?)_(%s)_regex" % '|'.join(map(str, self.section_possible_status))
-
-        # Initialize the test and section regex dictionaries
         self.test_regex = {}
-        self.section_regex ={}
-
-        for arg, value in self.args.items():
-            if not value:
-                raise Exception('The value of provided argument %s is %s. Should have a valid value.' % (key, value))
-            is_test =  re.search(self.test_argument_pattern, arg)
-            is_section = re.search(self.section_argument_pattern, arg)
-            if is_test:
-                if not is_test.group(1) in self.test_regex:
-                    self.test_regex[is_test.group(1)] = {}
-                self.test_regex[is_test.group(1)][is_test.group(2)] = re.compile(value)
-            elif is_section:
-                if not is_section.group(1) in self.section_regex:
-                    self.section_regex[is_section.group(1)] = {}
-                self.section_regex[is_section.group(1)][is_section.group(2)] = re.compile(value)
-            else:
-                # TODO: Make these call a traceback instead of a simple exception..
-                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))
-
-        self.initialized = True
+        self.test_regex[0] = {}
+        self.test_regex[0]['pass'] = re.compile(r"^PASS:(.+)")
+        self.test_regex[0]['fail'] = re.compile(r"^FAIL:(.+)")
+        self.test_regex[0]['skip'] = re.compile(r"^SKIP:(.+)")
+
+        self.section_regex = {}
+        self.section_regex[0] = {}
+        self.section_regex[0]['begin'] = re.compile(r"^BEGIN: .*/(.+)/ptest")
+        self.section_regex[0]['end'] = re.compile(r"^END: .*/(.+)/ptest")
 
     # Parse a line and return a tuple containing the type of result (test/section) and its category, status and name
     def parse_line(self, line):
-        if not self.initialized:
-            raise Exception("The parser is not initialized..")
 
         for test_category, test_status_list in self.test_regex.items():
             for test_status, status_regex in test_status_list.items():

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list