Esempio n. 1
0
    def __init__(self, d):

        super(QemuTarget, self).__init__(d)

        self.image_fstype = self.get_image_fstype(d)
        self.qemulog = os.path.join(self.testdir, "qemu_boot_log.%s" % self.datetime)
        self.origrootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True),  d.getVar("IMAGE_LINK_NAME", True) + '.' + self.image_fstype)
        self.rootfs = os.path.join(self.testdir, d.getVar("IMAGE_LINK_NAME", True) + '-testimage.' + self.image_fstype)
        self.kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("KERNEL_IMAGETYPE", False) + '-' + d.getVar('MACHINE', False) + '.bin')

        if d.getVar("DISTRO", True) == "poky-tiny":
            self.runner = QemuTinyRunner(machine=d.getVar("MACHINE", True),
                            rootfs=self.rootfs,
                            tmpdir = d.getVar("TMPDIR", True),
                            deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE", True),
                            display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
                            logfile = self.qemulog,
                            kernel = self.kernel,
                            boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)))
        else:
            self.runner = QemuRunner(machine=d.getVar("MACHINE", True),
                            rootfs=self.rootfs,
                            tmpdir = d.getVar("TMPDIR", True),
                            deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE", True),
                            display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
                            logfile = self.qemulog,
                            boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)))
Esempio n. 2
0
    def __init__(self, d):

        super(QemuTarget, self).__init__(d)

        self.image_fstype = self.get_image_fstype(d)
        self.qemulog = os.path.join(self.testdir, "qemu_boot_log.%s" % self.datetime)
        self.origrootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True),  d.getVar("IMAGE_LINK_NAME", True) + '.' + self.image_fstype)
        self.rootfs = os.path.join(self.testdir, d.getVar("IMAGE_LINK_NAME", True) + '-testimage.' + self.image_fstype)
        self.kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("KERNEL_IMAGETYPE") + '-' + d.getVar('MACHINE') + '.bin')

        if d.getVar("DISTRO", True) == "poky-tiny":
            self.runner = QemuTinyRunner(machine=d.getVar("MACHINE", True),
                            rootfs=self.rootfs,
                            tmpdir = d.getVar("TMPDIR", True),
                            deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE", True),
                            display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
                            logfile = self.qemulog,
                            kernel = self.kernel,
                            boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)))
        else:
            self.runner = QemuRunner(machine=d.getVar("MACHINE", True),
                            rootfs=self.rootfs,
                            tmpdir = d.getVar("TMPDIR", True),
                            deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE", True),
                            display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
                            logfile = self.qemulog,
                            boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)))
Esempio n. 3
0
class OEQemuTarget(OESSHTarget):
    def __init__(self, logger, ip, server_ip, timeout=300, user='******',
            port=None, machine='', rootfs='', kernel='', kvm=False,
            dump_dir='', dump_host_cmds='', display='', bootlog='',
            tmpdir='', dir_image='', boottime=60):

        super(OEQemuTarget, self).__init__(logger, ip, server_ip, timeout,
                user, port)

        self.ip = ip
        self.server_ip = server_ip
        self.machine = machine
        self.rootfs = rootfs
        self.kernel = kernel
        self.kvm = kvm

        self.runner = QemuRunner(machine=machine, rootfs=rootfs, tmpdir=tmpdir,
                                 deploy_dir_image=dir_image, display=display,
                                 logfile=bootlog, boottime=boottime,
                                 use_kvm=kvm, dump_dir=dump_dir,
                                 dump_host_cmds=dump_host_cmds)

    def start(self, params=None, extra_bootparams=None):
        if self.runner.start(params, extra_bootparams=extra_bootparams):
            self.ip = self.runner.ip
            self.server_ip = self.runner.server_ip
        else:
            self.stop()
            raise RuntimeError("FAILED to start qemu - check the task log and the boot log")

    def stop(self):
        self.runner.stop()
    def __init__(self, d):

        super(QemuTarget, self).__init__(d)

        self.image_fstype = self.get_image_fstype(d)
        self.qemulog = os.path.join(self.testdir,
                                    "qemu_boot_log.%s" % self.datetime)
        self.origrootfs = os.path.join(
            d.getVar("DEPLOY_DIR_IMAGE", True),
            d.getVar("IMAGE_LINK_NAME", True) + '.' + self.image_fstype)
        self.rootfs = os.path.join(
            self.testdir,
            d.getVar("IMAGE_LINK_NAME", True) + '-testimage.' +
            self.image_fstype)
        self.kernel = os.path.join(
            d.getVar("DEPLOY_DIR_IMAGE", True),
            d.getVar("KERNEL_IMAGETYPE", False) + '-' +
            d.getVar('MACHINE', False) + '.bin')
        dump_target_cmds = d.getVar("testimage_dump_target", True)
        dump_host_cmds = d.getVar("testimage_dump_host", True)
        dump_dir = d.getVar("TESTIMAGE_DUMP_DIR", True)

        # Log QemuRunner log output to a file
        import oe.path
        bb.utils.mkdirhier(self.testdir)
        self.qemurunnerlog = os.path.join(self.testdir,
                                          'qemurunner_log.%s' % self.datetime)
        logger = logging.getLogger('BitBake.QemuRunner')
        loggerhandler = logging.FileHandler(self.qemurunnerlog)
        loggerhandler.setFormatter(
            logging.Formatter("%(levelname)s: %(message)s"))
        logger.addHandler(loggerhandler)
        oe.path.symlink(os.path.basename(self.qemurunnerlog),
                        os.path.join(self.testdir, 'qemurunner_log'),
                        force=True)

        if d.getVar("DISTRO", True) == "poky-tiny":
            self.runner = QemuTinyRunner(
                machine=d.getVar("MACHINE", True),
                rootfs=self.rootfs,
                tmpdir=d.getVar("TMPDIR", True),
                deploy_dir_image=d.getVar("DEPLOY_DIR_IMAGE", True),
                display=d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
                logfile=self.qemulog,
                kernel=self.kernel,
                boottime=int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)))
        else:
            self.runner = QemuRunner(
                machine=d.getVar("MACHINE", True),
                rootfs=self.rootfs,
                tmpdir=d.getVar("TMPDIR", True),
                deploy_dir_image=d.getVar("DEPLOY_DIR_IMAGE", True),
                display=d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
                logfile=self.qemulog,
                boottime=int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)),
                dump_dir=dump_dir,
                dump_host_cmds=d.getVar("testimage_dump_host", True))

        self.target_dumper = TargetDumper(dump_target_cmds, dump_dir,
                                          self.runner)
Esempio n. 5
0
    def __init__(self, logger, server_ip, timeout=300, user='******',
            port=None, machine='', rootfs='', kernel='', kvm=False, slirp=False,
            dump_dir='', dump_host_cmds='', display='', bootlog='',
            tmpdir='', dir_image='', boottime=60, serial_ports=2,
            boot_patterns = defaultdict(str), ovmf=False, tmpfsdir=None, **kwargs):

        super(OEQemuTarget, self).__init__(logger, None, server_ip, timeout,
                user, port)

        self.server_ip = server_ip
        self.server_port = 0
        self.machine = machine
        self.rootfs = rootfs
        self.kernel = kernel
        self.kvm = kvm
        self.ovmf = ovmf
        self.use_slirp = slirp
        self.boot_patterns = boot_patterns

        self.runner = QemuRunner(machine=machine, rootfs=rootfs, tmpdir=tmpdir,
                                 deploy_dir_image=dir_image, display=display,
                                 logfile=bootlog, boottime=boottime,
                                 use_kvm=kvm, use_slirp=slirp, dump_dir=dump_dir,
                                 dump_host_cmds=dump_host_cmds, logger=logger,
                                 serial_ports=serial_ports, boot_patterns = boot_patterns, 
                                 use_ovmf=ovmf, tmpfsdir=tmpfsdir)
        dump_target_cmds = kwargs.get("testimage_dump_target")
        self.target_dumper = TargetDumper(dump_target_cmds, dump_dir, self.runner)
        self.target_dumper.create_dir("qemu")
