diff options
Diffstat (limited to 'meta/lib/oeqa/utils')
-rw-r--r-- | meta/lib/oeqa/utils/commands.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/meta/lib/oeqa/utils/commands.py b/meta/lib/oeqa/utils/commands.py index 1be7bedd40..50a08dc1fa 100644 --- a/meta/lib/oeqa/utils/commands.py +++ b/meta/lib/oeqa/utils/commands.py @@ -17,6 +17,7 @@ import logging from oeqa.utils import CommandError from oeqa.utils import ftools import re +import contextlib class Command(object): def __init__(self, command, bg=False, timeout=None, data=None, **options): @@ -173,3 +174,51 @@ def create_temp_layer(templayerdir, templayername, priority=999, recipepathspec= f.write('BBFILE_PATTERN_%s = "^${LAYERDIR}/"\n' % templayername) f.write('BBFILE_PRIORITY_%s = "%d"\n' % (templayername, priority)) f.write('BBFILE_PATTERN_IGNORE_EMPTY_%s = "1"\n' % templayername) + + +@contextlib.contextmanager +def runqemu(pn, test): + + import bb.tinfoil + import bb.build + + tinfoil = bb.tinfoil.Tinfoil() + tinfoil.prepare(False) + try: + tinfoil.logger.setLevel(logging.WARNING) + import oeqa.targetcontrol + tinfoil.config_data.setVar("TEST_LOG_DIR", "${WORKDIR}/testimage") + tinfoil.config_data.setVar("TEST_QEMUBOOT_TIMEOUT", "90") + import oe.recipeutils + recipefile = oe.recipeutils.pn_to_recipe(tinfoil.cooker, pn) + recipedata = oe.recipeutils.parse_recipe(recipefile, [], tinfoil.config_data) + + # The QemuRunner log is saved out, but we need to ensure it is at the right + # log level (and then ensure that since it's a child of the BitBake logger, + # we disable propagation so we don't then see the log events on the console) + logger = logging.getLogger('BitBake.QemuRunner') + logger.setLevel(logging.DEBUG) + logger.propagate = False + logdir = recipedata.getVar("TEST_LOG_DIR", True) + + qemu = oeqa.targetcontrol.QemuTarget(recipedata) + finally: + # We need to shut down tinfoil early here in case we actually want + # to run tinfoil-using utilities with the running QEMU instance. + # Luckily QemuTarget doesn't need it after the constructor. + tinfoil.shutdown() + + try: + qemu.deploy() + try: + qemu.start() + except bb.build.FuncFailed: + raise Exception('Failed to start QEMU - see the logs in %s' % logdir) + + yield qemu + + finally: + try: + qemu.stop() + except: + pass |