summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest/cases/wic.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/wic.py')
-rw-r--r--meta/lib/oeqa/selftest/cases/wic.py762
1 files changed, 529 insertions, 233 deletions
diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py
index 2bf5cb9a86..b616759209 100644
--- a/meta/lib/oeqa/selftest/cases/wic.py
+++ b/meta/lib/oeqa/selftest/cases/wic.py
@@ -11,39 +11,19 @@
11import os 11import os
12import sys 12import sys
13import unittest 13import unittest
14import hashlib
14 15
15from glob import glob 16from glob import glob
16from shutil import rmtree, copy 17from shutil import rmtree, copy
17from functools import wraps, lru_cache
18from tempfile import NamedTemporaryFile 18from tempfile import NamedTemporaryFile
19from tempfile import TemporaryDirectory
19 20
20from oeqa.selftest.case import OESelftestTestCase 21from oeqa.selftest.case import OESelftestTestCase
22from oeqa.core.decorator import OETestTag
23from oeqa.core.decorator.data import skipIfNotArch
21from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars, runqemu 24from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars, runqemu
22 25
23 26
24@lru_cache(maxsize=32)
25def get_host_arch(recipe):
26 """A cached call to get_bb_var('HOST_ARCH', <recipe>)"""
27 return get_bb_var('HOST_ARCH', recipe)
28
29
30def only_for_arch(archs, image='core-image-minimal'):
31 """Decorator for wrapping test cases that can be run only for specific target
32 architectures. A list of compatible architectures is passed in `archs`.
33 Current architecture will be determined by parsing bitbake output for
34 `image` recipe.
35 """
36 def wrapper(func):
37 @wraps(func)
38 def wrapped_f(*args, **kwargs):
39 arch = get_host_arch(image)
40 if archs and arch not in archs:
41 raise unittest.SkipTest("Testcase arch dependency not met: %s" % arch)
42 return func(*args, **kwargs)
43 wrapped_f.__name__ = func.__name__
44 return wrapped_f
45 return wrapper
46
47def extract_files(debugfs_output): 27def extract_files(debugfs_output):
48 """ 28 """
49 extract file names from the output of debugfs -R 'ls -p', 29 extract file names from the output of debugfs -R 'ls -p',
@@ -77,22 +57,18 @@ class WicTestCase(OESelftestTestCase):
77 57
78 def setUpLocal(self): 58 def setUpLocal(self):
79 """This code is executed before each test method.""" 59 """This code is executed before each test method."""
80 self.resultdir = self.builddir + "/wic-tmp/" 60 self.resultdir = os.path.join(self.builddir, "wic-tmp")
81 super(WicTestCase, self).setUpLocal() 61 super(WicTestCase, self).setUpLocal()
82 62
83 # Do this here instead of in setUpClass as the base setUp does some 63 # Do this here instead of in setUpClass as the base setUp does some
84 # clean up which can result in the native tools built earlier in 64 # clean up which can result in the native tools built earlier in
85 # setUpClass being unavailable. 65 # setUpClass being unavailable.
86 if not WicTestCase.image_is_ready: 66 if not WicTestCase.image_is_ready:
87 if get_bb_var('USE_NLS') == 'yes': 67 if self.td['USE_NLS'] != 'yes':
88 bitbake('wic-tools') 68 self.skipTest('wic-tools needs USE_NLS=yes')
89 else:
90 self.skipTest('wic-tools cannot be built due its (intltool|gettext)-native dependency and NLS disable')
91 69
92 bitbake('core-image-minimal') 70 bitbake('wic-tools core-image-minimal core-image-minimal-mtdutils')
93 bitbake('core-image-minimal-mtdutils')
94 WicTestCase.image_is_ready = True 71 WicTestCase.image_is_ready = True
95
96 rmtree(self.resultdir, ignore_errors=True) 72 rmtree(self.resultdir, ignore_errors=True)
97 73
98 def tearDownLocal(self): 74 def tearDownLocal(self):
@@ -103,15 +79,13 @@ class WicTestCase(OESelftestTestCase):
103 def _get_image_env_path(self, image): 79 def _get_image_env_path(self, image):
104 """Generate and obtain the path to <image>.env""" 80 """Generate and obtain the path to <image>.env"""
105 if image not in WicTestCase.wicenv_cache: 81 if image not in WicTestCase.wicenv_cache:
106 self.assertEqual(0, bitbake('%s -c do_rootfs_wicenv' % image).status) 82 bitbake('%s -c do_rootfs_wicenv' % image)
107 bb_vars = get_bb_vars(['STAGING_DIR', 'MACHINE'], image) 83 stdir = get_bb_var('STAGING_DIR', image)
108 stdir = bb_vars['STAGING_DIR'] 84 machine = self.td["MACHINE"]
109 machine = bb_vars['MACHINE']
110 WicTestCase.wicenv_cache[image] = os.path.join(stdir, machine, 'imgdata') 85 WicTestCase.wicenv_cache[image] = os.path.join(stdir, machine, 'imgdata')
111 return WicTestCase.wicenv_cache[image] 86 return WicTestCase.wicenv_cache[image]
112 87
113class Wic(WicTestCase): 88class CLITests(OESelftestTestCase):
114
115 def test_version(self): 89 def test_version(self):
116 """Test wic --version""" 90 """Test wic --version"""
117 runCmd('wic --version') 91 runCmd('wic --version')
@@ -172,68 +146,136 @@ class Wic(WicTestCase):
172 """Test wic without command""" 146 """Test wic without command"""
173 self.assertEqual(1, runCmd('wic', ignore_status=True).status) 147 self.assertEqual(1, runCmd('wic', ignore_status=True).status)
174 148
149class Wic(WicTestCase):
150 def test_skip_kernel_install(self):
151 """Test the functionality of not installing the kernel in the boot directory using the wic plugin"""
152 # create a temporary file for the WKS content
153 with NamedTemporaryFile("w", suffix=".wks") as wks:
154 wks.write(
155 'part --source bootimg-efi '
156 '--sourceparams="loader=grub-efi,install-kernel-into-boot-dir=false" '
157 '--label boot --active\n'
158 )
159 wks.flush()
160 # create a temporary directory to extract the disk image to
161 with TemporaryDirectory() as tmpdir:
162 img = 'core-image-minimal'
163 # build the image using the WKS file
164 cmd = "wic create %s -e %s -o %s" % (
165 wks.name, img, self.resultdir)
166 runCmd(cmd)
167 wksname = os.path.splitext(os.path.basename(wks.name))[0]
168 out = glob(os.path.join(
169 self.resultdir, "%s-*.direct" % wksname))
170 self.assertEqual(1, len(out))
171 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
172 # extract the content of the disk image to the temporary directory
173 cmd = "wic cp %s:1 %s -n %s" % (out[0], tmpdir, sysroot)
174 runCmd(cmd)
175 # check if the kernel is installed or not
176 kimgtype = get_bb_var('KERNEL_IMAGETYPE', img)
177 for file in os.listdir(tmpdir):
178 if file == kimgtype:
179 raise AssertionError(
180 "The kernel image '{}' was found in the partition".format(kimgtype)
181 )
182
183 def test_kernel_install(self):
184 """Test the installation of the kernel to the boot directory in the wic plugin"""
185 # create a temporary file for the WKS content
186 with NamedTemporaryFile("w", suffix=".wks") as wks:
187 wks.write(
188 'part --source bootimg-efi '
189 '--sourceparams="loader=grub-efi,install-kernel-into-boot-dir=true" '
190 '--label boot --active\n'
191 )
192 wks.flush()
193 # create a temporary directory to extract the disk image to
194 with TemporaryDirectory() as tmpdir:
195 img = 'core-image-minimal'
196 # build the image using the WKS file
197 cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir)
198 runCmd(cmd)
199 wksname = os.path.splitext(os.path.basename(wks.name))[0]
200 out = glob(os.path.join(self.resultdir, "%s-*.direct" % wksname))
201 self.assertEqual(1, len(out))
202 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
203 # extract the content of the disk image to the temporary directory
204 cmd = "wic cp %s:1 %s -n %s" % (out[0], tmpdir, sysroot)
205 runCmd(cmd)
206 # check if the kernel is installed or not
207 kimgtype = get_bb_var('KERNEL_IMAGETYPE', img)
208 found = False
209 for file in os.listdir(tmpdir):
210 if file == kimgtype:
211 found = True
212 break
213 self.assertTrue(
214 found, "The kernel image '{}' was not found in the boot partition".format(kimgtype)
215 )
216
175 def test_build_image_name(self): 217 def test_build_image_name(self):
176 """Test wic create wictestdisk --image-name=core-image-minimal""" 218 """Test wic create wictestdisk --image-name=core-image-minimal"""
177 cmd = "wic create wictestdisk --image-name=core-image-minimal -o %s" % self.resultdir 219 cmd = "wic create wictestdisk --image-name=core-image-minimal -o %s" % self.resultdir
178 runCmd(cmd) 220 runCmd(cmd)
179 self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct"))) 221 self.assertEqual(1, len(glob(os.path.join (self.resultdir, "wictestdisk-*.direct"))))
180 222
181 @only_for_arch(['i586', 'i686', 'x86_64']) 223 @skipIfNotArch(['i586', 'i686', 'x86_64'])
182 def test_gpt_image(self): 224 def test_gpt_image(self):
183 """Test creation of core-image-minimal with gpt table and UUID boot""" 225 """Test creation of core-image-minimal with gpt table and UUID boot"""
184 cmd = "wic create directdisk-gpt --image-name core-image-minimal -o %s" % self.resultdir 226 cmd = "wic create directdisk-gpt --image-name core-image-minimal -o %s" % self.resultdir
185 runCmd(cmd) 227 runCmd(cmd)
186 self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct"))) 228 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "directdisk-*.direct"))))
187 229
188 @only_for_arch(['i586', 'i686', 'x86_64']) 230 @skipIfNotArch(['i586', 'i686', 'x86_64'])
189 def test_iso_image(self): 231 def test_iso_image(self):
190 """Test creation of hybrid iso image with legacy and EFI boot""" 232 """Test creation of hybrid iso image with legacy and EFI boot"""
191 config = 'INITRAMFS_IMAGE = "core-image-minimal-initramfs"\n'\ 233 config = 'INITRAMFS_IMAGE = "core-image-minimal-initramfs"\n'\
192 'MACHINE_FEATURES_append = " efi"\n'\ 234 'MACHINE_FEATURES:append = " efi"\n'\
193 'DEPENDS_pn-core-image-minimal += "syslinux"\n' 235 'DEPENDS:pn-core-image-minimal += "syslinux"\n'
194 self.append_config(config) 236 self.append_config(config)
195 bitbake('core-image-minimal core-image-minimal-initramfs') 237 bitbake('core-image-minimal core-image-minimal-initramfs')
196 self.remove_config(config) 238 self.remove_config(config)
197 cmd = "wic create mkhybridiso --image-name core-image-minimal -o %s" % self.resultdir 239 cmd = "wic create mkhybridiso --image-name core-image-minimal -o %s" % self.resultdir
198 runCmd(cmd) 240 runCmd(cmd)
199 self.assertEqual(1, len(glob(self.resultdir + "HYBRID_ISO_IMG-*.direct"))) 241 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "HYBRID_ISO_IMG-*.direct"))))
200 self.assertEqual(1, len(glob(self.resultdir + "HYBRID_ISO_IMG-*.iso"))) 242 self.assertEqual(1, len(glob(os.path.join (self.resultdir, "HYBRID_ISO_IMG-*.iso"))))
201 243
202 @only_for_arch(['i586', 'i686', 'x86_64']) 244 @skipIfNotArch(['i586', 'i686', 'x86_64'])
203 def test_qemux86_directdisk(self): 245 def test_qemux86_directdisk(self):
204 """Test creation of qemux-86-directdisk image""" 246 """Test creation of qemux-86-directdisk image"""
205 cmd = "wic create qemux86-directdisk -e core-image-minimal -o %s" % self.resultdir 247 cmd = "wic create qemux86-directdisk -e core-image-minimal -o %s" % self.resultdir
206 runCmd(cmd) 248 runCmd(cmd)
207 self.assertEqual(1, len(glob(self.resultdir + "qemux86-directdisk-*direct"))) 249 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "qemux86-directdisk-*direct"))))
208 250
209 @only_for_arch(['i586', 'i686', 'x86_64']) 251 @skipIfNotArch(['i586', 'i686', 'x86_64', 'aarch64'])
210 def test_mkefidisk(self): 252 def test_mkefidisk(self):
211 """Test creation of mkefidisk image""" 253 """Test creation of mkefidisk image"""
212 cmd = "wic create mkefidisk -e core-image-minimal -o %s" % self.resultdir 254 cmd = "wic create mkefidisk -e core-image-minimal -o %s" % self.resultdir
213 runCmd(cmd) 255 runCmd(cmd)
214 self.assertEqual(1, len(glob(self.resultdir + "mkefidisk-*direct"))) 256 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "mkefidisk-*direct"))))
215 257
216 @only_for_arch(['i586', 'i686', 'x86_64']) 258 @skipIfNotArch(['i586', 'i686', 'x86_64'])
217 def test_bootloader_config(self): 259 def test_bootloader_config(self):
218 """Test creation of directdisk-bootloader-config image""" 260 """Test creation of directdisk-bootloader-config image"""
219 config = 'DEPENDS_pn-core-image-minimal += "syslinux"\n' 261 config = 'DEPENDS:pn-core-image-minimal += "syslinux"\n'
220 self.append_config(config) 262 self.append_config(config)
221 bitbake('core-image-minimal') 263 bitbake('core-image-minimal')
222 self.remove_config(config) 264 self.remove_config(config)
223 cmd = "wic create directdisk-bootloader-config -e core-image-minimal -o %s" % self.resultdir 265 cmd = "wic create directdisk-bootloader-config -e core-image-minimal -o %s" % self.resultdir
224 runCmd(cmd) 266 runCmd(cmd)
225 self.assertEqual(1, len(glob(self.resultdir + "directdisk-bootloader-config-*direct"))) 267 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "directdisk-bootloader-config-*direct"))))
226 268
227 @only_for_arch(['i586', 'i686', 'x86_64']) 269 @skipIfNotArch(['i586', 'i686', 'x86_64', 'aarch64'])
228 def test_systemd_bootdisk(self): 270 def test_systemd_bootdisk(self):
229 """Test creation of systemd-bootdisk image""" 271 """Test creation of systemd-bootdisk image"""
230 config = 'MACHINE_FEATURES_append = " efi"\n' 272 config = 'MACHINE_FEATURES:append = " efi"\n'
231 self.append_config(config) 273 self.append_config(config)
232 bitbake('core-image-minimal') 274 bitbake('core-image-minimal')
233 self.remove_config(config) 275 self.remove_config(config)
234 cmd = "wic create systemd-bootdisk -e core-image-minimal -o %s" % self.resultdir 276 cmd = "wic create systemd-bootdisk -e core-image-minimal -o %s" % self.resultdir
235 runCmd(cmd) 277 runCmd(cmd)
236 self.assertEqual(1, len(glob(self.resultdir + "systemd-bootdisk-*direct"))) 278 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "systemd-bootdisk-*direct"))))
237 279
238 def test_efi_bootpart(self): 280 def test_efi_bootpart(self):
239 """Test creation of efi-bootpart image""" 281 """Test creation of efi-bootpart image"""
@@ -242,7 +284,7 @@ class Wic(WicTestCase):
242 self.append_config('IMAGE_EFI_BOOT_FILES = "%s;kernel"\n' % kimgtype) 284 self.append_config('IMAGE_EFI_BOOT_FILES = "%s;kernel"\n' % kimgtype)
243 runCmd(cmd) 285 runCmd(cmd)
244 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') 286 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
245 images = glob(self.resultdir + "mkefidisk-*.direct") 287 images = glob(os.path.join(self.resultdir, "mkefidisk-*.direct"))
246 result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot)) 288 result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot))
247 self.assertIn("kernel",result.output) 289 self.assertIn("kernel",result.output)
248 290
@@ -252,14 +294,15 @@ class Wic(WicTestCase):
252 kimgtype = get_bb_var('KERNEL_IMAGETYPE', 'core-image-minimal') 294 kimgtype = get_bb_var('KERNEL_IMAGETYPE', 'core-image-minimal')
253 self.write_config('IMAGE_BOOT_FILES = "%s"\n' % kimgtype) 295 self.write_config('IMAGE_BOOT_FILES = "%s"\n' % kimgtype)
254 runCmd(cmd) 296 runCmd(cmd)
255 self.assertEqual(1, len(glob(self.resultdir + "sdimage-bootpart-*direct"))) 297 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "sdimage-bootpart-*direct"))))
256 298
257 @only_for_arch(['i586', 'i686', 'x86_64']) 299 # TODO this doesn't have to be x86-specific
300 @skipIfNotArch(['i586', 'i686', 'x86_64'])
258 def test_default_output_dir(self): 301 def test_default_output_dir(self):
259 """Test default output location""" 302 """Test default output location"""
260 for fname in glob("directdisk-*.direct"): 303 for fname in glob("directdisk-*.direct"):
261 os.remove(fname) 304 os.remove(fname)
262 config = 'DEPENDS_pn-core-image-minimal += "syslinux"\n' 305 config = 'DEPENDS:pn-core-image-minimal += "syslinux"\n'
263 self.append_config(config) 306 self.append_config(config)
264 bitbake('core-image-minimal') 307 bitbake('core-image-minimal')
265 self.remove_config(config) 308 self.remove_config(config)
@@ -267,7 +310,7 @@ class Wic(WicTestCase):
267 runCmd(cmd) 310 runCmd(cmd)
268 self.assertEqual(1, len(glob("directdisk-*.direct"))) 311 self.assertEqual(1, len(glob("directdisk-*.direct")))
269 312
270 @only_for_arch(['i586', 'i686', 'x86_64']) 313 @skipIfNotArch(['i586', 'i686', 'x86_64'])
271 def test_build_artifacts(self): 314 def test_build_artifacts(self):
272 """Test wic create directdisk providing all artifacts.""" 315 """Test wic create directdisk providing all artifacts."""
273 bb_vars = get_bb_vars(['STAGING_DATADIR', 'RECIPE_SYSROOT_NATIVE'], 316 bb_vars = get_bb_vars(['STAGING_DATADIR', 'RECIPE_SYSROOT_NATIVE'],
@@ -282,28 +325,28 @@ class Wic(WicTestCase):
282 "-n %(recipe_sysroot_native)s " 325 "-n %(recipe_sysroot_native)s "
283 "-r %(image_rootfs)s " 326 "-r %(image_rootfs)s "
284 "-o %(resultdir)s" % bbvars) 327 "-o %(resultdir)s" % bbvars)
285 self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct"))) 328 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "directdisk-*.direct"))))
286 329
287 def test_compress_gzip(self): 330 def test_compress_gzip(self):
288 """Test compressing an image with gzip""" 331 """Test compressing an image with gzip"""
289 runCmd("wic create wictestdisk " 332 runCmd("wic create wictestdisk "
290 "--image-name core-image-minimal " 333 "--image-name core-image-minimal "
291 "-c gzip -o %s" % self.resultdir) 334 "-c gzip -o %s" % self.resultdir)
292 self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct.gz"))) 335 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "wictestdisk-*.direct.gz"))))
293 336
294 def test_compress_bzip2(self): 337 def test_compress_bzip2(self):
295 """Test compressing an image with bzip2""" 338 """Test compressing an image with bzip2"""
296 runCmd("wic create wictestdisk " 339 runCmd("wic create wictestdisk "
297 "--image-name=core-image-minimal " 340 "--image-name=core-image-minimal "
298 "-c bzip2 -o %s" % self.resultdir) 341 "-c bzip2 -o %s" % self.resultdir)
299 self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct.bz2"))) 342 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "wictestdisk-*.direct.bz2"))))
300 343
301 def test_compress_xz(self): 344 def test_compress_xz(self):
302 """Test compressing an image with xz""" 345 """Test compressing an image with xz"""
303 runCmd("wic create wictestdisk " 346 runCmd("wic create wictestdisk "
304 "--image-name=core-image-minimal " 347 "--image-name=core-image-minimal "
305 "--compress-with=xz -o %s" % self.resultdir) 348 "--compress-with=xz -o %s" % self.resultdir)
306 self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct.xz"))) 349 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "wictestdisk-*.direct.xz"))))
307 350
308 def test_wrong_compressor(self): 351 def test_wrong_compressor(self):
309 """Test how wic breaks if wrong compressor is provided""" 352 """Test how wic breaks if wrong compressor is provided"""
@@ -317,23 +360,23 @@ class Wic(WicTestCase):
317 runCmd("wic create wictestdisk " 360 runCmd("wic create wictestdisk "
318 "--image-name=core-image-minimal " 361 "--image-name=core-image-minimal "
319 "-D -o %s" % self.resultdir) 362 "-D -o %s" % self.resultdir)
320 self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct"))) 363 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "wictestdisk-*.direct"))))
321 self.assertEqual(1, len(glob(self.resultdir + "tmp.wic*"))) 364 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "tmp.wic*"))))
322 365
323 def test_debug_long(self): 366 def test_debug_long(self):
324 """Test --debug option""" 367 """Test --debug option"""
325 runCmd("wic create wictestdisk " 368 runCmd("wic create wictestdisk "
326 "--image-name=core-image-minimal " 369 "--image-name=core-image-minimal "
327 "--debug -o %s" % self.resultdir) 370 "--debug -o %s" % self.resultdir)
328 self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct"))) 371 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "wictestdisk-*.direct"))))
329 self.assertEqual(1, len(glob(self.resultdir + "tmp.wic*"))) 372 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "tmp.wic*"))))
330 373
331 def test_skip_build_check_short(self): 374 def test_skip_build_check_short(self):
332 """Test -s option""" 375 """Test -s option"""
333 runCmd("wic create wictestdisk " 376 runCmd("wic create wictestdisk "
334 "--image-name=core-image-minimal " 377 "--image-name=core-image-minimal "
335 "-s -o %s" % self.resultdir) 378 "-s -o %s" % self.resultdir)
336 self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct"))) 379 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "wictestdisk-*.direct"))))
337 380
338 def test_skip_build_check_long(self): 381 def test_skip_build_check_long(self):
339 """Test --skip-build-check option""" 382 """Test --skip-build-check option"""
@@ -341,14 +384,14 @@ class Wic(WicTestCase):
341 "--image-name=core-image-minimal " 384 "--image-name=core-image-minimal "
342 "--skip-build-check " 385 "--skip-build-check "
343 "--outdir %s" % self.resultdir) 386 "--outdir %s" % self.resultdir)
344 self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct"))) 387 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "wictestdisk-*.direct"))))
345 388
346 def test_build_rootfs_short(self): 389 def test_build_rootfs_short(self):
347 """Test -f option""" 390 """Test -f option"""
348 runCmd("wic create wictestdisk " 391 runCmd("wic create wictestdisk "
349 "--image-name=core-image-minimal " 392 "--image-name=core-image-minimal "
350 "-f -o %s" % self.resultdir) 393 "-f -o %s" % self.resultdir)
351 self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct"))) 394 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "wictestdisk-*.direct"))))
352 395
353 def test_build_rootfs_long(self): 396 def test_build_rootfs_long(self):
354 """Test --build-rootfs option""" 397 """Test --build-rootfs option"""
@@ -356,9 +399,10 @@ class Wic(WicTestCase):
356 "--image-name=core-image-minimal " 399 "--image-name=core-image-minimal "
357 "--build-rootfs " 400 "--build-rootfs "
358 "--outdir %s" % self.resultdir) 401 "--outdir %s" % self.resultdir)
359 self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct"))) 402 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "wictestdisk-*.direct"))))
360 403
361 @only_for_arch(['i586', 'i686', 'x86_64']) 404 # TODO this doesn't have to be x86-specific
405 @skipIfNotArch(['i586', 'i686', 'x86_64'])
362 def test_rootfs_indirect_recipes(self): 406 def test_rootfs_indirect_recipes(self):
363 """Test usage of rootfs plugin with rootfs recipes""" 407 """Test usage of rootfs plugin with rootfs recipes"""
364 runCmd("wic create directdisk-multi-rootfs " 408 runCmd("wic create directdisk-multi-rootfs "
@@ -366,9 +410,10 @@ class Wic(WicTestCase):
366 "--rootfs rootfs1=core-image-minimal " 410 "--rootfs rootfs1=core-image-minimal "
367 "--rootfs rootfs2=core-image-minimal " 411 "--rootfs rootfs2=core-image-minimal "
368 "--outdir %s" % self.resultdir) 412 "--outdir %s" % self.resultdir)
369 self.assertEqual(1, len(glob(self.resultdir + "directdisk-multi-rootfs*.direct"))) 413 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "directdisk-multi-rootfs*.direct"))))
370 414
371 @only_for_arch(['i586', 'i686', 'x86_64']) 415 # TODO this doesn't have to be x86-specific
416 @skipIfNotArch(['i586', 'i686', 'x86_64'])
372 def test_rootfs_artifacts(self): 417 def test_rootfs_artifacts(self):
373 """Test usage of rootfs plugin with rootfs paths""" 418 """Test usage of rootfs plugin with rootfs paths"""
374 bb_vars = get_bb_vars(['STAGING_DATADIR', 'RECIPE_SYSROOT_NATIVE'], 419 bb_vars = get_bb_vars(['STAGING_DATADIR', 'RECIPE_SYSROOT_NATIVE'],
@@ -385,7 +430,7 @@ class Wic(WicTestCase):
385 "--rootfs-dir rootfs1=%(image_rootfs)s " 430 "--rootfs-dir rootfs1=%(image_rootfs)s "
386 "--rootfs-dir rootfs2=%(image_rootfs)s " 431 "--rootfs-dir rootfs2=%(image_rootfs)s "
387 "--outdir %(resultdir)s" % bbvars) 432 "--outdir %(resultdir)s" % bbvars)
388 self.assertEqual(1, len(glob(self.resultdir + "%(wks)s-*.direct" % bbvars))) 433 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "%(wks)s-*.direct" % bbvars))))
389 434
390 def test_exclude_path(self): 435 def test_exclude_path(self):
391 """Test --exclude-path wks option.""" 436 """Test --exclude-path wks option."""
@@ -406,7 +451,7 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r
406 % (wks_file, self.resultdir)) 451 % (wks_file, self.resultdir))
407 452
408 os.remove(wks_file) 453 os.remove(wks_file)
409 wicout = glob(self.resultdir + "%s-*direct" % 'temp') 454 wicout = glob(os.path.join(self.resultdir, "%s-*direct" % 'temp'))
410 self.assertEqual(1, len(wicout)) 455 self.assertEqual(1, len(wicout))
411 456
412 wicimg = wicout[0] 457 wicimg = wicout[0]
@@ -686,21 +731,130 @@ part /etc --source rootfs --fstype=ext4 --change-directory=etc
686 % (wks_file, self.resultdir), ignore_status=True).status) 731 % (wks_file, self.resultdir), ignore_status=True).status)
687 os.remove(wks_file) 732 os.remove(wks_file)
688 733
734 def test_no_fstab_update(self):
735 """Test --no-fstab-update wks option."""
736
737 oldpath = os.environ['PATH']
738 os.environ['PATH'] = get_bb_var("PATH", "wic-tools")
739
740 # Get stock fstab from base-files recipe
741 bitbake('base-files -c do_install')
742 bf_fstab = os.path.join(get_bb_var('D', 'base-files'), 'etc', 'fstab')
743 self.assertEqual(True, os.path.exists(bf_fstab))
744 bf_fstab_md5sum = runCmd('md5sum %s 2>/dev/null' % bf_fstab).output.split(" ")[0]
745
746 try:
747 no_fstab_update_path = os.path.join(self.resultdir, 'test-no-fstab-update')
748 os.makedirs(no_fstab_update_path)
749 wks_file = os.path.join(no_fstab_update_path, 'temp.wks')
750 with open(wks_file, 'w') as wks:
751 wks.writelines(['part / --source rootfs --fstype=ext4 --label rootfs\n',
752 'part /mnt/p2 --source rootfs --rootfs-dir=core-image-minimal ',
753 '--fstype=ext4 --label p2 --no-fstab-update\n'])
754 runCmd("wic create %s -e core-image-minimal -o %s" \
755 % (wks_file, self.resultdir))
756
757 part_fstab_md5sum = []
758 for i in range(1, 3):
759 part = glob(os.path.join(self.resultdir, 'temp-*.direct.p') + str(i))[0]
760 part_fstab = runCmd("debugfs -R 'cat etc/fstab' %s 2>/dev/null" % (part))
761 part_fstab_md5sum.append(hashlib.md5((part_fstab.output + "\n\n").encode('utf-8')).hexdigest())
762
763 # '/etc/fstab' in partition 2 should contain the same stock fstab file
764 # as the one installed by the base-file recipe.
765 self.assertEqual(bf_fstab_md5sum, part_fstab_md5sum[1])
766
767 # '/etc/fstab' in partition 1 should contain an updated fstab file.
768 self.assertNotEqual(bf_fstab_md5sum, part_fstab_md5sum[0])
769
770 finally:
771 os.environ['PATH'] = oldpath
772
773 def test_no_fstab_update_errors(self):
774 """Test --no-fstab-update wks option error handling."""
775 wks_file = 'temp.wks'
776
777 # Absolute argument.
778 with open(wks_file, 'w') as wks:
779 wks.write("part / --source rootfs --fstype=ext4 --no-fstab-update /etc")
780 self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \
781 % (wks_file, self.resultdir), ignore_status=True).status)
782 os.remove(wks_file)
783
784 # Argument pointing to parent directory.
785 with open(wks_file, 'w') as wks:
786 wks.write("part / --source rootfs --fstype=ext4 --no-fstab-update ././..")
787 self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \
788 % (wks_file, self.resultdir), ignore_status=True).status)
789 os.remove(wks_file)
790
791 def test_extra_space(self):
792 """Test --extra-space wks option."""
793 extraspace = 1024**3
794 runCmd("wic create wictestdisk "
795 "--image-name core-image-minimal "
796 "--extra-space %i -o %s" % (extraspace ,self.resultdir))
797 wicout = glob(os.path.join(self.resultdir, "wictestdisk-*.direct"))
798 self.assertEqual(1, len(wicout))
799 size = os.path.getsize(wicout[0])
800 self.assertTrue(size > extraspace, msg="Extra space not present (%s vs %s)" % (size, extraspace))
801
802 def test_no_table(self):
803 """Test --no-table wks option."""
804 wks_file = 'temp.wks'
805
806 # Absolute argument.
807 with open(wks_file, 'w') as wks:
808 wks.write("part testspace --no-table --fixed-size 16k --offset 4080k")
809 runCmd("wic create %s --image-name core-image-minimal -o %s" % (wks_file, self.resultdir))
810
811 wicout = glob(os.path.join(self.resultdir, "*.*"))
812
813 self.assertEqual(1, len(wicout))
814 size = os.path.getsize(wicout[0])
815 self.assertEqual(size, 4 * 1024 * 1024)
816
817 os.remove(wks_file)
818
819 def test_partition_hidden_attributes(self):
820 """Test --hidden wks option."""
821 wks_file = 'temp.wks'
822 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
823 try:
824 with open(wks_file, 'w') as wks:
825 wks.write("""
826part / --source rootfs --fstype=ext4
827part / --source rootfs --fstype=ext4 --hidden
828bootloader --ptable gpt""")
829
830 runCmd("wic create %s -e core-image-minimal -o %s" \
831 % (wks_file, self.resultdir))
832 wicout = os.path.join(self.resultdir, "*.direct")
833
834 result = runCmd("%s/usr/sbin/sfdisk --part-attrs %s 1" % (sysroot, wicout))
835 self.assertEqual('', result.output)
836 result = runCmd("%s/usr/sbin/sfdisk --part-attrs %s 2" % (sysroot, wicout))
837 self.assertEqual('RequiredPartition', result.output)
838
839 finally:
840 os.remove(wks_file)
841
842
689class Wic2(WicTestCase): 843class Wic2(WicTestCase):
690 844
691 def test_bmap_short(self): 845 def test_bmap_short(self):
692 """Test generation of .bmap file -m option""" 846 """Test generation of .bmap file -m option"""
693 cmd = "wic create wictestdisk -e core-image-minimal -m -o %s" % self.resultdir 847 cmd = "wic create wictestdisk -e core-image-minimal -m -o %s" % self.resultdir
694 runCmd(cmd) 848 runCmd(cmd)
695 self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*direct"))) 849 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "wictestdisk-*direct"))))
696 self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*direct.bmap"))) 850 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "wictestdisk-*direct.bmap"))))
697 851
698 def test_bmap_long(self): 852 def test_bmap_long(self):
699 """Test generation of .bmap file --bmap option""" 853 """Test generation of .bmap file --bmap option"""
700 cmd = "wic create wictestdisk -e core-image-minimal --bmap -o %s" % self.resultdir 854 cmd = "wic create wictestdisk -e core-image-minimal --bmap -o %s" % self.resultdir
701 runCmd(cmd) 855 runCmd(cmd)
702 self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*direct"))) 856 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "wictestdisk-*direct"))))
703 self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*direct.bmap"))) 857 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "wictestdisk-*direct.bmap"))))
704 858
705 def test_image_env(self): 859 def test_image_env(self):
706 """Test generation of <image>.env files.""" 860 """Test generation of <image>.env files."""
@@ -711,7 +865,7 @@ class Wic2(WicTestCase):
711 basename = bb_vars['IMAGE_BASENAME'] 865 basename = bb_vars['IMAGE_BASENAME']
712 self.assertEqual(basename, image) 866 self.assertEqual(basename, image)
713 path = os.path.join(imgdatadir, basename) + '.env' 867 path = os.path.join(imgdatadir, basename) + '.env'
714 self.assertTrue(os.path.isfile(path)) 868 self.assertTrue(os.path.isfile(path), msg="File %s wasn't generated as expected" % path)
715 869
716 wicvars = set(bb_vars['WICVARS'].split()) 870 wicvars = set(bb_vars['WICVARS'].split())
717 # filter out optional variables 871 # filter out optional variables
@@ -724,7 +878,7 @@ class Wic2(WicTestCase):
724 # test if variables used by wic present in the .env file 878 # test if variables used by wic present in the .env file
725 for var in wicvars: 879 for var in wicvars:
726 self.assertTrue(var in content, "%s is not in .env file" % var) 880 self.assertTrue(var in content, "%s is not in .env file" % var)
727 self.assertTrue(content[var]) 881 self.assertTrue(content[var], "%s doesn't have a value (%s)" % (var, content[var]))
728 882
729 def test_image_vars_dir_short(self): 883 def test_image_vars_dir_short(self):
730 """Test image vars directory selection -v option""" 884 """Test image vars directory selection -v option"""
@@ -736,7 +890,7 @@ class Wic2(WicTestCase):
736 "--image-name=%s -v %s -n %s -o %s" 890 "--image-name=%s -v %s -n %s -o %s"
737 % (image, imgenvdir, native_sysroot, 891 % (image, imgenvdir, native_sysroot,
738 self.resultdir)) 892 self.resultdir))
739 self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*direct"))) 893 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "wictestdisk-*direct"))))
740 894
741 def test_image_vars_dir_long(self): 895 def test_image_vars_dir_long(self):
742 """Test image vars directory selection --vars option""" 896 """Test image vars directory selection --vars option"""
@@ -751,58 +905,62 @@ class Wic2(WicTestCase):
751 "--outdir %s" 905 "--outdir %s"
752 % (image, imgenvdir, native_sysroot, 906 % (image, imgenvdir, native_sysroot,
753 self.resultdir)) 907 self.resultdir))
754 self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*direct"))) 908 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "wictestdisk-*direct"))))
755 909
756 @only_for_arch(['i586', 'i686', 'x86_64']) 910 # TODO this test could also work on aarch64
911 @skipIfNotArch(['i586', 'i686', 'x86_64'])
757 def test_wic_image_type(self): 912 def test_wic_image_type(self):
758 """Test building wic images by bitbake""" 913 """Test building wic images by bitbake"""
759 config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "wic-image-minimal"\n'\ 914 config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "wic-image-minimal"\n'\
760 'MACHINE_FEATURES_append = " efi"\n' 915 'MACHINE_FEATURES:append = " efi"\n'
761 self.append_config(config) 916 self.append_config(config)
762 self.assertEqual(0, bitbake('wic-image-minimal').status) 917 image = 'wic-image-minimal'
918 bitbake(image)
763 self.remove_config(config) 919 self.remove_config(config)
764 920
765 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'MACHINE']) 921 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], image)
766 deploy_dir = bb_vars['DEPLOY_DIR_IMAGE'] 922 prefix = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], '%s.' % bb_vars['IMAGE_LINK_NAME'])
767 machine = bb_vars['MACHINE'] 923
768 prefix = os.path.join(deploy_dir, 'wic-image-minimal-%s.' % machine)
769 # check if we have result image and manifests symlinks 924 # check if we have result image and manifests symlinks
770 # pointing to existing files 925 # pointing to existing files
771 for suffix in ('wic', 'manifest'): 926 for suffix in ('wic', 'manifest'):
772 path = prefix + suffix 927 path = prefix + suffix
773 self.assertTrue(os.path.islink(path)) 928 self.assertTrue(os.path.islink(path), msg="Link %s wasn't generated as expected" % path)
774 self.assertTrue(os.path.isfile(os.path.realpath(path))) 929 self.assertTrue(os.path.isfile(os.path.realpath(path)), msg="File linked to by %s wasn't generated as expected" % path)
775 930
776 @only_for_arch(['i586', 'i686', 'x86_64']) 931 # TODO this should work on aarch64
932 @skipIfNotArch(['i586', 'i686', 'x86_64'])
933 @OETestTag("runqemu")
777 def test_qemu(self): 934 def test_qemu(self):
778 """Test wic-image-minimal under qemu""" 935 """Test wic-image-minimal under qemu"""
779 config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "wic-image-minimal"\n'\ 936 config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "wic-image-minimal"\n'\
780 'MACHINE_FEATURES_append = " efi"\n' 937 'MACHINE_FEATURES:append = " efi"\n'
781 self.append_config(config) 938 self.append_config(config)
782 self.assertEqual(0, bitbake('wic-image-minimal').status) 939 bitbake('wic-image-minimal')
783 self.remove_config(config) 940 self.remove_config(config)
784 941
785 with runqemu('wic-image-minimal', ssh=False) as qemu: 942 with runqemu('wic-image-minimal', ssh=False, runqemuparams='nographic') as qemu:
786 cmd = "mount | grep '^/dev/' | cut -f1,3 -d ' ' | egrep -c -e '/dev/sda1 /boot' " \ 943 cmd = "mount | grep '^/dev/' | cut -f1,3 -d ' ' | egrep -c -e '/dev/sda1 /boot' " \
787 "-e '/dev/root /|/dev/sda2 /' -e '/dev/sda3 /media' -e '/dev/sda4 /mnt'" 944 "-e '/dev/root /|/dev/sda2 /' -e '/dev/sda3 /media' -e '/dev/sda4 /mnt'"
788 status, output = qemu.run_serial(cmd) 945 status, output = qemu.run_serial(cmd)
789 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) 946 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
790 self.assertEqual(output, '4') 947 self.assertEqual(output, '4')
791 cmd = "grep UUID= /etc/fstab" 948 cmd = "grep UUID=2c71ef06-a81d-4735-9d3a-379b69c6bdba /etc/fstab"
792 status, output = qemu.run_serial(cmd) 949 status, output = qemu.run_serial(cmd)
793 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) 950 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
794 self.assertEqual(output, 'UUID=2c71ef06-a81d-4735-9d3a-379b69c6bdba\t/media\text4\tdefaults\t0\t0') 951 self.assertEqual(output, 'UUID=2c71ef06-a81d-4735-9d3a-379b69c6bdba\t/media\text4\tdefaults\t0\t0')
795 952
796 @only_for_arch(['i586', 'i686', 'x86_64']) 953 @skipIfNotArch(['i586', 'i686', 'x86_64'])
954 @OETestTag("runqemu")
797 def test_qemu_efi(self): 955 def test_qemu_efi(self):
798 """Test core-image-minimal efi image under qemu""" 956 """Test core-image-minimal efi image under qemu"""
799 config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "mkefidisk.wks"\n' 957 config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "mkefidisk.wks"\n'
800 self.append_config(config) 958 self.append_config(config)
801 self.assertEqual(0, bitbake('core-image-minimal ovmf').status) 959 bitbake('core-image-minimal ovmf')
802 self.remove_config(config) 960 self.remove_config(config)
803 961
804 with runqemu('core-image-minimal', ssh=False, 962 with runqemu('core-image-minimal', ssh=False,
805 runqemuparams='ovmf', image_fstype='wic') as qemu: 963 runqemuparams='nographic ovmf', image_fstype='wic') as qemu:
806 cmd = "grep sda. /proc/partitions |wc -l" 964 cmd = "grep sda. /proc/partitions |wc -l"
807 status, output = qemu.run_serial(cmd) 965 status, output = qemu.run_serial(cmd)
808 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) 966 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
@@ -831,7 +989,7 @@ class Wic2(WicTestCase):
831 989
832 wksname = os.path.splitext(os.path.basename(wkspath))[0] 990 wksname = os.path.splitext(os.path.basename(wkspath))[0]
833 991
834 wicout = glob(self.resultdir + "%s-*direct" % wksname) 992 wicout = glob(os.path.join(self.resultdir, "%s-*direct" % wksname))
835 993
836 if not wicout: 994 if not wicout:
837 return (p, None) 995 return (p, None)
@@ -976,50 +1134,69 @@ class Wic2(WicTestCase):
976 size = int(size[:-3]) 1134 size = int(size[:-3])
977 self.assertGreaterEqual(size, 204800) 1135 self.assertGreaterEqual(size, 204800)
978 1136
979 @only_for_arch(['i586', 'i686', 'x86_64']) 1137 # TODO this test could also work on aarch64
1138 @skipIfNotArch(['i586', 'i686', 'x86_64'])
1139 @OETestTag("runqemu")
980 def test_rawcopy_plugin_qemu(self): 1140 def test_rawcopy_plugin_qemu(self):
981 """Test rawcopy plugin in qemu""" 1141 """Test rawcopy plugin in qemu"""
982 # build ext4 and wic images 1142 # build ext4 and then use it for a wic image
983 for fstype in ("ext4", "wic"): 1143 config = 'IMAGE_FSTYPES = "ext4"\n'
984 config = 'IMAGE_FSTYPES = "%s"\nWKS_FILE = "test_rawcopy_plugin.wks.in"\n' % fstype 1144 self.append_config(config)
985 self.append_config(config) 1145 bitbake('core-image-minimal')
986 self.assertEqual(0, bitbake('core-image-minimal').status) 1146 image_link_name = get_bb_var('IMAGE_LINK_NAME', 'core-image-minimal')
987 self.remove_config(config) 1147 self.remove_config(config)
988 1148
989 with runqemu('core-image-minimal', ssh=False, image_fstype='wic') as qemu: 1149 config = 'IMAGE_FSTYPES = "wic"\n' \
1150 'IMAGE_LINK_NAME_CORE_IMAGE_MINIMAL = "%s"\n'\
1151 'WKS_FILE = "test_rawcopy_plugin.wks.in"\n'\
1152 % image_link_name
1153 self.append_config(config)
1154 bitbake('core-image-minimal-mtdutils')
1155 self.remove_config(config)
1156
1157 with runqemu('core-image-minimal-mtdutils', ssh=False,
1158 runqemuparams='nographic', image_fstype='wic') as qemu:
990 cmd = "grep sda. /proc/partitions |wc -l" 1159 cmd = "grep sda. /proc/partitions |wc -l"
991 status, output = qemu.run_serial(cmd) 1160 status, output = qemu.run_serial(cmd)
992 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) 1161 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
993 self.assertEqual(output, '2') 1162 self.assertEqual(output, '2')
994 1163
995 def test_rawcopy_plugin(self): 1164 def _rawcopy_plugin(self, fstype):
996 """Test rawcopy plugin""" 1165 """Test rawcopy plugin"""
997 img = 'core-image-minimal' 1166 image = 'core-image-minimal'
998 machine = get_bb_var('MACHINE', img) 1167 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], image)
1168 params = ',unpack' if fstype.endswith('.gz') else ''
999 with NamedTemporaryFile("w", suffix=".wks") as wks: 1169 with NamedTemporaryFile("w", suffix=".wks") as wks:
1000 wks.writelines(['part /boot --active --source bootimg-pcbios\n', 1170 wks.write('part / --source rawcopy --sourceparams="file=%s.%s%s"\n'\
1001 'part / --source rawcopy --sourceparams="file=%s-%s.ext4" --use-uuid\n'\ 1171 % (bb_vars['IMAGE_LINK_NAME'], fstype, params))
1002 % (img, machine),
1003 'bootloader --timeout=0 --append="console=ttyS0,115200n8"\n'])
1004 wks.flush() 1172 wks.flush()
1005 cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir) 1173 cmd = "wic create %s -e %s -o %s" % (wks.name, image, self.resultdir)
1006 runCmd(cmd) 1174 runCmd(cmd)
1007 wksname = os.path.splitext(os.path.basename(wks.name))[0] 1175 wksname = os.path.splitext(os.path.basename(wks.name))[0]
1008 out = glob(self.resultdir + "%s-*direct" % wksname) 1176 out = glob(os.path.join(self.resultdir, "%s-*direct" % wksname))
1009 self.assertEqual(1, len(out)) 1177 self.assertEqual(1, len(out))
1010 1178
1179 def test_rawcopy_plugin(self):
1180 self._rawcopy_plugin('ext4')
1181
1182 def test_rawcopy_plugin_unpack(self):
1183 fstype = 'ext4.gz'
1184 config = 'IMAGE_FSTYPES = "%s"\n' % fstype
1185 self.append_config(config)
1186 self.assertEqual(0, bitbake('core-image-minimal').status)
1187 self.remove_config(config)
1188 self._rawcopy_plugin(fstype)
1189
1011 def test_empty_plugin(self): 1190 def test_empty_plugin(self):
1012 """Test empty plugin""" 1191 """Test empty plugin"""
1013 config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "test_empty_plugin.wks"\n' 1192 config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "test_empty_plugin.wks"\n'
1014 self.append_config(config) 1193 self.append_config(config)
1015 self.assertEqual(0, bitbake('core-image-minimal').status) 1194 image = 'core-image-minimal'
1195 bitbake(image)
1016 self.remove_config(config) 1196 self.remove_config(config)
1017 1197 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], image)
1018 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'MACHINE']) 1198 image_path = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], '%s.wic' % bb_vars['IMAGE_LINK_NAME'])
1019 deploy_dir = bb_vars['DEPLOY_DIR_IMAGE'] 1199 self.assertTrue(os.path.exists(image_path), msg="Image file %s wasn't generated as expected" % image_path)
1020 machine = bb_vars['MACHINE']
1021 image_path = os.path.join(deploy_dir, 'core-image-minimal-%s.wic' % machine)
1022 self.assertEqual(True, os.path.exists(image_path))
1023 1200
1024 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') 1201 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
1025 1202
@@ -1028,15 +1205,17 @@ class Wic2(WicTestCase):
1028 result = runCmd("wic ls %s -n %s | awk -F ' ' '{print $1 \" \" $5}' | grep '^2' | wc -w" % (image_path, sysroot)) 1205 result = runCmd("wic ls %s -n %s | awk -F ' ' '{print $1 \" \" $5}' | grep '^2' | wc -w" % (image_path, sysroot))
1029 self.assertEqual('1', result.output) 1206 self.assertEqual('1', result.output)
1030 1207
1031 @only_for_arch(['i586', 'i686', 'x86_64']) 1208 @skipIfNotArch(['i586', 'i686', 'x86_64'])
1209 @OETestTag("runqemu")
1032 def test_biosplusefi_plugin_qemu(self): 1210 def test_biosplusefi_plugin_qemu(self):
1033 """Test biosplusefi plugin in qemu""" 1211 """Test biosplusefi plugin in qemu"""
1034 config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "test_biosplusefi_plugin.wks"\nMACHINE_FEATURES_append = " efi"\n' 1212 config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "test_biosplusefi_plugin.wks"\nMACHINE_FEATURES:append = " efi"\n'
1035 self.append_config(config) 1213 self.append_config(config)
1036 self.assertEqual(0, bitbake('core-image-minimal').status) 1214 bitbake('core-image-minimal')
1037 self.remove_config(config) 1215 self.remove_config(config)
1038 1216
1039 with runqemu('core-image-minimal', ssh=False, image_fstype='wic') as qemu: 1217 with runqemu('core-image-minimal', ssh=False,
1218 runqemuparams='nographic', image_fstype='wic') as qemu:
1040 # Check that we have ONLY two /dev/sda* partitions (/boot and /) 1219 # Check that we have ONLY two /dev/sda* partitions (/boot and /)
1041 cmd = "grep sda. /proc/partitions | wc -l" 1220 cmd = "grep sda. /proc/partitions | wc -l"
1042 status, output = qemu.run_serial(cmd) 1221 status, output = qemu.run_serial(cmd)
@@ -1059,7 +1238,7 @@ class Wic2(WicTestCase):
1059 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) 1238 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
1060 self.assertEqual(output, '*') 1239 self.assertEqual(output, '*')
1061 1240
1062 @only_for_arch(['i586', 'i686', 'x86_64']) 1241 @skipIfNotArch(['i586', 'i686', 'x86_64'])
1063 def test_biosplusefi_plugin(self): 1242 def test_biosplusefi_plugin(self):
1064 """Test biosplusefi plugin""" 1243 """Test biosplusefi plugin"""
1065 # Wic generation below may fail depending on the order of the unittests 1244 # Wic generation below may fail depending on the order of the unittests
@@ -1068,9 +1247,9 @@ class Wic2(WicTestCase):
1068 # If an image hasn't been built yet, directory ${STAGING_DATADIR}/syslinux won't exists and _get_bootimg_dir() 1247 # If an image hasn't been built yet, directory ${STAGING_DATADIR}/syslinux won't exists and _get_bootimg_dir()
1069 # will raise with "Couldn't find correct bootimg_dir" 1248 # will raise with "Couldn't find correct bootimg_dir"
1070 # The easiest way to work-around this issue is to make sure we already built an image here, hence the bitbake call 1249 # The easiest way to work-around this issue is to make sure we already built an image here, hence the bitbake call
1071 config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "test_biosplusefi_plugin.wks"\nMACHINE_FEATURES_append = " efi"\n' 1250 config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "test_biosplusefi_plugin.wks"\nMACHINE_FEATURES:append = " efi"\n'
1072 self.append_config(config) 1251 self.append_config(config)
1073 self.assertEqual(0, bitbake('core-image-minimal').status) 1252 bitbake('core-image-minimal')
1074 self.remove_config(config) 1253 self.remove_config(config)
1075 1254
1076 img = 'core-image-minimal' 1255 img = 'core-image-minimal'
@@ -1082,9 +1261,60 @@ class Wic2(WicTestCase):
1082 cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir) 1261 cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir)
1083 runCmd(cmd) 1262 runCmd(cmd)
1084 wksname = os.path.splitext(os.path.basename(wks.name))[0] 1263 wksname = os.path.splitext(os.path.basename(wks.name))[0]
1085 out = glob(self.resultdir + "%s-*.direct" % wksname) 1264 out = glob(os.path.join(self.resultdir, "%s-*.direct" % wksname))
1265 self.assertEqual(1, len(out))
1266
1267 @skipIfNotArch(['i586', 'i686', 'x86_64', 'aarch64'])
1268 def test_uefi_kernel(self):
1269 """ Test uefi-kernel in wic """
1270 config = 'IMAGE_EFI_BOOT_FILES="/etc/fstab;testfile"\nIMAGE_FSTYPES = "wic"\nWKS_FILE = "test_uefikernel.wks"\nMACHINE_FEATURES:append = " efi"\n'
1271 self.append_config(config)
1272 bitbake('core-image-minimal')
1273 self.remove_config(config)
1274
1275 img = 'core-image-minimal'
1276 with NamedTemporaryFile("w", suffix=".wks") as wks:
1277 wks.writelines(['part /boot --source bootimg-efi --sourceparams="loader=uefi-kernel"\n'
1278 'part / --source rootfs --fstype=ext4 --align 1024 --use-uuid\n'\
1279 'bootloader --timeout=0 --append="console=ttyS0,115200n8"\n'])
1280 wks.flush()
1281 cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir)
1282 runCmd(cmd)
1283 wksname = os.path.splitext(os.path.basename(wks.name))[0]
1284 out = glob(os.path.join(self.resultdir, "%s-*.direct" % wksname))
1086 self.assertEqual(1, len(out)) 1285 self.assertEqual(1, len(out))
1087 1286
1287 # TODO this test could also work on aarch64
1288 @skipIfNotArch(['i586', 'i686', 'x86_64'])
1289 @OETestTag("runqemu")
1290 def test_efi_plugin_unified_kernel_image_qemu(self):
1291 """Test efi plugin's Unified Kernel Image feature in qemu"""
1292 config = 'IMAGE_FSTYPES = "wic"\n'\
1293 'INITRAMFS_IMAGE = "core-image-minimal-initramfs"\n'\
1294 'WKS_FILE = "test_efi_plugin.wks"\n'\
1295 'MACHINE_FEATURES:append = " efi"\n'
1296 self.append_config(config)
1297 bitbake('core-image-minimal core-image-minimal-initramfs ovmf')
1298 self.remove_config(config)
1299
1300 with runqemu('core-image-minimal', ssh=False,
1301 runqemuparams='nographic ovmf', image_fstype='wic') as qemu:
1302 # Check that /boot has EFI bootx64.efi (required for EFI)
1303 cmd = "ls /boot/EFI/BOOT/bootx64.efi | wc -l"
1304 status, output = qemu.run_serial(cmd)
1305 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
1306 self.assertEqual(output, '1')
1307 # Check that /boot has EFI/Linux/linux.efi (required for Unified Kernel Images auto detection)
1308 cmd = "ls /boot/EFI/Linux/linux.efi | wc -l"
1309 status, output = qemu.run_serial(cmd)
1310 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
1311 self.assertEqual(output, '1')
1312 # Check that /boot doesn't have loader/entries/boot.conf (Unified Kernel Images are auto detected by the bootloader)
1313 cmd = "ls /boot/loader/entries/boot.conf 2&>/dev/null | wc -l"
1314 status, output = qemu.run_serial(cmd)
1315 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
1316 self.assertEqual(output, '0')
1317
1088 def test_fs_types(self): 1318 def test_fs_types(self):
1089 """Test filesystem types for empty and not empty partitions""" 1319 """Test filesystem types for empty and not empty partitions"""
1090 img = 'core-image-minimal' 1320 img = 'core-image-minimal'
@@ -1101,7 +1331,7 @@ class Wic2(WicTestCase):
1101 cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir) 1331 cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir)
1102 runCmd(cmd) 1332 runCmd(cmd)
1103 wksname = os.path.splitext(os.path.basename(wks.name))[0] 1333 wksname = os.path.splitext(os.path.basename(wks.name))[0]
1104 out = glob(self.resultdir + "%s-*direct" % wksname) 1334 out = glob(os.path.join(self.resultdir, "%s-*direct" % wksname))
1105 self.assertEqual(1, len(out)) 1335 self.assertEqual(1, len(out))
1106 1336
1107 def test_kickstart_parser(self): 1337 def test_kickstart_parser(self):
@@ -1113,7 +1343,7 @@ class Wic2(WicTestCase):
1113 cmd = "wic create %s -e core-image-minimal -o %s" % (wks.name, self.resultdir) 1343 cmd = "wic create %s -e core-image-minimal -o %s" % (wks.name, self.resultdir)
1114 runCmd(cmd) 1344 runCmd(cmd)
1115 wksname = os.path.splitext(os.path.basename(wks.name))[0] 1345 wksname = os.path.splitext(os.path.basename(wks.name))[0]
1116 out = glob(self.resultdir + "%s-*direct" % wksname) 1346 out = glob(os.path.join(self.resultdir, "%s-*direct" % wksname))
1117 self.assertEqual(1, len(out)) 1347 self.assertEqual(1, len(out))
1118 1348
1119 def test_image_bootpart_globbed(self): 1349 def test_image_bootpart_globbed(self):
@@ -1124,11 +1354,11 @@ class Wic2(WicTestCase):
1124 self.append_config(config) 1354 self.append_config(config)
1125 runCmd(cmd) 1355 runCmd(cmd)
1126 self.remove_config(config) 1356 self.remove_config(config)
1127 self.assertEqual(1, len(glob(self.resultdir + "sdimage-bootpart-*direct"))) 1357 self.assertEqual(1, len(glob(os.path.join(self.resultdir, "sdimage-bootpart-*direct"))))
1128 1358
1129 def test_sparse_copy(self): 1359 def test_sparse_copy(self):
1130 """Test sparse_copy with FIEMAP and SEEK_HOLE filemap APIs""" 1360 """Test sparse_copy with FIEMAP and SEEK_HOLE filemap APIs"""
1131 libpath = os.path.join(get_bb_var('COREBASE'), 'scripts', 'lib', 'wic') 1361 libpath = os.path.join(self.td['COREBASE'], 'scripts', 'lib', 'wic')
1132 sys.path.insert(0, libpath) 1362 sys.path.insert(0, libpath)
1133 from filemap import FilemapFiemap, FilemapSeek, sparse_copy, ErrorNotSupp 1363 from filemap import FilemapFiemap, FilemapSeek, sparse_copy, ErrorNotSupp
1134 with NamedTemporaryFile("w", suffix=".wic-sparse") as sparse: 1364 with NamedTemporaryFile("w", suffix=".wic-sparse") as sparse:
@@ -1154,12 +1384,148 @@ class Wic2(WicTestCase):
1154 self.assertEqual(dest_stat.st_blocks, 8) 1384 self.assertEqual(dest_stat.st_blocks, 8)
1155 os.unlink(dest) 1385 os.unlink(dest)
1156 1386
1387 def test_mkfs_extraopts(self):
1388 """Test wks option --mkfs-extraopts for empty and not empty partitions"""
1389 img = 'core-image-minimal'
1390 with NamedTemporaryFile("w", suffix=".wks") as wks:
1391 wks.writelines(
1392 ['part ext2 --fstype ext2 --source rootfs --mkfs-extraopts "-D -F -i 8192"\n',
1393 "part btrfs --fstype btrfs --source rootfs --size 40M --mkfs-extraopts='--quiet'\n",
1394 'part squash --fstype squashfs --source rootfs --mkfs-extraopts "-no-sparse -b 4096"\n',
1395 'part emptyvfat --fstype vfat --size 1M --mkfs-extraopts "-S 1024 -s 64"\n',
1396 'part emptymsdos --fstype msdos --size 1M --mkfs-extraopts "-S 1024 -s 64"\n',
1397 'part emptyext2 --fstype ext2 --size 1M --mkfs-extraopts "-D -F -i 8192"\n',
1398 'part emptybtrfs --fstype btrfs --size 100M --mkfs-extraopts "--mixed -K"\n'])
1399 wks.flush()
1400 cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir)
1401 runCmd(cmd)
1402 wksname = os.path.splitext(os.path.basename(wks.name))[0]
1403 out = glob(os.path.join(self.resultdir, "%s-*direct" % wksname))
1404 self.assertEqual(1, len(out))
1405
1406 @skipIfNotArch(['i586', 'i686', 'x86_64'])
1407 @OETestTag("runqemu")
1408 def test_expand_mbr_image(self):
1409 """Test wic write --expand command for mbr image"""
1410 # build an image
1411 config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "directdisk.wks"\n'
1412 self.append_config(config)
1413 image = 'core-image-minimal'
1414 bitbake(image)
1415
1416 # get path to the image
1417 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], image)
1418 image_path = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], '%s.wic' % bb_vars['IMAGE_LINK_NAME'])
1419
1420 self.remove_config(config)
1421
1422 try:
1423 # expand image to 1G
1424 new_image_path = None
1425 with NamedTemporaryFile(mode='wb', suffix='.wic.exp',
1426 dir=bb_vars['DEPLOY_DIR_IMAGE'], delete=False) as sparse:
1427 sparse.truncate(1024 ** 3)
1428 new_image_path = sparse.name
1429
1430 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
1431 cmd = "wic write -n %s --expand 1:0 %s %s" % (sysroot, image_path, new_image_path)
1432 runCmd(cmd)
1433
1434 # check if partitions are expanded
1435 orig = runCmd("wic ls %s -n %s" % (image_path, sysroot))
1436 exp = runCmd("wic ls %s -n %s" % (new_image_path, sysroot))
1437 orig_sizes = [int(line.split()[3]) for line in orig.output.split('\n')[1:]]
1438 exp_sizes = [int(line.split()[3]) for line in exp.output.split('\n')[1:]]
1439 self.assertEqual(orig_sizes[0], exp_sizes[0]) # first partition is not resized
1440 self.assertTrue(orig_sizes[1] < exp_sizes[1], msg="Parition size wasn't enlarged (%s vs %s)" % (orig_sizes[1], exp_sizes[1]))
1441
1442 # Check if all free space is partitioned
1443 result = runCmd("%s/usr/sbin/sfdisk -F %s" % (sysroot, new_image_path))
1444 self.assertIn("0 B, 0 bytes, 0 sectors", result.output)
1445
1446 os.rename(image_path, image_path + '.bak')
1447 os.rename(new_image_path, image_path)
1448
1449 # Check if it boots in qemu
1450 with runqemu('core-image-minimal', ssh=False, runqemuparams='nographic') as qemu:
1451 cmd = "ls /etc/"
1452 status, output = qemu.run_serial('true')
1453 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
1454 finally:
1455 if os.path.exists(new_image_path):
1456 os.unlink(new_image_path)
1457 if os.path.exists(image_path + '.bak'):
1458 os.rename(image_path + '.bak', image_path)
1459
1460 def test_gpt_partition_name(self):
1461 """Test --part-name argument to set partition name in GPT table"""
1462 config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "test_gpt_partition_name.wks"\n'
1463 self.append_config(config)
1464 image = 'core-image-minimal'
1465 bitbake(image)
1466 self.remove_config(config)
1467 deploy_dir = get_bb_var('DEPLOY_DIR_IMAGE')
1468 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], image)
1469 image_path = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], '%s.wic' % bb_vars['IMAGE_LINK_NAME'])
1470
1471 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
1472
1473 # Image is created
1474 self.assertTrue(os.path.exists(image_path), "image file %s doesn't exist" % image_path)
1475
1476 # Check the names of the three partitions
1477 # as listed in test_gpt_partition_name.wks
1478 result = runCmd("%s/usr/sbin/sfdisk --part-label %s 1" % (sysroot, image_path))
1479 self.assertEqual('boot-A', result.output)
1480 result = runCmd("%s/usr/sbin/sfdisk --part-label %s 2" % (sysroot, image_path))
1481 self.assertEqual('root-A', result.output)
1482 # When the --part-name is not defined, the partition name is equal to the --label
1483 result = runCmd("%s/usr/sbin/sfdisk --part-label %s 3" % (sysroot, image_path))
1484 self.assertEqual('ext-space', result.output)
1485
1486 def test_empty_zeroize_plugin(self):
1487 img = 'core-image-minimal'
1488 expected_size = [ 1024*1024, # 1M
1489 512*1024, # 512K
1490 2*1024*1024] # 2M
1491 # Check combination of sourceparams
1492 with NamedTemporaryFile("w", suffix=".wks") as wks:
1493 wks.writelines(
1494 ['part empty --source empty --sourceparams="fill" --ondisk sda --fixed-size 1M\n',
1495 'part empty --source empty --sourceparams="size=512K" --ondisk sda --size 1M --align 1024\n',
1496 'part empty --source empty --sourceparams="size=2048k,bs=512K" --ondisk sda --size 4M --align 1024\n'
1497 ])
1498 wks.flush()
1499 cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir)
1500 runCmd(cmd)
1501 wksname = os.path.splitext(os.path.basename(wks.name))[0]
1502 wicout = glob(os.path.join(self.resultdir, "%s-*direct" % wksname))
1503 # Skip the complete image and just look at the single partitions
1504 for idx, value in enumerate(wicout[1:]):
1505 self.logger.info(wicout[idx])
1506 # Check if partitions are actually zeroized
1507 with open(wicout[idx], mode="rb") as fd:
1508 ba = bytearray(fd.read())
1509 for b in ba:
1510 self.assertEqual(b, 0)
1511 self.assertEqual(expected_size[idx], os.path.getsize(wicout[idx]))
1512
1513 # Check inconsistancy check between "fill" and "--size" parameter
1514 with NamedTemporaryFile("w", suffix=".wks") as wks:
1515 wks.writelines(['part empty --source empty --sourceparams="fill" --ondisk sda --size 1M\n'])
1516 wks.flush()
1517 cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir)
1518 result = runCmd(cmd, ignore_status=True)
1519 self.assertIn("Source parameter 'fill' only works with the '--fixed-size' option, exiting.", result.output)
1520 self.assertNotEqual(0, result.status)
1521
1522class ModifyTests(WicTestCase):
1157 def test_wic_ls(self): 1523 def test_wic_ls(self):
1158 """Test listing image content using 'wic ls'""" 1524 """Test listing image content using 'wic ls'"""
1159 runCmd("wic create wictestdisk " 1525 runCmd("wic create wictestdisk "
1160 "--image-name=core-image-minimal " 1526 "--image-name=core-image-minimal "
1161 "-D -o %s" % self.resultdir) 1527 "-D -o %s" % self.resultdir)
1162 images = glob(self.resultdir + "wictestdisk-*.direct") 1528 images = glob(os.path.join(self.resultdir, "wictestdisk-*.direct"))
1163 self.assertEqual(1, len(images)) 1529 self.assertEqual(1, len(images))
1164 1530
1165 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') 1531 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
@@ -1177,7 +1543,7 @@ class Wic2(WicTestCase):
1177 runCmd("wic create wictestdisk " 1543 runCmd("wic create wictestdisk "
1178 "--image-name=core-image-minimal " 1544 "--image-name=core-image-minimal "
1179 "-D -o %s" % self.resultdir) 1545 "-D -o %s" % self.resultdir)
1180 images = glob(self.resultdir + "wictestdisk-*.direct") 1546 images = glob(os.path.join(self.resultdir, "wictestdisk-*.direct"))
1181 self.assertEqual(1, len(images)) 1547 self.assertEqual(1, len(images))
1182 1548
1183 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') 1549 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
@@ -1195,7 +1561,7 @@ class Wic2(WicTestCase):
1195 # check if file is there 1561 # check if file is there
1196 result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot)) 1562 result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot))
1197 self.assertEqual(7, len(result.output.split('\n'))) 1563 self.assertEqual(7, len(result.output.split('\n')))
1198 self.assertTrue(os.path.basename(testfile.name) in result.output) 1564 self.assertIn(os.path.basename(testfile.name), result.output)
1199 1565
1200 # prepare directory 1566 # prepare directory
1201 testdir = os.path.join(self.resultdir, 'wic-test-cp-dir') 1567 testdir = os.path.join(self.resultdir, 'wic-test-cp-dir')
@@ -1209,13 +1575,13 @@ class Wic2(WicTestCase):
1209 # check if directory is there 1575 # check if directory is there
1210 result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot)) 1576 result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot))
1211 self.assertEqual(8, len(result.output.split('\n'))) 1577 self.assertEqual(8, len(result.output.split('\n')))
1212 self.assertTrue(os.path.basename(testdir) in result.output) 1578 self.assertIn(os.path.basename(testdir), result.output)
1213 1579
1214 # copy the file from the partition and check if it success 1580 # copy the file from the partition and check if it success
1215 dest = '%s-cp' % testfile.name 1581 dest = '%s-cp' % testfile.name
1216 runCmd("wic cp %s:1/%s %s -n %s" % (images[0], 1582 runCmd("wic cp %s:1/%s %s -n %s" % (images[0],
1217 os.path.basename(testfile.name), dest, sysroot)) 1583 os.path.basename(testfile.name), dest, sysroot))
1218 self.assertTrue(os.path.exists(dest)) 1584 self.assertTrue(os.path.exists(dest), msg="File %s wasn't generated as expected" % dest)
1219 1585
1220 1586
1221 def test_wic_rm(self): 1587 def test_wic_rm(self):
@@ -1223,105 +1589,35 @@ class Wic2(WicTestCase):
1223 runCmd("wic create mkefidisk " 1589 runCmd("wic create mkefidisk "
1224 "--image-name=core-image-minimal " 1590 "--image-name=core-image-minimal "
1225 "-D -o %s" % self.resultdir) 1591 "-D -o %s" % self.resultdir)
1226 images = glob(self.resultdir + "mkefidisk-*.direct") 1592 images = glob(os.path.join(self.resultdir, "mkefidisk-*.direct"))
1227 self.assertEqual(1, len(images)) 1593 self.assertEqual(1, len(images))
1228 1594
1229 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') 1595 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
1596 # Not bulletproof but hopefully sufficient
1597 kerneltype = get_bb_var('KERNEL_IMAGETYPE', 'virtual/kernel')
1230 1598
1231 # list directory content of the first partition 1599 # list directory content of the first partition
1232 result = runCmd("wic ls %s:1 -n %s" % (images[0], sysroot)) 1600 result = runCmd("wic ls %s:1 -n %s" % (images[0], sysroot))
1233 self.assertIn('\nBZIMAGE ', result.output) 1601 self.assertIn('\n%s ' % kerneltype.upper(), result.output)
1234 self.assertIn('\nEFI <DIR> ', result.output) 1602 self.assertIn('\nEFI <DIR> ', result.output)
1235 1603
1236 # remove file 1604 # remove file. EFI partitions are case-insensitive so exercise that too
1237 runCmd("wic rm %s:1/bzimage -n %s" % (images[0], sysroot)) 1605 runCmd("wic rm %s:1/%s -n %s" % (images[0], kerneltype.lower(), sysroot))
1238 1606
1239 # remove directory 1607 # remove directory
1240 runCmd("wic rm %s:1/efi -n %s" % (images[0], sysroot)) 1608 runCmd("wic rm %s:1/efi -n %s" % (images[0], sysroot))
1241 1609
1242 # check if they're removed 1610 # check if they're removed
1243 result = runCmd("wic ls %s:1 -n %s" % (images[0], sysroot)) 1611 result = runCmd("wic ls %s:1 -n %s" % (images[0], sysroot))
1244 self.assertNotIn('\nBZIMAGE ', result.output) 1612 self.assertNotIn('\n%s ' % kerneltype.upper(), result.output)
1245 self.assertNotIn('\nEFI <DIR> ', result.output) 1613 self.assertNotIn('\nEFI <DIR> ', result.output)
1246 1614
1247 def test_mkfs_extraopts(self):
1248 """Test wks option --mkfs-extraopts for empty and not empty partitions"""
1249 img = 'core-image-minimal'
1250 with NamedTemporaryFile("w", suffix=".wks") as wks:
1251 wks.writelines(
1252 ['part ext2 --fstype ext2 --source rootfs --mkfs-extraopts "-D -F -i 8192"\n',
1253 "part btrfs --fstype btrfs --source rootfs --size 40M --mkfs-extraopts='--quiet'\n",
1254 'part squash --fstype squashfs --source rootfs --mkfs-extraopts "-no-sparse -b 4096"\n',
1255 'part emptyvfat --fstype vfat --size 1M --mkfs-extraopts "-S 1024 -s 64"\n',
1256 'part emptymsdos --fstype msdos --size 1M --mkfs-extraopts "-S 1024 -s 64"\n',
1257 'part emptyext2 --fstype ext2 --size 1M --mkfs-extraopts "-D -F -i 8192"\n',
1258 'part emptybtrfs --fstype btrfs --size 100M --mkfs-extraopts "--mixed -K"\n'])
1259 wks.flush()
1260 cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir)
1261 runCmd(cmd)
1262 wksname = os.path.splitext(os.path.basename(wks.name))[0]
1263 out = glob(self.resultdir + "%s-*direct" % wksname)
1264 self.assertEqual(1, len(out))
1265
1266 def test_expand_mbr_image(self):
1267 """Test wic write --expand command for mbr image"""
1268 # build an image
1269 config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "directdisk.wks"\n'
1270 self.append_config(config)
1271 self.assertEqual(0, bitbake('core-image-minimal').status)
1272
1273 # get path to the image
1274 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'MACHINE'])
1275 deploy_dir = bb_vars['DEPLOY_DIR_IMAGE']
1276 machine = bb_vars['MACHINE']
1277 image_path = os.path.join(deploy_dir, 'core-image-minimal-%s.wic' % machine)
1278
1279 self.remove_config(config)
1280
1281 try:
1282 # expand image to 1G
1283 new_image_path = None
1284 with NamedTemporaryFile(mode='wb', suffix='.wic.exp',
1285 dir=deploy_dir, delete=False) as sparse:
1286 sparse.truncate(1024 ** 3)
1287 new_image_path = sparse.name
1288
1289 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
1290 cmd = "wic write -n %s --expand 1:0 %s %s" % (sysroot, image_path, new_image_path)
1291 runCmd(cmd)
1292
1293 # check if partitions are expanded
1294 orig = runCmd("wic ls %s -n %s" % (image_path, sysroot))
1295 exp = runCmd("wic ls %s -n %s" % (new_image_path, sysroot))
1296 orig_sizes = [int(line.split()[3]) for line in orig.output.split('\n')[1:]]
1297 exp_sizes = [int(line.split()[3]) for line in exp.output.split('\n')[1:]]
1298 self.assertEqual(orig_sizes[0], exp_sizes[0]) # first partition is not resized
1299 self.assertTrue(orig_sizes[1] < exp_sizes[1])
1300
1301 # Check if all free space is partitioned
1302 result = runCmd("%s/usr/sbin/sfdisk -F %s" % (sysroot, new_image_path))
1303 self.assertTrue("0 B, 0 bytes, 0 sectors" in result.output)
1304
1305 os.rename(image_path, image_path + '.bak')
1306 os.rename(new_image_path, image_path)
1307
1308 # Check if it boots in qemu
1309 with runqemu('core-image-minimal', ssh=False) as qemu:
1310 cmd = "ls /etc/"
1311 status, output = qemu.run_serial('true')
1312 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
1313 finally:
1314 if os.path.exists(new_image_path):
1315 os.unlink(new_image_path)
1316 if os.path.exists(image_path + '.bak'):
1317 os.rename(image_path + '.bak', image_path)
1318
1319 def test_wic_ls_ext(self): 1615 def test_wic_ls_ext(self):
1320 """Test listing content of the ext partition using 'wic ls'""" 1616 """Test listing content of the ext partition using 'wic ls'"""
1321 runCmd("wic create wictestdisk " 1617 runCmd("wic create wictestdisk "
1322 "--image-name=core-image-minimal " 1618 "--image-name=core-image-minimal "
1323 "-D -o %s" % self.resultdir) 1619 "-D -o %s" % self.resultdir)
1324 images = glob(self.resultdir + "wictestdisk-*.direct") 1620 images = glob(os.path.join(self.resultdir, "wictestdisk-*.direct"))
1325 self.assertEqual(1, len(images)) 1621 self.assertEqual(1, len(images))
1326 1622
1327 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') 1623 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
@@ -1329,14 +1625,14 @@ class Wic2(WicTestCase):
1329 # list directory content of the second ext4 partition 1625 # list directory content of the second ext4 partition
1330 result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot)) 1626 result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot))
1331 self.assertTrue(set(['bin', 'home', 'proc', 'usr', 'var', 'dev', 'lib', 'sbin']).issubset( 1627 self.assertTrue(set(['bin', 'home', 'proc', 'usr', 'var', 'dev', 'lib', 'sbin']).issubset(
1332 set(line.split()[-1] for line in result.output.split('\n') if line))) 1628 set(line.split()[-1] for line in result.output.split('\n') if line)), msg="Expected directories not present %s" % result.output)
1333 1629
1334 def test_wic_cp_ext(self): 1630 def test_wic_cp_ext(self):
1335 """Test copy files and directories to the ext partition.""" 1631 """Test copy files and directories to the ext partition."""
1336 runCmd("wic create wictestdisk " 1632 runCmd("wic create wictestdisk "
1337 "--image-name=core-image-minimal " 1633 "--image-name=core-image-minimal "
1338 "-D -o %s" % self.resultdir) 1634 "-D -o %s" % self.resultdir)
1339 images = glob(self.resultdir + "wictestdisk-*.direct") 1635 images = glob(os.path.join(self.resultdir, "wictestdisk-*.direct"))
1340 self.assertEqual(1, len(images)) 1636 self.assertEqual(1, len(images))
1341 1637
1342 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') 1638 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
@@ -1344,7 +1640,7 @@ class Wic2(WicTestCase):
1344 # list directory content of the ext4 partition 1640 # list directory content of the ext4 partition
1345 result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot)) 1641 result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot))
1346 dirs = set(line.split()[-1] for line in result.output.split('\n') if line) 1642 dirs = set(line.split()[-1] for line in result.output.split('\n') if line)
1347 self.assertTrue(set(['bin', 'home', 'proc', 'usr', 'var', 'dev', 'lib', 'sbin']).issubset(dirs)) 1643 self.assertTrue(set(['bin', 'home', 'proc', 'usr', 'var', 'dev', 'lib', 'sbin']).issubset(dirs), msg="Expected directories not present %s" % dirs)
1348 1644
1349 with NamedTemporaryFile("w", suffix=".wic-cp") as testfile: 1645 with NamedTemporaryFile("w", suffix=".wic-cp") as testfile:
1350 testfile.write("test") 1646 testfile.write("test")
@@ -1359,12 +1655,12 @@ class Wic2(WicTestCase):
1359 1655
1360 # check if the file to copy is in the partition 1656 # check if the file to copy is in the partition
1361 result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot)) 1657 result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot))
1362 self.assertTrue('fstab' in [line.split()[-1] for line in result.output.split('\n') if line]) 1658 self.assertIn('fstab', [line.split()[-1] for line in result.output.split('\n') if line])
1363 1659
1364 # copy file from the partition, replace the temporary file content with it and 1660 # copy file from the partition, replace the temporary file content with it and
1365 # check for the file size to validate the copy 1661 # check for the file size to validate the copy
1366 runCmd("wic cp %s:2/etc/fstab %s -n %s" % (images[0], testfile.name, sysroot)) 1662 runCmd("wic cp %s:2/etc/fstab %s -n %s" % (images[0], testfile.name, sysroot))
1367 self.assertTrue(os.stat(testfile.name).st_size > 0) 1663 self.assertTrue(os.stat(testfile.name).st_size > 0, msg="Filesize not as expected %s" % os.stat(testfile.name).st_size)
1368 1664
1369 1665
1370 def test_wic_rm_ext(self): 1666 def test_wic_rm_ext(self):
@@ -1372,25 +1668,25 @@ class Wic2(WicTestCase):
1372 runCmd("wic create mkefidisk " 1668 runCmd("wic create mkefidisk "
1373 "--image-name=core-image-minimal " 1669 "--image-name=core-image-minimal "
1374 "-D -o %s" % self.resultdir) 1670 "-D -o %s" % self.resultdir)
1375 images = glob(self.resultdir + "mkefidisk-*.direct") 1671 images = glob(os.path.join(self.resultdir, "mkefidisk-*.direct"))
1376 self.assertEqual(1, len(images)) 1672 self.assertEqual(1, len(images))
1377 1673
1378 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') 1674 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
1379 1675
1380 # list directory content of the /etc directory on ext4 partition 1676 # list directory content of the /etc directory on ext4 partition
1381 result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot)) 1677 result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot))
1382 self.assertTrue('fstab' in [line.split()[-1] for line in result.output.split('\n') if line]) 1678 self.assertIn('fstab', [line.split()[-1] for line in result.output.split('\n') if line])
1383 1679
1384 # remove file 1680 # remove file
1385 runCmd("wic rm %s:2/etc/fstab -n %s" % (images[0], sysroot)) 1681 runCmd("wic rm %s:2/etc/fstab -n %s" % (images[0], sysroot))
1386 1682
1387 # check if it's removed 1683 # check if it's removed
1388 result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot)) 1684 result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot))
1389 self.assertTrue('fstab' not in [line.split()[-1] for line in result.output.split('\n') if line]) 1685 self.assertNotIn('fstab', [line.split()[-1] for line in result.output.split('\n') if line])
1390 1686
1391 # remove non-empty directory 1687 # remove non-empty directory
1392 runCmd("wic rm -r %s:2/etc/ -n %s" % (images[0], sysroot)) 1688 runCmd("wic rm -r %s:2/etc/ -n %s" % (images[0], sysroot))
1393 1689
1394 # check if it's removed 1690 # check if it's removed
1395 result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot)) 1691 result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot))
1396 self.assertTrue('etc' not in [line.split()[-1] for line in result.output.split('\n') if line]) 1692 self.assertNotIn('etc', [line.split()[-1] for line in result.output.split('\n') if line])