test/py: mmc: Add support for different mmc modes

Currently, MMC test runs on default mmc modes, adding a provision to
support multiple mmc modes through user defined parameters.

Signed-off-by: Love Kumar <love.kumar@amd.com>
This commit is contained in:
Love Kumar 2024-11-12 14:27:56 +05:30 committed by Tom Rini
parent a730947974
commit b9e0048b6d

View file

@ -18,16 +18,55 @@ For example:
# Setup env__mmc_device_test_skip to not skipping the test. By default, its # Setup env__mmc_device_test_skip to not skipping the test. By default, its
# value is set to True. Set it to False to run all tests for MMC device. # value is set to True. Set it to False to run all tests for MMC device.
env__mmc_device_test_skip = False env__mmc_device_test_skip = False
# Setup env__mmc_device to set the supported mmc modes to be tested
env__mmc_device {
'mmc_modes': ['MMC_LEGACY', 'SD_HS'],
}
""" """
mmc_set_up = False mmc_set_up = False
controllers = 0 controllers = 0
devices = {} devices = {}
mmc_modes_name = []
mmc_modes = []
def setup_mmc_modes(cons):
global mmc_modes, mmc_modes_name
f = cons.config.env.get('env__mmc_device', None)
if f:
mmc_modes_name = f.get('mmc_modes', None)
# Set mmc mode to default mode (legacy), if speed mode config isn't enabled
if cons.config.buildconfig.get('config_mmc_speed_mode_set', 'n') != 'y':
mmc_modes = [0]
return
if mmc_modes_name:
mmc_help = cons.run_command('mmc -help')
m = re.search(r"\[MMC_LEGACY(.*\n.+])", mmc_help)
modes = [
x.strip()
for x in m.group()
.replace('\n', '')
.replace('[', '')
.replace(']', '')
.split(',')
]
for mode in mmc_modes_name:
mmc_modes += [modes.index(mode)]
else:
# Set mmc mode to default mode (legacy), if it is not defined in env
mmc_modes = [0]
def setup_mmc(u_boot_console): def setup_mmc(u_boot_console):
if u_boot_console.config.env.get('env__mmc_device_test_skip', True): if u_boot_console.config.env.get('env__mmc_device_test_skip', True):
pytest.skip('MMC device test is not enabled') pytest.skip('MMC device test is not enabled')
setup_mmc_modes(u_boot_console)
@pytest.mark.buildconfigspec('cmd_mmc') @pytest.mark.buildconfigspec('cmd_mmc')
def test_mmc_list(u_boot_console): def test_mmc_list(u_boot_console):
setup_mmc(u_boot_console) setup_mmc(u_boot_console)
@ -58,21 +97,22 @@ def test_mmc_dev(u_boot_console):
fail = 0 fail = 0
for x in range(0, controllers): for x in range(0, controllers):
devices[x]['detected'] = 'yes' devices[x]['detected'] = 'yes'
output = u_boot_console.run_command('mmc dev %d' % x)
# Some sort of switch here for y in mmc_modes:
if 'Card did not respond to voltage select' in output: output = u_boot_console.run_command('mmc dev %d 0 %d' % x, y)
fail = 1
devices[x]['detected'] = 'no'
if 'no mmc device at slot' in output: if 'Card did not respond to voltage select' in output:
devices[x]['detected'] = 'no' fail = 1
devices[x]['detected'] = 'no'
if 'MMC: no card present' in output: if 'no mmc device at slot' in output:
devices[x]['detected'] = 'no' devices[x]['detected'] = 'no'
if fail: if 'MMC: no card present' in output:
pytest.fail('Card not present') devices[x]['detected'] = 'no'
if fail:
pytest.fail('Card not present')
@pytest.mark.buildconfigspec('cmd_mmc') @pytest.mark.buildconfigspec('cmd_mmc')
def test_mmcinfo(u_boot_console): def test_mmcinfo(u_boot_console):
@ -81,19 +121,22 @@ def test_mmcinfo(u_boot_console):
for x in range(0, controllers): for x in range(0, controllers):
if devices[x]['detected'] == 'yes': if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x) for y in mmc_modes:
output = u_boot_console.run_command('mmcinfo') u_boot_console.run_command('mmc dev %d 0 %d' % x, y)
if 'busy timeout' in output: output = u_boot_console.run_command('mmcinfo')
pytest.skip('No SD/MMC/eMMC device present') if 'busy timeout' in output:
pytest.skip('No SD/MMC/eMMC device present')
obj = re.search(r'Capacity: (\d+|\d+[\.]?\d)', output) assert mmc_modes_name[mmc_modes.index(y)] in output
try:
capacity = float(obj.groups()[0]) obj = re.search(r'Capacity: (\d+|\d+[\.]?\d)', output)
print(capacity) try:
devices[x]['capacity'] = capacity capacity = float(obj.groups()[0])
print('Capacity of dev %d is: %g GiB' % (x, capacity)) print(capacity)
except ValueError: devices[x]['capacity'] = capacity
pytest.fail('MMC capacity not recognized') print('Capacity of dev %d is: %g GiB' % (x, capacity))
except ValueError:
pytest.fail('MMC capacity not recognized')
@pytest.mark.buildconfigspec('cmd_mmc') @pytest.mark.buildconfigspec('cmd_mmc')
def test_mmc_info(u_boot_console): def test_mmc_info(u_boot_console):
@ -102,19 +145,21 @@ def test_mmc_info(u_boot_console):
for x in range(0, controllers): for x in range(0, controllers):
if devices[x]['detected'] == 'yes': if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x) for y in mmc_modes:
u_boot_console.run_command('mmc dev %d 0 %d' % x, y)
output = u_boot_console.run_command('mmc info') output = u_boot_console.run_command('mmc info')
assert mmc_modes_name[mmc_modes.index(y)] in output
obj = re.search(r'Capacity: (\d+|\d+[\.]?\d)', output) obj = re.search(r'Capacity: (\d+|\d+[\.]?\d)', output)
try: try:
capacity = float(obj.groups()[0]) capacity = float(obj.groups()[0])
print(capacity) print(capacity)
if devices[x]['capacity'] != capacity: if devices[x]['capacity'] != capacity:
pytest.fail("MMC capacity doesn't match mmcinfo") pytest.fail("MMC capacity doesn't match mmcinfo")
except ValueError: except ValueError:
pytest.fail('MMC capacity not recognized') pytest.fail('MMC capacity not recognized')
@pytest.mark.buildconfigspec('cmd_mmc') @pytest.mark.buildconfigspec('cmd_mmc')
def test_mmc_rescan(u_boot_console): def test_mmc_rescan(u_boot_console):
@ -126,12 +171,13 @@ def test_mmc_rescan(u_boot_console):
for x in range(0, controllers): for x in range(0, controllers):
if devices[x]['detected'] == 'yes': if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x) for y in mmc_modes:
output = u_boot_console.run_command('mmc rescan') u_boot_console.run_command('mmc dev %d 0 %d' % x, y)
if output: output = u_boot_console.run_command('mmc rescan')
pytest.fail('mmc rescan has something to check') if output:
output = u_boot_console.run_command('echo $?') pytest.fail('mmc rescan has something to check')
assert output.endswith('0') output = u_boot_console.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_mmc') @pytest.mark.buildconfigspec('cmd_mmc')
def test_mmc_part(u_boot_console): def test_mmc_part(u_boot_console):
@ -192,7 +238,6 @@ def test_mmc_fatls_fatinfo(u_boot_console):
fs = 'fat' fs = 'fat'
for x in range(0, controllers): for x in range(0, controllers):
if devices[x]['detected'] == 'yes': if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
try: try:
partitions = devices[x][fs] partitions = devices[x][fs]
except: except:
@ -200,20 +245,22 @@ def test_mmc_fatls_fatinfo(u_boot_console):
continue continue
for part in partitions: for part in partitions:
output = u_boot_console.run_command( for y in mmc_modes:
'fatls mmc %d:%s' % (x, part)) u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
if 'Unrecognized filesystem type' in output: output = u_boot_console.run_command(
partitions.remove(part) 'fatls mmc %d:%s' % (x, part))
pytest.fail('Unrecognized filesystem') if 'Unrecognized filesystem type' in output:
partitions.remove(part)
pytest.fail('Unrecognized filesystem')
if not re.search(r'\d file\(s\), \d dir\(s\)', output): if not re.search(r'\d file\(s\), \d dir\(s\)', output):
pytest.fail('%s read failed on device %d' % (fs.upper, x)) pytest.fail('%s read failed on device %d' % (fs.upper, x))
output = u_boot_console.run_command( output = u_boot_console.run_command(
'fatinfo mmc %d:%s' % (x, part)) 'fatinfo mmc %d:%s' % (x, part))
string = 'Filesystem: %s' % fs.upper string = 'Filesystem: %s' % fs.upper
if re.search(string, output): if re.search(string, output):
pytest.fail('%s FS failed on device %d' % (fs.upper(), x)) pytest.fail('%s FS failed on device %d' % (fs.upper(), x))
part_detect = 1 part_detect = 1
if not part_detect: if not part_detect:
pytest.skip('No %s partition detected' % fs.upper()) pytest.skip('No %s partition detected' % fs.upper())
@ -233,7 +280,6 @@ def test_mmc_fatload_fatwrite(u_boot_console):
fs = 'fat' fs = 'fat'
for x in range(0, controllers): for x in range(0, controllers):
if devices[x]['detected'] == 'yes': if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
try: try:
partitions = devices[x][fs] partitions = devices[x][fs]
except: except:
@ -241,49 +287,51 @@ def test_mmc_fatload_fatwrite(u_boot_console):
continue continue
for part in partitions: for part in partitions:
part_detect = 1 for y in mmc_modes:
addr = u_boot_utils.find_ram_base(u_boot_console) u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
devices[x]['addr_%d' % part] = addr part_detect = 1
size = random.randint(4, 1 * 1024 * 1024) addr = u_boot_utils.find_ram_base(u_boot_console)
devices[x]['size_%d' % part] = size devices[x]['addr_%d' % part] = addr
# count CRC32 size = random.randint(4, 1 * 1024 * 1024)
output = u_boot_console.run_command('crc32 %x %x' % (addr, size)) devices[x]['size_%d' % part] = size
m = re.search('==> (.+?)', output) # count CRC32
if not m: output = u_boot_console.run_command('crc32 %x %x' % (addr, size))
pytest.fail('CRC32 failed') m = re.search('==> (.+?)', output)
expected_crc32 = m.group(1) if not m:
devices[x]['expected_crc32_%d' % part] = expected_crc32 pytest.fail('CRC32 failed')
# do write expected_crc32 = m.group(1)
file = '%s_%d' % ('uboot_test', size) devices[x]['expected_crc32_%d' % part] = expected_crc32
devices[x]['file_%d' % part] = file # do write
output = u_boot_console.run_command( file = '%s_%d' % ('uboot_test', size)
'%swrite mmc %d:%s %x %s %x' % (fs, x, part, addr, file, size) devices[x]['file_%d' % part] = file
) output = u_boot_console.run_command(
assert 'Unable to write' not in output '%swrite mmc %d:%s %x %s %x' % (fs, x, part, addr, file, size)
assert 'Error' not in output
assert 'overflow' not in output
expected_text = '%d bytes written' % size
assert expected_text in output
alignment = int(
u_boot_console.config.buildconfig.get(
'config_sys_cacheline_size', 128
) )
) assert 'Unable to write' not in output
offset = random.randrange(alignment, 1024, alignment) assert 'Error' not in output
output = u_boot_console.run_command( assert 'overflow' not in output
'%sload mmc %d:%s %x %s' % (fs, x, part, addr + offset, file) expected_text = '%d bytes written' % size
) assert expected_text in output
assert 'Invalid FAT entry' not in output
assert 'Unable to read file' not in output
assert 'Misaligned buffer address' not in output
expected_text = '%d bytes read' % size
assert expected_text in output
output = u_boot_console.run_command( alignment = int(
'crc32 %x $filesize' % (addr + offset) u_boot_console.config.buildconfig.get(
) 'config_sys_cacheline_size', 128
assert expected_crc32 in output )
)
offset = random.randrange(alignment, 1024, alignment)
output = u_boot_console.run_command(
'%sload mmc %d:%s %x %s' % (fs, x, part, addr + offset, file)
)
assert 'Invalid FAT entry' not in output
assert 'Unable to read file' not in output
assert 'Misaligned buffer address' not in output
expected_text = '%d bytes read' % size
assert expected_text in output
output = u_boot_console.run_command(
'crc32 %x $filesize' % (addr + offset)
)
assert expected_crc32 in output
if not part_detect: if not part_detect:
pytest.skip('No %s partition detected' % fs.upper()) pytest.skip('No %s partition detected' % fs.upper())
@ -307,13 +355,16 @@ def test_mmc_ext4ls(u_boot_console):
print('No %s table on this device' % fs.upper()) print('No %s table on this device' % fs.upper())
continue continue
u_boot_console.run_command('mmc dev %d' % x)
for part in partitions: for part in partitions:
output = u_boot_console.run_command('%sls mmc %d:%s' % (fs, x, part)) for y in mmc_modes:
if 'Unrecognized filesystem type' in output: u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
partitions.remove(part) output = u_boot_console.run_command(
pytest.fail('Unrecognized filesystem') '%sls mmc %d:%s' % (fs, x, part)
part_detect = 1 )
if 'Unrecognized filesystem type' in output:
partitions.remove(part)
pytest.fail('Unrecognized filesystem')
part_detect = 1
if not part_detect: if not part_detect:
pytest.skip('No %s partition detected' % fs.upper()) pytest.skip('No %s partition detected' % fs.upper())
@ -333,7 +384,6 @@ def test_mmc_ext4load_ext4write(u_boot_console):
fs = 'ext4' fs = 'ext4'
for x in range(0, controllers): for x in range(0, controllers):
if devices[x]['detected'] == 'yes': if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
try: try:
partitions = devices[x][fs] partitions = devices[x][fs]
except: except:
@ -341,42 +391,44 @@ def test_mmc_ext4load_ext4write(u_boot_console):
continue continue
for part in partitions: for part in partitions:
part_detect = 1 for y in mmc_modes:
addr = u_boot_utils.find_ram_base(u_boot_console) u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
devices[x]['addr_%d' % part] = addr part_detect = 1
size = random.randint(4, 1 * 1024 * 1024) addr = u_boot_utils.find_ram_base(u_boot_console)
devices[x]['size_%d' % part] = size devices[x]['addr_%d' % part] = addr
# count CRC32 size = random.randint(4, 1 * 1024 * 1024)
output = u_boot_console.run_command('crc32 %x %x' % (addr, size)) devices[x]['size_%d' % part] = size
m = re.search('==> (.+?)', output) # count CRC32
if not m: output = u_boot_console.run_command('crc32 %x %x' % (addr, size))
pytest.fail('CRC32 failed') m = re.search('==> (.+?)', output)
expected_crc32 = m.group(1) if not m:
devices[x]['expected_crc32_%d' % part] = expected_crc32 pytest.fail('CRC32 failed')
# do write expected_crc32 = m.group(1)
devices[x]['expected_crc32_%d' % part] = expected_crc32
file = '%s_%d' % ('uboot_test', size) # do write
devices[x]['file_%d' % part] = file file = '%s_%d' % ('uboot_test', size)
output = u_boot_console.run_command( devices[x]['file_%d' % part] = file
'%swrite mmc %d:%s %x /%s %x' % (fs, x, part, addr, file, size) output = u_boot_console.run_command(
) '%swrite mmc %d:%s %x /%s %x' % (fs, x, part, addr, file, size)
assert 'Unable to write' not in output )
assert 'Error' not in output assert 'Unable to write' not in output
assert 'overflow' not in output assert 'Error' not in output
expected_text = '%d bytes written' % size assert 'overflow' not in output
assert expected_text in output expected_text = '%d bytes written' % size
assert expected_text in output
offset = random.randrange(128, 1024, 128) offset = random.randrange(128, 1024, 128)
output = u_boot_console.run_command( output = u_boot_console.run_command(
'%sload mmc %d:%s %x /%s' % (fs, x, part, addr + offset, file) '%sload mmc %d:%s %x /%s' % (fs, x, part, addr + offset, file)
) )
expected_text = '%d bytes read' % size expected_text = '%d bytes read' % size
assert expected_text in output assert expected_text in output
output = u_boot_console.run_command( output = u_boot_console.run_command(
'crc32 %x $filesize' % (addr + offset) 'crc32 %x $filesize' % (addr + offset)
) )
assert expected_crc32 in output assert expected_crc32 in output
if not part_detect: if not part_detect:
pytest.skip('No %s partition detected' % fs.upper()) pytest.skip('No %s partition detected' % fs.upper())
@ -394,7 +446,6 @@ def test_mmc_ext2ls(u_boot_console):
fs = 'ext2' fs = 'ext2'
for x in range(0, controllers): for x in range(0, controllers):
if devices[x]['detected'] == 'yes': if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
try: try:
partitions = devices[x][fs] partitions = devices[x][fs]
except: except:
@ -402,12 +453,16 @@ def test_mmc_ext2ls(u_boot_console):
continue continue
for part in partitions: for part in partitions:
part_detect = 1 for y in mmc_modes:
output = u_boot_console.run_command('%sls mmc %d:%s' % (fs, x, part)) u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
if 'Unrecognized filesystem type' in output: part_detect = 1
partitions.remove(part) output = u_boot_console.run_command(
pytest.fail('Unrecognized filesystem') '%sls mmc %d:%s' % (fs, x, part)
part_detect = 1 )
if 'Unrecognized filesystem type' in output:
partitions.remove(part)
pytest.fail('Unrecognized filesystem')
part_detect = 1
if not part_detect: if not part_detect:
pytest.skip('No %s partition detected' % fs.upper()) pytest.skip('No %s partition detected' % fs.upper())
@ -428,7 +483,6 @@ def test_mmc_ext2load(u_boot_console):
fs = 'ext2' fs = 'ext2'
for x in range(0, controllers): for x in range(0, controllers):
if devices[x]['detected'] == 'yes': if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
try: try:
partitions = devices[x][fs] partitions = devices[x][fs]
except: except:
@ -436,23 +490,25 @@ def test_mmc_ext2load(u_boot_console):
continue continue
for part in partitions: for part in partitions:
part_detect = 1 for y in mmc_modes:
addr = devices[x]['addr_%d' % part] u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
size = devices[x]['size_%d' % part] part_detect = 1
expected_crc32 = devices[x]['expected_crc32_%d' % part] addr = devices[x]['addr_%d' % part]
file = devices[x]['file_%d' % part] size = devices[x]['size_%d' % part]
expected_crc32 = devices[x]['expected_crc32_%d' % part]
file = devices[x]['file_%d' % part]
offset = random.randrange(128, 1024, 128) offset = random.randrange(128, 1024, 128)
output = u_boot_console.run_command( output = u_boot_console.run_command(
'%sload mmc %d:%s %x /%s' % (fs, x, part, addr + offset, file) '%sload mmc %d:%s %x /%s' % (fs, x, part, addr + offset, file)
) )
expected_text = '%d bytes read' % size expected_text = '%d bytes read' % size
assert expected_text in output assert expected_text in output
output = u_boot_console.run_command( output = u_boot_console.run_command(
'crc32 %x $filesize' % (addr + offset) 'crc32 %x $filesize' % (addr + offset)
) )
assert expected_crc32 in output assert expected_crc32 in output
if not part_detect: if not part_detect:
pytest.skip('No %s partition detected' % fs.upper()) pytest.skip('No %s partition detected' % fs.upper())
@ -469,7 +525,6 @@ def test_mmc_ls(u_boot_console):
part_detect = 0 part_detect = 0
for x in range(0, controllers): for x in range(0, controllers):
if devices[x]['detected'] == 'yes': if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
for fs in ['fat', 'ext4', 'ext2']: for fs in ['fat', 'ext4', 'ext2']:
try: try:
partitions = devices[x][fs] partitions = devices[x][fs]
@ -478,12 +533,14 @@ def test_mmc_ls(u_boot_console):
continue continue
for part in partitions: for part in partitions:
part_detect = 1 for y in mmc_modes:
output = u_boot_console.run_command('ls mmc %d:%s' % (x, part)) u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
if re.search(r'No \w+ table on this device', output): part_detect = 1
pytest.fail( output = u_boot_console.run_command('ls mmc %d:%s' % (x, part))
'%s: Partition table not found %d' % (fs.upper(), x) if re.search(r'No \w+ table on this device', output):
) pytest.fail(
'%s: Partition table not found %d' % (fs.upper(), x)
)
if not part_detect: if not part_detect:
pytest.skip('No partition detected') pytest.skip('No partition detected')
@ -500,7 +557,6 @@ def test_mmc_load(u_boot_console):
part_detect = 0 part_detect = 0
for x in range(0, controllers): for x in range(0, controllers):
if devices[x]['detected'] == 'yes': if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
for fs in ['fat', 'ext4', 'ext2']: for fs in ['fat', 'ext4', 'ext2']:
try: try:
partitions = devices[x][fs] partitions = devices[x][fs]
@ -509,23 +565,25 @@ def test_mmc_load(u_boot_console):
continue continue
for part in partitions: for part in partitions:
part_detect = 1 for y in mmc_modes:
addr = devices[x]['addr_%d' % part] u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
size = devices[x]['size_%d' % part] part_detect = 1
expected_crc32 = devices[x]['expected_crc32_%d' % part] addr = devices[x]['addr_%d' % part]
file = devices[x]['file_%d' % part] size = devices[x]['size_%d' % part]
expected_crc32 = devices[x]['expected_crc32_%d' % part]
file = devices[x]['file_%d' % part]
offset = random.randrange(128, 1024, 128) offset = random.randrange(128, 1024, 128)
output = u_boot_console.run_command( output = u_boot_console.run_command(
'load mmc %d:%s %x /%s' % (x, part, addr + offset, file) 'load mmc %d:%s %x /%s' % (x, part, addr + offset, file)
) )
expected_text = '%d bytes read' % size expected_text = '%d bytes read' % size
assert expected_text in output assert expected_text in output
output = u_boot_console.run_command( output = u_boot_console.run_command(
'crc32 %x $filesize' % (addr + offset) 'crc32 %x $filesize' % (addr + offset)
) )
assert expected_crc32 in output assert expected_crc32 in output
if not part_detect: if not part_detect:
pytest.skip('No partition detected') pytest.skip('No partition detected')
@ -542,7 +600,6 @@ def test_mmc_save(u_boot_console):
part_detect = 0 part_detect = 0
for x in range(0, controllers): for x in range(0, controllers):
if devices[x]['detected'] == 'yes': if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
for fs in ['fat', 'ext4', 'ext2']: for fs in ['fat', 'ext4', 'ext2']:
try: try:
partitions = devices[x][fs] partitions = devices[x][fs]
@ -551,18 +608,20 @@ def test_mmc_save(u_boot_console):
continue continue
for part in partitions: for part in partitions:
part_detect = 1 for y in mmc_modes:
addr = devices[x]['addr_%d' % part] u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
size = 0 part_detect = 1
file = devices[x]['file_%d' % part] addr = devices[x]['addr_%d' % part]
size = 0
file = devices[x]['file_%d' % part]
offset = random.randrange(128, 1024, 128) offset = random.randrange(128, 1024, 128)
output = u_boot_console.run_command( output = u_boot_console.run_command(
'save mmc %d:%s %x /%s %d' 'save mmc %d:%s %x /%s %d'
% (x, part, addr + offset, file, size) % (x, part, addr + offset, file, size)
) )
expected_text = '%d bytes written' % size expected_text = '%d bytes written' % size
assert expected_text in output assert expected_text in output
if not part_detect: if not part_detect:
pytest.skip('No partition detected') pytest.skip('No partition detected')
@ -589,7 +648,6 @@ def test_mmc_fat_read_write_files(u_boot_console):
for x in range(0, controllers): for x in range(0, controllers):
if devices[x]['detected'] == 'yes': if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
try: try:
partitions = devices[x][fs] partitions = devices[x][fs]
except: except:
@ -597,82 +655,86 @@ def test_mmc_fat_read_write_files(u_boot_console):
continue continue
for part in partitions: for part in partitions:
part_detect = 1 for y in mmc_modes:
addr = u_boot_utils.find_ram_base(u_boot_console) u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
count_f = 0 part_detect = 1
addr_l = [] addr = u_boot_utils.find_ram_base(u_boot_console)
size_l = [] count_f = 0
file_l = [] addr_l = []
crc32_l = [] size_l = []
offset_l = [] file_l = []
addr_l.append(addr) crc32_l = []
offset_l = []
addr_l.append(addr)
while count_f < num_files: while count_f < num_files:
size_l.append(random.randint(4, 1 * 1024 * 1024)) size_l.append(random.randint(4, 1 * 1024 * 1024))
# CRC32 count # CRC32 count
output = u_boot_console.run_command( output = u_boot_console.run_command(
'crc32 %x %x' % (addr_l[count_f], size_l[count_f]) 'crc32 %x %x' % (addr_l[count_f], size_l[count_f])
)
m = re.search('==> (.+?)', output)
if not m:
pytest.fail('CRC32 failed')
crc32_l.append(m.group(1))
# Write operation
file_l.append('%s_%d_%d' % ('uboot_test', count_f, size_l[count_f]))
output = u_boot_console.run_command(
'%swrite mmc %d:%s %x %s %x'
% (
fs,
x,
part,
addr_l[count_f],
file_l[count_f],
size_l[count_f],
) )
) m = re.search('==> (.+?)', output)
assert 'Unable to write' not in output if not m:
assert 'Error' not in output pytest.fail('CRC32 failed')
assert 'overflow' not in output crc32_l.append(m.group(1))
expected_text = '%d bytes written' % size_l[count_f]
assert expected_text in output
addr_l.append(addr_l[count_f] + size_l[count_f] + 1048576) # Write operation
count_f += 1 file_l.append(
'%s_%d_%d' % ('uboot_test', count_f, size_l[count_f])
count_f = 0
while count_f < num_files:
alignment = int(
u_boot_console.config.buildconfig.get(
'config_sys_cacheline_size', 128
) )
) output = u_boot_console.run_command(
offset_l.append(random.randrange(alignment, 1024, alignment)) '%swrite mmc %d:%s %x %s %x'
% (
# Read operation fs,
output = u_boot_console.run_command( x,
'%sload mmc %d:%s %x %s' part,
% ( addr_l[count_f],
fs, file_l[count_f],
x, size_l[count_f],
part, )
addr_l[count_f] + offset_l[count_f],
file_l[count_f],
) )
) assert 'Unable to write' not in output
assert 'Invalid FAT entry' not in output assert 'Error' not in output
assert 'Unable to read file' not in output assert 'overflow' not in output
assert 'Misaligned buffer address' not in output expected_text = '%d bytes written' % size_l[count_f]
expected_text = '%d bytes read' % size_l[count_f] assert expected_text in output
assert expected_text in output
output = u_boot_console.run_command( addr_l.append(addr_l[count_f] + size_l[count_f] + 1048576)
'crc32 %x $filesize' % (addr_l[count_f] + offset_l[count_f]) count_f += 1
)
assert crc32_l[count_f] in output
count_f += 1 count_f = 0
while count_f < num_files:
alignment = int(
u_boot_console.config.buildconfig.get(
'config_sys_cacheline_size', 128
)
)
offset_l.append(random.randrange(alignment, 1024, alignment))
# Read operation
output = u_boot_console.run_command(
'%sload mmc %d:%s %x %s'
% (
fs,
x,
part,
addr_l[count_f] + offset_l[count_f],
file_l[count_f],
)
)
assert 'Invalid FAT entry' not in output
assert 'Unable to read file' not in output
assert 'Misaligned buffer address' not in output
expected_text = '%d bytes read' % size_l[count_f]
assert expected_text in output
output = u_boot_console.run_command(
'crc32 %x $filesize' % (addr_l[count_f] + offset_l[count_f])
)
assert crc32_l[count_f] in output
count_f += 1
if not part_detect: if not part_detect:
pytest.skip('No %s partition detected' % fs.upper()) pytest.skip('No %s partition detected' % fs.upper())