On 11/05/2016 10:45 AM, Stefan Brüns wrote:
The runner actually has no console dependency, only on the log provided
by the console. Accept both u_boot_console or a multiplexed_log.
diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py
-def run_and_log(u_boot_console, cmd, ignore_errors=False):
+def run_and_log(u_boot_console_or_log, cmd, ignore_errors=False):
"""Run a command and log its output.
Args:
I expect you also need to update the documentation for the function
parameter in the "Args" section of the docs too.
@@ -171,7 +171,10 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False):
"""
if isinstance(cmd, str):
cmd = cmd.split()
- runner = u_boot_console.log.get_runner(cmd[0], sys.stdout)
+ try:
+ runner = u_boot_console_or_log.get_runner(cmd[0], sys.stdout)
+ except:
+ runner = u_boot_console_or_log.log.get_runner(cmd[0], sys.stdout)
I don't like this because:
a) It duplicates the call to get_runner(), even though both calls are
logically the same thing, just with different parameter values.
b) It can catch exceptions that occur inside get_runner(), and then
potentially repeat that call.
Better would be:
if hasattr(u_boot_console_or_log, 'get_runner'):
get_runner = u_boot_console_or_log.get_runner
else:
get_runner = u_boot_console_or_log.log.get_runner
runner = get_runner(cmd[0], sys.stdout)
Same comment for the similar change in run_and_log_expect_exception().
You could perhaps even create a helper function
get_get_runner(u_boot_console_or_log) to share the code.
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot