diff options
author | Robert Yang <liezhi.yang@windriver.com> | 2017-08-21 18:23:08 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-08-23 14:16:01 +0100 |
commit | 20704967f6436f34fa24bc9d1f477bc356b4eb9a (patch) | |
tree | ddd46577313d1814a817416118e12bce138ec47a /meta/lib/oeqa/runtime/cases/ptest.py | |
parent | 86e062d61259696ca610bdfc8a02e3ea86ccf3f8 (diff) | |
download | poky-20704967f6436f34fa24bc9d1f477bc356b4eb9a.tar.gz |
runtime/cases/_ptest.py: rename it to ptest.py
It works now.
[YOCTO #11547]
(From OE-Core rev: 836393b467c3c0d53e4ace7611f991b0a5649182)
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/runtime/cases/ptest.py')
-rw-r--r-- | meta/lib/oeqa/runtime/cases/ptest.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/meta/lib/oeqa/runtime/cases/ptest.py b/meta/lib/oeqa/runtime/cases/ptest.py new file mode 100644 index 0000000000..ec8c038a56 --- /dev/null +++ b/meta/lib/oeqa/runtime/cases/ptest.py | |||
@@ -0,0 +1,82 @@ | |||
1 | from oeqa.runtime.case import OERuntimeTestCase | ||
2 | from oeqa.core.decorator.depends import OETestDepends | ||
3 | from oeqa.core.decorator.oeid import OETestID | ||
4 | from oeqa.core.decorator.data import skipIfNotFeature | ||
5 | from oeqa.utils.logparser import Lparser, Result | ||
6 | |||
7 | class PtestRunnerTest(OERuntimeTestCase): | ||
8 | |||
9 | # a ptest log parser | ||
10 | def parse_ptest(self, logfile): | ||
11 | parser = Lparser(test_0_pass_regex="^PASS:(.+)", | ||
12 | test_0_fail_regex="^FAIL:(.+)", | ||
13 | test_0_skip_regex="^SKIP:(.+)", | ||
14 | section_0_begin_regex="^BEGIN: .*/(.+)/ptest", | ||
15 | section_0_end_regex="^END: .*/(.+)/ptest") | ||
16 | parser.init() | ||
17 | result = Result() | ||
18 | |||
19 | with open(logfile, errors='replace') as f: | ||
20 | for line in f: | ||
21 | result_tuple = parser.parse_line(line) | ||
22 | if not result_tuple: | ||
23 | continue | ||
24 | result_tuple = line_type, category, status, name = parser.parse_line(line) | ||
25 | |||
26 | if line_type == 'section' and status == 'begin': | ||
27 | current_section = name | ||
28 | continue | ||
29 | |||
30 | if line_type == 'section' and status == 'end': | ||
31 | current_section = None | ||
32 | continue | ||
33 | |||
34 | if line_type == 'test' and status == 'pass': | ||
35 | result.store(current_section, name, status) | ||
36 | continue | ||
37 | |||
38 | if line_type == 'test' and status == 'fail': | ||
39 | result.store(current_section, name, status) | ||
40 | continue | ||
41 | |||
42 | if line_type == 'test' and status == 'skip': | ||
43 | result.store(current_section, name, status) | ||
44 | continue | ||
45 | |||
46 | result.sort_tests() | ||
47 | return result | ||
48 | |||
49 | @OETestID(1600) | ||
50 | @skipIfNotFeature('ptest', 'Test requires ptest to be in DISTRO_FEATURES') | ||
51 | @skipIfNotFeature('ptest-pkgs', 'Test requires ptest-pkgs to be in IMAGE_FEATURES') | ||
52 | @OETestDepends(['ssh.SSHTest.test_ssh']) | ||
53 | def test_ptestrunner(self): | ||
54 | import datetime | ||
55 | |||
56 | test_log_dir = self.td.get('TEST_LOG_DIR', '') | ||
57 | # The TEST_LOG_DIR maybe NULL when testimage is added after | ||
58 | # testdata.json is generated. | ||
59 | if not test_log_dir: | ||
60 | test_log_dir = os.path.join(self.td.get('WORKDIR', ''), 'testimage') | ||
61 | # Don't use self.td.get('DATETIME'), it's from testdata.json, not | ||
62 | # up-to-date, and may cause "File exists" when re-reun. | ||
63 | datetime = datetime.datetime.now().strftime('%Y%m%d%H%M%S') | ||
64 | ptest_log_dir_link = os.path.join(test_log_dir, 'ptest_log') | ||
65 | ptest_log_dir = '%s.%s' % (ptest_log_dir_link, datetime) | ||
66 | ptest_runner_log = os.path.join(ptest_log_dir, 'ptest-runner.log') | ||
67 | |||
68 | status, output = self.target.run('ptest-runner', 0) | ||
69 | os.makedirs(ptest_log_dir) | ||
70 | with open(ptest_runner_log, 'w') as f: | ||
71 | f.write(output) | ||
72 | |||
73 | # status != 0 is OK since some ptest tests may fail | ||
74 | self.assertTrue(status != 127, msg="Cannot execute ptest-runner!") | ||
75 | |||
76 | # Parse and save results | ||
77 | parse_result = self.parse_ptest(ptest_runner_log) | ||
78 | parse_result.log_as_files(ptest_log_dir, test_status = ['pass','fail', 'skip']) | ||
79 | if os.path.exists(ptest_log_dir_link): | ||
80 | # Remove the old link to create a new one | ||
81 | os.remove(ptest_log_dir_link) | ||
82 | os.symlink(os.path.basename(ptest_log_dir), ptest_log_dir_link) | ||