mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-28 02:35:28 +00:00
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>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user