diff options
Diffstat (limited to 'test/py/u_boot_utils.py')
-rw-r--r-- | test/py/u_boot_utils.py | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py index e358c58..2ba4bae 100644 --- a/test/py/u_boot_utils.py +++ b/test/py/u_boot_utils.py @@ -158,7 +158,9 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False): Args: u_boot_console: A console connection to U-Boot. - cmd: The command to run, as an array of argv[]. + cmd: The command to run, as an array of argv[], or a string. + If a string, note that it is split up so that quoted spaces + will not be preserved. E.g. "fred and" becomes ['"fred', 'and"'] 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 @@ -167,26 +169,15 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False): Returns: The output as a string. """ - + if isinstance(cmd, str): + cmd = cmd.split() runner = u_boot_console.log.get_runner(cmd[0], sys.stdout) output = runner.run(cmd, ignore_errors=ignore_errors) runner.close() return output -def cmd(u_boot_console, cmd_str): - """Run a single command string and log its output. - - Args: - u_boot_console: A console connection to U-Boot. - cmd: The command to run, as a string. - - Returns: - The output as a string. - """ - return run_and_log(u_boot_console, cmd_str.split()) - def run_and_log_expect_exception(u_boot_console, cmd, retcode, msg): - """Run a command which is expected to fail. + """Run a command that is expected to fail. This runs a command and checks that it fails with the expected return code and exception method. If not, an exception is raised. @@ -195,15 +186,17 @@ def run_and_log_expect_exception(u_boot_console, cmd, retcode, msg): u_boot_console: A console connection to U-Boot. cmd: The command to run, as an array of argv[]. retcode: Expected non-zero return code from the command. - msg: String which should be contained within the command's output. + msg: String that should be contained within the command's output. """ try: runner = u_boot_console.log.get_runner(cmd[0], sys.stdout) runner.run(cmd) except Exception as e: + assert(retcode == runner.exit_status) assert(msg in runner.output) else: - raise Exception('Expected exception, but not raised') + raise Exception("Expected an exception with retcode %d message '%s'," + "but it was not raised" % (retcode, msg)) finally: runner.close() |