2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
10 def _ExtractQueuedTestName(line
):
11 _
, test_name
, _
= line
.split(' ')
15 def _ExtractPassedTestNameAndTime(line
):
16 _
, test_name
, _
, test_time_string
= line
.split(' ')
17 if test_time_string
.endswith(':'):
18 test_time
= float(test_time_string
[:-2])
20 test_time
= float(test_time_string
[:-1])
21 return test_name
, test_time
25 return line
.endswith(' queued')
29 return 'passed' in line
.split(' ')
32 def _ProcessLogFile(file_path
):
35 with
open(file_path
, 'r') as f
:
38 if not line
.startswith('['):
41 queued_unittests
.append(_ExtractQueuedTestName(line
))
43 passed_unittests
.append(_ExtractPassedTestNameAndTime(line
))
44 queued_unittests
.sort()
45 passed_unittests
.sort(key
=lambda v
: -v
[1])
46 return queued_unittests
, passed_unittests
50 parser
= argparse
.ArgumentParser(
51 description
=('Process telemetry unittests log to print out passed '
54 'filepath', help='path to log file of telemetry unittest')
56 '-q', '--list-queued-tests', action
='store_true',
57 help='Also list all the queued telemetry unittests')
58 options
= parser
.parse_args(args
)
59 queued_unittests
, passed_unittests
= _ProcessLogFile(options
.filepath
)
60 print 'All passed telemetry unittests:\n'
61 for test
, time
in passed_unittests
:
63 if options
.list_queued_tests
:
64 print 'All queued telemetry unittests:\n'
65 print '\n'.join(queued_unittests
)
69 if __name__
== '__main__':
70 sys
.exit(main(sys
.argv
[1:]))