summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/oetest.py
diff options
context:
space:
mode:
authorMariano Lopez <mariano.lopez@linux.intel.com>2016-06-06 07:15:41 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-06-07 15:22:38 +0100
commit938f05333b94e91a628c940588e2bafc88b8bdef (patch)
tree0feb8cae22ed025cc6ac30c38aa00931684c970f /meta/lib/oeqa/oetest.py
parentd9b3ee8b38f877c1723e48f1aa311c28102786fb (diff)
downloadpoky-938f05333b94e91a628c940588e2bafc88b8bdef.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] (From OE-Core rev: b7111d9e9d64d21f57729d1ac1865aea6e54cc8b) 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.py74
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):
81 super(oeRuntimeTest, self).__init__(methodName) 81 super(oeRuntimeTest, self).__init__(methodName)
82 82
83 def setUp(self): 83 def setUp(self):
84 # Install packages in the DUT
85 self.tc.install_uninstall_packages(self.id())
86
84 # Check if test needs to run 87 # Check if test needs to run
85 if self.tc.sigterm: 88 if self.tc.sigterm:
86 self.fail("Got SIGTERM") 89 self.fail("Got SIGTERM")
@@ -94,6 +97,9 @@ class oeRuntimeTest(oeTest):
94 pass 97 pass
95 98
96 def tearDown(self): 99 def tearDown(self):
100 # Unistall packages in the DUT
101 self.tc.install_uninstall_packages(self.id(), False)
102
97 res = getResults() 103 res = getResults()
98 # If a test fails or there is an exception dump 104 # If a test fails or there is an exception dump
99 # for QemuTarget only 105 # for QemuTarget only
@@ -281,6 +287,19 @@ class TestContext(object):
281 287
282 return modules 288 return modules
283 289
290 def getModulefromID(self, test_id):
291 """
292 Returns the test module based on a test id.
293 """
294
295 module_name = ".".join(test_id.split(".")[:3])
296 modules = self.getTestModules()
297 for module in modules:
298 if module.name == module_name:
299 return module
300
301 return None
302
284 def getTests(self, test): 303 def getTests(self, test):
285 '''Return all individual tests executed when running the suite.''' 304 '''Return all individual tests executed when running the suite.'''
286 # Unfortunately unittest does not have an API for this, so we have 305 # Unfortunately unittest does not have an API for this, so we have
@@ -521,6 +540,43 @@ class RuntimeTestContext(TestContext):
521 shutil.copy2(file_path, dst_dir) 540 shutil.copy2(file_path, dst_dir)
522 shutil.rmtree(pkg_path) 541 shutil.rmtree(pkg_path)
523 542
543 def install_uninstall_packages(self, test_id, pkg_dir, install):
544 """
545 Check if the test requires a package and Install/Unistall it in the DUT
546 """
547
548 test = test_id.split(".")[4]
549 module = self.getModulefromID(test_id)
550 json = self._getJsonFile(module)
551 if json:
552 needed_packages = self._getNeededPackages(json, test)
553 if needed_packages:
554 self._install_uninstall_packages(needed_packages, pkg_dir, install)
555
556 def _install_uninstall_packages(self, needed_packages, pkg_dir, install=True):
557 """
558 Install/Unistall packages in the DUT without using a package manager
559 """
560
561 if isinstance(needed_packages, dict):
562 packages = [needed_packages]
563 elif isinstance(needed_packages, list):
564 packages = needed_packages
565
566 for package in packages:
567 pkg = package["pkg"]
568 rm = package.get("rm", False)
569 extract = package.get("extract", True)
570 src_dir = os.path.join(pkg_dir, pkg)
571
572 # Install package
573 if install and extract:
574 self.target.connection.copy_dir_to(src_dir, "/")
575
576 # Unistall package
577 elif not install and rm:
578 self.target.connection.delete_dir_structure(src_dir, "/")
579
524class ImageTestContext(RuntimeTestContext): 580class ImageTestContext(RuntimeTestContext):
525 def __init__(self, d, target, host_dumper): 581 def __init__(self, d, target, host_dumper):
526 super(ImageTestContext, self).__init__(d, target) 582 super(ImageTestContext, self).__init__(d, target)
@@ -536,11 +592,29 @@ class ImageTestContext(RuntimeTestContext):
536 self.sigterm = True 592 self.sigterm = True
537 self.target.stop() 593 self.target.stop()
538 594
595 def install_uninstall_packages(self, test_id, install=True):
596 """
597 Check if the test requires a package and Install/Unistall it in the DUT
598 """
599
600 pkg_dir = self.d.getVar("TEST_EXTRACTED_DIR", True)
601 super(ImageTestContext, self).install_uninstall_packages(test_id, pkg_dir, install)
602
539class ExportTestContext(RuntimeTestContext): 603class ExportTestContext(RuntimeTestContext):
540 def __init__(self, d, target, exported=False): 604 def __init__(self, d, target, exported=False):
541 super(ExportTestContext, self).__init__(d, target, exported) 605 super(ExportTestContext, self).__init__(d, target, exported)
542 self.sigterm = None 606 self.sigterm = None
543 607
608 def install_uninstall_packages(self, test_id, install=True):
609 """
610 Check if the test requires a package and Install/Unistall it in the DUT
611 """
612
613 export_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
614 extracted_dir = self.d.getVar("TEST_EXPORT_EXTRACTED_DIR", True)
615 pkg_dir = os.path.join(export_dir, extracted_dir)
616 super(ExportTestContext, self).install_uninstall_packages(test_id, pkg_dir, install)
617
544class SDKTestContext(TestContext): 618class SDKTestContext(TestContext):
545 def __init__(self, d, sdktestdir, sdkenv, tcname, *args): 619 def __init__(self, d, sdktestdir, sdkenv, tcname, *args):
546 super(SDKTestContext, self).__init__(d) 620 super(SDKTestContext, self).__init__(d)