Skip to content

Commit a7bdce2

Browse files
jbergstroemrvagg
authored andcommitted
test: support writing test output to file
This is a minimal effort to support test output written both to stdout and file in order to get our buildbots understanding test output. PR-URL: #934 Reviewed-By: Chris Dickinson <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent ed3b057 commit a7bdce2

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

tools/test.py

+20-8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030

3131
import imp
32+
import logging
3233
import optparse
3334
import os
3435
import platform
@@ -47,6 +48,8 @@
4748
from datetime import datetime
4849
from Queue import Queue, Empty
4950

51+
logger = logging.getLogger('testrunner')
52+
5053
VERBOSE = False
5154

5255

@@ -237,7 +240,7 @@ def HasRun(self, output):
237240
class TapProgressIndicator(SimpleProgressIndicator):
238241

239242
def Starting(self):
240-
print '1..%i' % len(self.cases)
243+
logger.info('1..%i' % len(self.cases))
241244
self._done = 0
242245

243246
def AboutToRun(self, case):
@@ -247,23 +250,23 @@ def HasRun(self, output):
247250
self._done += 1
248251
command = basename(output.command[-1])
249252
if output.UnexpectedOutput():
250-
print 'not ok %i - %s' % (self._done, command)
253+
logger.info('not ok %i - %s' % (self._done, command))
251254
for l in output.output.stderr.splitlines():
252-
print '#' + l
255+
logger.info('#' + l)
253256
for l in output.output.stdout.splitlines():
254-
print '#' + l
257+
logger.info('#' + l)
255258
else:
256-
print 'ok %i - %s' % (self._done, command)
259+
logger.info('ok %i - %s' % (self._done, command))
257260

258261
duration = output.test.duration
259262

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

264-
print ' ---'
265-
print ' duration_ms: %d.%d' % (total_seconds, duration.microseconds / 1000)
266-
print ' ...'
267+
logger.info(' ---')
268+
logger.info(' duration_ms: %d.%d' % (total_seconds, duration.microseconds / 1000))
269+
logger.info(' ...')
267270

268271
def Done(self):
269272
pass
@@ -1216,6 +1219,8 @@ def BuildOptions():
12161219
default='release')
12171220
result.add_option("-v", "--verbose", help="Verbose output",
12181221
default=False, action="store_true")
1222+
result.add_option('--logfile', dest='logfile',
1223+
help='write test output to file. NOTE: this only applies the tap progress indicator')
12191224
result.add_option("-S", dest="scons_flags", help="Flag to pass through to scons",
12201225
default=[], action="append")
12211226
result.add_option("-p", "--progress",
@@ -1359,6 +1364,13 @@ def Main():
13591364
parser.print_help()
13601365
return 1
13611366

1367+
ch = logging.StreamHandler(sys.stdout)
1368+
logger.addHandler(ch)
1369+
logger.setLevel('INFO')
1370+
if options.logfile:
1371+
fh = logging.FileHandler(options.logfile)
1372+
logger.addHandler(fh)
1373+
13621374
workspace = abspath(join(dirname(sys.argv[0]), '..'))
13631375
suites = GetSuites(join(workspace, 'test'))
13641376
repositories = [TestRepository(join(workspace, 'test', name)) for name in suites]

0 commit comments

Comments
 (0)