Esempio n. 6
0
    def __init__(self, d, logger, image_fstype=None):

        import oe.types

        super(QemuTarget, self).__init__(d, logger)

        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)
        dump_target_cmds = d.getVar("testimage_dump_target")
        dump_host_cmds = d.getVar("testimage_dump_host")
        dump_dir = d.getVar("TESTIMAGE_DUMP_DIR")
        qemu_use_kvm = d.getVar("QEMU_USE_KVM")
        if qemu_use_kvm and \
           (oe.types.boolean(qemu_use_kvm) and "x86" in d.getVar("MACHINE") or \
            d.getVar("MACHINE") in qemu_use_kvm.split()):
            use_kvm = True
        else:
            use_kvm = False

        # Log QemuRunner log output to a file
        import oe.path
        bb.utils.mkdirhier(self.testdir)
        self.qemurunnerlog = os.path.join(self.testdir, 'qemurunner_log.%s' % self.datetime)
        loggerhandler = logging.FileHandler(self.qemurunnerlog)
        loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
        self.logger.addHandler(loggerhandler)
        oe.path.symlink(os.path.basename(self.qemurunnerlog), os.path.join(self.testdir, 'qemurunner_log'), force=True)

        if d.getVar("DISTRO") == "poky-tiny":
            self.runner = QemuTinyRunner(machine=d.getVar("MACHINE"),
                            rootfs=self.rootfs,
                            tmpdir = d.getVar("TMPDIR"),
                            deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE"),
                            display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY"),
                            logfile = self.qemulog,
                            kernel = self.kernel,
                            boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")),
                            logger = logger)
        else:
            self.runner = QemuRunner(machine=d.getVar("MACHINE"),
                            rootfs=self.rootfs,
                            tmpdir = d.getVar("TMPDIR"),
                            deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE"),
                            display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY"),
                            logfile = self.qemulog,
                            boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")),
                            use_kvm = use_kvm,
                            dump_dir = dump_dir,
                            dump_host_cmds = d.getVar("testimage_dump_host"),
                            logger = logger)

        self.target_dumper = TargetDumper(dump_target_cmds, dump_dir, self.runner)
    def __init__(self, d, logger, image_fstype=None):

        import oe.types

        super(QemuTarget, self).__init__(d, logger)

        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)
        dump_target_cmds = d.getVar("testimage_dump_target")
        dump_host_cmds = d.getVar("testimage_dump_host")
        dump_dir = d.getVar("TESTIMAGE_DUMP_DIR")
        if not dump_dir:
            dump_dir = os.path.join(d.getVar('LOG_DIR'), 'runtime-hostdump')
        use_kvm = oe.types.qemu_use_kvm(d.getVar('QEMU_USE_KVM'), d.getVar('TARGET_ARCH'))

        # Log QemuRunner log output to a file
        import oe.path
        bb.utils.mkdirhier(self.testdir)
        self.qemurunnerlog = os.path.join(self.testdir, 'qemurunner_log.%s' % self.datetime)
        self.loggerhandler = logging.FileHandler(self.qemurunnerlog)
        self.loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
        self.logger.addHandler(self.loggerhandler)
        oe.path.symlink(os.path.basename(self.qemurunnerlog), os.path.join(self.testdir, 'qemurunner_log'), force=True)

        if d.getVar("DISTRO") == "poky-tiny":
            self.runner = QemuTinyRunner(machine=d.getVar("MACHINE"),
                            rootfs=self.rootfs,
                            tmpdir = d.getVar("TMPDIR"),
                            deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE"),
                            display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY"),
                            logfile = self.qemulog,
                            kernel = self.kernel,
                            boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")),
                            tmpfsdir = d.getVar("RUNQEMU_TMPFS_DIR"),
                            logger = logger)
        else:
            self.runner = QemuRunner(machine=d.getVar("MACHINE"),
                            rootfs=self.rootfs,
                            tmpdir = d.getVar("TMPDIR"),
                            deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE"),
                            display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY"),
                            logfile = self.qemulog,
                            boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")),
                            use_kvm = use_kvm,
                            dump_dir = dump_dir,
                            dump_host_cmds = d.getVar("testimage_dump_host"),
                            logger = logger,
                            tmpfsdir = d.getVar("RUNQEMU_TMPFS_DIR"),
                            serial_ports = len(d.getVar("SERIAL_CONSOLES").split()))

        self.target_dumper = TargetDumper(dump_target_cmds, dump_dir, self.runner)
Esempio n. 8
0
class QemuTarget(BaseTarget):

    supported_image_fstypes = ['ext3']

    def __init__(self, d):

        super(QemuTarget, self).__init__(d)

        self.image_fstype = self.get_image_fstype(d)
        self.qemulog = os.path.join(self.testdir, "qemu_boot_log.%s" % self.datetime)
        self.origrootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True),  d.getVar("IMAGE_LINK_NAME", True) + '.' + self.image_fstype)
        self.rootfs = os.path.join(self.testdir, d.getVar("IMAGE_LINK_NAME", True) + '-testimage.' + self.image_fstype)

        self.runner = QemuRunner(machine=d.getVar("MACHINE", True),
                        rootfs=self.rootfs,
                        tmpdir = d.getVar("TMPDIR", True),
                        deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE", True),
                        display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
                        logfile = self.qemulog,
                        boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)))

    def deploy(self):
        try:
            shutil.copyfile(self.origrootfs, self.rootfs)
        except Exception as e:
            bb.fatal("Error copying rootfs: %s" % e)

        qemuloglink = os.path.join(self.testdir, "qemu_boot_log")
        if os.path.islink(qemuloglink):
            os.unlink(qemuloglink)
        os.symlink(self.qemulog, qemuloglink)

        bb.note("rootfs file: %s" %  self.rootfs)
        bb.note("Qemu log file: %s" % self.qemulog)
        super(QemuTarget, self).deploy()

    def start(self, params=None):
        if self.runner.start(params):
            self.ip = self.runner.ip
            self.server_ip = self.runner.server_ip
            self.connection = SSHControl(ip=self.ip, logfile=self.sshlog)
        else:
            self.stop()
            raise bb.build.FuncFailed("%s - FAILED to start qemu - check the task log and the boot log" % self.pn)

    def stop(self):
        self.runner.stop()
        self.connection = None
        self.ip = None
        self.server_ip = None

    def restart(self, params=None):
        if self.runner.restart(params):
            self.ip = self.runner.ip
            self.server_ip = self.runner.server_ip
            self.connection = SSHControl(ip=self.ip, logfile=self.sshlog)
        else:
            raise bb.build.FuncFailed("%s - FAILED to re-start qemu - check the task log and the boot log" % self.pn)
