diff options
author | Vic Yang <victoryang@chromium.org> | 2013-05-26 16:51:37 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-05-28 12:53:55 -0700 |
commit | f4654f6d996449a6c9f1947bb6bb3760fa2a47eb (patch) | |
tree | cf1e1f62552357cebcfe3a895f0bfa4875c2b5db | |
parent | a46d5e7f3700e126c6bc5c31f93a8f297e11074f (diff) | |
download | chrome-ec-f4654f6d996449a6c9f1947bb6bb3760fa2a47eb.tar.gz |
Support emulator reboot
When emulator exits with reboot exit code, we should run the emulator
again.
BUG=chrome-os-partner:19235
TEST=Enable flash test on emulator. See it reboots.
BRANCH=None
Change-Id: Id0b4c21c1be7ae978be8b336a3498181d881c715
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/56701
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rwxr-xr-x | util/run_host_test | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/util/run_host_test b/util/run_host_test index 5a169d1089..b70b0eb80b 100755 --- a/util/run_host_test +++ b/util/run_host_test @@ -11,6 +11,15 @@ import time TIMEOUT=10 +EXIT_CODE_REBOOT = (1 << 6) + +RESULT_ID_TIMEOUT = 0 +RESULT_ID_PASS = 1 +RESULT_ID_FAIL = 2 +RESULT_ID_REBOOT = 3 + +EXPECT_LIST = [pexpect.TIMEOUT, 'Pass!', 'Fail!'] + class Tee(object): def __init__(self, target): self._target = target @@ -23,23 +32,39 @@ class Tee(object): sys.stdout.flush() self._target.flush() +def RunOnce(test_name, log, timeout_secs): + child = pexpect.spawn('build/host/{0}/{0}.exe'.format(test_name), + timeout=TIMEOUT) + child.logfile = log + try: + return child.expect(EXPECT_LIST) + except pexpect.EOF: + child.close() + if child.exitstatus & EXIT_CODE_REBOOT: + sys.stderr.write('System rebooting\n') + return RESULT_ID_REBOOT + else: + raise + log = StringIO() +tee_log = Tee(log) test_name = sys.argv[1] start_time = time.time() -child = pexpect.spawn('build/host/{0}/{0}.exe'.format(test_name), - timeout=TIMEOUT) -child.logfile = Tee(log) -result_id = child.expect([pexpect.TIMEOUT, 'Pass!', 'Fail!']) + +result_id = RESULT_ID_REBOOT +while result_id == RESULT_ID_REBOOT: + result_id = RunOnce(test_name, tee_log, start_time + TIMEOUT - time.time()) + elapsed_time = time.time() - start_time failed = False -if result_id == 0: +if result_id == RESULT_ID_TIMEOUT: sys.stderr.write('Test %s timed out after %d seconds!\n' % (test_name, TIMEOUT)) failed = True -elif result_id == 1: +elif result_id == RESULT_ID_PASS: sys.stderr.write('Test %s passed! (%.3f seconds)\n' % (test_name, elapsed_time)) -elif result_id == 2: +elif result_id == RESULT_ID_FAIL: sys.stderr.write('Test %s failed! (%.3f seconds)\n' % (test_name, elapsed_time)) failed = True |