aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSimon Glass2016-07-03 09:40:41 -0600
committerTom Rini2016-07-14 18:22:35 -0400
commit9e17b0345afe198490689d9f36fab3849e9ef69a (patch)
tree3a2f99565fb278053389a72c8fb179069efeb8ce /test
parent8b304a37df13477f02fca5a6f5eaa3e55d7b4bf1 (diff)
test/py: Provide a way to check that a command fails
Sometimes we want to run a command and check that it fails. Add a function to handle this. It can check the return code and also make sure that the output contains a given error message. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/py/u_boot_utils.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py
index ce0bbcf763a..e358c585bf8 100644
--- a/test/py/u_boot_utils.py
+++ b/test/py/u_boot_utils.py
@@ -185,6 +185,28 @@ def cmd(u_boot_console, cmd_str):
"""
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.
+
+ This runs a command and checks that it fails with the expected return code
+ and exception method. If not, an exception is raised.
+
+ Args:
+ 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.
+ """
+ try:
+ runner = u_boot_console.log.get_runner(cmd[0], sys.stdout)
+ runner.run(cmd)
+ except Exception as e:
+ assert(msg in runner.output)
+ else:
+ raise Exception('Expected exception, but not raised')
+ finally:
+ runner.close()
+
ram_base = None
def find_ram_base(u_boot_console):
"""Find the running U-Boot's RAM location.