Esempio n. 9
0
class OEQemuTarget(OESSHTarget):
    def __init__(self, logger, server_ip, timeout=300, user='******',
            port=None, machine='', rootfs='', kernel='', kvm=False, slirp=False,
            dump_dir='', dump_host_cmds='', display='', bootlog='',
            tmpdir='', dir_image='', boottime=60, serial_ports=2,
            boot_patterns = defaultdict(str), ovmf=False, tmpfsdir=None, **kwargs):

        super(OEQemuTarget, self).__init__(logger, None, server_ip, timeout,
                user, port)

        self.server_ip = server_ip
        self.server_port = 0
        self.machine = machine
        self.rootfs = rootfs
        self.kernel = kernel
        self.kvm = kvm
        self.ovmf = ovmf
        self.use_slirp = slirp
        self.boot_patterns = boot_patterns

        self.runner = QemuRunner(machine=machine, rootfs=rootfs, tmpdir=tmpdir,
                                 deploy_dir_image=dir_image, display=display,
                                 logfile=bootlog, boottime=boottime,
                                 use_kvm=kvm, use_slirp=slirp, dump_dir=dump_dir,
                                 dump_host_cmds=dump_host_cmds, logger=logger,
                                 serial_ports=serial_ports, boot_patterns = boot_patterns, 
                                 use_ovmf=ovmf, tmpfsdir=tmpfsdir)
        dump_target_cmds = kwargs.get("testimage_dump_target")
        self.target_dumper = TargetDumper(dump_target_cmds, dump_dir, self.runner)
        self.target_dumper.create_dir("qemu")

    def start(self, params=None, extra_bootparams=None, runqemuparams=''):
        if self.use_slirp and not self.server_ip:
            self.logger.error("Could not start qemu with slirp without server ip - provide 'TEST_SERVER_IP'")
            raise RuntimeError("FAILED to start qemu - check the task log and the boot log")
        if self.runner.start(params, extra_bootparams=extra_bootparams, runqemuparams=runqemuparams):
            self.ip = self.runner.ip
            if self.use_slirp:
                target_ip_port = self.runner.ip.split(':')
                if len(target_ip_port) == 2:
                    target_ip = target_ip_port[0]
                    port = target_ip_port[1]
                    self.ip = target_ip
                    self.ssh = self.ssh + ['-p', port]
                    self.scp = self.scp + ['-P', port]
                else:
                    self.logger.error("Could not get host machine port to connect qemu with slirp, ssh will not be "
                                      "able to connect to qemu with slirp")
            if self.runner.server_ip:
                self.server_ip = self.runner.server_ip
        else:
            self.stop()
            raise RuntimeError("FAILED to start qemu - check the task log and the boot log")

    def stop(self):
        self.runner.stop()
Esempio n. 10
0
    def __init__(self,
                 td,
                 logger,
                 timeout=300,
                 user='******',
                 port=None,
                 machine='',
                 rootfs='',
                 kernel='',
                 kvm=False,
                 dump_dir='',
                 dump_host_cmds='',
                 display='',
                 bootlog='',
                 tmpdir='',
                 dir_image='',
                 boottime=60,
                 **kwargs):

        super(OEQemuTarget, self).__init__(td, logger, timeout, user, port)

        self.ip = td['TEST_TARGET_IP']
        self.server_ip = td['TEST_SERVER_IP']
        self.machine = machine

        image_name = ("%s/%s" %
                      (td['DEPLOY_DIR_IMAGE'], td['IMAGE_LINK_NAME']))

        # Get rootfs
        if not rootfs:
            fstypes = [
                fs for fs in td['IMAGE_FSTYPES'].split(' ')
                if fs in self.supported_fstypes
            ]
            if not fstypes:
                bb.fatal(
                    'Unsupported image type built. Add a comptible image to '
                    'IMAGE_FSTYPES. Supported types: %s' %
                    ', '.join(self.supported_fstypes))
            rootfs = '%s.%s' % (image_name, fstypes[0])
        self.rootfs = rootfs

        self.kernel = kernel
        self.kvm = kvm

        self.runner = QemuRunner(machine=machine,
                                 rootfs=rootfs,
                                 tmpdir=tmpdir,
                                 deploy_dir_image=dir_image,
                                 display=display,
                                 logfile=bootlog,
                                 boottime=boottime,
                                 use_kvm=kvm,
                                 dump_dir=dump_dir,
                                 dump_host_cmds=dump_host_cmds,
                                 logger=logger)
Esempio n. 11
0
    def __init__(self, d):

        super(QemuTarget, self).__init__(d)

        self.image_fstype = self.get_image_fstype(d)
        self.qemulog = os.path.join(self.testdir, "qemu_boot_log.%s" % self.datetime)
        self.origrootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True),  d.getVar("IMAGE_LINK_NAME", True) + '.' + self.image_fstype)
        self.rootfs = os.path.join(self.testdir, d.getVar("IMAGE_LINK_NAME", True) + '-testimage.' + self.image_fstype)
        self.kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("KERNEL_IMAGETYPE", False) + '-' + d.getVar('MACHINE', False) + '.bin')
        dump_target_cmds = d.getVar("testimage_dump_target", True)
        dump_host_cmds = d.getVar("testimage_dump_host", True)
        dump_dir = d.getVar("TESTIMAGE_DUMP_DIR", True)
        if d.getVar("QEMU_USE_KVM", False) is not None \
           and d.getVar("QEMU_USE_KVM", False) == "True" \
           and "x86" in d.getVar("MACHINE", True):
            use_kvm = True
        else:
            use_kvm = False

        # Log QemuRunner log output to a file
        import oe.path
        bb.utils.mkdirhier(self.testdir)
        self.qemurunnerlog = os.path.join(self.testdir, 'qemurunner_log.%s' % self.datetime)
        logger = logging.getLogger('BitBake.QemuRunner')
        loggerhandler = logging.FileHandler(self.qemurunnerlog)
        loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
        logger.addHandler(loggerhandler)
        oe.path.symlink(os.path.basename(self.qemurunnerlog), os.path.join(self.testdir, 'qemurunner_log'), force=True)

        if d.getVar("DISTRO", True) == "poky-tiny":
            self.runner = QemuTinyRunner(machine=d.getVar("MACHINE", True),
                            rootfs=self.rootfs,
                            tmpdir = d.getVar("TMPDIR", True),
                            deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE", True),
                            display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
                            logfile = self.qemulog,
                            kernel = self.kernel,
                            boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)))
        else:
            self.runner = QemuRunner(machine=d.getVar("MACHINE", True),
                            rootfs=self.rootfs,
                            tmpdir = d.getVar("TMPDIR", True),
                            deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE", True),
                            display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
                            logfile = self.qemulog,
                            boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)),
                            use_kvm = use_kvm,
                            dump_dir = dump_dir,
                            dump_host_cmds = d.getVar("testimage_dump_host", True))

        self.target_dumper = TargetDumper(dump_target_cmds, dump_dir, self.runner)
Esempio n. 12
0
class OEQemuTarget(OESSHTarget):
    def __init__(self, logger, server_ip, timeout=300, user='******',
            port=None, machine='', rootfs='', kernel='', kvm=False, slirp=False,
            dump_dir='', dump_host_cmds='', display='', bootlog='',
            tmpdir='', dir_image='', boottime=60, **kwargs):

        super(OEQemuTarget, self).__init__(logger, None, server_ip, timeout,
                user, port)

        self.server_ip = server_ip
        self.machine = machine
        self.rootfs = rootfs
        self.kernel = kernel
        self.kvm = kvm
        self.use_slirp = slirp

        self.runner = QemuRunner(machine=machine, rootfs=rootfs, tmpdir=tmpdir,
                                 deploy_dir_image=dir_image, display=display,
                                 logfile=bootlog, boottime=boottime,
                                 use_kvm=kvm, use_slirp=slirp, dump_dir=dump_dir,
                                 dump_host_cmds=dump_host_cmds, logger=logger)

    def start(self, params=None, extra_bootparams=None, runqemuparams=''):
        if self.use_slirp and not self.server_ip:
            self.logger.error("Could not start qemu with slirp without server ip - provide 'TEST_SERVER_IP'")
            raise RuntimeError("FAILED to start qemu - check the task log and the boot log")
        if self.runner.start(params, extra_bootparams=extra_bootparams, runqemuparams=runqemuparams):
            self.ip = self.runner.ip
            if self.use_slirp:
                target_ip_port = self.runner.ip.split(':')
                if len(target_ip_port) == 2:
                    target_ip = target_ip_port[0]
                    port = target_ip_port[1]
                    self.ip = target_ip
                    self.ssh = self.ssh + ['-p', port]
                    self.scp = self.scp + ['-P', port]
                else:
                    self.logger.error("Could not get host machine port to connect qemu with slirp, ssh will not be "
                                      "able to connect to qemu with slirp")
            if self.runner.server_ip:
                self.server_ip = self.runner.server_ip
        else:
            self.stop()
            raise RuntimeError("FAILED to start qemu - check the task log and the boot log")

    def stop(self):
        self.runner.stop()
