blob: af38150613b616166ac51cfd55f75c321c0769ac [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:
Patrick Williams7784c422022-11-17 07:29:11 -0600139 features += 'IMAGE_FSTYPES += "ext4.%s"\n' % itype
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500140 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:
Patrick Williams7784c422022-11-17 07:29:11 -0600148 image_path = os.path.join(deploy_dir_image, "%s.ext4.%s" %
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500149 (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
Patrick Williams7784c422022-11-17 07:29:11 -0600209 config = """
210IMAGE_FSTYPES += "%s"
211WKS_FILE = "wictestdisk.wks"
212MKUBIFS_ARGS ?= "-m 2048 -e 129024 -c 2047"
213UBINIZE_ARGS ?= "-m 2048 -p 128KiB -s 512"
214""" % ' '.join(img_types)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500215 self.write_config(config)
216
217 bitbake(image_name)
218
219 deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
220 link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
221 for itype in img_types:
222 image_path = os.path.join(deploy_dir_image, "%s.%s" % (link_name, itype))
223 # check if result image is in deploy directory
224 self.assertTrue(os.path.exists(image_path),
225 "%s image %s doesn't exist" % (itype, image_path))
226
227 def test_useradd_static(self):
228 config = """
229USERADDEXTENSION = "useradd-staticids"
230USERADD_ERROR_DYNAMIC = "skip"
231USERADD_UID_TABLES += "files/static-passwd"
232USERADD_GID_TABLES += "files/static-group"
233"""
234 self.write_config(config)
235 bitbake("core-image-base")
Brad Bishop19323692019-04-05 15:28:33 -0400236
237 def test_no_busybox_base_utils(self):
238 config = """
Andrew Geisslerc926e172021-05-07 16:11:35 -0500239# Enable wayland
Andrew Geissler595f6302022-01-24 19:11:47 +0000240DISTRO_FEATURES:append = " pam opengl wayland"
Brad Bishop19323692019-04-05 15:28:33 -0400241
242# Switch to systemd
Andrew Geisslerd5838332022-05-27 11:33:10 -0500243DISTRO_FEATURES:append = " systemd"
Brad Bishop19323692019-04-05 15:28:33 -0400244VIRTUAL-RUNTIME_init_manager = "systemd"
245VIRTUAL-RUNTIME_initscripts = ""
246VIRTUAL-RUNTIME_syslog = ""
247VIRTUAL-RUNTIME_login_manager = "shadow-base"
248DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
249
250# Replace busybox
251PREFERRED_PROVIDER_virtual/base-utils = "packagegroup-core-base-utils"
252VIRTUAL-RUNTIME_base-utils = "packagegroup-core-base-utils"
253VIRTUAL-RUNTIME_base-utils-hwclock = "util-linux-hwclock"
254VIRTUAL-RUNTIME_base-utils-syslog = ""
255
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000256# Skip busybox
257SKIP_RECIPE[busybox] = "Don't build this"
Brad Bishop19323692019-04-05 15:28:33 -0400258"""
259 self.write_config(config)
260
Andrew Geisslerc926e172021-05-07 16:11:35 -0500261 bitbake("--graphviz core-image-weston")
Andrew Geisslerc182c622020-05-15 14:13:32 -0500262
263 def test_image_gen_debugfs(self):
264 """
265 Summary: Check debugfs generation
266 Expected: 1. core-image-minimal can be build with IMAGE_GEN_DEBUGFS variable set
267 2. debug filesystem is created when variable set
268 3. debug symbols available
269 Product: oe-core
270 Author: Humberto Ibarra <humberto.ibarra.lopez@intel.com>
271 Yeoh Ee Peng <ee.peng.yeoh@intel.com>
272 """
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500273
Andrew Geisslerc182c622020-05-15 14:13:32 -0500274 image_name = 'core-image-minimal'
275 features = 'IMAGE_GEN_DEBUGFS = "1"\n'
276 features += 'IMAGE_FSTYPES_DEBUGFS = "tar.bz2"\n'
Andrew Geisslerc182c622020-05-15 14:13:32 -0500277 self.write_config(features)
278
279 bitbake(image_name)
280 deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
281 dbg_tar_file = os.path.join(deploy_dir_image, "*-dbg.rootfs.tar.bz2")
282 debug_files = glob.glob(dbg_tar_file)
283 self.assertNotEqual(len(debug_files), 0, 'debug filesystem not generated at %s' % dbg_tar_file)
284 result = runCmd('cd %s; tar xvf %s' % (deploy_dir_image, dbg_tar_file))
285 self.assertEqual(result.status, 0, msg='Failed to extract %s: %s' % (dbg_tar_file, result.output))
286 result = runCmd('find %s -name %s' % (deploy_dir_image, "udevadm"))
287 self.assertTrue("udevadm" in result.output, msg='Failed to find udevadm: %s' % result.output)
288 dbg_symbols_targets = result.output.splitlines()
289 self.assertTrue(dbg_symbols_targets, msg='Failed to split udevadm: %s' % dbg_symbols_targets)
290 for t in dbg_symbols_targets:
291 result = runCmd('objdump --syms %s | grep debug' % t)
292 self.assertTrue("debug" in result.output, msg='Failed to find debug symbol: %s' % result.output)
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500293
294 def test_empty_image(self):
295 """Test creation of image with no packages"""
296 bitbake('test-empty-image')
297 res_dir = get_bb_var('DEPLOY_DIR_IMAGE')
298 images = os.path.join(res_dir, "test-empty-image-*.manifest")
299 result = glob.glob(images)
300 with open(result[1],"r") as f:
301 self.assertEqual(len(f.read().strip()),0)