mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-29 18:11:05 +00:00
If a host test fails, record the execution state of the EC host process. This is an attempt to provide a hint whether the test was blocked on I/O, if so it might be in 'D' state (but it might have recovered too late too). Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=none BUG=chromium:715011 TEST=run 'make runtests -j', then run it again with TIMEOUT reduced to 1 see it fail on 'kb_scan' and 'interrupt' tests with the trace containing '*** test [...] in state Ssl+ ***' Change-Id: I4590a4b84a2aba8d385d3ef911d5d0186e8ce2e3 Reviewed-on: https://chromium-review.googlesource.com/859771 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
84 lines
2.2 KiB
Python
Executable File
84 lines
2.2 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 signal
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
TIMEOUT=10
|
|
|
|
RESULT_ID_TIMEOUT = 0
|
|
RESULT_ID_PASS = 1
|
|
RESULT_ID_FAIL = 2
|
|
RESULT_ID_EOF = 3
|
|
|
|
EXPECT_LIST = [pexpect.TIMEOUT, 'Pass!', 'Fail!', pexpect.EOF]
|
|
|
|
PS_ARGS = ['ps', '--no-headers', '-o', 'stat', '--pid']
|
|
|
|
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):
|
|
child = pexpect.spawn('build/host/{0}/{0}.exe'.format(test_name),
|
|
timeout=TIMEOUT)
|
|
child.logfile = log
|
|
try:
|
|
return child.expect(EXPECT_LIST)
|
|
finally:
|
|
if child.isalive():
|
|
ps_cmd = PS_ARGS + ['%d' % (child.pid)]
|
|
ps_stat = subprocess.check_output(ps_cmd).strip()
|
|
log.write('\n*** test %s process %d in state %s ***\n' %
|
|
(test_name, child.pid, ps_stat))
|
|
child.kill(signal.SIGTERM)
|
|
child.read()
|
|
|
|
log = StringIO()
|
|
tee_log = Tee(log)
|
|
test_name = sys.argv[1]
|
|
start_time = time.time()
|
|
|
|
result_id = RunOnce(test_name, tee_log)
|
|
|
|
elapsed_time = time.time() - start_time
|
|
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))
|
|
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')
|
|
sys.stderr.write(log.getvalue())
|
|
sys.stderr.write('\n=============================\n')
|
|
sys.exit(1)
|
|
else:
|
|
sys.exit(0)
|