summaryrefslogtreecommitdiffstats
path: root/lib/oeqa/selftest/updater.py
diff options
context:
space:
mode:
authorcajun-rat <phil@advancedtelematic.com>2017-11-28 08:09:57 +0100
committerGitHub <noreply@github.com>2017-11-28 08:09:57 +0100
commit378d5ab768690886c3e701c558c2c612f6736386 (patch)
tree9c61eb6c00aeda2ded5a3d90eee490a3b0a9fc4b /lib/oeqa/selftest/updater.py
parentc1267b64afd5e2c33c327629b48da1a305adcda9 (diff)
parent495a4a4ec6d540e1045852bc92ef46aa6a6bd9d9 (diff)
downloadmeta-updater-378d5ab768690886c3e701c558c2c612f6736386.tar.gz
Merge pull request #183 from advancedtelematic/test/oe-selftest-grub
Test/oe selftest grub
Diffstat (limited to 'lib/oeqa/selftest/updater.py')
-rw-r--r--lib/oeqa/selftest/updater.py112
1 files changed, 75 insertions, 37 deletions
diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py
index ad99964..e3d4fc3 100644
--- a/lib/oeqa/selftest/updater.py
+++ b/lib/oeqa/selftest/updater.py
@@ -118,49 +118,16 @@ class QemuTests(oeSelfTest):
118 118
119 @classmethod 119 @classmethod
120 def setUpClass(cls): 120 def setUpClass(cls):
121 logger = logging.getLogger("selftest") 121 cls.qemu, cls.s = qemu_launch(machine='qemux86-64')
122 logger.info('Running bitbake to build core-image-minimal')
123 bitbake('core-image-minimal')
124 # Create empty object.
125 args = type('', (), {})()
126 args.imagename = 'core-image-minimal'
127 args.mac = None
128 # Could use DEPLOY_DIR_IMAGE here but it's already in the machine
129 # subdirectory.
130 args.dir = 'tmp/deploy/images'
131 args.efi = False
132 args.machine = None
133 args.kvm = None # Autodetect
134 args.no_gui = True
135 args.gdb = False
136 args.pcap = None
137 args.overlay = None
138 args.dry_run = False
139
140 cls.qemu = QemuCommand(args)
141 cmdline = cls.qemu.command_line()
142 print('Booting image with run-qemu-ota...')
143 cls.s = subprocess.Popen(cmdline)
144 time.sleep(10)
145 122
146 @classmethod 123 @classmethod
147 def tearDownClass(cls): 124 def tearDownClass(cls):
148 try: 125 qemu_terminate(cls.s)
149 cls.s.terminate()
150 except KeyboardInterrupt:
151 pass
152
153 def run_test_qemu(self, command):
154 command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' +
155 str(self.qemu.ssh_port) + ' "' + command + '"']
156 s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
157 value, err = s2.communicate()
158 return value, err
159 126
160 def test_hostname(self): 127 def test_hostname(self):
161 print('') 128 print('')
162 print('Checking machine name (hostname) of device:') 129 print('Checking machine name (hostname) of device:')
163 value, err = self.run_test_qemu('hostname') 130 value, err = qemu_send_command(self.qemu.ssh_port, 'hostname')
164 machine = get_bb_var('MACHINE', 'core-image-minimal') 131 machine = get_bb_var('MACHINE', 'core-image-minimal')
165 self.assertEqual(err, b'', 'Error: ' + err.decode()) 132 self.assertEqual(err, b'', 'Error: ' + err.decode())
166 # Strip off line ending. 133 # Strip off line ending.
@@ -172,8 +139,79 @@ class QemuTests(oeSelfTest):
172 def test_var_sota(self): 139 def test_var_sota(self):
173 print('') 140 print('')
174 print('Checking contents of /var/sota:') 141 print('Checking contents of /var/sota:')
175 value, err = self.run_test_qemu('ls /var/sota') 142 value, err = qemu_send_command(self.qemu.ssh_port, 'ls /var/sota')
176 self.assertEqual(err, b'', 'Error: ' + err.decode()) 143 self.assertEqual(err, b'', 'Error: ' + err.decode())
177 print(value.decode()) 144 print(value.decode())
178 145
146class GrubTests(oeSelfTest):
147
148 def setUpLocal(self):
149 # This is a bit of a hack but I can't see a better option.
150 path = os.path.abspath(os.path.dirname(__file__))
151 metadir = path + "/../../../../"
152 grub_config = 'OSTREE_BOOTLOADER = "grub"\nMACHINE = "intel-corei7-64"'
153 self.append_config(grub_config)
154 self.meta_intel = metadir + "meta-intel"
155 self.meta_minnow = metadir + "meta-updater-minnowboard"
156 runCmd('bitbake-layers add-layer "%s"' % self.meta_intel)
157 runCmd('bitbake-layers add-layer "%s"' % self.meta_minnow)
158 self.qemu, self.s = qemu_launch(efi=True, machine='intel-corei7-64')
159
160 def tearDownLocal(self):
161 qemu_terminate(self.s)
162 runCmd('bitbake-layers remove-layer "%s"' % self.meta_intel, ignore_status=True)
163 runCmd('bitbake-layers remove-layer "%s"' % self.meta_minnow, ignore_status=True)
164
165 def test_grub(self):
166 print('')
167 print('Checking machine name (hostname) of device:')
168 value, err = qemu_send_command(self.qemu.ssh_port, 'hostname')
169 machine = get_bb_var('MACHINE', 'core-image-minimal')
170 self.assertEqual(err, b'', 'Error: ' + err.decode())
171 # Strip off line ending.
172 value_str = value.decode()[:-1]
173 self.assertEqual(value_str, machine,
174 'MACHINE does not match hostname: ' + machine + ', ' + value_str)
175 print(value_str)
176
177
178def qemu_launch(efi=False, machine=None):
179 logger = logging.getLogger("selftest")
180 logger.info('Running bitbake to build core-image-minimal')
181 bitbake('core-image-minimal')
182 # Create empty object.
183 args = type('', (), {})()
184 args.imagename = 'core-image-minimal'
185 args.mac = None
186 # Could use DEPLOY_DIR_IMAGE here but it's already in the machine
187 # subdirectory.
188 args.dir = 'tmp/deploy/images'
189 args.efi = efi
190 args.machine = machine
191 args.kvm = None # Autodetect
192 args.no_gui = True
193 args.gdb = False
194 args.pcap = None
195 args.overlay = None
196 args.dry_run = False
197
198 qemu = QemuCommand(args)
199 cmdline = qemu.command_line()
200 print('Booting image with run-qemu-ota...')
201 s = subprocess.Popen(cmdline)
202 time.sleep(10)
203 return qemu, s
204
205def qemu_terminate(s):
206 try:
207 s.terminate()
208 except KeyboardInterrupt:
209 pass
210
211def qemu_send_command(port, command):
212 command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' +
213 str(port) + ' "' + command + '"']
214 s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
215 value, err = s2.communicate()
216 return value, err
179 217