AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
| 2 | # Copyright (c) 2018, Linaro Limited |
| 3 | # Author: Takahiro Akashi <takahiro.akashi@linaro.org> |
| 4 | |
| 5 | import os |
| 6 | import os.path |
| 7 | import pytest |
| 8 | import re |
| 9 | from subprocess import call, check_call, check_output, CalledProcessError |
| 10 | from fstest_defs import * |
Tom Rini | 50ad019 | 2023-12-09 14:52:46 -0500 | [diff] [blame] | 11 | # pylint: disable=E0611 |
Simon Glass | 1d5006c | 2022-10-29 19:47:05 -0600 | [diff] [blame] | 12 | from tests import fs_helper |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 13 | |
| 14 | supported_fs_basic = ['fat16', 'fat32', 'ext4'] |
Christian Taedcke | a1fd735 | 2023-11-15 13:44:22 +0100 | [diff] [blame] | 15 | supported_fs_ext = ['fat12', 'fat16', 'fat32'] |
Christian Taedcke | 570dc36 | 2023-11-15 13:44:24 +0100 | [diff] [blame] | 16 | supported_fs_fat = ['fat12', 'fat16'] |
Christian Taedcke | a1fd735 | 2023-11-15 13:44:22 +0100 | [diff] [blame] | 17 | supported_fs_mkdir = ['fat12', 'fat16', 'fat32'] |
| 18 | supported_fs_unlink = ['fat12', 'fat16', 'fat32'] |
Jean-Jacques Hiblot | 8aea8a6 | 2019-02-13 12:15:27 +0100 | [diff] [blame] | 19 | supported_fs_symlink = ['ext4'] |
Gabriel Dalimonte | 4b93d6e | 2025-02-17 13:26:44 -0500 | [diff] [blame] | 20 | supported_fs_rename = ['fat12', 'fat16', 'fat32'] |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 21 | |
| 22 | # |
| 23 | # Filesystem test specific setup |
| 24 | # |
| 25 | def pytest_addoption(parser): |
Akashi Takahiro | bcdd1f2 | 2018-09-27 16:07:23 +0900 | [diff] [blame] | 26 | """Enable --fs-type option. |
| 27 | |
| 28 | See pytest_configure() about how it works. |
| 29 | |
| 30 | Args: |
| 31 | parser: Pytest command-line parser. |
| 32 | |
| 33 | Returns: |
| 34 | Nothing. |
| 35 | """ |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 36 | parser.addoption('--fs-type', action='append', default=None, |
| 37 | help='Targeting Filesystem Types') |
| 38 | |
| 39 | def pytest_configure(config): |
Akashi Takahiro | bcdd1f2 | 2018-09-27 16:07:23 +0900 | [diff] [blame] | 40 | """Restrict a file system(s) to be tested. |
| 41 | |
| 42 | A file system explicitly named with --fs-type option is selected |
| 43 | if it belongs to a default supported_fs_xxx list. |
| 44 | Multiple options can be specified. |
| 45 | |
| 46 | Args: |
| 47 | config: Pytest configuration. |
| 48 | |
| 49 | Returns: |
| 50 | Nothing. |
| 51 | """ |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 52 | global supported_fs_basic |
AKASHI Takahiro | dde5d3f | 2018-09-11 15:59:20 +0900 | [diff] [blame] | 53 | global supported_fs_ext |
Christian Taedcke | 570dc36 | 2023-11-15 13:44:24 +0100 | [diff] [blame] | 54 | global supported_fs_fat |
AKASHI Takahiro | 1e90c2c | 2018-09-11 15:59:21 +0900 | [diff] [blame] | 55 | global supported_fs_mkdir |
Akashi, Takahiro | d49e799 | 2018-09-11 16:06:03 +0900 | [diff] [blame] | 56 | global supported_fs_unlink |
Jean-Jacques Hiblot | 8aea8a6 | 2019-02-13 12:15:27 +0100 | [diff] [blame] | 57 | global supported_fs_symlink |
Gabriel Dalimonte | 4b93d6e | 2025-02-17 13:26:44 -0500 | [diff] [blame] | 58 | global supported_fs_rename |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 59 | |
| 60 | def intersect(listA, listB): |
| 61 | return [x for x in listA if x in listB] |
| 62 | |
| 63 | supported_fs = config.getoption('fs_type') |
| 64 | if supported_fs: |
Simon Glass | e9f4d87 | 2018-12-27 08:11:13 -0700 | [diff] [blame] | 65 | print('*** FS TYPE modified: %s' % supported_fs) |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 66 | supported_fs_basic = intersect(supported_fs, supported_fs_basic) |
AKASHI Takahiro | dde5d3f | 2018-09-11 15:59:20 +0900 | [diff] [blame] | 67 | supported_fs_ext = intersect(supported_fs, supported_fs_ext) |
Christian Taedcke | 570dc36 | 2023-11-15 13:44:24 +0100 | [diff] [blame] | 68 | supported_fs_fat = intersect(supported_fs, supported_fs_fat) |
AKASHI Takahiro | 1e90c2c | 2018-09-11 15:59:21 +0900 | [diff] [blame] | 69 | supported_fs_mkdir = intersect(supported_fs, supported_fs_mkdir) |
Akashi, Takahiro | d49e799 | 2018-09-11 16:06:03 +0900 | [diff] [blame] | 70 | supported_fs_unlink = intersect(supported_fs, supported_fs_unlink) |
Jean-Jacques Hiblot | 8aea8a6 | 2019-02-13 12:15:27 +0100 | [diff] [blame] | 71 | supported_fs_symlink = intersect(supported_fs, supported_fs_symlink) |
Gabriel Dalimonte | 4b93d6e | 2025-02-17 13:26:44 -0500 | [diff] [blame] | 72 | supported_fs_rename = intersect(supported_fs, supported_fs_rename) |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 73 | |
| 74 | def pytest_generate_tests(metafunc): |
Akashi Takahiro | bcdd1f2 | 2018-09-27 16:07:23 +0900 | [diff] [blame] | 75 | """Parametrize fixtures, fs_obj_xxx |
| 76 | |
| 77 | Each fixture will be parametrized with a corresponding support_fs_xxx |
| 78 | list. |
| 79 | |
| 80 | Args: |
| 81 | metafunc: Pytest test function. |
| 82 | |
| 83 | Returns: |
| 84 | Nothing. |
| 85 | """ |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 86 | if 'fs_obj_basic' in metafunc.fixturenames: |
| 87 | metafunc.parametrize('fs_obj_basic', supported_fs_basic, |
| 88 | indirect=True, scope='module') |
AKASHI Takahiro | dde5d3f | 2018-09-11 15:59:20 +0900 | [diff] [blame] | 89 | if 'fs_obj_ext' in metafunc.fixturenames: |
| 90 | metafunc.parametrize('fs_obj_ext', supported_fs_ext, |
| 91 | indirect=True, scope='module') |
Christian Taedcke | 570dc36 | 2023-11-15 13:44:24 +0100 | [diff] [blame] | 92 | if 'fs_obj_fat' in metafunc.fixturenames: |
| 93 | metafunc.parametrize('fs_obj_fat', supported_fs_fat, |
| 94 | indirect=True, scope='module') |
AKASHI Takahiro | 1e90c2c | 2018-09-11 15:59:21 +0900 | [diff] [blame] | 95 | if 'fs_obj_mkdir' in metafunc.fixturenames: |
| 96 | metafunc.parametrize('fs_obj_mkdir', supported_fs_mkdir, |
| 97 | indirect=True, scope='module') |
Akashi, Takahiro | d49e799 | 2018-09-11 16:06:03 +0900 | [diff] [blame] | 98 | if 'fs_obj_unlink' in metafunc.fixturenames: |
| 99 | metafunc.parametrize('fs_obj_unlink', supported_fs_unlink, |
| 100 | indirect=True, scope='module') |
Jean-Jacques Hiblot | 8aea8a6 | 2019-02-13 12:15:27 +0100 | [diff] [blame] | 101 | if 'fs_obj_symlink' in metafunc.fixturenames: |
| 102 | metafunc.parametrize('fs_obj_symlink', supported_fs_symlink, |
| 103 | indirect=True, scope='module') |
Gabriel Dalimonte | 4b93d6e | 2025-02-17 13:26:44 -0500 | [diff] [blame] | 104 | if 'fs_obj_rename' in metafunc.fixturenames: |
| 105 | metafunc.parametrize('fs_obj_rename', supported_fs_rename, |
| 106 | indirect=True, scope='module') |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 107 | |
| 108 | # |
| 109 | # Helper functions |
| 110 | # |
| 111 | def fstype_to_ubname(fs_type): |
Michal Simek | 50fa118 | 2023-05-17 09:17:16 +0200 | [diff] [blame] | 112 | """Convert a file system type to an U-Boot specific string |
Akashi Takahiro | bcdd1f2 | 2018-09-27 16:07:23 +0900 | [diff] [blame] | 113 | |
| 114 | A generated string can be used as part of file system related commands |
| 115 | or a config name in u-boot. Currently fat16 and fat32 are handled |
| 116 | specifically. |
| 117 | |
| 118 | Args: |
| 119 | fs_type: File system type. |
| 120 | |
| 121 | Return: |
| 122 | A corresponding string for file system type. |
| 123 | """ |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 124 | if re.match('fat', fs_type): |
| 125 | return 'fat' |
| 126 | else: |
| 127 | return fs_type |
| 128 | |
| 129 | def check_ubconfig(config, fs_type): |
Akashi Takahiro | bcdd1f2 | 2018-09-27 16:07:23 +0900 | [diff] [blame] | 130 | """Check whether a file system is enabled in u-boot configuration. |
| 131 | |
| 132 | This function is assumed to be called in a fixture function so that |
| 133 | the whole test cases will be skipped if a given file system is not |
| 134 | enabled. |
| 135 | |
| 136 | Args: |
| 137 | fs_type: File system type. |
| 138 | |
| 139 | Return: |
| 140 | Nothing. |
| 141 | """ |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 142 | if not config.buildconfig.get('config_cmd_%s' % fs_type, None): |
| 143 | pytest.skip('.config feature "CMD_%s" not enabled' % fs_type.upper()) |
| 144 | if not config.buildconfig.get('config_%s_write' % fs_type, None): |
| 145 | pytest.skip('.config feature "%s_WRITE" not enabled' |
| 146 | % fs_type.upper()) |
| 147 | |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 148 | # from test/py/conftest.py |
| 149 | def tool_is_in_path(tool): |
Akashi Takahiro | bcdd1f2 | 2018-09-27 16:07:23 +0900 | [diff] [blame] | 150 | """Check whether a given command is available on host. |
| 151 | |
| 152 | Args: |
| 153 | tool: Command name. |
| 154 | |
| 155 | Return: |
| 156 | True if available, False if not. |
| 157 | """ |
Simon Glass | e9f4d87 | 2018-12-27 08:11:13 -0700 | [diff] [blame] | 158 | for path in os.environ['PATH'].split(os.pathsep): |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 159 | fn = os.path.join(path, tool) |
| 160 | if os.path.isfile(fn) and os.access(fn, os.X_OK): |
| 161 | return True |
| 162 | return False |
| 163 | |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 164 | # |
| 165 | # Fixture for basic fs test |
| 166 | # derived from test/fs/fs-test.sh |
| 167 | # |
Tom Rini | 1b91cee | 2021-01-28 14:39:56 -0500 | [diff] [blame] | 168 | @pytest.fixture() |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 169 | def fs_obj_basic(request, u_boot_config): |
Akashi Takahiro | bcdd1f2 | 2018-09-27 16:07:23 +0900 | [diff] [blame] | 170 | """Set up a file system to be used in basic fs test. |
| 171 | |
| 172 | Args: |
| 173 | request: Pytest request object. |
Michal Simek | 50fa118 | 2023-05-17 09:17:16 +0200 | [diff] [blame] | 174 | u_boot_config: U-Boot configuration. |
Akashi Takahiro | bcdd1f2 | 2018-09-27 16:07:23 +0900 | [diff] [blame] | 175 | |
| 176 | Return: |
| 177 | A fixture for basic fs test, i.e. a triplet of file system type, |
| 178 | volume file name and a list of MD5 hashes. |
| 179 | """ |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 180 | fs_type = request.param |
| 181 | fs_img = '' |
| 182 | |
| 183 | fs_ubtype = fstype_to_ubname(fs_type) |
| 184 | check_ubconfig(u_boot_config, fs_ubtype) |
| 185 | |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 186 | scratch_dir = u_boot_config.persistent_data_dir + '/scratch' |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 187 | |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 188 | small_file = scratch_dir + '/' + SMALL_FILE |
| 189 | big_file = scratch_dir + '/' + BIG_FILE |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 190 | |
| 191 | try: |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 192 | check_call('mkdir -p %s' % scratch_dir, shell=True) |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 193 | except CalledProcessError as err: |
| 194 | pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 195 | call('rm -f %s' % fs_img, shell=True) |
Alper Nebi Yasak | 46132c2 | 2021-05-20 22:09:46 +0300 | [diff] [blame] | 196 | return |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 197 | |
| 198 | try: |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 199 | # Create a subdirectory. |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 200 | check_call('mkdir %s/SUBDIR' % scratch_dir, shell=True) |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 201 | |
| 202 | # Create big file in this image. |
| 203 | # Note that we work only on the start 1MB, couple MBs in the 2GB range |
| 204 | # and the last 1 MB of the huge 2.5GB file. |
| 205 | # So, just put random values only in those areas. |
| 206 | check_call('dd if=/dev/urandom of=%s bs=1M count=1' |
| 207 | % big_file, shell=True) |
| 208 | check_call('dd if=/dev/urandom of=%s bs=1M count=2 seek=2047' |
| 209 | % big_file, shell=True) |
| 210 | check_call('dd if=/dev/urandom of=%s bs=1M count=1 seek=2499' |
| 211 | % big_file, shell=True) |
| 212 | |
| 213 | # Create a small file in this image. |
| 214 | check_call('dd if=/dev/urandom of=%s bs=1M count=1' |
| 215 | % small_file, shell=True) |
| 216 | |
| 217 | # Delete the small file copies which possibly are written as part of a |
| 218 | # previous test. |
| 219 | # check_call('rm -f "%s.w"' % MB1, shell=True) |
| 220 | # check_call('rm -f "%s.w2"' % MB1, shell=True) |
| 221 | |
| 222 | # Generate the md5sums of reads that we will test against small file |
| 223 | out = check_output( |
| 224 | 'dd if=%s bs=1M skip=0 count=1 2> /dev/null | md5sum' |
Tom Rini | 784e27d | 2019-10-24 11:59:24 -0400 | [diff] [blame] | 225 | % small_file, shell=True).decode() |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 226 | md5val = [ out.split()[0] ] |
| 227 | |
| 228 | # Generate the md5sums of reads that we will test against big file |
| 229 | # One from beginning of file. |
| 230 | out = check_output( |
| 231 | 'dd if=%s bs=1M skip=0 count=1 2> /dev/null | md5sum' |
Tom Rini | 784e27d | 2019-10-24 11:59:24 -0400 | [diff] [blame] | 232 | % big_file, shell=True).decode() |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 233 | md5val.append(out.split()[0]) |
| 234 | |
| 235 | # One from end of file. |
| 236 | out = check_output( |
| 237 | 'dd if=%s bs=1M skip=2499 count=1 2> /dev/null | md5sum' |
Tom Rini | 784e27d | 2019-10-24 11:59:24 -0400 | [diff] [blame] | 238 | % big_file, shell=True).decode() |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 239 | md5val.append(out.split()[0]) |
| 240 | |
| 241 | # One from the last 1MB chunk of 2GB |
| 242 | out = check_output( |
| 243 | 'dd if=%s bs=1M skip=2047 count=1 2> /dev/null | md5sum' |
Tom Rini | 784e27d | 2019-10-24 11:59:24 -0400 | [diff] [blame] | 244 | % big_file, shell=True).decode() |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 245 | md5val.append(out.split()[0]) |
| 246 | |
| 247 | # One from the start 1MB chunk from 2GB |
| 248 | out = check_output( |
| 249 | 'dd if=%s bs=1M skip=2048 count=1 2> /dev/null | md5sum' |
Tom Rini | 784e27d | 2019-10-24 11:59:24 -0400 | [diff] [blame] | 250 | % big_file, shell=True).decode() |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 251 | md5val.append(out.split()[0]) |
| 252 | |
| 253 | # One 1MB chunk crossing the 2GB boundary |
| 254 | out = check_output( |
| 255 | 'dd if=%s bs=512K skip=4095 count=2 2> /dev/null | md5sum' |
Tom Rini | 784e27d | 2019-10-24 11:59:24 -0400 | [diff] [blame] | 256 | % big_file, shell=True).decode() |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 257 | md5val.append(out.split()[0]) |
| 258 | |
Richard Weinberger | 41eca32 | 2024-11-21 15:32:07 -0700 | [diff] [blame] | 259 | try: |
| 260 | # 3GiB volume |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 261 | fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB', scratch_dir) |
Richard Weinberger | 41eca32 | 2024-11-21 15:32:07 -0700 | [diff] [blame] | 262 | except CalledProcessError as err: |
| 263 | pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) |
| 264 | return |
| 265 | |
Heinrich Schuchardt | bc85617 | 2020-04-20 20:48:40 +0200 | [diff] [blame] | 266 | except CalledProcessError as err: |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 267 | pytest.skip('Setup failed for filesystem: ' + fs_type + '. {}'.format(err)) |
AKASHI Takahiro | dde5d3f | 2018-09-11 15:59:20 +0900 | [diff] [blame] | 268 | return |
| 269 | else: |
| 270 | yield [fs_ubtype, fs_img, md5val] |
| 271 | finally: |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 272 | call('rm -rf %s' % scratch_dir, shell=True) |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 273 | call('rm -f %s' % fs_img, shell=True) |
AKASHI Takahiro | dde5d3f | 2018-09-11 15:59:20 +0900 | [diff] [blame] | 274 | |
| 275 | # |
| 276 | # Fixture for extended fs test |
| 277 | # |
Tom Rini | 1b91cee | 2021-01-28 14:39:56 -0500 | [diff] [blame] | 278 | @pytest.fixture() |
AKASHI Takahiro | dde5d3f | 2018-09-11 15:59:20 +0900 | [diff] [blame] | 279 | def fs_obj_ext(request, u_boot_config): |
Akashi Takahiro | bcdd1f2 | 2018-09-27 16:07:23 +0900 | [diff] [blame] | 280 | """Set up a file system to be used in extended fs test. |
| 281 | |
| 282 | Args: |
| 283 | request: Pytest request object. |
Michal Simek | 50fa118 | 2023-05-17 09:17:16 +0200 | [diff] [blame] | 284 | u_boot_config: U-Boot configuration. |
Akashi Takahiro | bcdd1f2 | 2018-09-27 16:07:23 +0900 | [diff] [blame] | 285 | |
| 286 | Return: |
| 287 | A fixture for extended fs test, i.e. a triplet of file system type, |
| 288 | volume file name and a list of MD5 hashes. |
| 289 | """ |
AKASHI Takahiro | dde5d3f | 2018-09-11 15:59:20 +0900 | [diff] [blame] | 290 | fs_type = request.param |
| 291 | fs_img = '' |
| 292 | |
| 293 | fs_ubtype = fstype_to_ubname(fs_type) |
| 294 | check_ubconfig(u_boot_config, fs_ubtype) |
| 295 | |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 296 | scratch_dir = u_boot_config.persistent_data_dir + '/scratch' |
AKASHI Takahiro | dde5d3f | 2018-09-11 15:59:20 +0900 | [diff] [blame] | 297 | |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 298 | min_file = scratch_dir + '/' + MIN_FILE |
| 299 | tmp_file = scratch_dir + '/tmpfile' |
AKASHI Takahiro | dde5d3f | 2018-09-11 15:59:20 +0900 | [diff] [blame] | 300 | |
| 301 | try: |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 302 | check_call('mkdir -p %s' % scratch_dir, shell=True) |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 303 | except CalledProcessError as err: |
| 304 | pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 305 | call('rm -f %s' % fs_img, shell=True) |
Alper Nebi Yasak | 46132c2 | 2021-05-20 22:09:46 +0300 | [diff] [blame] | 306 | return |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 307 | |
| 308 | try: |
AKASHI Takahiro | dde5d3f | 2018-09-11 15:59:20 +0900 | [diff] [blame] | 309 | # Create a test directory |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 310 | check_call('mkdir %s/dir1' % scratch_dir, shell=True) |
AKASHI Takahiro | dde5d3f | 2018-09-11 15:59:20 +0900 | [diff] [blame] | 311 | |
| 312 | # Create a small file and calculate md5 |
| 313 | check_call('dd if=/dev/urandom of=%s bs=1K count=20' |
| 314 | % min_file, shell=True) |
| 315 | out = check_output( |
| 316 | 'dd if=%s bs=1K 2> /dev/null | md5sum' |
Tom Rini | 784e27d | 2019-10-24 11:59:24 -0400 | [diff] [blame] | 317 | % min_file, shell=True).decode() |
AKASHI Takahiro | dde5d3f | 2018-09-11 15:59:20 +0900 | [diff] [blame] | 318 | md5val = [ out.split()[0] ] |
| 319 | |
| 320 | # Calculate md5sum of Test Case 4 |
| 321 | check_call('dd if=%s of=%s bs=1K count=20' |
| 322 | % (min_file, tmp_file), shell=True) |
| 323 | check_call('dd if=%s of=%s bs=1K seek=5 count=20' |
| 324 | % (min_file, tmp_file), shell=True) |
| 325 | out = check_output('dd if=%s bs=1K 2> /dev/null | md5sum' |
Tom Rini | 784e27d | 2019-10-24 11:59:24 -0400 | [diff] [blame] | 326 | % tmp_file, shell=True).decode() |
AKASHI Takahiro | dde5d3f | 2018-09-11 15:59:20 +0900 | [diff] [blame] | 327 | md5val.append(out.split()[0]) |
| 328 | |
| 329 | # Calculate md5sum of Test Case 5 |
| 330 | check_call('dd if=%s of=%s bs=1K count=20' |
| 331 | % (min_file, tmp_file), shell=True) |
| 332 | check_call('dd if=%s of=%s bs=1K seek=5 count=5' |
| 333 | % (min_file, tmp_file), shell=True) |
| 334 | out = check_output('dd if=%s bs=1K 2> /dev/null | md5sum' |
Tom Rini | 784e27d | 2019-10-24 11:59:24 -0400 | [diff] [blame] | 335 | % tmp_file, shell=True).decode() |
AKASHI Takahiro | dde5d3f | 2018-09-11 15:59:20 +0900 | [diff] [blame] | 336 | md5val.append(out.split()[0]) |
| 337 | |
| 338 | # Calculate md5sum of Test Case 7 |
| 339 | check_call('dd if=%s of=%s bs=1K count=20' |
| 340 | % (min_file, tmp_file), shell=True) |
| 341 | check_call('dd if=%s of=%s bs=1K seek=20 count=20' |
| 342 | % (min_file, tmp_file), shell=True) |
| 343 | out = check_output('dd if=%s bs=1K 2> /dev/null | md5sum' |
Tom Rini | 784e27d | 2019-10-24 11:59:24 -0400 | [diff] [blame] | 344 | % tmp_file, shell=True).decode() |
AKASHI Takahiro | dde5d3f | 2018-09-11 15:59:20 +0900 | [diff] [blame] | 345 | md5val.append(out.split()[0]) |
| 346 | |
| 347 | check_call('rm %s' % tmp_file, shell=True) |
Richard Weinberger | 41eca32 | 2024-11-21 15:32:07 -0700 | [diff] [blame] | 348 | |
| 349 | try: |
| 350 | # 128MiB volume |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 351 | fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', scratch_dir) |
Richard Weinberger | 41eca32 | 2024-11-21 15:32:07 -0700 | [diff] [blame] | 352 | except CalledProcessError as err: |
| 353 | pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) |
| 354 | return |
| 355 | |
AKASHI Takahiro | 615af9a | 2018-09-11 15:59:19 +0900 | [diff] [blame] | 356 | except CalledProcessError: |
| 357 | pytest.skip('Setup failed for filesystem: ' + fs_type) |
| 358 | return |
| 359 | else: |
| 360 | yield [fs_ubtype, fs_img, md5val] |
| 361 | finally: |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 362 | call('rm -rf %s' % scratch_dir, shell=True) |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 363 | call('rm -f %s' % fs_img, shell=True) |
AKASHI Takahiro | 1e90c2c | 2018-09-11 15:59:21 +0900 | [diff] [blame] | 364 | |
| 365 | # |
| 366 | # Fixture for mkdir test |
| 367 | # |
Tom Rini | 1b91cee | 2021-01-28 14:39:56 -0500 | [diff] [blame] | 368 | @pytest.fixture() |
AKASHI Takahiro | 1e90c2c | 2018-09-11 15:59:21 +0900 | [diff] [blame] | 369 | def fs_obj_mkdir(request, u_boot_config): |
Akashi Takahiro | bcdd1f2 | 2018-09-27 16:07:23 +0900 | [diff] [blame] | 370 | """Set up a file system to be used in mkdir test. |
| 371 | |
| 372 | Args: |
| 373 | request: Pytest request object. |
Michal Simek | 50fa118 | 2023-05-17 09:17:16 +0200 | [diff] [blame] | 374 | u_boot_config: U-Boot configuration. |
Akashi Takahiro | bcdd1f2 | 2018-09-27 16:07:23 +0900 | [diff] [blame] | 375 | |
| 376 | Return: |
| 377 | A fixture for mkdir test, i.e. a duplet of file system type and |
| 378 | volume file name. |
| 379 | """ |
AKASHI Takahiro | 1e90c2c | 2018-09-11 15:59:21 +0900 | [diff] [blame] | 380 | fs_type = request.param |
| 381 | fs_img = '' |
| 382 | |
| 383 | fs_ubtype = fstype_to_ubname(fs_type) |
| 384 | check_ubconfig(u_boot_config, fs_ubtype) |
| 385 | |
| 386 | try: |
| 387 | # 128MiB volume |
Richard Weinberger | 41eca32 | 2024-11-21 15:32:07 -0700 | [diff] [blame] | 388 | fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', None) |
AKASHI Takahiro | 1e90c2c | 2018-09-11 15:59:21 +0900 | [diff] [blame] | 389 | except: |
| 390 | pytest.skip('Setup failed for filesystem: ' + fs_type) |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 391 | return |
AKASHI Takahiro | 1e90c2c | 2018-09-11 15:59:21 +0900 | [diff] [blame] | 392 | else: |
| 393 | yield [fs_ubtype, fs_img] |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 394 | call('rm -f %s' % fs_img, shell=True) |
Akashi, Takahiro | d49e799 | 2018-09-11 16:06:03 +0900 | [diff] [blame] | 395 | |
| 396 | # |
| 397 | # Fixture for unlink test |
| 398 | # |
Tom Rini | 1b91cee | 2021-01-28 14:39:56 -0500 | [diff] [blame] | 399 | @pytest.fixture() |
Akashi, Takahiro | d49e799 | 2018-09-11 16:06:03 +0900 | [diff] [blame] | 400 | def fs_obj_unlink(request, u_boot_config): |
Akashi Takahiro | bcdd1f2 | 2018-09-27 16:07:23 +0900 | [diff] [blame] | 401 | """Set up a file system to be used in unlink test. |
| 402 | |
| 403 | Args: |
| 404 | request: Pytest request object. |
Michal Simek | 50fa118 | 2023-05-17 09:17:16 +0200 | [diff] [blame] | 405 | u_boot_config: U-Boot configuration. |
Akashi Takahiro | bcdd1f2 | 2018-09-27 16:07:23 +0900 | [diff] [blame] | 406 | |
| 407 | Return: |
| 408 | A fixture for unlink test, i.e. a duplet of file system type and |
| 409 | volume file name. |
| 410 | """ |
Akashi, Takahiro | d49e799 | 2018-09-11 16:06:03 +0900 | [diff] [blame] | 411 | fs_type = request.param |
| 412 | fs_img = '' |
| 413 | |
| 414 | fs_ubtype = fstype_to_ubname(fs_type) |
| 415 | check_ubconfig(u_boot_config, fs_ubtype) |
| 416 | |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 417 | scratch_dir = u_boot_config.persistent_data_dir + '/scratch' |
Akashi, Takahiro | d49e799 | 2018-09-11 16:06:03 +0900 | [diff] [blame] | 418 | |
| 419 | try: |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 420 | check_call('mkdir -p %s' % scratch_dir, shell=True) |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 421 | except CalledProcessError as err: |
| 422 | pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 423 | call('rm -f %s' % fs_img, shell=True) |
Alper Nebi Yasak | 46132c2 | 2021-05-20 22:09:46 +0300 | [diff] [blame] | 424 | return |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 425 | |
| 426 | try: |
Akashi, Takahiro | d49e799 | 2018-09-11 16:06:03 +0900 | [diff] [blame] | 427 | # Test Case 1 & 3 |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 428 | check_call('mkdir %s/dir1' % scratch_dir, shell=True) |
Akashi, Takahiro | d49e799 | 2018-09-11 16:06:03 +0900 | [diff] [blame] | 429 | check_call('dd if=/dev/urandom of=%s/dir1/file1 bs=1K count=1' |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 430 | % scratch_dir, shell=True) |
Akashi, Takahiro | d49e799 | 2018-09-11 16:06:03 +0900 | [diff] [blame] | 431 | check_call('dd if=/dev/urandom of=%s/dir1/file2 bs=1K count=1' |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 432 | % scratch_dir, shell=True) |
Akashi, Takahiro | d49e799 | 2018-09-11 16:06:03 +0900 | [diff] [blame] | 433 | |
| 434 | # Test Case 2 |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 435 | check_call('mkdir %s/dir2' % scratch_dir, shell=True) |
Tom Rini | 7f24c19 | 2019-10-24 11:59:20 -0400 | [diff] [blame] | 436 | for i in range(0, 20): |
| 437 | check_call('mkdir %s/dir2/0123456789abcdef%02x' |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 438 | % (scratch_dir, i), shell=True) |
Akashi, Takahiro | d49e799 | 2018-09-11 16:06:03 +0900 | [diff] [blame] | 439 | |
| 440 | # Test Case 4 |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 441 | check_call('mkdir %s/dir4' % scratch_dir, shell=True) |
Akashi, Takahiro | d49e799 | 2018-09-11 16:06:03 +0900 | [diff] [blame] | 442 | |
| 443 | # Test Case 5, 6 & 7 |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 444 | check_call('mkdir %s/dir5' % scratch_dir, shell=True) |
Akashi, Takahiro | d49e799 | 2018-09-11 16:06:03 +0900 | [diff] [blame] | 445 | check_call('dd if=/dev/urandom of=%s/dir5/file1 bs=1K count=1' |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 446 | % scratch_dir, shell=True) |
Akashi, Takahiro | d49e799 | 2018-09-11 16:06:03 +0900 | [diff] [blame] | 447 | |
Richard Weinberger | 41eca32 | 2024-11-21 15:32:07 -0700 | [diff] [blame] | 448 | try: |
| 449 | # 128MiB volume |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 450 | fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', scratch_dir) |
Richard Weinberger | 41eca32 | 2024-11-21 15:32:07 -0700 | [diff] [blame] | 451 | except CalledProcessError as err: |
| 452 | pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) |
| 453 | return |
| 454 | |
Akashi, Takahiro | d49e799 | 2018-09-11 16:06:03 +0900 | [diff] [blame] | 455 | except CalledProcessError: |
| 456 | pytest.skip('Setup failed for filesystem: ' + fs_type) |
| 457 | return |
| 458 | else: |
| 459 | yield [fs_ubtype, fs_img] |
| 460 | finally: |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 461 | call('rm -rf %s' % scratch_dir, shell=True) |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 462 | call('rm -f %s' % fs_img, shell=True) |
Jean-Jacques Hiblot | 8aea8a6 | 2019-02-13 12:15:27 +0100 | [diff] [blame] | 463 | |
| 464 | # |
| 465 | # Fixture for symlink fs test |
| 466 | # |
Tom Rini | 1b91cee | 2021-01-28 14:39:56 -0500 | [diff] [blame] | 467 | @pytest.fixture() |
Jean-Jacques Hiblot | 8aea8a6 | 2019-02-13 12:15:27 +0100 | [diff] [blame] | 468 | def fs_obj_symlink(request, u_boot_config): |
| 469 | """Set up a file system to be used in symlink fs test. |
| 470 | |
| 471 | Args: |
| 472 | request: Pytest request object. |
Michal Simek | 50fa118 | 2023-05-17 09:17:16 +0200 | [diff] [blame] | 473 | u_boot_config: U-Boot configuration. |
Jean-Jacques Hiblot | 8aea8a6 | 2019-02-13 12:15:27 +0100 | [diff] [blame] | 474 | |
| 475 | Return: |
| 476 | A fixture for basic fs test, i.e. a triplet of file system type, |
| 477 | volume file name and a list of MD5 hashes. |
| 478 | """ |
| 479 | fs_type = request.param |
| 480 | fs_img = '' |
| 481 | |
| 482 | fs_ubtype = fstype_to_ubname(fs_type) |
| 483 | check_ubconfig(u_boot_config, fs_ubtype) |
| 484 | |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 485 | scratch_dir = u_boot_config.persistent_data_dir + '/scratch' |
Jean-Jacques Hiblot | 8aea8a6 | 2019-02-13 12:15:27 +0100 | [diff] [blame] | 486 | |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 487 | small_file = scratch_dir + '/' + SMALL_FILE |
| 488 | medium_file = scratch_dir + '/' + MEDIUM_FILE |
Jean-Jacques Hiblot | 8aea8a6 | 2019-02-13 12:15:27 +0100 | [diff] [blame] | 489 | |
| 490 | try: |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 491 | check_call('mkdir -p %s' % scratch_dir, shell=True) |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 492 | except CalledProcessError as err: |
| 493 | pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 494 | call('rm -f %s' % fs_img, shell=True) |
Alper Nebi Yasak | 46132c2 | 2021-05-20 22:09:46 +0300 | [diff] [blame] | 495 | return |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 496 | |
| 497 | try: |
Jean-Jacques Hiblot | 8aea8a6 | 2019-02-13 12:15:27 +0100 | [diff] [blame] | 498 | # Create a subdirectory. |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 499 | check_call('mkdir %s/SUBDIR' % scratch_dir, shell=True) |
Jean-Jacques Hiblot | 8aea8a6 | 2019-02-13 12:15:27 +0100 | [diff] [blame] | 500 | |
| 501 | # Create a small file in this image. |
| 502 | check_call('dd if=/dev/urandom of=%s bs=1M count=1' |
| 503 | % small_file, shell=True) |
| 504 | |
| 505 | # Create a medium file in this image. |
| 506 | check_call('dd if=/dev/urandom of=%s bs=10M count=1' |
| 507 | % medium_file, shell=True) |
| 508 | |
| 509 | # Generate the md5sums of reads that we will test against small file |
| 510 | out = check_output( |
| 511 | 'dd if=%s bs=1M skip=0 count=1 2> /dev/null | md5sum' |
Tom Rini | 784e27d | 2019-10-24 11:59:24 -0400 | [diff] [blame] | 512 | % small_file, shell=True).decode() |
Jean-Jacques Hiblot | 8aea8a6 | 2019-02-13 12:15:27 +0100 | [diff] [blame] | 513 | md5val = [out.split()[0]] |
| 514 | out = check_output( |
| 515 | 'dd if=%s bs=10M skip=0 count=1 2> /dev/null | md5sum' |
Tom Rini | 784e27d | 2019-10-24 11:59:24 -0400 | [diff] [blame] | 516 | % medium_file, shell=True).decode() |
Jean-Jacques Hiblot | 8aea8a6 | 2019-02-13 12:15:27 +0100 | [diff] [blame] | 517 | md5val.extend([out.split()[0]]) |
| 518 | |
Richard Weinberger | 41eca32 | 2024-11-21 15:32:07 -0700 | [diff] [blame] | 519 | try: |
| 520 | # 1GiB volume |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 521 | fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x40000000, '1GB', scratch_dir) |
Richard Weinberger | 41eca32 | 2024-11-21 15:32:07 -0700 | [diff] [blame] | 522 | except CalledProcessError as err: |
| 523 | pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) |
| 524 | return |
| 525 | |
Jean-Jacques Hiblot | 8aea8a6 | 2019-02-13 12:15:27 +0100 | [diff] [blame] | 526 | except CalledProcessError: |
| 527 | pytest.skip('Setup failed for filesystem: ' + fs_type) |
| 528 | return |
| 529 | else: |
| 530 | yield [fs_ubtype, fs_img, md5val] |
| 531 | finally: |
Richard Weinberger | ba878ce | 2024-11-21 15:32:08 -0700 | [diff] [blame] | 532 | call('rm -rf %s' % scratch_dir, shell=True) |
Andy Shevchenko | e70ed8c | 2021-02-11 16:40:12 +0200 | [diff] [blame] | 533 | call('rm -f %s' % fs_img, shell=True) |
Christian Taedcke | 570dc36 | 2023-11-15 13:44:24 +0100 | [diff] [blame] | 534 | |
| 535 | # |
Gabriel Dalimonte | 4b93d6e | 2025-02-17 13:26:44 -0500 | [diff] [blame] | 536 | # Fixture for rename test |
| 537 | # |
| 538 | @pytest.fixture() |
| 539 | def fs_obj_rename(request, u_boot_config): |
| 540 | """Set up a file system to be used in rename tests. |
| 541 | |
| 542 | Args: |
| 543 | request: Pytest request object. |
| 544 | u_boot_config: U-Boot configuration. |
| 545 | |
| 546 | Return: |
| 547 | A fixture for rename tests, i.e. a triplet of file system type, |
| 548 | volume file name, and dictionary of test identifier and md5val. |
| 549 | """ |
| 550 | def new_rand_file(path): |
| 551 | check_call('dd if=/dev/urandom of=%s bs=1K count=1' % path, shell=True) |
| 552 | |
| 553 | def file_hash(path): |
| 554 | out = check_output( |
| 555 | 'dd if=%s bs=1K skip=0 count=1 2> /dev/null | md5sum' % path, |
| 556 | shell=True |
| 557 | ) |
| 558 | return out.decode().split()[0] |
| 559 | |
| 560 | fs_type = request.param |
| 561 | fs_img = '' |
| 562 | |
| 563 | fs_ubtype = fstype_to_ubname(fs_type) |
| 564 | check_ubconfig(u_boot_config, fs_ubtype) |
| 565 | |
| 566 | mount_dir = u_boot_config.persistent_data_dir + '/scratch' |
| 567 | |
| 568 | try: |
| 569 | check_call('mkdir -p %s' % mount_dir, shell=True) |
| 570 | except CalledProcessError as err: |
| 571 | pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) |
| 572 | call('rm -f %s' % fs_img, shell=True) |
| 573 | return |
| 574 | |
| 575 | try: |
| 576 | md5val = {} |
| 577 | # Test Case 1 |
| 578 | check_call('mkdir %s/test1' % mount_dir, shell=True) |
| 579 | new_rand_file('%s/test1/file1' % mount_dir) |
| 580 | md5val['test1'] = file_hash('%s/test1/file1' % mount_dir) |
| 581 | |
| 582 | # Test Case 2 |
| 583 | check_call('mkdir %s/test2' % mount_dir, shell=True) |
| 584 | new_rand_file('%s/test2/file1' % mount_dir) |
| 585 | new_rand_file('%s/test2/file_exist' % mount_dir) |
| 586 | md5val['test2'] = file_hash('%s/test2/file1' % mount_dir) |
| 587 | |
| 588 | # Test Case 3 |
| 589 | check_call('mkdir -p %s/test3/dir1' % mount_dir, shell=True) |
| 590 | new_rand_file('%s/test3/dir1/file1' % mount_dir) |
| 591 | md5val['test3'] = file_hash('%s/test3/dir1/file1' % mount_dir) |
| 592 | |
| 593 | # Test Case 4 |
| 594 | check_call('mkdir -p %s/test4/dir1' % mount_dir, shell=True) |
| 595 | check_call('mkdir -p %s/test4/dir2/dir1' % mount_dir, shell=True) |
| 596 | new_rand_file('%s/test4/dir1/file1' % mount_dir) |
| 597 | md5val['test4'] = file_hash('%s/test4/dir1/file1' % mount_dir) |
| 598 | |
| 599 | # Test Case 5 |
| 600 | check_call('mkdir -p %s/test5/dir1' % mount_dir, shell=True) |
| 601 | new_rand_file('%s/test5/file2' % mount_dir) |
| 602 | md5val['test5'] = file_hash('%s/test5/file2' % mount_dir) |
| 603 | |
| 604 | # Test Case 6 |
| 605 | check_call('mkdir -p %s/test6/dir2/existing' % mount_dir, shell=True) |
| 606 | new_rand_file('%s/test6/existing' % mount_dir) |
| 607 | md5val['test6'] = file_hash('%s/test6/existing' % mount_dir) |
| 608 | |
| 609 | # Test Case 7 |
| 610 | check_call('mkdir -p %s/test7/dir1' % mount_dir, shell=True) |
| 611 | check_call('mkdir -p %s/test7/dir2/dir1' % mount_dir, shell=True) |
| 612 | new_rand_file('%s/test7/dir2/dir1/file1' % mount_dir) |
| 613 | md5val['test7'] = file_hash('%s/test7/dir2/dir1/file1' % mount_dir) |
| 614 | |
| 615 | # Test Case 8 |
| 616 | check_call('mkdir -p %s/test8/dir1' % mount_dir, shell=True) |
| 617 | new_rand_file('%s/test8/dir1/file1' % mount_dir) |
| 618 | md5val['test8'] = file_hash('%s/test8/dir1/file1' % mount_dir) |
| 619 | |
| 620 | # Test Case 9 |
| 621 | check_call('mkdir -p %s/test9/dir1/nested/inner' % mount_dir, shell=True) |
| 622 | new_rand_file('%s/test9/dir1/nested/inner/file1' % mount_dir) |
| 623 | |
| 624 | # Test Case 10 |
| 625 | check_call('mkdir -p %s/test10' % mount_dir, shell=True) |
| 626 | new_rand_file('%s/test10/file1' % mount_dir) |
| 627 | md5val['test10'] = file_hash('%s/test10/file1' % mount_dir) |
| 628 | |
| 629 | # Test Case 11 |
| 630 | check_call('mkdir -p %s/test11/dir1' % mount_dir, shell=True) |
| 631 | new_rand_file('%s/test11/dir1/file1' % mount_dir) |
| 632 | md5val['test11'] = file_hash('%s/test11/dir1/file1' % mount_dir) |
| 633 | |
| 634 | try: |
| 635 | # 128MiB volume |
| 636 | fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', mount_dir) |
| 637 | except CalledProcessError as err: |
| 638 | pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) |
| 639 | return |
| 640 | |
| 641 | except CalledProcessError: |
| 642 | pytest.skip('Setup failed for filesystem: ' + fs_type) |
| 643 | return |
| 644 | else: |
| 645 | yield [fs_ubtype, fs_img, md5val] |
| 646 | finally: |
| 647 | call('rm -rf %s' % mount_dir, shell=True) |
| 648 | call('rm -f %s' % fs_img, shell=True) |
| 649 | |
| 650 | # |
Christian Taedcke | 570dc36 | 2023-11-15 13:44:24 +0100 | [diff] [blame] | 651 | # Fixture for fat test |
| 652 | # |
| 653 | @pytest.fixture() |
| 654 | def fs_obj_fat(request, u_boot_config): |
| 655 | """Set up a file system to be used in fat test. |
| 656 | |
| 657 | Args: |
| 658 | request: Pytest request object. |
| 659 | u_boot_config: U-Boot configuration. |
| 660 | |
| 661 | Return: |
| 662 | A fixture for fat test, i.e. a duplet of file system type and |
| 663 | volume file name. |
| 664 | """ |
| 665 | |
| 666 | # the maximum size of a FAT12 filesystem resulting in 4084 clusters |
| 667 | MAX_FAT12_SIZE = 261695 * 1024 |
| 668 | |
| 669 | # the minimum size of a FAT16 filesystem that can be created with |
| 670 | # mkfs.vfat resulting in 4087 clusters |
| 671 | MIN_FAT16_SIZE = 8208 * 1024 |
| 672 | |
| 673 | fs_type = request.param |
| 674 | fs_img = '' |
| 675 | |
| 676 | fs_ubtype = fstype_to_ubname(fs_type) |
| 677 | check_ubconfig(u_boot_config, fs_ubtype) |
| 678 | |
| 679 | fs_size = MAX_FAT12_SIZE if fs_type == 'fat12' else MIN_FAT16_SIZE |
| 680 | |
| 681 | try: |
| 682 | # the volume size depends on the filesystem |
Richard Weinberger | 41eca32 | 2024-11-21 15:32:07 -0700 | [diff] [blame] | 683 | fs_img = fs_helper.mk_fs(u_boot_config, fs_type, fs_size, f'{fs_size}', None, 1024) |
Christian Taedcke | 570dc36 | 2023-11-15 13:44:24 +0100 | [diff] [blame] | 684 | except: |
| 685 | pytest.skip('Setup failed for filesystem: ' + fs_type) |
| 686 | return |
| 687 | else: |
| 688 | yield [fs_ubtype, fs_img] |
| 689 | call('rm -f %s' % fs_img, shell=True) |