Skip to contentSkip to conversation

test/py: Support setting up specific timeout

PATCH Superseded Michal Simek 2 participants 3 messages May 18, 2016 – May 19, 2016

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 test/py: Support setting up specific timeout

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(...)

---

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 | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
test/py/u_boot_console_base.py +33 -0
index f7434363fbcb..dbbdd53b46dc 100644
@@ -56,6 +56,24 @@ 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):
+        if not self.p:
+            return
+        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 +409,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)
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/1 test/py: Support setting up specific timeout

Quoted 11 lines · Michal Simek

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(...)
test/py/u_boot_console_base.py +0 -0
 

test/py/u_boot_console_base.py class ConsoleDisableCheck(object): · line 74

Quoted 10 lines
test/py/u_boot_console_base.py +8 -0
+class ConsoleSetupTimeout(object):
 
+    def __init__(self, console, timeout):
+        self.p = console.p
+        self.orig_timeout = self.p.timeout
+        self.p.timeout = timeout
 
+    def __exit__(self, extype, value, traceback):
+        if not self.p:
+            return

That test can't fail, since __init__ already used self.p in a way that would have triggered an exception during the constructor, which I believe would cause neither __enter__ nor __exit__ to ever be called since the object would not exist.

Still, this does no harm, so either way,

#2 lore raw

PATCH v2 1/1 test/py: Support setting up specific timeout

Quoted 24 lines · Stephen Warren
Quoted 12 lines · Michal Simek

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(...)
test/py/u_boot_console_base.py +0 -0
 

test/py/u_boot_console_base.py class ConsoleDisableCheck(object): · line 74

Quoted 10 lines
test/py/u_boot_console_base.py +8 -0
+class ConsoleSetupTimeout(object):
 
+    def __init__(self, console, timeout):
+        self.p = console.p
+        self.orig_timeout = self.p.timeout
+        self.p.timeout = timeout
 
+    def __exit__(self, extype, value, traceback):
+        if not self.p:
+            return
Quoted 7 lines

That test can't fail, since __init__ already used self.p in a way that would have triggered an exception during the constructor, which I believe would cause neither __enter__ nor __exit__ to ever be called since the object would not exist.

Still, this does no harm, so either way,

I have tested it without that checking and you are right. I have sent v3 which remove this with your Reviewed-by line.

Thanks,
Michal