summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oeqa/oetest.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py
index 7abd850f63..8dd494a064 100644
--- a/meta/lib/oeqa/oetest.py
+++ b/meta/lib/oeqa/oetest.py
@@ -12,6 +12,7 @@ import unittest
12import inspect 12import inspect
13import subprocess 13import subprocess
14import signal 14import signal
15import shutil
15try: 16try:
16 import bb 17 import bb
17except ImportError: 18except ImportError:
@@ -264,6 +265,22 @@ class TestContext(object):
264 265
265 return testslist 266 return testslist
266 267
268 def getTestModules(self):
269 """
270 Returns all the test modules in the testlist.
271 """
272
273 import pkgutil
274
275 modules = []
276 for test in self.testslist:
277 if re.search("\w+\.\w+\.test_\S+", test):
278 test = '.'.join(t.split('.')[:3])
279 module = pkgutil.get_loader(test)
280 modules.append(module)
281
282 return modules
283
267 def getTests(self, test): 284 def getTests(self, test):
268 '''Return all individual tests executed when running the suite.''' 285 '''Return all individual tests executed when running the suite.'''
269 # Unfortunately unittest does not have an API for this, so we have 286 # Unfortunately unittest does not have an API for this, so we have
@@ -385,6 +402,44 @@ class RuntimeTestContext(TestContext):
385 if oeTest.hasPackage("procps"): 402 if oeTest.hasPackage("procps"):
386 oeRuntimeTest.pscmd = "ps -ef" 403 oeRuntimeTest.pscmd = "ps -ef"
387 404
405 def extract_packages(self):
406 """
407 Find and extract packages that will be needed during runtime.
408 """
409
410 needed_packages = {}
411 extracted_path = self.d.getVar("TEST_EXTRACTED_DIR", True)
412 modules = self.getTestModules()
413 bbpaths = self.d.getVar("BBPATH", True).split(":")
414
415 for module in modules:
416 json_file = self._getJsonFile(module)
417 if json_file:
418 needed_packages = self._getNeededPackages(json_file)
419
420 for key,value in needed_packages.items():
421 packages = ()
422 if isinstance(value, dict):
423 packages = (value, )
424 elif isinstance(value, list):
425 packages = value
426 else:
427 bb.fatal("Failed to process needed packages for %s; "
428 "Value must be a dict or list" % key)
429
430 for package in packages:
431 pkg = package["pkg"]
432 rm = package.get("rm", False)
433 extract = package.get("extract", True)
434 if extract:
435 dst_dir = os.path.join(extracted_path, pkg)
436
437 # Extract package and copy it to TEST_EXTRACTED_DIR
438 if extract and not os.path.exists(dst_dir):
439 pkg_dir = self._extract_in_tmpdir(pkg)
440 shutil.copytree(pkg_dir, dst_dir)
441 shutil.rmtree(pkg_dir)
442
388 def _getJsonFile(self, module): 443 def _getJsonFile(self, module):
389 """ 444 """
390 Returns the path of the JSON file for a module, empty if doesn't exitst. 445 Returns the path of the JSON file for a module, empty if doesn't exitst.
@@ -422,6 +477,21 @@ class RuntimeTestContext(TestContext):
422 477
423 return needed_packages 478 return needed_packages
424 479
480 def _extract_in_tmpdir(self, pkg):
481 """"
482 Returns path to a temp directory where the package was
483 extracted without dependencies.
484 """
485
486 from oeqa.utils.package_manager import get_package_manager
487
488 pkg_path = os.path.join(self.d.getVar("TEST_INSTALL_TMP_DIR", True), pkg)
489 pm = get_package_manager(self.d, pkg_path)
490 extract_dir = pm.extract(pkg)
491 shutil.rmtree(pkg_path)
492
493 return extract_dir
494
425class ImageTestContext(RuntimeTestContext): 495class ImageTestContext(RuntimeTestContext):
426 def __init__(self, d, target, host_dumper): 496 def __init__(self, d, target, host_dumper):
427 super(ImageTestContext, self).__init__(d, target) 497 super(ImageTestContext, self).__init__(d, target)