[oe-commits] [openembedded-core] 06/30: oeqa/logparser: Improve results handling

git at git.openembedded.org git at git.openembedded.org
Thu Jan 31 09:46:12 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 f317800e950b4a37b4034133bc52e0c47f04dc29
Author: Richard Purdie <richard.purdie at linuxfoundation.org>
AuthorDate: Tue Jan 29 15:08:58 2019 +0000

    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.
    
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 meta/lib/oeqa/runtime/cases/ptest.py | 14 ++++++-----
 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 3cfd7af..2843953 100644
--- a/meta/lib/oeqa/runtime/cases/ptest.py
+++ b/meta/lib/oeqa/runtime/cases/ptest.py
@@ -49,8 +49,9 @@ class PtestRunnerTest(OERuntimeTestCase):
         extras['ptestresult.rawlogs'] = {'log': output}
 
         # Parse and save results
-        parse_result, sections = PtestParser().parse(ptest_runner_log)
-        parse_result.log_as_files(ptest_log_dir, test_status = ['pass','fail', 'skip'])
+        parser = PtestParser()
+        results, sections = parser.parse(ptest_runner_log)
+        parser.results_as_files(ptest_log_dir, test_status = ['pass','fail', 'skip'])
         if os.path.exists(ptest_log_dir_link):
             # Remove the old link to create a new one
             os.remove(ptest_log_dir_link)
@@ -60,14 +61,15 @@ class PtestRunnerTest(OERuntimeTestCase):
 
         trans = str.maketrans("()", "__")
         resmap = {'pass': 'PASSED', 'skip': 'SKIPPED', 'fail': 'FAILED'}
-        for section in parse_result.result_dict:
-            for test, result in parse_result.result_dict[section]:
+        for section in results:
+            for test in results[section]:
+                result = results[section][test]
                 testname = "ptestresult." + (section or "No-section") + "." + "_".join(test.translate(trans).split())
                 extras[testname] = {'status': resmap[result]}
 
         failed_tests = {}
-        for section in parse_result.result_dict:
-            failed_testcases = [ "_".join(test.translate(trans).split()) for test, result in parse_result.result_dict[section] if result == 'fail' ]
+        for section in results:
+            failed_testcases = [ "_".join(test.translate(trans).split()) for test in results[section] if results[section][test] == 'fail' ]
             if failed_testcases:
                 failed_tests[section] = failed_testcases
 
diff --git a/meta/lib/oeqa/utils/logparser.py b/meta/lib/oeqa/utils/logparser.py
index dddea14..8585c19 100644
--- a/meta/lib/oeqa/utils/logparser.py
+++ b/meta/lib/oeqa/utils/logparser.py
@@ -8,7 +8,7 @@ from . import ftools
 # A parser that can be used to identify weather a line is a test result or a section statement.
 class PtestParser(object):
     def __init__(self):
-        self.results = Result()
+        self.results = {}
         self.sections = {}
 
     def parse(self, logfile):
@@ -65,52 +65,29 @@ class PtestParser(object):
                 for t in test_regex:
                     result = test_regex[t].search(line)
                     if result:
-                        self.results.store(current_section['name'], result.group(1), t)
+                        if current_section['name'] not in self.results:
+                            self.results[current_section['name']] = {}
+                        self.results[current_section['name']][result.group(1)] = t
 
-        self.results.sort_tests()
         return self.results, self.sections
 
-class Result(object):
-
-    def __init__(self):
-        self.result_dict = {}
-
-    def store(self, section, test, status):
-        if not section in self.result_dict:
-            self.result_dict[section] = []
-
-        self.result_dict[section].append((test, status))
-
-    # 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.
-    def sort_tests(self):
-        for package in self.result_dict:
-            sorted_results = sorted(self.result_dict[package], key=lambda tup: tup[0])
-            self.result_dict[package] = sorted_results
-
     # Log the results as files. The file name is the section name and the contents are the tests in that section.
-    def log_as_files(self, target_dir, test_status):
-        status_regex = re.compile('|'.join(map(str, test_status)))
+    def results_as_files(self, target_dir, test_status):
         if not type(test_status) == type([]):
             raise Exception("test_status should be a list. Got " + str(test_status) + " instead.")
         if not os.path.exists(target_dir):
             raise Exception("Target directory does not exist: %s" % target_dir)
 
-        for section, test_results in self.result_dict.items():
-            prefix = ''
-            for x in test_status:
-                prefix +=x+'.'
+        for section in self.results:
+            prefix = 'No-section'
             if section:
-                prefix += section
+                prefix = section
             section_file = os.path.join(target_dir, prefix)
             # purge the file contents if it exists
             open(section_file, 'w').close()
-            for test_result in test_results:
-                (test_name, status) = test_result
+            for test_name in sorted(self.results[section]):
+                status = self.results[section][test_name]
                 # we log only the tests with status in the test_status list
-                match_status = status_regex.search(status)
-                if match_status:
+                if status in test_status:
                     ftools.append_file(section_file, status + ": " + test_name)
 
-    # Not yet implemented!
-    def log_to_lava(self):
-        pass

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


More information about the Openembedded-commits mailing list