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