Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | |
| 15 | import os |
| 16 | import bb |
| 17 | import time |
| 18 | import subprocess |
| 19 | import sys |
| 20 | import pexpect |
| 21 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 22 | from oeqa.controllers.controllerimage import ControllerImageHardwareTarget |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 24 | class GrubTarget(ControllerImageHardwareTarget): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 43 | self.controller.run("umount /boot; umount /mnt/testrootfs;") |
| 44 | self.controller.ignore_status = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 45 | # Kernel files may not be in the image, so copy them just in case |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 46 | self.controller.copy_to(self.rootfs, "~/test-rootfs." + self.image_fstype) |
| 47 | self.controller.copy_to(self.kernel, "~/test-kernel") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | for cmd in self.deploy_cmds: |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 49 | self.controller.run(cmd) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 50 | |
| 51 | def _start(self, params=None): |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 52 | self.power_cycle(self.controller) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | |