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