diff options
author | Tom Rini <trini@konsulko.com> | 2019-04-10 08:18:18 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2019-04-10 08:18:18 -0400 |
commit | 48ff1bc4f0a97c3291d0c87c2717fc1d79da5ef5 (patch) | |
tree | 52c7f1f8b5f402e48fffbf4cc823da0f9f4d980c /test/py/tests | |
parent | 4c24dab391003b99b1e0784fd41fe756cb07039e (diff) | |
parent | 0a8406602ae5f234f3f670ab59628673cc52ff4d (diff) |
Merge branch '2019-04-09-master-imports-fs'
- test.py tests for mmc
- ext4 symlink support and other fixes
- ext4 block group descriptor sizing
Diffstat (limited to 'test/py/tests')
-rw-r--r-- | test/py/tests/test_fs/conftest.py | 77 | ||||
-rw-r--r-- | test/py/tests/test_fs/fstest_defs.py | 3 | ||||
-rw-r--r-- | test/py/tests/test_fs/fstest_helpers.py | 13 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_basic.py | 4 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_ext.py | 10 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_mkdir.py | 8 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_symlink.py | 130 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_unlink.py | 14 | ||||
-rw-r--r-- | test/py/tests/test_mmc_rd.py | 133 |
9 files changed, 378 insertions, 14 deletions
diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py index 43eeb4be0b..9324657d21 100644 --- a/test/py/tests/test_fs/conftest.py +++ b/test/py/tests/test_fs/conftest.py @@ -13,6 +13,7 @@ supported_fs_basic = ['fat16', 'fat32', 'ext4'] supported_fs_ext = ['fat16', 'fat32'] supported_fs_mkdir = ['fat16', 'fat32'] supported_fs_unlink = ['fat16', 'fat32'] +supported_fs_symlink = ['ext4'] # # Filesystem test specific setup @@ -48,6 +49,7 @@ def pytest_configure(config): global supported_fs_ext global supported_fs_mkdir global supported_fs_unlink + global supported_fs_symlink def intersect(listA, listB): return [x for x in listA if x in listB] @@ -59,6 +61,7 @@ def pytest_configure(config): supported_fs_ext = intersect(supported_fs, supported_fs_ext) supported_fs_mkdir = intersect(supported_fs, supported_fs_mkdir) supported_fs_unlink = intersect(supported_fs, supported_fs_unlink) + supported_fs_symlink = intersect(supported_fs, supported_fs_symlink) def pytest_generate_tests(metafunc): """Parametrize fixtures, fs_obj_xxx @@ -84,6 +87,9 @@ def pytest_generate_tests(metafunc): if 'fs_obj_unlink' in metafunc.fixturenames: metafunc.parametrize('fs_obj_unlink', supported_fs_unlink, indirect=True, scope='module') + if 'fs_obj_symlink' in metafunc.fixturenames: + metafunc.parametrize('fs_obj_symlink', supported_fs_symlink, + indirect=True, scope='module') # # Helper functions @@ -143,6 +149,8 @@ def mk_fs(config, fs_type, size, id): mkfs_opt = '-F 16' elif fs_type == 'fat32': mkfs_opt = '-F 32' + elif fs_type == 'ext4': + mkfs_opt = '-O ^metadata_csum' else: mkfs_opt = '' @@ -523,3 +531,72 @@ def fs_obj_unlink(request, u_boot_config): call('rmdir %s' % mount_dir, shell=True) if fs_img: call('rm -f %s' % fs_img, shell=True) + +# +# Fixture for symlink fs test +# +# NOTE: yield_fixture was deprecated since pytest-3.0 +@pytest.yield_fixture() +def fs_obj_symlink(request, u_boot_config): + """Set up a file system to be used in symlink fs test. + + Args: + request: Pytest request object. + u_boot_config: U-boot configuration. + + Return: + A fixture for basic fs test, i.e. a triplet of file system type, + volume file name and a list of MD5 hashes. + """ + fs_type = request.param + fs_img = '' + + fs_ubtype = fstype_to_ubname(fs_type) + check_ubconfig(u_boot_config, fs_ubtype) + + mount_dir = u_boot_config.persistent_data_dir + '/mnt' + + small_file = mount_dir + '/' + SMALL_FILE + medium_file = mount_dir + '/' + MEDIUM_FILE + + try: + + # 3GiB volume + fs_img = mk_fs(u_boot_config, fs_type, 0x40000000, '1GB') + + # Mount the image so we can populate it. + check_call('mkdir -p %s' % mount_dir, shell=True) + mount_fs(fs_type, fs_img, mount_dir) + + # Create a subdirectory. + check_call('mkdir %s/SUBDIR' % mount_dir, shell=True) + + # Create a small file in this image. + check_call('dd if=/dev/urandom of=%s bs=1M count=1' + % small_file, shell=True) + + # Create a medium file in this image. + check_call('dd if=/dev/urandom of=%s bs=10M count=1' + % medium_file, shell=True) + + # Generate the md5sums of reads that we will test against small file + out = check_output( + 'dd if=%s bs=1M skip=0 count=1 2> /dev/null | md5sum' + % small_file, shell=True) + md5val = [out.split()[0]] + out = check_output( + 'dd if=%s bs=10M skip=0 count=1 2> /dev/null | md5sum' + % medium_file, shell=True) + md5val.extend([out.split()[0]]) + + umount_fs(mount_dir) + except CalledProcessError: + pytest.skip('Setup failed for filesystem: ' + fs_type) + return + else: + yield [fs_ubtype, fs_img, md5val] + finally: + umount_fs(mount_dir) + call('rmdir %s' % mount_dir, shell=True) + if fs_img: + call('rm -f %s' % fs_img, shell=True) diff --git a/test/py/tests/test_fs/fstest_defs.py b/test/py/tests/test_fs/fstest_defs.py index 5f107562d9..35b2bb6518 100644 --- a/test/py/tests/test_fs/fstest_defs.py +++ b/test/py/tests/test_fs/fstest_defs.py @@ -6,6 +6,9 @@ MIN_FILE='testfile' # $SMALL_FILE is the name of the 1MB file in the file system image SMALL_FILE='1MB.file' +# $MEDIUM_FILE is the name of the 10MB file in the file system image +MEDIUM_FILE='10MB.file' + # $BIG_FILE is the name of the 2.5GB file in the file system image BIG_FILE='2.5GB.file' diff --git a/test/py/tests/test_fs/fstest_helpers.py b/test/py/tests/test_fs/fstest_helpers.py new file mode 100644 index 0000000000..faec298248 --- /dev/null +++ b/test/py/tests/test_fs/fstest_helpers.py @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2019, Texas Instrument +# Author: JJ Hiblot <jjhiblot@ti.com> +# + +from subprocess import check_call, CalledProcessError + +def assert_fs_integrity(fs_type, fs_img): + try: + if fs_type == 'ext4': + check_call('fsck.ext4 -n -f %s' % fs_img, shell=True) + except CalledProcessError: + raise diff --git a/test/py/tests/test_fs/test_basic.py b/test/py/tests/test_fs/test_basic.py index 140ca29ac7..71f3e86fb1 100644 --- a/test/py/tests/test_fs/test_basic.py +++ b/test/py/tests/test_fs/test_basic.py @@ -11,6 +11,7 @@ This test verifies basic read/write operation on file system. import pytest import re from fstest_defs import * +from fstest_helpers import assert_fs_integrity @pytest.mark.boardspec('sandbox') @pytest.mark.slow @@ -237,6 +238,7 @@ class TestFsBasic(object): 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[0] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) def test_fs12(self, u_boot_console, fs_obj_basic): """ @@ -252,6 +254,7 @@ class TestFsBasic(object): 'host bind 0 %s' % fs_img, '%swrite host 0:0 %x /. 0x10' % (fs_type, ADDR)]) assert('Unable to write' in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) def test_fs13(self, u_boot_console, fs_obj_basic): """ @@ -286,3 +289,4 @@ class TestFsBasic(object): 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[0] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) diff --git a/test/py/tests/test_fs/test_ext.py b/test/py/tests/test_fs/test_ext.py index 06cad5516d..2c47738b8d 100644 --- a/test/py/tests/test_fs/test_ext.py +++ b/test/py/tests/test_fs/test_ext.py @@ -11,6 +11,7 @@ This test verifies extended write operation on file system. import pytest import re from fstest_defs import * +from fstest_helpers import assert_fs_integrity @pytest.mark.boardspec('sandbox') @pytest.mark.slow @@ -36,6 +37,7 @@ class TestFsExt(object): 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[0] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) def test_fs_ext2(self, u_boot_console, fs_obj_ext): """ @@ -58,6 +60,7 @@ class TestFsExt(object): 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[0] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) def test_fs_ext3(self, u_boot_console, fs_obj_ext): """ @@ -72,6 +75,7 @@ class TestFsExt(object): '%swrite host 0:0 %x /dir1/none/%s.w3 $filesize' % (fs_type, ADDR, MIN_FILE)]) assert('Unable to write "/dir1/none/' in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) def test_fs_ext4(self, u_boot_console, fs_obj_ext): """ @@ -104,6 +108,7 @@ class TestFsExt(object): 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[1] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) def test_fs_ext5(self, u_boot_console, fs_obj_ext): """ @@ -136,6 +141,7 @@ class TestFsExt(object): 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[2] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) def test_fs_ext6(self, u_boot_console, fs_obj_ext): """ @@ -160,6 +166,7 @@ class TestFsExt(object): '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): """ @@ -192,6 +199,7 @@ class TestFsExt(object): 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[3] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) def test_fs_ext8(self, u_boot_console, fs_obj_ext): """ @@ -209,6 +217,7 @@ class TestFsExt(object): '%swrite host 0:0 %x /dir1/%s.w8 0x1400 %x' % (fs_type, ADDR, MIN_FILE, 0x100000 + 0x1400)) assert('Unable to write "/dir1' in output) + assert_fs_integrity(fs_type, fs_img) def test_fs_ext9(self, u_boot_console, fs_obj_ext): """ @@ -223,3 +232,4 @@ class TestFsExt(object): '%swrite host 0:0 %x /dir1/%s.w9 0x1400 0x1400' % (fs_type, ADDR, MIN_FILE)]) assert('Unable to write "/dir1' in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) diff --git a/test/py/tests/test_fs/test_mkdir.py b/test/py/tests/test_fs/test_mkdir.py index b3fe11cf3b..fa9561ec35 100644 --- a/test/py/tests/test_fs/test_mkdir.py +++ b/test/py/tests/test_fs/test_mkdir.py @@ -9,6 +9,7 @@ This test verifies mkdir operation on file system. """ import pytest +from fstest_helpers import assert_fs_integrity @pytest.mark.boardspec('sandbox') @pytest.mark.slow @@ -29,6 +30,8 @@ class TestMkdir(object): '%sls host 0:0 dir1' % fs_type) assert('./' in output) assert('../' in output) + assert_fs_integrity(fs_type, fs_img) + def test_mkdir2(self, u_boot_console, fs_obj_mkdir): """ @@ -46,6 +49,7 @@ class TestMkdir(object): '%sls host 0:0 dir1/dir2' % fs_type) assert('./' in output) assert('../' in output) + assert_fs_integrity(fs_type, fs_img) def test_mkdir3(self, u_boot_console, fs_obj_mkdir): """ @@ -58,6 +62,7 @@ class TestMkdir(object): 'host bind 0 %s' % fs_img, '%smkdir host 0:0 none/dir3' % fs_type]) assert('Unable to create a directory' in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) def test_mkdir4(self, u_boot_console, fs_obj_mkdir): """ @@ -69,6 +74,7 @@ class TestMkdir(object): 'host bind 0 %s' % fs_img, '%smkdir host 0:0 .' % fs_type]) assert('Unable to create a directory' in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) def test_mkdir5(self, u_boot_console, fs_obj_mkdir): """ @@ -80,6 +86,7 @@ class TestMkdir(object): 'host bind 0 %s' % fs_img, '%smkdir host 0:0 ..' % fs_type]) assert('Unable to create a directory' in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) def test_mkdir6(self, u_boot_console, fs_obj_mkdir): """ @@ -111,3 +118,4 @@ class TestMkdir(object): '%sls host 0:0 dir6/0123456789abcdef13/..' % fs_type) assert('0123456789abcdef00/' in output) assert('0123456789abcdef13/' in output) + assert_fs_integrity(fs_type, fs_img) diff --git a/test/py/tests/test_fs/test_symlink.py b/test/py/tests/test_fs/test_symlink.py new file mode 100644 index 0000000000..9ced101a29 --- /dev/null +++ b/test/py/tests/test_fs/test_symlink.py @@ -0,0 +1,130 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2019, Texas Instrument +# Author: Jean-Jacques Hiblot <jjhiblot@ti.com> +# +# U-Boot File System:symlink Test + +""" +This test verifies unlink operation (deleting a file or a directory) +on file system. +""" + +import pytest +import re +from fstest_defs import * +from fstest_helpers import assert_fs_integrity + + +@pytest.mark.boardspec('sandbox') +@pytest.mark.slow +class TestSymlink(object): + def test_symlink1(self, u_boot_console, fs_obj_symlink): + """ + Test Case 1 - create a link. and follow it when reading + """ + fs_type, fs_img, md5val = fs_obj_symlink + with u_boot_console.log.section('Test Case 1 - create link and read'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + 'setenv filesize', + 'ln host 0:0 %s /%s.link ' % (SMALL_FILE, SMALL_FILE), + ]) + assert('' in ''.join(output)) + + output = u_boot_console.run_command_list([ + '%sload host 0:0 %x /%s.link' % (fs_type, ADDR, SMALL_FILE), + 'printenv filesize']) + assert('filesize=100000' in ''.join(output)) + + # Test Case 4b - Read full 1MB of small file + output = u_boot_console.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[0] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) + + def test_symlink2(self, u_boot_console, fs_obj_symlink): + """ + Test Case 2 - create chained links + """ + fs_type, fs_img, md5val = fs_obj_symlink + with u_boot_console.log.section('Test Case 2 - create chained links'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + 'setenv filesize', + 'ln host 0:0 %s /%s.link1 ' % (SMALL_FILE, SMALL_FILE), + 'ln host 0:0 /%s.link1 /SUBDIR/%s.link2' % ( + SMALL_FILE, SMALL_FILE), + 'ln host 0:0 SUBDIR/%s.link2 /%s.link3' % ( + SMALL_FILE, SMALL_FILE), + ]) + assert('' in ''.join(output)) + + output = u_boot_console.run_command_list([ + '%sload host 0:0 %x /%s.link3' % (fs_type, ADDR, SMALL_FILE), + 'printenv filesize']) + assert('filesize=100000' in ''.join(output)) + + # Test Case 4b - Read full 1MB of small file + output = u_boot_console.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[0] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) + + def test_symlink3(self, u_boot_console, fs_obj_symlink): + """ + Test Case 3 - replace file/link with link + """ + fs_type, fs_img, md5val = fs_obj_symlink + with u_boot_console.log.section('Test Case 1 - create link and read'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + 'setenv filesize', + 'ln host 0:0 %s /%s ' % (MEDIUM_FILE, SMALL_FILE), + 'ln host 0:0 %s /%s.link ' % (MEDIUM_FILE, MEDIUM_FILE), + ]) + assert('' in ''.join(output)) + + output = u_boot_console.run_command_list([ + '%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE), + 'printenv filesize']) + assert('filesize=a00000' in ''.join(output)) + + output = u_boot_console.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[1] in ''.join(output)) + + output = u_boot_console.run_command_list([ + 'ln host 0:0 %s.link /%s ' % (MEDIUM_FILE, SMALL_FILE), + '%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE), + 'printenv filesize']) + assert('filesize=a00000' in ''.join(output)) + + output = u_boot_console.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[1] in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) + + def test_symlink4(self, u_boot_console, fs_obj_symlink): + """ + Test Case 4 - create a broken link + """ + fs_type, fs_img, md5val = fs_obj_symlink + with u_boot_console.log.section('Test Case 1 - create link and read'): + + output = u_boot_console.run_command_list([ + 'setenv filesize', + 'ln host 0:0 nowhere /link ', + ]) + assert('' in ''.join(output)) + + output = u_boot_console.run_command( + '%sload host 0:0 %x /link' % + (fs_type, ADDR)) + with u_boot_console.disable_check('error_notification'): + output = u_boot_console.run_command('printenv filesize') + assert('"filesize" not defined' in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) diff --git a/test/py/tests/test_fs/test_unlink.py b/test/py/tests/test_fs/test_unlink.py index 2b817468ed..97aafc63bb 100644 --- a/test/py/tests/test_fs/test_unlink.py +++ b/test/py/tests/test_fs/test_unlink.py @@ -10,6 +10,7 @@ on file system. """ import pytest +from fstest_helpers import assert_fs_integrity @pytest.mark.boardspec('sandbox') @pytest.mark.slow @@ -30,6 +31,7 @@ class TestUnlink(object): '%sls host 0:0 dir1/' % fs_type) assert(not 'file1' in output) assert('file2' in output) + assert_fs_integrity(fs_type, fs_img) def test_unlink2(self, u_boot_console, fs_obj_unlink): """ @@ -48,6 +50,7 @@ class TestUnlink(object): output = u_boot_console.run_command( '%sls host 0:0 dir2' % fs_type) assert('0 file(s), 2 dir(s)' in output) + assert_fs_integrity(fs_type, fs_img) def test_unlink3(self, u_boot_console, fs_obj_unlink): """ @@ -59,6 +62,7 @@ class TestUnlink(object): 'host bind 0 %s' % fs_img, '%srm host 0:0 dir1/nofile' % fs_type]) assert('nofile: doesn\'t exist' in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) def test_unlink4(self, u_boot_console, fs_obj_unlink): """ @@ -71,9 +75,10 @@ class TestUnlink(object): '%srm host 0:0 dir4' % fs_type]) assert('' == ''.join(output)) - output = u_boot_console.run_command( - '%sls host 0:0 /' % fs_type) - assert(not 'dir4' in output) + output = u_boot_console.run_command( + '%sls host 0:0 /' % fs_type) + assert(not 'dir4' in output) + assert_fs_integrity(fs_type, fs_img) def test_unlink5(self, u_boot_console, fs_obj_unlink): """ @@ -86,6 +91,7 @@ class TestUnlink(object): 'host bind 0 %s' % fs_img, '%srm host 0:0 dir5' % fs_type]) assert('directory is not empty' in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) def test_unlink6(self, u_boot_console, fs_obj_unlink): """ @@ -97,6 +103,7 @@ class TestUnlink(object): 'host bind 0 %s' % fs_img, '%srm host 0:0 dir5/.' % fs_type]) assert('directory is not empty' in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) def test_unlink7(self, u_boot_console, fs_obj_unlink): """ @@ -108,3 +115,4 @@ class TestUnlink(object): 'host bind 0 %s' % fs_img, '%srm host 0:0 dir5/..' % fs_type]) assert('directory is not empty' in ''.join(output)) + assert_fs_integrity(fs_type, fs_img) diff --git a/test/py/tests/test_mmc_rd.py b/test/py/tests/test_mmc_rd.py index a13bc0a5f6..2dc715bb51 100644 --- a/test/py/tests/test_mmc_rd.py +++ b/test/py/tests/test_mmc_rd.py @@ -6,6 +6,7 @@ # read if the test configuration contains a CRC of the expected data. import pytest +import time import u_boot_utils """ @@ -57,6 +58,116 @@ env__mmc_rd_configs = ( ) """ +def mmc_dev(u_boot_console, is_emmc, devid, partid): + """Run the "mmc dev" command. + + Args: + u_boot_console: A U-Boot console connection. + is_emmc: Whether the device is eMMC + devid: Device ID + partid: Partition ID + + Returns: + Nothing. + """ + + # Select MMC device + cmd = 'mmc dev %d' % devid + if is_emmc: + cmd += ' %d' % partid + response = u_boot_console.run_command(cmd) + assert 'no card present' not in response + if is_emmc: + partid_response = '(part %d)' % partid + else: + partid_response = '' + good_response = 'mmc%d%s is current device' % (devid, partid_response) + assert good_response in response + +@pytest.mark.buildconfigspec('cmd_mmc') +def test_mmc_dev(u_boot_console, env__mmc_rd_config): + """Test the "mmc dev" command. + + Args: + u_boot_console: A U-Boot console connection. + env__mmc_rd_config: The single MMC configuration on which + to run the test. See the file-level comment above for details + of the format. + + Returns: + Nothing. + """ + + is_emmc = env__mmc_rd_config['is_emmc'] + devid = env__mmc_rd_config['devid'] + partid = env__mmc_rd_config.get('partid', 0) + + # Select MMC device + mmc_dev(u_boot_console, is_emmc, devid, partid) + +@pytest.mark.buildconfigspec('cmd_mmc') +def test_mmc_rescan(u_boot_console, env__mmc_rd_config): + """Test the "mmc rescan" command. + + Args: + u_boot_console: A U-Boot console connection. + env__mmc_rd_config: The single MMC configuration on which + to run the test. See the file-level comment above for details + of the format. + + Returns: + Nothing. + """ + + is_emmc = env__mmc_rd_config['is_emmc'] + devid = env__mmc_rd_config['devid'] + partid = env__mmc_rd_config.get('partid', 0) + + # Select MMC device + mmc_dev(u_boot_console, is_emmc, devid, partid) + + # Rescan MMC device + cmd = 'mmc rescan' + response = u_boot_console.run_command(cmd) + assert 'no card present' not in response + +@pytest.mark.buildconfigspec('cmd_mmc') +def test_mmc_info(u_boot_console, env__mmc_rd_config): + """Test the "mmc info" command. + + Args: + u_boot_console: A U-Boot console connection. + env__mmc_rd_config: The single MMC configuration on which + to run the test. See the file-level comment above for details + of the format. + + Returns: + Nothing. + """ + + is_emmc = env__mmc_rd_config['is_emmc'] + devid = env__mmc_rd_config['devid'] + partid = env__mmc_rd_config.get('partid', 0) + info_device = env__mmc_rd_config['info_device'] + info_speed = env__mmc_rd_config['info_speed'] + info_mode = env__mmc_rd_config['info_mode'] + info_buswidth = env__mmc_rd_config['info_buswidth'] + + # Select MMC device + mmc_dev(u_boot_console, is_emmc, devid, partid) + + # Read MMC device information + cmd = 'mmc info' + response = u_boot_console.run_command(cmd) + good_response = "Device: %s" % info_device + assert good_response in response + good_response = "Bus Speed: %s" % info_speed + assert good_response in response + good_response = "Mode : %s" % info_mode + assert good_response in response + good_response = "Bus Width: %s" % info_buswidth + assert good_response in response + @pytest.mark.buildconfigspec('cmd_mmc') def test_mmc_rd(u_boot_console, env__mmc_rd_config): """Test the "mmc read" command. @@ -77,6 +188,7 @@ def test_mmc_rd(u_boot_console, env__mmc_rd_config): sector = env__mmc_rd_config.get('sector', 0) count_sectors = env__mmc_rd_config.get('count', 1) expected_crc32 = env__mmc_rd_config.get('crc32', None) + read_duration_max = env__mmc_rd_config.get('read_duration_max', 0) count_bytes = count_sectors * 512 bcfg = u_boot_console.config.buildconfig @@ -86,17 +198,7 @@ def test_mmc_rd(u_boot_console, env__mmc_rd_config): addr = '0x%08x' % ram_base # Select MMC device - cmd = 'mmc dev %d' % devid - if is_emmc: - cmd += ' %d' % partid - response = u_boot_console.run_command(cmd) - assert 'no card present' not in response - if is_emmc: - partid_response = '(part %d)' % partid - else: - partid_response = '' - good_response = 'mmc%d%s is current device' % (devid, partid_response) - assert good_response in response + mmc_dev(u_boot_console, is_emmc, devid, partid) # Clear target RAM if expected_crc32: @@ -113,7 +215,9 @@ def test_mmc_rd(u_boot_console, env__mmc_rd_config): # Read data cmd = 'mmc read %s %x %x' % (addr, sector, count_sectors) + tstart = time.time() response = u_boot_console.run_command(cmd) + tend = time.time() good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % ( devid, sector, count_sectors, count_sectors) assert good_response in response @@ -126,3 +230,10 @@ def test_mmc_rd(u_boot_console, env__mmc_rd_config): assert expected_crc32 in response else: u_boot_console.log.warning('CONFIG_CMD_CRC32 != y: Skipping check') + + # Check if the command did not take too long + if read_duration_max: + elapsed = tend - tstart + u_boot_console.log.info('Reading %d bytes took %f seconds' % + (count_bytes, elapsed)) + assert elapsed <= (read_duration_max - 0.01) |