[U-Boot] [PATCH v3 1/2] test/py: Pass u_boot_log instead of console for run_and_log

Stefan Brüns stefan.bruens at rwth-aachen.de
Sun Dec 11 22:58:47 CET 2016


From: Stefan Brüns <stefan.bruens at rwth-aachen.de>

The runner actually has no console dependency, only on the log provided
by the console.

Signed-off-by: Stefan Brüns <stefan.bruens at rwth-aachen.de>
---
Alternate approach to the previous patch, always pass the logfile, change
all callers accordingly.

 test/py/tests/test_dfu.py   |  2 +-
 test/py/tests/test_ums.py   | 10 +++++-----
 test/py/tests/test_vboot.py | 18 +++++++++---------
 test/py/u_boot_utils.py     | 12 ++++++------
 4 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/test/py/tests/test_dfu.py b/test/py/tests/test_dfu.py
index 585e6b29d7..b4f9a32abc 100644
--- a/test/py/tests/test_dfu.py
+++ b/test/py/tests/test_dfu.py
@@ -206,7 +206,7 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
         cmd = ['dfu-util', '-a', alt_setting, up_dn_load_arg, fn]
         if 'host_usb_port_path' in env__usb_dev_port:
             cmd += ['-p', env__usb_dev_port['host_usb_port_path']]
-        u_boot_utils.run_and_log(u_boot_console, cmd)
+        u_boot_utils.run_and_log(u_boot_console.log, cmd)
         u_boot_console.wait_for('Ctrl+C to exit ...')
 
     def dfu_write(alt_setting, fn):
diff --git a/test/py/tests/test_ums.py b/test/py/tests/test_ums.py
index 8c3ee2b053..54c47b0aee 100644
--- a/test/py/tests/test_ums.py
+++ b/test/py/tests/test_ums.py
@@ -156,7 +156,7 @@ def test_ums(u_boot_console, env__usb_dev_port, env__block_devs):
 
         u_boot_console.log.action('Mounting exported UMS device')
         cmd = ('/bin/mount', host_ums_part_node)
-        u_boot_utils.run_and_log(u_boot_console, cmd)
+        u_boot_utils.run_and_log(u_boot_console.log, cmd)
 
     def umount(ignore_errors):
         """Unmount the block device that U-Boot exports.
@@ -173,7 +173,7 @@ def test_ums(u_boot_console, env__usb_dev_port, env__block_devs):
 
         u_boot_console.log.action('Unmounting UMS device')
         cmd = ('/bin/umount', host_ums_part_node)
-        u_boot_utils.run_and_log(u_boot_console, cmd, ignore_errors)
+        u_boot_utils.run_and_log(u_boot_console.log, cmd, ignore_errors)
 
     def stop_ums(ignore_errors):
         """Stop U-Boot's ums shell command from executing.
@@ -207,11 +207,11 @@ def test_ums(u_boot_console, env__usb_dev_port, env__block_devs):
             mount()
             u_boot_console.log.action('Writing test file via UMS')
             cmd = ('rm', '-f', mounted_test_fn)
-            u_boot_utils.run_and_log(u_boot_console, cmd)
+            u_boot_utils.run_and_log(u_boot_console.log, cmd)
             if os.path.exists(mounted_test_fn):
                 raise Exception('Could not rm target UMS test file')
             cmd = ('cp', test_f.abs_fn, mounted_test_fn)
-            u_boot_utils.run_and_log(u_boot_console, cmd)
+            u_boot_utils.run_and_log(u_boot_console.log, cmd)
             ignore_cleanup_errors = False
         finally:
             umount(ignore_errors=ignore_cleanup_errors)
@@ -226,7 +226,7 @@ def test_ums(u_boot_console, env__usb_dev_port, env__block_devs):
             u_boot_console.log.action('Reading test file back via UMS')
             read_back_hash = u_boot_utils.md5sum_file(mounted_test_fn)
             cmd = ('rm', '-f', mounted_test_fn)
-            u_boot_utils.run_and_log(u_boot_console, cmd)
+            u_boot_utils.run_and_log(u_boot_console.log, cmd)
             ignore_cleanup_errors = False
         finally:
             umount(ignore_errors=ignore_cleanup_errors)
diff --git a/test/py/tests/test_vboot.py b/test/py/tests/test_vboot.py
index 6e62820743..0f893f1e91 100644
--- a/test/py/tests/test_vboot.py
+++ b/test/py/tests/test_vboot.py
@@ -50,7 +50,7 @@ def test_vboot(u_boot_console):
             dts: Device tree file to compile.
         """
         dtb = dts.replace('.dts', '.dtb')
-        util.run_and_log(cons, 'dtc %s %s%s -O dtb '
+        util.run_and_log(cons.log, 'dtc %s %s%s -O dtb '
                          '-o %s%s' % (dtc_args, datadir, dts, tmpdir, dtb))
 
     def run_bootm(sha_algo, test_type, expect_string, boots):
@@ -85,7 +85,7 @@ def test_vboot(u_boot_console):
         Args:
             its: Filename containing .its source.
         """
