blob: 0292c882f25e09b2f1dab02f289fe958949f5af0 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: MIT
5#
6
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007from oeqa.selftest.case import OESelftestTestCase
Patrick Williams45852732022-04-02 08:58:32 -05008from oeqa.core.decorator import OETestTag
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05009from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars, runqemu
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010from oeqa.utils.sshcontrol import SSHControl
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011import glob
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012import os
13import json
14
15class ImageFeatures(OESelftestTestCase):
16
17 test_user = 'tester'
18 root_user = 'root'
19
Patrick Williams45852732022-04-02 08:58:32 -050020 @OETestTag("runqemu")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050021 def test_non_root_user_can_connect_via_ssh_without_password(self):
22 """
23 Summary: Check if non root user can connect via ssh without password
24 Expected: 1. Connection to the image via ssh using root user without providing a password should be allowed.
25 2. Connection to the image via ssh using tester user without providing a password should be allowed.
26 Product: oe-core
27 Author: Ionut Chisanovici <ionutx.chisanovici@intel.com>
28 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
29 """
30
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080031 features = 'EXTRA_IMAGE_FEATURES = "ssh-server-openssh empty-root-password allow-empty-password allow-root-login"\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050032 features += 'INHERIT += "extrausers"\n'
33 features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(self.test_user, self.test_user)
34 self.write_config(features)
35
36 # Build a core-image-minimal
37 bitbake('core-image-minimal')
38
39 with runqemu("core-image-minimal") as qemu:
40 # Attempt to ssh with each user into qemu with empty password
41 for user in [self.root_user, self.test_user]:
42 ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user=user)
43 status, output = ssh.run("true")
44 self.assertEqual(status, 0, 'ssh to user %s failed with %s' % (user, output))
45
Patrick Williams45852732022-04-02 08:58:32 -050046 @OETestTag("runqemu")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050047 def test_all_users_can_connect_via_ssh_without_password(self):
48 """
49 Summary: Check if all users can connect via ssh without password
50 Expected: 1. Connection to the image via ssh using root user without providing a password should NOT be allowed.
51 2. Connection to the image via ssh using tester user without providing a password should be allowed.
52 Product: oe-core
53 Author: Ionut Chisanovici <ionutx.chisanovici@intel.com>
54 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
55 """
56
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080057 features = 'EXTRA_IMAGE_FEATURES = "ssh-server-openssh allow-empty-password allow-root-login"\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050058 features += 'INHERIT += "extrausers"\n'
59 features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(self.test_user, self.test_user)
60 self.write_config(features)
61
62 # Build a core-image-minimal
63 bitbake('core-image-minimal')
64
65 with runqemu("core-image-minimal") as qemu:
66 # Attempt to ssh with each user into qemu with empty password
67 for user in [self.root_user, self.test_user]:
68 ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user=user)
69 status, output = ssh.run("true")
70 if user == 'root':
71 self.assertNotEqual(status, 0, 'ssh to user root was allowed when it should not have been')
72 else:
73 self.assertEqual(status, 0, 'ssh to user tester failed with %s' % output)
74
75
Brad Bishopd7bf8c12018-02-25 22:55:05 -050076 def test_wayland_support_in_image(self):
77 """
78 Summary: Check Wayland support in image
79 Expected: 1. Wayland image can be build
80 2. Wayland feature can be installed
81 Product: oe-core
82 Author: Ionut Chisanovici <ionutx.chisanovici@intel.com>
83 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
84 """
85
86 distro_features = get_bb_var('DISTRO_FEATURES')
87 if not ('opengl' in distro_features and 'wayland' in distro_features):
88 self.skipTest('neither opengl nor wayland present on DISTRO_FEATURES so core-image-weston cannot be built')
89
90 # Build a core-image-weston
91 bitbake('core-image-weston')
92
Brad Bishopd7bf8c12018-02-25 22:55:05 -050093 def test_bmap(self):
94 """
95 Summary: Check bmap support
96 Expected: 1. core-image-minimal can be build with bmap support
97 2. core-image-minimal is sparse
98 Product: oe-core
99 Author: Ed Bartosh <ed.bartosh@linux.intel.com>
100 """
101
102 features = 'IMAGE_FSTYPES += " ext4 ext4.bmap ext4.bmap.gz"'
103 self.write_config(features)
104
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500105 image = 'core-image-minimal'
106 bitbake(image)
107 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], image)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500108
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500109 image_path = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], "%s.ext4" % bb_vars['IMAGE_LINK_NAME'])
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500110 bmap_path = "%s.bmap" % image_path
111 gzip_path = "%s.gz" % bmap_path
112
113 # check if result image, bmap and bmap.gz files are in deploy directory
114 self.assertTrue(os.path.exists(image_path))
115 self.assertTrue(os.path.exists(bmap_path))
116 self.assertTrue(os.path.exists(gzip_path))
117
118 # check if result image is sparse
119 image_stat = os.stat(image_path)
Brad Bishop64c979e2019-11-04 13:55:29 -0500120 self.assertGreater(image_stat.st_size, image_stat.st_blocks * 512)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500121
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500122 # check if the resulting gzip is valid, --force is needed in case gzip_path is a symlink
123 self.assertTrue(runCmd('gzip --test --force %s' % gzip_path))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500124
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500125 def test_hypervisor_fmts(self):
126 """
127 Summary: Check various hypervisor formats
128 Expected: 1. core-image-minimal can be built with vmdk, vdi and
129 qcow2 support.
130 2. qemu-img says each image has the expected format
131 Product: oe-core
132 Author: Tom Rini <trini@konsulko.com>
133 """
134
135 img_types = [ 'vmdk', 'vdi', 'qcow2' ]
136 features = ""
137 for itype in img_types:
Patrick Williams7784c422022-11-17 07:29:11 -0600138 features += 'IMAGE_FSTYPES += "ext4.%s"\n' % itype
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500139 self.write_config(features)
140
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500141 image = 'core-image-minimal'
142 bitbake(image)
143 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], image)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500144
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500145 for itype in img_types:
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500146 image_path = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], "%s.ext4.%s" %
147 (bb_vars['IMAGE_LINK_NAME'], itype))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500148
149 # check if result image file is in deploy directory
150 self.assertTrue(os.path.exists(image_path))
151
152 # check if result image is vmdk
153 sysroot = get_bb_var('STAGING_DIR_NATIVE', 'core-image-minimal')
154 result = runCmd('qemu-img info --output json %s' % image_path,
155 native_sysroot=sysroot)
Brad Bishopf3f93bb2019-10-16 14:33:32 -0400156 try:
157 data = json.loads(result.output)
158 self.assertEqual(data.get('format'), itype,
159 msg="Unexpected format in '%s'" % (result.output))
160 except json.decoder.JSONDecodeError:
161 self.fail("Could not parse '%ss'" % result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500162
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500163 def test_long_chain_conversion(self):
164 """
165 Summary: Check for chaining many CONVERSION_CMDs together
166 Expected: 1. core-image-minimal can be built with
Andrew Geissler78b72792022-06-14 06:47:25 -0500167 ext4.bmap.gz.bz2.zst.xz.u-boot and also create a
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500168 sha256sum
169 2. The above image has a valid sha256sum
170 Product: oe-core
171 Author: Tom Rini <trini@konsulko.com>
172 """
173
Andrew Geissler78b72792022-06-14 06:47:25 -0500174 conv = "ext4.bmap.gz.bz2.zst.xz.u-boot"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500175 features = 'IMAGE_FSTYPES += "%s %s.sha256sum"' % (conv, conv)
176 self.write_config(features)
177
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500178 image = 'core-image-minimal'
179 bitbake(image)
180 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], image)
181 image_path = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], "%s.%s" %
182 (bb_vars['IMAGE_LINK_NAME'], conv))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500183
184 # check if resulting image is in the deploy directory
185 self.assertTrue(os.path.exists(image_path))
186 self.assertTrue(os.path.exists(image_path + ".sha256sum"))
187
188 # check if the resulting sha256sum agrees
189 self.assertTrue(runCmd('cd %s;sha256sum -c %s.%s.sha256sum' %
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500190 (bb_vars['DEPLOY_DIR_IMAGE'], bb_vars['IMAGE_LINK_NAME'], conv)))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500191
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500192 def test_image_fstypes(self):
193 """
194 Summary: Check if image of supported image fstypes can be built
195 Expected: core-image-minimal can be built for various image types
196 Product: oe-core
197 Author: Ed Bartosh <ed.bartosh@linux.intel.com>
198 """
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500199 image = 'core-image-minimal'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500200
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500201 all_image_types = set(get_bb_var("IMAGE_TYPES", image).split())
202 skip_image_types = set(('container', 'elf', 'f2fs', 'tar.zst', 'wic.zst', 'squashfs-lzo'))
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000203 img_types = all_image_types - skip_image_types
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500204
Patrick Williams7784c422022-11-17 07:29:11 -0600205 config = """
206IMAGE_FSTYPES += "%s"
207WKS_FILE = "wictestdisk.wks"
208MKUBIFS_ARGS ?= "-m 2048 -e 129024 -c 2047"
209UBINIZE_ARGS ?= "-m 2048 -p 128KiB -s 512"
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500210MULTIUBI_BUILD += "mtd_2_128"
211MKUBIFS_ARGS_mtd_2_128 ?= "-m 2048 -e 129024 -c 2047"
212UBINIZE_ARGS_mtd_2_128 ?= "-m 2048 -p 128KiB -s 512"
213MULTIUBI_BUILD += "mtd_4_256"
214MKUBIFS_ARGS_mtd_4_256 ?= "-m 4096 -e 253952 -c 4096"
215UBINIZE_ARGS_mtd_4_256 ?= "-m 4096 -p 256KiB"
Patrick Williams7784c422022-11-17 07:29:11 -0600216""" % ' '.join(img_types)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500217 self.write_config(config)
218
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500219 bitbake(image)
220 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME', 'MULTIUBI_BUILD'], image)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500221
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500222 for itype in img_types:
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500223 if itype == 'multiubi':
224 # For multiubi build we need to manage MULTIUBI_BUILD entry to append
225 # specific name to IMAGE_LINK_NAME
226 for vname in bb_vars['MULTIUBI_BUILD'].split():
227 image_path = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], "%s_%s.ubifs" % (bb_vars['IMAGE_LINK_NAME'], vname))
228 # check if result image is in deploy directory
229 self.assertTrue(os.path.exists(image_path),
230 "%s image %s doesn't exist" % (itype, image_path))
231 else:
Patrick Williams8e7b46e2023-05-01 14:19:06 -0500232 image_path = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], "%s.%s" % (bb_vars['IMAGE_LINK_NAME'], itype))
233 # check if result image is in deploy directory
234 self.assertTrue(os.path.exists(image_path),
235 "%s image %s doesn't exist" % (itype, image_path))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500236
237 def test_useradd_static(self):
238 config = """
239USERADDEXTENSION = "useradd-staticids"
240USERADD_ERROR_DYNAMIC = "skip"
241USERADD_UID_TABLES += "files/static-passwd"
242USERADD_GID_TABLES += "files/static-group"
243"""
244 self.write_config(config)
245 bitbake("core-image-base")
Brad Bishop19323692019-04-05 15:28:33 -0400246
247 def test_no_busybox_base_utils(self):
248 config = """
Andrew Geisslerc926e172021-05-07 16:11:35 -0500249# Enable wayland
Andrew Geissler595f6302022-01-24 19:11:47 +0000250DISTRO_FEATURES:append = " pam opengl wayland"
Brad Bishop19323692019-04-05 15:28:33 -0400251
252# Switch to systemd
Andrew Geisslerd5838332022-05-27 11:33:10 -0500253DISTRO_FEATURES:append = " systemd"
Brad Bishop19323692019-04-05 15:28:33 -0400254VIRTUAL-RUNTIME_init_manager = "systemd"
255VIRTUAL-RUNTIME_initscripts = ""
256VIRTUAL-RUNTIME_syslog = ""
257VIRTUAL-RUNTIME_login_manager = "shadow-base"
258DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
259
260# Replace busybox
261PREFERRED_PROVIDER_virtual/base-utils = "packagegroup-core-base-utils"
262VIRTUAL-RUNTIME_base-utils = "packagegroup-core-base-utils"
263VIRTUAL-RUNTIME_base-utils-hwclock = "util-linux-hwclock"
264VIRTUAL-RUNTIME_base-utils-syslog = ""
265
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000266# Skip busybox
267SKIP_RECIPE[busybox] = "Don't build this"
Brad Bishop19323692019-04-05 15:28:33 -0400268"""
269 self.write_config(config)
270
Andrew Geisslerc926e172021-05-07 16:11:35 -0500271 bitbake("--graphviz core-image-weston")
Andrew Geisslerc182c622020-05-15 14:13:32 -0500272
273 def test_image_gen_debugfs(self):
274 """
275 Summary: Check debugfs generation
276 Expected: 1. core-image-minimal can be build with IMAGE_GEN_DEBUGFS variable set
277 2. debug filesystem is created when variable set
278 3. debug symbols available
279 Product: oe-core
280 Author: Humberto Ibarra <humberto.ibarra.lopez@intel.com>
281 Yeoh Ee Peng <ee.peng.yeoh@intel.com>
282 """
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500283
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500284 image = 'core-image-minimal'
285 image_fstypes_debugfs = 'tar.bz2'
Andrew Geisslerc182c622020-05-15 14:13:32 -0500286 features = 'IMAGE_GEN_DEBUGFS = "1"\n'
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500287 features += 'IMAGE_FSTYPES_DEBUGFS = "%s"\n' % image_fstypes_debugfs
Andrew Geisslerc182c622020-05-15 14:13:32 -0500288 self.write_config(features)
289
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500290 bitbake(image)
291 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], image)
292
293 dbg_tar_file = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], "%s-dbg.%s" % (bb_vars['IMAGE_LINK_NAME'], image_fstypes_debugfs))
294 self.assertTrue(os.path.exists(dbg_tar_file), 'debug filesystem not generated at %s' % dbg_tar_file)
295 result = runCmd('cd %s; tar xvf %s' % (bb_vars['DEPLOY_DIR_IMAGE'], dbg_tar_file))
Andrew Geisslerc182c622020-05-15 14:13:32 -0500296 self.assertEqual(result.status, 0, msg='Failed to extract %s: %s' % (dbg_tar_file, result.output))
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500297 result = runCmd('find %s -name %s' % (bb_vars['DEPLOY_DIR_IMAGE'], "udevadm"))
Andrew Geisslerc182c622020-05-15 14:13:32 -0500298 self.assertTrue("udevadm" in result.output, msg='Failed to find udevadm: %s' % result.output)
299 dbg_symbols_targets = result.output.splitlines()
300 self.assertTrue(dbg_symbols_targets, msg='Failed to split udevadm: %s' % dbg_symbols_targets)
301 for t in dbg_symbols_targets:
302 result = runCmd('objdump --syms %s | grep debug' % t)
303 self.assertTrue("debug" in result.output, msg='Failed to find debug symbol: %s' % result.output)
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500304
305 def test_empty_image(self):
306 """Test creation of image with no packages"""
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500307 image = 'test-empty-image'
308 bitbake(image)
309 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], image)
310 manifest = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], "%s.manifest" % bb_vars['IMAGE_LINK_NAME'])
311 self.assertTrue(os.path.exists(manifest))
312
313 with open(manifest, "r") as f:
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500314 self.assertEqual(len(f.read().strip()),0)
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500315
316 def test_mandb(self):
317 """
318 Test that an image containing manpages has working man and apropos commands.
319 """
320 config = """
321DISTRO_FEATURES:append = " api-documentation"
322CORE_IMAGE_EXTRA_INSTALL = "man-pages kmod-doc"
323"""
324 self.write_config(config)
325 bitbake("core-image-minimal")
326
327 with runqemu('core-image-minimal', ssh=False, runqemuparams='nographic') as qemu:
328 # This manpage is provided by man-pages
329 status, output = qemu.run_serial("apropos 8859")
330 self.assertEqual(status, 1, 'Failed to run apropos: %s' % (output))
331 self.assertIn("iso_8859_15", output)
332
333 # This manpage is provided by kmod
334 status, output = qemu.run_serial("man --pager=cat modprobe")
335 self.assertEqual(status, 1, 'Failed to run man: %s' % (output))
336 self.assertIn("force-modversion", output)