blob: afc629f29cdfc6348f3d1c379bb5af624b400320 [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)
164 self.assertTrue(json.loads(result.output).get('format') == itype)
165
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500166 def test_long_chain_conversion(self):
167 """
168 Summary: Check for chaining many CONVERSION_CMDs together
169 Expected: 1. core-image-minimal can be built with
170 ext4.bmap.gz.bz2.lzo.xz.u-boot and also create a
171 sha256sum
172 2. The above image has a valid sha256sum
173 Product: oe-core
174 Author: Tom Rini <trini@konsulko.com>
175 """
176
177 conv = "ext4.bmap.gz.bz2.lzo.xz.u-boot"
178 features = 'IMAGE_FSTYPES += "%s %s.sha256sum"' % (conv, conv)
179 self.write_config(features)
180
181 image_name = 'core-image-minimal'
182 bitbake(image_name)
183
184 deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
185 link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
186 image_path = os.path.join(deploy_dir_image, "%s.%s" %
187 (link_name, conv))
188
189 # check if resulting image is in the deploy directory
190 self.assertTrue(os.path.exists(image_path))
191 self.assertTrue(os.path.exists(image_path + ".sha256sum"))
192
193 # check if the resulting sha256sum agrees
194 self.assertTrue(runCmd('cd %s;sha256sum -c %s.%s.sha256sum' %
195 (deploy_dir_image, link_name, conv)))
196
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500197 def test_image_fstypes(self):
198 """
199 Summary: Check if image of supported image fstypes can be built
200 Expected: core-image-minimal can be built for various image types
201 Product: oe-core
202 Author: Ed Bartosh <ed.bartosh@linux.intel.com>
203 """
204 image_name = 'core-image-minimal'
205
206 img_types = [itype for itype in get_bb_var("IMAGE_TYPES", image_name).split() \
Brad Bishop316dfdd2018-06-25 12:45:53 -0400207 if itype not in ('container', 'elf', 'f2fs', 'multiubi')]
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)
212
213 self.write_config(config)
214
215 bitbake(image_name)
216
217 deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
218 link_name = get_bb_var('IMAGE_LINK_NAME', image_name)
219 for itype in img_types:
220 image_path = os.path.join(deploy_dir_image, "%s.%s" % (link_name, itype))
221 # check if result image is in deploy directory
222 self.assertTrue(os.path.exists(image_path),
223 "%s image %s doesn't exist" % (itype, image_path))
224
225 def test_useradd_static(self):
226 config = """
227USERADDEXTENSION = "useradd-staticids"
228USERADD_ERROR_DYNAMIC = "skip"
229USERADD_UID_TABLES += "files/static-passwd"
230USERADD_GID_TABLES += "files/static-group"
231"""
232 self.write_config(config)
233 bitbake("core-image-base")
Brad Bishop19323692019-04-05 15:28:33 -0400234
235 def test_no_busybox_base_utils(self):
236 config = """
237# Enable x11
238DISTRO_FEATURES_append += "x11"
239
240# Switch to systemd
241DISTRO_FEATURES += "systemd"
242VIRTUAL-RUNTIME_init_manager = "systemd"
243VIRTUAL-RUNTIME_initscripts = ""
244VIRTUAL-RUNTIME_syslog = ""
245VIRTUAL-RUNTIME_login_manager = "shadow-base"
246DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
247
248# Replace busybox
249PREFERRED_PROVIDER_virtual/base-utils = "packagegroup-core-base-utils"
250VIRTUAL-RUNTIME_base-utils = "packagegroup-core-base-utils"
251VIRTUAL-RUNTIME_base-utils-hwclock = "util-linux-hwclock"
252VIRTUAL-RUNTIME_base-utils-syslog = ""
253
254# Blacklist busybox
255PNBLACKLIST[busybox] = "Don't build this"
256"""
257 self.write_config(config)
258
259 bitbake("--graphviz core-image-sato")