Esempio n. 13
0
    def __init__(self,
                 logger,
                 server_ip,
                 timeout=300,
                 user='******',
                 port=None,
                 machine='',
                 rootfs='',
                 kernel='',
                 kvm=False,
                 slirp=False,
                 dump_dir='',
                 dump_host_cmds='',
                 display='',
                 bootlog='',
                 tmpdir='',
                 dir_image='',
                 boottime=60,
                 **kwargs):

        super(OEQemuTarget, self).__init__(logger, None, server_ip, timeout,
                                           user, port)

        self.server_ip = server_ip
        self.machine = machine
        self.rootfs = rootfs
        self.kernel = kernel
        self.kvm = kvm
        self.use_slirp = slirp

        self.runner = QemuRunner(machine=machine,
                                 rootfs=rootfs,
                                 tmpdir=tmpdir,
                                 deploy_dir_image=dir_image,
                                 display=display,
                                 logfile=bootlog,
                                 boottime=boottime,
                                 use_kvm=kvm,
                                 use_slirp=slirp,
                                 dump_dir=dump_dir,
                                 dump_host_cmds=dump_host_cmds,
                                 logger=logger)
Esempio n. 14
0
    def __init__(self, machine, rootfs, display, tmpdir, deploy_dir_image, logfile, boottime, dump_dir, dump_host_cmds, use_kvm):
        QemuRunner.__init__(self, machine, rootfs, display, tmpdir,
                            deploy_dir_image, logfile, boottime, None,
                            None, use_kvm)

        # Popen object for runqemu
        self.socketfile = tempfile.NamedTemporaryFile()
        self.runqemu = None
        self.socketname = self.socketfile.name
        self.server_socket = None

        self.kernel = rootfs
        self.deploy_dir_image = deploy_dir_image
        self.logfile = logfile
        self.use_kvm = use_kvm

        self.buffers = b''
        self._rbufsize = 4096
        # 5 minutes timeout...
        self.endtime = time.time() + 60*5
Esempio n. 15
0
    def __init__(self, d):

        super(QemuTarget, self).__init__(d)

        self.qemulog = os.path.join(self.testdir,
                                    "qemu_boot_log.%s" % self.datetime)
        self.origrootfs = os.path.join(
            d.getVar("DEPLOY_DIR_IMAGE", True),
            d.getVar("IMAGE_LINK_NAME", True) + '.ext3')
        self.rootfs = os.path.join(
            self.testdir,
            d.getVar("IMAGE_LINK_NAME", True) + '-testimage.ext3')

        self.runner = QemuRunner(
            machine=d.getVar("MACHINE", True),
            rootfs=self.rootfs,
            tmpdir=d.getVar("TMPDIR", True),
            deploy_dir_image=d.getVar("DEPLOY_DIR_IMAGE", True),
            display=d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
            logfile=self.qemulog,
            boottime=int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)))
Esempio n. 16
0
    def __init__(self, d):

        super(QemuTarget, self).__init__(d)

        self.qemulog = os.path.join(self.testdir, "qemu_boot_log.%s" % self.datetime)
        self.origrootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True),  d.getVar("IMAGE_LINK_NAME", True) + '.ext3')
        self.rootfs = os.path.join(self.testdir, d.getVar("IMAGE_LINK_NAME", True) + '-testimage.ext3')

        self.runner = QemuRunner(machine=d.getVar("MACHINE", True),
                        rootfs=self.rootfs,
                        tmpdir = d.getVar("TMPDIR", True),
                        deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE", True),
                        display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
                        logfile = self.qemulog,
                        boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)))
Esempio n. 17
0
File: qemu.py Progetto: kacf/poky
    def __init__(self, logger, ip, server_ip, timeout=300, user='******',
            port=None, machine='', rootfs='', kernel='', kvm=False,
            dump_dir='', dump_host_cmds='', display='', bootlog='',
            tmpdir='', dir_image='', boottime=60):

        super(OEQemuTarget, self).__init__(logger, ip, server_ip, timeout,
                user, port)

        self.ip = ip
        self.server_ip = server_ip
        self.machine = machine
        self.rootfs = rootfs
        self.kernel = kernel
        self.kvm = kvm

        self.runner = QemuRunner(machine=machine, rootfs=rootfs, tmpdir=tmpdir,
                                 deploy_dir_image=dir_image, display=display,
                                 logfile=bootlog, boottime=boottime,
                                 use_kvm=kvm, dump_dir=dump_dir,
                                 dump_host_cmds=dump_host_cmds)
