mirror of
https://git.yoctoproject.org/poky
synced 2026-05-30 12:29:55 +00:00
testimage.bbclass: Add package install feature
This allows to use the package install feature with the new OEQA framework. [YOCTO #10234] (From OE-Core rev: 077dc19445574457769eb4f231de97e8059cb75e) Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
f8d7db1905
commit
58789be270
@@ -159,7 +159,6 @@ def testimage_main(d):
|
|||||||
pn = d.getVar("PN")
|
pn = d.getVar("PN")
|
||||||
|
|
||||||
bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR"))
|
bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR"))
|
||||||
#test_create_extract_dirs(d)
|
|
||||||
|
|
||||||
image_name = ("%s/%s" % (d.getVar('DEPLOY_DIR_IMAGE'),
|
image_name = ("%s/%s" % (d.getVar('DEPLOY_DIR_IMAGE'),
|
||||||
d.getVar('IMAGE_LINK_NAME')))
|
d.getVar('IMAGE_LINK_NAME')))
|
||||||
@@ -170,6 +169,8 @@ def testimage_main(d):
|
|||||||
image_manifest = "%s.manifest" % image_name
|
image_manifest = "%s.manifest" % image_name
|
||||||
image_packages = OERuntimeTestContextExecutor.readPackagesManifest(image_manifest)
|
image_packages = OERuntimeTestContextExecutor.readPackagesManifest(image_manifest)
|
||||||
|
|
||||||
|
extract_dir = d.getVar("TEST_EXTRACTED_DIR")
|
||||||
|
|
||||||
# Get machine
|
# Get machine
|
||||||
machine = d.getVar("MACHINE")
|
machine = d.getVar("MACHINE")
|
||||||
|
|
||||||
@@ -236,7 +237,8 @@ def testimage_main(d):
|
|||||||
d.getVar("TEST_SERVER_IP"), **target_kwargs)
|
d.getVar("TEST_SERVER_IP"), **target_kwargs)
|
||||||
|
|
||||||
# test context
|
# test context
|
||||||
tc = OERuntimeTestContext(td, logger, target, host_dumper, image_packages)
|
tc = OERuntimeTestContext(td, logger, target, host_dumper,
|
||||||
|
image_packages, extract_dir)
|
||||||
|
|
||||||
# Load tests before starting the target
|
# Load tests before starting the target
|
||||||
test_paths = get_runtime_paths(d)
|
test_paths = get_runtime_paths(d)
|
||||||
@@ -343,22 +345,13 @@ def package_extraction(d, test_suites):
|
|||||||
from oeqa.utils.package_manager import find_packages_to_extract
|
from oeqa.utils.package_manager import find_packages_to_extract
|
||||||
from oeqa.utils.package_manager import extract_packages
|
from oeqa.utils.package_manager import extract_packages
|
||||||
|
|
||||||
test_create_extract_dirs(d)
|
bb.utils.remove(d.getVar("TEST_NEEDED_PACKAGES_DIR"), recurse=True)
|
||||||
packages = find_packages_to_extract(test_suites)
|
packages = find_packages_to_extract(test_suites)
|
||||||
extract_packages(d, packages)
|
if packages:
|
||||||
|
bb.utils.mkdirhier(d.getVar("TEST_INSTALL_TMP_DIR"))
|
||||||
def test_create_extract_dirs(d):
|
bb.utils.mkdirhier(d.getVar("TEST_PACKAGED_DIR"))
|
||||||
install_path = d.getVar("TEST_INSTALL_TMP_DIR")
|
bb.utils.mkdirhier(d.getVar("TEST_EXTRACTED_DIR"))
|
||||||
package_path = d.getVar("TEST_PACKAGED_DIR")
|
extract_packages(d, packages)
|
||||||
extracted_path = d.getVar("TEST_EXTRACTED_DIR")
|
|
||||||
bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR"))
|
|
||||||
bb.utils.remove(install_path, recurse=True)
|
|
||||||
bb.utils.remove(package_path, recurse=True)
|
|
||||||
bb.utils.remove(extracted_path, recurse=True)
|
|
||||||
bb.utils.mkdirhier(install_path)
|
|
||||||
bb.utils.mkdirhier(package_path)
|
|
||||||
bb.utils.mkdirhier(extracted_path)
|
|
||||||
|
|
||||||
|
|
||||||
testimage_main[vardepsexclude] += "BB_ORIGENV DATETIME"
|
testimage_main[vardepsexclude] += "BB_ORIGENV DATETIME"
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ def getSuiteCases(suite):
|
|||||||
Returns individual test from a test suite.
|
Returns individual test from a test suite.
|
||||||
"""
|
"""
|
||||||
tests = []
|
tests = []
|
||||||
for item in suite:
|
|
||||||
if isinstance(item, unittest.suite.TestSuite):
|
if isinstance(suite, unittest.TestCase):
|
||||||
|
tests.append(suite)
|
||||||
|
elif isinstance(suite, unittest.suite.TestSuite):
|
||||||
|
for item in suite:
|
||||||
tests.extend(getSuiteCases(item))
|
tests.extend(getSuiteCases(item))
|
||||||
elif isinstance(item, unittest.TestCase):
|
|
||||||
tests.append(item)
|
|
||||||
return tests
|
return tests
|
||||||
|
|
||||||
def getSuiteModules(suite):
|
def getSuiteModules(suite):
|
||||||
|
|||||||
@@ -2,7 +2,16 @@
|
|||||||
# Released under the MIT license (see COPYING.MIT)
|
# Released under the MIT license (see COPYING.MIT)
|
||||||
|
|
||||||
from oeqa.core.case import OETestCase
|
from oeqa.core.case import OETestCase
|
||||||
|
from oeqa.utils.package_manager import install_package, uninstall_package
|
||||||
|
|
||||||
class OERuntimeTestCase(OETestCase):
|
class OERuntimeTestCase(OETestCase):
|
||||||
# target instance set by OERuntimeTestLoader.
|
# target instance set by OERuntimeTestLoader.
|
||||||
target = None
|
target = None
|
||||||
|
|
||||||
|
def _oeSetUp(self):
|
||||||
|
super(OERuntimeTestCase, self)._oeSetUp()
|
||||||
|
install_package(self)
|
||||||
|
|
||||||
|
def _oeTearDown(self):
|
||||||
|
super(OERuntimeTestCase, self)._oeTearDown()
|
||||||
|
uninstall_package(self)
|
||||||
|
|||||||
@@ -15,12 +15,14 @@ class OERuntimeTestContext(OETestContext):
|
|||||||
runtime_files_dir = os.path.join(
|
runtime_files_dir = os.path.join(
|
||||||
os.path.dirname(os.path.abspath(__file__)), "files")
|
os.path.dirname(os.path.abspath(__file__)), "files")
|
||||||
|
|
||||||
def __init__(self, td, logger, target, host_dumper, image_packages):
|
def __init__(self, td, logger, target,
|
||||||
|
host_dumper, image_packages, extract_dir):
|
||||||
super(OERuntimeTestContext, self).__init__(td, logger)
|
super(OERuntimeTestContext, self).__init__(td, logger)
|
||||||
|
|
||||||
self.target = target
|
self.target = target
|
||||||
self.image_packages = image_packages
|
self.image_packages = image_packages
|
||||||
self.host_dumper = host_dumper
|
self.host_dumper = host_dumper
|
||||||
|
self.extract_dir = extract_dir
|
||||||
self._set_target_cmds()
|
self._set_target_cmds()
|
||||||
|
|
||||||
def _set_target_cmds(self):
|
def _set_target_cmds(self):
|
||||||
@@ -45,6 +47,7 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
|
|||||||
default_server_ip = '192.168.7.1'
|
default_server_ip = '192.168.7.1'
|
||||||
default_target_ip = '192.168.7.2'
|
default_target_ip = '192.168.7.2'
|
||||||
default_host_dumper_dir = '/tmp/oe-saved-tests'
|
default_host_dumper_dir = '/tmp/oe-saved-tests'
|
||||||
|
default_extract_dir = 'extract_dir'
|
||||||
|
|
||||||
def register_commands(self, logger, subparsers):
|
def register_commands(self, logger, subparsers):
|
||||||
super(OERuntimeTestContextExecutor, self).register_commands(logger, subparsers)
|
super(OERuntimeTestContextExecutor, self).register_commands(logger, subparsers)
|
||||||
@@ -72,6 +75,9 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
|
|||||||
runtime_group.add_argument('--packages-manifest', action='store',
|
runtime_group.add_argument('--packages-manifest', action='store',
|
||||||
help="Package manifest of the image under test")
|
help="Package manifest of the image under test")
|
||||||
|
|
||||||
|
runtime_group.add_argument('--extract-dir', action='store',
|
||||||
|
help='Directory where extracted packages reside')
|
||||||
|
|
||||||
runtime_group.add_argument('--qemu-boot', action='store',
|
runtime_group.add_argument('--qemu-boot', action='store',
|
||||||
help="Qemu boot configuration, only needed when target_type is QEMU.")
|
help="Qemu boot configuration, only needed when target_type is QEMU.")
|
||||||
|
|
||||||
@@ -126,4 +132,8 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
|
|||||||
OERuntimeTestContextExecutor.readPackagesManifest(
|
OERuntimeTestContextExecutor.readPackagesManifest(
|
||||||
args.packages_manifest)
|
args.packages_manifest)
|
||||||
|
|
||||||
|
self.tc_kwargs['init']['extract_dir'] = \
|
||||||
|
OERuntimeTestContextExecutor.readPackagesManifest(
|
||||||
|
args.extract_dir)
|
||||||
|
|
||||||
_executor_class = OERuntimeTestContextExecutor
|
_executor_class = OERuntimeTestContextExecutor
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import bb
|
import os
|
||||||
import json
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
from oeqa.core.utils.test import getCaseFile, getCaseMethod
|
||||||
|
|
||||||
def get_package_manager(d, root_path):
|
def get_package_manager(d, root_path):
|
||||||
"""
|
"""
|
||||||
@@ -86,6 +87,7 @@ def extract_packages(d, needed_packages):
|
|||||||
Extract packages that will be needed during runtime.
|
Extract packages that will be needed during runtime.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import bb
|
||||||
import oe.path
|
import oe.path
|
||||||
|
|
||||||
extracted_path = d.getVar('TEST_EXTRACTED_DIR')
|
extracted_path = d.getVar('TEST_EXTRACTED_DIR')
|
||||||
@@ -152,20 +154,38 @@ def _copy_package(d, pkg):
|
|||||||
shutil.copy2(file_path, dst_dir)
|
shutil.copy2(file_path, dst_dir)
|
||||||
shutil.rmtree(pkg_path)
|
shutil.rmtree(pkg_path)
|
||||||
|
|
||||||
def install_uninstall_packages(self, test_id, pkg_dir, install):
|
def install_package(test_case):
|
||||||
"""
|
"""
|
||||||
Check if the test requires a package and Install/Unistall it in the DUT
|
Installs package in DUT if required.
|
||||||
"""
|
"""
|
||||||
|
needed_packages = test_needs_package(test_case)
|
||||||
|
if needed_packages:
|
||||||
|
_install_uninstall_packages(needed_packages, test_case, True)
|
||||||
|
|
||||||
test = test_id.split('.')[4]
|
def uninstall_package(test_case):
|
||||||
module = self.getModulefromID(test_id)
|
"""
|
||||||
json = self._getJsonFile(module)
|
Uninstalls package in DUT if required.
|
||||||
if json:
|
"""
|
||||||
needed_packages = self._getNeededPackages(json, test)
|
needed_packages = test_needs_package(test_case)
|
||||||
|
if needed_packages:
|
||||||
|
_install_uninstall_packages(needed_packages, test_case, False)
|
||||||
|
|
||||||
|
def test_needs_package(test_case):
|
||||||
|
"""
|
||||||
|
Checks if a test case requires to install/uninstall packages.
|
||||||
|
"""
|
||||||
|
test_file = getCaseFile(test_case)
|
||||||
|
json_file = _get_json_file(test_file)
|
||||||
|
|
||||||
|
if json_file:
|
||||||
|
test_method = getCaseMethod(test_case)
|
||||||
|
needed_packages = _get_needed_packages(json_file, test_method)
|
||||||
if needed_packages:
|
if needed_packages:
|
||||||
self._install_uninstall_packages(needed_packages, pkg_dir, install)
|
return needed_packages
|
||||||
|
|
||||||
def _install_uninstall_packages(self, needed_packages, pkg_dir, install=True):
|
return None
|
||||||
|
|
||||||
|
def _install_uninstall_packages(needed_packages, test_case, install=True):
|
||||||
"""
|
"""
|
||||||
Install/Unistall packages in the DUT without using a package manager
|
Install/Unistall packages in the DUT without using a package manager
|
||||||
"""
|
"""
|
||||||
@@ -179,12 +199,12 @@ def _install_uninstall_packages(self, needed_packages, pkg_dir, install=True):
|
|||||||
pkg = package['pkg']
|
pkg = package['pkg']
|
||||||
rm = package.get('rm', False)
|
rm = package.get('rm', False)
|
||||||
extract = package.get('extract', True)
|
extract = package.get('extract', True)
|
||||||
src_dir = os.path.join(pkg_dir, pkg)
|
src_dir = os.path.join(test_case.tc.extract_dir, pkg)
|
||||||
|
|
||||||
# Install package
|
# Install package
|
||||||
if install and extract:
|
if install and extract:
|
||||||
self.target.connection.copy_dir_to(src_dir, '/')
|
test_case.tc.target.copyDirTo(src_dir, '/')
|
||||||
|
|
||||||
# Unistall package
|
# Unistall package
|
||||||
elif not install and rm:
|
elif not install and rm:
|
||||||
self.target.connection.delete_dir_structure(src_dir, '/')
|
test_case.tc.target.deleteDirStructure(src_dir, '/')
|
||||||
|
|||||||
Reference in New Issue
Block a user