summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2019-01-29 16:52:18 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-02-25 22:27:39 +0000
commitddabcfa8ea4eaa87ebd1d3901591f7afe2c1ccf9 (patch)
tree937ba8c2ef0f910b72e0d5a2a8c4b26911db3fcc /meta
parentc792536bcb6cdd901af861dbbee0b3c8482b1b03 (diff)
downloadpoky-ddabcfa8ea4eaa87ebd1d3901591f7afe2c1ccf9.tar.gz
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 (From OE-Core rev: d6065f136f6d353c3054cc3f440a4e259509f876) (From OE-Core rev: ba944a72302fa088c31c7b1eee4ad9f64f9769e4) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> Signed-off-by: Armin Kuster <akuster808@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/lib/oeqa/runtime/cases/ptest.py13
-rw-r--r--meta/lib/oeqa/utils/logparser.py21
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 2843953b38..6ae951356d 100644
--- a/meta/lib/oeqa/runtime/cases/ptest.py
+++ b/meta/lib/oeqa/runtime/cases/ptest.py
@@ -1,6 +1,6 @@
1import unittest 1import unittest
2import pprint 2import pprint
3import re 3import datetime
4 4
5from oeqa.runtime.case import OERuntimeTestCase 5from oeqa.runtime.case import OERuntimeTestCase
6from oeqa.core.decorator.depends import OETestDepends 6from oeqa.core.decorator.depends import OETestDepends
@@ -21,8 +21,6 @@ class PtestRunnerTest(OERuntimeTestCase):
21 if status != 0: 21 if status != 0:
22 self.skipTest("No -ptest packages are installed in the image") 22 self.skipTest("No -ptest packages are installed in the image")
23 23
24 import datetime
25
26 test_log_dir = self.td.get('TEST_LOG_DIR', '') 24 test_log_dir = self.td.get('TEST_LOG_DIR', '')
27 # The TEST_LOG_DIR maybe NULL when testimage is added after 25 # The TEST_LOG_DIR maybe NULL when testimage is added after
28 # testdata.json is generated. 26 # testdata.json is generated.
@@ -30,9 +28,9 @@ class PtestRunnerTest(OERuntimeTestCase):
30 test_log_dir = os.path.join(self.td.get('WORKDIR', ''), 'testimage') 28 test_log_dir = os.path.join(self.td.get('WORKDIR', ''), 'testimage')
31 # Don't use self.td.get('DATETIME'), it's from testdata.json, not 29 # Don't use self.td.get('DATETIME'), it's from testdata.json, not
32 # up-to-date, and may cause "File exists" when re-reun. 30 # up-to-date, and may cause "File exists" when re-reun.
33 datetime = datetime.datetime.now().strftime('%Y%m%d%H%M%S') 31 timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
34 ptest_log_dir_link = os.path.join(test_log_dir, 'ptest_log') 32 ptest_log_dir_link = os.path.join(test_log_dir, 'ptest_log')
35 ptest_log_dir = '%s.%s' % (ptest_log_dir_link, datetime) 33 ptest_log_dir = '%s.%s' % (ptest_log_dir_link, timestamp)
36 ptest_runner_log = os.path.join(ptest_log_dir, 'ptest-runner.log') 34 ptest_runner_log = os.path.join(ptest_log_dir, 'ptest-runner.log')
37 35
38 status, output = self.target.run('ptest-runner', 0) 36 status, output = self.target.run('ptest-runner', 0)
@@ -51,7 +49,7 @@ class PtestRunnerTest(OERuntimeTestCase):
51 # Parse and save results 49 # Parse and save results
52 parser = PtestParser() 50 parser = PtestParser()
53 results, sections = parser.parse(ptest_runner_log) 51 results, sections = parser.parse(ptest_runner_log)
54 parser.results_as_files(ptest_log_dir, test_status = ['pass','fail', 'skip']) 52 parser.results_as_files(ptest_log_dir)
55 if os.path.exists(ptest_log_dir_link): 53 if os.path.exists(ptest_log_dir_link):
56 # Remove the old link to create a new one 54 # Remove the old link to create a new one
57 os.remove(ptest_log_dir_link) 55 os.remove(ptest_log_dir_link)
@@ -60,12 +58,11 @@ class PtestRunnerTest(OERuntimeTestCase):
60 extras['ptestresult.sections'] = sections 58 extras['ptestresult.sections'] = sections
61 59
62 trans = str.maketrans("()", "__") 60 trans = str.maketrans("()", "__")
63 resmap = {'pass': 'PASSED', 'skip': 'SKIPPED', 'fail': 'FAILED'}
64 for section in results: 61 for section in results:
65 for test in results[section]: 62 for test in results[section]:
66 result = results[section][test] 63 result = results[section][test]
67 testname = "ptestresult." + (section or "No-section") + "." + "_".join(test.translate(trans).split()) 64 testname = "ptestresult." + (section or "No-section") + "." + "_".join(test.translate(trans).split())
68 extras[testname] = {'status': resmap[result]} 65 extras[testname] = {'status': result}
69 66
70 failed_tests = {} 67 failed_tests = {}
71 for section in results: 68 for section in results:
diff --git a/meta/lib/oeqa/utils/logparser.py b/meta/lib/oeqa/utils/logparser.py
index 8585c195c4..32fde14a7d 100644
--- a/meta/lib/oeqa/utils/logparser.py
+++ b/meta/lib/oeqa/utils/logparser.py
@@ -3,7 +3,6 @@
3import sys 3import sys
4import os 4import os
5import re 5import re
6from . import ftools
7 6
8# A parser that can be used to identify weather a line is a test result or a section statement. 7# A parser that can be used to identify weather a line is a test result or a section statement.
9class PtestParser(object): 8class PtestParser(object):
@@ -13,9 +12,9 @@ class PtestParser(object):
13 12
14 def parse(self, logfile): 13 def parse(self, logfile):
15 test_regex = {} 14 test_regex = {}
16 test_regex['pass'] = re.compile(r"^PASS:(.+)") 15 test_regex['PASSED'] = re.compile(r"^PASS:(.+)")
17 test_regex['fail'] = re.compile(r"^FAIL:(.+)") 16 test_regex['FAILED'] = re.compile(r"^FAIL:(.+)")
18 test_regex['skip'] = re.compile(r"^SKIP:(.+)") 17 test_regex['SKIPPED'] = re.compile(r"^SKIP:(.+)")
19 18
20 section_regex = {} 19 section_regex = {}
21 section_regex['begin'] = re.compile(r"^BEGIN: .*/(.+)/ptest") 20 section_regex['begin'] = re.compile(r"^BEGIN: .*/(.+)/ptest")
@@ -72,9 +71,7 @@ class PtestParser(object):
72 return self.results, self.sections 71 return self.results, self.sections
73 72
74 # Log the results as files. The file name is the section name and the contents are the tests in that section. 73 # Log the results as files. The file name is the section name and the contents are the tests in that section.
75 def results_as_files(self, target_dir, test_status): 74 def results_as_files(self, target_dir):
76 if not type(test_status) == type([]):
77 raise Exception("test_status should be a list. Got " + str(test_status) + " instead.")
78 if not os.path.exists(target_dir): 75 if not os.path.exists(target_dir):
79 raise Exception("Target directory does not exist: %s" % target_dir) 76 raise Exception("Target directory does not exist: %s" % target_dir)
80 77
@@ -84,10 +81,8 @@ class PtestParser(object):
84 prefix = section 81 prefix = section
85 section_file = os.path.join(target_dir, prefix) 82 section_file = os.path.join(target_dir, prefix)
86 # purge the file contents if it exists 83 # purge the file contents if it exists
87 open(section_file, 'w').close() 84 with open(section_file, 'w') as f:
88 for test_name in sorted(self.results[section]): 85 for test_name in sorted(self.results[section]):
89 status = self.results[section][test_name] 86 status = self.results[section][test_name]
90 # we log only the tests with status in the test_status list 87 f.write(status + ": " + test_name + "\n")
91 if status in test_status:
92 ftools.append_file(section_file, status + ": " + test_name)
93 88