get_test_health.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python3
  2. # Copyright 2022 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. """Get test health information for a Git repository.
  6. Example Usage:
  7. tools/android/test_health/get_test_health.py \
  8. --output-file ~/test_data.jsonl \
  9. --git-dir ~/git/chromium/src \
  10. --test-dir chrome/browser/android
  11. """
  12. import argparse
  13. import logging
  14. import pathlib
  15. import time
  16. import test_health_exporter
  17. import test_health_extractor
  18. def main():
  19. parser = argparse.ArgumentParser(
  20. description='Gather Java test health information for a Git repository'
  21. ' and export it as newline-delimited JSON.')
  22. parser.add_argument('-o',
  23. '--output-file',
  24. type=pathlib.Path,
  25. required=True,
  26. help='output file path for extracted test health data')
  27. parser.add_argument('--git-dir',
  28. type=pathlib.Path,
  29. required=False,
  30. help='root directory of the Git repository to read'
  31. ' (defaults to the Chromium repo)')
  32. parser.add_argument('--test-dir',
  33. type=pathlib.Path,
  34. required=False,
  35. help='subdirectory containing the tests of interest;'
  36. ' defaults to the root of the Git repo')
  37. args = parser.parse_args()
  38. logging.info('Extracting test health data from Git repo.')
  39. start_time = time.time()
  40. test_health_list = test_health_extractor.get_repo_test_health(
  41. args.git_dir, test_dir=args.test_dir)
  42. extraction_time = time.time() - start_time
  43. logging.debug(f'--- Extraction took {extraction_time:.2f} seconds ---')
  44. logging.info('Exporting test health data to file: ' +
  45. str(args.output_file))
  46. export_start_time = time.time()
  47. test_health_exporter.to_json_file(test_health_list, args.output_file)
  48. export_time = time.time() - export_start_time
  49. logging.debug(f'--- Export took {export_time:.2f} seconds ---')
  50. total_time = time.time() - start_time
  51. logging.debug(f'--- Took {total_time:.2f} seconds ---')
  52. if __name__ == '__main__':
  53. main()