Esempio n. 18
0
class QemuTarget(BaseTarget):

    supported_image_fstypes = ['ext3', 'ext4', 'cpio.gz', 'wic']

    def __init__(self, td, logger, image_fstype=None, **kwargs):

        import oe.types

        super(QemuTarget, self).__init__(td, logger, **kwargs)

        self.rootfs = ''
        self.kernel = ''
        self.image_fstype = ''

        if td['FIND_ROOTFS'] == '1':
            self.image_fstype = image_fstype or self.get_image_fstype(td)
            self.rootfs = os.path.join(
                td['DEPLOY_DIR_IMAGE'],
                td['IMAGE_LINK_NAME'] + '.' + self.image_fstype)
            self.kernel = os.path.join(
                td['DEPLOY_DIR_IMAGE'],
                td["KERNEL_IMAGETYPE"] + '-' + td['MACHINE'] + '.bin')
        self.qemulog = os.path.join(self.testdir,
                                    "qemu_boot_log.%s" % self.datetime)
        dump_target_cmds = td['testimage_dump_target']
        dump_host_cmds = td['testimage_dump_host']
        dump_dir = td['TESTIMAGE_DUMP_DIR']
        qemu_use_kvm = td['QEMU_USE_KVM']
        if qemu_use_kvm and \
           (oe.types.boolean(qemu_use_kvm) and "x86" in td['MACHINE'] or \
            td['MACHINE'] in qemu_use_kvm.split()):
            use_kvm = True
        else:
            use_kvm = False

        # Log QemuRunner log output to a file
        import oe.path
        bb.utils.mkdirhier(self.testdir)
        self.qemurunnerlog = os.path.join(self.testdir,
                                          'qemurunner_log.%s' % self.datetime)
        loggerhandler = logging.FileHandler(self.qemurunnerlog)
        loggerhandler.setFormatter(
            logging.Formatter("%(levelname)s: %(message)s"))
        self.logger.addHandler(loggerhandler)
        oe.path.symlink(os.path.basename(self.qemurunnerlog),
                        os.path.join(self.testdir, 'qemurunner_log'),
                        force=True)

        if td['DISTRO'] == "poky-tiny":
            self.runner = QemuTinyRunner(
                machine=td['MACHINE'],
                rootfs=self.rootfs,
                tmpdir=td['TMPDIR'],
                deploy_dir_image=td['DEPLOY_DIR_IMAGE'],
                display=td['DISPLAY'],
                logfile=self.qemulog,
                kernel=self.kernel,
                boottime=int(td['TEST_QEMUBOOT_TIMEOUT']),
                logger=logger)
        else:
            self.runner = QemuRunner(machine=td['MACHINE'],
                                     rootfs=self.rootfs,
                                     tmpdir=td['TMPDIR'],
                                     deploy_dir_image=td['DEPLOY_DIR_IMAGE'],
                                     display=td['DISPLAY'],
                                     logfile=self.qemulog,
                                     boottime=int(td['TEST_QEMUBOOT_TIMEOUT']),
                                     use_kvm=use_kvm,
                                     dump_dir=dump_dir,
                                     dump_host_cmds=td['testimage_dump_host'],
                                     logger=logger)

        self.target_dumper = TargetDumper(dump_target_cmds, dump_dir,
                                          self.runner)

    def deploy(self):
        bb.utils.mkdirhier(self.testdir)

        qemuloglink = os.path.join(self.testdir, "qemu_boot_log")
        if os.path.islink(qemuloglink):
            os.unlink(qemuloglink)
        os.symlink(self.qemulog, qemuloglink)

        self.logger.info("rootfs file: %s" % self.rootfs)
        self.logger.info("Qemu log file: %s" % self.qemulog)
        super(QemuTarget, self).deploy()

    def start(self,
              params=None,
              ssh=True,
              extra_bootparams='',
              runqemuparams='',
              launch_cmd='',
              discard_writes=True):
        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,
                                      discard_writes=discard_writes)

        if start:
            if ssh:
                self.ip = self.runner.ip
                self.server_ip = self.runner.server_ip
                self.connection = SSHControl(ip=self.ip, logfile=self.sshlog)
        else:
            self.stop()
            if os.path.exists(self.qemulog):
                with open(self.qemulog, 'r') as f:
                    bb.error("Qemu log output from %s:\n%s" %
                             (self.qemulog, f.read()))
            raise bb.build.FuncFailed(
                "%s - FAILED to start qemu - check the task log and the boot log"
                % self.pn)

    def check(self):
        return self.runner.is_alive()

    def stop(self):
        self.runner.stop()
        self.connection = None
        self.ip = None
        self.server_ip = None

    def restart(self, params=None):
        if self.runner.restart(params):
            self.ip = self.runner.ip
            self.server_ip = self.runner.server_ip
            self.connection = SSHControl(ip=self.ip, logfile=self.sshlog)
        else:
            raise bb.build.FuncFailed(
                "%s - FAILED to re-start qemu - check the task log and the boot log"
                % self.pn)

    def run_serial(self, command, timeout=5):
        return self.runner.run_serial(command, timeout=timeout)
Esempio n. 19
0
    def __init__(self, td, logger, image_fstype=None, **kwargs):

        import oe.types

        super(QemuTarget, self).__init__(td, logger, **kwargs)

        self.rootfs = ''
        self.kernel = ''
        self.image_fstype = ''

        if td['FIND_ROOTFS'] == '1':
            self.image_fstype = image_fstype or self.get_image_fstype(td)
            self.rootfs = os.path.join(
                td['DEPLOY_DIR_IMAGE'],
                td['IMAGE_LINK_NAME'] + '.' + self.image_fstype)
            self.kernel = os.path.join(
                td['DEPLOY_DIR_IMAGE'],
                td["KERNEL_IMAGETYPE"] + '-' + td['MACHINE'] + '.bin')
        self.qemulog = os.path.join(self.testdir,
                                    "qemu_boot_log.%s" % self.datetime)
        dump_target_cmds = td['testimage_dump_target']
        dump_host_cmds = td['testimage_dump_host']
        dump_dir = td['TESTIMAGE_DUMP_DIR']
        qemu_use_kvm = td['QEMU_USE_KVM']
        if qemu_use_kvm and \
           (oe.types.boolean(qemu_use_kvm) and "x86" in td['MACHINE'] or \
            td['MACHINE'] in qemu_use_kvm.split()):
            use_kvm = True
        else:
            use_kvm = False

        # Log QemuRunner log output to a file
        import oe.path
        bb.utils.mkdirhier(self.testdir)
        self.qemurunnerlog = os.path.join(self.testdir,
                                          'qemurunner_log.%s' % self.datetime)
        loggerhandler = logging.FileHandler(self.qemurunnerlog)
        loggerhandler.setFormatter(
            logging.Formatter("%(levelname)s: %(message)s"))
        self.logger.addHandler(loggerhandler)
        oe.path.symlink(os.path.basename(self.qemurunnerlog),
                        os.path.join(self.testdir, 'qemurunner_log'),
                        force=True)

        if td['DISTRO'] == "poky-tiny":
            self.runner = QemuTinyRunner(
                machine=td['MACHINE'],
                rootfs=self.rootfs,
                tmpdir=td['TMPDIR'],
                deploy_dir_image=td['DEPLOY_DIR_IMAGE'],
                display=td['DISPLAY'],
                logfile=self.qemulog,
                kernel=self.kernel,
                boottime=int(td['TEST_QEMUBOOT_TIMEOUT']),
                logger=logger)
        else:
            self.runner = QemuRunner(machine=td['MACHINE'],
                                     rootfs=self.rootfs,
                                     tmpdir=td['TMPDIR'],
                                     deploy_dir_image=td['DEPLOY_DIR_IMAGE'],
                                     display=td['DISPLAY'],
                                     logfile=self.qemulog,
                                     boottime=int(td['TEST_QEMUBOOT_TIMEOUT']),
                                     use_kvm=use_kvm,
                                     dump_dir=dump_dir,
                                     dump_host_cmds=td['testimage_dump_host'],
                                     logger=logger)

        self.target_dumper = TargetDumper(dump_target_cmds, dump_dir,
                                          self.runner)
