summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/utils')
-rw-r--r--meta/lib/oeqa/utils/commands.py49
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
17from oeqa.utils import CommandError 17from oeqa.utils import CommandError
18from oeqa.utils import ftools 18from oeqa.utils import ftools
19import re 19import re
20import contextlib
20 21
21class Command(object): 22class Command(object):
22 def __init__(self, command, bg=False, timeout=None, data=None, **options): 23 def __init__(self, command, bg=False, timeout=None, data=None, **options):
@@ -173,3 +174,51 @@ def create_temp_layer(templayerdir, templayername, priority=999, recipepathspec=
173 f.write('BBFILE_PATTERN_%s = "^${LAYERDIR}/"\n' % templayername) 174 f.write('BBFILE_PATTERN_%s = "^${LAYERDIR}/"\n' % templayername)
174 f.write('BBFILE_PRIORITY_%s = "%d"\n' % (templayername, priority)) 175 f.write('BBFILE_PRIORITY_%s = "%d"\n' % (templayername, priority))
175 f.write('BBFILE_PATTERN_IGNORE_EMPTY_%s = "1"\n' % templayername) 176 f.write('BBFILE_PATTERN_IGNORE_EMPTY_%s = "1"\n' % templayername)
177
178
179@contextlib.contextmanager
180def runqemu(pn, test):
181
182 import bb.tinfoil
183 import bb.build
184
185 tinfoil = bb.tinfoil.Tinfoil()
186 tinfoil.prepare(False)
187 try:
188 tinfoil.logger.setLevel(logging.WARNING)
189 import oeqa.targetcontrol
190 tinfoil.config_data.setVar("TEST_LOG_DIR", "${WORKDIR}/testimage")
191 tinfoil.config_data.setVar("TEST_QEMUBOOT_TIMEOUT", "90")
192 import oe.recipeutils
193 recipefile = oe.recipeutils.pn_to_recipe(tinfoil.cooker, pn)
194 recipedata = oe.recipeutils.parse_recipe(recipefile, [], tinfoil.config_data)
195
196 # The QemuRunner log is saved out, but we need to ensure it is at the right
197 # log level (and then ensure that since it's a child of the BitBake logger,
198 # we disable propagation so we don't then see the log events on the console)
199 logger = logging.getLogger('BitBake.QemuRunner')
200 logger.setLevel(logging.DEBUG)
201 logger.propagate = False
202 logdir = recipedata.getVar("TEST_LOG_DIR", True)
203
204 qemu = oeqa.targetcontrol.QemuTarget(recipedata)
205 finally:
206 # We need to shut down tinfoil early here in case we actually want
207 # to run tinfoil-using utilities with the running QEMU instance.
208 # Luckily QemuTarget doesn't need it after the constructor.
209 tinfoil.shutdown()
210
211 try:
212 qemu.deploy()
213 try:
214 qemu.start()
215 except bb.build.FuncFailed:
216 raise Exception('Failed to start QEMU - see the logs in %s' % logdir)
217
218 yield qemu
219
220 finally:
221 try:
222 qemu.stop()
223 except:
224 pass