1 #!/usr/bin/env python 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. 5 6 import argparse 7 import sys 8 9 10 def _ExtractQueuedTestName(line): 11 _, test_name, _ = line.split(' ') 12 return test_name 13 14 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]) 19 else: 20 test_time = float(test_time_string[:-1]) 21 return test_name, test_time 22 23 24 def _IsQueued(line): 25 return line.endswith(' queued') 26 27 28 def _IsPassed(line): 29 return 'passed' in line.split(' ') 30 31 32 def _ProcessLogFile(file_path): 33 passed_unittests = [] 34 queued_unittests = [] 35 with open(file_path, 'r') as f: 36 for line in f: 37 line = line.strip() 38 if not line.startswith('['): 39 continue 40 if _IsQueued(line): 41 queued_unittests.append(_ExtractQueuedTestName(line)) 42 elif _IsPassed(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 47 48 49 def main(args): 50 parser = argparse.ArgumentParser( 51 description=('Process telemetry unittests log to print out passed ' 52 'or queued tests.')) 53 parser.add_argument( 54 'filepath', help='path to log file of telemetry unittest') 55 parser.add_argument( 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: 62 print test, time 63 if options.list_queued_tests: 64 print 'All queued telemetry unittests:\n' 65 print '\n'.join(queued_unittests) 66 return 0 67 68 69 if __name__ == '__main__': 70 sys.exit(main(sys.argv[1:])) 71