Skip to content
Snippets Groups Projects
Commit ec70f8a9 authored by Simon Glass's avatar Simon Glass Committed by Tom Rini
Browse files

test: Drop the cmd() function


Instead of this, use the existing run_and_log() function, enhanced to
support a command string as well as a list of arguments.

Suggested-by: default avatarStephen Warren <swarren@nvidia.com>

Signed-off-by: default avatarSimon Glass <sjg@chromium.org>
parent 72f52268
Branches
Tags
No related merge requests found
...@@ -50,7 +50,7 @@ def test_vboot(u_boot_console): ...@@ -50,7 +50,7 @@ def test_vboot(u_boot_console):
dts: Device tree file to compile. dts: Device tree file to compile.
""" """
dtb = dts.replace('.dts', '.dtb') dtb = dts.replace('.dts', '.dtb')
util.cmd(cons, 'dtc %s %s%s -O dtb ' util.run_and_log(cons, 'dtc %s %s%s -O dtb '
'-o %s%s' % (dtc_args, datadir, dts, tmpdir, dtb)) '-o %s%s' % (dtc_args, datadir, dts, tmpdir, dtb))
def run_bootm(test_type, expect_string): def run_bootm(test_type, expect_string):
...@@ -138,12 +138,14 @@ def test_vboot(u_boot_console): ...@@ -138,12 +138,14 @@ def test_vboot(u_boot_console):
'-k', dtb]) '-k', dtb])
# Increment the first byte of the signature, which should cause failure # Increment the first byte of the signature, which should cause failure
sig = util.cmd(cons, 'fdtget -t bx %s %s value' % (fit, sig_node)) sig = util.run_and_log(cons, 'fdtget -t bx %s %s value' %
(fit, sig_node))
byte_list = sig.split() byte_list = sig.split()
byte = int(byte_list[0], 16) byte = int(byte_list[0], 16)
byte_list[0] = '%x' % (byte + 1) byte_list[0] = '%x' % (byte + 1)
sig = ' '.join(byte_list) sig = ' '.join(byte_list)
util.cmd(cons, 'fdtput -t bx %s %s value %s' % (fit, sig_node, sig)) util.run_and_log(cons, 'fdtput -t bx %s %s value %s' %
(fit, sig_node, sig))
run_bootm('Signed config with bad hash', 'Bad Data Hash') run_bootm('Signed config with bad hash', 'Bad Data Hash')
...@@ -164,13 +166,13 @@ def test_vboot(u_boot_console): ...@@ -164,13 +166,13 @@ def test_vboot(u_boot_console):
# Create an RSA key pair # Create an RSA key pair
public_exponent = 65537 public_exponent = 65537
util.cmd(cons, 'openssl genpkey -algorithm RSA -out %sdev.key ' util.run_and_log(cons, 'openssl genpkey -algorithm RSA -out %sdev.key '
'-pkeyopt rsa_keygen_bits:2048 ' '-pkeyopt rsa_keygen_bits:2048 '
'-pkeyopt rsa_keygen_pubexp:%d ' '-pkeyopt rsa_keygen_pubexp:%d '
'2>/dev/null' % (tmpdir, public_exponent)) '2>/dev/null' % (tmpdir, public_exponent))
# Create a certificate containing the public key # Create a certificate containing the public key
util.cmd(cons, 'openssl req -batch -new -x509 -key %sdev.key -out ' util.run_and_log(cons, 'openssl req -batch -new -x509 -key %sdev.key -out '
'%sdev.crt' % (tmpdir, tmpdir)) '%sdev.crt' % (tmpdir, tmpdir))
# Create a number kernel image with zeroes # Create a number kernel image with zeroes
......
...@@ -158,7 +158,9 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False): ...@@ -158,7 +158,9 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False):
Args: Args:
u_boot_console: A console connection to U-Boot. 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 ignore_errors: Indicate whether to ignore errors. If True, the function
will simply return if the command cannot be executed or exits with will simply return if the command cannot be executed or exits with
an error code, otherwise an exception will be raised if such an error code, otherwise an exception will be raised if such
...@@ -167,24 +169,13 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False): ...@@ -167,24 +169,13 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False):
Returns: Returns:
The output as a string. The output as a string.
""" """
if isinstance(cmd, str):
cmd = cmd.split()
runner = u_boot_console.log.get_runner(cmd[0], sys.stdout) runner = u_boot_console.log.get_runner(cmd[0], sys.stdout)
output = runner.run(cmd, ignore_errors=ignore_errors) output = runner.run(cmd, ignore_errors=ignore_errors)
runner.close() runner.close()
return output 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): def run_and_log_expect_exception(u_boot_console, cmd, retcode, msg):
"""Run a command that is expected to fail. """Run a command that is expected to fail.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment