summaryrefslogtreecommitdiff
path: root/util/run_host_test
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2021-08-19 12:07:24 -0600
committerCommit Bot <commit-bot@chromium.org>2021-08-19 21:14:32 +0000
commit481429fd98900042dc0f6ed18f644800a5863109 (patch)
treeb08cb19fea59e80e11e88325bf47790b54889509 /util/run_host_test
parentb8bf42b33a30e11d2a97fac4e897cfde76d6ca0d (diff)
downloadchrome-ec-481429fd98900042dc0f6ed18f644800a5863109.tar.gz
run_host_test: some cleanups
Chris suggested some good cleanups in CL:3105736, but this was just a firmware-branch cherry pick of a CL from >1yr ago. Making these changes on ToT instead. Summary of the changes: - Remove obsolete __future__ import since we only run on Python 3 now. - Use explicit 0, 1, 2, 3 exit codes for success, failure, timeout, and unexpected termination (respectively). This lets us drop a property. - Read from the process in unicode mode, since we just end up decoding later anyway. - verbose argument changed from counter to boolean since there's no additional behavior created by passing multiple times. BUG=none BRANCH=none TEST=make buildall -j32 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: Ibc9de7d45f5ac1242429481c6bc5f303cdef6b06 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3107925 Commit-Queue: Chris McDonald <cjmcdonald@chromium.org> Reviewed-by: Chris McDonald <cjmcdonald@chromium.org>
Diffstat (limited to 'util/run_host_test')
-rwxr-xr-xutil/run_host_test37
1 files changed, 16 insertions, 21 deletions
diff --git a/util/run_host_test b/util/run_host_test
index c6697aaeb6..15013d91b6 100755
--- a/util/run_host_test
+++ b/util/run_host_test
@@ -6,8 +6,6 @@
"""Wrapper that runs a host test. Handles timeout and stopping the emulator."""
-from __future__ import print_function
-
import argparse
import enum
import io
@@ -21,16 +19,10 @@ import time
class TestResult(enum.Enum):
"""An Enum representing the result of running a test."""
- SUCCESS = enum.auto()
- FAIL = enum.auto()
- TIMEOUT = enum.auto()
- UNEXPECTED_TERMINATION = enum.auto()
-
- @property
- def exit_code(self):
- if self is TestResult.SUCCESS:
- return 0
- return 1
+ SUCCESS = 0
+ FAIL = 1
+ TIMEOUT = 2
+ UNEXPECTED_TERMINATION = 3
@property
def reason(self):
@@ -52,14 +44,17 @@ def run_test(path, timeout=10):
bufsize=0,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
- env=env)
+ env=env,
+ encoding='utf-8',
+ errors='replace',
+ )
# Put the output pipe in non-blocking mode. We will then select(2)
# on the pipe to know when we have bytes to process.
os.set_blocking(proc.stdout.fileno(), False)
try:
- output_buffer = io.BytesIO()
+ output_buffer = io.StringIO()
while True:
select_timeout = timeout - (time.monotonic() - start_time)
if select_timeout <= 0:
@@ -74,9 +69,9 @@ def run_test(path, timeout=10):
output_buffer.write(proc.stdout.read())
output_log = output_buffer.getvalue()
- if b'Pass!' in output_log:
+ if 'Pass!' in output_log:
return TestResult.SUCCESS, output_log
- if b'Fail!' in output_log:
+ if 'Fail!' in output_log:
return TestResult.FAIL, output_log
if proc.poll():
return TestResult.UNEXPECTED_TERMINATION, output_log
@@ -98,8 +93,8 @@ def parse_options(argv):
parser.add_argument('--coverage', action='store_const', const='coverage',
default='host', dest='test_target',
help='Flag if this is a code coverage test.')
- parser.add_argument('--verbose', '-v', action='count', default=0,
- help='Increase output verbosity.')
+ parser.add_argument('--verbose', '-v', action='store_true',
+ help='Dump emulator output always, even if successful.')
parser.add_argument('test_name', type=str)
return parser.parse_args(argv)
@@ -123,11 +118,11 @@ def main(argv):
opts.test_name, result.reason, elapsed_time),
file=sys.stderr)
- if result is not TestResult.SUCCESS or opts.verbose > 0:
+ if result is not TestResult.SUCCESS or opts.verbose:
print('====== Emulator output ======', file=sys.stderr)
- print(output.decode('utf-8'), file=sys.stderr)
+ print(output, file=sys.stderr)
print('=============================', file=sys.stderr)
- return result.exit_code
+ return result.value
if __name__ == '__main__':