blob: 295e8765e985cf339bb0c6841a0275881a9a3427 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002# Copyright (C) 2016 Intel Corporation
Brad Bishopc342db32019-05-15 21:57:59 -04003#
4# SPDX-License-Identifier: MIT
5#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05006
7import os
8import sys
9import signal
10import time
Andrew Geissler82c905d2020-04-13 13:39:40 -050011from collections import defaultdict
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012
13from .ssh import OESSHTarget
14from oeqa.utils.qemurunner import QemuRunner
15
Brad Bishop316dfdd2018-06-25 12:45:53 -040016supported_fstypes = ['ext3', 'ext4', 'cpio.gz', 'wic']
Brad Bishop6e60e8b2018-02-01 10:27:11 -050017
18class OEQemuTarget(OESSHTarget):
Brad Bishop977dc1a2019-02-06 16:01:43 -050019 def __init__(self, logger, server_ip, timeout=300, user='root',
Brad Bishop19323692019-04-05 15:28:33 -040020 port=None, machine='', rootfs='', kernel='', kvm=False, slirp=False,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050021 dump_dir='', dump_host_cmds='', display='', bootlog='',
Andrew Geissler82c905d2020-04-13 13:39:40 -050022 tmpdir='', dir_image='', boottime=60, serial_ports=2,
23 boot_patterns = defaultdict(str), ovmf=False, **kwargs):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050024
Brad Bishop977dc1a2019-02-06 16:01:43 -050025 super(OEQemuTarget, self).__init__(logger, None, server_ip, timeout,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050026 user, port)
27
Brad Bishop6e60e8b2018-02-01 10:27:11 -050028 self.server_ip = server_ip
Andrew Geissler82c905d2020-04-13 13:39:40 -050029 self.server_port = 0
Brad Bishop6e60e8b2018-02-01 10:27:11 -050030 self.machine = machine
31 self.rootfs = rootfs
32 self.kernel = kernel
33 self.kvm = kvm
Andrew Geissler82c905d2020-04-13 13:39:40 -050034 self.ovmf = ovmf
Brad Bishop19323692019-04-05 15:28:33 -040035 self.use_slirp = slirp
Andrew Geissler82c905d2020-04-13 13:39:40 -050036 self.boot_patterns = boot_patterns
Brad Bishop6e60e8b2018-02-01 10:27:11 -050037
38 self.runner = QemuRunner(machine=machine, rootfs=rootfs, tmpdir=tmpdir,
39 deploy_dir_image=dir_image, display=display,
40 logfile=bootlog, boottime=boottime,
Brad Bishop19323692019-04-05 15:28:33 -040041 use_kvm=kvm, use_slirp=slirp, dump_dir=dump_dir,
Andrew Geissler82c905d2020-04-13 13:39:40 -050042 dump_host_cmds=dump_host_cmds, logger=logger,
43 serial_ports=serial_ports, boot_patterns = boot_patterns,
44 use_ovmf=ovmf)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050045
Brad Bishop19323692019-04-05 15:28:33 -040046 def start(self, params=None, extra_bootparams=None, runqemuparams=''):
47 if self.use_slirp and not self.server_ip:
48 self.logger.error("Could not start qemu with slirp without server ip - provide 'TEST_SERVER_IP'")
49 raise RuntimeError("FAILED to start qemu - check the task log and the boot log")
50 if self.runner.start(params, extra_bootparams=extra_bootparams, runqemuparams=runqemuparams):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050051 self.ip = self.runner.ip
Brad Bishop19323692019-04-05 15:28:33 -040052 if self.use_slirp:
53 target_ip_port = self.runner.ip.split(':')
54 if len(target_ip_port) == 2:
55 target_ip = target_ip_port[0]
56 port = target_ip_port[1]
57 self.ip = target_ip
58 self.ssh = self.ssh + ['-p', port]
59 self.scp = self.scp + ['-P', port]
60 else:
61 self.logger.error("Could not get host machine port to connect qemu with slirp, ssh will not be "
62 "able to connect to qemu with slirp")
63 if self.runner.server_ip:
64 self.server_ip = self.runner.server_ip
Brad Bishop6e60e8b2018-02-01 10:27:11 -050065 else:
66 self.stop()
67 raise RuntimeError("FAILED to start qemu - check the task log and the boot log")
68
69 def stop(self):
70 self.runner.stop()