From b167c7d3a67b5ca3118bc784184b7bd092be71f5 Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Tue, 14 May 2013 12:50:24 +0800 Subject: [PATCH] Redirect emulator output to stderr if a test fails If a test fails, redirect emulator output to stderr so that it shows up even when V=1 is not set. BUG=chrome-os-partner:19235 TEST=Manual BRANCH=None Change-Id: I6d8e05eaa222ebe043556bfcd3f63ca7e27c2721 Signed-off-by: Vic Yang Reviewed-on: https://gerrit.chromium.org/gerrit/51097 Reviewed-by: Vincent Palatin --- util/run_host_test | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/util/run_host_test b/util/run_host_test index bf8d8efd97..d4b64be40e 100755 --- a/util/run_host_test +++ b/util/run_host_test @@ -4,23 +4,45 @@ # 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 TIMEOUT=10 +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() + +log = StringIO() test_name = sys.argv[1] child = pexpect.spawn('build/host/{0}/{0}.exe'.format(test_name), timeout=TIMEOUT) -child.logfile = sys.stdout +child.logfile = Tee(log) result_id = child.expect([pexpect.TIMEOUT, 'Pass!', 'Fail!']) +failed = False if result_id == 0: sys.stderr.write('Test %s timed out after %d seconds!\n' % (test_name, TIMEOUT)) - sys.exit(1) + failed = True elif result_id == 1: sys.stderr.write('Test %s passed!\n' % test_name) - sys.exit(0) elif result_id == 2: sys.stderr.write('Test %s failed!\n' % test_name) + 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)