blob: 6c25bb901d193eb038917929e76ae98a92c3725c [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001from oeqa.selftest.case import OESelftestTestCase
2from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars, runqemu
3from oeqa.utils.sshcontrol import SSHControl
4from oeqa.core.decorator.oeid import OETestID
5import os
6import re
7import tempfile
8import shutil
Brad Bishop19323692019-04-05 15:28:33 -04009import oe.lsb
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010
11class TestExport(OESelftestTestCase):
12
13 @classmethod
14 def tearDownClass(cls):
15 runCmd("rm -rf /tmp/sdk")
16 super(TestExport, cls).tearDownClass()
17
18 @OETestID(1499)
19 def test_testexport_basic(self):
20 """
21 Summary: Check basic testexport functionality with only ping test enabled.
22 Expected: 1. testexport directory must be created.
23 2. runexported.py must run without any error/exception.
24 3. ping test must succeed.
25 Product: oe-core
26 Author: Mariano Lopez <mariano.lopez@intel.com>
27 """
28
29 features = 'INHERIT += "testexport"\n'
30 # These aren't the actual IP addresses but testexport class needs something defined
31 features += 'TEST_SERVER_IP = "192.168.7.1"\n'
32 features += 'TEST_TARGET_IP = "192.168.7.1"\n'
33 features += 'TEST_SUITES = "ping"\n'
34 self.write_config(features)
35
36 # Build tesexport for core-image-minimal
37 bitbake('core-image-minimal')
38 bitbake('-c testexport core-image-minimal')
39
40 testexport_dir = get_bb_var('TEST_EXPORT_DIR', 'core-image-minimal')
41
42 # Verify if TEST_EXPORT_DIR was created
43 isdir = os.path.isdir(testexport_dir)
44 self.assertEqual(True, isdir, 'Failed to create testexport dir: %s' % testexport_dir)
45
46 with runqemu('core-image-minimal') as qemu:
47 # Attempt to run runexported.py to perform ping test
48 test_path = os.path.join(testexport_dir, "oe-test")
49 data_file = os.path.join(testexport_dir, 'data', 'testdata.json')
50 manifest = os.path.join(testexport_dir, 'data', 'manifest')
51 cmd = ("%s runtime --test-data-file %s --packages-manifest %s "
52 "--target-ip %s --server-ip %s --quiet"
53 % (test_path, data_file, manifest, qemu.ip, qemu.server_ip))
54 result = runCmd(cmd)
55 # Verify ping test was succesful
56 self.assertEqual(0, result.status, 'oe-test runtime returned a non 0 status')
57
58 @OETestID(1641)
59 def test_testexport_sdk(self):
60 """
61 Summary: Check sdk functionality for testexport.
62 Expected: 1. testexport directory must be created.
63 2. SDK tarball must exists.
64 3. Uncompressing of tarball must succeed.
65 4. Check if the SDK directory is added to PATH.
66 5. Run tar from the SDK directory.
67 Product: oe-core
68 Author: Mariano Lopez <mariano.lopez@intel.com>
69 """
70
71 features = 'INHERIT += "testexport"\n'
72 # These aren't the actual IP addresses but testexport class needs something defined
73 features += 'TEST_SERVER_IP = "192.168.7.1"\n'
74 features += 'TEST_TARGET_IP = "192.168.7.1"\n'
75 features += 'TEST_SUITES = "ping"\n'
76 features += 'TEST_EXPORT_SDK_ENABLED = "1"\n'
77 features += 'TEST_EXPORT_SDK_PACKAGES = "nativesdk-tar"\n'
78 self.write_config(features)
79
80 # Build tesexport for core-image-minimal
81 bitbake('core-image-minimal')
82 bitbake('-c testexport core-image-minimal')
83
84 needed_vars = ['TEST_EXPORT_DIR', 'TEST_EXPORT_SDK_DIR', 'TEST_EXPORT_SDK_NAME']
85 bb_vars = get_bb_vars(needed_vars, 'core-image-minimal')
86 testexport_dir = bb_vars['TEST_EXPORT_DIR']
87 sdk_dir = bb_vars['TEST_EXPORT_SDK_DIR']
88 sdk_name = bb_vars['TEST_EXPORT_SDK_NAME']
89
90 # Check for SDK
91 tarball_name = "%s.sh" % sdk_name
92 tarball_path = os.path.join(testexport_dir, sdk_dir, tarball_name)
93 msg = "Couldn't find SDK tarball: %s" % tarball_path
94 self.assertEqual(os.path.isfile(tarball_path), True, msg)
95
96 # Extract SDK and run tar from SDK
97 result = runCmd("%s -y -d /tmp/sdk" % tarball_path)
98 self.assertEqual(0, result.status, "Couldn't extract SDK")
99
100 env_script = result.output.split()[-1]
101 result = runCmd(". %s; which tar" % env_script, shell=True)
102 self.assertEqual(0, result.status, "Couldn't setup SDK environment")
103 is_sdk_tar = True if "/tmp/sdk" in result.output else False
104 self.assertTrue(is_sdk_tar, "Couldn't setup SDK environment")
105
106 tar_sdk = result.output
107 result = runCmd("%s --version" % tar_sdk)
108 self.assertEqual(0, result.status, "Couldn't run tar from SDK")
109
110
111class TestImage(OESelftestTestCase):
112
113 @OETestID(1644)
114 def test_testimage_install(self):
115 """
116 Summary: Check install packages functionality for testimage/testexport.
117 Expected: 1. Import tests from a directory other than meta.
118 2. Check install/uninstall of socat.
119 Product: oe-core
120 Author: Mariano Lopez <mariano.lopez@intel.com>
121 """
122 if get_bb_var('DISTRO') == 'poky-tiny':
123 self.skipTest('core-image-full-cmdline not buildable for poky-tiny')
124
125 features = 'INHERIT += "testimage"\n'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800126 features += 'IMAGE_INSTALL_append = " libssl"\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500127 features += 'TEST_SUITES = "ping ssh selftest"\n'
128 self.write_config(features)
129
130 # Build core-image-sato and testimage
131 bitbake('core-image-full-cmdline socat')
132 bitbake('-c testimage core-image-full-cmdline')
133
134 @OETestID(1883)
135 def test_testimage_dnf(self):
136 """
137 Summary: Check package feeds functionality for dnf
138 Expected: 1. Check that remote package feeds can be accessed
139 Product: oe-core
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800140 Author: Alexander Kanavin <alex.kanavin@gmail.com>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500141 """
142 if get_bb_var('DISTRO') == 'poky-tiny':
143 self.skipTest('core-image-full-cmdline not buildable for poky-tiny')
144
145 features = 'INHERIT += "testimage"\n'
146 features += 'TEST_SUITES = "ping ssh dnf_runtime dnf.DnfBasicTest.test_dnf_help"\n'
147 # We don't yet know what the server ip and port will be - they will be patched
148 # in at the start of the on-image test
149 features += 'PACKAGE_FEED_URIS = "http://bogus_ip:bogus_port"\n'
150 features += 'EXTRA_IMAGE_FEATURES += "package-management"\n'
151 features += 'PACKAGE_CLASSES = "package_rpm"\n'
152
Brad Bishop6f8dcde2018-10-16 10:47:12 +0800153 bitbake('gnupg-native -c addto_recipe_sysroot')
154
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500155 # Enable package feed signing
156 self.gpg_home = tempfile.mkdtemp(prefix="oeqa-feed-sign-")
157 signing_key_dir = os.path.join(self.testlayer_path, 'files', 'signing')
Brad Bishop6f8dcde2018-10-16 10:47:12 +0800158 runCmd('gpg --batch --homedir %s --import %s' % (self.gpg_home, os.path.join(signing_key_dir, 'key.secret')), native_sysroot=get_bb_var("RECIPE_SYSROOT_NATIVE", "gnupg-native"))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500159 features += 'INHERIT += "sign_package_feed"\n'
160 features += 'PACKAGE_FEED_GPG_NAME = "testuser"\n'
161 features += 'PACKAGE_FEED_GPG_PASSPHRASE_FILE = "%s"\n' % os.path.join(signing_key_dir, 'key.passphrase')
162 features += 'GPG_PATH = "%s"\n' % self.gpg_home
163 self.write_config(features)
164
165 # Build core-image-sato and testimage
166 bitbake('core-image-full-cmdline socat')
167 bitbake('-c testimage core-image-full-cmdline')
168
169 # remove the oeqa-feed-sign temporal directory
170 shutil.rmtree(self.gpg_home, ignore_errors=True)
171
Brad Bishop19323692019-04-05 15:28:33 -0400172 @OETestID(1883)
173 def test_testimage_virgl_gtk(self):
174 """
175 Summary: Check host-assisted accelerate OpenGL functionality in qemu with gtk frontend
176 Expected: 1. Check that virgl kernel driver is loaded and 3d acceleration is enabled
177 2. Check that kmscube demo runs without crashing.
178 Product: oe-core
179 Author: Alexander Kanavin <alex.kanavin@gmail.com>
180 """
181 if "DISPLAY" not in os.environ:
182 self.skipTest("virgl gtk test must be run inside a X session")
183 distro = oe.lsb.distro_identifier()
184 if distro and distro == 'debian-8':
185 self.skipTest('virgl isn\'t working with Debian 8')
186
187 qemu_packageconfig = get_bb_var('PACKAGECONFIG', 'qemu-system-native')
188 features = 'INHERIT += "testimage"\n'
189 if 'gtk+' not in qemu_packageconfig:
190 features += 'PACKAGECONFIG_append_pn-qemu-system-native = " gtk+"\n'
191 if 'virglrenderer' not in qemu_packageconfig:
192 features += 'PACKAGECONFIG_append_pn-qemu-system-native = " virglrenderer"\n'
193 if 'glx' not in qemu_packageconfig:
194 features += 'PACKAGECONFIG_append_pn-qemu-system-native = " glx"\n'
195 features += 'TEST_SUITES = "ping ssh virgl"\n'
196 features += 'IMAGE_FEATURES_append = " ssh-server-dropbear"\n'
197 features += 'IMAGE_INSTALL_append = " kmscube"\n'
198 features += 'TEST_RUNQEMUPARAMS = "gtk-gl"\n'
199 self.write_config(features)
200 bitbake('core-image-minimal')
201 bitbake('-c testimage core-image-minimal')
202
203 @OETestID(1883)
204 def test_testimage_virgl_headless(self):
205 """
206 Summary: Check host-assisted accelerate OpenGL functionality in qemu with egl-headless frontend
207 Expected: 1. Check that virgl kernel driver is loaded and 3d acceleration is enabled
208 2. Check that kmscube demo runs without crashing.
209 Product: oe-core
210 Author: Alexander Kanavin <alex.kanavin@gmail.com>
211 """
212 import subprocess, os
213 try:
214 content = os.listdir("/dev/dri")
215 if len([i for i in content if i.startswith('render')]) == 0:
216 self.skipTest("No render nodes found in /dev/dri: %s" %(content))
217 except FileNotFoundError:
218 self.skipTest("/dev/dri directory does not exist; no render nodes available on this machine.")
219 try:
220 dripath = subprocess.check_output("pkg-config --variable=dridriverdir dri", shell=True)
221 except subprocess.CalledProcessError as e:
222 self.skipTest("Could not determine the path to dri drivers on the host via pkg-config.\nPlease install Mesa development files (particularly, dri.pc) on the host machine.")
223 qemu_packageconfig = get_bb_var('PACKAGECONFIG', 'qemu-system-native')
224 features = 'INHERIT += "testimage"\n'
225 if 'virglrenderer' not in qemu_packageconfig:
226 features += 'PACKAGECONFIG_append_pn-qemu-system-native = " virglrenderer"\n'
227 if 'glx' not in qemu_packageconfig:
228 features += 'PACKAGECONFIG_append_pn-qemu-system-native = " glx"\n'
229 features += 'TEST_SUITES = "ping ssh virgl"\n'
230 features += 'IMAGE_FEATURES_append = " ssh-server-dropbear"\n'
231 features += 'IMAGE_INSTALL_append = " kmscube"\n'
232 features += 'TEST_RUNQEMUPARAMS = "egl-headless"\n'
233 self.write_config(features)
234 bitbake('core-image-minimal')
235 bitbake('-c testimage core-image-minimal')
236
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500237class Postinst(OESelftestTestCase):
238 @OETestID(1540)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500239 @OETestID(1545)
240 def test_postinst_rootfs_and_boot(self):
241 """
242 Summary: The purpose of this test case is to verify Post-installation
243 scripts are called when rootfs is created and also test
244 that script can be delayed to run at first boot.
245 Dependencies: NA
246 Steps: 1. Add proper configuration to local.conf file
247 2. Build a "core-image-minimal" image
248 3. Verify that file created by postinst_rootfs recipe is
249 present on rootfs dir.
250 4. Boot the image created on qemu and verify that the file
251 created by postinst_boot recipe is present on image.
252 Expected: The files are successfully created during rootfs and boot
253 time for 3 different package managers: rpm,ipk,deb and
254 for initialization managers: sysvinit and systemd.
255
256 """
Brad Bishop316dfdd2018-06-25 12:45:53 -0400257
258 import oe.path
259
260 vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
261 rootfs = vars["IMAGE_ROOTFS"]
262 self.assertIsNotNone(rootfs)
263 sysconfdir = vars["sysconfdir"]
264 self.assertIsNotNone(sysconfdir)
265 # Need to use oe.path here as sysconfdir starts with /
266 hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
267 targettestdir = os.path.join(sysconfdir, "postinst-test")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500268
269 for init_manager in ("sysvinit", "systemd"):
270 for classes in ("package_rpm", "package_deb", "package_ipk"):
271 with self.subTest(init_manager=init_manager, package_class=classes):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400272 features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-delayed-b"\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500273 features += 'IMAGE_FEATURES += "package-management empty-root-password"\n'
274 features += 'PACKAGE_CLASSES = "%s"\n' % classes
275 if init_manager == "systemd":
276 features += 'DISTRO_FEATURES_append = " systemd"\n'
277 features += 'VIRTUAL-RUNTIME_init_manager = "systemd"\n'
278 features += 'DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"\n'
279 features += 'VIRTUAL-RUNTIME_initscripts = ""\n'
280 self.write_config(features)
281
282 bitbake('core-image-minimal')
283
Brad Bishop316dfdd2018-06-25 12:45:53 -0400284 self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs")),
285 "rootfs state file was not created")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500286
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500287 with runqemu('core-image-minimal') as qemu:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400288 # Make the test echo a string and search for that as
289 # run_serial()'s status code is useless.'
290 for filename in ("rootfs", "delayed-a", "delayed-b"):
291 status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename))
292 self.assertEqual(output, "found", "%s was not present on boot" % filename)
293
294
295
296 def test_failing_postinst(self):
297 """
298 Summary: The purpose of this test case is to verify that post-installation
299 scripts that contain errors are properly reported.
300 Expected: The scriptlet failure is properly reported.
301 The file that is created after the error in the scriptlet is not present.
302 Product: oe-core
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800303 Author: Alexander Kanavin <alex.kanavin@gmail.com>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400304 """
305
306 import oe.path
307
308 vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
309 rootfs = vars["IMAGE_ROOTFS"]
310 self.assertIsNotNone(rootfs)
311 sysconfdir = vars["sysconfdir"]
312 self.assertIsNotNone(sysconfdir)
313 # Need to use oe.path here as sysconfdir starts with /
314 hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
315
316 for classes in ("package_rpm", "package_deb", "package_ipk"):
317 with self.subTest(package_class=classes):
318 features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-rootfs-failing"\n'
319 features += 'PACKAGE_CLASSES = "%s"\n' % classes
320 self.write_config(features)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800321 bb_result = bitbake('core-image-minimal', ignore_status=True)
322 self.assertGreaterEqual(bb_result.output.find("Postinstall scriptlets of ['postinst-rootfs-failing'] have failed."), 0,
Brad Bishop316dfdd2018-06-25 12:45:53 -0400323 "Warning about a failed scriptlet not found in bitbake output: %s" %(bb_result.output))
324
325 self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs-before-failure")),
326 "rootfs-before-failure file was not created")
327 self.assertFalse(os.path.isfile(os.path.join(hosttestdir, "rootfs-after-failure")),
328 "rootfs-after-failure file was created")
329