import pytest
import u_boot_utils
-'''
+"""
Note: This test relies on:
a) boardenv_* to contain configuration values to define which USB ports are
(You may wish to change the group ID instead of setting the permissions wide
open. All that matters is that the user ID running the test can access the
device.)
-'''
+"""
# The set of file sizes to test. These values trigger various edge-cases such
# as one less than, equal to, and one greater than typical USB max packet
@pytest.mark.buildconfigspec('cmd_dfu')
def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
- '''Test the "dfu" command; the host system must be able to enumerate a USB
+ """Test the "dfu" command; the host system must be able to enumerate a USB
device when "dfu" is running, various DFU transfers are tested, and the
USB device must disappear when "dfu" is aborted.
Returns:
Nothing.
- '''
+ """
def start_dfu():
- '''Start U-Boot's dfu shell command.
+ """Start U-Boot's dfu shell command.
This also waits for the host-side USB enumeration process to complete.
Returns:
Nothing.
- '''
+ """
+
+ fh = u_boot_utils.attempt_to_open_file(
+ env__usb_dev_port['host_usb_dev_node'])
+ if fh:
+ fh.close()
+ raise Exception('USB device present before dfu command invoked')
u_boot_console.log.action(
'Starting long-running U-Boot dfu shell command')
fh.close()
def stop_dfu(ignore_errors):
- '''Stop U-Boot's dfu shell command from executing.
+ """Stop U-Boot's dfu shell command from executing.
This also waits for the host-side USB de-enumeration process to
complete.
Returns:
Nothing.
- '''
+ """
try:
u_boot_console.log.action(
raise
def run_dfu_util(alt_setting, fn, up_dn_load_arg):
- '''Invoke dfu-util on the host.
+ """Invoke dfu-util on the host.
Args:
alt_setting: The DFU "alternate setting" identifier to interact
Returns:
Nothing.
- '''
+ """
cmd = ['dfu-util', '-a', str(alt_setting), up_dn_load_arg, fn]
if 'host_usb_port_path' in env__usb_dev_port:
u_boot_console.wait_for('Ctrl+C to exit ...')
def dfu_write(alt_setting, fn):
- '''Write a file to the target board using DFU.
+ """Write a file to the target board using DFU.
Args:
alt_setting: The DFU "alternate setting" identifier to interact
Returns:
Nothing.
- '''
+ """
run_dfu_util(alt_setting, fn, '-D')
def dfu_read(alt_setting, fn):
- '''Read a file from the target board using DFU.
+ """Read a file from the target board using DFU.
Args:
alt_setting: The DFU "alternate setting" identifier to interact
Returns:
Nothing.
- '''
+ """
# dfu-util fails reads/uploads if the host file already exists
if os.path.exists(fn):
run_dfu_util(alt_setting, fn, '-U')
def dfu_write_read_check(size):
- '''Test DFU transfers of a specific size of data
+ """Test DFU transfers of a specific size of data
This function first writes data to the board then reads it back and
compares the written and read back data. Measures are taken to avoid
Returns:
Nothing.
- '''
+ """
test_f = u_boot_utils.PersistentRandomFile(u_boot_console,
'dfu_%d.bin' % size, size)
dfu_write(0, dummy_f.abs_fn)
for size in sizes:
- with u_boot_console.log.section("Data size %d" % size):
+ with u_boot_console.log.section('Data size %d' % size):
dfu_write_read_check(size)
# Make the status of each sub-test obvious. If the test didn't
# pass, an exception was thrown so this code isn't executed.