mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-28 02:35:28 +00:00
With this, the emulator is able to reboot itself without the help of run_host_test script. This makes it easier for development and also speeds up the test. BUG=chrome-os-partner:19235 TEST=Pass all tests BRANCH=None Change-Id: Ifa510442de19256c671ab91b6bc75fe9e8b9dc7b Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/62969 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
72 lines
1.7 KiB
Python
Executable File
72 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
from cStringIO import StringIO
|
|
import pexpect
|
|
import sys
|
|
import time
|
|
|
|
TIMEOUT=10
|
|
|
|
RESULT_ID_TIMEOUT = 0
|
|
RESULT_ID_PASS = 1
|
|
RESULT_ID_FAIL = 2
|
|
|
|
EXPECT_LIST = [pexpect.TIMEOUT, 'Pass!', 'Fail!']
|
|
|
|
class Tee(object):
|
|
def __init__(self, target):
|
|
self._target = target
|
|
|
|
def write(self, data):
|
|
sys.stdout.write(data)
|
|
self._target.write(data)
|
|
|
|
def flush(self):
|
|
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()
|
|
raise
|
|
finally:
|
|
child.kill(15)
|
|
|
|
log = StringIO()
|
|
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())
|
|
|
|
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))
|
|
failed = True
|
|
elif result_id == RESULT_ID_PASS:
|
|
sys.stderr.write('Test %s passed! (%.3f seconds)\n' %
|
|
(test_name, elapsed_time))
|
|
elif result_id == RESULT_ID_FAIL:
|
|
sys.stderr.write('Test %s failed! (%.3f seconds)\n' %
|
|
(test_name, elapsed_time))
|
|
failed = True
|
|
|
|
if failed:
|
|
sys.stderr.write('\n====== Emulator output ======\n')
|
|
sys.stderr.write(log.getvalue())
|
|
sys.stderr.write('\n=============================\n')
|
|
sys.exit(1)
|
|
else:
|
|
sys.exit(0)
|