diff options
| author | Mariano Lopez <mariano.lopez@linux.intel.com> | 2016-05-24 12:44:14 +0000 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-05-30 15:58:13 +0100 |
| commit | 92afca71817e6f5d95d2566eee1f2c9f70c45ef9 (patch) | |
| tree | 86ad8d12d5b4e85a0f34b2e21097e54deedf473d | |
| parent | 8a6891095831f9d2b58d5c943093f21eda8e7616 (diff) | |
| download | poky-92afca71817e6f5d95d2566eee1f2c9f70c45ef9.tar.gz | |
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>
| -rw-r--r-- | meta/lib/oeqa/oetest.py | 70 |
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 | |||
| 12 | import inspect | 12 | import inspect |
| 13 | import subprocess | 13 | import subprocess |
| 14 | import signal | 14 | import signal |
| 15 | import shutil | ||
| 15 | try: | 16 | try: |
| 16 | import bb | 17 | import bb |
| 17 | except ImportError: | 18 | except 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 | |||
| 425 | class ImageTestContext(RuntimeTestContext): | 495 | class 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) |
