blob: 7bc807d2bc623a29e32eb8e1de73b754d971d997 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# 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
22import oeqa.utils.sshcontrol as sshcontrol
23from oeqa.controllers.masterimage import MasterImageHardwareTarget
24
25class GrubTarget(MasterImageHardwareTarget):
26
27 def __init__(self, d):
28 super(GrubTarget, self).__init__(d)
29 self.deploy_cmds = [
30 'mount -L boot /boot',
31 'mkdir -p /mnt/testrootfs',
32 'mount -L testrootfs /mnt/testrootfs',
33 'cp ~/test-kernel /boot',
34 'rm -rf /mnt/testrootfs/*',
35 'tar xvf ~/test-rootfs.%s -C /mnt/testrootfs' % self.image_fstype,
36 ]
37
38 if not self.serialcontrol_cmd:
39 bb.fatal("This TEST_TARGET needs a TEST_SERIALCONTROL_CMD defined in local.conf.")
40
41
42 def _deploy(self):
43 # make sure these aren't mounted
44 self.master.run("umount /boot; umount /mnt/testrootfs;")
45 self.master.ignore_status = False
46 # Kernel files may not be in the image, so copy them just in case
47 self.master.copy_to(self.rootfs, "~/test-rootfs." + self.image_fstype)
48 self.master.copy_to(self.kernel, "~/test-kernel")
49 for cmd in self.deploy_cmds:
50 self.master.run(cmd)
51
52 def _start(self, params=None):
53 self.power_cycle(self.master)
54 try:
55 serialconn = pexpect.spawn(self.serialcontrol_cmd, env=self.origenv, logfile=sys.stdout)
56 serialconn.expect("GNU GRUB version 2.00")
57 serialconn.expect("Linux")
58 serialconn.sendline("x")
59 serialconn.expect("login:", timeout=120)
60 serialconn.close()
61 except pexpect.ExceptionPexpect as e:
62 bb.fatal('Serial interaction failed: %s' % str(e))
63
64 def _wait_until_booted(self):
65 try:
66 serialconn = pexpect.spawn(self.serialcontrol_cmd, env=self.origenv, logfile=sys.stdout)
67 serialconn.expect("login:", timeout=120)
68 serialconn.close()
69 except pexpect.ExceptionPexpect as e:
70 bb.fatal('Serial interaction failed: %s' % str(e))
71