diff options
author | Robert Yang <liezhi.yang@windriver.com> | 2017-03-24 01:44:59 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-03-26 13:17:01 +0100 |
commit | 9305d816bdf8837ea3a407091cb7f24a9a3ae8dc (patch) | |
tree | 6f2035ab9ee5da91bacea3c05ff6c86ce6a63f2e | |
parent | accf0362f964cc9d6330b6e52e83d748d890521f (diff) | |
download | openembedded-core-9305d816bdf8837ea3a407091cb7f24a9a3ae8dc.tar.gz openembedded-core-9305d816bdf8837ea3a407091cb7f24a9a3ae8dc.tar.bz2 openembedded-core-9305d816bdf8837ea3a407091cb7f24a9a3ae8dc.zip |
oeqa/targetcontrol.py: modify it to test runqemu
Modify the following files to test runqemu:
targetcontrol.py
utils/commands.py
utils/qemurunner.py
We need simulate how "runqemu" works in command line, so when test
"runqemu", the targetcontrol.py, utils/commands.py and
utils/qemurunner.py don't have to find the rootfs or set env vars.
[YOCTO #10249]
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/lib/oeqa/targetcontrol.py | 20 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/commands.py | 13 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/qemurunner.py | 28 |
3 files changed, 43 insertions, 18 deletions
diff --git a/meta/lib/oeqa/targetcontrol.py b/meta/lib/oeqa/targetcontrol.py index 2f071e0901..ea89538002 100644 --- a/meta/lib/oeqa/targetcontrol.py +++ b/meta/lib/oeqa/targetcontrol.py @@ -117,10 +117,15 @@ class QemuTarget(BaseTarget): super(QemuTarget, self).__init__(d) - self.image_fstype = image_fstype or self.get_image_fstype(d) + self.rootfs = '' + self.kernel = '' + self.image_fstype = '' + + if d.getVar('FIND_ROOTFS') == '1': + self.image_fstype = image_fstype or self.get_image_fstype(d) + self.rootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE"), d.getVar("IMAGE_LINK_NAME") + '.' + self.image_fstype) + self.kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE"), d.getVar("KERNEL_IMAGETYPE", False) + '-' + d.getVar('MACHINE', False) + '.bin') self.qemulog = os.path.join(self.testdir, "qemu_boot_log.%s" % self.datetime) - self.rootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE"), d.getVar("IMAGE_LINK_NAME") + '.' + self.image_fstype) - self.kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE"), d.getVar("KERNEL_IMAGETYPE", False) + '-' + d.getVar('MACHINE', False) + '.bin') dump_target_cmds = d.getVar("testimage_dump_target") dump_host_cmds = d.getVar("testimage_dump_host") dump_dir = d.getVar("TESTIMAGE_DUMP_DIR") @@ -176,8 +181,13 @@ class QemuTarget(BaseTarget): bb.note("Qemu log file: %s" % self.qemulog) super(QemuTarget, self).deploy() - def start(self, params=None, ssh=True, extra_bootparams=None, runqemuparams=''): - if self.runner.start(params, get_ip=ssh, extra_bootparams=extra_bootparams, runqemuparams=runqemuparams): + def start(self, params=None, ssh=True, extra_bootparams='', runqemuparams='', launch_cmd=''): + if launch_cmd: + start = self.runner.launch(get_ip=ssh, launch_cmd=launch_cmd) + else: + start = self.runner.start(params, get_ip=ssh, extra_bootparams=extra_bootparams, runqemuparams=runqemuparams) + + if start: if ssh: self.ip = self.runner.ip self.server_ip = self.runner.server_ip diff --git a/meta/lib/oeqa/utils/commands.py b/meta/lib/oeqa/utils/commands.py index 82c5908e9c..6528a98427 100644 --- a/meta/lib/oeqa/utils/commands.py +++ b/meta/lib/oeqa/utils/commands.py @@ -218,7 +218,10 @@ def create_temp_layer(templayerdir, templayername, priority=999, recipepathspec= @contextlib.contextmanager -def runqemu(pn, ssh=True, runqemuparams='', image_fstype=None): +def runqemu(pn, ssh=True, runqemuparams='', image_fstype=None, launch_cmd=None): + """ + launch_cmd means directly run the command, don't need set rootfs or env vars. + """ import bb.tinfoil import bb.build @@ -230,6 +233,12 @@ def runqemu(pn, ssh=True, runqemuparams='', image_fstype=None): import oeqa.targetcontrol tinfoil.config_data.setVar("TEST_LOG_DIR", "${WORKDIR}/testimage") tinfoil.config_data.setVar("TEST_QEMUBOOT_TIMEOUT", "1000") + # Tell QemuTarget() whether need find rootfs/kernel or not + if launch_cmd: + tinfoil.config_data.setVar("FIND_ROOTFS", '0') + else: + tinfoil.config_data.setVar("FIND_ROOTFS", '1') + recipedata = tinfoil.parse_recipe(pn) # The QemuRunner log is saved out, but we need to ensure it is at the right @@ -260,7 +269,7 @@ def runqemu(pn, ssh=True, runqemuparams='', image_fstype=None): try: qemu.deploy() try: - qemu.start(ssh=ssh, runqemuparams=runqemuparams) + qemu.start(ssh=ssh, runqemuparams=runqemuparams, launch_cmd=launch_cmd) except bb.build.FuncFailed: raise Exception('Failed to start QEMU - see the logs in %s' % logdir) diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py index c0abb96546..c292b759bc 100644 --- a/meta/lib/oeqa/utils/qemurunner.py +++ b/meta/lib/oeqa/utils/qemurunner.py @@ -97,7 +97,7 @@ class QemuRunner: self._dump_host() raise SystemExit - def start(self, qemuparams = None, get_ip = True, extra_bootparams = None, runqemuparams=''): + def start(self, qemuparams = None, get_ip = True, extra_bootparams = None, runqemuparams='', launch_cmd=None): if self.display: os.environ["DISPLAY"] = self.display # Set this flag so that Qemu doesn't do any grabs as SDL grabs @@ -117,6 +117,20 @@ class QemuRunner: else: os.environ["DEPLOY_DIR_IMAGE"] = self.deploy_dir_image + if not launch_cmd: + launch_cmd = 'runqemu snapshot' + if self.use_kvm: + logger.info('Using kvm for runqemu') + launch_cmd += ' kvm' + else: + logger.info('Not using kvm for runqemu') + if not self.display: + launch_cmd += ' nographic' + launch_cmd += ' %s %s' % (self.machine, self.rootfs) + + return self.launch(launch_cmd, qemuparams=qemuparams, get_ip=get_ip, extra_bootparams=extra_bootparams, runqemuparams=runqemuparams) + + def launch(self, launch_cmd, get_ip = True, qemuparams = None, extra_bootparams = None, runqemuparams=''): try: threadsock, threadport = self.create_socket() self.server_socket, self.serverport = self.create_socket() @@ -124,27 +138,19 @@ class QemuRunner: logger.error("Failed to create listening socket: %s" % msg[1]) return False - bootparams = 'console=tty1 console=ttyS0,115200n8 printk.time=1' if extra_bootparams: bootparams = bootparams + ' ' + extra_bootparams self.qemuparams = 'bootparams="{0}" qemuparams="-serial tcp:127.0.0.1:{1}"'.format(bootparams, threadport) - if not self.display: - self.qemuparams = 'nographic ' + self.qemuparams if qemuparams: self.qemuparams = self.qemuparams[:-1] + " " + qemuparams + " " + '\"' + launch_cmd += ' tcpserial=%s %s' % (self.serverport, self.qemuparams) + self.origchldhandler = signal.getsignal(signal.SIGCHLD) signal.signal(signal.SIGCHLD, self.handleSIGCHLD) - launch_cmd = 'runqemu snapshot %s ' % runqemuparams - if self.use_kvm: - logger.info('Using kvm for runqemu') - launch_cmd += 'kvm ' - else: - logger.info('Not using kvm for runqemu') - launch_cmd += 'tcpserial=%s %s %s %s' % (self.serverport, self.machine, self.rootfs, self.qemuparams) logger.info('launchcmd=%s'%(launch_cmd)) # FIXME: We pass in stdin=subprocess.PIPE here to work around stty |