Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright (c) 2015, Intel Corporation. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0-only |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5 | # |
| 6 | # AUTHORS |
| 7 | # Ed Bartosh <ed.bartosh@linux.intel.com> |
| 8 | |
| 9 | """Test cases for wic.""" |
| 10 | |
| 11 | import os |
| 12 | import sys |
| 13 | import unittest |
| 14 | |
| 15 | from glob import glob |
| 16 | from shutil import rmtree, copy |
| 17 | from functools import wraps, lru_cache |
| 18 | from tempfile import NamedTemporaryFile |
| 19 | |
| 20 | from oeqa.selftest.case import OESelftestTestCase |
| 21 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars, runqemu |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 22 | |
| 23 | |
| 24 | @lru_cache(maxsize=32) |
| 25 | def 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 | |
| 30 | def 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 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 47 | def extract_files(debugfs_output): |
| 48 | """ |
| 49 | extract file names from the output of debugfs -R 'ls -p', |
| 50 | which looks like this: |
| 51 | |
| 52 | /2/040755/0/0/.//\n |
| 53 | /2/040755/0/0/..//\n |
| 54 | /11/040700/0/0/lost+found^M//\n |
| 55 | /12/040755/1002/1002/run//\n |
| 56 | /13/040755/1002/1002/sys//\n |
| 57 | /14/040755/1002/1002/bin//\n |
| 58 | /80/040755/1002/1002/var//\n |
| 59 | /92/040755/1002/1002/tmp//\n |
| 60 | """ |
| 61 | # NOTE the occasional ^M in file names |
| 62 | return [line.split('/')[5].strip() for line in \ |
| 63 | debugfs_output.strip().split('/\n')] |
| 64 | |
| 65 | def files_own_by_root(debugfs_output): |
| 66 | for line in debugfs_output.strip().split('/\n'): |
| 67 | if line.split('/')[3:5] != ['0', '0']: |
| 68 | print(debugfs_output) |
| 69 | return False |
| 70 | return True |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 71 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 72 | class WicTestCase(OESelftestTestCase): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 73 | """Wic test class.""" |
| 74 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 75 | image_is_ready = False |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 76 | wicenv_cache = {} |
| 77 | |
| 78 | def setUpLocal(self): |
| 79 | """This code is executed before each test method.""" |
Brad Bishop | c4ea075 | 2018-11-15 14:30:15 -0800 | [diff] [blame] | 80 | self.resultdir = self.builddir + "/wic-tmp/" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 81 | super(WicTestCase, self).setUpLocal() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 82 | |
| 83 | # 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 |
| 85 | # setUpClass being unavailable. |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 86 | if not WicTestCase.image_is_ready: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 87 | if get_bb_var('USE_NLS') == 'yes': |
| 88 | bitbake('wic-tools') |
| 89 | else: |
| 90 | self.skipTest('wic-tools cannot be built due its (intltool|gettext)-native dependency and NLS disable') |
| 91 | |
| 92 | bitbake('core-image-minimal') |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 93 | bitbake('core-image-minimal-mtdutils') |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 94 | WicTestCase.image_is_ready = True |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 95 | |
| 96 | rmtree(self.resultdir, ignore_errors=True) |
| 97 | |
| 98 | def tearDownLocal(self): |
| 99 | """Remove resultdir as it may contain images.""" |
| 100 | rmtree(self.resultdir, ignore_errors=True) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 101 | super(WicTestCase, self).tearDownLocal() |
| 102 | |
| 103 | def _get_image_env_path(self, image): |
| 104 | """Generate and obtain the path to <image>.env""" |
| 105 | if image not in WicTestCase.wicenv_cache: |
| 106 | self.assertEqual(0, bitbake('%s -c do_rootfs_wicenv' % image).status) |
| 107 | bb_vars = get_bb_vars(['STAGING_DIR', 'MACHINE'], image) |
| 108 | stdir = bb_vars['STAGING_DIR'] |
| 109 | machine = bb_vars['MACHINE'] |
| 110 | WicTestCase.wicenv_cache[image] = os.path.join(stdir, machine, 'imgdata') |
| 111 | return WicTestCase.wicenv_cache[image] |
| 112 | |
| 113 | class Wic(WicTestCase): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 114 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 115 | def test_version(self): |
| 116 | """Test wic --version""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 117 | runCmd('wic --version') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 118 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 119 | def test_help(self): |
| 120 | """Test wic --help and wic -h""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 121 | runCmd('wic --help') |
| 122 | runCmd('wic -h') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 123 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 124 | def test_createhelp(self): |
| 125 | """Test wic create --help""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 126 | runCmd('wic create --help') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 127 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 128 | def test_listhelp(self): |
| 129 | """Test wic list --help""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 130 | runCmd('wic list --help') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 131 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 132 | def test_help_create(self): |
| 133 | """Test wic help create""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 134 | runCmd('wic help create') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 135 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 136 | def test_help_list(self): |
| 137 | """Test wic help list""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 138 | runCmd('wic help list') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 139 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 140 | def test_help_overview(self): |
| 141 | """Test wic help overview""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 142 | runCmd('wic help overview') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 143 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 144 | def test_help_plugins(self): |
| 145 | """Test wic help plugins""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 146 | runCmd('wic help plugins') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 147 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 148 | def test_help_kickstart(self): |
| 149 | """Test wic help kickstart""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 150 | runCmd('wic help kickstart') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 151 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 152 | def test_list_images(self): |
| 153 | """Test wic list images""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 154 | runCmd('wic list images') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 155 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 156 | def test_list_source_plugins(self): |
| 157 | """Test wic list source-plugins""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 158 | runCmd('wic list source-plugins') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 159 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 160 | def test_listed_images_help(self): |
| 161 | """Test wic listed images help""" |
| 162 | output = runCmd('wic list images').output |
| 163 | imagelist = [line.split()[0] for line in output.splitlines()] |
| 164 | for image in imagelist: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 165 | runCmd('wic list %s help' % image) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 166 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 167 | def test_unsupported_subcommand(self): |
| 168 | """Test unsupported subcommand""" |
| 169 | self.assertNotEqual(0, runCmd('wic unsupported', ignore_status=True).status) |
| 170 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 171 | def test_no_command(self): |
| 172 | """Test wic without command""" |
| 173 | self.assertEqual(1, runCmd('wic', ignore_status=True).status) |
| 174 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 175 | def test_build_image_name(self): |
| 176 | """Test wic create wictestdisk --image-name=core-image-minimal""" |
| 177 | cmd = "wic create wictestdisk --image-name=core-image-minimal -o %s" % self.resultdir |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 178 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 179 | self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct"))) |
| 180 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 181 | @only_for_arch(['i586', 'i686', 'x86_64']) |
| 182 | def test_gpt_image(self): |
| 183 | """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 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 185 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 186 | self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct"))) |
| 187 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 188 | @only_for_arch(['i586', 'i686', 'x86_64']) |
| 189 | def test_iso_image(self): |
| 190 | """Test creation of hybrid iso image with legacy and EFI boot""" |
| 191 | config = 'INITRAMFS_IMAGE = "core-image-minimal-initramfs"\n'\ |
| 192 | 'MACHINE_FEATURES_append = " efi"\n'\ |
| 193 | 'DEPENDS_pn-core-image-minimal += "syslinux"\n' |
| 194 | self.append_config(config) |
Brad Bishop | c4ea075 | 2018-11-15 14:30:15 -0800 | [diff] [blame] | 195 | bitbake('core-image-minimal core-image-minimal-initramfs') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 196 | self.remove_config(config) |
| 197 | cmd = "wic create mkhybridiso --image-name core-image-minimal -o %s" % self.resultdir |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 198 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 199 | self.assertEqual(1, len(glob(self.resultdir + "HYBRID_ISO_IMG-*.direct"))) |
| 200 | self.assertEqual(1, len(glob(self.resultdir + "HYBRID_ISO_IMG-*.iso"))) |
| 201 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 202 | @only_for_arch(['i586', 'i686', 'x86_64']) |
| 203 | def test_qemux86_directdisk(self): |
| 204 | """Test creation of qemux-86-directdisk image""" |
| 205 | cmd = "wic create qemux86-directdisk -e core-image-minimal -o %s" % self.resultdir |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 206 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 207 | self.assertEqual(1, len(glob(self.resultdir + "qemux86-directdisk-*direct"))) |
| 208 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 209 | @only_for_arch(['i586', 'i686', 'x86_64']) |
| 210 | def test_mkefidisk(self): |
| 211 | """Test creation of mkefidisk image""" |
| 212 | cmd = "wic create mkefidisk -e core-image-minimal -o %s" % self.resultdir |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 213 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 214 | self.assertEqual(1, len(glob(self.resultdir + "mkefidisk-*direct"))) |
| 215 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 216 | @only_for_arch(['i586', 'i686', 'x86_64']) |
| 217 | def test_bootloader_config(self): |
| 218 | """Test creation of directdisk-bootloader-config image""" |
| 219 | config = 'DEPENDS_pn-core-image-minimal += "syslinux"\n' |
| 220 | self.append_config(config) |
| 221 | bitbake('core-image-minimal') |
| 222 | self.remove_config(config) |
| 223 | cmd = "wic create directdisk-bootloader-config -e core-image-minimal -o %s" % self.resultdir |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 224 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 225 | self.assertEqual(1, len(glob(self.resultdir + "directdisk-bootloader-config-*direct"))) |
| 226 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 227 | @only_for_arch(['i586', 'i686', 'x86_64']) |
| 228 | def test_systemd_bootdisk(self): |
| 229 | """Test creation of systemd-bootdisk image""" |
| 230 | config = 'MACHINE_FEATURES_append = " efi"\n' |
| 231 | self.append_config(config) |
| 232 | bitbake('core-image-minimal') |
| 233 | self.remove_config(config) |
| 234 | cmd = "wic create systemd-bootdisk -e core-image-minimal -o %s" % self.resultdir |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 235 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 236 | self.assertEqual(1, len(glob(self.resultdir + "systemd-bootdisk-*direct"))) |
| 237 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 238 | def test_sdimage_bootpart(self): |
| 239 | """Test creation of sdimage-bootpart image""" |
| 240 | cmd = "wic create sdimage-bootpart -e core-image-minimal -o %s" % self.resultdir |
| 241 | kimgtype = get_bb_var('KERNEL_IMAGETYPE', 'core-image-minimal') |
| 242 | self.write_config('IMAGE_BOOT_FILES = "%s"\n' % kimgtype) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 243 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 244 | self.assertEqual(1, len(glob(self.resultdir + "sdimage-bootpart-*direct"))) |
| 245 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 246 | @only_for_arch(['i586', 'i686', 'x86_64']) |
| 247 | def test_default_output_dir(self): |
| 248 | """Test default output location""" |
| 249 | for fname in glob("directdisk-*.direct"): |
| 250 | os.remove(fname) |
| 251 | config = 'DEPENDS_pn-core-image-minimal += "syslinux"\n' |
| 252 | self.append_config(config) |
| 253 | bitbake('core-image-minimal') |
| 254 | self.remove_config(config) |
| 255 | cmd = "wic create directdisk -e core-image-minimal" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 256 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 257 | self.assertEqual(1, len(glob("directdisk-*.direct"))) |
| 258 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 259 | @only_for_arch(['i586', 'i686', 'x86_64']) |
| 260 | def test_build_artifacts(self): |
| 261 | """Test wic create directdisk providing all artifacts.""" |
| 262 | bb_vars = get_bb_vars(['STAGING_DATADIR', 'RECIPE_SYSROOT_NATIVE'], |
| 263 | 'wic-tools') |
| 264 | bb_vars.update(get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_ROOTFS'], |
| 265 | 'core-image-minimal')) |
| 266 | bbvars = {key.lower(): value for key, value in bb_vars.items()} |
| 267 | bbvars['resultdir'] = self.resultdir |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 268 | runCmd("wic create directdisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 269 | "-b %(staging_datadir)s " |
| 270 | "-k %(deploy_dir_image)s " |
| 271 | "-n %(recipe_sysroot_native)s " |
| 272 | "-r %(image_rootfs)s " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 273 | "-o %(resultdir)s" % bbvars) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 274 | self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct"))) |
| 275 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 276 | def test_compress_gzip(self): |
| 277 | """Test compressing an image with gzip""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 278 | runCmd("wic create wictestdisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 279 | "--image-name core-image-minimal " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 280 | "-c gzip -o %s" % self.resultdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 281 | self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct.gz"))) |
| 282 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 283 | def test_compress_bzip2(self): |
| 284 | """Test compressing an image with bzip2""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 285 | runCmd("wic create wictestdisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 286 | "--image-name=core-image-minimal " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 287 | "-c bzip2 -o %s" % self.resultdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 288 | self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct.bz2"))) |
| 289 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 290 | def test_compress_xz(self): |
| 291 | """Test compressing an image with xz""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 292 | runCmd("wic create wictestdisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 293 | "--image-name=core-image-minimal " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 294 | "--compress-with=xz -o %s" % self.resultdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 295 | self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct.xz"))) |
| 296 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 297 | def test_wrong_compressor(self): |
| 298 | """Test how wic breaks if wrong compressor is provided""" |
| 299 | self.assertEqual(2, runCmd("wic create wictestdisk " |
| 300 | "--image-name=core-image-minimal " |
| 301 | "-c wrong -o %s" % self.resultdir, |
| 302 | ignore_status=True).status) |
| 303 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 304 | def test_debug_short(self): |
| 305 | """Test -D option""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 306 | runCmd("wic create wictestdisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 307 | "--image-name=core-image-minimal " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 308 | "-D -o %s" % self.resultdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 309 | self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct"))) |
| 310 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 311 | def test_debug_long(self): |
| 312 | """Test --debug option""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 313 | runCmd("wic create wictestdisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 314 | "--image-name=core-image-minimal " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 315 | "--debug -o %s" % self.resultdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 316 | self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct"))) |
| 317 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 318 | def test_skip_build_check_short(self): |
| 319 | """Test -s option""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 320 | runCmd("wic create wictestdisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 321 | "--image-name=core-image-minimal " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 322 | "-s -o %s" % self.resultdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 323 | self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct"))) |
| 324 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 325 | def test_skip_build_check_long(self): |
| 326 | """Test --skip-build-check option""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 327 | runCmd("wic create wictestdisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 328 | "--image-name=core-image-minimal " |
| 329 | "--skip-build-check " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 330 | "--outdir %s" % self.resultdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 331 | self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct"))) |
| 332 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 333 | def test_build_rootfs_short(self): |
| 334 | """Test -f option""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 335 | runCmd("wic create wictestdisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 336 | "--image-name=core-image-minimal " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 337 | "-f -o %s" % self.resultdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 338 | self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct"))) |
| 339 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 340 | def test_build_rootfs_long(self): |
| 341 | """Test --build-rootfs option""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 342 | runCmd("wic create wictestdisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 343 | "--image-name=core-image-minimal " |
| 344 | "--build-rootfs " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 345 | "--outdir %s" % self.resultdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 346 | self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*.direct"))) |
| 347 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 348 | @only_for_arch(['i586', 'i686', 'x86_64']) |
| 349 | def test_rootfs_indirect_recipes(self): |
| 350 | """Test usage of rootfs plugin with rootfs recipes""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 351 | runCmd("wic create directdisk-multi-rootfs " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 352 | "--image-name=core-image-minimal " |
| 353 | "--rootfs rootfs1=core-image-minimal " |
| 354 | "--rootfs rootfs2=core-image-minimal " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 355 | "--outdir %s" % self.resultdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 356 | self.assertEqual(1, len(glob(self.resultdir + "directdisk-multi-rootfs*.direct"))) |
| 357 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 358 | @only_for_arch(['i586', 'i686', 'x86_64']) |
| 359 | def test_rootfs_artifacts(self): |
| 360 | """Test usage of rootfs plugin with rootfs paths""" |
| 361 | bb_vars = get_bb_vars(['STAGING_DATADIR', 'RECIPE_SYSROOT_NATIVE'], |
| 362 | 'wic-tools') |
| 363 | bb_vars.update(get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_ROOTFS'], |
| 364 | 'core-image-minimal')) |
| 365 | bbvars = {key.lower(): value for key, value in bb_vars.items()} |
| 366 | bbvars['wks'] = "directdisk-multi-rootfs" |
| 367 | bbvars['resultdir'] = self.resultdir |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 368 | runCmd("wic create %(wks)s " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 369 | "--bootimg-dir=%(staging_datadir)s " |
| 370 | "--kernel-dir=%(deploy_dir_image)s " |
| 371 | "--native-sysroot=%(recipe_sysroot_native)s " |
| 372 | "--rootfs-dir rootfs1=%(image_rootfs)s " |
| 373 | "--rootfs-dir rootfs2=%(image_rootfs)s " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 374 | "--outdir %(resultdir)s" % bbvars) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 375 | self.assertEqual(1, len(glob(self.resultdir + "%(wks)s-*.direct" % bbvars))) |
| 376 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 377 | def test_exclude_path(self): |
| 378 | """Test --exclude-path wks option.""" |
| 379 | |
| 380 | oldpath = os.environ['PATH'] |
| 381 | os.environ['PATH'] = get_bb_var("PATH", "wic-tools") |
| 382 | |
| 383 | try: |
| 384 | wks_file = 'temp.wks' |
| 385 | with open(wks_file, 'w') as wks: |
| 386 | rootfs_dir = get_bb_var('IMAGE_ROOTFS', 'core-image-minimal') |
| 387 | wks.write(""" |
| 388 | part / --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path usr |
| 389 | part /usr --source rootfs --ondisk mmcblk0 --fstype=ext4 --rootfs-dir %s/usr |
| 390 | part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --rootfs-dir %s/usr""" |
| 391 | % (rootfs_dir, rootfs_dir)) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 392 | runCmd("wic create %s -e core-image-minimal -o %s" \ |
| 393 | % (wks_file, self.resultdir)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 394 | |
| 395 | os.remove(wks_file) |
| 396 | wicout = glob(self.resultdir + "%s-*direct" % 'temp') |
| 397 | self.assertEqual(1, len(wicout)) |
| 398 | |
| 399 | wicimg = wicout[0] |
| 400 | |
| 401 | # verify partition size with wic |
| 402 | res = runCmd("parted -m %s unit b p 2>/dev/null" % wicimg) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 403 | |
| 404 | # parse parted output which looks like this: |
| 405 | # BYT;\n |
| 406 | # /var/tmp/wic/build/tmpfwvjjkf_-201611101222-hda.direct:200MiB:file:512:512:msdos::;\n |
| 407 | # 1:0.00MiB:200MiB:200MiB:ext4::;\n |
| 408 | partlns = res.output.splitlines()[2:] |
| 409 | |
| 410 | self.assertEqual(3, len(partlns)) |
| 411 | |
| 412 | for part in [1, 2, 3]: |
| 413 | part_file = os.path.join(self.resultdir, "selftest_img.part%d" % part) |
| 414 | partln = partlns[part-1].split(":") |
| 415 | self.assertEqual(7, len(partln)) |
| 416 | start = int(partln[1].rstrip("B")) / 512 |
| 417 | length = int(partln[3].rstrip("B")) / 512 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 418 | runCmd("dd if=%s of=%s skip=%d count=%d" % |
| 419 | (wicimg, part_file, start, length)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 420 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 421 | # Test partition 1, should contain the normal root directories, except |
| 422 | # /usr. |
| 423 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % \ |
| 424 | os.path.join(self.resultdir, "selftest_img.part1")) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 425 | files = extract_files(res.output) |
| 426 | self.assertIn("etc", files) |
| 427 | self.assertNotIn("usr", files) |
| 428 | |
| 429 | # Partition 2, should contain common directories for /usr, not root |
| 430 | # directories. |
| 431 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % \ |
| 432 | os.path.join(self.resultdir, "selftest_img.part2")) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 433 | files = extract_files(res.output) |
| 434 | self.assertNotIn("etc", files) |
| 435 | self.assertNotIn("usr", files) |
| 436 | self.assertIn("share", files) |
| 437 | |
| 438 | # Partition 3, should contain the same as partition 2, including the bin |
| 439 | # directory, but not the files inside it. |
| 440 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % \ |
| 441 | os.path.join(self.resultdir, "selftest_img.part3")) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 442 | files = extract_files(res.output) |
| 443 | self.assertNotIn("etc", files) |
| 444 | self.assertNotIn("usr", files) |
| 445 | self.assertIn("share", files) |
| 446 | self.assertIn("bin", files) |
| 447 | res = runCmd("debugfs -R 'ls -p bin' %s 2>/dev/null" % \ |
| 448 | os.path.join(self.resultdir, "selftest_img.part3")) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 449 | files = extract_files(res.output) |
| 450 | self.assertIn(".", files) |
| 451 | self.assertIn("..", files) |
| 452 | self.assertEqual(2, len(files)) |
| 453 | |
| 454 | for part in [1, 2, 3]: |
| 455 | part_file = os.path.join(self.resultdir, "selftest_img.part%d" % part) |
| 456 | os.remove(part_file) |
| 457 | |
| 458 | finally: |
| 459 | os.environ['PATH'] = oldpath |
| 460 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 461 | def test_include_path(self): |
| 462 | """Test --include-path wks option.""" |
| 463 | |
| 464 | oldpath = os.environ['PATH'] |
| 465 | os.environ['PATH'] = get_bb_var("PATH", "wic-tools") |
| 466 | |
| 467 | try: |
| 468 | include_path = os.path.join(self.resultdir, 'test-include') |
| 469 | os.makedirs(include_path) |
| 470 | with open(os.path.join(include_path, 'test-file'), 'w') as t: |
| 471 | t.write("test\n") |
| 472 | wks_file = os.path.join(include_path, 'temp.wks') |
| 473 | with open(wks_file, 'w') as wks: |
| 474 | rootfs_dir = get_bb_var('IMAGE_ROOTFS', 'core-image-minimal') |
| 475 | wks.write(""" |
| 476 | part /part1 --source rootfs --ondisk mmcblk0 --fstype=ext4 |
| 477 | part /part2 --source rootfs --ondisk mmcblk0 --fstype=ext4 --include-path %s""" |
| 478 | % (include_path)) |
| 479 | runCmd("wic create %s -e core-image-minimal -o %s" \ |
| 480 | % (wks_file, self.resultdir)) |
| 481 | |
| 482 | part1 = glob(os.path.join(self.resultdir, 'temp-*.direct.p1'))[0] |
| 483 | part2 = glob(os.path.join(self.resultdir, 'temp-*.direct.p2'))[0] |
| 484 | |
| 485 | # Test partition 1, should not contain 'test-file' |
| 486 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part1)) |
| 487 | files = extract_files(res.output) |
| 488 | self.assertNotIn('test-file', files) |
| 489 | self.assertEqual(True, files_own_by_root(res.output)) |
| 490 | |
| 491 | # Test partition 2, should contain 'test-file' |
| 492 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part2)) |
| 493 | files = extract_files(res.output) |
| 494 | self.assertIn('test-file', files) |
| 495 | self.assertEqual(True, files_own_by_root(res.output)) |
| 496 | |
| 497 | finally: |
| 498 | os.environ['PATH'] = oldpath |
| 499 | |
| 500 | def test_include_path_embeded(self): |
| 501 | """Test --include-path wks option.""" |
| 502 | |
| 503 | oldpath = os.environ['PATH'] |
| 504 | os.environ['PATH'] = get_bb_var("PATH", "wic-tools") |
| 505 | |
| 506 | try: |
| 507 | include_path = os.path.join(self.resultdir, 'test-include') |
| 508 | os.makedirs(include_path) |
| 509 | with open(os.path.join(include_path, 'test-file'), 'w') as t: |
| 510 | t.write("test\n") |
| 511 | wks_file = os.path.join(include_path, 'temp.wks') |
| 512 | with open(wks_file, 'w') as wks: |
| 513 | wks.write(""" |
| 514 | part / --source rootfs --fstype=ext4 --include-path %s --include-path core-image-minimal-mtdutils export/""" |
| 515 | % (include_path)) |
| 516 | runCmd("wic create %s -e core-image-minimal -o %s" \ |
| 517 | % (wks_file, self.resultdir)) |
| 518 | |
| 519 | part1 = glob(os.path.join(self.resultdir, 'temp-*.direct.p1'))[0] |
| 520 | |
| 521 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part1)) |
| 522 | files = extract_files(res.output) |
| 523 | self.assertIn('test-file', files) |
| 524 | self.assertEqual(True, files_own_by_root(res.output)) |
| 525 | |
| 526 | res = runCmd("debugfs -R 'ls -p /export/etc/' %s 2>/dev/null" % (part1)) |
| 527 | files = extract_files(res.output) |
| 528 | self.assertIn('passwd', files) |
| 529 | self.assertEqual(True, files_own_by_root(res.output)) |
| 530 | |
| 531 | finally: |
| 532 | os.environ['PATH'] = oldpath |
| 533 | |
| 534 | def test_include_path_errors(self): |
| 535 | """Test --include-path wks option error handling.""" |
| 536 | wks_file = 'temp.wks' |
| 537 | |
| 538 | # Absolute argument. |
| 539 | with open(wks_file, 'w') as wks: |
| 540 | wks.write("part / --source rootfs --fstype=ext4 --include-path core-image-minimal-mtdutils /export") |
| 541 | self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \ |
| 542 | % (wks_file, self.resultdir), ignore_status=True).status) |
| 543 | os.remove(wks_file) |
| 544 | |
| 545 | # Argument pointing to parent directory. |
| 546 | with open(wks_file, 'w') as wks: |
| 547 | wks.write("part / --source rootfs --fstype=ext4 --include-path core-image-minimal-mtdutils ././..") |
| 548 | self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \ |
| 549 | % (wks_file, self.resultdir), ignore_status=True).status) |
| 550 | os.remove(wks_file) |
| 551 | |
| 552 | # 3 Argument pointing to parent directory. |
| 553 | with open(wks_file, 'w') as wks: |
| 554 | wks.write("part / --source rootfs --fstype=ext4 --include-path core-image-minimal-mtdutils export/ dummy") |
| 555 | self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \ |
| 556 | % (wks_file, self.resultdir), ignore_status=True).status) |
| 557 | os.remove(wks_file) |
| 558 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 559 | def test_exclude_path_errors(self): |
| 560 | """Test --exclude-path wks option error handling.""" |
| 561 | wks_file = 'temp.wks' |
| 562 | |
| 563 | # Absolute argument. |
| 564 | with open(wks_file, 'w') as wks: |
| 565 | wks.write("part / --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path /usr") |
| 566 | self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \ |
| 567 | % (wks_file, self.resultdir), ignore_status=True).status) |
| 568 | os.remove(wks_file) |
| 569 | |
| 570 | # Argument pointing to parent directory. |
| 571 | with open(wks_file, 'w') as wks: |
| 572 | wks.write("part / --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path ././..") |
| 573 | self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \ |
| 574 | % (wks_file, self.resultdir), ignore_status=True).status) |
| 575 | os.remove(wks_file) |
| 576 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 577 | def test_permissions(self): |
| 578 | """Test permissions are respected""" |
| 579 | |
| 580 | oldpath = os.environ['PATH'] |
| 581 | os.environ['PATH'] = get_bb_var("PATH", "wic-tools") |
| 582 | |
| 583 | t_normal = """ |
| 584 | part / --source rootfs --fstype=ext4 |
| 585 | """ |
| 586 | t_exclude = """ |
| 587 | part / --source rootfs --fstype=ext4 --exclude-path=home |
| 588 | """ |
| 589 | t_multi = """ |
| 590 | part / --source rootfs --ondisk sda --fstype=ext4 |
| 591 | part /export --source rootfs --rootfs=core-image-minimal-mtdutils --fstype=ext4 |
| 592 | """ |
| 593 | t_change = """ |
| 594 | part / --source rootfs --ondisk sda --fstype=ext4 --exclude-path=etc/Â Â |
| 595 | part /etc --source rootfs --fstype=ext4 --change-directory=etc |
| 596 | """ |
| 597 | tests = [t_normal, t_exclude, t_multi, t_change] |
| 598 | |
| 599 | try: |
| 600 | for test in tests: |
| 601 | include_path = os.path.join(self.resultdir, 'test-include') |
| 602 | os.makedirs(include_path) |
| 603 | wks_file = os.path.join(include_path, 'temp.wks') |
| 604 | with open(wks_file, 'w') as wks: |
| 605 | wks.write(test) |
| 606 | runCmd("wic create %s -e core-image-minimal -o %s" \ |
| 607 | % (wks_file, self.resultdir)) |
| 608 | |
| 609 | for part in glob(os.path.join(self.resultdir, 'temp-*.direct.p*')): |
| 610 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part)) |
| 611 | self.assertEqual(True, files_own_by_root(res.output)) |
| 612 | |
| 613 | rmtree(self.resultdir, ignore_errors=True) |
| 614 | |
| 615 | finally: |
| 616 | os.environ['PATH'] = oldpath |
| 617 | |
| 618 | def test_change_directory(self): |
| 619 | """Test --change-directory wks option.""" |
| 620 | |
| 621 | oldpath = os.environ['PATH'] |
| 622 | os.environ['PATH'] = get_bb_var("PATH", "wic-tools") |
| 623 | |
| 624 | try: |
| 625 | include_path = os.path.join(self.resultdir, 'test-include') |
| 626 | os.makedirs(include_path) |
| 627 | wks_file = os.path.join(include_path, 'temp.wks') |
| 628 | with open(wks_file, 'w') as wks: |
| 629 | wks.write("part /etc --source rootfs --fstype=ext4 --change-directory=etc") |
| 630 | runCmd("wic create %s -e core-image-minimal -o %s" \ |
| 631 | % (wks_file, self.resultdir)) |
| 632 | |
| 633 | part1 = glob(os.path.join(self.resultdir, 'temp-*.direct.p1'))[0] |
| 634 | |
| 635 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part1)) |
| 636 | files = extract_files(res.output) |
| 637 | self.assertIn('passwd', files) |
| 638 | |
| 639 | finally: |
| 640 | os.environ['PATH'] = oldpath |
| 641 | |
| 642 | def test_change_directory_errors(self): |
| 643 | """Test --change-directory wks option error handling.""" |
| 644 | wks_file = 'temp.wks' |
| 645 | |
| 646 | # Absolute argument. |
| 647 | with open(wks_file, 'w') as wks: |
| 648 | wks.write("part / --source rootfs --fstype=ext4 --change-directory /usr") |
| 649 | self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \ |
| 650 | % (wks_file, self.resultdir), ignore_status=True).status) |
| 651 | os.remove(wks_file) |
| 652 | |
| 653 | # Argument pointing to parent directory. |
| 654 | with open(wks_file, 'w') as wks: |
| 655 | wks.write("part / --source rootfs --fstype=ext4 --change-directory ././..") |
| 656 | self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \ |
| 657 | % (wks_file, self.resultdir), ignore_status=True).status) |
| 658 | os.remove(wks_file) |
| 659 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 660 | class Wic2(WicTestCase): |
| 661 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 662 | def test_bmap_short(self): |
| 663 | """Test generation of .bmap file -m option""" |
| 664 | cmd = "wic create wictestdisk -e core-image-minimal -m -o %s" % self.resultdir |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 665 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 666 | self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*direct"))) |
| 667 | self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*direct.bmap"))) |
| 668 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 669 | def test_bmap_long(self): |
| 670 | """Test generation of .bmap file --bmap option""" |
| 671 | cmd = "wic create wictestdisk -e core-image-minimal --bmap -o %s" % self.resultdir |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 672 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 673 | self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*direct"))) |
| 674 | self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*direct.bmap"))) |
| 675 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 676 | def test_image_env(self): |
| 677 | """Test generation of <image>.env files.""" |
| 678 | image = 'core-image-minimal' |
| 679 | imgdatadir = self._get_image_env_path(image) |
| 680 | |
| 681 | bb_vars = get_bb_vars(['IMAGE_BASENAME', 'WICVARS'], image) |
| 682 | basename = bb_vars['IMAGE_BASENAME'] |
| 683 | self.assertEqual(basename, image) |
| 684 | path = os.path.join(imgdatadir, basename) + '.env' |
| 685 | self.assertTrue(os.path.isfile(path)) |
| 686 | |
| 687 | wicvars = set(bb_vars['WICVARS'].split()) |
| 688 | # filter out optional variables |
| 689 | wicvars = wicvars.difference(('DEPLOY_DIR_IMAGE', 'IMAGE_BOOT_FILES', |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 690 | 'INITRD', 'INITRD_LIVE', 'ISODIR','INITRAMFS_IMAGE', |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 691 | 'INITRAMFS_IMAGE_BUNDLE', 'INITRAMFS_LINK_NAME', |
| 692 | 'APPEND')) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 693 | with open(path) as envfile: |
| 694 | content = dict(line.split("=", 1) for line in envfile) |
| 695 | # test if variables used by wic present in the .env file |
| 696 | for var in wicvars: |
| 697 | self.assertTrue(var in content, "%s is not in .env file" % var) |
| 698 | self.assertTrue(content[var]) |
| 699 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 700 | def test_image_vars_dir_short(self): |
| 701 | """Test image vars directory selection -v option""" |
| 702 | image = 'core-image-minimal' |
| 703 | imgenvdir = self._get_image_env_path(image) |
| 704 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") |
| 705 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 706 | runCmd("wic create wictestdisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 707 | "--image-name=%s -v %s -n %s -o %s" |
| 708 | % (image, imgenvdir, native_sysroot, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 709 | self.resultdir)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 710 | self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*direct"))) |
| 711 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 712 | def test_image_vars_dir_long(self): |
| 713 | """Test image vars directory selection --vars option""" |
| 714 | image = 'core-image-minimal' |
| 715 | imgenvdir = self._get_image_env_path(image) |
| 716 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") |
| 717 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 718 | runCmd("wic create wictestdisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 719 | "--image-name=%s " |
| 720 | "--vars %s " |
| 721 | "--native-sysroot %s " |
| 722 | "--outdir %s" |
| 723 | % (image, imgenvdir, native_sysroot, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 724 | self.resultdir)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 725 | self.assertEqual(1, len(glob(self.resultdir + "wictestdisk-*direct"))) |
| 726 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 727 | @only_for_arch(['i586', 'i686', 'x86_64']) |
| 728 | def test_wic_image_type(self): |
| 729 | """Test building wic images by bitbake""" |
| 730 | config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "wic-image-minimal"\n'\ |
| 731 | 'MACHINE_FEATURES_append = " efi"\n' |
| 732 | self.append_config(config) |
| 733 | self.assertEqual(0, bitbake('wic-image-minimal').status) |
| 734 | self.remove_config(config) |
| 735 | |
| 736 | bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'MACHINE']) |
| 737 | deploy_dir = bb_vars['DEPLOY_DIR_IMAGE'] |
| 738 | machine = bb_vars['MACHINE'] |
| 739 | prefix = os.path.join(deploy_dir, 'wic-image-minimal-%s.' % machine) |
| 740 | # check if we have result image and manifests symlinks |
| 741 | # pointing to existing files |
| 742 | for suffix in ('wic', 'manifest'): |
| 743 | path = prefix + suffix |
| 744 | self.assertTrue(os.path.islink(path)) |
| 745 | self.assertTrue(os.path.isfile(os.path.realpath(path))) |
| 746 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 747 | @only_for_arch(['i586', 'i686', 'x86_64']) |
| 748 | def test_qemu(self): |
| 749 | """Test wic-image-minimal under qemu""" |
| 750 | config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "wic-image-minimal"\n'\ |
| 751 | 'MACHINE_FEATURES_append = " efi"\n' |
| 752 | self.append_config(config) |
| 753 | self.assertEqual(0, bitbake('wic-image-minimal').status) |
| 754 | self.remove_config(config) |
| 755 | |
| 756 | with runqemu('wic-image-minimal', ssh=False) as qemu: |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame] | 757 | cmd = "mount | grep '^/dev/' | cut -f1,3 -d ' ' | egrep -c -e '/dev/sda1 /boot' " \ |
| 758 | "-e '/dev/root /|/dev/sda2 /' -e '/dev/sda3 /media' -e '/dev/sda4 /mnt'" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 759 | status, output = qemu.run_serial(cmd) |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame] | 760 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) |
| 761 | self.assertEqual(output, '4') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 762 | cmd = "grep UUID= /etc/fstab" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 763 | status, output = qemu.run_serial(cmd) |
| 764 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 765 | self.assertEqual(output, 'UUID=2c71ef06-a81d-4735-9d3a-379b69c6bdba\t/media\text4\tdefaults\t0\t0') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 766 | |
| 767 | @only_for_arch(['i586', 'i686', 'x86_64']) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 768 | def test_qemu_efi(self): |
| 769 | """Test core-image-minimal efi image under qemu""" |
| 770 | config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "mkefidisk.wks"\n' |
| 771 | self.append_config(config) |
| 772 | self.assertEqual(0, bitbake('core-image-minimal ovmf').status) |
| 773 | self.remove_config(config) |
| 774 | |
| 775 | with runqemu('core-image-minimal', ssh=False, |
| 776 | runqemuparams='ovmf', image_fstype='wic') as qemu: |
| 777 | cmd = "grep sda. /proc/partitions |wc -l" |
| 778 | status, output = qemu.run_serial(cmd) |
| 779 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) |
| 780 | self.assertEqual(output, '3') |
| 781 | |
| 782 | @staticmethod |
| 783 | def _make_fixed_size_wks(size): |
| 784 | """ |
| 785 | Create a wks of an image with a single partition. Size of the partition is set |
| 786 | using --fixed-size flag. Returns a tuple: (path to wks file, wks image name) |
| 787 | """ |
| 788 | with NamedTemporaryFile("w", suffix=".wks", delete=False) as tempf: |
| 789 | wkspath = tempf.name |
| 790 | tempf.write("part " \ |
| 791 | "--source rootfs --ondisk hda --align 4 --fixed-size %d " |
| 792 | "--fstype=ext4\n" % size) |
| 793 | wksname = os.path.splitext(os.path.basename(wkspath))[0] |
| 794 | |
| 795 | return wkspath, wksname |
| 796 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 797 | def test_fixed_size(self): |
| 798 | """ |
| 799 | Test creation of a simple image with partition size controlled through |
| 800 | --fixed-size flag |
| 801 | """ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 802 | wkspath, wksname = Wic2._make_fixed_size_wks(200) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 803 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 804 | runCmd("wic create %s -e core-image-minimal -o %s" \ |
| 805 | % (wkspath, self.resultdir)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 806 | os.remove(wkspath) |
| 807 | wicout = glob(self.resultdir + "%s-*direct" % wksname) |
| 808 | self.assertEqual(1, len(wicout)) |
| 809 | |
| 810 | wicimg = wicout[0] |
| 811 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 812 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") |
| 813 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 814 | # verify partition size with wic |
| 815 | res = runCmd("parted -m %s unit mib p 2>/dev/null" % wicimg, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 816 | native_sysroot=native_sysroot) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 817 | |
| 818 | # parse parted output which looks like this: |
| 819 | # BYT;\n |
| 820 | # /var/tmp/wic/build/tmpfwvjjkf_-201611101222-hda.direct:200MiB:file:512:512:msdos::;\n |
| 821 | # 1:0.00MiB:200MiB:200MiB:ext4::;\n |
| 822 | partlns = res.output.splitlines()[2:] |
| 823 | |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 824 | self.assertEqual(1, len(partlns), |
| 825 | msg="Partition list '%s'" % res.output) |
| 826 | self.assertEqual("1:0.00MiB:200MiB:200MiB:ext4::;", partlns[0], |
| 827 | msg="Partition list '%s'" % res.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 828 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 829 | def test_fixed_size_error(self): |
| 830 | """ |
| 831 | Test creation of a simple image with partition size controlled through |
| 832 | --fixed-size flag. The size of partition is intentionally set to 1MiB |
| 833 | in order to trigger an error in wic. |
| 834 | """ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 835 | wkspath, wksname = Wic2._make_fixed_size_wks(1) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 836 | |
| 837 | self.assertEqual(1, runCmd("wic create %s -e core-image-minimal -o %s" \ |
| 838 | % (wkspath, self.resultdir), ignore_status=True).status) |
| 839 | os.remove(wkspath) |
| 840 | wicout = glob(self.resultdir + "%s-*direct" % wksname) |
| 841 | self.assertEqual(0, len(wicout)) |
| 842 | |
| 843 | @only_for_arch(['i586', 'i686', 'x86_64']) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 844 | def test_rawcopy_plugin_qemu(self): |
| 845 | """Test rawcopy plugin in qemu""" |
| 846 | # build ext4 and wic images |
| 847 | for fstype in ("ext4", "wic"): |
| 848 | config = 'IMAGE_FSTYPES = "%s"\nWKS_FILE = "test_rawcopy_plugin.wks.in"\n' % fstype |
| 849 | self.append_config(config) |
| 850 | self.assertEqual(0, bitbake('core-image-minimal').status) |
| 851 | self.remove_config(config) |
| 852 | |
| 853 | with runqemu('core-image-minimal', ssh=False, image_fstype='wic') as qemu: |
| 854 | cmd = "grep sda. /proc/partitions |wc -l" |
| 855 | status, output = qemu.run_serial(cmd) |
| 856 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) |
| 857 | self.assertEqual(output, '2') |
| 858 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 859 | def test_rawcopy_plugin(self): |
| 860 | """Test rawcopy plugin""" |
| 861 | img = 'core-image-minimal' |
| 862 | machine = get_bb_var('MACHINE', img) |
| 863 | with NamedTemporaryFile("w", suffix=".wks") as wks: |
| 864 | wks.writelines(['part /boot --active --source bootimg-pcbios\n', |
| 865 | 'part / --source rawcopy --sourceparams="file=%s-%s.ext4" --use-uuid\n'\ |
| 866 | % (img, machine), |
| 867 | 'bootloader --timeout=0 --append="console=ttyS0,115200n8"\n']) |
| 868 | wks.flush() |
| 869 | cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 870 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 871 | wksname = os.path.splitext(os.path.basename(wks.name))[0] |
| 872 | out = glob(self.resultdir + "%s-*direct" % wksname) |
| 873 | self.assertEqual(1, len(out)) |
| 874 | |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 875 | @only_for_arch(['i586', 'i686', 'x86_64']) |
| 876 | def test_biosplusefi_plugin_qemu(self): |
| 877 | """Test biosplusefi plugin in qemu""" |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 878 | config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "test_biosplusefi_plugin.wks"\nMACHINE_FEATURES_append = " efi"\n' |
| 879 | self.append_config(config) |
| 880 | self.assertEqual(0, bitbake('core-image-minimal').status) |
| 881 | self.remove_config(config) |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 882 | |
| 883 | with runqemu('core-image-minimal', ssh=False, image_fstype='wic') as qemu: |
| 884 | # Check that we have ONLY two /dev/sda* partitions (/boot and /) |
| 885 | cmd = "grep sda. /proc/partitions | wc -l" |
| 886 | status, output = qemu.run_serial(cmd) |
| 887 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) |
| 888 | self.assertEqual(output, '2') |
| 889 | # Check that /dev/sda1 is /boot and that either /dev/root OR /dev/sda2 is / |
| 890 | cmd = "mount | grep '^/dev/' | cut -f1,3 -d ' ' | egrep -c -e '/dev/sda1 /boot' -e '/dev/root /|/dev/sda2 /'" |
| 891 | status, output = qemu.run_serial(cmd) |
| 892 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) |
| 893 | self.assertEqual(output, '2') |
| 894 | # Check that /boot has EFI bootx64.efi (required for EFI) |
| 895 | cmd = "ls /boot/EFI/BOOT/bootx64.efi | wc -l" |
| 896 | status, output = qemu.run_serial(cmd) |
| 897 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) |
| 898 | self.assertEqual(output, '1') |
| 899 | # Check that "BOOTABLE" flag is set on boot partition (required for PC-Bios) |
| 900 | # Trailing "cat" seems to be required; otherwise run_serial() sends back echo of the input command |
| 901 | cmd = "fdisk -l /dev/sda | grep /dev/sda1 | awk {print'$2'} | cat" |
| 902 | status, output = qemu.run_serial(cmd) |
| 903 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) |
| 904 | self.assertEqual(output, '*') |
| 905 | |
| 906 | @only_for_arch(['i586', 'i686', 'x86_64']) |
| 907 | def test_biosplusefi_plugin(self): |
| 908 | """Test biosplusefi plugin""" |
| 909 | # Wic generation below may fail depending on the order of the unittests |
| 910 | # This is because bootimg-pcbios (that bootimg-biosplusefi uses) generate its MBR inside STAGING_DATADIR directory |
| 911 | # which may or may not exists depending on what was built already |
| 912 | # If an image hasn't been built yet, directory ${STAGING_DATADIR}/syslinux won't exists and _get_bootimg_dir() |
| 913 | # will raise with "Couldn't find correct bootimg_dir" |
| 914 | # The easiest way to work-around this issue is to make sure we already built an image here, hence the bitbake call |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 915 | config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "test_biosplusefi_plugin.wks"\nMACHINE_FEATURES_append = " efi"\n' |
| 916 | self.append_config(config) |
| 917 | self.assertEqual(0, bitbake('core-image-minimal').status) |
| 918 | self.remove_config(config) |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 919 | |
| 920 | img = 'core-image-minimal' |
| 921 | with NamedTemporaryFile("w", suffix=".wks") as wks: |
| 922 | wks.writelines(['part /boot --active --source bootimg-biosplusefi --sourceparams="loader=grub-efi"\n', |
| 923 | 'part / --source rootfs --fstype=ext4 --align 1024 --use-uuid\n'\ |
| 924 | 'bootloader --timeout=0 --append="console=ttyS0,115200n8"\n']) |
| 925 | wks.flush() |
| 926 | cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir) |
| 927 | runCmd(cmd) |
| 928 | wksname = os.path.splitext(os.path.basename(wks.name))[0] |
| 929 | out = glob(self.resultdir + "%s-*.direct" % wksname) |
| 930 | self.assertEqual(1, len(out)) |
| 931 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 932 | def test_fs_types(self): |
| 933 | """Test filesystem types for empty and not empty partitions""" |
| 934 | img = 'core-image-minimal' |
| 935 | with NamedTemporaryFile("w", suffix=".wks") as wks: |
| 936 | wks.writelines(['part ext2 --fstype ext2 --source rootfs\n', |
| 937 | 'part btrfs --fstype btrfs --source rootfs --size 40M\n', |
| 938 | 'part squash --fstype squashfs --source rootfs\n', |
| 939 | 'part swap --fstype swap --size 1M\n', |
| 940 | 'part emptyvfat --fstype vfat --size 1M\n', |
| 941 | 'part emptymsdos --fstype msdos --size 1M\n', |
| 942 | 'part emptyext2 --fstype ext2 --size 1M\n', |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 943 | 'part emptybtrfs --fstype btrfs --size 150M\n']) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 944 | wks.flush() |
| 945 | cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 946 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 947 | wksname = os.path.splitext(os.path.basename(wks.name))[0] |
| 948 | out = glob(self.resultdir + "%s-*direct" % wksname) |
| 949 | self.assertEqual(1, len(out)) |
| 950 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 951 | def test_kickstart_parser(self): |
| 952 | """Test wks parser options""" |
| 953 | with NamedTemporaryFile("w", suffix=".wks") as wks: |
| 954 | wks.writelines(['part / --fstype ext3 --source rootfs --system-id 0xFF '\ |
| 955 | '--overhead-factor 1.2 --size 100k\n']) |
| 956 | wks.flush() |
| 957 | cmd = "wic create %s -e core-image-minimal -o %s" % (wks.name, self.resultdir) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 958 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 959 | wksname = os.path.splitext(os.path.basename(wks.name))[0] |
| 960 | out = glob(self.resultdir + "%s-*direct" % wksname) |
| 961 | self.assertEqual(1, len(out)) |
| 962 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 963 | def test_image_bootpart_globbed(self): |
| 964 | """Test globbed sources with image-bootpart plugin""" |
| 965 | img = "core-image-minimal" |
| 966 | cmd = "wic create sdimage-bootpart -e %s -o %s" % (img, self.resultdir) |
| 967 | config = 'IMAGE_BOOT_FILES = "%s*"' % get_bb_var('KERNEL_IMAGETYPE', img) |
| 968 | self.append_config(config) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 969 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 970 | self.remove_config(config) |
| 971 | self.assertEqual(1, len(glob(self.resultdir + "sdimage-bootpart-*direct"))) |
| 972 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 973 | def test_sparse_copy(self): |
| 974 | """Test sparse_copy with FIEMAP and SEEK_HOLE filemap APIs""" |
| 975 | libpath = os.path.join(get_bb_var('COREBASE'), 'scripts', 'lib', 'wic') |
| 976 | sys.path.insert(0, libpath) |
| 977 | from filemap import FilemapFiemap, FilemapSeek, sparse_copy, ErrorNotSupp |
| 978 | with NamedTemporaryFile("w", suffix=".wic-sparse") as sparse: |
| 979 | src_name = sparse.name |
| 980 | src_size = 1024 * 10 |
| 981 | sparse.truncate(src_size) |
| 982 | # write one byte to the file |
| 983 | with open(src_name, 'r+b') as sfile: |
| 984 | sfile.seek(1024 * 4) |
| 985 | sfile.write(b'\x00') |
| 986 | dest = sparse.name + '.out' |
| 987 | # copy src file to dest using different filemap APIs |
| 988 | for api in (FilemapFiemap, FilemapSeek, None): |
| 989 | if os.path.exists(dest): |
| 990 | os.unlink(dest) |
| 991 | try: |
| 992 | sparse_copy(sparse.name, dest, api=api) |
| 993 | except ErrorNotSupp: |
| 994 | continue # skip unsupported API |
| 995 | dest_stat = os.stat(dest) |
| 996 | self.assertEqual(dest_stat.st_size, src_size) |
| 997 | # 8 blocks is 4K (physical sector size) |
| 998 | self.assertEqual(dest_stat.st_blocks, 8) |
| 999 | os.unlink(dest) |
| 1000 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1001 | def test_wic_ls(self): |
| 1002 | """Test listing image content using 'wic ls'""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1003 | runCmd("wic create wictestdisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1004 | "--image-name=core-image-minimal " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1005 | "-D -o %s" % self.resultdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1006 | images = glob(self.resultdir + "wictestdisk-*.direct") |
| 1007 | self.assertEqual(1, len(images)) |
| 1008 | |
| 1009 | sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') |
| 1010 | |
| 1011 | # list partitions |
| 1012 | result = runCmd("wic ls %s -n %s" % (images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1013 | self.assertEqual(3, len(result.output.split('\n'))) |
| 1014 | |
| 1015 | # list directory content of the first partition |
| 1016 | result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1017 | self.assertEqual(6, len(result.output.split('\n'))) |
| 1018 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1019 | def test_wic_cp(self): |
| 1020 | """Test copy files and directories to the the wic image.""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1021 | runCmd("wic create wictestdisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1022 | "--image-name=core-image-minimal " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1023 | "-D -o %s" % self.resultdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1024 | images = glob(self.resultdir + "wictestdisk-*.direct") |
| 1025 | self.assertEqual(1, len(images)) |
| 1026 | |
| 1027 | sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') |
| 1028 | |
| 1029 | # list directory content of the first partition |
| 1030 | result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1031 | self.assertEqual(6, len(result.output.split('\n'))) |
| 1032 | |
| 1033 | with NamedTemporaryFile("w", suffix=".wic-cp") as testfile: |
| 1034 | testfile.write("test") |
| 1035 | |
| 1036 | # copy file to the partition |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1037 | runCmd("wic cp %s %s:1/ -n %s" % (testfile.name, images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1038 | |
| 1039 | # check if file is there |
| 1040 | result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1041 | self.assertEqual(7, len(result.output.split('\n'))) |
| 1042 | self.assertTrue(os.path.basename(testfile.name) in result.output) |
| 1043 | |
| 1044 | # prepare directory |
| 1045 | testdir = os.path.join(self.resultdir, 'wic-test-cp-dir') |
| 1046 | testsubdir = os.path.join(testdir, 'subdir') |
| 1047 | os.makedirs(os.path.join(testsubdir)) |
| 1048 | copy(testfile.name, testdir) |
| 1049 | |
| 1050 | # copy directory to the partition |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1051 | runCmd("wic cp %s %s:1/ -n %s" % (testdir, images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1052 | |
| 1053 | # check if directory is there |
| 1054 | result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1055 | self.assertEqual(8, len(result.output.split('\n'))) |
| 1056 | self.assertTrue(os.path.basename(testdir) in result.output) |
| 1057 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1058 | # copy the file from the partition and check if it success |
| 1059 | dest = '%s-cp' % testfile.name |
| 1060 | runCmd("wic cp %s:1/%s %s -n %s" % (images[0], |
| 1061 | os.path.basename(testfile.name), dest, sysroot)) |
| 1062 | self.assertTrue(os.path.exists(dest)) |
| 1063 | |
| 1064 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1065 | def test_wic_rm(self): |
| 1066 | """Test removing files and directories from the the wic image.""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1067 | runCmd("wic create mkefidisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1068 | "--image-name=core-image-minimal " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1069 | "-D -o %s" % self.resultdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1070 | images = glob(self.resultdir + "mkefidisk-*.direct") |
| 1071 | self.assertEqual(1, len(images)) |
| 1072 | |
| 1073 | sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') |
| 1074 | |
| 1075 | # list directory content of the first partition |
| 1076 | result = runCmd("wic ls %s:1 -n %s" % (images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1077 | self.assertIn('\nBZIMAGE ', result.output) |
| 1078 | self.assertIn('\nEFI <DIR> ', result.output) |
| 1079 | |
| 1080 | # remove file |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1081 | runCmd("wic rm %s:1/bzimage -n %s" % (images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1082 | |
| 1083 | # remove directory |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1084 | runCmd("wic rm %s:1/efi -n %s" % (images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1085 | |
| 1086 | # check if they're removed |
| 1087 | result = runCmd("wic ls %s:1 -n %s" % (images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1088 | self.assertNotIn('\nBZIMAGE ', result.output) |
| 1089 | self.assertNotIn('\nEFI <DIR> ', result.output) |
| 1090 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1091 | def test_mkfs_extraopts(self): |
| 1092 | """Test wks option --mkfs-extraopts for empty and not empty partitions""" |
| 1093 | img = 'core-image-minimal' |
| 1094 | with NamedTemporaryFile("w", suffix=".wks") as wks: |
| 1095 | wks.writelines( |
| 1096 | ['part ext2 --fstype ext2 --source rootfs --mkfs-extraopts "-D -F -i 8192"\n', |
| 1097 | "part btrfs --fstype btrfs --source rootfs --size 40M --mkfs-extraopts='--quiet'\n", |
| 1098 | 'part squash --fstype squashfs --source rootfs --mkfs-extraopts "-no-sparse -b 4096"\n', |
| 1099 | 'part emptyvfat --fstype vfat --size 1M --mkfs-extraopts "-S 1024 -s 64"\n', |
| 1100 | 'part emptymsdos --fstype msdos --size 1M --mkfs-extraopts "-S 1024 -s 64"\n', |
| 1101 | 'part emptyext2 --fstype ext2 --size 1M --mkfs-extraopts "-D -F -i 8192"\n', |
| 1102 | 'part emptybtrfs --fstype btrfs --size 100M --mkfs-extraopts "--mixed -K"\n']) |
| 1103 | wks.flush() |
| 1104 | cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1105 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1106 | wksname = os.path.splitext(os.path.basename(wks.name))[0] |
| 1107 | out = glob(self.resultdir + "%s-*direct" % wksname) |
| 1108 | self.assertEqual(1, len(out)) |
| 1109 | |
| 1110 | def test_expand_mbr_image(self): |
| 1111 | """Test wic write --expand command for mbr image""" |
| 1112 | # build an image |
| 1113 | config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "directdisk.wks"\n' |
| 1114 | self.append_config(config) |
| 1115 | self.assertEqual(0, bitbake('core-image-minimal').status) |
| 1116 | |
| 1117 | # get path to the image |
| 1118 | bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'MACHINE']) |
| 1119 | deploy_dir = bb_vars['DEPLOY_DIR_IMAGE'] |
| 1120 | machine = bb_vars['MACHINE'] |
| 1121 | image_path = os.path.join(deploy_dir, 'core-image-minimal-%s.wic' % machine) |
| 1122 | |
| 1123 | self.remove_config(config) |
| 1124 | |
| 1125 | try: |
| 1126 | # expand image to 1G |
| 1127 | new_image_path = None |
| 1128 | with NamedTemporaryFile(mode='wb', suffix='.wic.exp', |
| 1129 | dir=deploy_dir, delete=False) as sparse: |
| 1130 | sparse.truncate(1024 ** 3) |
| 1131 | new_image_path = sparse.name |
| 1132 | |
| 1133 | sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') |
| 1134 | cmd = "wic write -n %s --expand 1:0 %s %s" % (sysroot, image_path, new_image_path) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1135 | runCmd(cmd) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1136 | |
| 1137 | # check if partitions are expanded |
| 1138 | orig = runCmd("wic ls %s -n %s" % (image_path, sysroot)) |
| 1139 | exp = runCmd("wic ls %s -n %s" % (new_image_path, sysroot)) |
| 1140 | orig_sizes = [int(line.split()[3]) for line in orig.output.split('\n')[1:]] |
| 1141 | exp_sizes = [int(line.split()[3]) for line in exp.output.split('\n')[1:]] |
| 1142 | self.assertEqual(orig_sizes[0], exp_sizes[0]) # first partition is not resized |
| 1143 | self.assertTrue(orig_sizes[1] < exp_sizes[1]) |
| 1144 | |
| 1145 | # Check if all free space is partitioned |
| 1146 | result = runCmd("%s/usr/sbin/sfdisk -F %s" % (sysroot, new_image_path)) |
| 1147 | self.assertTrue("0 B, 0 bytes, 0 sectors" in result.output) |
| 1148 | |
| 1149 | os.rename(image_path, image_path + '.bak') |
| 1150 | os.rename(new_image_path, image_path) |
| 1151 | |
| 1152 | # Check if it boots in qemu |
| 1153 | with runqemu('core-image-minimal', ssh=False) as qemu: |
| 1154 | cmd = "ls /etc/" |
| 1155 | status, output = qemu.run_serial('true') |
| 1156 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) |
| 1157 | finally: |
| 1158 | if os.path.exists(new_image_path): |
| 1159 | os.unlink(new_image_path) |
| 1160 | if os.path.exists(image_path + '.bak'): |
| 1161 | os.rename(image_path + '.bak', image_path) |
| 1162 | |
| 1163 | def test_wic_ls_ext(self): |
| 1164 | """Test listing content of the ext partition using 'wic ls'""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1165 | runCmd("wic create wictestdisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1166 | "--image-name=core-image-minimal " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1167 | "-D -o %s" % self.resultdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1168 | images = glob(self.resultdir + "wictestdisk-*.direct") |
| 1169 | self.assertEqual(1, len(images)) |
| 1170 | |
| 1171 | sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') |
| 1172 | |
| 1173 | # list directory content of the second ext4 partition |
| 1174 | result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1175 | self.assertTrue(set(['bin', 'home', 'proc', 'usr', 'var', 'dev', 'lib', 'sbin']).issubset( |
| 1176 | set(line.split()[-1] for line in result.output.split('\n') if line))) |
| 1177 | |
| 1178 | def test_wic_cp_ext(self): |
| 1179 | """Test copy files and directories to the ext partition.""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1180 | runCmd("wic create wictestdisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1181 | "--image-name=core-image-minimal " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1182 | "-D -o %s" % self.resultdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1183 | images = glob(self.resultdir + "wictestdisk-*.direct") |
| 1184 | self.assertEqual(1, len(images)) |
| 1185 | |
| 1186 | sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') |
| 1187 | |
| 1188 | # list directory content of the ext4 partition |
| 1189 | result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1190 | dirs = set(line.split()[-1] for line in result.output.split('\n') if line) |
| 1191 | self.assertTrue(set(['bin', 'home', 'proc', 'usr', 'var', 'dev', 'lib', 'sbin']).issubset(dirs)) |
| 1192 | |
| 1193 | with NamedTemporaryFile("w", suffix=".wic-cp") as testfile: |
| 1194 | testfile.write("test") |
| 1195 | |
| 1196 | # copy file to the partition |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1197 | runCmd("wic cp %s %s:2/ -n %s" % (testfile.name, images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1198 | |
| 1199 | # check if file is there |
| 1200 | result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1201 | newdirs = set(line.split()[-1] for line in result.output.split('\n') if line) |
| 1202 | self.assertEqual(newdirs.difference(dirs), set([os.path.basename(testfile.name)])) |
| 1203 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1204 | # check if the file to copy is in the partition |
| 1205 | result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot)) |
| 1206 | self.assertTrue('fstab' in [line.split()[-1] for line in result.output.split('\n') if line]) |
| 1207 | |
| 1208 | # copy file from the partition, replace the temporary file content with it and |
| 1209 | # check for the file size to validate the copy |
| 1210 | runCmd("wic cp %s:2/etc/fstab %s -n %s" % (images[0], testfile.name, sysroot)) |
| 1211 | self.assertTrue(os.stat(testfile.name).st_size > 0) |
| 1212 | |
| 1213 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1214 | def test_wic_rm_ext(self): |
| 1215 | """Test removing files from the ext partition.""" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1216 | runCmd("wic create mkefidisk " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1217 | "--image-name=core-image-minimal " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1218 | "-D -o %s" % self.resultdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1219 | images = glob(self.resultdir + "mkefidisk-*.direct") |
| 1220 | self.assertEqual(1, len(images)) |
| 1221 | |
| 1222 | sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') |
| 1223 | |
| 1224 | # list directory content of the /etc directory on ext4 partition |
| 1225 | result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1226 | self.assertTrue('fstab' in [line.split()[-1] for line in result.output.split('\n') if line]) |
| 1227 | |
| 1228 | # remove file |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1229 | runCmd("wic rm %s:2/etc/fstab -n %s" % (images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1230 | |
| 1231 | # check if it's removed |
| 1232 | result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1233 | self.assertTrue('fstab' not in [line.split()[-1] for line in result.output.split('\n') if line]) |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 1234 | |
| 1235 | # remove non-empty directory |
| 1236 | runCmd("wic rm -r %s:2/etc/ -n %s" % (images[0], sysroot)) |
| 1237 | |
| 1238 | # check if it's removed |
| 1239 | result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot)) |
| 1240 | self.assertTrue('etc' not in [line.split()[-1] for line in result.output.split('\n') if line]) |