diff mbox

[U-Boot,v3] test/py: Support setting up specific timeout

Message ID d3b98b9f20831027485c8f3d2042eb05136575dc.1463637459.git.michal.simek@xilinx.com
State Accepted
Commit 87861c1970d9e1c475e62304b8e249aa3edf8c39
Delegated to: Tom Rini
Headers show

Commit Message

Michal Simek May 19, 2016, 5:57 a.m. UTC
Large file transfers, flash erasing and more complicated tests
requires more time to finish. Provide a way to setup specific
timeout directly in test.

For example description for 50s test:
timeout = 50000
with u_boot_console.temporary_timeout(timeout):
  u_boot_console.run_command(...)

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Stephen Warren <swarren@nvidia.com>
---

Changes in v3:
- Remove if not self.p checking from __exit__ reported by Stephen

Changes in v2:
- save console.p instead of simple console
- Some fixes in comments
- Save orig_timeout directly in class
- Remove get_spawn call
- Test if self.p exists

 test/py/u_boot_console_base.py | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

Comments

Tom Rini May 30, 2016, 6 p.m. UTC | #1
On Thu, May 19, 2016 at 07:57:41AM +0200, Michal Simek wrote:

> Large file transfers, flash erasing and more complicated tests
> requires more time to finish. Provide a way to setup specific
> timeout directly in test.
> 
> For example description for 50s test:
> timeout = 50000
> with u_boot_console.temporary_timeout(timeout):
>   u_boot_console.run_command(...)
> 
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> Reviewed-by: Stephen Warren <swarren@nvidia.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/test/py/u_boot_console_base.py b/test/py/u_boot_console_base.py
index f7434363fbcb..815fa64d5ff3 100644
--- a/test/py/u_boot_console_base.py
+++ b/test/py/u_boot_console_base.py
@@ -56,6 +56,22 @@  class ConsoleDisableCheck(object):
         self.console.disable_check_count[self.check_type] -= 1
         self.console.eval_bad_patterns()
 
+class ConsoleSetupTimeout(object):
+    """Context manager (for Python's with statement) that temporarily sets up
+    timeout for specific command. This is useful when execution time is greater
+    then default 30s."""
+
+    def __init__(self, console, timeout):
+        self.p = console.p
+        self.orig_timeout = self.p.timeout
+        self.p.timeout = timeout
+
+    def __enter__(self):
+        return self
+
+    def __exit__(self, extype, value, traceback):
+        self.p.timeout = self.orig_timeout
+
 class ConsoleBase(object):
     """The interface through which test functions interact with the U-Boot
     console. This primarily involves executing shell commands, capturing their
@@ -391,3 +407,18 @@  class ConsoleBase(object):
         """
 
         return ConsoleDisableCheck(self, check_type)
+
+    def temporary_timeout(self, timeout):
+        """Temporarily set up different timeout for commands.
+
+        Create a new context manager (for use with the "with" statement) which
+        temporarily change timeout.
+
+        Args:
+            timeout: Time in milliseconds.
+
+        Returns:
+            A context manager object.
+        """
+
+        return ConsoleSetupTimeout(self, timeout)