GK SDK 源码库: XMIPCLinuxV100R005C00SPC030 (kernel/tools/open_source excluded)

This commit is contained in:
lai
2026-09-06 03:52:57 +08:00
commit b1928b41c0
21813 changed files with 4413081 additions and 0 deletions
@@ -0,0 +1,602 @@
# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2018, Linaro Limited
# Author: Takahiro Akashi <takahiro.akashi@linaro.org>
import os
import os.path
import pytest
import re
from subprocess import call, check_call, check_output, CalledProcessError
from fstest_defs import *
supported_fs_basic = ['fat16', 'fat32', 'ext4']
supported_fs_ext = ['fat16', 'fat32']
supported_fs_mkdir = ['fat16', 'fat32']
supported_fs_unlink = ['fat16', 'fat32']
supported_fs_symlink = ['ext4']
#
# Filesystem test specific setup
#
def pytest_addoption(parser):
"""Enable --fs-type option.
See pytest_configure() about how it works.
Args:
parser: Pytest command-line parser.
Returns:
Nothing.
"""
parser.addoption('--fs-type', action='append', default=None,
help='Targeting Filesystem Types')
def pytest_configure(config):
"""Restrict a file system(s) to be tested.
A file system explicitly named with --fs-type option is selected
if it belongs to a default supported_fs_xxx list.
Multiple options can be specified.
Args:
config: Pytest configuration.
Returns:
Nothing.
"""
global supported_fs_basic
global supported_fs_ext
global supported_fs_mkdir
global supported_fs_unlink
global supported_fs_symlink
def intersect(listA, listB):
return [x for x in listA if x in listB]
supported_fs = config.getoption('fs_type')
if supported_fs:
print('*** FS TYPE modified: %s' % supported_fs)
supported_fs_basic = intersect(supported_fs, supported_fs_basic)
supported_fs_ext = intersect(supported_fs, supported_fs_ext)
supported_fs_mkdir = intersect(supported_fs, supported_fs_mkdir)
supported_fs_unlink = intersect(supported_fs, supported_fs_unlink)
supported_fs_symlink = intersect(supported_fs, supported_fs_symlink)
def pytest_generate_tests(metafunc):
"""Parametrize fixtures, fs_obj_xxx
Each fixture will be parametrized with a corresponding support_fs_xxx
list.
Args:
metafunc: Pytest test function.
Returns:
Nothing.
"""
if 'fs_obj_basic' in metafunc.fixturenames:
metafunc.parametrize('fs_obj_basic', supported_fs_basic,
indirect=True, scope='module')
if 'fs_obj_ext' in metafunc.fixturenames:
metafunc.parametrize('fs_obj_ext', supported_fs_ext,
indirect=True, scope='module')
if 'fs_obj_mkdir' in metafunc.fixturenames:
metafunc.parametrize('fs_obj_mkdir', supported_fs_mkdir,
indirect=True, scope='module')
if 'fs_obj_unlink' in metafunc.fixturenames:
metafunc.parametrize('fs_obj_unlink', supported_fs_unlink,
indirect=True, scope='module')
if 'fs_obj_symlink' in metafunc.fixturenames:
metafunc.parametrize('fs_obj_symlink', supported_fs_symlink,
indirect=True, scope='module')
#
# Helper functions
#
def fstype_to_ubname(fs_type):
"""Convert a file system type to an U-boot specific string
A generated string can be used as part of file system related commands
or a config name in u-boot. Currently fat16 and fat32 are handled
specifically.
Args:
fs_type: File system type.
Return:
A corresponding string for file system type.
"""
if re.match('fat', fs_type):
return 'fat'
else:
return fs_type
def check_ubconfig(config, fs_type):
"""Check whether a file system is enabled in u-boot configuration.
This function is assumed to be called in a fixture function so that
the whole test cases will be skipped if a given file system is not
enabled.
Args:
fs_type: File system type.
Return:
Nothing.
"""
if not config.buildconfig.get('config_cmd_%s' % fs_type, None):
pytest.skip('.config feature "CMD_%s" not enabled' % fs_type.upper())
if not config.buildconfig.get('config_%s_write' % fs_type, None):
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'
elif fs_type == 'ext4':
mkfs_opt = '-O ^metadata_csum'
else:
mkfs_opt = ''
if re.match('fat', fs_type):
fs_lnxtype = 'vfat'
else:
fs_lnxtype = fs_type
count = (size + 1048576 - 1) / 1048576
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)
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.
Args:
tool: Command name.
Return:
True if available, False if not.
"""
for path in os.environ['PATH'].split(os.pathsep):
fn = os.path.join(path, tool)
if os.path.isfile(fn) and os.access(fn, os.X_OK):
return True
return False
fuse_mounted = False
def mount_fs(fs_type, device, mount_point):
"""Mount a volume.
Args:
fs_type: File system type.
device: Volume's file name.
mount_point: Mount point.
Return:
Nothing.
"""
global fuse_mounted
fuse_mounted = False
try:
if tool_is_in_path('guestmount'):
fuse_mounted = True
check_call('guestmount -a %s -m /dev/sda %s'
% (device, mount_point), shell=True)
else:
mount_opt = 'loop,rw'
if re.match('fat', fs_type):
mount_opt += ',umask=0000'
check_call('sudo mount -o %s %s %s'
% (mount_opt, device, mount_point), shell=True)
# may not be effective for some file systems
check_call('sudo chmod a+rw %s' % mount_point, shell=True)
except CalledProcessError:
raise
def umount_fs(mount_point):
"""Unmount a volume.
Args:
mount_point: Mount point.
Return:
Nothing.
"""
if fuse_mounted:
call('sync')
call('guestunmount %s' % mount_point, shell=True)
else:
call('sudo umount %s' % mount_point, shell=True)
#
# Fixture for basic fs test
# derived from test/fs/fs-test.sh
#
# NOTE: yield_fixture was deprecated since pytest-3.0
@pytest.yield_fixture()
def fs_obj_basic(request, u_boot_config):
"""Set up a file system to be used in basic fs test.
Args:
request: Pytest request object.
u_boot_config: U-boot configuration.
Return:
A fixture for basic fs test, i.e. a triplet of file system type,
volume file name and a list of MD5 hashes.
"""
fs_type = request.param
fs_img = ''
fs_ubtype = fstype_to_ubname(fs_type)
check_ubconfig(u_boot_config, fs_ubtype)
mount_dir = u_boot_config.persistent_data_dir + '/mnt'
small_file = mount_dir + '/' + SMALL_FILE
big_file = mount_dir + '/' + BIG_FILE
try:
# 3GiB volume
fs_img = mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB')
# Mount the image so we can populate it.
check_call('mkdir -p %s' % mount_dir, shell=True)
mount_fs(fs_type, fs_img, mount_dir)
# Create a subdirectory.
check_call('mkdir %s/SUBDIR' % mount_dir, shell=True)
# Create big file in this image.
# Note that we work only on the start 1MB, couple MBs in the 2GB range
# and the last 1 MB of the huge 2.5GB file.
# So, just put random values only in those areas.
check_call('dd if=/dev/urandom of=%s bs=1M count=1'
% big_file, shell=True)
check_call('dd if=/dev/urandom of=%s bs=1M count=2 seek=2047'
% big_file, shell=True)
check_call('dd if=/dev/urandom of=%s bs=1M count=1 seek=2499'
% big_file, shell=True)
# Create a small file in this image.
check_call('dd if=/dev/urandom of=%s bs=1M count=1'
% small_file, shell=True)
# Delete the small file copies which possibly are written as part of a
# previous test.
# check_call('rm -f "%s.w"' % MB1, shell=True)
# check_call('rm -f "%s.w2"' % MB1, shell=True)
# Generate the md5sums of reads that we will test against small file
out = check_output(
'dd if=%s bs=1M skip=0 count=1 2> /dev/null | md5sum'
% small_file, shell=True).decode()
md5val = [ out.split()[0] ]
# Generate the md5sums of reads that we will test against big file
# One from beginning of file.
out = check_output(
'dd if=%s bs=1M skip=0 count=1 2> /dev/null | md5sum'
% big_file, shell=True).decode()
md5val.append(out.split()[0])
# One from end of file.
out = check_output(
'dd if=%s bs=1M skip=2499 count=1 2> /dev/null | md5sum'
% big_file, shell=True).decode()
md5val.append(out.split()[0])
# One from the last 1MB chunk of 2GB
out = check_output(
'dd if=%s bs=1M skip=2047 count=1 2> /dev/null | md5sum'
% big_file, shell=True).decode()
md5val.append(out.split()[0])
# One from the start 1MB chunk from 2GB
out = check_output(
'dd if=%s bs=1M skip=2048 count=1 2> /dev/null | md5sum'
% big_file, shell=True).decode()
md5val.append(out.split()[0])
# One 1MB chunk crossing the 2GB boundary
out = check_output(
'dd if=%s bs=512K skip=4095 count=2 2> /dev/null | md5sum'
% big_file, shell=True).decode()
md5val.append(out.split()[0])
umount_fs(mount_dir)
except CalledProcessError:
pytest.skip('Setup failed for filesystem: ' + fs_type)
return
else:
yield [fs_ubtype, fs_img, md5val]
finally:
umount_fs(mount_dir)
call('rmdir %s' % mount_dir, shell=True)
if fs_img:
call('rm -f %s' % fs_img, shell=True)
#
# Fixture for extended fs test
#
# NOTE: yield_fixture was deprecated since pytest-3.0
@pytest.yield_fixture()
def fs_obj_ext(request, u_boot_config):
"""Set up a file system to be used in extended fs test.
Args:
request: Pytest request object.
u_boot_config: U-boot configuration.
Return:
A fixture for extended fs test, i.e. a triplet of file system type,
volume file name and a list of MD5 hashes.
"""
fs_type = request.param
fs_img = ''
fs_ubtype = fstype_to_ubname(fs_type)
check_ubconfig(u_boot_config, fs_ubtype)
mount_dir = u_boot_config.persistent_data_dir + '/mnt'
min_file = mount_dir + '/' + MIN_FILE
tmp_file = mount_dir + '/tmpfile'
try:
# 128MiB volume
fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
# Mount the image so we can populate it.
check_call('mkdir -p %s' % mount_dir, shell=True)
mount_fs(fs_type, fs_img, mount_dir)
# Create a test directory
check_call('mkdir %s/dir1' % mount_dir, shell=True)
# Create a small file and calculate md5
check_call('dd if=/dev/urandom of=%s bs=1K count=20'
% min_file, shell=True)
out = check_output(
'dd if=%s bs=1K 2> /dev/null | md5sum'
% min_file, shell=True).decode()
md5val = [ out.split()[0] ]
# Calculate md5sum of Test Case 4
check_call('dd if=%s of=%s bs=1K count=20'
% (min_file, tmp_file), shell=True)
check_call('dd if=%s of=%s bs=1K seek=5 count=20'
% (min_file, tmp_file), shell=True)
out = check_output('dd if=%s bs=1K 2> /dev/null | md5sum'
% tmp_file, shell=True).decode()
md5val.append(out.split()[0])
# Calculate md5sum of Test Case 5
check_call('dd if=%s of=%s bs=1K count=20'
% (min_file, tmp_file), shell=True)
check_call('dd if=%s of=%s bs=1K seek=5 count=5'
% (min_file, tmp_file), shell=True)
out = check_output('dd if=%s bs=1K 2> /dev/null | md5sum'
% tmp_file, shell=True).decode()
md5val.append(out.split()[0])
# Calculate md5sum of Test Case 7
check_call('dd if=%s of=%s bs=1K count=20'
% (min_file, tmp_file), shell=True)
check_call('dd if=%s of=%s bs=1K seek=20 count=20'
% (min_file, tmp_file), shell=True)
out = check_output('dd if=%s bs=1K 2> /dev/null | md5sum'
% tmp_file, shell=True).decode()
md5val.append(out.split()[0])
check_call('rm %s' % tmp_file, shell=True)
umount_fs(mount_dir)
except CalledProcessError:
pytest.skip('Setup failed for filesystem: ' + fs_type)
return
else:
yield [fs_ubtype, fs_img, md5val]
finally:
umount_fs(mount_dir)
call('rmdir %s' % mount_dir, shell=True)
if fs_img:
call('rm -f %s' % fs_img, shell=True)
#
# Fixture for mkdir test
#
# NOTE: yield_fixture was deprecated since pytest-3.0
@pytest.yield_fixture()
def fs_obj_mkdir(request, u_boot_config):
"""Set up a file system to be used in mkdir test.
Args:
request: Pytest request object.
u_boot_config: U-boot configuration.
Return:
A fixture for mkdir test, i.e. a duplet of file system type and
volume file name.
"""
fs_type = request.param
fs_img = ''
fs_ubtype = fstype_to_ubname(fs_type)
check_ubconfig(u_boot_config, fs_ubtype)
try:
# 128MiB volume
fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
except:
pytest.skip('Setup failed for filesystem: ' + fs_type)
else:
yield [fs_ubtype, fs_img]
finally:
if fs_img:
call('rm -f %s' % fs_img, shell=True)
#
# Fixture for unlink test
#
# NOTE: yield_fixture was deprecated since pytest-3.0
@pytest.yield_fixture()
def fs_obj_unlink(request, u_boot_config):
"""Set up a file system to be used in unlink test.
Args:
request: Pytest request object.
u_boot_config: U-boot configuration.
Return:
A fixture for unlink test, i.e. a duplet of file system type and
volume file name.
"""
fs_type = request.param
fs_img = ''
fs_ubtype = fstype_to_ubname(fs_type)
check_ubconfig(u_boot_config, fs_ubtype)
mount_dir = u_boot_config.persistent_data_dir + '/mnt'
try:
# 128MiB volume
fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
# Mount the image so we can populate it.
check_call('mkdir -p %s' % mount_dir, shell=True)
mount_fs(fs_type, fs_img, mount_dir)
# Test Case 1 & 3
check_call('mkdir %s/dir1' % mount_dir, shell=True)
check_call('dd if=/dev/urandom of=%s/dir1/file1 bs=1K count=1'
% mount_dir, shell=True)
check_call('dd if=/dev/urandom of=%s/dir1/file2 bs=1K count=1'
% mount_dir, shell=True)
# Test Case 2
check_call('mkdir %s/dir2' % mount_dir, shell=True)
for i in range(0, 20):
check_call('mkdir %s/dir2/0123456789abcdef%02x'
% (mount_dir, i), shell=True)
# Test Case 4
check_call('mkdir %s/dir4' % mount_dir, shell=True)
# Test Case 5, 6 & 7
check_call('mkdir %s/dir5' % mount_dir, shell=True)
check_call('dd if=/dev/urandom of=%s/dir5/file1 bs=1K count=1'
% mount_dir, shell=True)
umount_fs(mount_dir)
except CalledProcessError:
pytest.skip('Setup failed for filesystem: ' + fs_type)
return
else:
yield [fs_ubtype, fs_img]
finally:
umount_fs(mount_dir)
call('rmdir %s' % mount_dir, shell=True)
if fs_img:
call('rm -f %s' % fs_img, shell=True)
#
# Fixture for symlink fs test
#
# NOTE: yield_fixture was deprecated since pytest-3.0
@pytest.yield_fixture()
def fs_obj_symlink(request, u_boot_config):
"""Set up a file system to be used in symlink fs test.
Args:
request: Pytest request object.
u_boot_config: U-boot configuration.
Return:
A fixture for basic fs test, i.e. a triplet of file system type,
volume file name and a list of MD5 hashes.
"""
fs_type = request.param
fs_img = ''
fs_ubtype = fstype_to_ubname(fs_type)
check_ubconfig(u_boot_config, fs_ubtype)
mount_dir = u_boot_config.persistent_data_dir + '/mnt'
small_file = mount_dir + '/' + SMALL_FILE
medium_file = mount_dir + '/' + MEDIUM_FILE
try:
# 3GiB volume
fs_img = mk_fs(u_boot_config, fs_type, 0x40000000, '1GB')
# Mount the image so we can populate it.
check_call('mkdir -p %s' % mount_dir, shell=True)
mount_fs(fs_type, fs_img, mount_dir)
# Create a subdirectory.
check_call('mkdir %s/SUBDIR' % mount_dir, shell=True)
# Create a small file in this image.
check_call('dd if=/dev/urandom of=%s bs=1M count=1'
% small_file, shell=True)
# Create a medium file in this image.
check_call('dd if=/dev/urandom of=%s bs=10M count=1'
% medium_file, shell=True)
# Generate the md5sums of reads that we will test against small file
out = check_output(
'dd if=%s bs=1M skip=0 count=1 2> /dev/null | md5sum'
% small_file, shell=True).decode()
md5val = [out.split()[0]]
out = check_output(
'dd if=%s bs=10M skip=0 count=1 2> /dev/null | md5sum'
% medium_file, shell=True).decode()
md5val.extend([out.split()[0]])
umount_fs(mount_dir)
except CalledProcessError:
pytest.skip('Setup failed for filesystem: ' + fs_type)
return
else:
yield [fs_ubtype, fs_img, md5val]
finally:
umount_fs(mount_dir)
call('rmdir %s' % mount_dir, shell=True)
if fs_img:
call('rm -f %s' % fs_img, shell=True)
@@ -0,0 +1,16 @@
# SPDX-License-Identifier: GPL-2.0+
# $MIN_FILE is the name of the 20KB file in the file system image
MIN_FILE='testfile'
# $SMALL_FILE is the name of the 1MB file in the file system image
SMALL_FILE='1MB.file'
# $MEDIUM_FILE is the name of the 10MB file in the file system image
MEDIUM_FILE='10MB.file'
# $BIG_FILE is the name of the 2.5GB file in the file system image
BIG_FILE='2.5GB.file'
ADDR=0x01000008
LENGTH=0x00100000
@@ -0,0 +1,13 @@
# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2019, Texas Instrument
# Author: JJ Hiblot <jjhiblot@ti.com>
#
from subprocess import check_call, CalledProcessError
def assert_fs_integrity(fs_type, fs_img):
try:
if fs_type == 'ext4':
check_call('fsck.ext4 -n -f %s' % fs_img, shell=True)
except CalledProcessError:
raise
@@ -0,0 +1,292 @@
# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2018, Linaro Limited
# Author: Takahiro Akashi <takahiro.akashi@linaro.org>
#
# U-Boot File System:Basic Test
"""
This test verifies basic read/write operation on file system.
"""
import pytest
import re
from fstest_defs import *
from fstest_helpers import assert_fs_integrity
@pytest.mark.boardspec('sandbox')
@pytest.mark.slow
class TestFsBasic(object):
def test_fs1(self, u_boot_console, fs_obj_basic):
"""
Test Case 1 - ls command, listing a root directory and invalid directory
"""
fs_type,fs_img,md5val = fs_obj_basic
with u_boot_console.log.section('Test Case 1a - ls'):
# Test Case 1 - ls
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sls host 0:0' % fs_type])
assert(re.search('2621440000 *%s' % BIG_FILE, ''.join(output)))
assert(re.search('1048576 *%s' % SMALL_FILE, ''.join(output)))
with u_boot_console.log.section('Test Case 1b - ls (invalid dir)'):
# In addition, test with a nonexistent directory to see if we crash.
output = u_boot_console.run_command(
'%sls host 0:0 invalid_d' % fs_type)
if fs_type == 'ext4':
assert('Can not find directory' in output)
else:
assert('' == output)
def test_fs2(self, u_boot_console, fs_obj_basic):
"""
Test Case 2 - size command for a small file
"""
fs_type,fs_img,md5val = fs_obj_basic
with u_boot_console.log.section('Test Case 2a - size (small)'):
# 1MB is 0x0010 0000
# Test Case 2a - size of small file
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%ssize host 0:0 /%s' % (fs_type, SMALL_FILE),
'printenv filesize',
'setenv filesize'])
assert('filesize=100000' in ''.join(output))
with u_boot_console.log.section('Test Case 2b - size (/../<file>)'):
# Test Case 2b - size of small file via a path using '..'
output = u_boot_console.run_command_list([
'%ssize host 0:0 /SUBDIR/../%s' % (fs_type, SMALL_FILE),
'printenv filesize',
'setenv filesize'])
assert('filesize=100000' in ''.join(output))
def test_fs3(self, u_boot_console, fs_obj_basic):
"""
Test Case 3 - size command for a large file
"""
fs_type,fs_img,md5val = fs_obj_basic
with u_boot_console.log.section('Test Case 3 - size (large)'):
# 2.5GB (1024*1024*2500) is 0x9C40 0000
# Test Case 3 - size of big file
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%ssize host 0:0 /%s' % (fs_type, BIG_FILE),
'printenv filesize',
'setenv filesize'])
assert('filesize=9c400000' in ''.join(output))
def test_fs4(self, u_boot_console, fs_obj_basic):
"""
Test Case 4 - load a small file, 1MB
"""
fs_type,fs_img,md5val = fs_obj_basic
with u_boot_console.log.section('Test Case 4 - load (small)'):
# Test Case 4a - Read full 1MB of small file
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE),
'printenv filesize'])
assert('filesize=100000' in ''.join(output))
# Test Case 4b - Read full 1MB of small file
output = u_boot_console.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[0] in ''.join(output))
def test_fs5(self, u_boot_console, fs_obj_basic):
"""
Test Case 5 - load, reading first 1MB of 3GB file
"""
fs_type,fs_img,md5val = fs_obj_basic
with u_boot_console.log.section('Test Case 5 - load (first 1MB)'):
# Test Case 5a - First 1MB of big file
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s %x 0x0' % (fs_type, ADDR, BIG_FILE, LENGTH),
'printenv filesize'])
assert('filesize=100000' in ''.join(output))
# Test Case 5b - First 1MB of big file
output = u_boot_console.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[1] in ''.join(output))
def test_fs6(self, u_boot_console, fs_obj_basic):
"""
Test Case 6 - load, reading last 1MB of 3GB file
"""
fs_type,fs_img,md5val = fs_obj_basic
with u_boot_console.log.section('Test Case 6 - load (last 1MB)'):
# fails for ext as no offset support
# Test Case 6a - Last 1MB of big file
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s %x 0x9c300000'
% (fs_type, ADDR, BIG_FILE, LENGTH),
'printenv filesize'])
assert('filesize=100000' in ''.join(output))
# Test Case 6b - Last 1MB of big file
output = u_boot_console.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[2] in ''.join(output))
def test_fs7(self, u_boot_console, fs_obj_basic):
"""
Test Case 7 - load, 1MB from the last 1MB in 2GB
"""
fs_type,fs_img,md5val = fs_obj_basic
with u_boot_console.log.section('Test Case 7 - load (last 1MB in 2GB)'):
# fails for ext as no offset support
# Test Case 7a - One from the last 1MB chunk of 2GB
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s %x 0x7ff00000'
% (fs_type, ADDR, BIG_FILE, LENGTH),
'printenv filesize'])
assert('filesize=100000' in ''.join(output))
# Test Case 7b - One from the last 1MB chunk of 2GB
output = u_boot_console.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[3] in ''.join(output))
def test_fs8(self, u_boot_console, fs_obj_basic):
"""
Test Case 8 - load, reading first 1MB in 2GB
"""
fs_type,fs_img,md5val = fs_obj_basic
with u_boot_console.log.section('Test Case 8 - load (first 1MB in 2GB)'):
# fails for ext as no offset support
# Test Case 8a - One from the start 1MB chunk from 2GB
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s %x 0x80000000'
% (fs_type, ADDR, BIG_FILE, LENGTH),
'printenv filesize'])
assert('filesize=100000' in ''.join(output))
# Test Case 8b - One from the start 1MB chunk from 2GB
output = u_boot_console.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[4] in ''.join(output))
def test_fs9(self, u_boot_console, fs_obj_basic):
"""
Test Case 9 - load, 1MB crossing 2GB boundary
"""
fs_type,fs_img,md5val = fs_obj_basic
with u_boot_console.log.section('Test Case 9 - load (crossing 2GB boundary)'):
# fails for ext as no offset support
# Test Case 9a - One 1MB chunk crossing the 2GB boundary
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s %x 0x7ff80000'
% (fs_type, ADDR, BIG_FILE, LENGTH),
'printenv filesize'])
assert('filesize=100000' in ''.join(output))
# Test Case 9b - One 1MB chunk crossing the 2GB boundary
output = u_boot_console.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[5] in ''.join(output))
def test_fs10(self, u_boot_console, fs_obj_basic):
"""
Test Case 10 - load, reading beyond file end'):
"""
fs_type,fs_img,md5val = fs_obj_basic
with u_boot_console.log.section('Test Case 10 - load (beyond file end)'):
# Generic failure case
# Test Case 10 - 2MB chunk from the last 1MB of big file
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s 0x00200000 0x9c300000'
% (fs_type, ADDR, BIG_FILE),
'printenv filesize',
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert('filesize=100000' in ''.join(output))
def test_fs11(self, u_boot_console, fs_obj_basic):
"""
Test Case 11 - write'
"""
fs_type,fs_img,md5val = fs_obj_basic
with u_boot_console.log.section('Test Case 11 - write'):
# Read 1MB from small file
# Write it back to test the writes
# Test Case 11a - Check that the write succeeded
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE),
'%swrite host 0:0 %x /%s.w $filesize'
% (fs_type, ADDR, SMALL_FILE)])
assert('1048576 bytes written' in ''.join(output))
# Test Case 11b - Check md5 of written to is same
# as the one read from
output = u_boot_console.run_command_list([
'%sload host 0:0 %x /%s.w' % (fs_type, ADDR, SMALL_FILE),
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[0] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_fs12(self, u_boot_console, fs_obj_basic):
"""
Test Case 12 - write to "." directory
"""
fs_type,fs_img,md5val = fs_obj_basic
with u_boot_console.log.section('Test Case 12 - write (".")'):
# Next test case checks writing a file whose dirent
# is the first in the block, which is always true for "."
# The write should fail, but the lookup should work
# Test Case 12 - Check directory traversal
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%swrite host 0:0 %x /. 0x10' % (fs_type, ADDR)])
assert('Unable to write' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_fs13(self, u_boot_console, fs_obj_basic):
"""
Test Case 13 - write to a file with "/./<filename>"
"""
fs_type,fs_img,md5val = fs_obj_basic
with u_boot_console.log.section('Test Case 13 - write ("./<file>")'):
# Read 1MB from small file
# Write it via "same directory", i.e. "." dirent
# Test Case 13a - Check directory traversal
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE),
'%swrite host 0:0 %x /./%s2 $filesize'
% (fs_type, ADDR, SMALL_FILE)])
assert('1048576 bytes written' in ''.join(output))
# Test Case 13b - Check md5 of written to is same
# as the one read from
output = u_boot_console.run_command_list([
'mw.b %x 00 100' % ADDR,
'%sload host 0:0 %x /./%s2' % (fs_type, ADDR, SMALL_FILE),
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[0] in ''.join(output))
# Test Case 13c - Check md5 of written to is same
# as the one read from
output = u_boot_console.run_command_list([
'mw.b %x 00 100' % ADDR,
'%sload host 0:0 %x /%s2' % (fs_type, ADDR, SMALL_FILE),
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[0] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
@@ -0,0 +1,319 @@
# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2018, Linaro Limited
# Author: Takahiro Akashi <takahiro.akashi@linaro.org>
#
# U-Boot File System:Exntented Test
"""
This test verifies extended write operation on file system.
"""
import pytest
import re
from fstest_defs import *
from fstest_helpers import assert_fs_integrity
@pytest.mark.boardspec('sandbox')
@pytest.mark.slow
class TestFsExt(object):
def test_fs_ext1(self, u_boot_console, fs_obj_ext):
"""
Test Case 1 - write a file with absolute path
"""
fs_type,fs_img,md5val = fs_obj_ext
with u_boot_console.log.section('Test Case 1 - write with abs path'):
# Test Case 1a - Check if command successfully returned
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
'%swrite host 0:0 %x /dir1/%s.w1 $filesize'
% (fs_type, ADDR, MIN_FILE)])
assert('20480 bytes written' in ''.join(output))
# Test Case 1b - Check md5 of file content
output = u_boot_console.run_command_list([
'mw.b %x 00 100' % ADDR,
'%sload host 0:0 %x /dir1/%s.w1' % (fs_type, ADDR, MIN_FILE),
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[0] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_fs_ext2(self, u_boot_console, fs_obj_ext):
"""
Test Case 2 - write to a file with relative path
"""
fs_type,fs_img,md5val = fs_obj_ext
with u_boot_console.log.section('Test Case 2 - write with rel path'):
# Test Case 2a - Check if command successfully returned
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
'%swrite host 0:0 %x dir1/%s.w2 $filesize'
% (fs_type, ADDR, MIN_FILE)])
assert('20480 bytes written' in ''.join(output))
# Test Case 2b - Check md5 of file content
output = u_boot_console.run_command_list([
'mw.b %x 00 100' % ADDR,
'%sload host 0:0 %x dir1/%s.w2' % (fs_type, ADDR, MIN_FILE),
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[0] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_fs_ext3(self, u_boot_console, fs_obj_ext):
"""
Test Case 3 - write to a file with invalid path
"""
fs_type,fs_img,md5val = fs_obj_ext
with u_boot_console.log.section('Test Case 3 - write with invalid path'):
# Test Case 3 - Check if command expectedly failed
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
'%swrite host 0:0 %x /dir1/none/%s.w3 $filesize'
% (fs_type, ADDR, MIN_FILE)])
assert('Unable to write "/dir1/none/' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_fs_ext4(self, u_boot_console, fs_obj_ext):
"""
Test Case 4 - write at non-zero offset, enlarging file size
"""
fs_type,fs_img,md5val = fs_obj_ext
with u_boot_console.log.section('Test Case 4 - write at non-zero offset, enlarging file size'):
# Test Case 4a - Check if command successfully returned
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
'%swrite host 0:0 %x /dir1/%s.w4 $filesize'
% (fs_type, ADDR, MIN_FILE)])
output = u_boot_console.run_command(
'%swrite host 0:0 %x /dir1/%s.w4 $filesize 0x1400'
% (fs_type, ADDR, MIN_FILE))
assert('20480 bytes written' in output)
# Test Case 4b - Check size of written file
output = u_boot_console.run_command_list([
'%ssize host 0:0 /dir1/%s.w4' % (fs_type, MIN_FILE),
'printenv filesize',
'setenv filesize'])
assert('filesize=6400' in ''.join(output))
# Test Case 4c - Check md5 of file content
output = u_boot_console.run_command_list([
'mw.b %x 00 100' % ADDR,
'%sload host 0:0 %x /dir1/%s.w4' % (fs_type, ADDR, MIN_FILE),
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[1] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_fs_ext5(self, u_boot_console, fs_obj_ext):
"""
Test Case 5 - write at non-zero offset, shrinking file size
"""
fs_type,fs_img,md5val = fs_obj_ext
with u_boot_console.log.section('Test Case 5 - write at non-zero offset, shrinking file size'):
# Test Case 5a - Check if command successfully returned
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
'%swrite host 0:0 %x /dir1/%s.w5 $filesize'
% (fs_type, ADDR, MIN_FILE)])
output = u_boot_console.run_command(
'%swrite host 0:0 %x /dir1/%s.w5 0x1400 0x1400'
% (fs_type, ADDR, MIN_FILE))
assert('5120 bytes written' in output)
# Test Case 5b - Check size of written file
output = u_boot_console.run_command_list([
'%ssize host 0:0 /dir1/%s.w5' % (fs_type, MIN_FILE),
'printenv filesize',
'setenv filesize'])
assert('filesize=2800' in ''.join(output))
# Test Case 5c - Check md5 of file content
output = u_boot_console.run_command_list([
'mw.b %x 00 100' % ADDR,
'%sload host 0:0 %x /dir1/%s.w5' % (fs_type, ADDR, MIN_FILE),
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[2] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_fs_ext6(self, u_boot_console, fs_obj_ext):
"""
Test Case 6 - write nothing at the start, truncating to zero
"""
fs_type,fs_img,md5val = fs_obj_ext
with u_boot_console.log.section('Test Case 6 - write nothing at the start, truncating to zero'):
# Test Case 6a - Check if command successfully returned
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
'%swrite host 0:0 %x /dir1/%s.w6 $filesize'
% (fs_type, ADDR, MIN_FILE)])
output = u_boot_console.run_command(
'%swrite host 0:0 %x /dir1/%s.w6 0 0'
% (fs_type, ADDR, MIN_FILE))
assert('0 bytes written' in output)
# Test Case 6b - Check size of written file
output = u_boot_console.run_command_list([
'%ssize host 0:0 /dir1/%s.w6' % (fs_type, MIN_FILE),
'printenv filesize',
'setenv filesize'])
assert('filesize=0' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_fs_ext7(self, u_boot_console, fs_obj_ext):
"""
Test Case 7 - write at the end (append)
"""
fs_type,fs_img,md5val = fs_obj_ext
with u_boot_console.log.section('Test Case 7 - write at the end (append)'):
# Test Case 7a - Check if command successfully returned
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
'%swrite host 0:0 %x /dir1/%s.w7 $filesize'
% (fs_type, ADDR, MIN_FILE)])
output = u_boot_console.run_command(
'%swrite host 0:0 %x /dir1/%s.w7 $filesize $filesize'
% (fs_type, ADDR, MIN_FILE))
assert('20480 bytes written' in output)
# Test Case 7b - Check size of written file
output = u_boot_console.run_command_list([
'%ssize host 0:0 /dir1/%s.w7' % (fs_type, MIN_FILE),
'printenv filesize',
'setenv filesize'])
assert('filesize=a000' in ''.join(output))
# Test Case 7c - Check md5 of file content
output = u_boot_console.run_command_list([
'mw.b %x 00 100' % ADDR,
'%sload host 0:0 %x /dir1/%s.w7' % (fs_type, ADDR, MIN_FILE),
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[3] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_fs_ext8(self, u_boot_console, fs_obj_ext):
"""
Test Case 8 - write at offset beyond the end of file
"""
fs_type,fs_img,md5val = fs_obj_ext
with u_boot_console.log.section('Test Case 8 - write beyond the end'):
# Test Case 8a - Check if command expectedly failed
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
'%swrite host 0:0 %x /dir1/%s.w8 $filesize'
% (fs_type, ADDR, MIN_FILE)])
output = u_boot_console.run_command(
'%swrite host 0:0 %x /dir1/%s.w8 0x1400 %x'
% (fs_type, ADDR, MIN_FILE, 0x100000 + 0x1400))
assert('Unable to write "/dir1' in output)
assert_fs_integrity(fs_type, fs_img)
def test_fs_ext9(self, u_boot_console, fs_obj_ext):
"""
Test Case 9 - write to a non-existing file at non-zero offset
"""
fs_type,fs_img,md5val = fs_obj_ext
with u_boot_console.log.section('Test Case 9 - write to non-existing file with non-zero offset'):
# Test Case 9a - Check if command expectedly failed
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
'%swrite host 0:0 %x /dir1/%s.w9 0x1400 0x1400'
% (fs_type, ADDR, MIN_FILE)])
assert('Unable to write "/dir1' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_fs_ext10(self, u_boot_console, fs_obj_ext):
"""
'Test Case 10 - create/delete as many directories under root directory
as amount of directory entries goes beyond one cluster size)'
"""
fs_type,fs_img,md5val = fs_obj_ext
with u_boot_console.log.section('Test Case 10 - create/delete (many)'):
# Test Case 10a - Create many files
# Please note that the size of directory entry is 32 bytes.
# So one typical cluster may holds 64 (2048/32) entries.
output = u_boot_console.run_command(
'host bind 0 %s' % fs_img)
for i in range(0, 66):
output = u_boot_console.run_command(
'%swrite host 0:0 %x /FILE0123456789_%02x 100'
% (fs_type, ADDR, i))
output = u_boot_console.run_command('%sls host 0:0 /' % fs_type)
assert('FILE0123456789_00' in output)
assert('FILE0123456789_41' in output)
# Test Case 10b - Delete many files
for i in range(0, 66):
output = u_boot_console.run_command(
'%srm host 0:0 /FILE0123456789_%02x'
% (fs_type, i))
output = u_boot_console.run_command('%sls host 0:0 /' % fs_type)
assert(not 'FILE0123456789_00' in output)
assert(not 'FILE0123456789_41' in output)
# Test Case 10c - Create many files again
# Please note no.64 and 65 are intentionally re-created
for i in range(64, 128):
output = u_boot_console.run_command(
'%swrite host 0:0 %x /FILE0123456789_%02x 100'
% (fs_type, ADDR, i))
output = u_boot_console.run_command('%sls host 0:0 /' % fs_type)
assert('FILE0123456789_40' in output)
assert('FILE0123456789_79' in output)
assert_fs_integrity(fs_type, fs_img)
def test_fs_ext11(self, u_boot_console, fs_obj_ext):
"""
'Test Case 11 - create/delete as many directories under non-root
directory as amount of directory entries goes beyond one cluster size)'
"""
fs_type,fs_img,md5val = fs_obj_ext
with u_boot_console.log.section('Test Case 11 - create/delete (many)'):
# Test Case 11a - Create many files
# Please note that the size of directory entry is 32 bytes.
# So one typical cluster may holds 64 (2048/32) entries.
output = u_boot_console.run_command(
'host bind 0 %s' % fs_img)
for i in range(0, 66):
output = u_boot_console.run_command(
'%swrite host 0:0 %x /dir1/FILE0123456789_%02x 100'
% (fs_type, ADDR, i))
output = u_boot_console.run_command('%sls host 0:0 /dir1' % fs_type)
assert('FILE0123456789_00' in output)
assert('FILE0123456789_41' in output)
# Test Case 11b - Delete many files
for i in range(0, 66):
output = u_boot_console.run_command(
'%srm host 0:0 /dir1/FILE0123456789_%02x'
% (fs_type, i))
output = u_boot_console.run_command('%sls host 0:0 /dir1' % fs_type)
assert(not 'FILE0123456789_00' in output)
assert(not 'FILE0123456789_41' in output)
# Test Case 11c - Create many files again
# Please note no.64 and 65 are intentionally re-created
for i in range(64, 128):
output = u_boot_console.run_command(
'%swrite host 0:0 %x /dir1/FILE0123456789_%02x 100'
% (fs_type, ADDR, i))
output = u_boot_console.run_command('%sls host 0:0 /dir1' % fs_type)
assert('FILE0123456789_40' in output)
assert('FILE0123456789_79' in output)
assert_fs_integrity(fs_type, fs_img)
@@ -0,0 +1,121 @@
# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2018, Linaro Limited
# Author: Takahiro Akashi <takahiro.akashi@linaro.org>
#
# U-Boot File System:mkdir Test
"""
This test verifies mkdir operation on file system.
"""
import pytest
from fstest_helpers import assert_fs_integrity
@pytest.mark.boardspec('sandbox')
@pytest.mark.slow
class TestMkdir(object):
def test_mkdir1(self, u_boot_console, fs_obj_mkdir):
"""
Test Case 1 - create a directory under a root
"""
fs_type,fs_img = fs_obj_mkdir
with u_boot_console.log.section('Test Case 1 - mkdir'):
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%smkdir host 0:0 dir1' % fs_type,
'%sls host 0:0 /' % fs_type])
assert('dir1/' in ''.join(output))
output = u_boot_console.run_command(
'%sls host 0:0 dir1' % fs_type)
assert('./' in output)
assert('../' in output)
assert_fs_integrity(fs_type, fs_img)
def test_mkdir2(self, u_boot_console, fs_obj_mkdir):
"""
Test Case 2 - create a directory under a sub-directory
"""
fs_type,fs_img = fs_obj_mkdir
with u_boot_console.log.section('Test Case 2 - mkdir (sub-sub directory)'):
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%smkdir host 0:0 dir1/dir2' % fs_type,
'%sls host 0:0 dir1' % fs_type])
assert('dir2/' in ''.join(output))
output = u_boot_console.run_command(
'%sls host 0:0 dir1/dir2' % fs_type)
assert('./' in output)
assert('../' in output)
assert_fs_integrity(fs_type, fs_img)
def test_mkdir3(self, u_boot_console, fs_obj_mkdir):
"""
Test Case 3 - trying to create a directory with a non-existing
path should fail
"""
fs_type,fs_img = fs_obj_mkdir
with u_boot_console.log.section('Test Case 3 - mkdir (non-existing path)'):
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%smkdir host 0:0 none/dir3' % fs_type])
assert('Unable to create a directory' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_mkdir4(self, u_boot_console, fs_obj_mkdir):
"""
Test Case 4 - trying to create "." should fail
"""
fs_type,fs_img = fs_obj_mkdir
with u_boot_console.log.section('Test Case 4 - mkdir (".")'):
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%smkdir host 0:0 .' % fs_type])
assert('Unable to create a directory' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_mkdir5(self, u_boot_console, fs_obj_mkdir):
"""
Test Case 5 - trying to create ".." should fail
"""
fs_type,fs_img = fs_obj_mkdir
with u_boot_console.log.section('Test Case 5 - mkdir ("..")'):
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%smkdir host 0:0 ..' % fs_type])
assert('Unable to create a directory' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_mkdir6(self, u_boot_console, fs_obj_mkdir):
"""
'Test Case 6 - create as many directories as amount of directory
entries goes beyond a cluster size)'
"""
fs_type,fs_img = fs_obj_mkdir
with u_boot_console.log.section('Test Case 6 - mkdir (create many)'):
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%smkdir host 0:0 dir6' % fs_type,
'%sls host 0:0 /' % fs_type])
assert('dir6/' in ''.join(output))
for i in range(0, 20):
output = u_boot_console.run_command(
'%smkdir host 0:0 dir6/0123456789abcdef%02x'
% (fs_type, i))
output = u_boot_console.run_command('%sls host 0:0 dir6' % fs_type)
assert('0123456789abcdef00/' in output)
assert('0123456789abcdef13/' in output)
output = u_boot_console.run_command(
'%sls host 0:0 dir6/0123456789abcdef13/.' % fs_type)
assert('./' in output)
assert('../' in output)
output = u_boot_console.run_command(
'%sls host 0:0 dir6/0123456789abcdef13/..' % fs_type)
assert('0123456789abcdef00/' in output)
assert('0123456789abcdef13/' in output)
assert_fs_integrity(fs_type, fs_img)
@@ -0,0 +1,130 @@
# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2019, Texas Instrument
# Author: Jean-Jacques Hiblot <jjhiblot@ti.com>
#
# U-Boot File System:symlink Test
"""
This test verifies unlink operation (deleting a file or a directory)
on file system.
"""
import pytest
import re
from fstest_defs import *
from fstest_helpers import assert_fs_integrity
@pytest.mark.boardspec('sandbox')
@pytest.mark.slow
class TestSymlink(object):
def test_symlink1(self, u_boot_console, fs_obj_symlink):
"""
Test Case 1 - create a link. and follow it when reading
"""
fs_type, fs_img, md5val = fs_obj_symlink
with u_boot_console.log.section('Test Case 1 - create link and read'):
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'setenv filesize',
'ln host 0:0 %s /%s.link ' % (SMALL_FILE, SMALL_FILE),
])
assert('' in ''.join(output))
output = u_boot_console.run_command_list([
'%sload host 0:0 %x /%s.link' % (fs_type, ADDR, SMALL_FILE),
'printenv filesize'])
assert('filesize=100000' in ''.join(output))
# Test Case 4b - Read full 1MB of small file
output = u_boot_console.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[0] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_symlink2(self, u_boot_console, fs_obj_symlink):
"""
Test Case 2 - create chained links
"""
fs_type, fs_img, md5val = fs_obj_symlink
with u_boot_console.log.section('Test Case 2 - create chained links'):
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'setenv filesize',
'ln host 0:0 %s /%s.link1 ' % (SMALL_FILE, SMALL_FILE),
'ln host 0:0 /%s.link1 /SUBDIR/%s.link2' % (
SMALL_FILE, SMALL_FILE),
'ln host 0:0 SUBDIR/%s.link2 /%s.link3' % (
SMALL_FILE, SMALL_FILE),
])
assert('' in ''.join(output))
output = u_boot_console.run_command_list([
'%sload host 0:0 %x /%s.link3' % (fs_type, ADDR, SMALL_FILE),
'printenv filesize'])
assert('filesize=100000' in ''.join(output))
# Test Case 4b - Read full 1MB of small file
output = u_boot_console.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[0] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_symlink3(self, u_boot_console, fs_obj_symlink):
"""
Test Case 3 - replace file/link with link
"""
fs_type, fs_img, md5val = fs_obj_symlink
with u_boot_console.log.section('Test Case 1 - create link and read'):
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'setenv filesize',
'ln host 0:0 %s /%s ' % (MEDIUM_FILE, SMALL_FILE),
'ln host 0:0 %s /%s.link ' % (MEDIUM_FILE, MEDIUM_FILE),
])
assert('' in ''.join(output))
output = u_boot_console.run_command_list([
'%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE),
'printenv filesize'])
assert('filesize=a00000' in ''.join(output))
output = u_boot_console.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[1] in ''.join(output))
output = u_boot_console.run_command_list([
'ln host 0:0 %s.link /%s ' % (MEDIUM_FILE, SMALL_FILE),
'%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE),
'printenv filesize'])
assert('filesize=a00000' in ''.join(output))
output = u_boot_console.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[1] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_symlink4(self, u_boot_console, fs_obj_symlink):
"""
Test Case 4 - create a broken link
"""
fs_type, fs_img, md5val = fs_obj_symlink
with u_boot_console.log.section('Test Case 1 - create link and read'):
output = u_boot_console.run_command_list([
'setenv filesize',
'ln host 0:0 nowhere /link ',
])
assert('' in ''.join(output))
output = u_boot_console.run_command(
'%sload host 0:0 %x /link' %
(fs_type, ADDR))
with u_boot_console.disable_check('error_notification'):
output = u_boot_console.run_command('printenv filesize')
assert('"filesize" not defined' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
@@ -0,0 +1,118 @@
# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2018, Linaro Limited
# Author: Takahiro Akashi <takahiro.akashi@linaro.org>
#
# U-Boot File System:unlink Test
"""
This test verifies unlink operation (deleting a file or a directory)
on file system.
"""
import pytest
from fstest_helpers import assert_fs_integrity
@pytest.mark.boardspec('sandbox')
@pytest.mark.slow
class TestUnlink(object):
def test_unlink1(self, u_boot_console, fs_obj_unlink):
"""
Test Case 1 - delete a file
"""
fs_type,fs_img = fs_obj_unlink
with u_boot_console.log.section('Test Case 1 - unlink (file)'):
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%srm host 0:0 dir1/file1' % fs_type,
'%sls host 0:0 dir1/file1' % fs_type])
assert('' == ''.join(output))
output = u_boot_console.run_command(
'%sls host 0:0 dir1/' % fs_type)
assert(not 'file1' in output)
assert('file2' in output)
assert_fs_integrity(fs_type, fs_img)
def test_unlink2(self, u_boot_console, fs_obj_unlink):
"""
Test Case 2 - delete many files
"""
fs_type,fs_img = fs_obj_unlink
with u_boot_console.log.section('Test Case 2 - unlink (many)'):
output = u_boot_console.run_command('host bind 0 %s' % fs_img)
for i in range(0, 20):
output = u_boot_console.run_command_list([
'%srm host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i),
'%sls host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i)])
assert('' == ''.join(output))
output = u_boot_console.run_command(
'%sls host 0:0 dir2' % fs_type)
assert('0 file(s), 2 dir(s)' in output)
assert_fs_integrity(fs_type, fs_img)
def test_unlink3(self, u_boot_console, fs_obj_unlink):
"""
Test Case 3 - trying to delete a non-existing file should fail
"""
fs_type,fs_img = fs_obj_unlink
with u_boot_console.log.section('Test Case 3 - unlink (non-existing)'):
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%srm host 0:0 dir1/nofile' % fs_type])
assert('nofile: doesn\'t exist' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_unlink4(self, u_boot_console, fs_obj_unlink):
"""
Test Case 4 - delete an empty directory
"""
fs_type,fs_img = fs_obj_unlink
with u_boot_console.log.section('Test Case 4 - unlink (directory)'):
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%srm host 0:0 dir4' % fs_type])
assert('' == ''.join(output))
output = u_boot_console.run_command(
'%sls host 0:0 /' % fs_type)
assert(not 'dir4' in output)
assert_fs_integrity(fs_type, fs_img)
def test_unlink5(self, u_boot_console, fs_obj_unlink):
"""
Test Case 5 - trying to deleting a non-empty directory ".."
should fail
"""
fs_type,fs_img = fs_obj_unlink
with u_boot_console.log.section('Test Case 5 - unlink ("non-empty directory")'):
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%srm host 0:0 dir5' % fs_type])
assert('directory is not empty' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_unlink6(self, u_boot_console, fs_obj_unlink):
"""
Test Case 6 - trying to deleting a "." should fail
"""
fs_type,fs_img = fs_obj_unlink
with u_boot_console.log.section('Test Case 6 - unlink (".")'):
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%srm host 0:0 dir5/.' % fs_type])
assert('directory is not empty' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_unlink7(self, u_boot_console, fs_obj_unlink):
"""
Test Case 7 - trying to deleting a ".." should fail
"""
fs_type,fs_img = fs_obj_unlink
with u_boot_console.log.section('Test Case 7 - unlink ("..")'):
output = u_boot_console.run_command_list([
'host bind 0 %s' % fs_img,
'%srm host 0:0 dir5/..' % fs_type])
assert('directory is not empty' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)