summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/lib/oeqa/core/target/qemu.py2
-rw-r--r--meta/lib/oeqa/selftest/cases/runqemu.py5
-rw-r--r--meta/lib/oeqa/targetcontrol.py25
-rw-r--r--meta/lib/oeqa/utils/commands.py25
-rw-r--r--meta/lib/oeqa/utils/qemurunner.py7
-rw-r--r--meta/lib/oeqa/utils/qemutinyrunner.py3
6 files changed, 26 insertions, 41 deletions
diff --git a/meta/lib/oeqa/core/target/qemu.py b/meta/lib/oeqa/core/target/qemu.py
index 2dc521c216..d359bf9fe3 100644
--- a/meta/lib/oeqa/core/target/qemu.py
+++ b/meta/lib/oeqa/core/target/qemu.py
@@ -31,7 +31,7 @@ class OEQemuTarget(OESSHTarget):
31 deploy_dir_image=dir_image, display=display, 31 deploy_dir_image=dir_image, display=display,
32 logfile=bootlog, boottime=boottime, 32 logfile=bootlog, boottime=boottime,
33 use_kvm=kvm, dump_dir=dump_dir, 33 use_kvm=kvm, dump_dir=dump_dir,
34 dump_host_cmds=dump_host_cmds) 34 dump_host_cmds=dump_host_cmds, logger=logger)
35 35
36 def start(self, params=None, extra_bootparams=None): 36 def start(self, params=None, extra_bootparams=None):
37 if self.runner.start(params, extra_bootparams=extra_bootparams): 37 if self.runner.start(params, extra_bootparams=extra_bootparams):
diff --git a/meta/lib/oeqa/selftest/cases/runqemu.py b/meta/lib/oeqa/selftest/cases/runqemu.py
index 1a8d12178d..47d41f5218 100644
--- a/meta/lib/oeqa/selftest/cases/runqemu.py
+++ b/meta/lib/oeqa/selftest/cases/runqemu.py
@@ -3,7 +3,6 @@
3# 3#
4 4
5import re 5import re
6import logging
7 6
8from oeqa.selftest.case import OESelftestTestCase 7from oeqa.selftest.case import OESelftestTestCase
9from oeqa.utils.commands import bitbake, runqemu, get_bb_var 8from oeqa.utils.commands import bitbake, runqemu, get_bb_var
@@ -24,10 +23,6 @@ class RunqemuTests(OESelftestTestCase):
24 self.fstypes = "ext4 iso hddimg wic.vmdk wic.qcow2 wic.vdi" 23 self.fstypes = "ext4 iso hddimg wic.vmdk wic.qcow2 wic.vdi"
25 self.cmd_common = "runqemu nographic" 24 self.cmd_common = "runqemu nographic"
26 25
27 # Avoid emit the same record multiple times.
28 mainlogger = logging.getLogger("BitBake.Main")
29 mainlogger.propagate = False
30
31 self.write_config( 26 self.write_config(
32""" 27"""
33MACHINE = "%s" 28MACHINE = "%s"
diff --git a/meta/lib/oeqa/targetcontrol.py b/meta/lib/oeqa/targetcontrol.py
index e17c89552f..f63936c3ec 100644
--- a/meta/lib/oeqa/targetcontrol.py
+++ b/meta/lib/oeqa/targetcontrol.py
@@ -18,19 +18,18 @@ from oeqa.utils.dump import TargetDumper
18from oeqa.controllers.testtargetloader import TestTargetLoader 18from oeqa.controllers.testtargetloader import TestTargetLoader
19from abc import ABCMeta, abstractmethod 19from abc import ABCMeta, abstractmethod
20 20
21logger = logging.getLogger('BitBake.QemuRunner')
22
23class BaseTarget(object, metaclass=ABCMeta): 21class BaseTarget(object, metaclass=ABCMeta):
24 22
25 supported_image_fstypes = [] 23 supported_image_fstypes = []
26 24
27 def __init__(self, d): 25 def __init__(self, d, logger):
28 self.connection = None 26 self.connection = None
29 self.ip = None 27 self.ip = None
30 self.server_ip = None 28 self.server_ip = None
31 self.datetime = d.getVar('DATETIME') 29 self.datetime = d.getVar('DATETIME')
32 self.testdir = d.getVar("TEST_LOG_DIR") 30 self.testdir = d.getVar("TEST_LOG_DIR")
33 self.pn = d.getVar("PN") 31 self.pn = d.getVar("PN")
32 self.logger = logger
34 33
35 @abstractmethod 34 @abstractmethod
36 def deploy(self): 35 def deploy(self):
@@ -40,7 +39,7 @@ class BaseTarget(object, metaclass=ABCMeta):
40 if os.path.islink(sshloglink): 39 if os.path.islink(sshloglink):
41 os.unlink(sshloglink) 40 os.unlink(sshloglink)
42 os.symlink(self.sshlog, sshloglink) 41 os.symlink(self.sshlog, sshloglink)
43 logger.info("SSH log file: %s" % self.sshlog) 42 self.logger.info("SSH log file: %s" % self.sshlog)
44 43
45 @abstractmethod 44 @abstractmethod
46 def start(self, params=None, ssh=True, extra_bootparams=None): 45 def start(self, params=None, ssh=True, extra_bootparams=None):
@@ -90,7 +89,7 @@ class QemuTarget(BaseTarget):
90 89
91 supported_image_fstypes = ['ext3', 'ext4', 'cpio.gz', 'wic'] 90 supported_image_fstypes = ['ext3', 'ext4', 'cpio.gz', 'wic']
92 91
93 def __init__(self, d, image_fstype=None, logger=None): 92 def __init__(self, d, logger, image_fstype=None):
94 93
95 super(QemuTarget, self).__init__(d, logger) 94 super(QemuTarget, self).__init__(d, logger)
96 95
@@ -120,7 +119,7 @@ class QemuTarget(BaseTarget):
120 self.qemurunnerlog = os.path.join(self.testdir, 'qemurunner_log.%s' % self.datetime) 119 self.qemurunnerlog = os.path.join(self.testdir, 'qemurunner_log.%s' % self.datetime)
121 loggerhandler = logging.FileHandler(self.qemurunnerlog) 120 loggerhandler = logging.FileHandler(self.qemurunnerlog)
122 loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s")) 121 loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
123 logger.addHandler(loggerhandler) 122 self.logger.addHandler(loggerhandler)
124 oe.path.symlink(os.path.basename(self.qemurunnerlog), os.path.join(self.testdir, 'qemurunner_log'), force=True) 123 oe.path.symlink(os.path.basename(self.qemurunnerlog), os.path.join(self.testdir, 'qemurunner_log'), force=True)
125 124
126 if d.getVar("DISTRO") == "poky-tiny": 125 if d.getVar("DISTRO") == "poky-tiny":
@@ -131,7 +130,8 @@ class QemuTarget(BaseTarget):
131 display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY"), 130 display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY"),
132 logfile = self.qemulog, 131 logfile = self.qemulog,
133 kernel = self.kernel, 132 kernel = self.kernel,
134 boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT"))) 133 boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")),
134 logger = logger)
135 else: 135 else:
136 self.runner = QemuRunner(machine=d.getVar("MACHINE"), 136 self.runner = QemuRunner(machine=d.getVar("MACHINE"),
137 rootfs=self.rootfs, 137 rootfs=self.rootfs,
@@ -142,7 +142,8 @@ class QemuTarget(BaseTarget):
142 boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")), 142 boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")),
143 use_kvm = use_kvm, 143 use_kvm = use_kvm,
144 dump_dir = dump_dir, 144 dump_dir = dump_dir,
145 dump_host_cmds = d.getVar("testimage_dump_host")) 145 dump_host_cmds = d.getVar("testimage_dump_host"),
146 logger = logger)
146 147
147 self.target_dumper = TargetDumper(dump_target_cmds, dump_dir, self.runner) 148 self.target_dumper = TargetDumper(dump_target_cmds, dump_dir, self.runner)
148 149
@@ -154,8 +155,8 @@ class QemuTarget(BaseTarget):
154 os.unlink(qemuloglink) 155 os.unlink(qemuloglink)
155 os.symlink(self.qemulog, qemuloglink) 156 os.symlink(self.qemulog, qemuloglink)
156 157
157 logger.info("rootfs file: %s" % self.rootfs) 158 self.logger.info("rootfs file: %s" % self.rootfs)
158 logger.info("Qemu log file: %s" % self.qemulog) 159 self.logger.info("Qemu log file: %s" % self.qemulog)
159 super(QemuTarget, self).deploy() 160 super(QemuTarget, self).deploy()
160 161
161 def start(self, params=None, ssh=True, extra_bootparams='', runqemuparams='', launch_cmd='', discard_writes=True): 162 def start(self, params=None, ssh=True, extra_bootparams='', runqemuparams='', launch_cmd='', discard_writes=True):
@@ -207,14 +208,14 @@ class SimpleRemoteTarget(BaseTarget):
207 self.port = addr.split(":")[1] 208 self.port = addr.split(":")[1]
208 except IndexError: 209 except IndexError:
209 self.port = None 210 self.port = None
210 logger.info("Target IP: %s" % self.ip) 211 self.logger.info("Target IP: %s" % self.ip)
211 self.server_ip = d.getVar("TEST_SERVER_IP") 212 self.server_ip = d.getVar("TEST_SERVER_IP")
212 if not self.server_ip: 213 if not self.server_ip:
213 try: 214 try:
214 self.server_ip = subprocess.check_output(['ip', 'route', 'get', self.ip ]).split("\n")[0].split()[-1] 215 self.server_ip = subprocess.check_output(['ip', 'route', 'get', self.ip ]).split("\n")[0].split()[-1]
215 except Exception as e: 216 except Exception as e:
216 bb.fatal("Failed to determine the host IP address (alternatively you can set TEST_SERVER_IP with the IP address of this machine): %s" % e) 217 bb.fatal("Failed to determine the host IP address (alternatively you can set TEST_SERVER_IP with the IP address of this machine): %s" % e)
217 logger.info("Server IP: %s" % self.server_ip) 218 self.logger.info("Server IP: %s" % self.server_ip)
218 219
219 def deploy(self): 220 def deploy(self):
220 super(SimpleRemoteTarget, self).deploy() 221 super(SimpleRemoteTarget, self).deploy()
diff --git a/meta/lib/oeqa/utils/commands.py b/meta/lib/oeqa/utils/commands.py
index 5e5345434d..0bb90028dc 100644
--- a/meta/lib/oeqa/utils/commands.py
+++ b/meta/lib/oeqa/utils/commands.py
@@ -296,6 +296,12 @@ def runqemu(pn, ssh=True, runqemuparams='', image_fstype=None, launch_cmd=None,
296 import bb.tinfoil 296 import bb.tinfoil
297 import bb.build 297 import bb.build
298 298
299 # Need a non-'BitBake' logger to capture the runner output
300 targetlogger = logging.getLogger('TargetRunner')
301 targetlogger.setLevel(logging.DEBUG)
302 handler = logging.StreamHandler(sys.stdout)
303 targetlogger.addHandler(handler)
304
299 tinfoil = bb.tinfoil.Tinfoil() 305 tinfoil = bb.tinfoil.Tinfoil()
300 tinfoil.prepare(config_only=False, quiet=True) 306 tinfoil.prepare(config_only=False, quiet=True)
301 try: 307 try:
@@ -313,31 +319,15 @@ def runqemu(pn, ssh=True, runqemuparams='', image_fstype=None, launch_cmd=None,
313 for key, value in overrides.items(): 319 for key, value in overrides.items():
314 recipedata.setVar(key, value) 320 recipedata.setVar(key, value)
315 321
316 # The QemuRunner log is saved out, but we need to ensure it is at the right
317 # log level (and then ensure that since it's a child of the BitBake logger,
318 # we disable propagation so we don't then see the log events on the console)
319 logger = logging.getLogger('BitBake.QemuRunner')
320 logger.setLevel(logging.DEBUG)
321 logger.propagate = False
322 logdir = recipedata.getVar("TEST_LOG_DIR") 322 logdir = recipedata.getVar("TEST_LOG_DIR")
323 323
324 qemu = oeqa.targetcontrol.QemuTarget(recipedata, image_fstype) 324 qemu = oeqa.targetcontrol.QemuTarget(recipedata, targetlogger, image_fstype)
325 finally: 325 finally:
326 # We need to shut down tinfoil early here in case we actually want 326 # We need to shut down tinfoil early here in case we actually want
327 # to run tinfoil-using utilities with the running QEMU instance. 327 # to run tinfoil-using utilities with the running QEMU instance.
328 # Luckily QemuTarget doesn't need it after the constructor. 328 # Luckily QemuTarget doesn't need it after the constructor.
329 tinfoil.shutdown() 329 tinfoil.shutdown()
330 330
331 # Setup bitbake logger as console handler is removed by tinfoil.shutdown
332 bblogger = logging.getLogger('BitBake')
333 bblogger.setLevel(logging.INFO)
334 console = logging.StreamHandler(sys.stdout)
335 bbformat = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
336 if sys.stdout.isatty():
337 bbformat.enable_color()
338 console.setFormatter(bbformat)
339 bblogger.addHandler(console)
340
341 try: 331 try:
342 qemu.deploy() 332 qemu.deploy()
343 try: 333 try:
@@ -352,6 +342,7 @@ def runqemu(pn, ssh=True, runqemuparams='', image_fstype=None, launch_cmd=None,
352 qemu.stop() 342 qemu.stop()
353 except: 343 except:
354 pass 344 pass
345 targetlogger.removeHandler(handler)
355 346
356def updateEnv(env_file): 347def updateEnv(env_file):
357 """ 348 """
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
index 32148871ff..82335d8456 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -28,7 +28,7 @@ re_control_char = re.compile('[%s]' % re.escape("".join(control_chars)))
28 28
29class QemuRunner: 29class QemuRunner:
30 30
31 def __init__(self, machine, rootfs, display, tmpdir, deploy_dir_image, logfile, boottime, dump_dir, dump_host_cmds, use_kvm): 31 def __init__(self, machine, rootfs, display, tmpdir, deploy_dir_image, logfile, boottime, dump_dir, dump_host_cmds, use_kvm, logger):
32 32
33 # Popen object for runqemu 33 # Popen object for runqemu
34 self.runqemu = None 34 self.runqemu = None
@@ -57,9 +57,7 @@ class QemuRunner:
57 self.qemu_pidfile = 'pidfile_'+str(os.getpid()) 57 self.qemu_pidfile = 'pidfile_'+str(os.getpid())
58 self.host_dumper = HostDumper(dump_host_cmds, dump_dir) 58 self.host_dumper = HostDumper(dump_host_cmds, dump_dir)
59 59
60 self.logger = logging.getLogger("BitBake.QemuRunner") 60 self.logger = logger
61 self.handler = logging.StreamHandler(sys.stdout)
62 self.logger.addHandler(self.handler)
63 61
64 def create_socket(self): 62 def create_socket(self):
65 try: 63 try:
@@ -371,7 +369,6 @@ class QemuRunner:
371 self.ip = None 369 self.ip = None
372 if os.path.exists(self.qemu_pidfile): 370 if os.path.exists(self.qemu_pidfile):
373 os.remove(self.qemu_pidfile) 371 os.remove(self.qemu_pidfile)
374 self.logger.removeHandler(self.handler)
375 372
376 def stop_qemu_system(self): 373 def stop_qemu_system(self):
377 if self.qemupid: 374 if self.qemupid:
diff --git a/meta/lib/oeqa/utils/qemutinyrunner.py b/meta/lib/oeqa/utils/qemutinyrunner.py
index 1bf59007ff..63b5d1648b 100644
--- a/meta/lib/oeqa/utils/qemutinyrunner.py
+++ b/meta/lib/oeqa/utils/qemutinyrunner.py
@@ -17,7 +17,7 @@ from .qemurunner import QemuRunner
17 17
18class QemuTinyRunner(QemuRunner): 18class QemuTinyRunner(QemuRunner):
19 19
20 def __init__(self, machine, rootfs, display, tmpdir, deploy_dir_image, logfile, kernel, boottime): 20 def __init__(self, machine, rootfs, display, tmpdir, deploy_dir_image, logfile, kernel, boottime, logger):
21 21
22 # Popen object for runqemu 22 # Popen object for runqemu
23 self.runqemu = None 23 self.runqemu = None
@@ -40,6 +40,7 @@ class QemuTinyRunner(QemuRunner):
40 self.socketfile = "console.sock" 40 self.socketfile = "console.sock"
41 self.server_socket = None 41 self.server_socket = None
42 self.kernel = kernel 42 self.kernel = kernel
43 self.logger = logger
43 44
44 45
45 def create_socket(self): 46 def create_socket(self):