Esempio n. 20
0
class QemuTarget(BaseTarget):

    supported_image_fstypes = ['ext3', 'ext4', 'cpio.gz', 'wic']

    def __init__(self, d, logger, image_fstype=None):

        import oe.types

        super(QemuTarget, self).__init__(d, logger)

        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)
        dump_target_cmds = d.getVar("testimage_dump_target")
        dump_host_cmds = d.getVar("testimage_dump_host")
        dump_dir = d.getVar("TESTIMAGE_DUMP_DIR")
        qemu_use_kvm = d.getVar("QEMU_USE_KVM")
        if qemu_use_kvm and \
           (oe.types.boolean(qemu_use_kvm) and "x86" in d.getVar("MACHINE") or \
            d.getVar("MACHINE") in qemu_use_kvm.split()):
            use_kvm = True
        else:
            use_kvm = False

        # Log QemuRunner log output to a file
        import oe.path
        bb.utils.mkdirhier(self.testdir)
        self.qemurunnerlog = os.path.join(self.testdir, 'qemurunner_log.%s' % self.datetime)
        loggerhandler = logging.FileHandler(self.qemurunnerlog)
        loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
        self.logger.addHandler(loggerhandler)
        oe.path.symlink(os.path.basename(self.qemurunnerlog), os.path.join(self.testdir, 'qemurunner_log'), force=True)

        if d.getVar("DISTRO") == "poky-tiny":
            self.runner = QemuTinyRunner(machine=d.getVar("MACHINE"),
                            rootfs=self.rootfs,
                            tmpdir = d.getVar("TMPDIR"),
                            deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE"),
                            display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY"),
                            logfile = self.qemulog,
                            kernel = self.kernel,
                            boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")),
                            logger = logger)
        else:
            self.runner = QemuRunner(machine=d.getVar("MACHINE"),
                            rootfs=self.rootfs,
                            tmpdir = d.getVar("TMPDIR"),
                            deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE"),
                            display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY"),
                            logfile = self.qemulog,
                            boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")),
                            use_kvm = use_kvm,
                            dump_dir = dump_dir,
                            dump_host_cmds = d.getVar("testimage_dump_host"),
                            logger = logger)

        self.target_dumper = TargetDumper(dump_target_cmds, dump_dir, self.runner)

    def deploy(self):
        bb.utils.mkdirhier(self.testdir)

        qemuloglink = os.path.join(self.testdir, "qemu_boot_log")
        if os.path.islink(qemuloglink):
            os.unlink(qemuloglink)
        os.symlink(self.qemulog, qemuloglink)

        self.logger.info("rootfs file: %s" %  self.rootfs)
        self.logger.info("Qemu log file: %s" % self.qemulog)
        super(QemuTarget, self).deploy()

    def start(self, params=None, ssh=True, extra_bootparams='', runqemuparams='', launch_cmd='', discard_writes=True):
        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, discard_writes=discard_writes)

        if start:
            if ssh:
                self.ip = self.runner.ip
                self.server_ip = self.runner.server_ip
                self.connection = SSHControl(ip=self.ip, logfile=self.sshlog)
        else:
            self.stop()
            if os.path.exists(self.qemulog):
                with open(self.qemulog, 'r') as f:
                    bb.error("Qemu log output from %s:\n%s" % (self.qemulog, f.read()))
            raise bb.build.FuncFailed("%s - FAILED to start qemu - check the task log and the boot log" % self.pn)

    def check(self):
        return self.runner.is_alive()

    def stop(self):
        self.runner.stop()
        self.connection = None
        self.ip = None
        self.server_ip = None

    def restart(self, params=None):
        if self.runner.restart(params):
            self.ip = self.runner.ip
            self.server_ip = self.runner.server_ip
            self.connection = SSHControl(ip=self.ip, logfile=self.sshlog)
        else:
            raise bb.build.FuncFailed("%s - FAILED to re-start qemu - check the task log and the boot log" % self.pn)

    def run_serial(self, command, timeout=5):
        return self.runner.run_serial(command, timeout=timeout)
Esempio n. 21
0
class QemuTarget(BaseTarget):

    supported_image_fstypes = ['ext3', 'ext4', 'cpio.gz', 'wic']

    def __init__(self, d, logger, image_fstype=None):

        import oe.types

        super(QemuTarget, self).__init__(d, logger)

        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)
        dump_target_cmds = d.getVar("testimage_dump_target")
        dump_host_cmds = d.getVar("testimage_dump_host")
        dump_dir = d.getVar("TESTIMAGE_DUMP_DIR")
        if not dump_dir:
            dump_dir = os.path.join(d.getVar('LOG_DIR'), 'runtime-hostdump')
        use_kvm = oe.types.qemu_use_kvm(d.getVar('QEMU_USE_KVM'),
                                        d.getVar('TARGET_ARCH'))

        # Log QemuRunner log output to a file
        import oe.path
        bb.utils.mkdirhier(self.testdir)
        self.qemurunnerlog = os.path.join(self.testdir,
                                          'qemurunner_log.%s' % self.datetime)
        loggerhandler = logging.FileHandler(self.qemurunnerlog)
        loggerhandler.setFormatter(
            logging.Formatter("%(levelname)s: %(message)s"))
        self.logger.addHandler(loggerhandler)
        oe.path.symlink(os.path.basename(self.qemurunnerlog),
                        os.path.join(self.testdir, 'qemurunner_log'),
                        force=True)

        if d.getVar("DISTRO") == "poky-tiny":
            self.runner = QemuTinyRunner(
                machine=d.getVar("MACHINE"),
                rootfs=self.rootfs,
                tmpdir=d.getVar("TMPDIR"),
                deploy_dir_image=d.getVar("DEPLOY_DIR_IMAGE"),
                display=d.getVar("BB_ORIGENV", False).getVar("DISPLAY"),
                logfile=self.qemulog,
                kernel=self.kernel,
                boottime=int(d.getVar("TEST_QEMUBOOT_TIMEOUT")),
                logger=logger)
        else:
            self.runner = QemuRunner(
                machine=d.getVar("MACHINE"),
                rootfs=self.rootfs,
                tmpdir=d.getVar("TMPDIR"),
                deploy_dir_image=d.getVar("DEPLOY_DIR_IMAGE"),
                display=d.getVar("BB_ORIGENV", False).getVar("DISPLAY"),
                logfile=self.qemulog,
                boottime=int(d.getVar("TEST_QEMUBOOT_TIMEOUT")),
                use_kvm=use_kvm,
                dump_dir=dump_dir,
                dump_host_cmds=d.getVar("testimage_dump_host"),
                logger=logger)

        self.target_dumper = TargetDumper(dump_target_cmds, dump_dir,
                                          self.runner)

    def deploy(self):
        bb.utils.mkdirhier(self.testdir)

        qemuloglink = os.path.join(self.testdir, "qemu_boot_log")
        if os.path.islink(qemuloglink):
            os.unlink(qemuloglink)
        os.symlink(self.qemulog, qemuloglink)

        self.logger.info("rootfs file: %s" % self.rootfs)
        self.logger.info("Qemu log file: %s" % self.qemulog)
        super(QemuTarget, self).deploy()

    def start(self,
              params=None,
              ssh=True,
              extra_bootparams='',
              runqemuparams='',
              launch_cmd='',
              discard_writes=True):
        if launch_cmd:
            start = self.runner.launch(get_ip=ssh,
                                       launch_cmd=launch_cmd,
                                       qemuparams=params)
        else:
            start = self.runner.start(params,
                                      get_ip=ssh,
                                      extra_bootparams=extra_bootparams,
                                      runqemuparams=runqemuparams,
                                      discard_writes=discard_writes)

        if start:
            if ssh:
                self.ip = self.runner.ip
                self.server_ip = self.runner.server_ip
                self.connection = SSHControl(ip=self.ip, logfile=self.sshlog)
        else:
            self.stop()
            if os.path.exists(self.qemulog):
                with open(self.qemulog, 'r') as f:
                    bb.error("Qemu log output from %s:\n%s" %
                             (self.qemulog, f.read()))
            raise bb.build.FuncFailed(
                "%s - FAILED to start qemu - check the task log and the boot log"
                % self.pn)

    def check(self):
        return self.runner.is_alive()

    def stop(self):
        self.runner.stop()
        self.connection = None
        self.ip = None
        self.server_ip = None

    def restart(self, params=None):
        if self.runner.restart(params):
            self.ip = self.runner.ip
            self.server_ip = self.runner.server_ip
            self.connection = SSHControl(ip=self.ip, logfile=self.sshlog)
        else:
            raise bb.build.FuncFailed(
                "%s - FAILED to re-start qemu - check the task log and the boot log"
                % self.pn)

    def run_serial(self, command, timeout=60):
        return self.runner.run_serial(command, timeout=timeout)
