diff options
author | Robert Yang <liezhi.yang@windriver.com> | 2017-08-21 18:23:05 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-08-23 14:16:01 +0100 |
commit | dccf0efb41f27d9d654e527d213c0494421ed234 (patch) | |
tree | 6abd658846784da9b80a59ac0b38e1c071e64139 | |
parent | 487c62b8536fee1104ac7b34d258d5d0c20d7d7c (diff) | |
download | poky-dccf0efb41f27d9d654e527d213c0494421ed234.tar.gz |
runtime/cases/_ptest.py: revive it
* Make it work with current oeqa
* Skip the test if ptest is not in DISTRO_FEATURES
* Skip the test if ptest-pkgs is not in IMAGE_FEATURES
* The logs are saved to:
testimage/ptest_log -> testimage/ptest_log.<datetime>
* This provides data that could be used to detect regressions in ptest results
[YOCTO #11547]
(From OE-Core rev: f1dfb59495db9e79441c8aa623ede7ef20045a20)
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/lib/oeqa/runtime/cases/_ptest.py | 96 |
1 files changed, 35 insertions, 61 deletions
diff --git a/meta/lib/oeqa/runtime/cases/_ptest.py b/meta/lib/oeqa/runtime/cases/_ptest.py index aaed9a5352..6d239494b8 100644 --- a/meta/lib/oeqa/runtime/cases/_ptest.py +++ b/meta/lib/oeqa/runtime/cases/_ptest.py | |||
@@ -1,28 +1,10 @@ | |||
1 | import os | ||
2 | import shutil | ||
3 | import subprocess | ||
4 | |||
5 | from oeqa.runtime.case import OERuntimeTestCase | 1 | from oeqa.runtime.case import OERuntimeTestCase |
6 | from oeqa.core.decorator.depends import OETestDepends | 2 | from oeqa.core.decorator.depends import OETestDepends |
7 | from oeqa.core.decorator.oeid import OETestID | 3 | from oeqa.core.decorator.oeid import OETestID |
8 | from oeqa.core.decorator.data import skipIfNotDataVar, skipIfNotFeature | 4 | from oeqa.core.decorator.data import skipIfNotFeature |
9 | from oeqa.runtime.decorator.package import OEHasPackage | 5 | from oeqa.utils.logparser import Lparser, Result |
10 | |||
11 | from oeqa.runtime.cases.dnf import DnfTest | ||
12 | from oeqa.utils.logparser import * | ||
13 | from oeqa.utils.httpserver import HTTPService | ||
14 | |||
15 | class PtestRunnerTest(DnfTest): | ||
16 | 6 | ||
17 | @classmethod | 7 | class PtestRunnerTest(OERuntimeTestCase): |
18 | def setUpClass(cls): | ||
19 | rpm_deploy = os.path.join(cls.tc.td['DEPLOY_DIR'], 'rpm') | ||
20 | cls.repo_server = HTTPService(rpm_deploy, cls.tc.target.server_ip) | ||
21 | cls.repo_server.start() | ||
22 | |||
23 | @classmethod | ||
24 | def tearDownClass(cls): | ||
25 | cls.repo_server.stop() | ||
26 | 8 | ||
27 | # a ptest log parser | 9 | # a ptest log parser |
28 | def parse_ptest(self, logfile): | 10 | def parse_ptest(self, logfile): |
@@ -59,45 +41,37 @@ class PtestRunnerTest(DnfTest): | |||
59 | result.sort_tests() | 41 | result.sort_tests() |
60 | return result | 42 | return result |
61 | 43 | ||
62 | def _install_ptest_packages(self): | 44 | @OETestID(1600) |
63 | # Get ptest packages that can be installed in the image. | 45 | @skipIfNotFeature('ptest', 'Test requires ptest to be in DISTRO_FEATURES') |
64 | packages_dir = os.path.join(self.tc.td['DEPLOY_DIR'], 'rpm') | 46 | @skipIfNotFeature('ptest-pkgs', 'Test requires ptest-pkgs to be in IMAGE_FEATURES') |
65 | ptest_pkgs = [pkg[:pkg.find('-ptest')+6] | ||
66 | for _, _, filenames in os.walk(packages_dir) | ||
67 | for pkg in filenames | ||
68 | if 'ptest' in pkg | ||
69 | and pkg[:pkg.find('-ptest')] in self.tc.image_packages] | ||
70 | |||
71 | repo_url = 'http://%s:%s' % (self.target.server_ip, | ||
72 | self.repo_server.port) | ||
73 | dnf_options = ('--repofrompath=oe-ptest-repo,%s ' | ||
74 | '--nogpgcheck ' | ||
75 | 'install -y' % repo_url) | ||
76 | self.dnf('%s %s ptest-runner' % (dnf_options, ' '.join(ptest_pkgs))) | ||
77 | |||
78 | @skipIfNotFeature('package-management', | ||
79 | 'Test requires package-management to be in DISTRO_FEATURES') | ||
80 | @skipIfNotFeature('ptest', | ||
81 | 'Test requires package-management to be in DISTRO_FEATURES') | ||
82 | @skipIfNotDataVar('IMAGE_PKGTYPE', 'rpm', | ||
83 | 'RPM is not the primary package manager') | ||
84 | @OEHasPackage(['dnf']) | ||
85 | @OETestDepends(['ssh.SSHTest.test_ssh']) | 47 | @OETestDepends(['ssh.SSHTest.test_ssh']) |
86 | def test_ptestrunner(self): | 48 | def test_ptestrunner(self): |
87 | self.ptest_log = os.path.join(self.tc.td['TEST_LOG_DIR'], | 49 | import datetime |
88 | 'ptest-%s.log' % self.tc.td['DATETIME']) | 50 | |
89 | self._install_ptest_packages() | 51 | test_log_dir = self.td.get('TEST_LOG_DIR', '') |
90 | 52 | # The TEST_LOG_DIR maybe NULL when testimage is added after | |
91 | (runnerstatus, result) = self.target.run('/usr/bin/ptest-runner > /tmp/ptest.log 2>&1', 0) | 53 | # testdata.json is generated. |
92 | #exit code is !=0 even if ptest-runner executes because some ptest tests fail. | 54 | if not test_log_dir: |
93 | self.assertTrue(runnerstatus != 127, msg="Cannot execute ptest-runner!") | 55 | test_log_dir = os.path.join(self.td.get('WORKDIR', ''), 'testimage') |
94 | self.target.copyFrom('/tmp/ptest.log', self.ptest_log) | 56 | # Don't use self.td.get('DATETIME'), it's from testdata.json, not |
95 | shutil.copyfile(self.ptest_log, "ptest.log") | 57 | # up-to-date, and may cause "File exists" when re-reun. |
96 | 58 | datetime = datetime.datetime.now().strftime('%Y%m%d%H%M%S') | |
97 | result = self.parse_ptest("ptest.log") | 59 | ptest_log_dir_link = os.path.join(test_log_dir, 'ptest_log') |
98 | log_results_to_location = "./results" | 60 | ptest_log_dir = '%s.%s' % (ptest_log_dir_link, datetime) |
99 | if os.path.exists(log_results_to_location): | 61 | ptest_runner_log = os.path.join(ptest_log_dir, 'ptest-runner.log') |
100 | shutil.rmtree(log_results_to_location) | 62 | |
101 | os.makedirs(log_results_to_location) | 63 | status, output = self.target.run('ptest-runner', 0) |
102 | 64 | os.makedirs(ptest_log_dir) | |
103 | result.log_as_files(log_results_to_location, test_status = ['pass','fail']) | 65 | with open(ptest_runner_log, 'w') as f: |
66 | f.write(output) | ||
67 | |||
68 | # status != 0 is OK since some ptest tests may fail | ||
69 | self.assertTrue(status != 127, msg="Cannot execute ptest-runner!") | ||
70 | |||
71 | # Parse and save results | ||
72 | parse_result = self.parse_ptest(ptest_runner_log) | ||
73 | parse_result.log_as_files(ptest_log_dir, test_status = ['pass','fail']) | ||
74 | if os.path.exists(ptest_log_dir_link): | ||
75 | # Remove the old link to create a new one | ||
76 | os.remove(ptest_log_dir_link) | ||
77 | os.symlink(os.path.basename(ptest_log_dir), ptest_log_dir_link) | ||