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