OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Generates incremental code coverage reports for Java code in Chromium. | 6 """Generates incremental code coverage reports for Java code in Chromium. |
7 | 7 |
8 Usage: | 8 Usage: |
9 | 9 |
10 build/android/emma_coverage_stats.py -v --out <output file path> --emma-dir | 10 build/android/emma_coverage_stats.py -v --out <output file path> --emma-dir |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 return None | 293 return None |
294 emma_file = self._source_to_emma[file_path] | 294 emma_file = self._source_to_emma[file_path] |
295 total_line_coverage = self._emma_parser.GetLineCoverage(emma_file) | 295 total_line_coverage = self._emma_parser.GetLineCoverage(emma_file) |
296 incremental_line_coverage = [line for line in total_line_coverage | 296 incremental_line_coverage = [line for line in total_line_coverage |
297 if line.lineno in line_numbers] | 297 if line.lineno in line_numbers] |
298 line_by_line_coverage = [ | 298 line_by_line_coverage = [ |
299 { | 299 { |
300 'line': line.source, | 300 'line': line.source, |
301 'coverage': line.covered_status, | 301 'coverage': line.covered_status, |
302 'changed': line.lineno in line_numbers, | 302 'changed': line.lineno in line_numbers, |
| 303 'fractional_coverage': line.fractional_line_coverage, |
303 } | 304 } |
304 for line in total_line_coverage | 305 for line in total_line_coverage |
305 ] | 306 ] |
306 total_covered_lines, total_lines = ( | 307 total_covered_lines, total_lines = ( |
307 self.GetSummaryStatsForLines(total_line_coverage)) | 308 self.GetSummaryStatsForLines(total_line_coverage)) |
308 incremental_covered_lines, incremental_total_lines = ( | 309 incremental_covered_lines, incremental_total_lines = ( |
309 self.GetSummaryStatsForLines(incremental_line_coverage)) | 310 self.GetSummaryStatsForLines(incremental_line_coverage)) |
310 | 311 |
311 file_coverage_stats = { | 312 file_coverage_stats = { |
312 'absolute': { | 313 'absolute': { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 389 |
389 Args: | 390 Args: |
390 file_path: A string representing path to the file. | 391 file_path: A string representing path to the file. |
391 | 392 |
392 Returns: | 393 Returns: |
393 True for Java files that exist, False for all others. | 394 True for Java files that exist, False for all others. |
394 """ | 395 """ |
395 if os.path.splitext(file_path)[1] == '.java' and os.path.exists(file_path): | 396 if os.path.splitext(file_path)[1] == '.java' and os.path.exists(file_path): |
396 return True | 397 return True |
397 else: | 398 else: |
398 logging.debug( | 399 logging.info('Skipping file %s, cannot compute code coverage.', file_path) |
399 'Skipping file %s, cannot compute code coverage.', file_path) | |
400 return False | 400 return False |
401 | 401 |
402 @staticmethod | 402 @staticmethod |
403 def GetPackageNameFromFile(file_path): | 403 def GetPackageNameFromFile(file_path): |
404 """Gets the full package name including the file name for a given file path. | 404 """Gets the full package name including the file name for a given file path. |
405 | 405 |
406 Args: | 406 Args: |
407 file_path: String representing the path to the Java source file. | 407 file_path: String representing the path to the Java source file. |
408 | 408 |
409 Returns: | 409 Returns: |
(...skipping 28 matching lines...) Expand all Loading... |
438 with open(line_coverage_file) as f: | 438 with open(line_coverage_file) as f: |
439 potential_files_for_coverage = json.load(f) | 439 potential_files_for_coverage = json.load(f) |
440 | 440 |
441 files_for_coverage = {f: lines | 441 files_for_coverage = {f: lines |
442 for f, lines in potential_files_for_coverage.iteritems() | 442 for f, lines in potential_files_for_coverage.iteritems() |
443 if _EmmaCoverageStats.NeedsCoverage(f)} | 443 if _EmmaCoverageStats.NeedsCoverage(f)} |
444 | 444 |
445 coverage_results = {} | 445 coverage_results = {} |
446 if files_for_coverage: | 446 if files_for_coverage: |
447 code_coverage = _EmmaCoverageStats(coverage_dir, files_for_coverage.keys()) | 447 code_coverage = _EmmaCoverageStats(coverage_dir, files_for_coverage.keys()) |
448 coverage_results = code_coverage.GetCoverageDict( | 448 coverage_results = code_coverage.GetCoverageDict(files_for_coverage) |
449 files_for_coverage) | |
450 else: | 449 else: |
451 logging.info('No Java files requiring coverage were included in %s.', | 450 logging.info('No Java files requiring coverage were included in %s.', |
452 line_coverage_file) | 451 line_coverage_file) |
453 | 452 |
454 with open(out_file_path, 'w+') as out_status_file: | 453 with open(out_file_path, 'w+') as out_status_file: |
455 json.dump(coverage_results, out_status_file) | 454 json.dump(coverage_results, out_status_file) |
456 | 455 |
457 | 456 |
458 def main(): | 457 def main(): |
459 argparser = argparse.ArgumentParser() | 458 argparser = argparse.ArgumentParser() |
460 argparser.add_argument('--out', required=True, type=str, | 459 argparser.add_argument('--out', required=True, type=str, |
461 help='Report output file path.') | 460 help='Report output file path.') |
462 argparser.add_argument('--emma-dir', required=True, type=str, | 461 argparser.add_argument('--emma-dir', required=True, type=str, |
463 help='EMMA HTML report directory.') | 462 help='EMMA HTML report directory.') |
464 argparser.add_argument('--lines-for-coverage-file', required=True, type=str, | 463 argparser.add_argument('--lines-for-coverage-file', required=True, type=str, |
465 help='File containing a JSON object. Should contain a ' | 464 help='File containing a JSON object. Should contain a ' |
466 'dict mapping file names to lists of line numbers of ' | 465 'dict mapping file names to lists of line numbers of ' |
467 'code for which coverage information is desired.') | 466 'code for which coverage information is desired.') |
468 argparser.add_argument('-v', '--verbose', action='count', | 467 argparser.add_argument('-v', '--verbose', action='count', |
469 help='Print verbose log information.') | 468 help='Print verbose log information.') |
470 args = argparser.parse_args() | 469 args = argparser.parse_args() |
471 run_tests_helper.SetLogLevel(args.verbose) | 470 run_tests_helper.SetLogLevel(args.verbose) |
472 GenerateCoverageReport(args.lines_for_coverage_file, args.out, args.emma_dir) | 471 GenerateCoverageReport(args.lines_for_coverage_file, args.out, args.emma_dir) |
473 | 472 |
474 | 473 |
475 if __name__ == '__main__': | 474 if __name__ == '__main__': |
476 sys.exit(main()) | 475 sys.exit(main()) |
OLD | NEW |