blob: c3a98979c56f6767e66845e8069b2563e7227dd9 [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
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000022from oeqa.controllers.controllerimage import ControllerImageHardwareTarget
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000024class GrubTarget(ControllerImageHardwareTarget):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025
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
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000043 self.controller.run("umount /boot; umount /mnt/testrootfs;")
44 self.controller.ignore_status = False
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045 # Kernel files may not be in the image, so copy them just in case
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000046 self.controller.copy_to(self.rootfs, "~/test-rootfs." + self.image_fstype)
47 self.controller.copy_to(self.kernel, "~/test-kernel")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050048 for cmd in self.deploy_cmds:
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000049 self.controller.run(cmd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050050
51 def _start(self, params=None):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000052 self.power_cycle(self.controller)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053 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