
Hi Stephen,
On 20 January 2016 at 15:15, Stephen Warren swarren@wwwdotorg.org wrote:
From: Stephen Warren swarren@nvidia.com
Add various common utility functions. These will be used by a forthcoming re-written UMS test, and a brand-new DFU test.
Signed-off-by: Stephen Warren swarren@nvidia.com
test/py/u_boot_console_base.py | 19 +++++ test/py/u_boot_utils.py | 171 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 test/py/u_boot_utils.py
Acked-by: Simon Glass sjg@chromium.org
diff --git a/test/py/u_boot_console_base.py b/test/py/u_boot_console_base.py index 433bec6e9fdd..06f61f987180 100644 --- a/test/py/u_boot_console_base.py +++ b/test/py/u_boot_console_base.py @@ -215,6 +215,25 @@ class ConsoleBase(object): self.log.action('Sending Ctrl-C') self.run_command(chr(3), wait_for_echo=False, send_nl=False)
- def wait_for(self, text):
'''Wait for a pattern to be emitted by U-Boot.
I meant to say we should use """ for function comments to keep it consistent with the rest of U-Boot. Maybe could adjust this in a follow-on patch?
This is useful when a long-running command such as "dfu" is executing,
and it periodically emits some text that should show up at a specific
location in the log file.
Args:
text: The text to wait for; either a string (containing raw text,
not a regular expression) or an re object.
Returns:
Nothing.
'''
if type(text) == type(''):
text = re.escape(text)
self.p.expect([text])
Does this potentially wait forever?
- def drain_console(self): '''Read from and log the U-Boot console for a short time.
diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py new file mode 100644 index 000000000000..539af618dbf2 --- /dev/null +++ b/test/py/u_boot_utils.py @@ -0,0 +1,171 @@ +# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. +# +# SPDX-License-Identifier: GPL-2.0
+# Utility code shared across multiple tests.
+import hashlib +import os +import os.path +import sys +import time
+def md5sum_data(data):
- '''Calculate the MD5 hash of some data.
- Args:
data: The data to hash.
- Returns:
The hash of the data, as a binary string.
- '''
- h = hashlib.md5()
- h.update(data)
- return h.digest()
Or just:
return hashlib.md5().update(data).digest()
Regards, Simon