-        util.run_and_log(cons, [mkimage, '-D', dtc_args, '-f',
+        util.run_and_log(cons.log, [mkimage, '-D', dtc_args, '-f',
                                 '%s%s' % (datadir, its), fit])
 
     def sign_fit(sha_algo):
@@ -99,7 +99,7 @@ def test_vboot(u_boot_console):
                     use.
         """
         cons.log.action('%s: Sign images' % sha_algo)
-        util.run_and_log(cons, [mkimage, '-F', '-k', tmpdir, '-K', dtb,
+        util.run_and_log(cons.log, [mkimage, '-F', '-k', tmpdir, '-K', dtb,
                                 '-r', fit])
 
     def test_with_algo(sha_algo):
@@ -140,23 +140,23 @@ def test_vboot(u_boot_console):
 
         cons.log.action('%s: Check signed config on the host' % sha_algo)
 
-        util.run_and_log(cons, [fit_check_sign, '-f', fit, '-k', tmpdir,
+        util.run_and_log(cons.log, [fit_check_sign, '-f', fit, '-k', tmpdir,
                                 '-k', dtb])
 
         # Increment the first byte of the signature, which should cause failure
-        sig = util.run_and_log(cons, 'fdtget -t bx %s %s value' %
+        sig = util.run_and_log(cons.log, 'fdtget -t bx %s %s value' %
                                (fit, sig_node))
         byte_list = sig.split()
         byte = int(byte_list[0], 16)
         byte_list[0] = '%x' % (byte + 1)
         sig = ' '.join(byte_list)
-        util.run_and_log(cons, 'fdtput -t bx %s %s value %s' %
+        util.run_and_log(cons.log, 'fdtput -t bx %s %s value %s' %
                          (fit, sig_node, sig))
 
         run_bootm(sha_algo, 'Signed config with bad hash', 'Bad Data Hash', False)
 
         cons.log.action('%s: Check bad config on the host' % sha_algo)
-        util.run_and_log_expect_exception(cons, [fit_check_sign, '-f', fit,
+        util.run_and_log_expect_exception(cons.log, [fit_check_sign, '-f', fit,
                 '-k', dtb], 1, 'Failed to verify required signature')
 
     cons = u_boot_console
@@ -172,13 +172,13 @@ def test_vboot(u_boot_console):
 
     # Create an RSA key pair
     public_exponent = 65537
-    util.run_and_log(cons, 'openssl genpkey -algorithm RSA -out %sdev.key '
+    util.run_and_log(cons.log, 'openssl genpkey -algorithm RSA -out %sdev.key '
                      '-pkeyopt rsa_keygen_bits:2048 '
                      '-pkeyopt rsa_keygen_pubexp:%d '
                      '2>/dev/null'  % (tmpdir, public_exponent))
 
     # Create a certificate containing the public key
-    util.run_and_log(cons, 'openssl req -batch -new -x509 -key %sdev.key -out '
+    util.run_and_log(cons.log, 'openssl req -batch -new -x509 -key %sdev.key -out '
                      '%sdev.crt' % (tmpdir, tmpdir))
 
     # Create a number kernel image with zeroes
diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py
index 2ba4baed07..4c6dae3b4a 100644
--- a/test/py/u_boot_utils.py
+++ b/test/py/u_boot_utils.py
@@ -153,11 +153,11 @@ def wait_until_file_open_fails(fn, ignore_errors):
         return
     raise Exception('File can still be opened')
 
-def run_and_log(u_boot_console, cmd, ignore_errors=False):
+def run_and_log(log, cmd, ignore_errors=False):
     """Run a command and log its output.
 
     Args:
-        u_boot_console: A console connection to U-Boot.
+        log: A LogFile instance.
         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"']
@@ -171,25 +171,25 @@ 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)
+    runner = log.get_runner(cmd[0], sys.stdout)
     output = runner.run(cmd, ignore_errors=ignore_errors)
     runner.close()
     return output
 
-def run_and_log_expect_exception(u_boot_console, cmd, retcode, msg):
+def run_and_log_expect_exception(log, cmd, retcode, msg):
     """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.
 
     Args:
-        u_boot_console: A console connection to U-Boot.
+        log: A LogFile instance.
         cmd: The command to run, as an array of argv[].
         retcode: Expected non-zero return code from the command.
         msg: String that should be contained within the command's output.
     """
+    runner = log.get_runner(cmd[0], sys.stdout)
     try:
-        runner = u_boot_console.log.get_runner(cmd[0], sys.stdout)
         runner.run(cmd)
     except Exception as e:
         assert(retcode == runner.exit_status)
-- 
2.11.0



More information about the U-Boot mailing list