blob: 8213d63e375430f159dcaf554b42d990adf0b73c [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005from oeqa.selftest.case import OESelftestTestCase
6from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007from oeqa.utils.sshcontrol import SSHControl
8import os
9import json
10
11class ImageFeatures(OESelftestTestCase):
12
13 test_user = 'tester'
14 root_user = 'root'
15
Brad Bishopd7bf8c12018-02-25 22:55:05 -050016 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 Bishop1a4b7ee2018-12-16 17:11:34 -080026 features = 'EXTRA_IMAGE_FEATURES = "ssh-server-openssh empty-root-password allow-empty-password allow-root-login"\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050027 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 Bishopd7bf8c12018-02-25 22:55:05 -050041 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 Bishop1a4b7ee2018-12-16 17:11:34 -080051 features = 'EXTRA_IMAGE_FEATURES = "ssh-server-openssh allow-empty-password allow-root-login"\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050052 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 Bishopd7bf8c12018-02-25 22:55:05 -050070 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 Bishopd7bf8c12018-02-25 22:55:05 -050082 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 Bishopd7bf8c12018-02-25 22:55:05 -050099 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)
127 self.assertTrue(image_stat.st_size > image_stat.st_blocks * 512)
128
129 # check if the resulting gzip is valid
130 self.assertTrue(runCmd('gzip -t %s' % gzip_path))
131
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500132 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 Bishopa34c0302019-09-23 22:34:48 -0400164 self.assertTrue(json.loads(result.output).get('format') == itype,
165 msg="Could not parse '%s'" % result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500166
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500167 def test_long_chain_conversion(self):
168 """
169 Summary: Check for chaining many CONVERSION_CMDs together
170 Expected: 1. core-image-minimal can be built with
171 ext4.bmap.gz.bz2.lzo.xz.u-boot and also create a
172 sha256sum
173 2. The above image has a valid sha256sum
174 Product: oe-core
175 Author: Tom Rini <trini@konsulko.com>
176 """
177
178 conv = "ext4.bmap.gz.bz2.lzo.xz.u-boot"
179 features = 'IMAGE_FSTYPES += "%s %s.sha256sum"' % (conv, conv)
180 self.write_config(features)
181
182 image_name = 'core-image-minimal'
183 bitbake(image_name)
184
185 deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
186 link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
187 image_path = os.path.join(deploy_dir_image, "%s.%s" %
188 (link_name, conv))
189
190 # check if resulting image is in the deploy directory
191 self.assertTrue(os.path.exists(image_path))
192 self.assertTrue(os.path.exists(image_path + ".sha256sum"))
193
194 # check if the resulting sha256sum agrees
195 self.assertTrue(runCmd('cd %s;sha256sum -c %s.%s.sha256sum' %
196 (deploy_dir_image, link_name, conv)))
197
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500198 def test_image_fstypes(self):
199 """
200 Summary: Check if image of supported image fstypes can be built
201 Expected: core-image-minimal can be built for various image types
202 Product: oe-core
203 Author: Ed Bartosh <ed.bartosh@linux.intel.com>
204 """
205 image_name = 'core-image-minimal'
206
207 img_types = [itype for itype in get_bb_var("IMAGE_TYPES", image_name).split() \
Brad Bishop316dfdd2018-06-25 12:45:53 -0400208 if itype not in ('container', 'elf', 'f2fs', 'multiubi')]
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500209
210 config = 'IMAGE_FSTYPES += "%s"\n'\
211 'MKUBIFS_ARGS ?= "-m 2048 -e 129024 -c 2047"\n'\
212 'UBINIZE_ARGS ?= "-m 2048 -p 128KiB -s 512"' % ' '.join(img_types)
213
214 self.write_config(config)
215
216 bitbake(image_name)
217
218 deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
219 link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
220 for itype in img_types:
221 image_path = os.path.join(deploy_dir_image, "%s.%s" % (link_name, itype))
222 # check if result image is in deploy directory
223 self.assertTrue(os.path.exists(image_path),
224 "%s image %s doesn't exist" % (itype, image_path))
225
226 def test_useradd_static(self):
227 config = """
228USERADDEXTENSION = "useradd-staticids"
229USERADD_ERROR_DYNAMIC = "skip"
230USERADD_UID_TABLES += "files/static-passwd"
231USERADD_GID_TABLES += "files/static-group"
232"""
233 self.write_config(config)
234 bitbake("core-image-base")
Brad Bishop19323692019-04-05 15:28:33 -0400235
236 def test_no_busybox_base_utils(self):
237 config = """
238# Enable x11
239DISTRO_FEATURES_append += "x11"
240
241# Switch to systemd
242DISTRO_FEATURES += "systemd"
243VIRTUAL-RUNTIME_init_manager = "systemd"
244VIRTUAL-RUNTIME_initscripts = ""
245VIRTUAL-RUNTIME_syslog = ""
246VIRTUAL-RUNTIME_login_manager = "shadow-base"
247DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
248
249# Replace busybox
250PREFERRED_PROVIDER_virtual/base-utils = "packagegroup-core-base-utils"
251VIRTUAL-RUNTIME_base-utils = "packagegroup-core-base-utils"
252VIRTUAL-RUNTIME_base-utils-hwclock = "util-linux-hwclock"
253VIRTUAL-RUNTIME_base-utils-syslog = ""
254
255# Blacklist busybox
256PNBLACKLIST[busybox] = "Don't build this"
257"""
258 self.write_config(config)
259
260 bitbake("--graphviz core-image-sato")