From 752c3769874596d012cd8325099d2ae20123f989 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 9 Feb 2025 09:07:14 -0700 Subject: test/py: Shorten u_boot_console This fixture name is quite long and results in lots of verbose code. We know this is U-Boot so the 'u_boot_' part is not necessary. But it is also a bit of a misnomer, since it provides access to all the information available to tests. It is not just the console. It would be too confusing to use con as it would be confused with config and it is probably too short. So shorten it to 'ubman'. Signed-off-by: Simon Glass Link: https://lore.kernel.org/u-boot/CAFLszTgPa4aT_J9h9pqeTtLCVn4x2JvLWRcWRD8NaN3uoSAtyA@mail.gmail.com/ --- test/py/tests/test_fs/test_ext.py | 124 +++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 62 deletions(-) (limited to 'test/py/tests/test_fs/test_ext.py') diff --git a/test/py/tests/test_fs/test_ext.py b/test/py/tests/test_fs/test_ext.py index 05fefa53a0e..9c213f2da55 100644 --- a/test/py/tests/test_fs/test_ext.py +++ b/test/py/tests/test_fs/test_ext.py @@ -29,14 +29,14 @@ 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'): + 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' @@ -44,7 +44,7 @@ class TestFsExt(object): 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), 'md5sum %x $filesize' % ADDR, @@ -52,14 +52,14 @@ class TestFsExt(object): 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'): + 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' @@ -67,7 +67,7 @@ class TestFsExt(object): 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), 'md5sum %x $filesize' % ADDR, @@ -75,14 +75,14 @@ class TestFsExt(object): 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'): + 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' @@ -90,32 +90,32 @@ class TestFsExt(object): 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'): + 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( + output = ubman.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([ + output = ubman.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([ + output = ubman.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, @@ -123,32 +123,32 @@ class TestFsExt(object): 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'): + 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( + output = ubman.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([ + output = ubman.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([ + output = ubman.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, @@ -156,57 +156,57 @@ class TestFsExt(object): 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'): + 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( + output = ubman.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([ + output = ubman.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): + 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)'): + 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( + output = ubman.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([ + output = ubman.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([ + output = ubman.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, @@ -214,32 +214,32 @@ class TestFsExt(object): 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'): + 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( + output = ubman.run_command( '%swrite host 0:0 %x /dir1/%s.w8 0x1400 %x' % (fs_type, 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'): + 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' @@ -247,98 +247,98 @@ class TestFsExt(object): 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)'): + 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( + output = ubman.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('%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( + 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) + output = ubman.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( + output = ubman.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('%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): + 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)'): + 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( + output = ubman.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('%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( + 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) + output = ubman.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( + output = ubman.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('%sls host 0:0 /dir1' % fs_type) 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'): + 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), -- cgit v1.2.3 From 6592425c6d7e4e010f3de88bc8ced7163e4f12e2 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Mon, 17 Mar 2025 04:12:42 +0100 Subject: test_fs: Allow testing FS_GENERIC The generic filesystem interface was so far untested. The interface is similar to the FS specific interfaces with FS specific prefixes, like ext4ls, fatmkdir, ... but it does not have any prefixes, i.e. it provides plain ls, mkdir, ... commands. Extend the test parameters to include 'fs_cmd_prefix' and optionally 'fs_cmd_write' parameters. The 'fs_cmd_prefix' allow specifying the filesystem specific command prefix, like 'ext4' in 'ext4ls'. The 'fs_cmd_write' allows selecting between 'write'/'save' command name for storing files into the filesystem, see last paragraph. Introduce new 'fs_generic' fs_type which is used to parametrize existing tests and run them without any prefixes if detected, thus testing the generic filesystem interface. Use the fatfs as the backing store for the generic FS tests. The check_ubconfig needs to be slightly adjusted to avoid test for CMD_FS_GENERIC_WRITE which does not exist separately from CMD_FS_GENERIC. The CMD_FS_GENERIC does not provide generic 'write' command, instead the generic equivalent command is called 'save' . Add simple ternary oeprator to use 'save' command for CMD_FS_GENERIC tests and '..write' commands for filesystem specific tests. Enable generic filesystem tests for basic/extended/mkdir/unlink tests. Signed-off-by: Marek Vasut --- test/py/tests/test_fs/test_ext.py | 156 +++++++++++++++++++------------------- 1 file changed, 78 insertions(+), 78 deletions(-) (limited to 'test/py/tests/test_fs/test_ext.py') diff --git a/test/py/tests/test_fs/test_ext.py b/test/py/tests/test_fs/test_ext.py index 9c213f2da55..a75cd74dade 100644 --- a/test/py/tests/test_fs/test_ext.py +++ b/test/py/tests/test_fs/test_ext.py @@ -33,20 +33,20 @@ class TestFsExt(object): """ Test Case 1 - write a file with absolute path """ - fs_type,fs_img,md5val = fs_obj_ext + 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 = 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 = 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)) @@ -56,20 +56,20 @@ class TestFsExt(object): """ Test Case 2 - write to a file with relative path """ - fs_type,fs_img,md5val = fs_obj_ext + 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 = 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 = 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)) @@ -79,14 +79,14 @@ class TestFsExt(object): """ Test Case 3 - write to a file with invalid path """ - fs_type,fs_img,md5val = fs_obj_ext + 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 = 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) @@ -94,22 +94,22 @@ class TestFsExt(object): """ Test Case 4 - write at non-zero offset, enlarging file size """ - fs_type,fs_img,md5val = fs_obj_ext + 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 = 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)]) + '%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( - '%swrite host 0:0 %x /dir1/%s.w4 $filesize 0x1400' - % (fs_type, ADDR, MIN_FILE)) + '%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 = ubman.run_command_list([ - '%ssize host 0:0 /dir1/%s.w4' % (fs_type, MIN_FILE), + '%ssize host 0:0 /dir1/%s.w4' % (fs_cmd_prefix, MIN_FILE), 'printenv filesize', 'setenv filesize']) assert('filesize=6400' in ''.join(output)) @@ -117,7 +117,7 @@ class TestFsExt(object): # Test Case 4c - Check md5 of file content 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)) @@ -127,22 +127,22 @@ class TestFsExt(object): """ Test Case 5 - write at non-zero offset, shrinking file size """ - fs_type,fs_img,md5val = fs_obj_ext + 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 = 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)]) + '%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( - '%swrite host 0:0 %x /dir1/%s.w5 0x1400 0x1400' - % (fs_type, ADDR, MIN_FILE)) + '%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 = ubman.run_command_list([ - '%ssize host 0:0 /dir1/%s.w5' % (fs_type, MIN_FILE), + '%ssize host 0:0 /dir1/%s.w5' % (fs_cmd_prefix, MIN_FILE), 'printenv filesize', 'setenv filesize']) assert('filesize=2800' in ''.join(output)) @@ -150,7 +150,7 @@ class TestFsExt(object): # Test Case 5c - Check md5 of file content 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)) @@ -160,22 +160,22 @@ class TestFsExt(object): """ Test Case 6 - write nothing at the start, truncating to zero """ - fs_type,fs_img,md5val = fs_obj_ext + 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 = 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)]) + '%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( - '%swrite host 0:0 %x /dir1/%s.w6 0 0' - % (fs_type, ADDR, MIN_FILE)) + '%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 = ubman.run_command_list([ - '%ssize host 0:0 /dir1/%s.w6' % (fs_type, MIN_FILE), + '%ssize host 0:0 /dir1/%s.w6' % (fs_cmd_prefix, MIN_FILE), 'printenv filesize', 'setenv filesize']) assert('filesize=0' in ''.join(output)) @@ -185,22 +185,22 @@ class TestFsExt(object): """ Test Case 7 - write at the end (append) """ - fs_type,fs_img,md5val = fs_obj_ext + 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 = 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)]) + '%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( - '%swrite host 0:0 %x /dir1/%s.w7 $filesize $filesize' - % (fs_type, ADDR, MIN_FILE)) + '%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 = ubman.run_command_list([ - '%ssize host 0:0 /dir1/%s.w7' % (fs_type, MIN_FILE), + '%ssize host 0:0 /dir1/%s.w7' % (fs_cmd_prefix, MIN_FILE), 'printenv filesize', 'setenv filesize']) assert('filesize=a000' in ''.join(output)) @@ -208,7 +208,7 @@ class TestFsExt(object): # Test Case 7c - Check md5 of file content 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)) @@ -218,17 +218,17 @@ class TestFsExt(object): """ Test Case 8 - write at offset beyond the end of file """ - fs_type,fs_img,md5val = fs_obj_ext + 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 = 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)]) + '%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( - '%swrite host 0:0 %x /dir1/%s.w8 0x1400 %x' - % (fs_type, ADDR, MIN_FILE, 0x100000 + 0x1400)) + '%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) @@ -236,14 +236,14 @@ class TestFsExt(object): """ Test Case 9 - write to a non-existing file at non-zero offset """ - fs_type,fs_img,md5val = fs_obj_ext + 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 = 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) @@ -252,7 +252,7 @@ class TestFsExt(object): '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 + 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. @@ -262,9 +262,9 @@ class TestFsExt(object): for i in range(0, 66): output = ubman.run_command( - '%swrite host 0:0 %x /FILE0123456789_%02x 100' - % (fs_type, ADDR, i)) - output = ubman.run_command('%sls host 0:0 /' % fs_type) + '%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) @@ -272,8 +272,8 @@ class TestFsExt(object): for i in range(0, 66): output = ubman.run_command( '%srm host 0:0 /FILE0123456789_%02x' - % (fs_type, i)) - output = ubman.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) @@ -281,9 +281,9 @@ class TestFsExt(object): # Please note no.64 and 65 are intentionally re-created for i in range(64, 128): output = ubman.run_command( - '%swrite host 0:0 %x /FILE0123456789_%02x 100' - % (fs_type, ADDR, i)) - output = ubman.run_command('%sls host 0:0 /' % fs_type) + '%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) @@ -294,7 +294,7 @@ class TestFsExt(object): '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 + 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. @@ -304,9 +304,9 @@ class TestFsExt(object): for i in range(0, 66): output = ubman.run_command( - '%swrite host 0:0 %x /dir1/FILE0123456789_%02x 100' - % (fs_type, ADDR, i)) - output = ubman.run_command('%sls host 0:0 /dir1' % fs_type) + '%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) @@ -314,8 +314,8 @@ class TestFsExt(object): for i in range(0, 66): output = ubman.run_command( '%srm host 0:0 /dir1/FILE0123456789_%02x' - % (fs_type, i)) - output = ubman.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) @@ -323,9 +323,9 @@ class TestFsExt(object): # Please note no.64 and 65 are intentionally re-created for i in range(64, 128): output = ubman.run_command( - '%swrite host 0:0 %x /dir1/FILE0123456789_%02x 100' - % (fs_type, ADDR, i)) - output = ubman.run_command('%sls host 0:0 /dir1' % fs_type) + '%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) @@ -335,15 +335,15 @@ class TestFsExt(object): """ Test Case 12 - write plain and mangle file """ - fs_type,fs_img,md5val = fs_obj_ext + 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 = 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() -- cgit v1.2.3 From 8d0cc62a60b5b92a010f75fd61d9eb9cb8299567 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Mon, 17 Mar 2025 04:12:50 +0100 Subject: test_fs: Add exfat tests Add tests for the exfat filesystem. These tests are largely an extension of the FS_GENERIC tests with the following notable exceptions. The filesystem image for exfat tests is generated using combination of exfatprogs mkfs.exfat and python fattools. The fattols are capable of generating exfat filesystem images too, but this is not used, the fattools are only used as a replacement for dosfstools 'mcopy' and 'mdir', which are used to insert files and directories into existing fatfs images and list existing fatfs images respectively, without the need for superuser access to mount such images. The exfat filesystem has no filesystem specific command, there is only the generic filesystem command interface, therefore check_ubconfig() has to special case exfat and skip check for CONFIG_CMD_EXFAT and instead check for CONFIG_FS_EXFAT. Signed-off-by: Marek Vasut --- test/py/tests/test_fs/test_ext.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'test/py/tests/test_fs/test_ext.py') diff --git a/test/py/tests/test_fs/test_ext.py b/test/py/tests/test_fs/test_ext.py index a75cd74dade..41f126e7876 100644 --- a/test/py/tests/test_fs/test_ext.py +++ b/test/py/tests/test_fs/test_ext.py @@ -345,11 +345,19 @@ class TestFsExt(object): '%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) -- cgit v1.2.3