Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
| 4 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5 | from oeqa.selftest.case import OESelftestTestCase |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame] | 6 | from oeqa.core.decorator import OETestTag |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 7 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 8 | from oeqa.utils.sshcontrol import SSHControl |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9 | import glob |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10 | import os |
| 11 | import json |
| 12 | |
| 13 | class ImageFeatures(OESelftestTestCase): |
| 14 | |
| 15 | test_user = 'tester' |
| 16 | root_user = 'root' |
| 17 | |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame] | 18 | @OETestTag("runqemu") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 19 | def test_non_root_user_can_connect_via_ssh_without_password(self): |
| 20 | """ |
| 21 | Summary: Check if non root user can connect via ssh without password |
| 22 | Expected: 1. Connection to the image via ssh using root user without providing a password should be allowed. |
| 23 | 2. Connection to the image via ssh using tester user without providing a password should be allowed. |
| 24 | Product: oe-core |
| 25 | Author: Ionut Chisanovici <ionutx.chisanovici@intel.com> |
| 26 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 27 | """ |
| 28 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 29 | features = 'EXTRA_IMAGE_FEATURES = "ssh-server-openssh empty-root-password allow-empty-password allow-root-login"\n' |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 30 | features += 'INHERIT += "extrausers"\n' |
| 31 | features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(self.test_user, self.test_user) |
| 32 | self.write_config(features) |
| 33 | |
| 34 | # Build a core-image-minimal |
| 35 | bitbake('core-image-minimal') |
| 36 | |
| 37 | with runqemu("core-image-minimal") as qemu: |
| 38 | # Attempt to ssh with each user into qemu with empty password |
| 39 | for user in [self.root_user, self.test_user]: |
| 40 | ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user=user) |
| 41 | status, output = ssh.run("true") |
| 42 | self.assertEqual(status, 0, 'ssh to user %s failed with %s' % (user, output)) |
| 43 | |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame] | 44 | @OETestTag("runqemu") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 45 | def test_all_users_can_connect_via_ssh_without_password(self): |
| 46 | """ |
| 47 | Summary: Check if all users can connect via ssh without password |
| 48 | Expected: 1. Connection to the image via ssh using root user without providing a password should NOT be allowed. |
| 49 | 2. Connection to the image via ssh using tester user without providing a password should be allowed. |
| 50 | Product: oe-core |
| 51 | Author: Ionut Chisanovici <ionutx.chisanovici@intel.com> |
| 52 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 53 | """ |
| 54 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 55 | features = 'EXTRA_IMAGE_FEATURES = "ssh-server-openssh allow-empty-password allow-root-login"\n' |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 56 | features += 'INHERIT += "extrausers"\n' |
| 57 | features += 'EXTRA_USERS_PARAMS = "useradd -p \'\' {}; usermod -s /bin/sh {};"'.format(self.test_user, self.test_user) |
| 58 | self.write_config(features) |
| 59 | |
| 60 | # Build a core-image-minimal |
| 61 | bitbake('core-image-minimal') |
| 62 | |
| 63 | with runqemu("core-image-minimal") as qemu: |
| 64 | # Attempt to ssh with each user into qemu with empty password |
| 65 | for user in [self.root_user, self.test_user]: |
| 66 | ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user=user) |
| 67 | status, output = ssh.run("true") |
| 68 | if user == 'root': |
| 69 | self.assertNotEqual(status, 0, 'ssh to user root was allowed when it should not have been') |
| 70 | else: |
| 71 | self.assertEqual(status, 0, 'ssh to user tester failed with %s' % output) |
| 72 | |
| 73 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 74 | def test_wayland_support_in_image(self): |
| 75 | """ |
| 76 | Summary: Check Wayland support in image |
| 77 | Expected: 1. Wayland image can be build |
| 78 | 2. Wayland feature can be installed |
| 79 | Product: oe-core |
| 80 | Author: Ionut Chisanovici <ionutx.chisanovici@intel.com> |
| 81 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 82 | """ |
| 83 | |
| 84 | distro_features = get_bb_var('DISTRO_FEATURES') |
| 85 | if not ('opengl' in distro_features and 'wayland' in distro_features): |
| 86 | self.skipTest('neither opengl nor wayland present on DISTRO_FEATURES so core-image-weston cannot be built') |
| 87 | |
| 88 | # Build a core-image-weston |
| 89 | bitbake('core-image-weston') |
| 90 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 91 | def test_bmap(self): |
| 92 | """ |
| 93 | Summary: Check bmap support |
| 94 | Expected: 1. core-image-minimal can be build with bmap support |
| 95 | 2. core-image-minimal is sparse |
| 96 | Product: oe-core |
| 97 | Author: Ed Bartosh <ed.bartosh@linux.intel.com> |
| 98 | """ |
| 99 | |
| 100 | features = 'IMAGE_FSTYPES += " ext4 ext4.bmap ext4.bmap.gz"' |
| 101 | self.write_config(features) |
| 102 | |
| 103 | image_name = 'core-image-minimal' |
| 104 | bitbake(image_name) |
| 105 | |
| 106 | deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') |
| 107 | link_name = get_bb_var('IMAGE_LINK_NAME', image_name) |
| 108 | image_path = os.path.join(deploy_dir_image, "%s.ext4" % link_name) |
| 109 | bmap_path = "%s.bmap" % image_path |
| 110 | gzip_path = "%s.gz" % bmap_path |
| 111 | |
| 112 | # check if result image, bmap and bmap.gz files are in deploy directory |
| 113 | self.assertTrue(os.path.exists(image_path)) |
| 114 | self.assertTrue(os.path.exists(bmap_path)) |
| 115 | self.assertTrue(os.path.exists(gzip_path)) |
| 116 | |
| 117 | # check if result image is sparse |
| 118 | image_stat = os.stat(image_path) |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 119 | self.assertGreater(image_stat.st_size, image_stat.st_blocks * 512) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 120 | |
| 121 | # check if the resulting gzip is valid |
| 122 | self.assertTrue(runCmd('gzip -t %s' % gzip_path)) |
| 123 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 124 | def test_hypervisor_fmts(self): |
| 125 | """ |
| 126 | Summary: Check various hypervisor formats |
| 127 | Expected: 1. core-image-minimal can be built with vmdk, vdi and |
| 128 | qcow2 support. |
| 129 | 2. qemu-img says each image has the expected format |
| 130 | Product: oe-core |
| 131 | Author: Tom Rini <trini@konsulko.com> |
| 132 | """ |
| 133 | |
| 134 | img_types = [ 'vmdk', 'vdi', 'qcow2' ] |
| 135 | features = "" |
| 136 | for itype in img_types: |
| 137 | features += 'IMAGE_FSTYPES += "wic.%s"\n' % itype |
| 138 | self.write_config(features) |
| 139 | |
| 140 | image_name = 'core-image-minimal' |
| 141 | bitbake(image_name) |
| 142 | |
| 143 | deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') |
| 144 | link_name = get_bb_var('IMAGE_LINK_NAME', image_name) |
| 145 | for itype in img_types: |
| 146 | image_path = os.path.join(deploy_dir_image, "%s.wic.%s" % |
| 147 | (link_name, itype)) |
| 148 | |
| 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 Bishop | f3f93bb | 2019-10-16 14:33:32 -0400 | [diff] [blame] | 156 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 162 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 163 | 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 Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame^] | 167 | ext4.bmap.gz.bz2.zst.xz.u-boot and also create a |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 168 | sha256sum |
| 169 | 2. The above image has a valid sha256sum |
| 170 | Product: oe-core |
| 171 | Author: Tom Rini <trini@konsulko.com> |
| 172 | """ |
| 173 | |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame^] | 174 | conv = "ext4.bmap.gz.bz2.zst.xz.u-boot" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 175 | features = 'IMAGE_FSTYPES += "%s %s.sha256sum"' % (conv, conv) |
| 176 | self.write_config(features) |
| 177 | |
| 178 | image_name = 'core-image-minimal' |
| 179 | bitbake(image_name) |
| 180 | |
| 181 | deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') |
| 182 | link_name = get_bb_var('IMAGE_LINK_NAME', image_name) |
| 183 | image_path = os.path.join(deploy_dir_image, "%s.%s" % |
| 184 | (link_name, conv)) |
| 185 | |
| 186 | # check if resulting image is in the deploy directory |
| 187 | self.assertTrue(os.path.exists(image_path)) |
| 188 | self.assertTrue(os.path.exists(image_path + ".sha256sum")) |
| 189 | |
| 190 | # check if the resulting sha256sum agrees |
| 191 | self.assertTrue(runCmd('cd %s;sha256sum -c %s.%s.sha256sum' % |
| 192 | (deploy_dir_image, link_name, conv))) |
| 193 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 194 | def test_image_fstypes(self): |
| 195 | """ |
| 196 | Summary: Check if image of supported image fstypes can be built |
| 197 | Expected: core-image-minimal can be built for various image types |
| 198 | Product: oe-core |
| 199 | Author: Ed Bartosh <ed.bartosh@linux.intel.com> |
| 200 | """ |
| 201 | image_name = 'core-image-minimal' |
| 202 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 203 | all_image_types = set(get_bb_var("IMAGE_TYPES", image_name).split()) |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame^] | 204 | skip_image_types = set(('container', 'elf', 'f2fs', 'multiubi', 'tar.zst', 'wic.zst', 'squashfs-lzo')) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 205 | img_types = all_image_types - skip_image_types |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 206 | |
| 207 | config = 'IMAGE_FSTYPES += "%s"\n'\ |
| 208 | 'MKUBIFS_ARGS ?= "-m 2048 -e 129024 -c 2047"\n'\ |
| 209 | 'UBINIZE_ARGS ?= "-m 2048 -p 128KiB -s 512"' % ' '.join(img_types) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 210 | self.write_config(config) |
| 211 | |
| 212 | bitbake(image_name) |
| 213 | |
| 214 | deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') |
| 215 | link_name = get_bb_var('IMAGE_LINK_NAME', image_name) |
| 216 | for itype in img_types: |
| 217 | image_path = os.path.join(deploy_dir_image, "%s.%s" % (link_name, itype)) |
| 218 | # check if result image is in deploy directory |
| 219 | self.assertTrue(os.path.exists(image_path), |
| 220 | "%s image %s doesn't exist" % (itype, image_path)) |
| 221 | |
| 222 | def test_useradd_static(self): |
| 223 | config = """ |
| 224 | USERADDEXTENSION = "useradd-staticids" |
| 225 | USERADD_ERROR_DYNAMIC = "skip" |
| 226 | USERADD_UID_TABLES += "files/static-passwd" |
| 227 | USERADD_GID_TABLES += "files/static-group" |
| 228 | """ |
| 229 | self.write_config(config) |
| 230 | bitbake("core-image-base") |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 231 | |
| 232 | def test_no_busybox_base_utils(self): |
| 233 | config = """ |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 234 | # Enable wayland |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 235 | DISTRO_FEATURES:append = " pam opengl wayland" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 236 | |
| 237 | # Switch to systemd |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 238 | DISTRO_FEATURES:append = " systemd" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 239 | VIRTUAL-RUNTIME_init_manager = "systemd" |
| 240 | VIRTUAL-RUNTIME_initscripts = "" |
| 241 | VIRTUAL-RUNTIME_syslog = "" |
| 242 | VIRTUAL-RUNTIME_login_manager = "shadow-base" |
| 243 | DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit" |
| 244 | |
| 245 | # Replace busybox |
| 246 | PREFERRED_PROVIDER_virtual/base-utils = "packagegroup-core-base-utils" |
| 247 | VIRTUAL-RUNTIME_base-utils = "packagegroup-core-base-utils" |
| 248 | VIRTUAL-RUNTIME_base-utils-hwclock = "util-linux-hwclock" |
| 249 | VIRTUAL-RUNTIME_base-utils-syslog = "" |
| 250 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 251 | # Skip busybox |
| 252 | SKIP_RECIPE[busybox] = "Don't build this" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 253 | """ |
| 254 | self.write_config(config) |
| 255 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 256 | bitbake("--graphviz core-image-weston") |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 257 | |
| 258 | def test_image_gen_debugfs(self): |
| 259 | """ |
| 260 | Summary: Check debugfs generation |
| 261 | Expected: 1. core-image-minimal can be build with IMAGE_GEN_DEBUGFS variable set |
| 262 | 2. debug filesystem is created when variable set |
| 263 | 3. debug symbols available |
| 264 | Product: oe-core |
| 265 | Author: Humberto Ibarra <humberto.ibarra.lopez@intel.com> |
| 266 | Yeoh Ee Peng <ee.peng.yeoh@intel.com> |
| 267 | """ |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 268 | |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 269 | image_name = 'core-image-minimal' |
| 270 | features = 'IMAGE_GEN_DEBUGFS = "1"\n' |
| 271 | features += 'IMAGE_FSTYPES_DEBUGFS = "tar.bz2"\n' |
| 272 | features += 'MACHINE = "genericx86-64"\n' |
| 273 | self.write_config(features) |
| 274 | |
| 275 | bitbake(image_name) |
| 276 | deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') |
| 277 | dbg_tar_file = os.path.join(deploy_dir_image, "*-dbg.rootfs.tar.bz2") |
| 278 | debug_files = glob.glob(dbg_tar_file) |
| 279 | self.assertNotEqual(len(debug_files), 0, 'debug filesystem not generated at %s' % dbg_tar_file) |
| 280 | result = runCmd('cd %s; tar xvf %s' % (deploy_dir_image, dbg_tar_file)) |
| 281 | self.assertEqual(result.status, 0, msg='Failed to extract %s: %s' % (dbg_tar_file, result.output)) |
| 282 | result = runCmd('find %s -name %s' % (deploy_dir_image, "udevadm")) |
| 283 | self.assertTrue("udevadm" in result.output, msg='Failed to find udevadm: %s' % result.output) |
| 284 | dbg_symbols_targets = result.output.splitlines() |
| 285 | self.assertTrue(dbg_symbols_targets, msg='Failed to split udevadm: %s' % dbg_symbols_targets) |
| 286 | for t in dbg_symbols_targets: |
| 287 | result = runCmd('objdump --syms %s | grep debug' % t) |
| 288 | self.assertTrue("debug" in result.output, msg='Failed to find debug symbol: %s' % result.output) |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 289 | |
| 290 | def test_empty_image(self): |
| 291 | """Test creation of image with no packages""" |
| 292 | bitbake('test-empty-image') |
| 293 | res_dir = get_bb_var('DEPLOY_DIR_IMAGE') |
| 294 | images = os.path.join(res_dir, "test-empty-image-*.manifest") |
| 295 | result = glob.glob(images) |
| 296 | with open(result[1],"r") as f: |
| 297 | self.assertEqual(len(f.read().strip()),0) |