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 <sjg@chromium.org>
Link: https://lore.kernel.org/u-boot/CAFLszTgPa4aT_J9h9pqeTtLCVn4x2JvLWRcWRD8NaN3uoSAtyA@mail.gmail.com/
This commit is contained in:
Simon Glass
2025-02-09 09:07:14 -07:00
parent 00dfb7038e
commit 752c376987
105 changed files with 2676 additions and 2676 deletions

View File

@@ -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)

View File

@@ -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)