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