From 9c46b5a2b406508eb5ac7cc62b79a2b796ada193 Mon Sep 17 00:00:00 2001 From: estevenson Date: Tue, 18 Aug 2015 10:00:18 -0700 Subject: [PATCH] Add fractional line coverage + logging change. Added fractional line coverage to line by line coverage information so that the fractional line coverage will be available in generated JSON files. Changed logging level of skipped files. BUG= Review URL: https://codereview.chromium.org/1284083004 Cr-Original-Commit-Position: refs/heads/master@{#343944} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 39bc8c2a5c6a7b9b4f97d2b29359e151b9ccf402 --- android/emma_coverage_stats.py | 7 +++--- android/emma_coverage_stats_test.py | 39 ++++++++++++++++++----------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/android/emma_coverage_stats.py b/android/emma_coverage_stats.py index d882cea6e..b6620febd 100755 --- a/android/emma_coverage_stats.py +++ b/android/emma_coverage_stats.py @@ -300,6 +300,7 @@ class _EmmaCoverageStats(object): 'line': line.source, 'coverage': line.covered_status, 'changed': line.lineno in line_numbers, + 'fractional_coverage': line.fractional_line_coverage, } for line in total_line_coverage ] @@ -395,8 +396,7 @@ class _EmmaCoverageStats(object): if os.path.splitext(file_path)[1] == '.java' and os.path.exists(file_path): return True else: - logging.debug( - 'Skipping file %s, cannot compute code coverage.', file_path) + logging.info('Skipping file %s, cannot compute code coverage.', file_path) return False @staticmethod @@ -445,8 +445,7 @@ def GenerateCoverageReport(line_coverage_file, out_file_path, coverage_dir): coverage_results = {} if files_for_coverage: code_coverage = _EmmaCoverageStats(coverage_dir, files_for_coverage.keys()) - coverage_results = code_coverage.GetCoverageDict( - files_for_coverage) + coverage_results = code_coverage.GetCoverageDict(files_for_coverage) else: logging.info('No Java files requiring coverage were included in %s.', line_coverage_file) diff --git a/android/emma_coverage_stats_test.py b/android/emma_coverage_stats_test.py index e4f950695..111f24aec 100755 --- a/android/emma_coverage_stats_test.py +++ b/android/emma_coverage_stats_test.py @@ -401,32 +401,38 @@ class _EmmaCoverageStatsTest(unittest.TestCase): { 'line': line_coverage[0].source, 'coverage': line_coverage[0].covered_status, - 'changed': True + 'changed': True, + 'fractional_coverage': line_coverage[0].fractional_line_coverage, }, { 'line': line_coverage[1].source, 'coverage': line_coverage[1].covered_status, - 'changed': False + 'changed': False, + 'fractional_coverage': line_coverage[1].fractional_line_coverage, }, { 'line': line_coverage[2].source, 'coverage': line_coverage[2].covered_status, - 'changed': True + 'changed': True, + 'fractional_coverage': line_coverage[2].fractional_line_coverage, }, { 'line': line_coverage[3].source, 'coverage': line_coverage[3].covered_status, - 'changed': False + 'changed': False, + 'fractional_coverage': line_coverage[3].fractional_line_coverage, }, { 'line': line_coverage[4].source, 'coverage': line_coverage[4].covered_status, - 'changed': True + 'changed': True, + 'fractional_coverage': line_coverage[4].fractional_line_coverage, }, { 'line': line_coverage[5].source, 'coverage': line_coverage[5].covered_status, - 'changed': True + 'changed': True, + 'fractional_coverage': line_coverage[5].fractional_line_coverage, } ] } @@ -482,22 +488,27 @@ class _EmmaCoverageStatsTest(unittest.TestCase): '/path/2/File2.java': { 'absolute': {'covered': 1, 'total': 2}, 'incremental': {'covered': 1, 'total': 2}, - 'source': [{'changed': True, 'coverage': 0, 'line': ''}, - {'changed': True, 'coverage': 1, 'line': ''}] + 'source': [{'changed': True, 'coverage': 0, + 'line': '', 'fractional_coverage': 1.0}, + {'changed': True, 'coverage': 1, + 'line': '', 'fractional_coverage': 1.0}] }, '/path/to/1/File1.java': { 'absolute': {'covered': 2.5, 'total': 3}, 'incremental': {'covered': 2, 'total': 2}, - 'source': [{'changed': True, 'coverage': 1, 'line': ''}, - {'changed': False, 'coverage': 2, 'line': ''}, - {'changed': True, 'coverage': -1, 'line': ''}, - {'changed': True, 'coverage': 1, 'line': ''}] + 'source': [{'changed': True, 'coverage': 1, + 'line': '', 'fractional_coverage': 1.0}, + {'changed': False, 'coverage': 2, + 'line': '', 'fractional_coverage': 0.5}, + {'changed': True, 'coverage': -1, + 'line': '', 'fractional_coverage': 1.0}, + {'changed': True, 'coverage': 1, + 'line': '', 'fractional_coverage': 1.0}] } }, 'patch': {'incremental': {'covered': 3, 'total': 4}} } - # Return the relevant coverage info for each file. We aren't testing - # _GetCoverageStatusForFile here. + # Return the relevant coverage info for each file. self.simple_coverage._emma_parser.GetLineCoverage = ( lambda x: coverage_info[x]) result_dict = self.simple_coverage.GetCoverageDict(files_for_coverage)