summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa
diff options
context:
space:
mode:
authorStefan Stanacar <stefanx.stanacar@intel.com>2014-04-30 13:31:57 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-04-30 21:52:32 +0100
commitcc4234eaca0b9b3bb8c0e5ccc894fc4838fa8f46 (patch)
tree059e74f7665f182d8ecfdb4c5045fef5501c7f4b /meta/lib/oeqa
parentd36c6061c11d0edeb2b8dd5bb3b2c63a1f37c109 (diff)
downloadpoky-cc4234eaca0b9b3bb8c0e5ccc894fc4838fa8f46.tar.gz
oeqa/controllers/masterimage: add a base class for hw targets
Right now GummibootTarget is the only hardware TEST_TARGET with deployment, but we will add more, so let's make an abstract base class, that will do the common thing for all the hw targets. (From OE-Core rev: 1d70b1908e1dc5d612b0627022659639e3f384e5) Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com> Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa')
-rw-r--r--meta/lib/oeqa/controllers/masterimage.py137
1 files changed, 91 insertions, 46 deletions
diff --git a/meta/lib/oeqa/controllers/masterimage.py b/meta/lib/oeqa/controllers/masterimage.py
index 188c630bcd..1bd0ab4c66 100644
--- a/meta/lib/oeqa/controllers/masterimage.py
+++ b/meta/lib/oeqa/controllers/masterimage.py
@@ -1,17 +1,50 @@
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 using a "master image" - this is a "known good" image that is
7# installed onto the device as part of initial setup and will be booted into
8# with no interaction; we can then use it to deploy the image to be tested
9# to a second partition before running the tests.
10#
11# For an example master image, see core-image-testmaster
12# (meta/recipes-extended/images/core-image-testmaster.bb)
13
1import os 14import os
2import bb 15import bb
3import traceback 16import traceback
4import time 17import time
18import subprocess
5 19
6import oeqa.targetcontrol 20import oeqa.targetcontrol
7import oeqa.utils.sshcontrol as sshcontrol 21import oeqa.utils.sshcontrol as sshcontrol
8import oeqa.utils.commands as commands 22import oeqa.utils.commands as commands
9 23
10class GummibootTarget(oeqa.targetcontrol.SimpleRemoteTarget): 24from abc import ABCMeta, abstractmethod
25
26class MasterImageHardwareTarget(oeqa.targetcontrol.BaseTarget):
27
28 __metaclass__ = ABCMeta
11 29
12 def __init__(self, d): 30 def __init__(self, d):
13 # let our base class do the ip thing 31 super(MasterImageHardwareTarget, self).__init__(d)
14 super(GummibootTarget, self).__init__(d) 32
33 # target ip
34 addr = d.getVar("TEST_TARGET_IP", True) or bb.fatal('Please set TEST_TARGET_IP with the IP address of the machine you want to run the tests on.')
35 self.ip = addr.split(":")[0]
36 try:
37 self.port = addr.split(":")[1]
38 except IndexError:
39 self.port = None
40 bb.note("Target IP: %s" % self.ip)
41 self.server_ip = d.getVar("TEST_SERVER_IP", True)
42 if not self.server_ip:
43 try:
44 self.server_ip = subprocess.check_output(['ip', 'route', 'get', self.ip ]).split("\n")[0].split()[-1]
45 except Exception as e:
46 bb.fatal("Failed to determine the host IP address (alternatively you can set TEST_SERVER_IP with the IP address of this machine): %s" % e)
47 bb.note("Server IP: %s" % self.server_ip)
15 48
16 # test rootfs + kernel 49 # test rootfs + kernel
17 self.rootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME", True) + '.tar.gz') 50 self.rootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME", True) + '.tar.gz')
@@ -26,36 +59,11 @@ class GummibootTarget(oeqa.targetcontrol.SimpleRemoteTarget):
26 if not os.path.isfile(self.kernel): 59 if not os.path.isfile(self.kernel):
27 bb.fatal("No kernel found. Expected path: %s" % self.kernel) 60 bb.fatal("No kernel found. Expected path: %s" % self.kernel)
28 61
29 # if the user knows what he's doing, then by all means...
30 # test-rootfs.tar.gz and test-kernel are hardcoded names in other places
31 # they really have to be used like that in commands though
32 cmds = d.getVar("TEST_DEPLOY_CMDS", True)
33
34 # this the value we need to set in the LoaderEntryOneShot EFI variable
35 # so the system boots the 'test' bootloader label and not the default
36 # The first four bytes are EFI bits, and the rest is an utf-16le string
37 # (EFI vars values need to be utf-16)
38 # $ echo -en "test\0" | iconv -f ascii -t utf-16le | hexdump -C
39 # 00000000 74 00 65 00 73 00 74 00 00 00 |t.e.s.t...|
40 self.efivarvalue = r'\x07\x00\x00\x00\x74\x00\x65\x00\x73\x00\x74\x00\x00\x00'
41
42 if cmds:
43 self.deploy_cmds = cmds.split("\n")
44 else:
45 self.deploy_cmds = [
46 'mount -L boot /boot',
47 'mkdir -p /mnt/testrootfs',
48 'mount -L testrootfs /mnt/testrootfs',
49 'modprobe efivarfs',
50 'mount -t efivarfs efivarfs /sys/firmware/efi/efivars',
51 'cp ~/test-kernel /boot',
52 'rm -rf /mnt/testrootfs/*',
53 'tar xzvf ~/test-rootfs.tar.gz -C /mnt/testrootfs',
54 'printf "%s" > /sys/firmware/efi/efivars/LoaderEntryOneShot-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f' % self.efivarvalue
55 ]
56
57 # master ssh connection 62 # master ssh connection
58 self.master = None 63 self.master = None
64 # if the user knows what they are doing, then by all means...
65 self.user_cmds = d.getVar("TEST_DEPLOY_CMDS", True)
66 self.deploy_cmds = None
59 67
60 # this is the name of the command that controls the power for a board 68 # this is the name of the command that controls the power for a board
61 # e.g: TEST_POWERCONTROL_CMD = "/home/user/myscripts/powercontrol.py ${MACHINE} what-ever-other-args-the-script-wants" 69 # e.g: TEST_POWERCONTROL_CMD = "/home/user/myscripts/powercontrol.py ${MACHINE} what-ever-other-args-the-script-wants"
@@ -94,22 +102,67 @@ class GummibootTarget(oeqa.targetcontrol.SimpleRemoteTarget):
94 def deploy(self): 102 def deploy(self):
95 bb.plain("%s - deploying image on target" % self.pn) 103 bb.plain("%s - deploying image on target" % self.pn)
96 # base class just sets the ssh log file for us 104 # base class just sets the ssh log file for us
97 super(GummibootTarget, self).deploy() 105 super(MasterImageHardwareTarget, self).deploy()
98 self.master = sshcontrol.SSHControl(ip=self.ip, logfile=self.sshlog, timeout=600, port=self.port) 106 self.master = sshcontrol.SSHControl(ip=self.ip, logfile=self.sshlog, timeout=600, port=self.port)
107 status, output = self.master.run("cat /etc/masterimage")
108 if status != 0:
109 bb.fatal("No ssh connectivity or target isn't running a master image.\n%s" % output)
110 if self.user_cmds:
111 self.deploy_cmds = self.user_cmds.split("\n")
99 try: 112 try:
100 self._deploy() 113 self._deploy()
101 except Exception as e: 114 except Exception as e:
102 bb.fatal("Failed deploying test image: %s" % e) 115 bb.fatal("Failed deploying test image: %s" % e)
103 116
117 @abstractmethod
104 def _deploy(self): 118 def _deploy(self):
105 # make sure we are in the right image 119 pass
106 status, output = self.master.run("cat /etc/masterimage") 120
107 if status != 0: 121 def start(self, params=None):
108 raise Exception("No ssh connectivity or target isn't running a master image.\n%s" % output) 122 bb.plain("%s - boot test image on target" % self.pn)
123 self._start()
124 # set the ssh object for the target/test image
125 self.connection = sshcontrol.SSHControl(self.ip, logfile=self.sshlog, port=self.port)
126 bb.plain("%s - start running tests" % self.pn)
127
128 @abstractmethod
129 def _start(self):
130 pass
109 131
132 def stop(self):
133 bb.plain("%s - reboot/powercycle target" % self.pn)
134 self.power_cycle(self.connection)
135
136 def restart(self):
137 pass
138
139
140class GummibootTarget(MasterImageHardwareTarget):
141
142 def __init__(self, d):
143 super(GummibootTarget, self).__init__(d)
144 # this the value we need to set in the LoaderEntryOneShot EFI variable
145 # so the system boots the 'test' bootloader label and not the default
146 # The first four bytes are EFI bits, and the rest is an utf-16le string
147 # (EFI vars values need to be utf-16)
148 # $ echo -en "test\0" | iconv -f ascii -t utf-16le | hexdump -C
149 # 00000000 74 00 65 00 73 00 74 00 00 00 |t.e.s.t...|
150 self.efivarvalue = r'\x07\x00\x00\x00\x74\x00\x65\x00\x73\x00\x74\x00\x00\x00'
151 self.deploy_cmds = [
152 'mount -L boot /boot',
153 'mkdir -p /mnt/testrootfs',
154 'mount -L testrootfs /mnt/testrootfs',
155 'modprobe efivarfs',
156 'mount -t efivarfs efivarfs /sys/firmware/efi/efivars',
157 'cp ~/test-kernel /boot',
158 'rm -rf /mnt/testrootfs/*',
159 'tar xzvf ~/test-rootfs.tar.gz -C /mnt/testrootfs',
160 'printf "%s" > /sys/firmware/efi/efivars/LoaderEntryOneShot-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f' % self.efivarvalue
161 ]
162
163 def _deploy(self):
110 # make sure these aren't mounted 164 # make sure these aren't mounted
111 self.master.run("umount /boot; umount /mnt/testrootfs; umount /sys/firmware/efi/efivars;") 165 self.master.run("umount /boot; umount /mnt/testrootfs; umount /sys/firmware/efi/efivars;")
112
113 # from now on, every deploy cmd should return 0 166 # from now on, every deploy cmd should return 0
114 # else an exception will be thrown by sshcontrol 167 # else an exception will be thrown by sshcontrol
115 self.master.ignore_status = False 168 self.master.ignore_status = False
@@ -118,16 +171,8 @@ class GummibootTarget(oeqa.targetcontrol.SimpleRemoteTarget):
118 for cmd in self.deploy_cmds: 171 for cmd in self.deploy_cmds:
119 self.master.run(cmd) 172 self.master.run(cmd)
120 173
121 174 def _start(self, params=None):
122 def start(self, params=None):
123 bb.plain("%s - boot test image on target" % self.pn)
124 self.power_cycle(self.master) 175 self.power_cycle(self.master)
125 # there are better ways than a timeout but this should work for now 176 # there are better ways than a timeout but this should work for now
126 time.sleep(120) 177 time.sleep(120)
127 # set the ssh object for the target/test image
128 self.connection = sshcontrol.SSHControl(self.ip, logfile=self.sshlog, port=self.port)
129 bb.plain("%s - start running tests" % self.pn)
130 178
131 def stop(self):
132 bb.plain("%s - reboot/powercycle target" % self.pn)
133 self.power_cycle(self.connection)