diff options
author | Mariano Lopez <mariano.lopez@linux.intel.com> | 2016-06-06 07:15:41 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-06-06 22:48:04 +0100 |
commit | b7111d9e9d64d21f57729d1ac1865aea6e54cc8b (patch) | |
tree | 1c055d0bd0f6f984aed857620f070c59680f57ee /meta/lib/oeqa/oetest.py | |
parent | a26f23d3ce8f7e9f59dbc9bf27516377fd7a0a6d (diff) | |
download | openembedded-core-contrib-b7111d9e9d64d21f57729d1ac1865aea6e54cc8b.tar.gz |
oetest.py: Add install/uninstall functionality for DUTs
Add the functionality to install/unistall packages in the
DUTs without the use of the package manager. This is possible
with the extraction introduced in package manager class.
testimage and testexport bbclasses has been modified in order
to support this new feature.
[YOCTO #8694]
Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/oetest.py')
-rw-r--r-- | meta/lib/oeqa/oetest.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py index 819f95987b..feb0f71eb4 100644 --- a/meta/lib/oeqa/oetest.py +++ b/meta/lib/oeqa/oetest.py @@ -81,6 +81,9 @@ class oeRuntimeTest(oeTest): super(oeRuntimeTest, self).__init__(methodName) def setUp(self): + # Install packages in the DUT + self.tc.install_uninstall_packages(self.id()) + # Check if test needs to run if self.tc.sigterm: self.fail("Got SIGTERM") @@ -94,6 +97,9 @@ class oeRuntimeTest(oeTest): pass def tearDown(self): + # Unistall packages in the DUT + self.tc.install_uninstall_packages(self.id(), False) + res = getResults() # If a test fails or there is an exception dump # for QemuTarget only @@ -281,6 +287,19 @@ class TestContext(object): return modules + def getModulefromID(self, test_id): + """ + Returns the test module based on a test id. + """ + + module_name = ".".join(test_id.split(".")[:3]) + modules = self.getTestModules() + for module in modules: + if module.name == module_name: + return module + + return None + def getTests(self, test): '''Return all individual tests executed when running the suite.''' # Unfortunately unittest does not have an API for this, so we have @@ -521,6 +540,43 @@ class RuntimeTestContext(TestContext): shutil.copy2(file_path, dst_dir) shutil.rmtree(pkg_path) + def install_uninstall_packages(self, test_id, pkg_dir, install): + """ + Check if the test requires a package and Install/Unistall it in the DUT + """ + + test = test_id.split(".")[4] + module = self.getModulefromID(test_id) + json = self._getJsonFile(module) + if json: + needed_packages = self._getNeededPackages(json, test) + if needed_packages: + self._install_uninstall_packages(needed_packages, pkg_dir, install) + + def _install_uninstall_packages(self, needed_packages, pkg_dir, install=True): + """ + Install/Unistall packages in the DUT without using a package manager + """ + + if isinstance(needed_packages, dict): + packages = [needed_packages] + elif isinstance(needed_packages, list): + packages = needed_packages + + for package in packages: + pkg = package["pkg"] + rm = package.get("rm", False) + extract = package.get("extract", True) + src_dir = os.path.join(pkg_dir, pkg) + + # Install package + if install and extract: + self.target.connection.copy_dir_to(src_dir, "/") + + # Unistall package + elif not install and rm: + self.target.connection.delete_dir_structure(src_dir, "/") + class ImageTestContext(RuntimeTestContext): def __init__(self, d, target, host_dumper): super(ImageTestContext, self).__init__(d, target) @@ -536,11 +592,29 @@ class ImageTestContext(RuntimeTestContext): self.sigterm = True self.target.stop() + def install_uninstall_packages(self, test_id, install=True): + """ + Check if the test requires a package and Install/Unistall it in the DUT + """ + + pkg_dir = self.d.getVar("TEST_EXTRACTED_DIR", True) + super(ImageTestContext, self).install_uninstall_packages(test_id, pkg_dir, install) + class ExportTestContext(RuntimeTestContext): def __init__(self, d, target, exported=False): super(ExportTestContext, self).__init__(d, target, exported) self.sigterm = None + def install_uninstall_packages(self, test_id, install=True): + """ + Check if the test requires a package and Install/Unistall it in the DUT + """ + + export_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + extracted_dir = self.d.getVar("TEST_EXPORT_EXTRACTED_DIR", True) + pkg_dir = os.path.join(export_dir, extracted_dir) + super(ExportTestContext, self).install_uninstall_packages(test_id, pkg_dir, install) + class SDKTestContext(TestContext): def __init__(self, d, sdktestdir, sdkenv, tcname, *args): super(SDKTestContext, self).__init__(d) |