blob: ee82169c2a37eae1d2b22e23fc9289869a8971c2 [file] [log] [blame]
AKASHI Takahiro615af9a2018-09-11 15:59:19 +09001# SPDX-License-Identifier: GPL-2.0+
2# Copyright (c) 2018, Linaro Limited
3# Author: Takahiro Akashi <takahiro.akashi@linaro.org>
4
5import os
6import os.path
7import pytest
8import re
9from subprocess import call, check_call, check_output, CalledProcessError
10from fstest_defs import *
11
12supported_fs_basic = ['fat16', 'fat32', 'ext4']
AKASHI Takahirodde5d3f2018-09-11 15:59:20 +090013supported_fs_ext = ['fat16', 'fat32']
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090014supported_fs_mkdir = ['fat16', 'fat32']
Akashi, Takahirod49e7992018-09-11 16:06:03 +090015supported_fs_unlink = ['fat16', 'fat32']
Jean-Jacques Hiblot8aea8a62019-02-13 12:15:27 +010016supported_fs_symlink = ['ext4']
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090017
18#
19# Filesystem test specific setup
20#
21def pytest_addoption(parser):
Akashi Takahirobcdd1f22018-09-27 16:07:23 +090022 """Enable --fs-type option.
23
24 See pytest_configure() about how it works.
25
26 Args:
27 parser: Pytest command-line parser.
28
29 Returns:
30 Nothing.
31 """
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090032 parser.addoption('--fs-type', action='append', default=None,
33 help='Targeting Filesystem Types')
34
35def pytest_configure(config):
Akashi Takahirobcdd1f22018-09-27 16:07:23 +090036 """Restrict a file system(s) to be tested.
37
38 A file system explicitly named with --fs-type option is selected
39 if it belongs to a default supported_fs_xxx list.
40 Multiple options can be specified.
41
42 Args:
43 config: Pytest configuration.
44
45 Returns:
46 Nothing.
47 """
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090048 global supported_fs_basic
AKASHI Takahirodde5d3f2018-09-11 15:59:20 +090049 global supported_fs_ext
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090050 global supported_fs_mkdir
Akashi, Takahirod49e7992018-09-11 16:06:03 +090051 global supported_fs_unlink
Jean-Jacques Hiblot8aea8a62019-02-13 12:15:27 +010052 global supported_fs_symlink
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090053
54 def intersect(listA, listB):
55 return [x for x in listA if x in listB]
56
57 supported_fs = config.getoption('fs_type')
58 if supported_fs:
Simon Glasse9f4d872018-12-27 08:11:13 -070059 print('*** FS TYPE modified: %s' % supported_fs)
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090060 supported_fs_basic = intersect(supported_fs, supported_fs_basic)
AKASHI Takahirodde5d3f2018-09-11 15:59:20 +090061 supported_fs_ext = intersect(supported_fs, supported_fs_ext)
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090062 supported_fs_mkdir = intersect(supported_fs, supported_fs_mkdir)
Akashi, Takahirod49e7992018-09-11 16:06:03 +090063 supported_fs_unlink = intersect(supported_fs, supported_fs_unlink)
Jean-Jacques Hiblot8aea8a62019-02-13 12:15:27 +010064 supported_fs_symlink = intersect(supported_fs, supported_fs_symlink)
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090065
66def pytest_generate_tests(metafunc):
Akashi Takahirobcdd1f22018-09-27 16:07:23 +090067 """Parametrize fixtures, fs_obj_xxx
68
69 Each fixture will be parametrized with a corresponding support_fs_xxx
70 list.
71
72 Args:
73 metafunc: Pytest test function.
74
75 Returns:
76 Nothing.
77 """
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090078 if 'fs_obj_basic' in metafunc.fixturenames:
79 metafunc.parametrize('fs_obj_basic', supported_fs_basic,
80 indirect=True, scope='module')
AKASHI Takahirodde5d3f2018-09-11 15:59:20 +090081 if 'fs_obj_ext' in metafunc.fixturenames:
82 metafunc.parametrize('fs_obj_ext', supported_fs_ext,
83 indirect=True, scope='module')
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090084 if 'fs_obj_mkdir' in metafunc.fixturenames:
85 metafunc.parametrize('fs_obj_mkdir', supported_fs_mkdir,
86 indirect=True, scope='module')
Akashi, Takahirod49e7992018-09-11 16:06:03 +090087 if 'fs_obj_unlink' in metafunc.fixturenames:
88 metafunc.parametrize('fs_obj_unlink', supported_fs_unlink,
89 indirect=True, scope='module')
Jean-Jacques Hiblot8aea8a62019-02-13 12:15:27 +010090 if 'fs_obj_symlink' in metafunc.fixturenames:
91 metafunc.parametrize('fs_obj_symlink', supported_fs_symlink,
92 indirect=True, scope='module')
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090093
94#
95# Helper functions
96#
97def fstype_to_ubname(fs_type):
Akashi Takahirobcdd1f22018-09-27 16:07:23 +090098 """Convert a file system type to an U-boot specific string
99
100 A generated string can be used as part of file system related commands
101 or a config name in u-boot. Currently fat16 and fat32 are handled
102 specifically.
103
104 Args:
105 fs_type: File system type.
106
107 Return:
108 A corresponding string for file system type.
109 """
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900110 if re.match('fat', fs_type):
111 return 'fat'
112 else:
113 return fs_type
114
115def check_ubconfig(config, fs_type):
Akashi Takahirobcdd1f22018-09-27 16:07:23 +0900116 """Check whether a file system is enabled in u-boot configuration.
117
118 This function is assumed to be called in a fixture function so that
119 the whole test cases will be skipped if a given file system is not
120 enabled.
121
122 Args:
123 fs_type: File system type.
124
125 Return:
126 Nothing.
127 """
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900128 if not config.buildconfig.get('config_cmd_%s' % fs_type, None):
129 pytest.skip('.config feature "CMD_%s" not enabled' % fs_type.upper())
130 if not config.buildconfig.get('config_%s_write' % fs_type, None):
131 pytest.skip('.config feature "%s_WRITE" not enabled'
132 % fs_type.upper())
133
134def mk_fs(config, fs_type, size, id):
Akashi Takahirobcdd1f22018-09-27 16:07:23 +0900135 """Create a file system volume.
136
137 Args:
138 fs_type: File system type.
139 size: Size of file system in MiB.
140 id: Prefix string of volume's file name.
141
142 Return:
143 Nothing.
144 """
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900145 fs_img = '%s.%s.img' % (id, fs_type)
146 fs_img = config.persistent_data_dir + '/' + fs_img
147
148 if fs_type == 'fat16':
149 mkfs_opt = '-F 16'
150 elif fs_type == 'fat32':
151 mkfs_opt = '-F 32'
Jean-Jacques Hiblot5390ced2019-02-13 12:15:22 +0100152 elif fs_type == 'ext4':
153 mkfs_opt = '-O ^metadata_csum'
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900154 else:
155 mkfs_opt = ''
156
157 if re.match('fat', fs_type):
158 fs_lnxtype = 'vfat'
159 else:
160 fs_lnxtype = fs_type
161
162 count = (size + 1048576 - 1) / 1048576
163
164 try:
165 check_call('rm -f %s' % fs_img, shell=True)
166 check_call('dd if=/dev/zero of=%s bs=1M count=%d'
167 % (fs_img, count), shell=True)
168 check_call('mkfs.%s %s %s'
169 % (fs_lnxtype, mkfs_opt, fs_img), shell=True)
170 return fs_img
171 except CalledProcessError:
172 call('rm -f %s' % fs_img, shell=True)
173 raise
174
175# from test/py/conftest.py
176def tool_is_in_path(tool):
Akashi Takahirobcdd1f22018-09-27 16:07:23 +0900177 """Check whether a given command is available on host.
178
179 Args:
180 tool: Command name.
181
182 Return:
183 True if available, False if not.
184 """
Simon Glasse9f4d872018-12-27 08:11:13 -0700185 for path in os.environ['PATH'].split(os.pathsep):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900186 fn = os.path.join(path, tool)
187 if os.path.isfile(fn) and os.access(fn, os.X_OK):
188 return True
189 return False
190
191fuse_mounted = False
192
193def mount_fs(fs_type, device, mount_point):
Akashi Takahirobcdd1f22018-09-27 16:07:23 +0900194 """Mount a volume.
195
196 Args:
197 fs_type: File system type.
198 device: Volume's file name.
199 mount_point: Mount point.
200
201 Return:
202 Nothing.
203 """
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900204 global fuse_mounted
205
206 fuse_mounted = False
207 try:
208 if tool_is_in_path('guestmount'):
209 fuse_mounted = True
210 check_call('guestmount -a %s -m /dev/sda %s'
211 % (device, mount_point), shell=True)
212 else:
Simon Glasse9f4d872018-12-27 08:11:13 -0700213 mount_opt = 'loop,rw'
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900214 if re.match('fat', fs_type):
Simon Glasse9f4d872018-12-27 08:11:13 -0700215 mount_opt += ',umask=0000'
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900216
217 check_call('sudo mount -o %s %s %s'
218 % (mount_opt, device, mount_point), shell=True)
219
220 # may not be effective for some file systems
221 check_call('sudo chmod a+rw %s' % mount_point, shell=True)
222 except CalledProcessError:
223 raise
224
Akashi Takahiro89101f82018-09-27 16:07:22 +0900225def umount_fs(mount_point):
Akashi Takahirobcdd1f22018-09-27 16:07:23 +0900226 """Unmount a volume.
227
228 Args:
229 mount_point: Mount point.
230
231 Return:
232 Nothing.
233 """
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900234 if fuse_mounted:
235 call('sync')
236 call('guestunmount %s' % mount_point, shell=True)
237 else:
238 call('sudo umount %s' % mount_point, shell=True)
239
240#
241# Fixture for basic fs test
242# derived from test/fs/fs-test.sh
243#
244# NOTE: yield_fixture was deprecated since pytest-3.0
245@pytest.yield_fixture()
246def fs_obj_basic(request, u_boot_config):
Akashi Takahirobcdd1f22018-09-27 16:07:23 +0900247 """Set up a file system to be used in basic fs test.
248
249 Args:
250 request: Pytest request object.
251 u_boot_config: U-boot configuration.
252
253 Return:
254 A fixture for basic fs test, i.e. a triplet of file system type,
255 volume file name and a list of MD5 hashes.
256 """
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900257 fs_type = request.param
258 fs_img = ''
259
260 fs_ubtype = fstype_to_ubname(fs_type)
261 check_ubconfig(u_boot_config, fs_ubtype)
262
263 mount_dir = u_boot_config.persistent_data_dir + '/mnt'
264
265 small_file = mount_dir + '/' + SMALL_FILE
266 big_file = mount_dir + '/' + BIG_FILE
267
268 try:
269
270 # 3GiB volume
271 fs_img = mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB')
272
273 # Mount the image so we can populate it.
274 check_call('mkdir -p %s' % mount_dir, shell=True)
275 mount_fs(fs_type, fs_img, mount_dir)
276
277 # Create a subdirectory.
278 check_call('mkdir %s/SUBDIR' % mount_dir, shell=True)
279
280 # Create big file in this image.
281 # Note that we work only on the start 1MB, couple MBs in the 2GB range
282 # and the last 1 MB of the huge 2.5GB file.
283 # So, just put random values only in those areas.
284 check_call('dd if=/dev/urandom of=%s bs=1M count=1'
285 % big_file, shell=True)
286 check_call('dd if=/dev/urandom of=%s bs=1M count=2 seek=2047'
287 % big_file, shell=True)
288 check_call('dd if=/dev/urandom of=%s bs=1M count=1 seek=2499'
289 % big_file, shell=True)
290
291 # Create a small file in this image.
292 check_call('dd if=/dev/urandom of=%s bs=1M count=1'
293 % small_file, shell=True)
294
295 # Delete the small file copies which possibly are written as part of a
296 # previous test.
297 # check_call('rm -f "%s.w"' % MB1, shell=True)
298 # check_call('rm -f "%s.w2"' % MB1, shell=True)
299
300 # Generate the md5sums of reads that we will test against small file
301 out = check_output(
302 'dd if=%s bs=1M skip=0 count=1 2> /dev/null | md5sum'
Tom Rini784e27d2019-10-24 11:59:24 -0400303 % small_file, shell=True).decode()
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900304 md5val = [ out.split()[0] ]
305
306 # Generate the md5sums of reads that we will test against big file
307 # One from beginning of file.
308 out = check_output(
309 'dd if=%s bs=1M skip=0 count=1 2> /dev/null | md5sum'
Tom Rini784e27d2019-10-24 11:59:24 -0400310 % big_file, shell=True).decode()
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900311 md5val.append(out.split()[0])
312
313 # One from end of file.
314 out = check_output(
315 'dd if=%s bs=1M skip=2499 count=1 2> /dev/null | md5sum'
Tom Rini784e27d2019-10-24 11:59:24 -0400316 % big_file, shell=True).decode()
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900317 md5val.append(out.split()[0])
318
319 # One from the last 1MB chunk of 2GB
320 out = check_output(
321 'dd if=%s bs=1M skip=2047 count=1 2> /dev/null | md5sum'
Tom Rini784e27d2019-10-24 11:59:24 -0400322 % big_file, shell=True).decode()
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900323 md5val.append(out.split()[0])
324
325 # One from the start 1MB chunk from 2GB
326 out = check_output(
327 'dd if=%s bs=1M skip=2048 count=1 2> /dev/null | md5sum'
Tom Rini784e27d2019-10-24 11:59:24 -0400328 % big_file, shell=True).decode()
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900329 md5val.append(out.split()[0])
330
331 # One 1MB chunk crossing the 2GB boundary
332 out = check_output(
333 'dd if=%s bs=512K skip=4095 count=2 2> /dev/null | md5sum'
Tom Rini784e27d2019-10-24 11:59:24 -0400334 % big_file, shell=True).decode()
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900335 md5val.append(out.split()[0])
336
Akashi Takahiro89101f82018-09-27 16:07:22 +0900337 umount_fs(mount_dir)
Heinrich Schuchardtbc856172020-04-20 20:48:40 +0200338 except CalledProcessError as err:
339 pytest.skip('Setup failed for filesystem: ' + fs_type + \
340 '. {}'.format(err))
AKASHI Takahirodde5d3f2018-09-11 15:59:20 +0900341 return
342 else:
343 yield [fs_ubtype, fs_img, md5val]
344 finally:
Akashi Takahiro89101f82018-09-27 16:07:22 +0900345 umount_fs(mount_dir)
AKASHI Takahirodde5d3f2018-09-11 15:59:20 +0900346 call('rmdir %s' % mount_dir, shell=True)
347 if fs_img:
348 call('rm -f %s' % fs_img, shell=True)
349
350#
351# Fixture for extended fs test
352#
353# NOTE: yield_fixture was deprecated since pytest-3.0
354@pytest.yield_fixture()
355def fs_obj_ext(request, u_boot_config):
Akashi Takahirobcdd1f22018-09-27 16:07:23 +0900356 """Set up a file system to be used in extended fs test.
357
358 Args:
359 request: Pytest request object.
360 u_boot_config: U-boot configuration.
361
362 Return:
363 A fixture for extended fs test, i.e. a triplet of file system type,
364 volume file name and a list of MD5 hashes.
365 """
AKASHI Takahirodde5d3f2018-09-11 15:59:20 +0900366 fs_type = request.param
367 fs_img = ''
368
369 fs_ubtype = fstype_to_ubname(fs_type)
370 check_ubconfig(u_boot_config, fs_ubtype)
371
372 mount_dir = u_boot_config.persistent_data_dir + '/mnt'
373
374 min_file = mount_dir + '/' + MIN_FILE
375 tmp_file = mount_dir + '/tmpfile'
376
377 try:
378
379 # 128MiB volume
380 fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
381
382 # Mount the image so we can populate it.
383 check_call('mkdir -p %s' % mount_dir, shell=True)
384 mount_fs(fs_type, fs_img, mount_dir)
385
386 # Create a test directory
387 check_call('mkdir %s/dir1' % mount_dir, shell=True)
388
389 # Create a small file and calculate md5
390 check_call('dd if=/dev/urandom of=%s bs=1K count=20'
391 % min_file, shell=True)
392 out = check_output(
393 'dd if=%s bs=1K 2> /dev/null | md5sum'
Tom Rini784e27d2019-10-24 11:59:24 -0400394 % min_file, shell=True).decode()
AKASHI Takahirodde5d3f2018-09-11 15:59:20 +0900395 md5val = [ out.split()[0] ]
396
397 # Calculate md5sum of Test Case 4
398 check_call('dd if=%s of=%s bs=1K count=20'
399 % (min_file, tmp_file), shell=True)
400 check_call('dd if=%s of=%s bs=1K seek=5 count=20'
401 % (min_file, tmp_file), shell=True)
402 out = check_output('dd if=%s bs=1K 2> /dev/null | md5sum'
Tom Rini784e27d2019-10-24 11:59:24 -0400403 % tmp_file, shell=True).decode()
AKASHI Takahirodde5d3f2018-09-11 15:59:20 +0900404 md5val.append(out.split()[0])
405
406 # Calculate md5sum of Test Case 5
407 check_call('dd if=%s of=%s bs=1K count=20'
408 % (min_file, tmp_file), shell=True)
409 check_call('dd if=%s of=%s bs=1K seek=5 count=5'
410 % (min_file, tmp_file), shell=True)
411 out = check_output('dd if=%s bs=1K 2> /dev/null | md5sum'
Tom Rini784e27d2019-10-24 11:59:24 -0400412 % tmp_file, shell=True).decode()
AKASHI Takahirodde5d3f2018-09-11 15:59:20 +0900413 md5val.append(out.split()[0])
414
415 # Calculate md5sum of Test Case 7
416 check_call('dd if=%s of=%s bs=1K count=20'
417 % (min_file, tmp_file), shell=True)
418 check_call('dd if=%s of=%s bs=1K seek=20 count=20'
419 % (min_file, tmp_file), shell=True)
420 out = check_output('dd if=%s bs=1K 2> /dev/null | md5sum'
Tom Rini784e27d2019-10-24 11:59:24 -0400421 % tmp_file, shell=True).decode()
AKASHI Takahirodde5d3f2018-09-11 15:59:20 +0900422 md5val.append(out.split()[0])
423
424 check_call('rm %s' % tmp_file, shell=True)
Akashi Takahiro89101f82018-09-27 16:07:22 +0900425 umount_fs(mount_dir)
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900426 except CalledProcessError:
427 pytest.skip('Setup failed for filesystem: ' + fs_type)
428 return
429 else:
430 yield [fs_ubtype, fs_img, md5val]
431 finally:
Akashi Takahiro89101f82018-09-27 16:07:22 +0900432 umount_fs(mount_dir)
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900433 call('rmdir %s' % mount_dir, shell=True)
434 if fs_img:
435 call('rm -f %s' % fs_img, shell=True)
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +0900436
437#
438# Fixture for mkdir test
439#
440# NOTE: yield_fixture was deprecated since pytest-3.0
441@pytest.yield_fixture()
442def fs_obj_mkdir(request, u_boot_config):
Akashi Takahirobcdd1f22018-09-27 16:07:23 +0900443 """Set up a file system to be used in mkdir test.
444
445 Args:
446 request: Pytest request object.
447 u_boot_config: U-boot configuration.
448
449 Return:
450 A fixture for mkdir test, i.e. a duplet of file system type and
451 volume file name.
452 """
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +0900453 fs_type = request.param
454 fs_img = ''
455
456 fs_ubtype = fstype_to_ubname(fs_type)
457 check_ubconfig(u_boot_config, fs_ubtype)
458
459 try:
460 # 128MiB volume
461 fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
462 except:
463 pytest.skip('Setup failed for filesystem: ' + fs_type)
464 else:
465 yield [fs_ubtype, fs_img]
466 finally:
467 if fs_img:
468 call('rm -f %s' % fs_img, shell=True)
Akashi, Takahirod49e7992018-09-11 16:06:03 +0900469
470#
471# Fixture for unlink test
472#
473# NOTE: yield_fixture was deprecated since pytest-3.0
474@pytest.yield_fixture()
475def fs_obj_unlink(request, u_boot_config):
Akashi Takahirobcdd1f22018-09-27 16:07:23 +0900476 """Set up a file system to be used in unlink test.
477
478 Args:
479 request: Pytest request object.
480 u_boot_config: U-boot configuration.
481
482 Return:
483 A fixture for unlink test, i.e. a duplet of file system type and
484 volume file name.
485 """
Akashi, Takahirod49e7992018-09-11 16:06:03 +0900486 fs_type = request.param
487 fs_img = ''
488
489 fs_ubtype = fstype_to_ubname(fs_type)
490 check_ubconfig(u_boot_config, fs_ubtype)
491
492 mount_dir = u_boot_config.persistent_data_dir + '/mnt'
493
494 try:
495
496 # 128MiB volume
497 fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
498
499 # Mount the image so we can populate it.
500 check_call('mkdir -p %s' % mount_dir, shell=True)
501 mount_fs(fs_type, fs_img, mount_dir)
502
503 # Test Case 1 & 3
504 check_call('mkdir %s/dir1' % mount_dir, shell=True)
505 check_call('dd if=/dev/urandom of=%s/dir1/file1 bs=1K count=1'
506 % mount_dir, shell=True)
507 check_call('dd if=/dev/urandom of=%s/dir1/file2 bs=1K count=1'
508 % mount_dir, shell=True)
509
510 # Test Case 2
511 check_call('mkdir %s/dir2' % mount_dir, shell=True)
Tom Rini7f24c192019-10-24 11:59:20 -0400512 for i in range(0, 20):
513 check_call('mkdir %s/dir2/0123456789abcdef%02x'
Akashi, Takahirod49e7992018-09-11 16:06:03 +0900514 % (mount_dir, i), shell=True)
515
516 # Test Case 4
517 check_call('mkdir %s/dir4' % mount_dir, shell=True)
518
519 # Test Case 5, 6 & 7
520 check_call('mkdir %s/dir5' % mount_dir, shell=True)
521 check_call('dd if=/dev/urandom of=%s/dir5/file1 bs=1K count=1'
522 % mount_dir, shell=True)
523
Akashi Takahiro89101f82018-09-27 16:07:22 +0900524 umount_fs(mount_dir)
Akashi, Takahirod49e7992018-09-11 16:06:03 +0900525 except CalledProcessError:
526 pytest.skip('Setup failed for filesystem: ' + fs_type)
527 return
528 else:
529 yield [fs_ubtype, fs_img]
530 finally:
Akashi Takahiro89101f82018-09-27 16:07:22 +0900531 umount_fs(mount_dir)
Akashi, Takahirod49e7992018-09-11 16:06:03 +0900532 call('rmdir %s' % mount_dir, shell=True)
533 if fs_img:
534 call('rm -f %s' % fs_img, shell=True)
Jean-Jacques Hiblot8aea8a62019-02-13 12:15:27 +0100535
536#
537# Fixture for symlink fs test
538#
539# NOTE: yield_fixture was deprecated since pytest-3.0
540@pytest.yield_fixture()
541def fs_obj_symlink(request, u_boot_config):
542 """Set up a file system to be used in symlink fs test.
543
544 Args:
545 request: Pytest request object.
546 u_boot_config: U-boot configuration.
547
548 Return:
549 A fixture for basic fs test, i.e. a triplet of file system type,
550 volume file name and a list of MD5 hashes.
551 """
552 fs_type = request.param
553 fs_img = ''
554
555 fs_ubtype = fstype_to_ubname(fs_type)
556 check_ubconfig(u_boot_config, fs_ubtype)
557
558 mount_dir = u_boot_config.persistent_data_dir + '/mnt'
559
560 small_file = mount_dir + '/' + SMALL_FILE
561 medium_file = mount_dir + '/' + MEDIUM_FILE
562
563 try:
564
565 # 3GiB volume
566 fs_img = mk_fs(u_boot_config, fs_type, 0x40000000, '1GB')
567
568 # Mount the image so we can populate it.
569 check_call('mkdir -p %s' % mount_dir, shell=True)
570 mount_fs(fs_type, fs_img, mount_dir)
571
572 # Create a subdirectory.
573 check_call('mkdir %s/SUBDIR' % mount_dir, shell=True)
574
575 # Create a small file in this image.
576 check_call('dd if=/dev/urandom of=%s bs=1M count=1'
577 % small_file, shell=True)
578
579 # Create a medium file in this image.
580 check_call('dd if=/dev/urandom of=%s bs=10M count=1'
581 % medium_file, shell=True)
582
583 # Generate the md5sums of reads that we will test against small file
584 out = check_output(
585 'dd if=%s bs=1M skip=0 count=1 2> /dev/null | md5sum'
Tom Rini784e27d2019-10-24 11:59:24 -0400586 % small_file, shell=True).decode()
Jean-Jacques Hiblot8aea8a62019-02-13 12:15:27 +0100587 md5val = [out.split()[0]]
588 out = check_output(
589 'dd if=%s bs=10M skip=0 count=1 2> /dev/null | md5sum'
Tom Rini784e27d2019-10-24 11:59:24 -0400590 % medium_file, shell=True).decode()
Jean-Jacques Hiblot8aea8a62019-02-13 12:15:27 +0100591 md5val.extend([out.split()[0]])
592
593 umount_fs(mount_dir)
594 except CalledProcessError:
595 pytest.skip('Setup failed for filesystem: ' + fs_type)
596 return
597 else:
598 yield [fs_ubtype, fs_img, md5val]
599 finally:
600 umount_fs(mount_dir)
601 call('rmdir %s' % mount_dir, shell=True)
602 if fs_img:
603 call('rm -f %s' % fs_img, shell=True)