Esempio n. 22
0
    def __init__(self, d, image_fstype=None):

        super(QemuTarget, self).__init__(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)
        dump_target_cmds = d.getVar("testimage_dump_target")
        dump_host_cmds = d.getVar("testimage_dump_host")
        dump_dir = d.getVar("TESTIMAGE_DUMP_DIR")
        qemu_use_kvm = d.getVar("QEMU_USE_KVM")
        if qemu_use_kvm and \
           (qemu_use_kvm == "True" and "x86" in d.getVar("MACHINE") or \
            d.getVar("MACHINE") in qemu_use_kvm.split()):
            use_kvm = True
        else:
            use_kvm = False

        # Log QemuRunner log output to a file
        import oe.path
        bb.utils.mkdirhier(self.testdir)
        self.qemurunnerlog = os.path.join(self.testdir,
                                          'qemurunner_log.%s' % self.datetime)
        loggerhandler = logging.FileHandler(self.qemurunnerlog)
        loggerhandler.setFormatter(
            logging.Formatter("%(levelname)s: %(message)s"))
        logger.addHandler(loggerhandler)
        oe.path.symlink(os.path.basename(self.qemurunnerlog),
                        os.path.join(self.testdir, 'qemurunner_log'),
                        force=True)

        if d.getVar("DISTRO") == "poky-tiny":
            self.runner = QemuTinyRunner(
                machine=d.getVar("MACHINE"),
                rootfs=self.rootfs,
                tmpdir=d.getVar("TMPDIR"),
                deploy_dir_image=d.getVar("DEPLOY_DIR_IMAGE"),
                display=d.getVar("BB_ORIGENV", False).getVar("DISPLAY"),
                logfile=self.qemulog,
                kernel=self.kernel,
                boottime=int(d.getVar("TEST_QEMUBOOT_TIMEOUT")))
        else:
            self.runner = QemuRunner(
                machine=d.getVar("MACHINE"),
                rootfs=self.rootfs,
                tmpdir=d.getVar("TMPDIR"),
                deploy_dir_image=d.getVar("DEPLOY_DIR_IMAGE"),
                display=d.getVar("BB_ORIGENV", False).getVar("DISPLAY"),
                logfile=self.qemulog,
                boottime=int(d.getVar("TEST_QEMUBOOT_TIMEOUT")),
                use_kvm=use_kvm,
                dump_dir=dump_dir,
                dump_host_cmds=d.getVar("testimage_dump_host"))

        self.target_dumper = TargetDumper(dump_target_cmds, dump_dir,
                                          self.runner)
Esempio n. 23
0
class OEQemuTarget(OESSHTarget):
    def __init__(self,
                 logger,
                 server_ip,
                 timeout=300,
                 user='******',
                 port=None,
                 machine='',
                 rootfs='',
                 kernel='',
                 kvm=False,
                 slirp=False,
                 dump_dir='',
                 dump_host_cmds='',
                 display='',
                 bootlog='',
                 tmpdir='',
                 dir_image='',
                 boottime=60,
                 serial_ports=2,
                 boot_patterns=defaultdict(str),
                 ovmf=False,
                 tmpfsdir=None,
                 **kwargs):

        super(OEQemuTarget, self).__init__(logger, None, server_ip, timeout,
                                           user, port)

        self.server_ip = server_ip
        self.server_port = 0
        self.machine = machine
        self.rootfs = rootfs
        self.kernel = kernel
        self.kvm = kvm
        self.ovmf = ovmf
        self.use_slirp = slirp
        self.boot_patterns = boot_patterns
        self.dump_dir = dump_dir
        self.bootlog = bootlog

        self.runner = QemuRunner(machine=machine,
                                 rootfs=rootfs,
                                 tmpdir=tmpdir,
                                 deploy_dir_image=dir_image,
                                 display=display,
                                 logfile=bootlog,
                                 boottime=boottime,
                                 use_kvm=kvm,
                                 use_slirp=slirp,
                                 dump_dir=dump_dir,
                                 dump_host_cmds=dump_host_cmds,
                                 logger=logger,
                                 serial_ports=serial_ports,
                                 boot_patterns=boot_patterns,
                                 use_ovmf=ovmf,
                                 tmpfsdir=tmpfsdir)
        dump_monitor_cmds = kwargs.get("testimage_dump_monitor")
        self.monitor_dumper = MonitorDumper(dump_monitor_cmds, dump_dir,
                                            self.runner)
        if self.monitor_dumper:
            self.monitor_dumper.create_dir("qmp")

        dump_target_cmds = kwargs.get("testimage_dump_target")
        self.target_dumper = TargetDumper(dump_target_cmds, dump_dir,
                                          self.runner)
        self.target_dumper.create_dir("qemu")

    def start(self, params=None, extra_bootparams=None, runqemuparams=''):
        if self.use_slirp and not self.server_ip:
            self.logger.error(
                "Could not start qemu with slirp without server ip - provide 'TEST_SERVER_IP'"
            )
            raise RuntimeError(
                "FAILED to start qemu - check the task log and the boot log")
        if self.runner.start(params,
                             extra_bootparams=extra_bootparams,
                             runqemuparams=runqemuparams):
            self.ip = self.runner.ip
            if self.use_slirp:
                target_ip_port = self.runner.ip.split(':')
                if len(target_ip_port) == 2:
                    target_ip = target_ip_port[0]
                    port = target_ip_port[1]
                    self.ip = target_ip
                    self.ssh = self.ssh + ['-p', port]
                    self.scp = self.scp + ['-P', port]
                else:
                    self.logger.error(
                        "Could not get host machine port to connect qemu with slirp, ssh will not be "
                        "able to connect to qemu with slirp")
            if self.runner.server_ip:
                self.server_ip = self.runner.server_ip
        else:
            self.stop()
            # Display the first 20 lines of top and
            # last 20 lines of the bootlog when the
            # target is not being booted up.
            topfile = glob.glob(self.dump_dir + "/*_qemu/host_*_top")
            msg = "\n\n===== start: snippet =====\n\n"
            for f in topfile:
                msg += "file: %s\n\n" % f
                with open(f) as tf:
                    for x in range(20):
                        msg += next(tf)
            msg += "\n\n===== end: snippet =====\n\n"
            blcmd = ["tail", "-20", self.bootlog]
            msg += "===== start: snippet =====\n\n"
            try:
                out = subprocess.check_output(blcmd,
                                              stderr=subprocess.STDOUT,
                                              timeout=1).decode('utf-8')
                msg += "file: %s\n\n" % self.bootlog
                msg += out
            except (subprocess.CalledProcessError, subprocess.TimeoutExpired,
                    FileNotFoundError) as err:
                msg += "Error running command: %s\n%s\n" % (blcmd, err)
            msg += "\n\n===== end: snippet =====\n"

            raise RuntimeError(
                "FAILED to start qemu - check the task log and the boot log %s"
                % (msg))

    def stop(self):
        self.runner.stop()
Esempio n. 24
0
class OEQemuTarget(OESSHTarget):
    supported_fstypes = ['ext3', 'ext4', 'cpio.gz', 'wic']

    def __init__(self,
                 td,
                 logger,
                 timeout=300,
                 user='******',
                 port=None,
                 machine='',
                 rootfs='',
                 kernel='',
                 kvm=False,
                 dump_dir='',
                 dump_host_cmds='',
                 display='',
                 bootlog='',
                 tmpdir='',
                 dir_image='',
                 boottime=60,
                 **kwargs):

        super(OEQemuTarget, self).__init__(td, logger, timeout, user, port)

        self.ip = td['TEST_TARGET_IP']
        self.server_ip = td['TEST_SERVER_IP']
        self.machine = machine

        image_name = ("%s/%s" %
                      (td['DEPLOY_DIR_IMAGE'], td['IMAGE_LINK_NAME']))

        # Get rootfs
        if not rootfs:
            fstypes = [
                fs for fs in td['IMAGE_FSTYPES'].split(' ')
                if fs in self.supported_fstypes
            ]
            if not fstypes:
                bb.fatal(
                    'Unsupported image type built. Add a comptible image to '
                    'IMAGE_FSTYPES. Supported types: %s' %
                    ', '.join(self.supported_fstypes))
            rootfs = '%s.%s' % (image_name, fstypes[0])
        self.rootfs = rootfs

        self.kernel = kernel
        self.kvm = kvm

        self.runner = QemuRunner(machine=machine,
                                 rootfs=rootfs,
                                 tmpdir=tmpdir,
                                 deploy_dir_image=dir_image,
                                 display=display,
                                 logfile=bootlog,
                                 boottime=boottime,
                                 use_kvm=kvm,
                                 dump_dir=dump_dir,
                                 dump_host_cmds=dump_host_cmds,
                                 logger=logger)

    def start(self, params=None, extra_bootparams=None):
        if self.runner.start(params, extra_bootparams=extra_bootparams):
            self.ip = self.runner.ip
            self.server_ip = self.runner.server_ip
        else:
            self.stop()
            raise RuntimeError(
                "FAILED to start qemu - check the task log and the boot log")

    def deploy(self):
        pass

    def stop(self):
        self.runner.stop()
