mirror of
https://git.yoctoproject.org/poky
synced 2026-05-09 17:39:31 +00:00
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>
This commit is contained in:
committed by
Richard Purdie
parent
487c62b853
commit
dccf0efb41
@@ -1,28 +1,10 @@
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from oeqa.runtime.case import OERuntimeTestCase
|
||||
from oeqa.core.decorator.depends import OETestDepends
|
||||
from oeqa.core.decorator.oeid import OETestID
|
||||
from oeqa.core.decorator.data import skipIfNotDataVar, skipIfNotFeature
|
||||
from oeqa.runtime.decorator.package import OEHasPackage
|
||||
from oeqa.core.decorator.data import skipIfNotFeature
|
||||
from oeqa.utils.logparser import Lparser, Result
|
||||
|
||||
from oeqa.runtime.cases.dnf import DnfTest
|
||||
from oeqa.utils.logparser import *
|
||||
from oeqa.utils.httpserver import HTTPService
|
||||
|
||||
class PtestRunnerTest(DnfTest):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
rpm_deploy = os.path.join(cls.tc.td['DEPLOY_DIR'], 'rpm')
|
||||
cls.repo_server = HTTPService(rpm_deploy, cls.tc.target.server_ip)
|
||||
cls.repo_server.start()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.repo_server.stop()
|
||||
class PtestRunnerTest(OERuntimeTestCase):
|
||||
|
||||
# a ptest log parser
|
||||
def parse_ptest(self, logfile):
|
||||
@@ -59,45 +41,37 @@ class PtestRunnerTest(DnfTest):
|
||||
result.sort_tests()
|
||||
return result
|
||||
|
||||
def _install_ptest_packages(self):
|
||||
# Get ptest packages that can be installed in the image.
|
||||
packages_dir = os.path.join(self.tc.td['DEPLOY_DIR'], 'rpm')
|
||||
ptest_pkgs = [pkg[:pkg.find('-ptest')+6]
|
||||
for _, _, filenames in os.walk(packages_dir)
|
||||
for pkg in filenames
|
||||
if 'ptest' in pkg
|
||||
and pkg[:pkg.find('-ptest')] in self.tc.image_packages]
|
||||
|
||||
repo_url = 'http://%s:%s' % (self.target.server_ip,
|
||||
self.repo_server.port)
|
||||
dnf_options = ('--repofrompath=oe-ptest-repo,%s '
|
||||
'--nogpgcheck '
|
||||
'install -y' % repo_url)
|
||||
self.dnf('%s %s ptest-runner' % (dnf_options, ' '.join(ptest_pkgs)))
|
||||
|
||||
@skipIfNotFeature('package-management',
|
||||
'Test requires package-management to be in DISTRO_FEATURES')
|
||||
@skipIfNotFeature('ptest',
|
||||
'Test requires package-management to be in DISTRO_FEATURES')
|
||||
@skipIfNotDataVar('IMAGE_PKGTYPE', 'rpm',
|
||||
'RPM is not the primary package manager')
|
||||
@OEHasPackage(['dnf'])
|
||||
@OETestID(1600)
|
||||
@skipIfNotFeature('ptest', 'Test requires ptest to be in DISTRO_FEATURES')
|
||||
@skipIfNotFeature('ptest-pkgs', 'Test requires ptest-pkgs to be in IMAGE_FEATURES')
|
||||
@OETestDepends(['ssh.SSHTest.test_ssh'])
|
||||
def test_ptestrunner(self):
|
||||
self.ptest_log = os.path.join(self.tc.td['TEST_LOG_DIR'],
|
||||
'ptest-%s.log' % self.tc.td['DATETIME'])
|
||||
self._install_ptest_packages()
|
||||
import datetime
|
||||
|
||||
(runnerstatus, result) = self.target.run('/usr/bin/ptest-runner > /tmp/ptest.log 2>&1', 0)
|
||||
#exit code is !=0 even if ptest-runner executes because some ptest tests fail.
|
||||
self.assertTrue(runnerstatus != 127, msg="Cannot execute ptest-runner!")
|
||||
self.target.copyFrom('/tmp/ptest.log', self.ptest_log)
|
||||
shutil.copyfile(self.ptest_log, "ptest.log")
|
||||
test_log_dir = self.td.get('TEST_LOG_DIR', '')
|
||||
# The TEST_LOG_DIR maybe NULL when testimage is added after
|
||||
# testdata.json is generated.
|
||||
if not test_log_dir:
|
||||
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')
|
||||
ptest_log_dir_link = os.path.join(test_log_dir, 'ptest_log')
|
||||
ptest_log_dir = '%s.%s' % (ptest_log_dir_link, datetime)
|
||||
ptest_runner_log = os.path.join(ptest_log_dir, 'ptest-runner.log')
|
||||
|
||||
result = self.parse_ptest("ptest.log")
|
||||
log_results_to_location = "./results"
|
||||
if os.path.exists(log_results_to_location):
|
||||
shutil.rmtree(log_results_to_location)
|
||||
os.makedirs(log_results_to_location)
|
||||
status, output = self.target.run('ptest-runner', 0)
|
||||
os.makedirs(ptest_log_dir)
|
||||
with open(ptest_runner_log, 'w') as f:
|
||||
f.write(output)
|
||||
|
||||
result.log_as_files(log_results_to_location, test_status = ['pass','fail'])
|
||||
# status != 0 is OK since some ptest tests may fail
|
||||
self.assertTrue(status != 127, msg="Cannot execute ptest-runner!")
|
||||
|
||||
# Parse and save results
|
||||
parse_result = self.parse_ptest(ptest_runner_log)
|
||||
parse_result.log_as_files(ptest_log_dir, test_status = ['pass','fail'])
|
||||
if os.path.exists(ptest_log_dir_link):
|
||||
# Remove the old link to create a new one
|
||||
os.remove(ptest_log_dir_link)
|
||||
os.symlink(os.path.basename(ptest_log_dir), ptest_log_dir_link)
|
||||
|
||||
Reference in New Issue
Block a user