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
# value is set to True. Set it to False to run all tests for MMC device.
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
controllers = 0
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):
if u_boot_console.config.env.get('env__mmc_device_test_skip', True):
pytest.skip('MMC device test is not enabled')
setup_mmc_modes(u_boot_console)
@pytest.mark.buildconfigspec('cmd_mmc')
def test_mmc_list(u_boot_console):
setup_mmc(u_boot_console)
@ -58,9 +97,10 @@ def test_mmc_dev(u_boot_console):
fail = 0
for x in range(0, controllers):
devices[x]['detected'] = 'yes'
output = u_boot_console.run_command('mmc dev %d' % x)
# Some sort of switch here
for y in mmc_modes:
output = u_boot_console.run_command('mmc dev %d 0 %d' % x, y)
if 'Card did not respond to voltage select' in output:
fail = 1
devices[x]['detected'] = 'no'
@ -81,11 +121,14 @@ def test_mmcinfo(u_boot_console):
for x in range(0, controllers):
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('mmcinfo')
if 'busy timeout' in output:
pytest.skip('No SD/MMC/eMMC device present')
assert mmc_modes_name[mmc_modes.index(y)] in output
obj = re.search(r'Capacity: (\d+|\d+[\.]?\d)', output)
try:
capacity = float(obj.groups()[0])
@ -102,9 +145,11 @@ def test_mmc_info(u_boot_console):
for x in range(0, controllers):
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')
assert mmc_modes_name[mmc_modes.index(y)] in output
obj = re.search(r'Capacity: (\d+|\d+[\.]?\d)', output)
try:
@ -126,7 +171,8 @@ def test_mmc_rescan(u_boot_console):
for x in range(0, controllers):
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 rescan')
if output:
pytest.fail('mmc rescan has something to check')
@ -192,7 +238,6 @@ def test_mmc_fatls_fatinfo(u_boot_console):
fs = 'fat'
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@ -200,6 +245,8 @@ def test_mmc_fatls_fatinfo(u_boot_console):
continue
for part in partitions:
for y in mmc_modes:
u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
output = u_boot_console.run_command(
'fatls mmc %d:%s' % (x, part))
if 'Unrecognized filesystem type' in output:
@ -233,7 +280,6 @@ def test_mmc_fatload_fatwrite(u_boot_console):
fs = 'fat'
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@ -241,6 +287,8 @@ def test_mmc_fatload_fatwrite(u_boot_console):
continue
for part in partitions:
for y in mmc_modes:
u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
part_detect = 1
addr = u_boot_utils.find_ram_base(u_boot_console)
devices[x]['addr_%d' % part] = addr
@ -307,9 +355,12 @@ def test_mmc_ext4ls(u_boot_console):
print('No %s table on this device' % fs.upper())
continue
u_boot_console.run_command('mmc dev %d' % x)
for part in partitions:
output = u_boot_console.run_command('%sls mmc %d:%s' % (fs, x, part))
for y in mmc_modes:
u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
output = u_boot_console.run_command(
'%sls mmc %d:%s' % (fs, x, part)
)
if 'Unrecognized filesystem type' in output:
partitions.remove(part)
pytest.fail('Unrecognized filesystem')
@ -333,7 +384,6 @@ def test_mmc_ext4load_ext4write(u_boot_console):
fs = 'ext4'
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@ -341,6 +391,8 @@ def test_mmc_ext4load_ext4write(u_boot_console):
continue
for part in partitions:
for y in mmc_modes:
u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
part_detect = 1
addr = u_boot_utils.find_ram_base(u_boot_console)
devices[x]['addr_%d' % part] = addr
@ -353,8 +405,8 @@ def test_mmc_ext4load_ext4write(u_boot_console):
pytest.fail('CRC32 failed')
expected_crc32 = m.group(1)
devices[x]['expected_crc32_%d' % part] = expected_crc32
# do write
# do write
file = '%s_%d' % ('uboot_test', size)
devices[x]['file_%d' % part] = file
output = u_boot_console.run_command(
@ -394,7 +446,6 @@ def test_mmc_ext2ls(u_boot_console):
fs = 'ext2'
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@ -402,8 +453,12 @@ def test_mmc_ext2ls(u_boot_console):
continue
for part in partitions:
for y in mmc_modes:
u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
part_detect = 1
output = u_boot_console.run_command('%sls mmc %d:%s' % (fs, x, part))
output = u_boot_console.run_command(
'%sls mmc %d:%s' % (fs, x, part)
)
if 'Unrecognized filesystem type' in output:
partitions.remove(part)
pytest.fail('Unrecognized filesystem')
@ -428,7 +483,6 @@ def test_mmc_ext2load(u_boot_console):
fs = 'ext2'
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@ -436,6 +490,8 @@ def test_mmc_ext2load(u_boot_console):
continue
for part in partitions:
for y in mmc_modes:
u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
part_detect = 1
addr = devices[x]['addr_%d' % part]
size = devices[x]['size_%d' % part]
@ -469,7 +525,6 @@ def test_mmc_ls(u_boot_console):
part_detect = 0
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
for fs in ['fat', 'ext4', 'ext2']:
try:
partitions = devices[x][fs]
@ -478,6 +533,8 @@ def test_mmc_ls(u_boot_console):
continue
for part in partitions:
for y in mmc_modes:
u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
part_detect = 1
output = u_boot_console.run_command('ls mmc %d:%s' % (x, part))
if re.search(r'No \w+ table on this device', output):
@ -500,7 +557,6 @@ def test_mmc_load(u_boot_console):
part_detect = 0
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
for fs in ['fat', 'ext4', 'ext2']:
try:
partitions = devices[x][fs]
@ -509,6 +565,8 @@ def test_mmc_load(u_boot_console):
continue
for part in partitions:
for y in mmc_modes:
u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
part_detect = 1
addr = devices[x]['addr_%d' % part]
size = devices[x]['size_%d' % part]
@ -542,7 +600,6 @@ def test_mmc_save(u_boot_console):
part_detect = 0
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
for fs in ['fat', 'ext4', 'ext2']:
try:
partitions = devices[x][fs]
@ -551,6 +608,8 @@ def test_mmc_save(u_boot_console):
continue
for part in partitions:
for y in mmc_modes:
u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
part_detect = 1
addr = devices[x]['addr_%d' % part]
size = 0
@ -589,7 +648,6 @@ def test_mmc_fat_read_write_files(u_boot_console):
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@ -597,6 +655,8 @@ def test_mmc_fat_read_write_files(u_boot_console):
continue
for part in partitions:
for y in mmc_modes:
u_boot_console.run_command('mmc dev %d %d %d' % x, part, y)
part_detect = 1
addr = u_boot_utils.find_ram_base(u_boot_console)
count_f = 0
@ -620,7 +680,9 @@ def test_mmc_fat_read_write_files(u_boot_console):
crc32_l.append(m.group(1))
# Write operation
file_l.append('%s_%d_%d' % ('uboot_test', count_f, size_l[count_f]))
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'
% (