diff options
Diffstat (limited to 'test/py/tests/test_fs')
-rw-r--r-- | test/py/tests/test_fs/conftest.py | 166 | ||||
-rw-r--r-- | test/py/tests/test_fs/fstest_helpers.py | 4 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_basic.py | 175 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_erofs.py | 76 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_ext.py | 288 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_fs_cmd.py | 4 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_fs_fat.py | 6 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_mkdir.py | 88 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_rename.py | 372 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_squashfs/test_sqfs_load.py | 54 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py | 64 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_symlink.py | 46 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_unlink.py | 88 |
13 files changed, 981 insertions, 450 deletions
diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py index af2adaf1645..c73fb4abbcb 100644 --- a/test/py/tests/test_fs/conftest.py +++ b/test/py/tests/test_fs/conftest.py @@ -8,16 +8,16 @@ import pytest import re from subprocess import call, check_call, check_output, CalledProcessError from fstest_defs import * -import u_boot_utils as util # pylint: disable=E0611 from tests import fs_helper -supported_fs_basic = ['fat16', 'fat32', 'ext4'] -supported_fs_ext = ['fat12', 'fat16', 'fat32'] +supported_fs_basic = ['fat16', 'fat32', 'exfat', 'ext4', 'fs_generic'] +supported_fs_ext = ['fat12', 'fat16', 'fat32', 'exfat', 'fs_generic'] supported_fs_fat = ['fat12', 'fat16'] -supported_fs_mkdir = ['fat12', 'fat16', 'fat32'] -supported_fs_unlink = ['fat12', 'fat16', 'fat32'] +supported_fs_mkdir = ['fat12', 'fat16', 'fat32', 'exfat', 'fs_generic'] +supported_fs_unlink = ['fat12', 'fat16', 'fat32', 'exfat', 'fs_generic'] supported_fs_symlink = ['ext4'] +supported_fs_rename = ['fat12', 'fat16', 'fat32'] # # Filesystem test specific setup @@ -55,6 +55,7 @@ def pytest_configure(config): global supported_fs_mkdir global supported_fs_unlink global supported_fs_symlink + global supported_fs_rename def intersect(listA, listB): return [x for x in listA if x in listB] @@ -68,6 +69,7 @@ def pytest_configure(config): 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) + supported_fs_rename = intersect(supported_fs, supported_fs_rename) def pytest_generate_tests(metafunc): """Parametrize fixtures, fs_obj_xxx @@ -99,10 +101,29 @@ def pytest_generate_tests(metafunc): if 'fs_obj_symlink' in metafunc.fixturenames: metafunc.parametrize('fs_obj_symlink', supported_fs_symlink, indirect=True, scope='module') + if 'fs_obj_rename' in metafunc.fixturenames: + metafunc.parametrize('fs_obj_rename', supported_fs_rename, + indirect=True, scope='module') # # Helper functions # +def fstype_to_prefix(fs_type): + """Convert a file system type to an U-Boot command prefix + + Args: + fs_type: File system type. + + Return: + A corresponding command prefix for file system type. + """ + if fs_type == 'fs_generic' or fs_type == 'exfat': + return '' + elif re.match('fat', fs_type): + return 'fat' + else: + return fs_type + def fstype_to_ubname(fs_type): """Convert a file system type to an U-Boot specific string @@ -134,8 +155,12 @@ def check_ubconfig(config, fs_type): Return: Nothing. """ - if not config.buildconfig.get('config_cmd_%s' % fs_type, None): + if fs_type == 'exfat' and not config.buildconfig.get('config_fs_%s' % fs_type, None): + pytest.skip('.config feature "FS_%s" not enabled' % fs_type.upper()) + if fs_type != 'exfat' and not config.buildconfig.get('config_cmd_%s' % fs_type, None): pytest.skip('.config feature "CMD_%s" not enabled' % fs_type.upper()) + if fs_type == 'fs_generic' or fs_type == 'exfat': + return if not config.buildconfig.get('config_%s_write' % fs_type, None): pytest.skip('.config feature "%s_WRITE" not enabled' % fs_type.upper()) @@ -173,6 +198,8 @@ def fs_obj_basic(request, u_boot_config): volume file name and a list of MD5 hashes. """ fs_type = request.param + fs_cmd_prefix = fstype_to_prefix(fs_type) + fs_cmd_write = 'save' if fs_type == 'fs_generic' or fs_type == 'exfat' else 'write' fs_img = '' fs_ubtype = fstype_to_ubname(fs_type) @@ -262,7 +289,7 @@ def fs_obj_basic(request, u_boot_config): pytest.skip('Setup failed for filesystem: ' + fs_type + '. {}'.format(err)) return else: - yield [fs_ubtype, fs_img, md5val] + yield [fs_ubtype, fs_cmd_prefix, fs_cmd_write, fs_img, md5val] finally: call('rm -rf %s' % scratch_dir, shell=True) call('rm -f %s' % fs_img, shell=True) @@ -283,6 +310,8 @@ def fs_obj_ext(request, u_boot_config): volume file name and a list of MD5 hashes. """ fs_type = request.param + fs_cmd_prefix = fstype_to_prefix(fs_type) + fs_cmd_write = 'save' if fs_type == 'fs_generic' or fs_type == 'exfat' else 'write' fs_img = '' fs_ubtype = fstype_to_ubname(fs_type) @@ -352,7 +381,7 @@ def fs_obj_ext(request, u_boot_config): pytest.skip('Setup failed for filesystem: ' + fs_type) return else: - yield [fs_ubtype, fs_img, md5val] + yield [fs_ubtype, fs_cmd_prefix, fs_cmd_write, fs_img, md5val] finally: call('rm -rf %s' % scratch_dir, shell=True) call('rm -f %s' % fs_img, shell=True) @@ -373,6 +402,7 @@ def fs_obj_mkdir(request, u_boot_config): volume file name. """ fs_type = request.param + fs_cmd_prefix = fstype_to_prefix(fs_type) fs_img = '' fs_ubtype = fstype_to_ubname(fs_type) @@ -385,7 +415,7 @@ def fs_obj_mkdir(request, u_boot_config): pytest.skip('Setup failed for filesystem: ' + fs_type) return else: - yield [fs_ubtype, fs_img] + yield [fs_ubtype, fs_cmd_prefix, fs_img] call('rm -f %s' % fs_img, shell=True) # @@ -404,6 +434,7 @@ def fs_obj_unlink(request, u_boot_config): volume file name. """ fs_type = request.param + fs_cmd_prefix = fstype_to_prefix(fs_type) fs_img = '' fs_ubtype = fstype_to_ubname(fs_type) @@ -451,7 +482,7 @@ def fs_obj_unlink(request, u_boot_config): pytest.skip('Setup failed for filesystem: ' + fs_type) return else: - yield [fs_ubtype, fs_img] + yield [fs_ubtype, fs_cmd_prefix, fs_img] finally: call('rm -rf %s' % scratch_dir, shell=True) call('rm -f %s' % fs_img, shell=True) @@ -528,6 +559,121 @@ def fs_obj_symlink(request, u_boot_config): call('rm -f %s' % fs_img, shell=True) # +# Fixture for rename test +# +@pytest.fixture() +def fs_obj_rename(request, u_boot_config): + """Set up a file system to be used in rename tests. + + Args: + request: Pytest request object. + u_boot_config: U-Boot configuration. + + Return: + A fixture for rename tests, i.e. a triplet of file system type, + volume file name, and dictionary of test identifier and md5val. + """ + def new_rand_file(path): + check_call('dd if=/dev/urandom of=%s bs=1K count=1' % path, shell=True) + + def file_hash(path): + out = check_output( + 'dd if=%s bs=1K skip=0 count=1 2> /dev/null | md5sum' % path, + shell=True + ) + return out.decode().split()[0] + + 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 + '/scratch' + + try: + check_call('mkdir -p %s' % mount_dir, shell=True) + except CalledProcessError as err: + pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) + call('rm -f %s' % fs_img, shell=True) + return + + try: + md5val = {} + # Test Case 1 + check_call('mkdir %s/test1' % mount_dir, shell=True) + new_rand_file('%s/test1/file1' % mount_dir) + md5val['test1'] = file_hash('%s/test1/file1' % mount_dir) + + # Test Case 2 + check_call('mkdir %s/test2' % mount_dir, shell=True) + new_rand_file('%s/test2/file1' % mount_dir) + new_rand_file('%s/test2/file_exist' % mount_dir) + md5val['test2'] = file_hash('%s/test2/file1' % mount_dir) + + # Test Case 3 + check_call('mkdir -p %s/test3/dir1' % mount_dir, shell=True) + new_rand_file('%s/test3/dir1/file1' % mount_dir) + md5val['test3'] = file_hash('%s/test3/dir1/file1' % mount_dir) + + # Test Case 4 + check_call('mkdir -p %s/test4/dir1' % mount_dir, shell=True) + check_call('mkdir -p %s/test4/dir2/dir1' % mount_dir, shell=True) + new_rand_file('%s/test4/dir1/file1' % mount_dir) + md5val['test4'] = file_hash('%s/test4/dir1/file1' % mount_dir) + + # Test Case 5 + check_call('mkdir -p %s/test5/dir1' % mount_dir, shell=True) + new_rand_file('%s/test5/file2' % mount_dir) + md5val['test5'] = file_hash('%s/test5/file2' % mount_dir) + + # Test Case 6 + check_call('mkdir -p %s/test6/dir2/existing' % mount_dir, shell=True) + new_rand_file('%s/test6/existing' % mount_dir) + md5val['test6'] = file_hash('%s/test6/existing' % mount_dir) + + # Test Case 7 + check_call('mkdir -p %s/test7/dir1' % mount_dir, shell=True) + check_call('mkdir -p %s/test7/dir2/dir1' % mount_dir, shell=True) + new_rand_file('%s/test7/dir2/dir1/file1' % mount_dir) + md5val['test7'] = file_hash('%s/test7/dir2/dir1/file1' % mount_dir) + + # Test Case 8 + check_call('mkdir -p %s/test8/dir1' % mount_dir, shell=True) + new_rand_file('%s/test8/dir1/file1' % mount_dir) + md5val['test8'] = file_hash('%s/test8/dir1/file1' % mount_dir) + + # Test Case 9 + check_call('mkdir -p %s/test9/dir1/nested/inner' % mount_dir, shell=True) + new_rand_file('%s/test9/dir1/nested/inner/file1' % mount_dir) + + # Test Case 10 + check_call('mkdir -p %s/test10' % mount_dir, shell=True) + new_rand_file('%s/test10/file1' % mount_dir) + md5val['test10'] = file_hash('%s/test10/file1' % mount_dir) + + # Test Case 11 + check_call('mkdir -p %s/test11/dir1' % mount_dir, shell=True) + new_rand_file('%s/test11/dir1/file1' % mount_dir) + md5val['test11'] = file_hash('%s/test11/dir1/file1' % mount_dir) + + try: + # 128MiB volume + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', mount_dir) + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + + except CalledProcessError: + pytest.skip('Setup failed for filesystem: ' + fs_type) + return + else: + yield [fs_ubtype, fs_img, md5val] + finally: + call('rm -rf %s' % mount_dir, shell=True) + call('rm -f %s' % fs_img, shell=True) + +# # Fixture for fat test # @pytest.fixture() diff --git a/test/py/tests/test_fs/fstest_helpers.py b/test/py/tests/test_fs/fstest_helpers.py index faec2982489..d25326ee993 100644 --- a/test/py/tests/test_fs/fstest_helpers.py +++ b/test/py/tests/test_fs/fstest_helpers.py @@ -9,5 +9,9 @@ def assert_fs_integrity(fs_type, fs_img): try: if fs_type == 'ext4': check_call('fsck.ext4 -n -f %s' % fs_img, shell=True) + elif fs_type == 'exfat': + check_call('fsck.exfat -n %s' % fs_img, shell=True) + elif fs_type in ['fat12', 'fat16', 'fat32']: + check_call('fsck.fat -n %s' % fs_img, shell=True) except CalledProcessError: raise diff --git a/test/py/tests/test_fs/test_basic.py b/test/py/tests/test_fs/test_basic.py index b5f4704172a..64a3b50f52a 100644 --- a/test/py/tests/test_fs/test_basic.py +++ b/test/py/tests/test_fs/test_basic.py @@ -16,273 +16,274 @@ 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): + def test_fs1(self, ubman, 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'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic + with ubman.log.section('Test Case 1a - ls'): # Test Case 1 - ls - output = u_boot_console.run_command_list([ + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sls host 0:0' % fs_type]) + '%sls host 0:0' % fs_cmd_prefix]) 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)'): + with ubman.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) + output = ubman.run_command( + '%sls host 0:0 invalid_d' % fs_cmd_prefix) assert('' == output) - def test_fs2(self, u_boot_console, fs_obj_basic): + def test_fs2(self, ubman, 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)'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic + with ubman.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([ + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%ssize host 0:0 /%s' % (fs_type, SMALL_FILE), + '%ssize host 0:0 /%s' % (fs_cmd_prefix, SMALL_FILE), 'printenv filesize', 'setenv filesize']) assert('filesize=100000' in ''.join(output)) - with u_boot_console.log.section('Test Case 2b - size (/../<file>)'): + with ubman.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), + output = ubman.run_command_list([ + '%ssize host 0:0 /SUBDIR/../%s' % (fs_cmd_prefix, SMALL_FILE), 'printenv filesize', 'setenv filesize']) assert('filesize=100000' in ''.join(output)) - def test_fs3(self, u_boot_console, fs_obj_basic): + def test_fs3(self, ubman, 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)'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic + with ubman.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([ + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%ssize host 0:0 /%s' % (fs_type, BIG_FILE), + '%ssize host 0:0 /%s' % (fs_cmd_prefix, BIG_FILE), 'printenv filesize', 'setenv filesize']) assert('filesize=9c400000' in ''.join(output)) - def test_fs4(self, u_boot_console, fs_obj_basic): + def test_fs4(self, ubman, 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)'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic + with ubman.log.section('Test Case 4 - load (small)'): # Test Case 4a - Read full 1MB of small file - output = u_boot_console.run_command_list([ + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE), + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, 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([ + output = ubman.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): + def test_fs5(self, ubman, 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)'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic + with ubman.log.section('Test Case 5 - load (first 1MB)'): # Test Case 5a - First 1MB of big file - output = u_boot_console.run_command_list([ + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sload host 0:0 %x /%s %x 0x0' % (fs_type, ADDR, BIG_FILE, LENGTH), + '%sload host 0:0 %x /%s %x 0x0' % (fs_cmd_prefix, 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([ + output = ubman.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): + def test_fs6(self, ubman, 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)'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic + with ubman.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([ + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, '%sload host 0:0 %x /%s %x 0x9c300000' - % (fs_type, ADDR, BIG_FILE, LENGTH), + % (fs_cmd_prefix, 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([ + output = ubman.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): + def test_fs7(self, ubman, 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)'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic + with ubman.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([ + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, '%sload host 0:0 %x /%s %x 0x7ff00000' - % (fs_type, ADDR, BIG_FILE, LENGTH), + % (fs_cmd_prefix, 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([ + output = ubman.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): + def test_fs8(self, ubman, 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)'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic + with ubman.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([ + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, '%sload host 0:0 %x /%s %x 0x80000000' - % (fs_type, ADDR, BIG_FILE, LENGTH), + % (fs_cmd_prefix, 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([ + output = ubman.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): + def test_fs9(self, ubman, 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)'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic + with ubman.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([ + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, '%sload host 0:0 %x /%s %x 0x7ff80000' - % (fs_type, ADDR, BIG_FILE, LENGTH), + % (fs_cmd_prefix, 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([ + output = ubman.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): + def test_fs10(self, ubman, 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)'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic + with ubman.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([ + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, '%sload host 0:0 %x /%s 0x00200000 0x9c300000' - % (fs_type, ADDR, BIG_FILE), + % (fs_cmd_prefix, 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): + def test_fs11(self, ubman, 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'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic + with ubman.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([ + output = ubman.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)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, SMALL_FILE), + '%s%s host 0:0 %x /%s.w $filesize' + % (fs_cmd_prefix, fs_cmd_write, 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), + output = ubman.run_command_list([ + '%sload host 0:0 %x /%s.w' % (fs_cmd_prefix, 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): + def test_fs12(self, ubman, 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 (".")'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic + with ubman.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([ + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%swrite host 0:0 %x /. 0x10' % (fs_type, ADDR)]) + '%s%s host 0:0 %x /. 0x10' + % (fs_cmd_prefix, fs_cmd_write, 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): + def test_fs13(self, ubman, 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>")'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic + with ubman.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([ + output = ubman.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)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, SMALL_FILE), + '%s%s host 0:0 %x /./%s2 $filesize' + % (fs_cmd_prefix, fs_cmd_write, 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([ + output = ubman.run_command_list([ 'mw.b %x 00 100' % ADDR, - '%sload host 0:0 %x /./%s2' % (fs_type, ADDR, SMALL_FILE), + '%sload host 0:0 %x /./%s2' % (fs_cmd_prefix, 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([ + output = ubman.run_command_list([ 'mw.b %x 00 100' % ADDR, - '%sload host 0:0 %x /%s2' % (fs_type, ADDR, SMALL_FILE), + '%sload host 0:0 %x /%s2' % (fs_cmd_prefix, ADDR, SMALL_FILE), 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[0] in ''.join(output)) diff --git a/test/py/tests/test_fs/test_erofs.py b/test/py/tests/test_fs/test_erofs.py index 87ad8f2d5fd..a2bb6b505f2 100644 --- a/test/py/tests/test_fs/test_erofs.py +++ b/test/py/tests/test_fs/test_erofs.py @@ -65,64 +65,64 @@ def clean_erofs_image(build_dir): image_path = os.path.join(build_dir, EROFS_IMAGE_NAME) os.remove(image_path) -def erofs_ls_at_root(u_boot_console): +def erofs_ls_at_root(ubman): """ Test if all the present files and directories were listed. """ - no_slash = u_boot_console.run_command('erofsls host 0') - slash = u_boot_console.run_command('erofsls host 0 /') + no_slash = ubman.run_command('erofsls host 0') + slash = ubman.run_command('erofsls host 0 /') assert no_slash == slash expected_lines = ['./', '../', '4096 f4096', '7812 f7812', 'subdir/', '<SYM> symdir', '<SYM> symfile', '4 file(s), 3 dir(s)'] - output = u_boot_console.run_command('erofsls host 0') + output = ubman.run_command('erofsls host 0') for line in expected_lines: assert line in output -def erofs_ls_at_subdir(u_boot_console): +def erofs_ls_at_subdir(ubman): """ Test if the path resolution works. """ expected_lines = ['./', '../', '100 subdir-file', '1 file(s), 2 dir(s)'] - output = u_boot_console.run_command('erofsls host 0 subdir') + output = ubman.run_command('erofsls host 0 subdir') for line in expected_lines: assert line in output -def erofs_ls_at_symlink(u_boot_console): +def erofs_ls_at_symlink(ubman): """ Test if the symbolic link's target resolution works. """ - output = u_boot_console.run_command('erofsls host 0 symdir') - output_subdir = u_boot_console.run_command('erofsls host 0 subdir') + output = ubman.run_command('erofsls host 0 symdir') + output_subdir = ubman.run_command('erofsls host 0 subdir') assert output == output_subdir expected_lines = ['./', '../', '100 subdir-file', '1 file(s), 2 dir(s)'] for line in expected_lines: assert line in output -def erofs_ls_at_non_existent_dir(u_boot_console): +def erofs_ls_at_non_existent_dir(ubman): """ Test if the EROFS support will crash when get a nonexistent directory. """ - out_non_existent = u_boot_console.run_command('erofsls host 0 fff') - out_not_dir = u_boot_console.run_command('erofsls host 0 f1000') + out_non_existent = ubman.run_command('erofsls host 0 fff') + out_not_dir = ubman.run_command('erofsls host 0 f1000') assert out_non_existent == out_not_dir assert '' in out_non_existent -def erofs_load_files(u_boot_console, files, sizes, address): +def erofs_load_files(ubman, files, sizes, address): """ Loads files and asserts their checksums. """ - build_dir = u_boot_console.config.build_dir + build_dir = ubman.config.build_dir for (file, size) in zip(files, sizes): - out = u_boot_console.run_command('erofsload host 0 {} {}'.format(address, file)) + out = ubman.run_command('erofsload host 0 {} {}'.format(address, file)) # check if the right amount of bytes was read assert size in out # calculate u-boot file's checksum - out = u_boot_console.run_command('md5sum {} {}'.format(address, hex(int(size)))) + out = ubman.run_command('md5sum {} {}'.format(address, hex(int(size)))) u_boot_checksum = out.split()[-1] # calculate original file's checksum @@ -134,54 +134,54 @@ def erofs_load_files(u_boot_console, files, sizes, address): # compare checksum assert u_boot_checksum == original_checksum -def erofs_load_files_at_root(u_boot_console): +def erofs_load_files_at_root(ubman): """ Test load file from the root directory. """ files = ['f4096', 'f7812'] sizes = ['4096', '7812'] address = '$kernel_addr_r' - erofs_load_files(u_boot_console, files, sizes, address) + erofs_load_files(ubman, files, sizes, address) -def erofs_load_files_at_subdir(u_boot_console): +def erofs_load_files_at_subdir(ubman): """ Test load file from the subdirectory. """ files = ['subdir/subdir-file'] sizes = ['100'] address = '$kernel_addr_r' - erofs_load_files(u_boot_console, files, sizes, address) + erofs_load_files(ubman, files, sizes, address) -def erofs_load_files_at_symlink(u_boot_console): +def erofs_load_files_at_symlink(ubman): """ Test load file from the symlink. """ files = ['symfile'] sizes = ['7812'] address = '$kernel_addr_r' - erofs_load_files(u_boot_console, files, sizes, address) + erofs_load_files(ubman, files, sizes, address) -def erofs_load_non_existent_file(u_boot_console): +def erofs_load_non_existent_file(ubman): """ Test if the EROFS support will crash when load a nonexistent file. """ address = '$kernel_addr_r' file = 'non-existent' - out = u_boot_console.run_command('erofsload host 0 {} {}'.format(address, file)) + out = ubman.run_command('erofsload host 0 {} {}'.format(address, file)) assert 'Failed to load' in out -def erofs_run_all_tests(u_boot_console): +def erofs_run_all_tests(ubman): """ Runs all test cases. """ - erofs_ls_at_root(u_boot_console) - erofs_ls_at_subdir(u_boot_console) - erofs_ls_at_symlink(u_boot_console) - erofs_ls_at_non_existent_dir(u_boot_console) - erofs_load_files_at_root(u_boot_console) - erofs_load_files_at_subdir(u_boot_console) - erofs_load_files_at_symlink(u_boot_console) - erofs_load_non_existent_file(u_boot_console) + erofs_ls_at_root(ubman) + erofs_ls_at_subdir(ubman) + erofs_ls_at_symlink(ubman) + erofs_ls_at_non_existent_dir(ubman) + erofs_load_files_at_root(ubman) + erofs_load_files_at_subdir(ubman) + erofs_load_files_at_symlink(ubman) + erofs_load_non_existent_file(ubman) @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_fs_generic') @@ -190,11 +190,11 @@ def erofs_run_all_tests(u_boot_console): @pytest.mark.requiredtool('mkfs.erofs') @pytest.mark.requiredtool('md5sum') -def test_erofs(u_boot_console): +def test_erofs(ubman): """ Executes the erofs test suite. """ - build_dir = u_boot_console.config.build_dir + build_dir = ubman.config.build_dir # If the EFI subsystem is enabled and initialized, EFI subsystem tries to # add EFI boot option when the new disk is detected. If there is no EFI @@ -203,15 +203,15 @@ def test_erofs(u_boot_console): # Restart U-Boot to clear the previous state. # TODO: Ideally EFI test cases need to be fixed, but it will # increase the number of system reset. - u_boot_console.restart_uboot() + ubman.restart_uboot() try: # setup test environment make_erofs_image(build_dir) image_path = os.path.join(build_dir, EROFS_IMAGE_NAME) - u_boot_console.run_command('host bind 0 {}'.format(image_path)) + ubman.run_command('host bind 0 {}'.format(image_path)) # run all tests - erofs_run_all_tests(u_boot_console) + erofs_run_all_tests(ubman) except: clean_erofs_image(build_dir) raise AssertionError diff --git a/test/py/tests/test_fs/test_ext.py b/test/py/tests/test_fs/test_ext.py index 05fefa53a0e..41f126e7876 100644 --- a/test/py/tests/test_fs/test_ext.py +++ b/test/py/tests/test_fs/test_ext.py @@ -29,327 +29,335 @@ def str2fat(long_filename): @pytest.mark.boardspec('sandbox') @pytest.mark.slow class TestFsExt(object): - def test_fs_ext1(self, u_boot_console, fs_obj_ext): + def test_fs_ext1(self, ubman, 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'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext + with ubman.log.section('Test Case 1 - write with abs path'): # Test Case 1a - Check if command successfully returned - output = u_boot_console.run_command_list([ + output = ubman.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)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x /dir1/%s.w1 $filesize' + % (fs_cmd_prefix, fs_cmd_write, 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([ + output = ubman.run_command_list([ 'mw.b %x 00 100' % ADDR, - '%sload host 0:0 %x /dir1/%s.w1' % (fs_type, ADDR, MIN_FILE), + '%sload host 0:0 %x /dir1/%s.w1' % (fs_cmd_prefix, 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): + def test_fs_ext2(self, ubman, 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'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext + with ubman.log.section('Test Case 2 - write with rel path'): # Test Case 2a - Check if command successfully returned - output = u_boot_console.run_command_list([ + output = ubman.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)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x dir1/%s.w2 $filesize' + % (fs_cmd_prefix, fs_cmd_write, 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([ + output = ubman.run_command_list([ 'mw.b %x 00 100' % ADDR, - '%sload host 0:0 %x dir1/%s.w2' % (fs_type, ADDR, MIN_FILE), + '%sload host 0:0 %x dir1/%s.w2' % (fs_cmd_prefix, 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): + def test_fs_ext3(self, ubman, 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'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext + with ubman.log.section('Test Case 3 - write with invalid path'): # Test Case 3 - Check if command expectedly failed - output = u_boot_console.run_command_list([ + output = ubman.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)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x /dir1/none/%s.w3 $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)]) assert('Unable to write file /dir1/none/' in ''.join(output)) assert_fs_integrity(fs_type, fs_img) - def test_fs_ext4(self, u_boot_console, fs_obj_ext): + def test_fs_ext4(self, ubman, 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'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext + with ubman.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([ + output = ubman.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)) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x /dir1/%s.w4 $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)]) + output = ubman.run_command( + '%s%s host 0:0 %x /dir1/%s.w4 $filesize 0x1400' + % (fs_cmd_prefix, fs_cmd_write, 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), + output = ubman.run_command_list([ + '%ssize host 0:0 /dir1/%s.w4' % (fs_cmd_prefix, 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([ + output = ubman.run_command_list([ 'mw.b %x 00 100' % ADDR, - '%sload host 0:0 %x /dir1/%s.w4' % (fs_type, ADDR, MIN_FILE), + '%sload host 0:0 %x /dir1/%s.w4' % (fs_cmd_prefix, 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): + def test_fs_ext5(self, ubman, 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'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext + with ubman.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([ + output = ubman.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)) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x /dir1/%s.w5 $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)]) + output = ubman.run_command( + '%s%s host 0:0 %x /dir1/%s.w5 0x1400 0x1400' + % (fs_cmd_prefix, fs_cmd_write, 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), + output = ubman.run_command_list([ + '%ssize host 0:0 /dir1/%s.w5' % (fs_cmd_prefix, 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([ + output = ubman.run_command_list([ 'mw.b %x 00 100' % ADDR, - '%sload host 0:0 %x /dir1/%s.w5' % (fs_type, ADDR, MIN_FILE), + '%sload host 0:0 %x /dir1/%s.w5' % (fs_cmd_prefix, 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): + def test_fs_ext6(self, ubman, 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'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext + with ubman.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([ + output = ubman.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)) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x /dir1/%s.w6 $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)]) + output = ubman.run_command( + '%s%s host 0:0 %x /dir1/%s.w6 0 0' + % (fs_cmd_prefix, fs_cmd_write, 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), + output = ubman.run_command_list([ + '%ssize host 0:0 /dir1/%s.w6' % (fs_cmd_prefix, 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): + def test_fs_ext7(self, ubman, 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)'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext + with ubman.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([ + output = ubman.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)) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x /dir1/%s.w7 $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)]) + output = ubman.run_command( + '%s%s host 0:0 %x /dir1/%s.w7 $filesize $filesize' + % (fs_cmd_prefix, fs_cmd_write, 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), + output = ubman.run_command_list([ + '%ssize host 0:0 /dir1/%s.w7' % (fs_cmd_prefix, 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([ + output = ubman.run_command_list([ 'mw.b %x 00 100' % ADDR, - '%sload host 0:0 %x /dir1/%s.w7' % (fs_type, ADDR, MIN_FILE), + '%sload host 0:0 %x /dir1/%s.w7' % (fs_cmd_prefix, 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): + def test_fs_ext8(self, ubman, 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'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext + with ubman.log.section('Test Case 8 - write beyond the end'): # Test Case 8a - Check if command expectedly failed - output = u_boot_console.run_command_list([ + output = ubman.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)) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x /dir1/%s.w8 $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)]) + output = ubman.run_command( + '%s%s host 0:0 %x /dir1/%s.w8 0x1400 %x' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE, 0x100000 + 0x1400)) assert('Unable to write file /dir1' in output) assert_fs_integrity(fs_type, fs_img) - def test_fs_ext9(self, u_boot_console, fs_obj_ext): + def test_fs_ext9(self, ubman, 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'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext + with ubman.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([ + output = ubman.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)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x /dir1/%s.w9 0x1400 0x1400' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)]) assert('Unable to write file /dir1' in ''.join(output)) assert_fs_integrity(fs_type, fs_img) - def test_fs_ext10(self, u_boot_console, fs_obj_ext): + def test_fs_ext10(self, ubman, 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)'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext + with ubman.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( + output = ubman.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) + output = ubman.run_command( + '%s%s host 0:0 %x /FILE0123456789_%02x 100' + % (fs_cmd_prefix, fs_cmd_write, ADDR, i)) + output = ubman.run_command('%sls host 0:0 /' % fs_cmd_prefix) 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( + output = ubman.run_command( '%srm host 0:0 /FILE0123456789_%02x' - % (fs_type, i)) - output = u_boot_console.run_command('%sls host 0:0 /' % fs_type) + % (fs_cmd_prefix, i)) + output = ubman.run_command('%sls host 0:0 /' % fs_cmd_prefix) 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) + output = ubman.run_command( + '%s%s host 0:0 %x /FILE0123456789_%02x 100' + % (fs_cmd_prefix, fs_cmd_write, ADDR, i)) + output = ubman.run_command('%sls host 0:0 /' % fs_cmd_prefix) 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): + def test_fs_ext11(self, ubman, 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)'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext + with ubman.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( + output = ubman.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) + output = ubman.run_command( + '%s%s host 0:0 %x /dir1/FILE0123456789_%02x 100' + % (fs_cmd_prefix, fs_cmd_write, ADDR, i)) + output = ubman.run_command('%sls host 0:0 /dir1' % fs_cmd_prefix) 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( + output = ubman.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) + % (fs_cmd_prefix, i)) + output = ubman.run_command('%sls host 0:0 /dir1' % fs_cmd_prefix) 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) + output = ubman.run_command( + '%s%s host 0:0 %x /dir1/FILE0123456789_%02x 100' + % (fs_cmd_prefix, fs_cmd_write, ADDR, i)) + output = ubman.run_command('%sls host 0:0 /dir1' % fs_cmd_prefix) assert('FILE0123456789_40' in output) assert('FILE0123456789_79' in output) assert_fs_integrity(fs_type, fs_img) - def test_fs_ext12(self, u_boot_console, fs_obj_ext): + def test_fs_ext12(self, ubman, fs_obj_ext): """ Test Case 12 - write plain and mangle file """ - fs_type,fs_img,md5val = fs_obj_ext - with u_boot_console.log.section('Test Case 12 - write plain and mangle file'): + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext + with ubman.log.section('Test Case 12 - write plain and mangle file'): # Test Case 12a - Check if command successfully returned - output = u_boot_console.run_command_list([ + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%swrite host 0:0 %x /%s 0' - % (fs_type, ADDR, PLAIN_FILE), - '%swrite host 0:0 %x /%s 0' - % (fs_type, ADDR, MANGLE_FILE)]) + '%s%s host 0:0 %x /%s 0' + % (fs_cmd_prefix, fs_cmd_write, ADDR, PLAIN_FILE), + '%s%s host 0:0 %x /%s 0' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MANGLE_FILE)]) assert('0 bytes written' in ''.join(output)) - # Test Case 12b - Read file system content - output = check_output('mdir -i %s' % fs_img, shell=True).decode() - # Test Case 12c - Check if short filename is not mangled - assert(str2fat(PLAIN_FILE) in ''.join(output)) - # Test Case 12d - Check if long filename is mangled - assert(str2fat(MANGLE_FILE) in ''.join(output)) + if fs_type == 'exfat': + # Test Case 12b - Read file system content + output = check_output('fattools ls %s' % fs_img, shell=True).decode() + # Test Case 12c - Check if short filename is not mangled + assert(PLAIN_FILE in ''.join(output)) + # Test Case 12d - Check if long filename is mangled + assert(MANGLE_FILE in ''.join(output)) + else: + # Test Case 12b - Read file system content + output = check_output('mdir -i %s' % fs_img, shell=True).decode() + # Test Case 12c - Check if short filename is not mangled + assert(str2fat(PLAIN_FILE) in ''.join(output)) + # Test Case 12d - Check if long filename is mangled + assert(str2fat(MANGLE_FILE) in ''.join(output)) assert_fs_integrity(fs_type, fs_img) diff --git a/test/py/tests/test_fs/test_fs_cmd.py b/test/py/tests/test_fs/test_fs_cmd.py index 700cf3591de..c925547c7bc 100644 --- a/test/py/tests/test_fs/test_fs_cmd.py +++ b/test/py/tests/test_fs/test_fs_cmd.py @@ -6,8 +6,8 @@ import pytest @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_fs_generic') -def test_fstypes(u_boot_console): +def test_fstypes(ubman): """Test that `fstypes` prints a result which includes `sandbox`.""" - output = u_boot_console.run_command('fstypes') + output = ubman.run_command('fstypes') assert "Supported filesystems:" in output assert "sandbox" in output diff --git a/test/py/tests/test_fs/test_fs_fat.py b/test/py/tests/test_fs/test_fs_fat.py index 4009d0b63a3..b61d8ab9eac 100644 --- a/test/py/tests/test_fs/test_fs_fat.py +++ b/test/py/tests/test_fs/test_fs_fat.py @@ -14,12 +14,12 @@ import re @pytest.mark.boardspec('sandbox') @pytest.mark.slow class TestFsFat(object): - def test_fs_fat1(self, u_boot_console, fs_obj_fat): + def test_fs_fat1(self, ubman, fs_obj_fat): """Test that `fstypes` prints a result which includes `sandbox`.""" fs_type,fs_img = fs_obj_fat - with u_boot_console.log.section('Test Case 1 - fatinfo'): + with ubman.log.section('Test Case 1 - fatinfo'): # Test Case 1 - ls - output = u_boot_console.run_command_list([ + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, 'fatinfo host 0:0']) assert(re.search('Filesystem: %s' % fs_type.upper(), ''.join(output))) diff --git a/test/py/tests/test_fs/test_mkdir.py b/test/py/tests/test_fs/test_mkdir.py index fa9561ec359..1578c3cba3a 100644 --- a/test/py/tests/test_fs/test_mkdir.py +++ b/test/py/tests/test_fs/test_mkdir.py @@ -14,108 +14,108 @@ 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): + def test_mkdir1(self, ubman, 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([ + fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir + with ubman.log.section('Test Case 1 - mkdir'): + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%smkdir host 0:0 dir1' % fs_type, - '%sls host 0:0 /' % fs_type]) + '%smkdir host 0:0 dir1' % fs_cmd_prefix, + '%sls host 0:0 /' % fs_cmd_prefix]) assert('dir1/' in ''.join(output)) - output = u_boot_console.run_command( - '%sls host 0:0 dir1' % fs_type) + output = ubman.run_command( + '%sls host 0:0 dir1' % fs_cmd_prefix) assert('./' in output) assert('../' in output) assert_fs_integrity(fs_type, fs_img) - def test_mkdir2(self, u_boot_console, fs_obj_mkdir): + def test_mkdir2(self, ubman, 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([ + fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir + with ubman.log.section('Test Case 2 - mkdir (sub-sub directory)'): + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%smkdir host 0:0 dir1/dir2' % fs_type, - '%sls host 0:0 dir1' % fs_type]) + '%smkdir host 0:0 dir1/dir2' % fs_cmd_prefix, + '%sls host 0:0 dir1' % fs_cmd_prefix]) assert('dir2/' in ''.join(output)) - output = u_boot_console.run_command( - '%sls host 0:0 dir1/dir2' % fs_type) + output = ubman.run_command( + '%sls host 0:0 dir1/dir2' % fs_cmd_prefix) assert('./' in output) assert('../' in output) assert_fs_integrity(fs_type, fs_img) - def test_mkdir3(self, u_boot_console, fs_obj_mkdir): + def test_mkdir3(self, ubman, 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([ + fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir + with ubman.log.section('Test Case 3 - mkdir (non-existing path)'): + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%smkdir host 0:0 none/dir3' % fs_type]) + '%smkdir host 0:0 none/dir3' % fs_cmd_prefix]) 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): + def test_mkdir4(self, ubman, 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([ + fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir + with ubman.log.section('Test Case 4 - mkdir (".")'): + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%smkdir host 0:0 .' % fs_type]) + '%smkdir host 0:0 .' % fs_cmd_prefix]) 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): + def test_mkdir5(self, ubman, 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([ + fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir + with ubman.log.section('Test Case 5 - mkdir ("..")'): + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%smkdir host 0:0 ..' % fs_type]) + '%smkdir host 0:0 ..' % fs_cmd_prefix]) 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): + def test_mkdir6(self, ubman, 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([ + fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir + with ubman.log.section('Test Case 6 - mkdir (create many)'): + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%smkdir host 0:0 dir6' % fs_type, - '%sls host 0:0 /' % fs_type]) + '%smkdir host 0:0 dir6' % fs_cmd_prefix, + '%sls host 0:0 /' % fs_cmd_prefix]) assert('dir6/' in ''.join(output)) for i in range(0, 20): - output = u_boot_console.run_command( + output = ubman.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) + % (fs_cmd_prefix, i)) + output = ubman.run_command('%sls host 0:0 dir6' % fs_cmd_prefix) assert('0123456789abcdef00/' in output) assert('0123456789abcdef13/' in output) - output = u_boot_console.run_command( - '%sls host 0:0 dir6/0123456789abcdef13/.' % fs_type) + output = ubman.run_command( + '%sls host 0:0 dir6/0123456789abcdef13/.' % fs_cmd_prefix) assert('./' in output) assert('../' in output) - output = u_boot_console.run_command( - '%sls host 0:0 dir6/0123456789abcdef13/..' % fs_type) + output = ubman.run_command( + '%sls host 0:0 dir6/0123456789abcdef13/..' % fs_cmd_prefix) assert('0123456789abcdef00/' in output) assert('0123456789abcdef13/' in output) assert_fs_integrity(fs_type, fs_img) diff --git a/test/py/tests/test_fs/test_rename.py b/test/py/tests/test_fs/test_rename.py new file mode 100644 index 00000000000..e36cff99bb7 --- /dev/null +++ b/test/py/tests/test_fs/test_rename.py @@ -0,0 +1,372 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2025 Gabriel Dalimonte <gabriel.dalimonte@gmail.com> +# +# U-Boot File System:rename Test + + +import pytest + +from fstest_defs import * +from fstest_helpers import assert_fs_integrity + +@pytest.mark.boardspec('sandbox') +@pytest.mark.slow +class TestRename(object): + def test_rename1(self, ubman, fs_obj_rename): + """ + Test Case 1 - rename a file (successful mv) + """ + fs_type, fs_img, md5val = fs_obj_rename + with ubman.log.section('Test Case 1 - rename a file'): + d = 'test1' + src = '%s/file1' % d + dst = '%s/file2' % d + output = ubman.run_command_list([ + 'host bind 0 %s' % fs_img, + 'setenv filesize', + 'mv host 0:0 %s %s' % (src, dst), + ]) + assert('' == ''.join(output)) + + output = ubman.run_command_list([ + 'load host 0:0 %x /%s' % (ADDR, dst), + 'printenv filesize']) + assert('filesize=400' in output) + + output = ubman.run_command_list([ + 'ls host 0:0 %s' % (d), + ]) + assert('file1' not in ''.join(output)) + + output = ubman.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val['test1'] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) + + def test_rename2(self, ubman, fs_obj_rename): + """ + Test Case 2 - rename a file to an existing file (successful mv) + """ + fs_type, fs_img, md5val = fs_obj_rename + with ubman.log.section('Test Case 2 - rename a file to an existing file'): + d = 'test2' + src = '%s/file1' % d + dst = '%s/file_exist' % d + output = ubman.run_command_list([ + 'host bind 0 %s' % fs_img, + 'setenv filesize', + 'mv host 0:0 %s %s' % (src, dst), + ]) + assert('' == ''.join(output)) + + output = ubman.run_command_list([ + 'load host 0:0 %x /%s' % (ADDR, dst), + 'printenv filesize']) + assert('filesize=400' in output) + + output = ubman.run_command_list([ + 'ls host 0:0 %s' % (d), + ]) + assert('file1' not in ''.join(output)) + + output = ubman.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val['test2'] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) + + def test_rename3(self, ubman, fs_obj_rename): + """ + Test Case 3 - rename a directory (successful mv) + """ + fs_type, fs_img, md5val = fs_obj_rename + with ubman.log.section('Test Case 3 - rename a directory'): + d = 'test3' + src = '%s/dir1' % d + dst = '%s/dir2' % d + output = ubman.run_command_list([ + 'host bind 0 %s' % fs_img, + 'setenv filesize', + 'mv host 0:0 %s %s' % (src, dst), + ]) + assert('' == ''.join(output)) + + output = ubman.run_command_list([ + 'load host 0:0 %x /%s/file1' % (ADDR, dst), + 'printenv filesize']) + assert('filesize=400' in output) + + output = ubman.run_command_list([ + 'ls host 0:0 %s' % (d), + ]) + assert('dir1' not in ''.join(output)) + + output = ubman.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val['test3'] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) + + def test_rename4(self, ubman, fs_obj_rename): + """ + Test Case 4 - rename a directory to an existing directory (successful + mv) + """ + fs_type, fs_img, md5val = fs_obj_rename + with ubman.log.section('Test Case 4 - rename a directory to an existing directory'): + d = 'test4' + src = '%s/dir1' % d + dst = '%s/dir2' % d + output = ubman.run_command_list([ + 'host bind 0 %s' % fs_img, + 'setenv filesize', + 'mv host 0:0 %s %s' % (src, dst), + ]) + assert('' == ''.join(output)) + + output = ubman.run_command_list([ + 'load host 0:0 %x /%s/dir1/file1' % (ADDR, dst), + 'printenv filesize']) + assert('filesize=400' in output) + + output = ubman.run_command_list([ + 'ls host 0:0 %s' % (d), + ]) + assert('dir1' not in ''.join(output)) + + output = ubman.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val['test4'] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) + + def test_rename5(self, ubman, fs_obj_rename): + """ + Test Case 5 - rename a directory to an existing file (failed mv) + """ + fs_type, fs_img, md5val = fs_obj_rename + with ubman.log.section('Test Case 5 - rename a directory to an existing file'): + d = 'test5' + src = '%s/dir1' % d + dst = '%s/file2' % d + output = ubman.run_command_list([ + 'host bind 0 %s' % fs_img, + 'setenv filesize', + 'mv host 0:0 %s %s' % (src, dst), + ]) + assert('' == ''.join(output)) + + output = ubman.run_command_list([ + 'ls host 0:0 %s' % (d), + ]) + assert('dir1' in ''.join(output)) + assert('file2' in ''.join(output)) + + output = ubman.run_command_list([ + 'load host 0:0 %x /%s' % (ADDR, dst), + 'printenv filesize']) + assert('filesize=400' in output) + + output = ubman.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val['test5'] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) + + def test_rename6(self, ubman, fs_obj_rename): + """ + Test Case 6 - rename a file to an existing empty directory (failed mv) + """ + fs_type, fs_img, md5val = fs_obj_rename + with ubman.log.section('Test Case 6 - rename a file to an existing empty directory'): + d = 'test6' + src = '%s/existing' % d + dst = '%s/dir2' % d + output = ubman.run_command_list([ + 'host bind 0 %s' % fs_img, + 'setenv filesize', + 'mv host 0:0 %s %s' % (src, dst), + ]) + assert('' == ''.join(output)) + + output = ubman.run_command_list([ + 'load host 0:0 %x /%s' % (ADDR, src), + 'printenv filesize']) + assert('filesize=400' in output) + + output = ubman.run_command_list([ + 'ls host 0:0 %s' % (d), + ]) + assert('dir2' in ''.join(output)) + assert('existing' in ''.join(output)) + + output = ubman.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val['test6'] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) + + def test_rename7(self, ubman, fs_obj_rename): + """ + Test Case 7 - rename a directory to a non-empty directory (failed mv) + """ + fs_type, fs_img, md5val = fs_obj_rename + with ubman.log.section('Test Case 7 - rename a directory to a non-empty directory'): + d = 'test7' + src = '%s/dir1' % d + dst = '%s/dir2' % d + output = ubman.run_command_list([ + 'host bind 0 %s' % fs_img, + 'setenv filesize', + 'mv host 0:0 %s %s' % (src, dst), + ]) + assert('' == ''.join(output)) + + output = ubman.run_command_list([ + 'load host 0:0 %x /%s/dir1/file1' % (ADDR, dst), + 'printenv filesize']) + assert('filesize=400' in output) + + output = ubman.run_command_list([ + 'ls host 0:0 %s' % (d), + ]) + assert('dir1' in ''.join(output)) + assert('dir2' in ''.join(output)) + + output = ubman.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val['test7'] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) + + def test_rename8(self, ubman, fs_obj_rename): + """ + Test Case 8 - rename a directory inside itself (failed mv) + """ + fs_type, fs_img, md5val = fs_obj_rename + with ubman.log.section('Test Case 8 - rename a directory inside itself'): + d = 'test8' + src = '%s/dir1' % d + dst = '%s/dir1/dir1' % d + output = ubman.run_command_list([ + 'host bind 0 %s' % fs_img, + 'setenv filesize', + 'mv host 0:0 %s %s' % (src, dst), + ]) + assert('' == ''.join(output)) + + output = ubman.run_command_list([ + 'load host 0:0 %x /%s/file1' % (ADDR, src), + 'printenv filesize']) + assert('filesize=400' in output) + + output = ubman.run_command_list([ + 'ls host 0:0 %s' % (d), + ]) + assert('dir1' in ''.join(output)) + + output = ubman.run_command_list([ + 'ls host 0:0 %s' % (src), + ]) + assert('file1' in ''.join(output)) + assert('dir1' not in ''.join(output)) + + output = ubman.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val['test8'] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) + + def test_rename9(self, ubman, fs_obj_rename): + """ + Test Case 9 - rename a directory inside itself with backtracks (failed + mv) + """ + fs_type, fs_img, md5val = fs_obj_rename + with ubman.log.section('Test Case 9 - rename a directory inside itself with backtracks'): + d = 'test9' + src = '%s/dir1/nested' % d + dst = '%s/dir1/nested/inner/./../../../dir1/nested/inner/another' % d + output = ubman.run_command_list([ + 'host bind 0 %s' % fs_img, + 'setenv filesize', + 'mv host 0:0 %s %s' % (src, dst), + ]) + assert('' == ''.join(output)) + + output = ubman.run_command_list([ + 'ls host 0:0 %s/dir1' % (d), + ]) + assert('nested' in ''.join(output)) + + output = ubman.run_command_list([ + 'ls host 0:0 %s' % (src), + ]) + assert('inner' in ''.join(output)) + assert('nested' not in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) + + def test_rename10(self, ubman, fs_obj_rename): + """ + Test Case 10 - rename a file to itself (successful mv) + """ + fs_type, fs_img, md5val = fs_obj_rename + with ubman.log.section('Test Case 10 - rename a file to itself'): + d = 'test10' + src = '%s/file1' % d + output = ubman.run_command_list([ + 'host bind 0 %s' % fs_img, + 'setenv filesize', + 'mv host 0:0 %s %s' % (src, src), + ]) + assert('' == ''.join(output)) + + output = ubman.run_command_list([ + 'load host 0:0 %x /%s' % (ADDR, src), + 'printenv filesize']) + assert('filesize=400' in output) + + output = ubman.run_command_list([ + 'ls host 0:0 %s' % (d), + ]) + assert('file1' in ''.join(output)) + + output = ubman.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val['test10'] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) + + def test_rename11(self, ubman, fs_obj_rename): + """ + Test Case 11 - rename a directory to itself (successful mv) + """ + fs_type, fs_img, md5val = fs_obj_rename + with ubman.log.section('Test Case 11 - rename a directory to itself'): + # / at the end here is intentional. Ensures trailing / doesn't + # affect mv producing an updated dst path for fs_rename + d = 'test11/' + src = '%sdir1' % d + output = ubman.run_command_list([ + 'host bind 0 %s' % fs_img, + 'setenv filesize', + 'mv host 0:0 %s %s' % (src, d), + ]) + assert('' == ''.join(output)) + + output = ubman.run_command_list([ + 'load host 0:0 %x /%s/file1' % (ADDR, src), + 'printenv filesize']) + assert('filesize=400' in output) + + output = ubman.run_command_list([ + 'ls host 0:0 %s' % (d), + ]) + assert('dir1' in ''.join(output)) + + output = ubman.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val['test11'] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) diff --git a/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py b/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py index 6ec6ccec6c9..33093f61ac3 100644 --- a/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py +++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py @@ -27,11 +27,11 @@ def original_md5sum(path): return checksum -def uboot_md5sum(u_boot_console, address, count): +def uboot_md5sum(ubman, address, count): """ Runs U-Boot's md5sum command. Args: - u_boot_console: provides the means to interact with U-Boot's console. + ubman: provides the means to interact with U-Boot's console. address: address where the file was loaded (e.g.: $kernel_addr_r). count: file's size. It was named 'count' to match md5sum's respective argument name. @@ -39,89 +39,89 @@ def uboot_md5sum(u_boot_console, address, count): The checksum of the file loaded with sqfsload as a string. """ - out = u_boot_console.run_command('md5sum {} {}'.format(address, count)) + out = ubman.run_command('md5sum {} {}'.format(address, count)) checksum = out.split()[-1] return checksum -def sqfs_load_files(u_boot_console, files, sizes, address): +def sqfs_load_files(ubman, files, sizes, address): """ Loads files and asserts their checksums. Args: - u_boot_console: provides the means to interact with U-Boot's console. + ubman: provides the means to interact with U-Boot's console. files: list of files to be loaded. sizes: the sizes of each file. address: the address where the files should be loaded. """ - build_dir = u_boot_console.config.build_dir + build_dir = ubman.config.build_dir for (file, size) in zip(files, sizes): - out = u_boot_console.run_command('sqfsload host 0 {} {}'.format(address, file)) + out = ubman.run_command('sqfsload host 0 {} {}'.format(address, file)) # check if the right amount of bytes was read assert size in out # compare original file's checksum against u-boot's - u_boot_checksum = uboot_md5sum(u_boot_console, address, hex(int(size))) + u_boot_checksum = uboot_md5sum(ubman, address, hex(int(size))) original_file_path = os.path.join(build_dir, SQFS_SRC_DIR + '/' + file) original_checksum = original_md5sum(original_file_path) assert u_boot_checksum == original_checksum -def sqfs_load_files_at_root(u_boot_console): +def sqfs_load_files_at_root(ubman): """ Calls sqfs_load_files passing the files at the SquashFS image's root. Args: - u_boot_console: provides the means to interact with U-Boot's console. + ubman: provides the means to interact with U-Boot's console. """ files = ['f4096', 'f5096', 'f1000'] sizes = ['4096', '5096', '1000'] address = '$kernel_addr_r' - sqfs_load_files(u_boot_console, files, sizes, address) + sqfs_load_files(ubman, files, sizes, address) -def sqfs_load_files_at_subdir(u_boot_console): +def sqfs_load_files_at_subdir(ubman): """ Calls sqfs_load_files passing the files at the SquashFS image's subdir. This test checks if the path resolution works, since the file is not at the root directory. Args: - u_boot_console: provides the means to interact with U-Boot's console. + ubman: provides the means to interact with U-Boot's console. """ files = ['subdir/subdir-file'] sizes = ['100'] address = '$kernel_addr_r' - sqfs_load_files(u_boot_console, files, sizes, address) + sqfs_load_files(ubman, files, sizes, address) -def sqfs_load_non_existent_file(u_boot_console): +def sqfs_load_non_existent_file(ubman): """ Calls sqfs_load_files passing an non-existent file to raise an error. This test checks if the SquashFS support won't crash if it doesn't find the specified file. Args: - u_boot_console: provides the means to interact with U-Boot's console. + ubman: provides the means to interact with U-Boot's console. """ address = '$kernel_addr_r' file = 'non-existent' - out = u_boot_console.run_command('sqfsload host 0 {} {}'.format(address, file)) + out = ubman.run_command('sqfsload host 0 {} {}'.format(address, file)) assert 'Failed to load' in out -def sqfs_run_all_load_tests(u_boot_console): +def sqfs_run_all_load_tests(ubman): """ Runs all the previously defined test cases. Args: - u_boot_console: provides the means to interact with U-Boot's console. + ubman: provides the means to interact with U-Boot's console. """ - sqfs_load_files_at_root(u_boot_console) - sqfs_load_files_at_subdir(u_boot_console) - sqfs_load_non_existent_file(u_boot_console) + sqfs_load_files_at_root(ubman) + sqfs_load_files_at_subdir(ubman) + sqfs_load_non_existent_file(ubman) @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_fs_generic') @pytest.mark.buildconfigspec('cmd_squashfs') @pytest.mark.buildconfigspec('fs_squashfs') @pytest.mark.requiredtool('mksquashfs') -def test_sqfs_load(u_boot_console): +def test_sqfs_load(ubman): """ Executes the sqfsload test suite. First, it generates the SquashFS images, then it runs the test cases and @@ -129,9 +129,9 @@ def test_sqfs_load(u_boot_console): cleaned before exiting. Args: - u_boot_console: provides the means to interact with U-Boot's console. + ubman: provides the means to interact with U-Boot's console. """ - build_dir = u_boot_console.config.build_dir + build_dir = ubman.config.build_dir # setup test environment check_mksquashfs_version() @@ -142,8 +142,8 @@ def test_sqfs_load(u_boot_console): for image in STANDARD_TABLE: try: image_path = os.path.join(build_dir, image) - u_boot_console.run_command('host bind 0 {}'.format(image_path)) - sqfs_run_all_load_tests(u_boot_console) + ubman.run_command('host bind 0 {}'.format(image_path)) + sqfs_run_all_load_tests(ubman) except: clean_all_images(build_dir) clean_sqfs_src_dir(build_dir) diff --git a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py index a20a7d1a663..adda3b98cda 100644 --- a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py +++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py @@ -10,70 +10,70 @@ from sqfs_common import generate_sqfs_src_dir, make_all_images from sqfs_common import clean_sqfs_src_dir, clean_all_images from sqfs_common import check_mksquashfs_version -def sqfs_ls_at_root(u_boot_console): +def sqfs_ls_at_root(ubman): """ Runs sqfsls at image's root. This test checks if all the present files and directories were listed. Also, it checks if passing the slash or not changes the output, which it shouldn't. Args: - u_boot_console: provides the means to interact with U-Boot's console. + ubman: provides the means to interact with U-Boot's console. """ - no_slash = u_boot_console.run_command('sqfsls host 0') - slash = u_boot_console.run_command('sqfsls host 0 /') + no_slash = ubman.run_command('sqfsls host 0') + slash = ubman.run_command('sqfsls host 0 /') assert no_slash == slash expected_lines = ['empty-dir/', '1000 f1000', '4096 f4096', '5096 f5096', 'subdir/', '<SYM> sym', '4 file(s), 2 dir(s)'] - output = u_boot_console.run_command('sqfsls host 0') + output = ubman.run_command('sqfsls host 0') for line in expected_lines: assert line in output -def sqfs_ls_at_empty_dir(u_boot_console): +def sqfs_ls_at_empty_dir(ubman): """ Runs sqfsls at an empty directory. This tests checks if sqfsls will print anything other than the 'Empty directory' message. Args: - u_boot_console: provides the means to interact with U-Boot's console. + ubman: provides the means to interact with U-Boot's console. """ - assert u_boot_console.run_command('sqfsls host 0 empty-dir') == 'Empty directory.' + assert ubman.run_command('sqfsls host 0 empty-dir') == 'Empty directory.' -def sqfs_ls_at_subdir(u_boot_console): +def sqfs_ls_at_subdir(ubman): """ Runs sqfsls at the SquashFS image's subdir. This test checks if the path resolution works, since the directory is not the root. Args: - u_boot_console: provides the means to interact with U-Boot's console. + ubman: provides the means to interact with U-Boot's console. """ expected_lines = ['100 subdir-file', '1 file(s), 0 dir(s)'] - output = u_boot_console.run_command('sqfsls host 0 subdir') + output = ubman.run_command('sqfsls host 0 subdir') for line in expected_lines: assert line in output -def sqfs_ls_at_symlink(u_boot_console): +def sqfs_ls_at_symlink(ubman): """ Runs sqfsls at a SquashFS image's symbolic link. This test checks if the symbolic link's target resolution works. Args: - u_boot_console: provides the means to interact with U-Boot's console. + ubman: provides the means to interact with U-Boot's console. """ # since sym -> subdir, the following outputs must be equal - output = u_boot_console.run_command('sqfsls host 0 sym') - output_subdir = u_boot_console.run_command('sqfsls host 0 subdir') + output = ubman.run_command('sqfsls host 0 sym') + output_subdir = ubman.run_command('sqfsls host 0 subdir') assert output == output_subdir expected_lines = ['100 subdir-file', '1 file(s), 0 dir(s)'] for line in expected_lines: assert line in output -def sqfs_ls_at_non_existent_dir(u_boot_console): +def sqfs_ls_at_non_existent_dir(ubman): """ Runs sqfsls at a file and at a non-existent directory. This test checks if the SquashFS support won't crash if it doesn't find the @@ -81,24 +81,24 @@ def sqfs_ls_at_non_existent_dir(u_boot_console): directory. In both cases, the output should be the same. Args: - u_boot_console: provides the means to interact with U-Boot's console. + ubman: provides the means to interact with U-Boot's console. """ - out_non_existent = u_boot_console.run_command('sqfsls host 0 fff') - out_not_dir = u_boot_console.run_command('sqfsls host 0 f1000') + out_non_existent = ubman.run_command('sqfsls host 0 fff') + out_not_dir = ubman.run_command('sqfsls host 0 f1000') assert out_non_existent == out_not_dir assert '** Cannot find directory. **' in out_non_existent -def sqfs_run_all_ls_tests(u_boot_console): +def sqfs_run_all_ls_tests(ubman): """ Runs all the previously defined test cases. Args: - u_boot_console: provides the means to interact with U-Boot's console. + ubman: provides the means to interact with U-Boot's console. """ - sqfs_ls_at_root(u_boot_console) - sqfs_ls_at_empty_dir(u_boot_console) - sqfs_ls_at_subdir(u_boot_console) - sqfs_ls_at_symlink(u_boot_console) - sqfs_ls_at_non_existent_dir(u_boot_console) + sqfs_ls_at_root(ubman) + sqfs_ls_at_empty_dir(ubman) + sqfs_ls_at_subdir(ubman) + sqfs_ls_at_symlink(ubman) + sqfs_ls_at_non_existent_dir(ubman) @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_fs_generic') @@ -106,7 +106,7 @@ def sqfs_run_all_ls_tests(u_boot_console): @pytest.mark.buildconfigspec('fs_squashfs') @pytest.mark.requiredtool('mksquashfs') @pytest.mark.singlethread -def test_sqfs_ls(u_boot_console): +def test_sqfs_ls(ubman): """ Executes the sqfsls test suite. First, it generates the SquashFS images, then it runs the test cases and @@ -114,9 +114,9 @@ def test_sqfs_ls(u_boot_console): cleaned before exiting. Args: - u_boot_console: provides the means to interact with U-Boot's console. + ubman: provides the means to interact with U-Boot's console. """ - build_dir = u_boot_console.config.build_dir + build_dir = ubman.config.build_dir # If the EFI subsystem is enabled and initialized, EFI subsystem tries to # add EFI boot option when the new disk is detected. If there is no EFI @@ -125,7 +125,7 @@ def test_sqfs_ls(u_boot_console): # Restart U-Boot to clear the previous state. # TODO: Ideally EFI test cases need to be fixed, but it will # increase the number of system reset. - u_boot_console.restart_uboot() + ubman.restart_uboot() # setup test environment check_mksquashfs_version() @@ -136,8 +136,8 @@ def test_sqfs_ls(u_boot_console): for image in STANDARD_TABLE: try: image_path = os.path.join(build_dir, image) - u_boot_console.run_command('host bind 0 {}'.format(image_path)) - sqfs_run_all_ls_tests(u_boot_console) + ubman.run_command('host bind 0 {}'.format(image_path)) + sqfs_run_all_ls_tests(ubman) except: clean_all_images(build_dir) clean_sqfs_src_dir(build_dir) diff --git a/test/py/tests/test_fs/test_symlink.py b/test/py/tests/test_fs/test_symlink.py index 9ced101a294..9ffd7e6e54d 100644 --- a/test/py/tests/test_fs/test_symlink.py +++ b/test/py/tests/test_fs/test_symlink.py @@ -18,38 +18,38 @@ 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): + def test_symlink1(self, ubman, 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([ + with ubman.log.section('Test Case 1 - create link and read'): + output = ubman.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([ + output = ubman.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([ + output = ubman.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): + def test_symlink2(self, ubman, 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([ + with ubman.log.section('Test Case 2 - create chained links'): + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, 'setenv filesize', 'ln host 0:0 %s /%s.link1 ' % (SMALL_FILE, SMALL_FILE), @@ -60,25 +60,25 @@ class TestSymlink(object): ]) assert('' in ''.join(output)) - output = u_boot_console.run_command_list([ + output = ubman.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([ + output = ubman.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): + def test_symlink3(self, ubman, 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([ + with ubman.log.section('Test Case 1 - create link and read'): + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, 'setenv filesize', 'ln host 0:0 %s /%s ' % (MEDIUM_FILE, SMALL_FILE), @@ -86,45 +86,45 @@ class TestSymlink(object): ]) assert('' in ''.join(output)) - output = u_boot_console.run_command_list([ + output = ubman.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([ + output = ubman.run_command_list([ 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[1] in ''.join(output)) - output = u_boot_console.run_command_list([ + output = ubman.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([ + output = ubman.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): + def test_symlink4(self, ubman, 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'): + with ubman.log.section('Test Case 1 - create link and read'): - output = u_boot_console.run_command_list([ + output = ubman.run_command_list([ 'setenv filesize', 'ln host 0:0 nowhere /link ', ]) assert('' in ''.join(output)) - output = u_boot_console.run_command( + output = ubman.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') + with ubman.disable_check('error_notification'): + output = ubman.run_command('printenv filesize') assert('"filesize" not defined' in ''.join(output)) assert_fs_integrity(fs_type, fs_img) diff --git a/test/py/tests/test_fs/test_unlink.py b/test/py/tests/test_fs/test_unlink.py index 97aafc63bb5..1e2df3dbfd8 100644 --- a/test/py/tests/test_fs/test_unlink.py +++ b/test/py/tests/test_fs/test_unlink.py @@ -15,104 +15,104 @@ 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): + def test_unlink1(self, ubman, 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([ + fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink + with ubman.log.section('Test Case 1 - unlink (file)'): + output = ubman.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]) + '%srm host 0:0 dir1/file1' % fs_cmd_prefix, + '%sls host 0:0 dir1/file1' % fs_cmd_prefix]) assert('' == ''.join(output)) - output = u_boot_console.run_command( - '%sls host 0:0 dir1/' % fs_type) + output = ubman.run_command( + '%sls host 0:0 dir1/' % fs_cmd_prefix) 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): + def test_unlink2(self, ubman, 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) + fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink + with ubman.log.section('Test Case 2 - unlink (many)'): + output = ubman.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)]) + output = ubman.run_command_list([ + '%srm host 0:0 dir2/0123456789abcdef%02x' % (fs_cmd_prefix, i), + '%sls host 0:0 dir2/0123456789abcdef%02x' % (fs_cmd_prefix, i)]) assert('' == ''.join(output)) - output = u_boot_console.run_command( - '%sls host 0:0 dir2' % fs_type) + output = ubman.run_command( + '%sls host 0:0 dir2' % fs_cmd_prefix) 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): + def test_unlink3(self, ubman, 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([ + fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink + with ubman.log.section('Test Case 3 - unlink (non-existing)'): + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%srm host 0:0 dir1/nofile' % fs_type]) + '%srm host 0:0 dir1/nofile' % fs_cmd_prefix]) 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): + def test_unlink4(self, ubman, 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([ + fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink + with ubman.log.section('Test Case 4 - unlink (directory)'): + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%srm host 0:0 dir4' % fs_type]) + '%srm host 0:0 dir4' % fs_cmd_prefix]) assert('' == ''.join(output)) - output = u_boot_console.run_command( - '%sls host 0:0 /' % fs_type) + output = ubman.run_command( + '%sls host 0:0 /' % fs_cmd_prefix) assert(not 'dir4' in output) assert_fs_integrity(fs_type, fs_img) - def test_unlink5(self, u_boot_console, fs_obj_unlink): + def test_unlink5(self, ubman, 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([ + fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink + with ubman.log.section('Test Case 5 - unlink ("non-empty directory")'): + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%srm host 0:0 dir5' % fs_type]) + '%srm host 0:0 dir5' % fs_cmd_prefix]) 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): + def test_unlink6(self, ubman, 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([ + fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink + with ubman.log.section('Test Case 6 - unlink (".")'): + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%srm host 0:0 dir5/.' % fs_type]) + '%srm host 0:0 dir5/.' % fs_cmd_prefix]) 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): + def test_unlink7(self, ubman, 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([ + fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink + with ubman.log.section('Test Case 7 - unlink ("..")'): + output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%srm host 0:0 dir5/..' % fs_type]) + '%srm host 0:0 dir5/..' % fs_cmd_prefix]) assert('directory is not empty' in ''.join(output)) assert_fs_integrity(fs_type, fs_img) |