list_telemetry_unittests 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. import argparse
  6. import sys
  7. def _ExtractQueuedTestName(line):
  8. _, test_name, _ = line.split(' ')
  9. return test_name
  10. def _ExtractPassedTestNameAndTime(line):
  11. _, test_name, _, test_time_string = line.split(' ')
  12. if test_time_string.endswith(':'):
  13. test_time = float(test_time_string[:-2])
  14. else:
  15. test_time = float(test_time_string[:-1])
  16. return test_name, test_time
  17. def _IsQueued(line):
  18. return line.endswith(' queued')
  19. def _IsPassed(line):
  20. return 'passed' in line.split(' ')
  21. def _ProcessLogFile(file_path):
  22. passed_unittests = []
  23. queued_unittests = []
  24. with open(file_path, 'r') as f:
  25. for line in f:
  26. line = line.strip()
  27. if not line.startswith('['):
  28. continue
  29. if _IsQueued(line):
  30. queued_unittests.append(_ExtractQueuedTestName(line))
  31. elif _IsPassed(line):
  32. passed_unittests.append(_ExtractPassedTestNameAndTime(line))
  33. queued_unittests.sort()
  34. passed_unittests.sort(key=lambda v: -v[1])
  35. return queued_unittests, passed_unittests
  36. def main(args):
  37. parser = argparse.ArgumentParser(
  38. description=('Process telemetry unittests log to print out passed '
  39. 'or queued tests.'))
  40. parser.add_argument(
  41. 'filepath', help='path to log file of telemetry unittest')
  42. parser.add_argument(
  43. '-q', '--list-queued-tests', action='store_true',
  44. help='Also list all the queued telemetry unittests')
  45. options = parser.parse_args(args)
  46. queued_unittests, passed_unittests = _ProcessLogFile(options.filepath)
  47. print 'All passed telemetry unittests:\n'
  48. for test, time in passed_unittests:
  49. print test, time
  50. if options.list_queued_tests:
  51. print 'All queued telemetry unittests:\n'
  52. print '\n'.join(queued_unittests)
  53. return 0
  54. if __name__ == '__main__':
  55. sys.exit(main(sys.argv[1:]))