mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-24 14:25:56 +00:00
usb: Fix test failure with multiple partitions
When test_usb_load finds multiple partitions of the same type then
it will cause a test failure. The call to write the test file will
write a different test file to each partition but only return the
name and size of the last one written. So the test then fails to
load the test file from the first partition as it uses the name of
a file on a different partition.
Refactor the code so that only one test file is written at a time
and is written to only the partition being tested at that time. This
allows the correct file name to always be available to the code that
runs the load command. This reduces the number of files written and
also the number of calls to crc32 needed.
Fixes: 1c5b6edad3
("test/py: usb: Add tests for USB device")
Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
Reviewed-by: Love Kumar <love.kumar@amd.com>
This commit is contained in:
parent
bf066dc3eb
commit
32e40f3dd8
1 changed files with 82 additions and 84 deletions
|
@ -288,27 +288,7 @@ def test_usb_fatls_fatinfo(u_boot_console):
|
|||
if not part_detect:
|
||||
pytest.skip('No %s partition detected' % fs.upper())
|
||||
|
||||
@pytest.mark.buildconfigspec('cmd_usb')
|
||||
@pytest.mark.buildconfigspec('cmd_fat')
|
||||
@pytest.mark.buildconfigspec('cmd_memory')
|
||||
def test_usb_fatload_fatwrite(u_boot_console):
|
||||
devices, controllers, storage_device = test_usb_part(u_boot_console)
|
||||
if not devices:
|
||||
pytest.skip('No devices detected')
|
||||
|
||||
part_detect = 0
|
||||
fs = 'fat'
|
||||
for x in range(0, int(storage_device)):
|
||||
if devices[x]['detected'] == 'yes':
|
||||
u_boot_console.run_command('usb dev %d' % x)
|
||||
try:
|
||||
partitions = devices[x][fs]
|
||||
except:
|
||||
print('No %s table on this device' % fs.upper())
|
||||
continue
|
||||
|
||||
for part in partitions:
|
||||
part_detect = 1
|
||||
def usb_fatload_fatwrite(u_boot_console, fs, x, part):
|
||||
addr = u_boot_utils.find_ram_base(u_boot_console)
|
||||
size = random.randint(4, 1 * 1024 * 1024)
|
||||
output = u_boot_console.run_command('crc32 %x %x' % (addr, size))
|
||||
|
@ -347,11 +327,34 @@ def test_usb_fatload_fatwrite(u_boot_console):
|
|||
)
|
||||
assert expected_crc32 in output
|
||||
|
||||
return file, size, expected_crc32
|
||||
|
||||
@pytest.mark.buildconfigspec('cmd_usb')
|
||||
@pytest.mark.buildconfigspec('cmd_fat')
|
||||
@pytest.mark.buildconfigspec('cmd_memory')
|
||||
def test_usb_fatload_fatwrite(u_boot_console):
|
||||
devices, controllers, storage_device = test_usb_part(u_boot_console)
|
||||
if not devices:
|
||||
pytest.skip('No devices detected')
|
||||
|
||||
part_detect = 0
|
||||
fs = 'fat'
|
||||
for x in range(0, int(storage_device)):
|
||||
if devices[x]['detected'] == 'yes':
|
||||
u_boot_console.run_command('usb dev %d' % x)
|
||||
try:
|
||||
partitions = devices[x][fs]
|
||||
except:
|
||||
print('No %s table on this device' % fs.upper())
|
||||
continue
|
||||
|
||||
for part in partitions:
|
||||
part_detect = 1
|
||||
usb_fatload_fatwrite(u_boot_console, fs, x, part)
|
||||
|
||||
if not part_detect:
|
||||
pytest.skip('No %s partition detected' % fs.upper())
|
||||
|
||||
return file, size
|
||||
|
||||
@pytest.mark.buildconfigspec('cmd_usb')
|
||||
@pytest.mark.buildconfigspec('cmd_ext4')
|
||||
def test_usb_ext4ls(u_boot_console):
|
||||
|
@ -380,28 +383,7 @@ def test_usb_ext4ls(u_boot_console):
|
|||
if not part_detect:
|
||||
pytest.skip('No %s partition detected' % fs.upper())
|
||||
|
||||
@pytest.mark.buildconfigspec('cmd_usb')
|
||||
@pytest.mark.buildconfigspec('cmd_ext4')
|
||||
@pytest.mark.buildconfigspec('ext4_write')
|
||||
@pytest.mark.buildconfigspec('cmd_memory')
|
||||
def test_usb_ext4load_ext4write(u_boot_console):
|
||||
devices, controllers, storage_device = test_usb_part(u_boot_console)
|
||||
if not devices:
|
||||
pytest.skip('No devices detected')
|
||||
|
||||
part_detect = 0
|
||||
fs = 'ext4'
|
||||
for x in range(0, int(storage_device)):
|
||||
if devices[x]['detected'] == 'yes':
|
||||
u_boot_console.run_command('usb dev %d' % x)
|
||||
try:
|
||||
partitions = devices[x][fs]
|
||||
except:
|
||||
print('No %s table on this device' % fs.upper())
|
||||
continue
|
||||
|
||||
for part in partitions:
|
||||
part_detect = 1
|
||||
def usb_ext4load_ext4write(u_boot_console, fs, x, part):
|
||||
addr = u_boot_utils.find_ram_base(u_boot_console)
|
||||
size = random.randint(4, 1 * 1024 * 1024)
|
||||
output = u_boot_console.run_command('crc32 %x %x' % (addr, size))
|
||||
|
@ -432,11 +414,35 @@ def test_usb_ext4load_ext4write(u_boot_console):
|
|||
)
|
||||
assert expected_crc32 in output
|
||||
|
||||
return file, size, expected_crc32
|
||||
|
||||
@pytest.mark.buildconfigspec('cmd_usb')
|
||||
@pytest.mark.buildconfigspec('cmd_ext4')
|
||||
@pytest.mark.buildconfigspec('ext4_write')
|
||||
@pytest.mark.buildconfigspec('cmd_memory')
|
||||
def test_usb_ext4load_ext4write(u_boot_console):
|
||||
devices, controllers, storage_device = test_usb_part(u_boot_console)
|
||||
if not devices:
|
||||
pytest.skip('No devices detected')
|
||||
|
||||
part_detect = 0
|
||||
fs = 'ext4'
|
||||
for x in range(0, int(storage_device)):
|
||||
if devices[x]['detected'] == 'yes':
|
||||
u_boot_console.run_command('usb dev %d' % x)
|
||||
try:
|
||||
partitions = devices[x][fs]
|
||||
except:
|
||||
print('No %s table on this device' % fs.upper())
|
||||
continue
|
||||
|
||||
for part in partitions:
|
||||
part_detect = 1
|
||||
usb_ext4load_ext4write(u_boot_console, fs, x, part)
|
||||
|
||||
if not part_detect:
|
||||
pytest.skip('No %s partition detected' % fs.upper())
|
||||
|
||||
return file, size
|
||||
|
||||
@pytest.mark.buildconfigspec('cmd_usb')
|
||||
@pytest.mark.buildconfigspec('cmd_ext2')
|
||||
def test_usb_ext2ls(u_boot_console):
|
||||
|
@ -473,7 +479,6 @@ def test_usb_ext2ls(u_boot_console):
|
|||
@pytest.mark.buildconfigspec('cmd_memory')
|
||||
def test_usb_ext2load(u_boot_console):
|
||||
devices, controllers, storage_device = test_usb_part(u_boot_console)
|
||||
file, size = test_usb_ext4load_ext4write(u_boot_console)
|
||||
|
||||
if not devices:
|
||||
pytest.skip('No devices detected')
|
||||
|
@ -491,12 +496,9 @@ def test_usb_ext2load(u_boot_console):
|
|||
|
||||
for part in partitions:
|
||||
part_detect = 1
|
||||
file, size, expected_crc32 = \
|
||||
usb_ext4load_ext4write(u_boot_console, 'ext4', x, part)
|
||||
addr = u_boot_utils.find_ram_base(u_boot_console)
|
||||
output = u_boot_console.run_command('crc32 %x %x' % (addr, size))
|
||||
m = re.search('==> (.+?)', output)
|
||||
if not m:
|
||||
pytest.fail('CRC32 failed')
|
||||
expected_crc32 = m.group(1)
|
||||
|
||||
offset = random.randrange(128, 1024, 128)
|
||||
output = u_boot_console.run_command(
|
||||
|
@ -565,15 +567,11 @@ def test_usb_load(u_boot_console):
|
|||
addr = u_boot_utils.find_ram_base(u_boot_console)
|
||||
|
||||
if fs == 'fat':
|
||||
file, size = test_usb_fatload_fatwrite(u_boot_console)
|
||||
file, size, expected_crc32 = \
|
||||
usb_fatload_fatwrite(u_boot_console, fs, x, part)
|
||||
elif fs == 'ext4':
|
||||
file, size = test_usb_ext4load_ext4write(u_boot_console)
|
||||
|
||||
output = u_boot_console.run_command('crc32 %x %x' % (addr, size))
|
||||
m = re.search('==> (.+?)', output)
|
||||
if not m:
|
||||
pytest.fail('CRC32 failed')
|
||||
expected_crc32 = m.group(1)
|
||||
file, size, expected_crc32 = \
|
||||
usb_ext4load_ext4write(u_boot_console, fs, x, part)
|
||||
|
||||
offset = random.randrange(128, 1024, 128)
|
||||
output = u_boot_console.run_command(
|
||||
|
|
Loading…
Add table
Reference in a new issue