aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-10-29 19:47:05 -0600
committerSimon Glass <sjg@chromium.org>2022-11-07 16:24:30 -0700
commit4349ba5977cdc00ff0398353c33ba04fcd9dd762 (patch)
treed4278ba732db1d58a10f6dda73a3ba65186c3858 /test
parent6ca4d5b96b54bdd6086c084631500e918b37ceb7 (diff)
downloadu-boot-4349ba5977cdc00ff0398353c33ba04fcd9dd762.zip
u-boot-4349ba5977cdc00ff0398353c33ba04fcd9dd762.tar.gz
u-boot-4349ba5977cdc00ff0398353c33ba04fcd9dd762.tar.bz2
test: Split out mk_fs function into a helper
This function is useful for other tests. Move it into common code. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/py/tests/fs_helper.py54
-rw-r--r--test/py/tests/test_fs/conftest.py58
2 files changed, 60 insertions, 52 deletions
diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py
new file mode 100644
index 0000000..2d8f1f6
--- /dev/null
+++ b/test/py/tests/fs_helper.py
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Helper functions for dealing with filesystems
+#
+# Copyright (c) 2018, Linaro Limited
+# Author: Takahiro Akashi <takahiro.akashi@linaro.org>
+
+import re
+import os
+from subprocess import call, check_call, check_output, CalledProcessError
+
+def mk_fs(config, fs_type, size, prefix):
+ """Create a file system volume
+
+ Args:
+ fs_type (str): File system type, e.g. 'ext4'
+ size (int): Size of file system in bytes
+ prefix (str): Prefix string of volume's file name
+ """
+ fs_img = '%s.%s.img' % (prefix, fs_type)
+ fs_img = config.persistent_data_dir + '/' + fs_img
+
+ if fs_type == 'fat16':
+ mkfs_opt = '-F 16'
+ elif fs_type == 'fat32':
+ mkfs_opt = '-F 32'
+ else:
+ mkfs_opt = ''
+
+ if re.match('fat', fs_type):
+ fs_lnxtype = 'vfat'
+ else:
+ fs_lnxtype = fs_type
+
+ count = (size + 1048576 - 1) / 1048576
+
+ # Some distributions do not add /sbin to the default PATH, where mkfs lives
+ if '/sbin' not in os.environ["PATH"].split(os.pathsep):
+ os.environ["PATH"] += os.pathsep + '/sbin'
+
+ try:
+ check_call('rm -f %s' % fs_img, shell=True)
+ check_call('dd if=/dev/zero of=%s bs=1M count=%d'
+ % (fs_img, count), shell=True)
+ check_call('mkfs.%s %s %s'
+ % (fs_lnxtype, mkfs_opt, fs_img), shell=True)
+ if fs_type == 'ext4':
+ sb_content = check_output('tune2fs -l %s' % fs_img, shell=True).decode()
+ if 'metadata_csum' in sb_content:
+ check_call('tune2fs -O ^metadata_csum %s' % fs_img, shell=True)
+ return fs_img
+ except CalledProcessError:
+ call('rm -f %s' % fs_img, shell=True)
+ raise
diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py
index b638284..9329ec6 100644
--- a/test/py/tests/test_fs/conftest.py
+++ b/test/py/tests/test_fs/conftest.py
@@ -9,6 +9,7 @@ import re
from subprocess import call, check_call, check_output, CalledProcessError
from fstest_defs import *
import u_boot_utils as util
+from tests import fs_helper
supported_fs_basic = ['fat16', 'fat32', 'ext4']
supported_fs_ext = ['fat16', 'fat32']
@@ -132,53 +133,6 @@ def check_ubconfig(config, fs_type):
pytest.skip('.config feature "%s_WRITE" not enabled'
% fs_type.upper())
-def mk_fs(config, fs_type, size, id):
- """Create a file system volume.
-
- Args:
- fs_type: File system type.
- size: Size of file system in MiB.
- id: Prefix string of volume's file name.
-
- Return:
- Nothing.
- """
- fs_img = '%s.%s.img' % (id, fs_type)
- fs_img = config.persistent_data_dir + '/' + fs_img
-
- if fs_type == 'fat16':
- mkfs_opt = '-F 16'
- elif fs_type == 'fat32':
- mkfs_opt = '-F 32'
- else:
- mkfs_opt = ''
-
- if re.match('fat', fs_type):
- fs_lnxtype = 'vfat'
- else:
- fs_lnxtype = fs_type
-
- count = (size + 1048576 - 1) / 1048576
-
- # Some distributions do not add /sbin to the default PATH, where mkfs lives
- if '/sbin' not in os.environ["PATH"].split(os.pathsep):
- os.environ["PATH"] += os.pathsep + '/sbin'
-
- try:
- check_call('rm -f %s' % fs_img, shell=True)
- check_call('dd if=/dev/zero of=%s bs=1M count=%d'
- % (fs_img, count), shell=True)
- check_call('mkfs.%s %s %s'
- % (fs_lnxtype, mkfs_opt, fs_img), shell=True)
- if fs_type == 'ext4':
- sb_content = check_output('tune2fs -l %s' % fs_img, shell=True).decode()
- if 'metadata_csum' in sb_content:
- check_call('tune2fs -O ^metadata_csum %s' % fs_img, shell=True)
- return fs_img
- except CalledProcessError:
- call('rm -f %s' % fs_img, shell=True)
- raise
-
# from test/py/conftest.py
def tool_is_in_path(tool):
"""Check whether a given command is available on host.
@@ -283,7 +237,7 @@ def fs_obj_basic(request, u_boot_config):
try:
# 3GiB volume
- fs_img = mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB')
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB')
except CalledProcessError as err:
pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
return
@@ -405,7 +359,7 @@ def fs_obj_ext(request, u_boot_config):
try:
# 128MiB volume
- fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
except CalledProcessError as err:
pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
return
@@ -500,7 +454,7 @@ def fs_obj_mkdir(request, u_boot_config):
try:
# 128MiB volume
- fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
except:
pytest.skip('Setup failed for filesystem: ' + fs_type)
return
@@ -534,7 +488,7 @@ def fs_obj_unlink(request, u_boot_config):
try:
# 128MiB volume
- fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
except CalledProcessError as err:
pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
return
@@ -617,7 +571,7 @@ def fs_obj_symlink(request, u_boot_config):
try:
# 1GiB volume
- fs_img = mk_fs(u_boot_config, fs_type, 0x40000000, '1GB')
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x40000000, '1GB')
except CalledProcessError as err:
pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
return