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