diff options
Diffstat (limited to 'test/py')
| -rw-r--r-- | test/py/conftest.py | 22 | ||||
| -rw-r--r-- | test/py/console_base.py | 25 | ||||
| -rw-r--r-- | test/py/pytest.ini | 1 | ||||
| -rw-r--r-- | test/py/requirements.txt | 1 | ||||
| -rw-r--r-- | test/py/tests/fs_helper.py | 10 | ||||
| -rw-r--r-- | test/py/tests/test_distro.py | 61 | ||||
| -rw-r--r-- | test/py/tests/test_fs/conftest.py | 44 | ||||
| -rw-r--r-- | test/py/tests/test_fs/fstest_helpers.py | 2 | ||||
| -rw-r--r-- | test/py/tests/test_fs/test_basic.py | 71 | ||||
| -rw-r--r-- | test/py/tests/test_fs/test_ext.py | 176 | ||||
| -rw-r--r-- | test/py/tests/test_fs/test_mkdir.py | 42 | ||||
| -rw-r--r-- | test/py/tests/test_fs/test_unlink.py | 38 | ||||
| -rw-r--r-- | test/py/tests/test_ut.py | 17 | 
13 files changed, 328 insertions, 182 deletions
| diff --git a/test/py/conftest.py b/test/py/conftest.py index e59897c1f78..5aea85647af 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -334,6 +334,7 @@ def pytest_configure(config):      ubconfig.dtb = build_dir + '/arch/sandbox/dts/test.dtb'      ubconfig.connection_ok = True      ubconfig.timing = config.getoption('timing') +    ubconfig.role = config.getoption('role')      env_vars = (          'board_type', @@ -760,6 +761,26 @@ def setup_singlethread(item):          if worker_id and worker_id != 'master':              pytest.skip('must run single-threaded') +def setup_role(item): +    """Process any 'role' marker for a test. + +    Skip this test if the role does not match. + +    Args: +        item (pytest.Item): The pytest test item +    """ +    required_roles = [] +    for roles in item.iter_markers('role'): +        role = roles.args[0] +        if role.startswith('!'): +            if ubconfig.role == role[1:]: +                pytest.skip(f'role "{ubconfig.role}" not supported') +                return +        else: +            required_roles.append(role) +    if required_roles and ubconfig.role not in required_roles: +        pytest.skip(f'board "{ubconfig.role}" not supported') +  def start_test_section(item):      anchors[item.name] = log.start_section(item.name) @@ -781,6 +802,7 @@ def pytest_runtest_setup(item):      setup_buildconfigspec(item)      setup_requiredtool(item)      setup_singlethread(item) +    setup_role(item)  def pytest_runtest_protocol(item, nextitem):      """pytest hook: Called to execute a test. diff --git a/test/py/console_base.py b/test/py/console_base.py index 260df773bac..88d444b44b8 100644 --- a/test/py/console_base.py +++ b/test/py/console_base.py @@ -370,21 +370,30 @@ class ConsoleBase(object):              output.append(self.run_command(cmd))          return output -    def ctrlc(self): -        """Send a CTRL-C character to U-Boot. +    def send(self, msg): +        """Send characters without waiting for echo, etc.""" +        self.run_command(msg, wait_for_prompt=False, wait_for_echo=False, +                         send_nl=False) + +    def ctrl(self, char): +        """Send a CTRL- character to U-Boot.          This is useful in order to stop execution of long-running synchronous          commands such as "ums".          Args: -            None. - -        Returns: -            Nothing. +            char (str): Character to send, e.g. 'C' to send Ctrl-C          """ +        self.log.action(f'Sending Ctrl-{char}') +        self.send(chr(ord(char) - ord('@'))) -        self.log.action('Sending Ctrl-C') -        self.run_command(chr(3), wait_for_echo=False, send_nl=False) +    def ctrlc(self): +        """Send a CTRL-C character to U-Boot. + +        This is useful in order to stop execution of long-running synchronous +        commands such as "ums". +        """ +        self.ctrl('C')      def wait_for(self, text):          """Wait for a pattern to be emitted by U-Boot. diff --git a/test/py/pytest.ini b/test/py/pytest.ini index 26d83f83e00..361be0178ee 100644 --- a/test/py/pytest.ini +++ b/test/py/pytest.ini @@ -12,3 +12,4 @@ markers =      requiredtool: U-Boot: Required host tools for a test.      slow: U-Boot: Specific test will run slowly.      singlethread: Cannot run in parallel +    role: U-Boot: Indicates the lab 'role' which can execute this test diff --git a/test/py/requirements.txt b/test/py/requirements.txt index acfe17dce9f..804a427b351 100644 --- a/test/py/requirements.txt +++ b/test/py/requirements.txt @@ -2,3 +2,4 @@ filelock==3.0.12  pycryptodomex==3.21.0  pytest==6.2.5  pytest-xdist==2.5.0 +FATtools==1.0.42 diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py index ccfc0201a49..9c459fccf97 100644 --- a/test/py/tests/fs_helper.py +++ b/test/py/tests/fs_helper.py @@ -35,7 +35,9 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000):      else:          mkfs_opt = '' -    if re.match('fat', fs_type): +    if fs_type == 'exfat': +        fs_lnxtype = 'exfat' +    elif re.match('fat', fs_type) or fs_type == 'fs_generic':          fs_lnxtype = 'vfat'      else:          fs_lnxtype = fs_type @@ -43,7 +45,7 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000):      if src_dir:          if fs_lnxtype == 'ext4':              mkfs_opt = mkfs_opt + ' -d ' + src_dir -        elif fs_lnxtype != 'vfat': +        elif fs_lnxtype != 'vfat' and fs_lnxtype != 'exfat':              raise ValueError(f'src_dir not implemented for fs {fs_lnxtype}')      count = (size + size_gran - 1) // size_gran @@ -54,7 +56,7 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000):      try:          check_call(f'rm -f {fs_img}', shell=True) -        check_call(f'dd if=/dev/zero of={fs_img} bs={size_gran} count={count}', +        check_call(f'truncate -s $(( {size_gran} * {count} )) {fs_img}',                     shell=True)          check_call(f'mkfs.{fs_lnxtype} {mkfs_opt} {fs_img}', shell=True)          if fs_type == 'ext4': @@ -64,6 +66,8 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000):                  check_call(f'tune2fs -O ^metadata_csum {fs_img}', shell=True)          elif fs_lnxtype == 'vfat' and src_dir:              check_call(f'mcopy -i {fs_img} -vsmpQ {src_dir}/* ::/', shell=True) +        elif fs_lnxtype == 'exfat' and src_dir: +            check_call(f'fattools cp {src_dir}/* {fs_img}', shell=True)          return fs_img      except CalledProcessError:          call(f'rm -f {fs_img}', shell=True) diff --git a/test/py/tests/test_distro.py b/test/py/tests/test_distro.py new file mode 100644 index 00000000000..bdf4ab657d1 --- /dev/null +++ b/test/py/tests/test_distro.py @@ -0,0 +1,61 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2025 Canonical Ltd. +# Written by Simon Glass <simon.glass@canonical.com> + +import pytest + +# Enable early console so that the test can see if something goes wrong +CONSOLE = 'earlycon=uart8250,io,0x3f8 console=uart8250,io,0x3f8' + +@pytest.mark.boardspec('qemu-x86_64') +@pytest.mark.role('qemu-x86_64') +def test_distro(ubman): +    """Test that of-platdata can be generated and used in sandbox""" +    with ubman.log.section('boot'): +        ubman.run_command('boot', wait_for_prompt=False) + +    with ubman.log.section('Grub'): +        # Wait for grub to come up and offset a menu +        ubman.p.expect(['Try or Install Ubuntu']) + +        # Press 'e' to edit the command line +        ubman.log.info("Pressing 'e'") +        ubman.run_command('e', wait_for_prompt=False, send_nl=False) + +        # Wait until we see the editor appear +        ubman.p.expect(['/casper/initrd']) + +        # Go down to the 'linux' line. Avoid using down-arrow as that includes +        # an Escape character, which may be parsed by Grub as such, causing it +        # to return to the top menu +        ubman.log.info("Going DOWN") +        ubman.ctrl('N') +        ubman.ctrl('N') +        ubman.ctrl('N') + +        # Go to end of line +        ubman.log.info("Going to EOL") +        ubman.ctrl('E') + +        # Backspace to remove 'quiet splash' +        ubman.log.info("Erasing quiet and splash") +        ubman.send('\b' * len('quiet splash')) + +        # Send our noisy console +        ubman.log.info("Noisy console") +        ubman.send(CONSOLE) + +        # Tell grub to boot +        ubman.log.info("boot") +        ubman.ctrl('X') +        ubman.p.expect(['Booting a command list']) + +    with ubman.log.section('Linux'): +        # Linux should start immediately +        ubman.p.expect(['Linux version']) + +    with ubman.log.section('Ubuntu'): +        # Shortly later, we should see this banner +        ubman.p.expect(['Welcome to .*Ubuntu 24.04.1 LTS.*!']) + +    ubman.restart_uboot() diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py index 47a584ffe7c..c73fb4abbcb 100644 --- a/test/py/tests/test_fs/conftest.py +++ b/test/py/tests/test_fs/conftest.py @@ -11,11 +11,11 @@ from fstest_defs import *  # 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'] @@ -108,6 +108,22 @@ def pytest_generate_tests(metafunc):  #  # 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 @@ -139,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()) @@ -178,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) @@ -267,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) @@ -288,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) @@ -357,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) @@ -378,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) @@ -390,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)  # @@ -409,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) @@ -456,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) diff --git a/test/py/tests/test_fs/fstest_helpers.py b/test/py/tests/test_fs/fstest_helpers.py index c1447b4d43e..d25326ee993 100644 --- a/test/py/tests/test_fs/fstest_helpers.py +++ b/test/py/tests/test_fs/fstest_helpers.py @@ -9,6 +9,8 @@ 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: diff --git a/test/py/tests/test_fs/test_basic.py b/test/py/tests/test_fs/test_basic.py index 5a02348bb94..64a3b50f52a 100644 --- a/test/py/tests/test_fs/test_basic.py +++ b/test/py/tests/test_fs/test_basic.py @@ -20,32 +20,32 @@ class TestFsBasic(object):          """          Test Case 1 - ls command, listing a root directory and invalid directory          """ -        fs_type,fs_img,md5val = fs_obj_basic +        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 = 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 ubman.log.section('Test Case 1b - ls (invalid dir)'):              # In addition, test with a nonexistent directory to see if we crash.              output = ubman.run_command( -                '%sls host 0:0 invalid_d' % fs_type) +                '%sls host 0:0 invalid_d' % fs_cmd_prefix)              assert('' == output)      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 +        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 = 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)) @@ -53,7 +53,7 @@ class TestFsBasic(object):          with ubman.log.section('Test Case 2b - size (/../<file>)'):              # Test Case 2b - size of small file via a path using '..'              output = ubman.run_command_list([ -                '%ssize host 0:0 /SUBDIR/../%s' % (fs_type, SMALL_FILE), +                '%ssize host 0:0 /SUBDIR/../%s' % (fs_cmd_prefix, SMALL_FILE),                  'printenv filesize',                  'setenv filesize'])              assert('filesize=100000' in ''.join(output)) @@ -62,13 +62,13 @@ class TestFsBasic(object):          """          Test Case 3 - size command for a large file          """ -        fs_type,fs_img,md5val = fs_obj_basic +        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 = 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)) @@ -77,12 +77,12 @@ class TestFsBasic(object):          """          Test Case 4 - load a small file, 1MB          """ -        fs_type,fs_img,md5val = fs_obj_basic +        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 = 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)) @@ -96,12 +96,12 @@ class TestFsBasic(object):          """          Test Case 5 - load, reading first 1MB of 3GB file          """ -        fs_type,fs_img,md5val = fs_obj_basic +        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 = 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)) @@ -115,14 +115,14 @@ class TestFsBasic(object):          """          Test Case 6 - load, reading last 1MB of 3GB file          """ -        fs_type,fs_img,md5val = fs_obj_basic +        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 = 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)) @@ -136,14 +136,14 @@ class TestFsBasic(object):          """          Test Case 7 - load, 1MB from the last 1MB in 2GB          """ -        fs_type,fs_img,md5val = fs_obj_basic +        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 = 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)) @@ -157,14 +157,14 @@ class TestFsBasic(object):          """          Test Case 8 - load, reading first 1MB in 2GB          """ -        fs_type,fs_img,md5val = fs_obj_basic +        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 = 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)) @@ -178,14 +178,14 @@ class TestFsBasic(object):          """          Test Case 9 - load, 1MB crossing 2GB boundary          """ -        fs_type,fs_img,md5val = fs_obj_basic +        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 = 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)) @@ -199,14 +199,14 @@ class TestFsBasic(object):          """          Test Case 10 - load, reading beyond file end'):          """ -        fs_type,fs_img,md5val = fs_obj_basic +        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 = 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']) @@ -216,22 +216,22 @@ class TestFsBasic(object):          """          Test Case 11 - write'          """ -        fs_type,fs_img,md5val = fs_obj_basic +        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 = 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 = ubman.run_command_list([ -                '%sload host 0:0 %x /%s.w' % (fs_type, ADDR, SMALL_FILE), +                '%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)) @@ -241,7 +241,7 @@ class TestFsBasic(object):          """          Test Case 12 - write to "." directory          """ -        fs_type,fs_img,md5val = fs_obj_basic +        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 "." @@ -249,7 +249,8 @@ class TestFsBasic(object):              # Test Case 12 - Check directory traversal              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) @@ -257,23 +258,23 @@ class TestFsBasic(object):          """          Test Case 13 - write to a file with "/./<filename>"          """ -        fs_type,fs_img,md5val = fs_obj_basic +        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 = 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 = 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)) @@ -282,7 +283,7 @@ class TestFsBasic(object):              # as the one read from              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_ext.py b/test/py/tests/test_fs/test_ext.py index 9c213f2da55..41f126e7876 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,21 +335,29 @@ 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() -            # 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_mkdir.py b/test/py/tests/test_fs/test_mkdir.py index df680a87d57..1578c3cba3a 100644 --- a/test/py/tests/test_fs/test_mkdir.py +++ b/test/py/tests/test_fs/test_mkdir.py @@ -18,16 +18,16 @@ class TestMkdir(object):          """          Test Case 1 - create a directory under a root          """ -        fs_type,fs_img = fs_obj_mkdir +        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 = ubman.run_command( -                '%sls host 0:0 dir1' % fs_type) +                '%sls host 0:0 dir1' % fs_cmd_prefix)              assert('./'   in output)              assert('../'  in output)              assert_fs_integrity(fs_type, fs_img) @@ -37,16 +37,16 @@ class TestMkdir(object):          """          Test Case 2 - create a directory under a sub-directory          """ -        fs_type,fs_img = fs_obj_mkdir +        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 = ubman.run_command( -                '%sls host 0:0 dir1/dir2' % fs_type) +                '%sls host 0:0 dir1/dir2' % fs_cmd_prefix)              assert('./'   in output)              assert('../'  in output)              assert_fs_integrity(fs_type, fs_img) @@ -56,11 +56,11 @@ class TestMkdir(object):          Test Case 3 - trying to create a directory with a non-existing          path should fail          """ -        fs_type,fs_img = fs_obj_mkdir +        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) @@ -68,11 +68,11 @@ class TestMkdir(object):          """          Test Case 4 - trying to create "." should fail          """ -        fs_type,fs_img = fs_obj_mkdir +        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) @@ -80,11 +80,11 @@ class TestMkdir(object):          """          Test Case 5 - trying to create ".." should fail          """ -        fs_type,fs_img = fs_obj_mkdir +        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) @@ -93,29 +93,29 @@ class TestMkdir(object):          'Test Case 6 - create as many directories as amount of directory          entries goes beyond a cluster size)'          """ -        fs_type,fs_img = fs_obj_mkdir +        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 = ubman.run_command(                      '%smkdir host 0:0 dir6/0123456789abcdef%02x' -                    % (fs_type, i)) -            output = ubman.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 = ubman.run_command( -                '%sls host 0:0 dir6/0123456789abcdef13/.' % fs_type) +                '%sls host 0:0 dir6/0123456789abcdef13/.' % fs_cmd_prefix)              assert('./'   in output)              assert('../'  in output)              output = ubman.run_command( -                '%sls host 0:0 dir6/0123456789abcdef13/..' % fs_type) +                '%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_unlink.py b/test/py/tests/test_fs/test_unlink.py index 7e911f02413..1e2df3dbfd8 100644 --- a/test/py/tests/test_fs/test_unlink.py +++ b/test/py/tests/test_fs/test_unlink.py @@ -19,16 +19,16 @@ class TestUnlink(object):          """          Test Case 1 - delete a file          """ -        fs_type,fs_img = fs_obj_unlink +        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 = ubman.run_command( -                '%sls host 0:0 dir1/' % fs_type) +                '%sls host 0:0 dir1/' % fs_cmd_prefix)              assert(not 'file1' in output)              assert('file2' in output)              assert_fs_integrity(fs_type, fs_img) @@ -37,18 +37,18 @@ class TestUnlink(object):          """          Test Case 2 - delete many files          """ -        fs_type,fs_img = fs_obj_unlink +        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 = ubman.run_command_list([ -                    '%srm host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i), -                    '%sls host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i)]) +                    '%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 = ubman.run_command( -                '%sls host 0:0 dir2' % fs_type) +                '%sls host 0:0 dir2' % fs_cmd_prefix)              assert('0 file(s), 2 dir(s)' in output)              assert_fs_integrity(fs_type, fs_img) @@ -56,11 +56,11 @@ class TestUnlink(object):          """          Test Case 3 - trying to delete a non-existing file should fail          """ -        fs_type,fs_img = fs_obj_unlink +        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) @@ -68,15 +68,15 @@ class TestUnlink(object):          """          Test Case 4 - delete an empty directory          """ -        fs_type,fs_img = fs_obj_unlink +        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 = ubman.run_command( -                '%sls host 0:0 /' % fs_type) +                '%sls host 0:0 /' % fs_cmd_prefix)              assert(not 'dir4' in output)              assert_fs_integrity(fs_type, fs_img) @@ -85,11 +85,11 @@ class TestUnlink(object):          Test Case 5 - trying to deleting a non-empty directory ".."          should fail          """ -        fs_type,fs_img = fs_obj_unlink +        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) @@ -97,11 +97,11 @@ class TestUnlink(object):          """          Test Case 6 - trying to deleting a "." should fail          """ -        fs_type,fs_img = fs_obj_unlink +        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) @@ -109,10 +109,10 @@ class TestUnlink(object):          """          Test Case 7 - trying to deleting a ".." should fail          """ -        fs_type,fs_img = fs_obj_unlink +        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) diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index ea0c43cd4fc..b8adb597e11 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -57,6 +57,17 @@ def setup_image(ubman, devnum, part_type, img_size=20, second_part=False,                               stdin=spec.encode('utf-8'))      return fname, mnt +def copy_partition(ubman, fsfile, outname): +    """Copy a partition into a disk iamge + +    Args: +        ubman (ConsoleBase): U-Boot fixture +        fsfile (str): Name of partition file +        outname (str): Name of full-disk file to update +    """ +    utils.run_and_log(ubman, +                      f'dd if={fsfile} of={outname} bs=1M seek=1 conv=notrunc') +  def setup_bootmenu_image(ubman):      """Create a 20MB disk image with a single ext4 partition @@ -172,7 +183,7 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}      fsfile = 'ext18M.img'      utils.run_and_log(ubman, f'fallocate -l 18M {fsfile}')      utils.run_and_log(ubman, f'mkfs.ext4 {fsfile} -d {mnt}') -    utils.run_and_log(ubman, f'dd if={fsfile} of={fname} bs=1M seek=1') +    copy_partition(ubman, fsfile, fname)      utils.run_and_log(ubman, f'rm -rf {mnt}')      utils.run_and_log(ubman, f'rm -f {fsfile}') @@ -224,7 +235,7 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)      utils.run_and_log(ubman, f'fallocate -l 18M {fsfile}')      utils.run_and_log(ubman, f'mkfs.vfat {fsfile}')      utils.run_and_log(ubman, ['sh', '-c', f'mcopy -i {fsfile} {mnt}/* ::/']) -    utils.run_and_log(ubman, f'dd if={fsfile} of={fname} bs=1M seek=1') +    copy_partition(ubman, fsfile, fname)      utils.run_and_log(ubman, f'rm -rf {mnt}')      utils.run_and_log(ubman, f'rm -f {fsfile}') @@ -562,7 +573,7 @@ def setup_efi_image(ubman):      utils.run_and_log(ubman, f'fallocate -l 18M {fsfile}')      utils.run_and_log(ubman, f'mkfs.vfat {fsfile}')      utils.run_and_log(ubman, ['sh', '-c', f'mcopy -vs -i {fsfile} {mnt}/* ::/']) -    utils.run_and_log(ubman, f'dd if={fsfile} of={fname} bs=1M seek=1') +    copy_partition(ubman, fsfile, fname)      utils.run_and_log(ubman, f'rm -rf {mnt}')      utils.run_and_log(ubman, f'rm -f {fsfile}') | 
