[oe-commits] [openembedded-core] 13/13: oeqa/logparser: Various misc cleanups

git at git.openembedded.org git at git.openembedded.org
Tue Jan 29 17:45:59 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 1f2f9364105d52e019c3f607d2e4af1c48bbf43d
Author: Richard Purdie <richard.purdie at linuxfoundation.org>
AuthorDate: Tue Jan 29 16:52:18 2019 +0000

    oeqa/logparser: Various misc cleanups
    
    Get rid of further unneeded code complications:
    
    * value mappings we could just direct use
    * ftools when we can write files easily ourself
    * test result status filtering we don't use
    * variable overwriting module imports
    
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 meta/lib/oeqa/runtime/cases/ptest.py | 13 +++++--------
 meta/lib/oeqa/utils/logparser.py     | 21 ++++++++-------------
 2 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/meta/lib/oeqa/runtime/cases/ptest.py b/meta/lib/oeqa/runtime/cases/ptest.py
index 2843953..6ae9513 100644
--- a/meta/lib/oeqa/runtime/cases/ptest.py
+++ b/meta/lib/oeqa/runtime/cases/ptest.py
@@ -1,6 +1,6 @@
 import unittest
 import pprint
-import re
+import datetime
 
 from oeqa.runtime.case import OERuntimeTestCase
 from oeqa.core.decorator.depends import OETestDepends
@@ -21,8 +21,6 @@ class PtestRunnerTest(OERuntimeTestCase):
         if status != 0:
             self.skipTest("No -ptest packages are installed in the image")
 
-        import datetime
-
         test_log_dir = self.td.get('TEST_LOG_DIR', '')
         # The TEST_LOG_DIR maybe NULL when testimage is added after
         # testdata.json is generated.
@@ -30,9 +28,9 @@ class PtestRunnerTest(OERuntimeTestCase):
             test_log_dir = os.path.join(self.td.get('WORKDIR', ''), 'testimage')
         # Don't use self.td.get('DATETIME'), it's from testdata.json, not
         # up-to-date, and may cause "File exists" when re-reun.
-        datetime = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
+        timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
         ptest_log_dir_link = os.path.join(test_log_dir, 'ptest_log')
-        ptest_log_dir = '%s.%s' % (ptest_log_dir_link, datetime)
+        ptest_log_dir = '%s.%s' % (ptest_log_dir_link, timestamp)
         ptest_runner_log = os.path.join(ptest_log_dir, 'ptest-runner.log')
 
         status, output = self.target.run('ptest-runner', 0)
@@ -51,7 +49,7 @@ class PtestRunnerTest(OERuntimeTestCase):
         # Parse and save results
         parser = PtestParser()
         results, sections = parser.parse(ptest_runner_log)
-        parser.results_as_files(ptest_log_dir, test_status = ['pass','fail', 'skip'])
+        parser.results_as_files(ptest_log_dir)
         if os.path.exists(ptest_log_dir_link):
             # Remove the old link to create a new one
             os.remove(ptest_log_dir_link)
@@ -60,12 +58,11 @@ class PtestRunnerTest(OERuntimeTestCase):
         extras['ptestresult.sections'] = sections
 
         trans = str.maketrans("()", "__")
-        resmap = {'pass': 'PASSED', 'skip': 'SKIPPED', 'fail': 'FAILED'}
         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]}
+                extras[testname] = {'status': result}
 
         failed_tests = {}
         for section in results:
diff --git a/meta/lib/oeqa/utils/logparser.py b/meta/lib/oeqa/utils/logparser.py
index 8585c19..32fde14 100644
--- a/meta/lib/oeqa/utils/logparser.py
+++ b/meta/lib/oeqa/utils/logparser.py
@@ -3,7 +3,6 @@
 import sys
 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 PtestParser(object):
@@ -13,9 +12,9 @@ class PtestParser(object):
 
     def parse(self, logfile):
         test_regex = {}
-        test_regex['pass'] = re.compile(r"^PASS:(.+)")
-        test_regex['fail'] = re.compile(r"^FAIL:(.+)")
-        test_regex['skip'] = re.compile(r"^SKIP:(.+)")
+        test_regex['PASSED'] = re.compile(r"^PASS:(.+)")
+        test_regex['FAILED'] = re.compile(r"^FAIL:(.+)")
+        test_regex['SKIPPED'] = re.compile(r"^SKIP:(.+)")
 
         section_regex = {}
         section_regex['begin'] = re.compile(r"^BEGIN: .*/(.+)/ptest")
@@ -72,9 +71,7 @@ class PtestParser(object):
         return self.results, self.sections
 
     # Log the results as files. The file name is the section name and the contents are the tests in that section.
-    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.")
+    def results_as_files(self, target_dir):
         if not os.path.exists(target_dir):
             raise Exception("Target directory does not exist: %s" % target_dir)
 
@@ -84,10 +81,8 @@ class PtestParser(object):
                 prefix = section
             section_file = os.path.join(target_dir, prefix)
             # purge the file contents if it exists
-            open(section_file, 'w').close()
-            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
-                if status in test_status:
-                    ftools.append_file(section_file, status + ": " + test_name)
+            with open(section_file, 'w') as f:
+                for test_name in sorted(self.results[section]):
+                    status = self.results[section][test_name]
+                    f.write(status + ": " + test_name + "\n")
 

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


More information about the Openembedded-commits mailing list