mirror of
https://git.yoctoproject.org/poky
synced 2026-09-14 12:49:34 +02:00
oetest.py: Add extract_packages() to RuntimeTestContext class
This new method extracts the content of package (RPM, DEB, or IPK) to a directory inside of WORKDIR. The extraction is needed for later install in the DUTs without using a package manager. [YOCTO #8694] (From OE-Core rev: 90d585f59f217f23694a9b02a73b79d18dfdb579) Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
8a68910958
commit
92afca7181
@@ -12,6 +12,7 @@ import unittest
|
|||||||
import inspect
|
import inspect
|
||||||
import subprocess
|
import subprocess
|
||||||
import signal
|
import signal
|
||||||
|
import shutil
|
||||||
try:
|
try:
|
||||||
import bb
|
import bb
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -264,6 +265,22 @@ class TestContext(object):
|
|||||||
|
|
||||||
return testslist
|
return testslist
|
||||||
|
|
||||||
|
def getTestModules(self):
|
||||||
|
"""
|
||||||
|
Returns all the test modules in the testlist.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import pkgutil
|
||||||
|
|
||||||
|
modules = []
|
||||||
|
for test in self.testslist:
|
||||||
|
if re.search("\w+\.\w+\.test_\S+", test):
|
||||||
|
test = '.'.join(t.split('.')[:3])
|
||||||
|
module = pkgutil.get_loader(test)
|
||||||
|
modules.append(module)
|
||||||
|
|
||||||
|
return modules
|
||||||
|
|
||||||
def getTests(self, test):
|
def getTests(self, test):
|
||||||
'''Return all individual tests executed when running the suite.'''
|
'''Return all individual tests executed when running the suite.'''
|
||||||
# Unfortunately unittest does not have an API for this, so we have
|
# Unfortunately unittest does not have an API for this, so we have
|
||||||
@@ -385,6 +402,44 @@ class RuntimeTestContext(TestContext):
|
|||||||
if oeTest.hasPackage("procps"):
|
if oeTest.hasPackage("procps"):
|
||||||
oeRuntimeTest.pscmd = "ps -ef"
|
oeRuntimeTest.pscmd = "ps -ef"
|
||||||
|
|
||||||
|
def extract_packages(self):
|
||||||
|
"""
|
||||||
|
Find and extract packages that will be needed during runtime.
|
||||||
|
"""
|
||||||
|
|
||||||
|
needed_packages = {}
|
||||||
|
extracted_path = self.d.getVar("TEST_EXTRACTED_DIR", True)
|
||||||
|
modules = self.getTestModules()
|
||||||
|
bbpaths = self.d.getVar("BBPATH", True).split(":")
|
||||||
|
|
||||||
|
for module in modules:
|
||||||
|
json_file = self._getJsonFile(module)
|
||||||
|
if json_file:
|
||||||
|
needed_packages = self._getNeededPackages(json_file)
|
||||||
|
|
||||||
|
for key,value in needed_packages.items():
|
||||||
|
packages = ()
|
||||||
|
if isinstance(value, dict):
|
||||||
|
packages = (value, )
|
||||||
|
elif isinstance(value, list):
|
||||||
|
packages = value
|
||||||
|
else:
|
||||||
|
bb.fatal("Failed to process needed packages for %s; "
|
||||||
|
"Value must be a dict or list" % key)
|
||||||
|
|
||||||
|
for package in packages:
|
||||||
|
pkg = package["pkg"]
|
||||||
|
rm = package.get("rm", False)
|
||||||
|
extract = package.get("extract", True)
|
||||||
|
if extract:
|
||||||
|
dst_dir = os.path.join(extracted_path, pkg)
|
||||||
|
|
||||||
|
# Extract package and copy it to TEST_EXTRACTED_DIR
|
||||||
|
if extract and not os.path.exists(dst_dir):
|
||||||
|
pkg_dir = self._extract_in_tmpdir(pkg)
|
||||||
|
shutil.copytree(pkg_dir, dst_dir)
|
||||||
|
shutil.rmtree(pkg_dir)
|
||||||
|
|
||||||
def _getJsonFile(self, module):
|
def _getJsonFile(self, module):
|
||||||
"""
|
"""
|
||||||
Returns the path of the JSON file for a module, empty if doesn't exitst.
|
Returns the path of the JSON file for a module, empty if doesn't exitst.
|
||||||
@@ -422,6 +477,21 @@ class RuntimeTestContext(TestContext):
|
|||||||
|
|
||||||
return needed_packages
|
return needed_packages
|
||||||
|
|
||||||
|
def _extract_in_tmpdir(self, pkg):
|
||||||
|
""""
|
||||||
|
Returns path to a temp directory where the package was
|
||||||
|
extracted without dependencies.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from oeqa.utils.package_manager import get_package_manager
|
||||||
|
|
||||||
|
pkg_path = os.path.join(self.d.getVar("TEST_INSTALL_TMP_DIR", True), pkg)
|
||||||
|
pm = get_package_manager(self.d, pkg_path)
|
||||||
|
extract_dir = pm.extract(pkg)
|
||||||
|
shutil.rmtree(pkg_path)
|
||||||
|
|
||||||
|
return extract_dir
|
||||||
|
|
||||||
class ImageTestContext(RuntimeTestContext):
|
class ImageTestContext(RuntimeTestContext):
|
||||||
def __init__(self, d, target, host_dumper):
|
def __init__(self, d, target, host_dumper):
|
||||||
super(ImageTestContext, self).__init__(d, target)
|
super(ImageTestContext, self).__init__(d, target)
|
||||||
|
|||||||
Reference in New Issue
Block a user