diff options
author | Vic (Chun-Ju) Yang <victoryang@chromium.org> | 2014-01-10 11:50:18 +0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-01-15 04:52:54 +0000 |
commit | 361731dc588c1e38202b554e5153197d64477259 (patch) | |
tree | 2785518f1395772bb9f6343edfa779f32a052671 /util | |
parent | 5edde63ac253c98ddb8a5c8584b766f09336d49c (diff) | |
download | chrome-ec-361731dc588c1e38202b554e5153197d64477259.tar.gz |
Clean up run_host_test script
This includes:
- Remove an unused function argument
- Style fix
- Handle EOF by pexpect instead of catching exception
BUG=chrome-os-partner:19235
TEST=Run all tests
TEST=Make a test crash and check EOF is handled properly
BRANCH=None
Change-Id: I3636cdab6e68cacf97c4b245b14b2d57613a1674
Signed-off-by: Vic (Chun-Ju) Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/182049
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'util')
-rwxr-xr-x | util/run_host_test | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/util/run_host_test b/util/run_host_test index c25374b95f..c130b822fb 100755 --- a/util/run_host_test +++ b/util/run_host_test @@ -15,8 +15,9 @@ TIMEOUT=10 RESULT_ID_TIMEOUT = 0 RESULT_ID_PASS = 1 RESULT_ID_FAIL = 2 +RESULT_ID_EOF = 3 -EXPECT_LIST = [pexpect.TIMEOUT, 'Pass!', 'Fail!'] +EXPECT_LIST = [pexpect.TIMEOUT, 'Pass!', 'Fail!', pexpect.EOF] class Tee(object): def __init__(self, target): @@ -30,15 +31,12 @@ class Tee(object): sys.stdout.flush() self._target.flush() -def RunOnce(test_name, log, timeout_secs): +def RunOnce(test_name, log): child = pexpect.spawn('build/host/{0}/{0}.exe'.format(test_name), - timeout=TIMEOUT) + timeout=TIMEOUT) child.logfile = log try: return child.expect(EXPECT_LIST) - except pexpect.EOF: - child.close() - return RESULT_ID_FAIL finally: if child.isalive(): child.kill(signal.SIGTERM) @@ -49,10 +47,9 @@ tee_log = Tee(log) test_name = sys.argv[1] start_time = time.time() -result_id = RunOnce(test_name, tee_log, start_time + TIMEOUT - time.time()) +result_id = RunOnce(test_name, tee_log) elapsed_time = time.time() - start_time -failed = False if result_id == RESULT_ID_TIMEOUT: sys.stderr.write('Test %s timed out after %d seconds!\n' % (test_name, TIMEOUT)) @@ -60,10 +57,15 @@ if result_id == RESULT_ID_TIMEOUT: elif result_id == RESULT_ID_PASS: sys.stderr.write('Test %s passed! (%.3f seconds)\n' % (test_name, elapsed_time)) + failed = False elif result_id == RESULT_ID_FAIL: sys.stderr.write('Test %s failed! (%.3f seconds)\n' % (test_name, elapsed_time)) failed = True +elif result_id == RESULT_ID_EOF: + sys.stderr.write('Test %s terminated unexpectedly! (%.3f seconds)\n' % + (test_name, elapsed_time)) + failed = True if failed: sys.stderr.write('\n====== Emulator output ======\n') |