test/py: fix timeout to be absolute
PATCH v2 1/8 test/py: fix timeout to be absolute
From: Stephen Warren <[email protected]>
Currently, Spawn.expect() imposes its timeout solely upon receipt of new data, not on its overall operation. In theory, this could cause the timeout not to fire if U-Boot continually generated output that did not match the expected patterns.
Fix the code to additionally impose a timeout on overall operation, which is the intended mode of operation.
--- test/py/u_boot_spawn.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
test/py/u_boot_spawn.py +6 -1
@@ -122,6 +122,7 @@ class Spawn(object): if type(patterns[pi]) == type(''): patterns[pi] = re.compile(patterns[pi]) + tstart_s = time.time() try: while True: earliest_m = None
@@ -142,7 +143,11 @@ class Spawn(object): self.after = self.buf[pos:posafter] self.buf = self.buf[posafter:] return earliest_pi - events = self.poll.poll(self.timeout) + tnow_s = time.time() + tdelta_ms = (tnow_s - tstart_s) * 1000 + if tdelta_ms > self.timeout: + raise Timeout() + events = self.poll.poll(self.timeout - tdelta_ms) if not events: raise Timeout() c = os.read(self.fd, 1024)
Signature · 1 line
2.7.0
PATCH v2 2/8 test/py: move U-Boot respawn trigger to the test core
From: Stephen Warren <[email protected]>
Prior to this change, U-Boot was lazilly (re-)spawned if/when a test attempted to interact with it, and no active connection existed. This approach was simple, yet had the disadvantage that U-Boot might be spawned in the middle of a test function, e.g. after the test had already performed actions such as creating data files, etc. In that case, this could cause the log to contain the sequence (1) some test logs, (2) U-Boot's boot process, (3) the rest of that test's logs. This isn't optimally readable. This issue will affect the upcoming DFU and enhanced UMS tests.
This change converts u_boot_console to be a function-scoped fixture, so that pytest attempts to re-create the object for each test invocation. This allows the fixture factory function to ensure that U-Boot is spawned prior to every test. In practice, the same object is returned each time so there is essentially no additional overhead due to this change.
This allows us to remove:
- The explicit ensure_spawned() call from test_sleep, since the core now ensures that the spawn happens before the test code is executed.
- The laxy calls to ensure_spawned() in the u_boot_console_* implementations.
The one downside is that test_env's "state_ttest_env" fixture must be converted to a function-scoped fixture too, since a module-scoped fixture cannot use a function-scoped fixture. To avoid overhead, we use the same trick of returning the same object each time.
--- test/py/conftest.py | 3 ++- test/py/tests/test_env.py | 8 ++++++-- test/py/tests/test_sandbox_exit.py | 2 -- test/py/tests/test_sleep.py | 4 ---- test/py/u_boot_console_base.py | 2 -- test/py/u_boot_console_sandbox.py | 1 - 6 files changed, 8 insertions(+), 12 deletions(-)
test/py/conftest.py +2 -1
@@ -227,7 +227,7 @@ def pytest_generate_tests(metafunc): vals = subconfig.get(fn + 's', []) metafunc.parametrize(fn, vals) - at pytest.fixture(scope='session') + at pytest.fixture(scope='function') def u_boot_console(request): '''Generate the value of a test's u_boot_console fixture.
@@ -238,6 +238,7 @@ def u_boot_console(request): The fixture value. ''' + console.ensure_spawned() return console tests_not_run = set()
test/py/tests/test_env.py +6 -2
@@ -77,11 +77,15 @@ class StateTestEnv(object): return var n += 1 - at pytest.fixture(scope='module') +ste = None + at pytest.fixture(scope='function') def state_test_env(u_boot_console): '''pytest fixture to provide a StateTestEnv object to tests.''' - return StateTestEnv(u_boot_console) + global ste + if not ste: + ste = StateTestEnv(u_boot_console) + return ste def unset_var(state_test_env, var): '''Unset an environment variable.
test/py/tests/test_sandbox_exit.py +0 -2
@@ -13,7 +13,6 @@ def test_reset(u_boot_console): u_boot_console.run_command('reset', wait_for_prompt=False) assert(u_boot_console.validate_exited()) - u_boot_console.ensure_spawned() @pytest.mark.boardspec('sandbox') def test_ctrl_c(u_boot_console):
@@ -21,4 +20,3 @@ def test_ctrl_c(u_boot_console): u_boot_console.kill(signal.SIGINT) assert(u_boot_console.validate_exited()) - u_boot_console.ensure_spawned()
test/py/tests/test_sleep.py +0 -4
@@ -9,10 +9,6 @@ def test_sleep(u_boot_console): '''Test the sleep command, and validate that it sleeps for approximately the correct amount of time.''' - # Do this before we time anything, to make sure U-Boot is already running. - # Otherwise, the system boot time is included in the time measurement. - u_boot_console.ensure_spawned() - # 3s isn't too long, but is enough to cross a few second boundaries. sleep_time = 3 tstart = time.time()
test/py/u_boot_console_base.py +0 -2
@@ -144,8 +144,6 @@ class ConsoleBase(object): command string and emitted the subsequent command prompts. ''' - self.ensure_spawned() - if self.at_prompt and \ self.at_prompt_logevt != self.logstream.logfile.cur_evt: self.logstream.write(self.prompt, implicit=True)
test/py/u_boot_console_sandbox.py +0 -1
@@ -51,7 +51,6 @@ class ConsoleSandbox(ConsoleBase): Nothing. ''' - self.ensure_spawned() self.log.action('kill %d' % sig) self.p.kill(sig)
Signature · 1 line
2.7.0
PATCH v2 2/8 test/py: move U-Boot respawn trigger to the test core
Quoted 33 lines · Stephen Warren
From: Stephen Warren <[email protected]>
Prior to this change, U-Boot was lazilly (re-)spawned if/when a test attempted to interact with it, and no active connection existed. This approach was simple, yet had the disadvantage that U-Boot might be spawned in the middle of a test function, e.g. after the test had already performed actions such as creating data files, etc. In that case, this could cause the log to contain the sequence (1) some test logs, (2) U-Boot's boot process, (3) the rest of that test's logs. This isn't optimally readable. This issue will affect the upcoming DFU and enhanced UMS tests.
This change converts
u_boot_consoleto be a function-scoped fixture, so that pytest attempts to re-create the object for each test invocation. This allows the fixture factory function to ensure that U-Boot is spawned prior to every test. In practice, the same object is returned each time so there is essentially no additional overhead due to this change.This allows us to remove:
- The explicit
ensure_spawned()call fromtest_sleep, since the core now ensures that the spawn happens before the test code is executed.- The laxy calls to
ensure_spawned()in the u_boot_console_* implementations.The one downside is that test_env's "
state_ttest_env" fixture must be converted to a function-scoped fixture too, since a module-scoped fixture cannot use a function-scoped fixture. To avoid overhead, we use the same trick of returning the same object each time.Signed-off-by Stephen Warren <[email protected]>Acked-by Simon Glass <[email protected]>
Quoted 8 lines
--- test/py/conftest.py | 3 ++- test/py/tests/test_env.py | 8 ++++++-- test/py/tests/test_sandbox_exit.py | 2 -- test/py/tests/test_sleep.py | 4 ---- test/py/u_boot_console_base.py | 2 -- test/py/u_boot_console_sandbox.py | 1 - 6 files changed, 8 insertions(+), 12 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 3/8 test/py: drain console log at the end of any failed test
In reply to Stephen WarrenFrom: Stephen Warren <[email protected]>
Tests may fail for a number of reasons, and in particular for reasons other than a timeout waiting for U-Boot to print expected data. If the last operation that a failed test performs is not waiting for U-Boot to print something, then any trailing output from U-Boot during that test's operation will not be logged as part of that test, but rather either along with the next test, or even thrown away, potentiall hiding clues
re: the test failure reason.
Solve this by explicitly draining (and hence logging) the U-Boot output in the case of failed tests.
--- test/py/conftest.py | 1 + test/py/u_boot_console_base.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
test/py/conftest.py +1 -0
@@ -386,6 +386,7 @@ def pytest_runtest_protocol(item, nextitem): skipped = report if failed: + console.drain_console() tests_failed.add(item.name) elif skipped: tests_skipped.add(item.name)
test/py/u_boot_console_base.py +38 -0
@@ -14,6 +14,7 @@ import os import pytest import re import sys +import u_boot_spawn # Regexes for text we expect U-Boot to send to the console. pattern_u_boot_spl_signon = re.compile('(U-Boot SPL \\d{4}\\.\\d{2}-[^\r\n]*)')
@@ -213,6 +214,43 @@ class ConsoleBase(object): self.run_command(chr(3), wait_for_echo=False, send_nl=False) + def drain_console(self): + '''Read from and log the U-Boot console for a short time. + + U-Boot's console output is only logged when the test code actively + waits for U-Boot to emit specific data. There are cases where tests + can fail without doing this. For example, if a test asks U-Boot to + enable USB device mode, then polls until a host-side device node + exists. In such a case, it is useful to log U-Boot's console output + in case U-Boot printed clues as to why the host-side even did not + occur. This function will do that. + + Args: + None. + + Returns: + Nothing. + ''' + + # If we are already not connected to U-Boot, there's nothing to drain. + # This should only happen when a previous call to run_command() or + # wait_for() failed (and hence the output has already been logged), or + # the system is shutting down. + if not self.p: + return + + orig_timeout = self.p.timeout + try: + # Drain the log for a relatively short time. + self.p.timeout = 1000 + # Wait for something U-Boot will likely never send. This will + # cause the console output to be read and logged. + self.p.expect(['This should never match U-Boot output']) + except u_boot_spawn.Timeout: + pass + finally: + self.p.timeout = orig_timeout + def ensure_spawned(self): '''Ensure a connection to a correctly running U-Boot instance.
Signature · 1 line
2.7.0
PATCH v2 3/8 test/py: drain console log at the end of any failed test
Quoted 13 lines · Stephen Warren
From: Stephen Warren <[email protected]>
Tests may fail for a number of reasons, and in particular for reasons other than a timeout waiting for U-Boot to print expected data. If the last operation that a failed test performs is not waiting for U-Boot to print something, then any trailing output from U-Boot during that test's operation will not be logged as part of that test, but rather either along with the next test, or even thrown away, potentiall hiding clues
re: the test failure reason.Solve this by explicitly draining (and hence logging) the U-Boot output in the case of failed tests.
Quoted 6 lines
Signed-off-by Stephen Warren <[email protected]>Acked-by Simon Glass <[email protected]>--- test/py/conftest.py | 1 + test/py/u_boot_console_base.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
Applied to u-boot-dm, thanks!
PATCH v2 4/8 test/py: log when tests send CTRL-C
In reply to Stephen WarrenFrom: Stephen Warren <[email protected]>
Write a note to the log file when a test sends CTRL-C to U-Boot. This makes it easier to follow what's happening in the logs, especially since U-Boot doesn't echo the character back to its output, so there's no other signal of what's going on.
--- test/py/u_boot_console_base.py | 1 + 1 file changed, 1 insertion(+)
test/py/u_boot_console_base.py +1 -0
@@ -212,6 +212,7 @@ class ConsoleBase(object): Nothing. ''' + self.log.action('Sending Ctrl-C') self.run_command(chr(3), wait_for_echo=False, send_nl=False) def drain_console(self):
Signature · 1 line
2.7.0
PATCH v2 4/8 test/py: log when tests send CTRL-C
Quoted 7 lines · Stephen Warren
From: Stephen Warren <[email protected]>
Write a note to the log file when a test sends CTRL-C to U-Boot. This makes it easier to follow what's happening in the logs, especially since U-Boot doesn't echo the character back to its output, so there's no other signal of what's going on.
Quoted 5 lines
Signed-off-by Stephen Warren <[email protected]>Acked-by Simon Glass <[email protected]>--- test/py/u_boot_console_base.py | 1 + 1 file changed, 1 insertion(+)
Applied to u-boot-dm, thanks!
PATCH v2 5/8 test/py: optionally ignore errors from shell commands
In reply to Stephen WarrenFrom: Stephen Warren <[email protected]>
Sometimes it's useful to run shell commands and ignore any errors. One example might be cleanup logic; if a test-case experiences an error, the cleanup logic might experience an error too, and we don't want that error to mask the original error, so we want to ignore the subsequent error.
--- test/py/multiplexed_log.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
test/py/multiplexed_log.py +6 -2
@@ -106,13 +106,17 @@ class RunAndLog(object): '''Clean up any resources managed by this object.''' pass - def run(self, cmd, cwd=None): + def run(self, cmd, cwd=None, ignore_errors=False): '''Run a command as a sub-process, and log the results. Args: cmd: The command to execute. cwd: The directory to run the command in. Can be None to use the current directory. + ignore_errors: Indicate whether to ignore errors. If True, the + function will simply return if the command cannot be executed + or exits with an error code, otherwise an exception will be + raised if such problems occur. Returns: Nothing.
@@ -148,7 +152,7 @@ class RunAndLog(object): exception = e if output and not output.endswith('\n'): output += '\n' - if exit_status and not exception: + if exit_status and not exception and not ignore_errors: exception = Exception('Exit code: ' + str(exit_status)) if exception: output += str(exception) + '\n'
Signature · 1 line
2.7.0
PATCH v2 5/8 test/py: optionally ignore errors from shell commands
Quoted 7 lines · Stephen Warren
From: Stephen Warren <[email protected]>
Sometimes it's useful to run shell commands and ignore any errors. One example might be cleanup logic; if a test-case experiences an error, the cleanup logic might experience an error too, and we don't want that error to mask the original error, so we want to ignore the subsequent error.
Quoted 5 lines
Signed-off-by Stephen Warren <[email protected]>Acked-by Simon Glass <[email protected]>--- test/py/multiplexed_log.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 6/8 test/py: add various utility code
In reply to Stephen WarrenFrom: Stephen Warren <[email protected]>
Add various common utility functions. These will be used by a forthcoming re-written UMS test, and a brand-new DFU test.
--- test/py/u_boot_console_base.py | 19 +++++ test/py/u_boot_utils.py | 171 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 test/py/u_boot_utils.py
test/py/u_boot_console_base.py +19 -0
@@ -215,6 +215,25 @@ class ConsoleBase(object): self.log.action('Sending Ctrl-C') self.run_command(chr(3), wait_for_echo=False, send_nl=False) + def wait_for(self, text): + '''Wait for a pattern to be emitted by U-Boot. + + This is useful when a long-running command such as "dfu" is executing, + and it periodically emits some text that should show up at a specific + location in the log file. + + Args: + text: The text to wait for; either a string (containing raw text, + not a regular expression) or an re object. + + Returns: + Nothing. + ''' + + if type(text) == type(''): + text = re.escape(text) + self.p.expect([text]) + def drain_console(self): '''Read from and log the U-Boot console for a short time.
test/py/u_boot_utils.py new file +171 -0
171 lines not on this page · raw message
Signature · 1 line
2.7.0
PATCH v2 6/8 test/py: add various utility code
Quoted 5 lines · Stephen Warren
From: Stephen Warren <[email protected]>
Add various common utility functions. These will be used by a forthcoming re-written UMS test, and a brand-new DFU test.
Quoted 7 lines
Signed-off-by Stephen Warren <[email protected]>Acked-by Simon Glass <[email protected]>--- test/py/u_boot_console_base.py | 19 +++++ test/py/u_boot_utils.py | 171 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 test/py/u_boot_utils.py
Applied to u-boot-dm, thanks!
PATCH v2 7/8 test/py: ums: add filesystem-based testing
In reply to Stephen WarrenFrom: Stephen Warren <[email protected]>
Enhance the UMS test to optionally mount a partition and read/write a file to it, validating that the content written and read back are identical.
This enhancement is backwards-compatible; old boardenv contents that don't define the new configuration data will cause the test code to perform as before.
test/ums/ is deleted since the Python test now performs the same testing that it did.
The code is also re-written to make use of the recently added utility module, and split it up into nested functions so the overall logic of the test process can be followed more easily without the details cluttering the code.
---
v2: Fix file-level and function-level comment to describe the enhanced test more fully.
--- test/py/tests/test_ums.py | 236 +++++++++++++++++++++++++++++++++++--------- test/ums/README | 30 ------ test/ums/ums_gadget_test.sh | 183 ---------------------------------- 3 files changed, 188 insertions(+), 261 deletions(-) delete mode 100644 test/ums/README delete mode 100755 test/ums/ums_gadget_test.sh
test/py/tests/test_ums.py +188 -48
@@ -2,13 +2,17 @@ # # SPDX-License-Identifier: GPL-2.0 -# Test U-Boot's "ums" command. At present, this test only ensures that a UMS -# device can be enumerated by the host/test machine. In the future, this test -# should be enhanced to validate disk IO. +# Test U-Boot's "ums" command. The test starts UMS in U-Boot, waits for USB +# device enumeration on the host, reads a small block of data from the UMS +# block device, optionally mounts a partition and performs filesystem-based +# read/write tests, and finally aborts the "ums" command in U-Boot. import os +import os.path import pytest +import re import time +import u_boot_utils ''' Note: This test relies on:
@@ -17,13 +21,36 @@ a) boardenv_* to contain configuration values to define which USB ports are available for testing. Without this, this test will be automatically skipped. For example: +# Leave this list empty if you have no block_devs below with writable +# partitions defined. +env__mount_points = ( + "/mnt/ubtest-mnt-p2371-2180-na", +) + env__usb_dev_ports = ( - {'tgt_usb_ctlr': '0', 'host_ums_dev_node': '/dev/disk/by-path/pci-0000:00:14.0-usb-0:13:1.0-scsi-0:0:0:0'}, + { + "tgt_usb_ctlr": "0", + "host_ums_dev_node": "/dev/disk/by-path/pci-0000:00:14.0-usb-0:13:1.0-scsi-0:0:0:0", + }, ) env__block_devs = ( - {'type': 'mmc', 'id': '0'}, # eMMC; always present - {'type': 'mmc', 'id': '1'}, # SD card; present since I plugged one in + # eMMC; always present + { + "type": "mmc", + "id": "0", + # The following two properties are optional. + # If present, the partition will be mounted and a file written-to and + # read-from it. If missing, only a simple block read test will be + # performed. + "writable_fs_partition": 1, + "writable_fs_subdir": "tmp/", + }, + # SD card; present since I plugged one in + { + "type": "mmc", + "id": "1" + }, ) b) udev rules to set permissions on devices nodes, so that sudo is not
@@ -34,47 +61,42 @@ ACTION=="add", SUBSYSTEM=="block", SUBSYSTEMS=="usb", KERNELS=="3-13", MODE:="66 (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.) -''' -def open_ums_device(host_ums_dev_node): - '''Attempt to open a device node, returning either the opened file handle, - or None on any error.''' +c) /etc/fstab entries to allow the block device to be mounted without requiring +root permissions. For example: - try: - return open(host_ums_dev_node, 'rb') - except: - return None - -def wait_for_ums_device(host_ums_dev_node): - '''Continually attempt to open the device node exported by the "ums" - command, and either return the opened file handle, or raise an exception - after a timeout.''' - - for i in xrange(100): - fh = open_ums_device(host_ums_dev_node) - if fh: - return fh - time.sleep(0.1) - raise Exception('UMS device did not appear') - -def wait_for_ums_device_gone(host_ums_dev_node): - '''Continually attempt to open the device node exported by the "ums" - command, and either return once the device has disappeared, or raise an - exception if it does not before a timeout occurs.''' - - for i in xrange(100): - fh = open_ums_device(host_ums_dev_node) - if not fh: - return - fh.close() - time.sleep(0.1) - raise Exception('UMS device did not disappear') +/dev/disk/by-path/pci-0000:00:14.0-usb-0:13:1.0-scsi-0:0:0:0-part1 /mnt/ubtest-mnt-p2371-2180-na ext4 noauto,user,nosuid,nodev + +This entry is only needed if any block_devs above contain a +writable_fs_partition value. +''' @pytest.mark.buildconfigspec('cmd_usb_mass_storage') def test_ums(u_boot_console, env__usb_dev_port, env__block_devs): '''Test the "ums" command; the host system must be able to enumerate a UMS - device when "ums" is running, and this device must disappear when "ums" is - aborted.''' + device when "ums" is running, block and optionally file I/O are tested, + and this device must disappear when "ums" is aborted. + + Args: + u_boot_console: A U-Boot console connection. + env__usb_dev_port: The single USB device-mode port specification on + which to run the test. See the file-level comment above for + details of the format. + env__block_devs: The list of block devices that the target U-Boot + device has attached. See the file-level comment above for details + of the format. + + Returns: + Nothing. + ''' + + have_writable_fs_partition = 'writable_fs_partition' in env__block_devs[0] + if not have_writable_fs_partition: + # If 'writable_fs_subdir' is missing, we'll skip all parts of the + # testing which mount filesystems. + u_boot_console.log.warning( + 'boardenv missing "writable_fs_partition"; ' + + 'UMS testing will be limited.') tgt_usb_ctlr = env__usb_dev_port['tgt_usb_ctlr'] host_ums_dev_node = env__usb_dev_port['host_ums_dev_node']
@@ -84,11 +106,129 @@ def test_ums(u_boot_console, env__usb_dev_port, env__block_devs): # device list here. We'll test each block device somewhere else. tgt_dev_type = env__block_devs[0]['type'] tgt_dev_id = env__block_devs[0]['id'] + if have_writable_fs_partition: + mount_point = u_boot_console.config.env['env__mount_points'][0] + mount_subdir = env__block_devs[0]['writable_fs_subdir'] + part_num = env__block_devs[0]['writable_fs_partition'] + host_ums_part_node = '%s-part%d' % (host_ums_dev_node, part_num) + else: + host_ums_part_node = host_ums_dev_node + + test_f = u_boot_utils.PersistentRandomFile(u_boot_console, 'ums.bin', + 1024 * 1024); + if have_writable_fs_partition: + mounted_test_fn = mount_point + '/' + mount_subdir + test_f.fn + + def start_ums(): + '''Start U-Boot's ums shell command. + + This also waits for the host-side USB enumeration process to complete. + + Args: + None. + + Returns: + Nothing. + ''' + + u_boot_console.log.action( + 'Starting long-running U-Boot ums shell command') + cmd = 'ums %s %s %s' % (tgt_usb_ctlr, tgt_dev_type, tgt_dev_id) + u_boot_console.run_command(cmd, wait_for_prompt=False) + u_boot_console.wait_for(re.compile('UMS: LUN.*[\r\n]')) + fh = u_boot_utils.wait_until_open_succeeds(host_ums_part_node) + u_boot_console.log.action('Reading raw data from UMS device') + fh.read(4096) + fh.close() + + def mount(): + '''Mount the block device that U-Boot exports. + + Args: + None. + + Returns: + Nothing. + ''' + + u_boot_console.log.action('Mounting exported UMS device') + cmd = ('/bin/mount', host_ums_part_node) + u_boot_utils.run_and_log(u_boot_console, cmd) - cmd = 'ums %s %s %s' % (tgt_usb_ctlr, tgt_dev_type, tgt_dev_id) - u_boot_console.run_command('ums 0 mmc 0', wait_for_prompt=False) - fh = wait_for_ums_device(host_ums_dev_node) - fh.read(4096) - fh.close() - u_boot_console.ctrlc() - wait_for_ums_device_gone(host_ums_dev_node) + def umount(ignore_errors): + '''Unmount the block device that U-Boot exports. + + Args: + ignore_errors: Ignore any errors. This is useful if an error has + already been detected, and the code is performing best-effort + cleanup. In this case, we do not want to mask the original + error by "honoring" any new errors. + + Returns: + Nothing. + ''' + + u_boot_console.log.action('Unmounting UMS device') + cmd = ('/bin/umount', host_ums_part_node) + u_boot_utils.run_and_log(u_boot_console, cmd, ignore_errors) + + def stop_ums(ignore_errors): + '''Stop U-Boot's ums shell command from executing. + + This also waits for the host-side USB de-enumeration process to + complete. + + Args: + ignore_errors: Ignore any errors. This is useful if an error has + already been detected, and the code is performing best-effort + cleanup. In this case, we do not want to mask the original + error by "honoring" any new errors. + + Returns: + Nothing. + ''' + + u_boot_console.log.action( + 'Stopping long-running U-Boot ums shell command') + u_boot_console.ctrlc() + u_boot_utils.wait_until_file_open_fails(host_ums_part_node, + ignore_errors) + + ignore_cleanup_errors = True + try: + start_ums() + if not have_writable_fs_partition: + # Skip filesystem-based testing if not configured + return + try: + mount() + u_boot_console.log.action('Writing test file via UMS') + cmd = ('rm', '-f', mounted_test_fn) + u_boot_utils.run_and_log(u_boot_console, cmd) + if os.path.exists(mounted_test_fn): + raise Exception('Could not rm target UMS test file') + cmd = ('cp', test_f.abs_fn, mounted_test_fn) + u_boot_utils.run_and_log(u_boot_console, cmd) + ignore_cleanup_errors = False + finally: + umount(ignore_errors=ignore_cleanup_errors) + finally: + stop_ums(ignore_errors=ignore_cleanup_errors) + + ignore_cleanup_errors = True + try: + start_ums() + try: + mount() + u_boot_console.log.action('Reading test file back via UMS') + read_back_hash = u_boot_utils.md5sum_file(mounted_test_fn) + cmd = ('rm', '-f', mounted_test_fn) + u_boot_utils.run_and_log(u_boot_console, cmd) + ignore_cleanup_errors = False + finally: + umount(ignore_errors=ignore_cleanup_errors) + finally: + stop_ums(ignore_errors=ignore_cleanup_errors) + + written_hash = test_f.content_hash + assert(written_hash == read_back_hash)
test/ums/README deleted +0 -30
@@ -1,30 +0,0 @@ -UMS test script. - -ums_gadget_test.sh -================== - -Example usage: -1. On the target: - create UMS exportable partitions (with e.g. gpt write), or specify a - partition number (PART_NUM) as "-" to use the entire device - ums 0 mmc 0 -2. On the host: - sudo test/ums/ums_gadget_test.sh VID PID PART_NUM [-f FILE_SYSTEM] [test_file] - e.g. sudo test/ums/ums_gadget_test.sh 0525 a4a5 6 -f vfat ./dat_14M.img - -... where: - VID - UMS device USB Vendor ID - PID - UMS device USB Product ID - PART_NUM - is the partition number on which UMS operates or "-" to use the - whole device - -Information about available partitions on the target one can read with using -the 'mmc part' or 'part list' commands. - -The partition num (PART_NUM) can be specified as '-' for using the whole device. - -The [-f FILE_SYSTEM] optional switch allows for formatting target partition to -FILE_SYSTEM. - -The last, optional [test_file] parameter is for specifying the exact test file -to use.
test/ums/ums_gadget_test.sh deleted +0 -183
183 lines not on this page · raw message
Signature · 1 line
2.7.0
PATCH v2 7/8 test/py: ums: add filesystem-based testing
Quoted 23 lines · Stephen Warren
From: Stephen Warren <[email protected]>
Enhance the UMS test to optionally mount a partition and read/write a file to it, validating that the content written and read back are identical.
This enhancement is backwards-compatible; old boardenv contents that don't define the new configuration data will cause the test code to perform as before.
test/ums/ is deleted since the Python test now performs the same testing that it did.
The code is also re-written to make use of the recently added utility module, and split it up into nested functions so the overall logic of the test process can be followed more easily without the details cluttering the code.
Signed-off-by Stephen Warren <[email protected]>Acked-by Lukasz Majewski <[email protected]>Acked-by Simon Glass <[email protected]>---
v2: Fix file-level and function-level comment to describe the enhanced test more fully.
Quoted 7 lines
--- test/py/tests/test_ums.py | 236 +++++++++++++++++++++++++++++++++++--------- test/ums/README | 30 ------ test/ums/ums_gadget_test.sh | 183 ---------------------------------- 3 files changed, 188 insertions(+), 261 deletions(-) delete mode 100644 test/ums/README delete mode 100755 test/ums/ums_gadget_test.sh
Applied to u-boot-dm, thanks!
PATCH v2 8/8 test/py: add DFU test
In reply to Stephen WarrenFrom: Stephen Warren <[email protected]>
Add a test of DFU functionality to the Python test suite. The test starts DFU in U-Boot, waits for USB device enumeration on the host, executes dfu-util multiple times to test various transfer sizes, many of which trigger USB driver edge cases, and finally aborts the DFU command in U-Boot.
This test mirrors the functionality previously available via the shell scripts in test/dfu, and hence those are removed too.
---
v2: Fix file comment to refer to "dfu" not "ums", and be generally more descriptive.
--- test/dfu/README | 44 ------- test/dfu/dfu_gadget_test.sh | 108 ---------------- test/dfu/dfu_gadget_test_init.sh | 45 ------- test/py/tests/test_dfu.py | 262 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 262 insertions(+), 197 deletions(-) delete mode 100644 test/dfu/README delete mode 100755 test/dfu/dfu_gadget_test.sh delete mode 100755 test/dfu/dfu_gadget_test_init.sh create mode 100644 test/py/tests/test_dfu.py
test/dfu/README deleted +0 -44
@@ -1,44 +0,0 @@ -DFU TEST CASE DESCRIPTION: - -The prerequisites for running this script are assured by -dfu_gadget_test_init.sh, which is automatically invoked by dfu_gadget_test.sh. -In this file user is able to generate their own set of test files by altering -the default set of TEST_FILES_SIZES variable. -The dfu_gadget_test_init.sh would generate test images only if they are not -already generated. - -On the target device, environment variable "dfu_alt_info" must contain at -least: - - dfu_test.bin fat 0 6;dfudummy.bin fat 0 6 - -Depending on your device, you may need to replace "fat" with -"ext4", and "6" with the relevant partition number. For reference please -consult the config file for TRATS/TRATS2 devices -(../../include/configs/trats{2}.h) - -One can use fat, ext4 or any other supported file system supported by U-Boot. -These can be created by exporting storage devices via UMS (ums 0 mmc 0) and -using standard tools on host (like mkfs.ext4). - -Example usage: -1. On the target: - setenv dfu_alt_info dfu_test.bin fat 0 6\;dfudummy.bin fat 0 6 - dfu 0 mmc 0 -2. On the host: - test/dfu/dfu_gadget_test.sh X Y [test file name] [usb device vendor:product] - e.g. test/dfu/dfu_gadget_test.sh 0 1 - or - e.g. test/dfu/dfu_gadget_test.sh 0 1 ./dat_960.img - or - e.g. test/dfu/dfu_gadget_test.sh 0 1 0451:d022 - or - e.g. test/dfu/dfu_gadget_test.sh 0 1 ./dat_960.img 0451:d022 - -... where X and Y are dfu_test.bin's and dfudummy.bin's alt setting numbers. -They can be obtained from dfu-util -l or $dfu_alt_info. -It is also possible to pass optional [test file name] to force the script to -test one particular file. -If many DFU devices are connected, it may be useful to filter on USB -vendor/product ID (0451:d022). -One can get them by running "lsusb" command on a host PC.
test/dfu/dfu_gadget_test.sh deleted +0 -108
108 lines not on this page · raw message
test/dfu/dfu_gadget_test_init.sh deleted +0 -45
45 lines not on this page · raw message
test/py/tests/test_dfu.py new file +262 -0
262 lines not on this page · raw message
Signature · 1 line
2.7.0
PATCH v2 8/8 test/py: add DFU test
Quoted 17 lines · Stephen Warren
From: Stephen Warren <[email protected]>
Add a test of DFU functionality to the Python test suite. The test starts DFU in U-Boot, waits for USB device enumeration on the host, executes dfu-util multiple times to test various transfer sizes, many of which trigger USB driver edge cases, and finally aborts the DFU command in U-Boot.
This test mirrors the functionality previously available via the shell scripts in test/dfu, and hence those are removed too.
Signed-off-by Stephen Warren <[email protected]>Acked-by Lukasz Majewski <[email protected]>Acked-by Simon Glass <[email protected]>---
v2: Fix file comment to refer to "dfu" not "ums", and be generally more descriptive.
Quoted 10 lines
--- test/dfu/README | 44 ------- test/dfu/dfu_gadget_test.sh | 108 ---------------- test/dfu/dfu_gadget_test_init.sh | 45 ------- test/py/tests/test_dfu.py | 262 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 262 insertions(+), 197 deletions(-) delete mode 100644 test/dfu/README delete mode 100755 test/dfu/dfu_gadget_test.sh delete mode 100755 test/dfu/dfu_gadget_test_init.sh create mode 100644 test/py/tests/test_dfu.py
Applied to u-boot-dm, thanks!
PATCH v2 1/8 test/py: fix timeout to be absolute
In reply to Stephen WarrenQuoted 10 lines · Stephen Warren
From: Stephen Warren <[email protected]>
Currently,
Spawn.expect()imposes its timeout solely upon receipt of new data, not on its overall operation. In theory, this could cause the timeout not to fire if U-Boot continually generated output that did not match the expected patterns.Fix the code to additionally impose a timeout on overall operation, which is the intended mode of operation.
Quoted 6 lines
Signed-off-by Stephen Warren <[email protected]>Reviewed-by Lukasz Majewski <[email protected]>Acked-by Simon Glass <[email protected]>--- test/py/u_boot_spawn.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Applied to u-boot-dm, thanks!