Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: support writing test output to file #934

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@


import imp
import logging
import optparse
import os
import platform
Expand All @@ -47,6 +48,8 @@
from datetime import datetime
from Queue import Queue, Empty

logger = logging.getLogger('testrunner')

VERBOSE = False


Expand Down Expand Up @@ -237,7 +240,7 @@ def HasRun(self, output):
class TapProgressIndicator(SimpleProgressIndicator):

def Starting(self):
print '1..%i' % len(self.cases)
logger.info('1..%i' % len(self.cases))
self._done = 0

def AboutToRun(self, case):
Expand All @@ -247,23 +250,23 @@ def HasRun(self, output):
self._done += 1
command = basename(output.command[-1])
if output.UnexpectedOutput():
print 'not ok %i - %s' % (self._done, command)
logger.info('not ok %i - %s' % (self._done, command))
for l in output.output.stderr.splitlines():
print '#' + l
logger.info('#' + l)
for l in output.output.stdout.splitlines():
print '#' + l
logger.info('#' + l)
else:
print 'ok %i - %s' % (self._done, command)
logger.info('ok %i - %s' % (self._done, command))

duration = output.test.duration

# total_seconds() was added in 2.7
total_seconds = (duration.microseconds +
(duration.seconds + duration.days * 24 * 3600) * 10**6) / 10**6

print ' ---'
print ' duration_ms: %d.%d' % (total_seconds, duration.microseconds / 1000)
print ' ...'
logger.info(' ---')
logger.info(' duration_ms: %d.%d' % (total_seconds, duration.microseconds / 1000))
logger.info(' ...')

def Done(self):
pass
Expand Down Expand Up @@ -1216,6 +1219,8 @@ def BuildOptions():
default='release')
result.add_option("-v", "--verbose", help="Verbose output",
default=False, action="store_true")
result.add_option('--logfile', dest='logfile',
help='write test output to file. NOTE: this only applies the tap progress indicator')
result.add_option("-S", dest="scons_flags", help="Flag to pass through to scons",
default=[], action="append")
result.add_option("-p", "--progress",
Expand Down Expand Up @@ -1359,6 +1364,13 @@ def Main():
parser.print_help()
return 1

ch = logging.StreamHandler(sys.stdout)
logger.addHandler(ch)
logger.setLevel('INFO')
if options.logfile:
fh = logging.FileHandler(options.logfile)
logger.addHandler(fh)

workspace = abspath(join(dirname(sys.argv[0]), '..'))
suites = GetSuites(join(workspace, 'test'))
repositories = [TestRepository(join(workspace, 'test', name)) for name in suites]
Expand Down