summaryrefslogtreecommitdiffstats
path: root/lib/oeqa/selftest
diff options
context:
space:
mode:
Diffstat (limited to 'lib/oeqa/selftest')
l---------lib/oeqa/selftest/cases/qemucommand.py1
-rw-r--r--lib/oeqa/selftest/cases/updater.py (renamed from lib/oeqa/selftest/updater.py)144
l---------lib/oeqa/selftest/qemucommand.py1
3 files changed, 89 insertions, 57 deletions
diff --git a/lib/oeqa/selftest/cases/qemucommand.py b/lib/oeqa/selftest/cases/qemucommand.py
new file mode 120000
index 0000000..075cdb8
--- /dev/null
+++ b/lib/oeqa/selftest/cases/qemucommand.py
@@ -0,0 +1 @@
../../../../scripts/qemucommand.py \ No newline at end of file
diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/cases/updater.py
index ad99964..253320d 100644
--- a/lib/oeqa/selftest/updater.py
+++ b/lib/oeqa/selftest/cases/updater.py
@@ -1,18 +1,19 @@
1import unittest
2import os 1import os
3import logging 2import logging
4import subprocess 3import subprocess
5import time 4import time
5import unittest
6 6
7from oeqa.selftest.base import oeSelfTest 7from oeqa.selftest.case import OESelftestTestCase
8from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars 8from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars
9from oeqa.selftest.qemucommand import QemuCommand 9from qemucommand import QemuCommand
10 10
11 11
12class SotaToolsTests(oeSelfTest): 12class SotaToolsTests(OESelftestTestCase):
13 13
14 @classmethod 14 @classmethod
15 def setUpClass(cls): 15 def setUpClass(cls):
16 super(SotaToolsTests, cls).setUpClass()
16 logger = logging.getLogger("selftest") 17 logger = logging.getLogger("selftest")
17 logger.info('Running bitbake to build aktualizr-native tools') 18 logger.info('Running bitbake to build aktualizr-native tools')
18 bitbake('aktualizr-native') 19 bitbake('aktualizr-native')
@@ -31,31 +32,22 @@ class SotaToolsTests(oeSelfTest):
31 result = runCmd('%s --help' % p, ignore_status=True) 32 result = runCmd('%s --help' % p, ignore_status=True)
32 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) 33 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
33 34
34 35 def test_garagesign_help(self):
35class GarageSignTests(oeSelfTest): 36 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'aktualizr-native')
36
37 @classmethod
38 def setUpClass(cls):
39 logger = logging.getLogger("selftest")
40 logger.info('Running bitbake to build garage-sign-native')
41 bitbake('garage-sign-native')
42
43 def test_help(self):
44 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'garage-sign-native')
45 p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "garage-sign" 37 p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "garage-sign"
46 self.assertTrue(os.path.isfile(p), msg = "No garage-sign found (%s)" % p) 38 self.assertTrue(os.path.isfile(p), msg = "No garage-sign found (%s)" % p)
47 result = runCmd('%s --help' % p, ignore_status=True) 39 result = runCmd('%s --help' % p, ignore_status=True)
48 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output) 40 self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
49 41
50 42
51class HsmTests(oeSelfTest): 43class HsmTests(OESelftestTestCase):
52 44
53 def test_hsm(self): 45 def test_hsm(self):
54 self.write_config('SOTA_CLIENT_FEATURES="hsm hsm-test"') 46 self.write_config('SOTA_CLIENT_FEATURES="hsm"')
55 bitbake('core-image-minimal') 47 bitbake('core-image-minimal')
56 48
57 49
58class GeneralTests(oeSelfTest): 50class GeneralTests(OESelftestTestCase):
59 51
60 def test_feature_sota(self): 52 def test_feature_sota(self):
61 result = get_bb_var('DISTRO_FEATURES').find('sota') 53 result = get_bb_var('DISTRO_FEATURES').find('sota')
@@ -114,53 +106,21 @@ class GeneralTests(oeSelfTest):
114 self.assertNotEqual(size1, size2, "Image sizes are identical; image was not rebuilt.") 106 self.assertNotEqual(size1, size2, "Image sizes are identical; image was not rebuilt.")
115 107
116 108
117class QemuTests(oeSelfTest): 109class QemuTests(OESelftestTestCase):
118 110
119 @classmethod 111 @classmethod
120 def setUpClass(cls): 112 def setUpClass(cls):
121 logger = logging.getLogger("selftest") 113 super(QemuTests, cls).setUpClass()
122 logger.info('Running bitbake to build core-image-minimal') 114 cls.qemu, cls.s = qemu_launch(machine='qemux86-64')
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 115
146 @classmethod 116 @classmethod
147 def tearDownClass(cls): 117 def tearDownClass(cls):
148 try: 118 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 119
160 def test_hostname(self): 120 def test_hostname(self):
161 print('') 121 print('')
162 print('Checking machine name (hostname) of device:') 122 print('Checking machine name (hostname) of device:')
163 value, err = self.run_test_qemu('hostname') 123 value, err = qemu_send_command(self.qemu.ssh_port, 'hostname')
164 machine = get_bb_var('MACHINE', 'core-image-minimal') 124 machine = get_bb_var('MACHINE', 'core-image-minimal')
165 self.assertEqual(err, b'', 'Error: ' + err.decode()) 125 self.assertEqual(err, b'', 'Error: ' + err.decode())
166 # Strip off line ending. 126 # Strip off line ending.
@@ -172,8 +132,80 @@ class QemuTests(oeSelfTest):
172 def test_var_sota(self): 132 def test_var_sota(self):
173 print('') 133 print('')
174 print('Checking contents of /var/sota:') 134 print('Checking contents of /var/sota:')
175 value, err = self.run_test_qemu('ls /var/sota') 135 value, err = qemu_send_command(self.qemu.ssh_port, 'ls /var/sota')
176 self.assertEqual(err, b'', 'Error: ' + err.decode()) 136 self.assertEqual(err, b'', 'Error: ' + err.decode())
177 print(value.decode()) 137 print(value.decode())
178 138
179 139
140class GrubTests(OESelftestTestCase):
141
142 def setUpLocal(self):
143 # This is a bit of a hack but I can't see a better option.
144 path = os.path.abspath(os.path.dirname(__file__))
145 metadir = path + "/../../../../../"
146 grub_config = 'OSTREE_BOOTLOADER = "grub"\nMACHINE = "intel-corei7-64"'
147 self.append_config(grub_config)
148 self.meta_intel = metadir + "meta-intel"
149 self.meta_minnow = metadir + "meta-updater-minnowboard"
150 runCmd('bitbake-layers add-layer "%s"' % self.meta_intel)
151 runCmd('bitbake-layers add-layer "%s"' % self.meta_minnow)
152 self.qemu, self.s = qemu_launch(efi=True, machine='intel-corei7-64')
153
154 def tearDownLocal(self):
155 qemu_terminate(self.s)
156 runCmd('bitbake-layers remove-layer "%s"' % self.meta_intel, ignore_status=True)
157 runCmd('bitbake-layers remove-layer "%s"' % self.meta_minnow, ignore_status=True)
158
159 def test_grub(self):
160 print('')
161 print('Checking machine name (hostname) of device:')
162 value, err = qemu_send_command(self.qemu.ssh_port, 'hostname')
163 machine = get_bb_var('MACHINE', 'core-image-minimal')
164 self.assertEqual(err, b'', 'Error: ' + err.decode())
165 # Strip off line ending.
166 value_str = value.decode()[:-1]
167 self.assertEqual(value_str, machine,
168 'MACHINE does not match hostname: ' + machine + ', ' + value_str)
169 print(value_str)
170
171
172def qemu_launch(efi=False, machine=None):
173 logger = logging.getLogger("selftest")
174 logger.info('Running bitbake to build core-image-minimal')
175 bitbake('core-image-minimal')
176 # Create empty object.
177 args = type('', (), {})()
178 args.imagename = 'core-image-minimal'
179 args.mac = None
180 # Could use DEPLOY_DIR_IMAGE here but it's already in the machine
181 # subdirectory.
182 args.dir = 'tmp/deploy/images'
183 args.efi = efi
184 args.machine = machine
185 args.kvm = None # Autodetect
186 args.no_gui = True
187 args.gdb = False
188 args.pcap = None
189 args.overlay = None
190 args.dry_run = False
191
192 qemu = QemuCommand(args)
193 cmdline = qemu.command_line()
194 print('Booting image with run-qemu-ota...')
195 s = subprocess.Popen(cmdline)
196 time.sleep(10)
197 return qemu, s
198
199def qemu_terminate(s):
200 try:
201 s.terminate()
202 except KeyboardInterrupt:
203 pass
204
205def qemu_send_command(port, command):
206 command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' +
207 str(port) + ' "' + command + '"']
208 s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
209 value, err = s2.communicate()
210 return value, err
211
diff --git a/lib/oeqa/selftest/qemucommand.py b/lib/oeqa/selftest/qemucommand.py
deleted file mode 120000
index bc06dde..0000000
--- a/lib/oeqa/selftest/qemucommand.py
+++ /dev/null
@@ -1 +0,0 @@
1../../../scripts/qemucommand.py \ No newline at end of file