1# Copyright (C) 2014 Intel Corporation 2# 3# Released under the MIT license (see COPYING.MIT) 4 5# This module adds support to testimage.bbclass to deploy images and run 6# tests on a Generic PC that boots using grub bootloader. The device must 7# be set up as per README.hardware and the master image should be deployed 8# onto the harddisk so that it boots into it by default.For booting into the 9# image under test we interact with grub over serial, so for the 10# Generic PC you will need an additional serial cable and device under test 11# needs to have a serial interface. The separate ext3 12# partition that will contain the image to be tested must be labelled 13# "testrootfs" so that the deployment code below can find it. 14 15import os 16import bb 17import time 18import subprocess 19import sys 20import pexpect 21 22from oeqa.controllers.controllerimage import ControllerImageHardwareTarget 23 24class GrubTarget(ControllerImageHardwareTarget): 25 26 def __init__(self, d): 27 super(GrubTarget, self).__init__(d) 28 self.deploy_cmds = [ 29 'mount -L boot /boot', 30 'mkdir -p /mnt/testrootfs', 31 'mount -L testrootfs /mnt/testrootfs', 32 'cp ~/test-kernel /boot', 33 'rm -rf /mnt/testrootfs/*', 34 'tar xvf ~/test-rootfs.%s -C /mnt/testrootfs' % self.image_fstype, 35 ] 36 37 if not self.serialcontrol_cmd: 38 bb.fatal("This TEST_TARGET needs a TEST_SERIALCONTROL_CMD defined in local.conf.") 39 40 41 def _deploy(self): 42 # make sure these aren't mounted 43 self.controller.run("umount /boot; umount /mnt/testrootfs;") 44 self.controller.ignore_status = False 45 # Kernel files may not be in the image, so copy them just in case 46 self.controller.copy_to(self.rootfs, "~/test-rootfs." + self.image_fstype) 47 self.controller.copy_to(self.kernel, "~/test-kernel") 48 for cmd in self.deploy_cmds: 49 self.controller.run(cmd) 50 51 def _start(self, params=None): 52 self.power_cycle(self.controller) 53 try: 54 serialconn = pexpect.spawn(self.serialcontrol_cmd, env=self.origenv, logfile=sys.stdout) 55 serialconn.expect("GNU GRUB version 2.00") 56 serialconn.expect("Linux") 57 serialconn.sendline("x") 58 serialconn.expect("login:", timeout=120) 59 serialconn.close() 60 except pexpect.ExceptionPexpect as e: 61 bb.fatal('Serial interaction failed: %s' % str(e)) 62 63 def _wait_until_booted(self): 64 try: 65 serialconn = pexpect.spawn(self.serialcontrol_cmd, env=self.origenv, logfile=sys.stdout) 66 serialconn.expect("login:", timeout=120) 67 serialconn.close() 68 except pexpect.ExceptionPexpect as e: 69 bb.fatal('Serial interaction failed: %s' % str(e)) 70 71