blob: d3fd52851c016f9d5a5b9a4fed9c9e78892808f8 [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
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009from oeqa.utils.commands import runCmd, bitbake, get_bb_var, 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
105 image_name = 'core-image-minimal'
106 bitbake(image_name)
107
108 deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
109 link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
110 image_path = os.path.join(deploy_dir_image, "%s.ext4" % link_name)
111 bmap_path = "%s.bmap" % image_path
112 gzip_path = "%s.gz" % bmap_path
113
114 # check if result image, bmap and bmap.gz files are in deploy directory
115 self.assertTrue(os.path.exists(image_path))
116 self.assertTrue(os.path.exists(bmap_path))
117 self.assertTrue(os.path.exists(gzip_path))
118
119 # check if result image is sparse
120 image_stat = os.stat(image_path)
Brad Bishop64c979e2019-11-04 13:55:29 -0500121 self.assertGreater(image_stat.st_size, image_stat.st_blocks * 512)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500122
123 # check if the resulting gzip is valid
124 self.assertTrue(runCmd('gzip -t %s' % gzip_path))
125
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500126 def test_hypervisor_fmts(self):
127 """
128 Summary: Check various hypervisor formats
129 Expected: 1. core-image-minimal can be built with vmdk, vdi and
130 qcow2 support.
131 2. qemu-img says each image has the expected format
132 Product: oe-core
133 Author: Tom Rini <trini@konsulko.com>
134 """
135
136 img_types = [ 'vmdk', 'vdi', 'qcow2' ]
137 features = ""
138 for itype in img_types:
139 features += 'IMAGE_FSTYPES += "wic.%s"\n' % itype
140 self.write_config(features)
141
142 image_name = 'core-image-minimal'
143 bitbake(image_name)
144
145 deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
146 link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
147 for itype in img_types:
148 image_path = os.path.join(deploy_dir_image, "%s.wic.%s" %
149 (link_name, itype))
150
151 # check if result image file is in deploy directory
152 self.assertTrue(os.path.exists(image_path))
153
154 # check if result image is vmdk
155 sysroot = get_bb_var('STAGING_DIR_NATIVE', 'core-image-minimal')
156 result = runCmd('qemu-img info --output json %s' % image_path,
157 native_sysroot=sysroot)
Brad Bishopf3f93bb2019-10-16 14:33:32 -0400158 try:
159 data = json.loads(result.output)
160 self.assertEqual(data.get('format'), itype,
161 msg="Unexpected format in '%s'" % (result.output))
162 except json.decoder.JSONDecodeError:
163 self.fail("Could not parse '%ss'" % result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500164
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500165 def test_long_chain_conversion(self):
166 """
167 Summary: Check for chaining many CONVERSION_CMDs together
168 Expected: 1. core-image-minimal can be built with
Andrew Geissler78b72792022-06-14 06:47:25 -0500169 ext4.bmap.gz.bz2.zst.xz.u-boot and also create a
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500170 sha256sum
171 2. The above image has a valid sha256sum
172 Product: oe-core
173 Author: Tom Rini <trini@konsulko.com>
174 """
175
Andrew Geissler78b72792022-06-14 06:47:25 -0500176 conv = "ext4.bmap.gz.bz2.zst.xz.u-boot"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500177 features = 'IMAGE_FSTYPES += "%s %s.sha256sum"' % (conv, conv)
178 self.write_config(features)
179
180 image_name = 'core-image-minimal'
181 bitbake(image_name)
182
183 deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
184 link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
185 image_path = os.path.join(deploy_dir_image, "%s.%s" %
186 (link_name, conv))
187
188 # check if resulting image is in the deploy directory
189 self.assertTrue(os.path.exists(image_path))
190 self.assertTrue(os.path.exists(image_path + ".sha256sum"))
191
192 # check if the resulting sha256sum agrees
193 self.assertTrue(runCmd('cd %s;sha256sum -c %s.%s.sha256sum' %
194 (deploy_dir_image, link_name, conv)))
195
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500196 def test_image_fstypes(self):
197 """
198 Summary: Check if image of supported image fstypes can be built
199 Expected: core-image-minimal can be built for various image types
200 Product: oe-core
201 Author: Ed Bartosh <ed.bartosh@linux.intel.com>
202 """
203 image_name = 'core-image-minimal'
204
Andrew Geissler82c905d2020-04-13 13:39:40 -0500205 all_image_types = set(get_bb_var("IMAGE_TYPES", image_name).split())
Andrew Geissler78b72792022-06-14 06:47:25 -0500206 skip_image_types = set(('container', 'elf', 'f2fs', 'multiubi', 'tar.zst', 'wic.zst', 'squashfs-lzo'))
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000207 img_types = all_image_types - skip_image_types
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500208
209 config = 'IMAGE_FSTYPES += "%s"\n'\
210 'MKUBIFS_ARGS ?= "-m 2048 -e 129024 -c 2047"\n'\
211 'UBINIZE_ARGS ?= "-m 2048 -p 128KiB -s 512"' % ' '.join(img_types)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500212 self.write_config(config)
213
214 bitbake(image_name)
215
216 deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
217 link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
218 for itype in img_types:
219 image_path = os.path.join(deploy_dir_image, "%s.%s" % (link_name, itype))
220 # check if result image is in deploy directory
221 self.assertTrue(os.path.exists(image_path),
222 "%s image %s doesn't exist" % (itype, image_path))
223
224 def test_useradd_static(self):
225 config = """
226USERADDEXTENSION = "useradd-staticids"
227USERADD_ERROR_DYNAMIC = "skip"
228USERADD_UID_TABLES += "files/static-passwd"
229USERADD_GID_TABLES += "files/static-group"
230"""
231 self.write_config(config)
232 bitbake("core-image-base")
Brad Bishop19323692019-04-05 15:28:33 -0400233
234 def test_no_busybox_base_utils(self):
235 config = """
Andrew Geisslerc926e172021-05-07 16:11:35 -0500236# Enable wayland
Andrew Geissler595f6302022-01-24 19:11:47 +0000237DISTRO_FEATURES:append = " pam opengl wayland"
Brad Bishop19323692019-04-05 15:28:33 -0400238
239# Switch to systemd
Andrew Geisslerd5838332022-05-27 11:33:10 -0500240DISTRO_FEATURES:append = " systemd"
Brad Bishop19323692019-04-05 15:28:33 -0400241VIRTUAL-RUNTIME_init_manager = "systemd"
242VIRTUAL-RUNTIME_initscripts = ""
243VIRTUAL-RUNTIME_syslog = ""
244VIRTUAL-RUNTIME_login_manager = "shadow-base"
245DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
246
247# Replace busybox
248PREFERRED_PROVIDER_virtual/base-utils = "packagegroup-core-base-utils"
249VIRTUAL-RUNTIME_base-utils = "packagegroup-core-base-utils"
250VIRTUAL-RUNTIME_base-utils-hwclock = "util-linux-hwclock"
251VIRTUAL-RUNTIME_base-utils-syslog = ""
252
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000253# Skip busybox
254SKIP_RECIPE[busybox] = "Don't build this"
Brad Bishop19323692019-04-05 15:28:33 -0400255"""
256 self.write_config(config)
257
Andrew Geisslerc926e172021-05-07 16:11:35 -0500258 bitbake("--graphviz core-image-weston")
Andrew Geisslerc182c622020-05-15 14:13:32 -0500259
260 def test_image_gen_debugfs(self):
261 """
262 Summary: Check debugfs generation
263 Expected: 1. core-image-minimal can be build with IMAGE_GEN_DEBUGFS variable set
264 2. debug filesystem is created when variable set
265 3. debug symbols available
266 Product: oe-core
267 Author: Humberto Ibarra <humberto.ibarra.lopez@intel.com>
268 Yeoh Ee Peng <ee.peng.yeoh@intel.com>
269 """
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500270
Andrew Geisslerc182c622020-05-15 14:13:32 -0500271 image_name = 'core-image-minimal'
272 features = 'IMAGE_GEN_DEBUGFS = "1"\n'
273 features += 'IMAGE_FSTYPES_DEBUGFS = "tar.bz2"\n'
274 features += 'MACHINE = "genericx86-64"\n'
275 self.write_config(features)
276
277 bitbake(image_name)
278 deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
279 dbg_tar_file = os.path.join(deploy_dir_image, "*-dbg.rootfs.tar.bz2")
280 debug_files = glob.glob(dbg_tar_file)
281 self.assertNotEqual(len(debug_files), 0, 'debug filesystem not generated at %s' % dbg_tar_file)
282 result = runCmd('cd %s; tar xvf %s' % (deploy_dir_image, dbg_tar_file))
283 self.assertEqual(result.status, 0, msg='Failed to extract %s: %s' % (dbg_tar_file, result.output))
284 result = runCmd('find %s -name %s' % (deploy_dir_image, "udevadm"))
285 self.assertTrue("udevadm" in result.output, msg='Failed to find udevadm: %s' % result.output)
286 dbg_symbols_targets = result.output.splitlines()
287 self.assertTrue(dbg_symbols_targets, msg='Failed to split udevadm: %s' % dbg_symbols_targets)
288 for t in dbg_symbols_targets:
289 result = runCmd('objdump --syms %s | grep debug' % t)
290 self.assertTrue("debug" in result.output, msg='Failed to find debug symbol: %s' % result.output)
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500291
292 def test_empty_image(self):
293 """Test creation of image with no packages"""
294 bitbake('test-empty-image')
295 res_dir = get_bb_var('DEPLOY_DIR_IMAGE')
296 images = os.path.join(res_dir, "test-empty-image-*.manifest")
297 result = glob.glob(images)
298 with open(result[1],"r") as f:
299 self.assertEqual(len(f.read().strip()),0)