Esempio n. 25
0
class QemuTarget(BaseTarget):

    supported_image_fstypes = ['ext3', 'ext4', 'cpio.gz']

    def __init__(self, d):

        super(QemuTarget, self).__init__(d)

        self.image_fstype = self.get_image_fstype(d)
        self.qemulog = os.path.join(self.testdir, "qemu_boot_log.%s" % self.datetime)
        self.origrootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True),  d.getVar("IMAGE_LINK_NAME", True) + '.' + self.image_fstype)
        self.rootfs = os.path.join(self.testdir, d.getVar("IMAGE_LINK_NAME", True) + '-testimage.' + self.image_fstype)
        self.kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("KERNEL_IMAGETYPE", False) + '-' + d.getVar('MACHINE', False) + '.bin')

        # Log QemuRunner log output to a file
        import oe.path
        bb.utils.mkdirhier(self.testdir)
        self.qemurunnerlog = os.path.join(self.testdir, 'qemurunner_log.%s' % self.datetime)
        logger = logging.getLogger('BitBake.QemuRunner')
        loggerhandler = logging.FileHandler(self.qemurunnerlog)
        loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
        logger.addHandler(loggerhandler)
        oe.path.symlink(os.path.basename(self.qemurunnerlog), os.path.join(self.testdir, 'qemurunner_log'), force=True)

        if d.getVar("DISTRO", True) == "poky-tiny":
            self.runner = QemuTinyRunner(machine=d.getVar("MACHINE", True),
                            rootfs=self.rootfs,
                            tmpdir = d.getVar("TMPDIR", True),
                            deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE", True),
                            display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
                            logfile = self.qemulog,
                            kernel = self.kernel,
                            boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)))
        else:
            self.runner = QemuRunner(machine=d.getVar("MACHINE", True),
                            rootfs=self.rootfs,
                            tmpdir = d.getVar("TMPDIR", True),
                            deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE", True),
                            display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
                            logfile = self.qemulog,
                            boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)))

    def deploy(self):
        try:
            bb.utils.mkdirhier(self.testdir)
            shutil.copyfile(self.origrootfs, self.rootfs)
        except Exception as e:
            bb.fatal("Error copying rootfs: %s" % e)

        qemuloglink = os.path.join(self.testdir, "qemu_boot_log")
        if os.path.islink(qemuloglink):
            os.unlink(qemuloglink)
        os.symlink(self.qemulog, qemuloglink)

        bb.note("rootfs file: %s" %  self.rootfs)
        bb.note("Qemu log file: %s" % self.qemulog)
        super(QemuTarget, self).deploy()

    def start(self, params=None):
        if self.runner.start(params):
            self.ip = self.runner.ip
            self.server_ip = self.runner.server_ip
            self.connection = SSHControl(ip=self.ip, logfile=self.sshlog)
        else:
            self.stop()
            if os.path.exists(self.qemulog):
                with open(self.qemulog, 'r') as f:
                    bb.error("Qemu log output from %s:\n%s" % (self.qemulog, f.read()))
            raise bb.build.FuncFailed("%s - FAILED to start qemu - check the task log and the boot log" % self.pn)

    def stop(self):
        self.runner.stop()
        self.connection = None
        self.ip = None
        self.server_ip = None

    def restart(self, params=None):
        if self.runner.restart(params):
            self.ip = self.runner.ip
            self.server_ip = self.runner.server_ip
            self.connection = SSHControl(ip=self.ip, logfile=self.sshlog)
        else:
            raise bb.build.FuncFailed("%s - FAILED to re-start qemu - check the task log and the boot log" % self.pn)

    def run_serial(self, command):
        return self.runner.run_serial(command)
Esempio n. 26
0
class QemuTarget(BaseTarget):

    supported_image_fstypes = ['ext3', 'ext4', 'cpio.gz']

    def __init__(self, d):

        super(QemuTarget, self).__init__(d)

        self.image_fstype = self.get_image_fstype(d)
        self.qemulog = os.path.join(self.testdir,
                                    "qemu_boot_log.%s" % self.datetime)
        self.origrootfs = os.path.join(
            d.getVar("DEPLOY_DIR_IMAGE", True),
            d.getVar("IMAGE_LINK_NAME", True) + '.' + self.image_fstype)
        self.rootfs = os.path.join(
            self.testdir,
            d.getVar("IMAGE_LINK_NAME", True) + '-testimage.' +
            self.image_fstype)
        self.kernel = os.path.join(
            d.getVar("DEPLOY_DIR_IMAGE", True),
            d.getVar("KERNEL_IMAGETYPE", False) + '-' +
            d.getVar('MACHINE', False) + '.bin')

        if d.getVar("DISTRO", True) == "poky-tiny":
            self.runner = QemuTinyRunner(
                machine=d.getVar("MACHINE", True),
                rootfs=self.rootfs,
                tmpdir=d.getVar("TMPDIR", True),
                deploy_dir_image=d.getVar("DEPLOY_DIR_IMAGE", True),
                display=d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
                logfile=self.qemulog,
                kernel=self.kernel,
                boottime=int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)))
        else:
            self.runner = QemuRunner(
                machine=d.getVar("MACHINE", True),
                rootfs=self.rootfs,
                tmpdir=d.getVar("TMPDIR", True),
                deploy_dir_image=d.getVar("DEPLOY_DIR_IMAGE", True),
                display=d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
                logfile=self.qemulog,
                boottime=int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)))

    def deploy(self):
        try:
            shutil.copyfile(self.origrootfs, self.rootfs)
        except Exception as e:
            bb.fatal("Error copying rootfs: %s" % e)

        qemuloglink = os.path.join(self.testdir, "qemu_boot_log")
        if os.path.islink(qemuloglink):
            os.unlink(qemuloglink)
        os.symlink(self.qemulog, qemuloglink)

        bb.note("rootfs file: %s" % self.rootfs)
        bb.note("Qemu log file: %s" % self.qemulog)
        super(QemuTarget, self).deploy()

    def start(self, params=None):
        if self.runner.start(params):
            self.ip = self.runner.ip
            self.server_ip = self.runner.server_ip
            self.connection = SSHControl(ip=self.ip, logfile=self.sshlog)
        else:
            self.stop()
            raise bb.build.FuncFailed(
                "%s - FAILED to start qemu - check the task log and the boot log"
                % self.pn)

    def stop(self):
        self.runner.stop()
        self.connection = None
        self.ip = None
        self.server_ip = None

    def restart(self, params=None):
        if self.runner.restart(params):
            self.ip = self.runner.ip
            self.server_ip = self.runner.server_ip
            self.connection = SSHControl(ip=self.ip, logfile=self.sshlog)
        else:
            raise bb.build.FuncFailed(
                "%s - FAILED to re-start qemu - check the task log and the boot log"
                % self.pn)

    def run_serial(self, command):
        return self.runner.run_serial(command)