From 58689f69b8346ccbc0b358fbc6279a0787e5c8fa Mon Sep 17 00:00:00 2001 From: elenairina Date: Wed, 4 Jul 2018 04:48:14 -0700 Subject: [LcovMerger] Make int fields of SourceFileCoverage be dynamically computed. RELNOTES: None. PiperOrigin-RevId: 203264765 --- .../com/google/devtools/lcovmerger/LcovParser.java | 12 ++--- .../devtools/lcovmerger/SourceFileCoverage.java | 59 +++------------------- .../devtools/lcovmerger/LcovMergerTestUtils.java | 14 ----- 3 files changed, 14 insertions(+), 71 deletions(-) (limited to 'tools') diff --git a/tools/test/LcovMerger/java/com/google/devtools/lcovmerger/LcovParser.java b/tools/test/LcovMerger/java/com/google/devtools/lcovmerger/LcovParser.java index a5cd7a0dd2..b441b8761e 100644 --- a/tools/test/LcovMerger/java/com/google/devtools/lcovmerger/LcovParser.java +++ b/tools/test/LcovMerger/java/com/google/devtools/lcovmerger/LcovParser.java @@ -208,7 +208,7 @@ class LcovParser { } try { int nrFunctionsFound = Integer.parseInt(lineContent); - currentSourceFileCoverage.nrFunctionsFound(nrFunctionsFound); + assert currentSourceFileCoverage.nrFunctionsFound() == nrFunctionsFound; } catch (NumberFormatException e) { logger.log(Level.WARNING, "Tracefile contains invalid number of functions on FNF line " + line); @@ -226,7 +226,7 @@ class LcovParser { } try { int nrFunctionsHit = Integer.parseInt(lineContent); - currentSourceFileCoverage.nrFunctionsHit(nrFunctionsHit); + assert currentSourceFileCoverage.nrFunctionsHit() == nrFunctionsHit; } catch (NumberFormatException e) { logger.log(Level.WARNING, "Tracefile contains invalid number of functions hit on FNH line " + line); @@ -314,7 +314,7 @@ class LcovParser { } try { int nrBranchesFound = Integer.parseInt(lineContent); - currentSourceFileCoverage.nrBranchesFound(nrBranchesFound); + assert currentSourceFileCoverage.nrBranchesFound() == nrBranchesFound; } catch (NumberFormatException e) { logger.log(Level.WARNING, "Tracefile contains invalid number of branches in BRDA line " + line); @@ -332,7 +332,7 @@ class LcovParser { } try { int nrBranchesHit = Integer.parseInt(lineContent); - currentSourceFileCoverage.nrBranchesHit(nrBranchesHit); + assert currentSourceFileCoverage.nrBranchesHit() == nrBranchesHit; } catch (NumberFormatException e) { logger.log(Level.WARNING, "Tracefile contains invalid number of branches hit in BRH line " + line); @@ -382,7 +382,7 @@ class LcovParser { } try { int nrLines = Integer.parseInt(lineContent); - currentSourceFileCoverage.nrOfLinesWithNonZeroExecution(nrLines); + assert currentSourceFileCoverage.nrOfLinesWithNonZeroExecution() == nrLines; } catch (NumberFormatException e) { logger.log(Level.WARNING, "Tracefile contains an invalid number on LHL line " + line); return false; @@ -399,7 +399,7 @@ class LcovParser { } try { int nrLines = Integer.parseInt(lineContent); - currentSourceFileCoverage.nrOfInstrumentedLines(nrLines); + assert currentSourceFileCoverage.nrOfInstrumentedLines() == nrLines; } catch (NumberFormatException e) { logger.log(Level.WARNING, "Tracefile contains an invalid number on LF line " + line); return false; diff --git a/tools/test/LcovMerger/java/com/google/devtools/lcovmerger/SourceFileCoverage.java b/tools/test/LcovMerger/java/com/google/devtools/lcovmerger/SourceFileCoverage.java index 3e293a789c..0cdb1a6f85 100644 --- a/tools/test/LcovMerger/java/com/google/devtools/lcovmerger/SourceFileCoverage.java +++ b/tools/test/LcovMerger/java/com/google/devtools/lcovmerger/SourceFileCoverage.java @@ -34,13 +34,6 @@ class SourceFileCoverage { private final TreeMap branches; // line number to branch private final TreeMap lines; // line number to line execution - private int nrFunctionsFound; - private int nrFunctionsHit; - private int nrBranchesFound; - private int nrBranchesHit; - private int nrOfLinesWithNonZeroExecution; - private int nrOfInstrumentedLines; - SourceFileCoverage(String sourcefile) { this.sourceFileName = sourcefile; this.functionsExecution = new TreeMap<>(); @@ -61,13 +54,6 @@ class SourceFileCoverage { this.functionsExecution.putAll(other.functionsExecution); this.branches.putAll(other.branches); this.lines.putAll(other.lines); - - this.nrFunctionsFound = other.nrFunctionsFound; - this.nrFunctionsHit = other.nrFunctionsHit; - this.nrBranchesFound = other.nrBranchesFound; - this.nrBranchesHit = other.nrBranchesHit; - this.nrOfLinesWithNonZeroExecution = other.nrOfLinesWithNonZeroExecution; - this.nrOfInstrumentedLines = other.nrOfInstrumentedLines; } /* @@ -169,13 +155,6 @@ class SourceFileCoverage { merged.addAllFunctionsExecution(mergeFunctionsExecution(source1, source2)); merged.addAllBranches(mergeBranches(source1, source2)); merged.addAllLines(mergeLines(source1, source2)); - - merged.nrBranchesHit(getNumberOfBranchesHit(merged)); - merged.nrOfLinesWithNonZeroExecution(getNumberOfExecutedLines(merged)); - merged.nrFunctionsFound(merged.lineNumbers.size()); - merged.nrFunctionsHit(merged.functionsExecution.size()); - merged.nrBranchesFound(merged.branches.size()); - merged.nrOfInstrumentedLines(merged.lines.size()); return merged; } @@ -184,51 +163,29 @@ class SourceFileCoverage { } int nrFunctionsFound() { - return nrFunctionsFound; - } - - void nrFunctionsFound(int nrFunctionsFound) { - this.nrFunctionsFound = nrFunctionsFound; + return functionsExecution.size(); } int nrFunctionsHit() { - return nrFunctionsHit; - } - - void nrFunctionsHit(int nrFunctionsHit) { - this.nrFunctionsHit = nrFunctionsHit; + return (int) functionsExecution.entrySet().stream() + .filter(function -> function.getValue() > 0) + .count(); } int nrBranchesFound() { - return nrBranchesFound; - } - - void nrBranchesFound(int nrBranchesFound) { - this.nrBranchesFound = nrBranchesFound; + return branches.size(); } int nrBranchesHit() { - return nrBranchesHit; - } - - void nrBranchesHit(int nrBranchesHit) { - this.nrBranchesHit = nrBranchesHit; + return getNumberOfBranchesHit(this); } int nrOfLinesWithNonZeroExecution() { - return nrOfLinesWithNonZeroExecution; - } - - void nrOfLinesWithNonZeroExecution(int nrOfLinesWithNonZeroExecution) { - this.nrOfLinesWithNonZeroExecution = nrOfLinesWithNonZeroExecution; + return getNumberOfExecutedLines(this); } int nrOfInstrumentedLines() { - return nrOfInstrumentedLines; - } - - void nrOfInstrumentedLines(int nrOfInstrumentedLines) { - this.nrOfInstrumentedLines = nrOfInstrumentedLines; + return this.lines.size(); } Collection getAllLineExecution() { diff --git a/tools/test/LcovMerger/javatests/com/google/devtools/lcovmerger/LcovMergerTestUtils.java b/tools/test/LcovMerger/javatests/com/google/devtools/lcovmerger/LcovMergerTestUtils.java index abaed3186d..eac604aeb3 100644 --- a/tools/test/LcovMerger/javatests/com/google/devtools/lcovmerger/LcovMergerTestUtils.java +++ b/tools/test/LcovMerger/javatests/com/google/devtools/lcovmerger/LcovMergerTestUtils.java @@ -244,9 +244,6 @@ public class LcovMergerTestUtils { sourceFile.addLineNumber(FUNC_3, FUNC_3_LINE_NR); sourceFile.addFunctionExecution(FUNC_3, FUNC_3_NR_EXECUTED_LINES_TRACEFILE1); - sourceFile.nrFunctionsFound(NR_FUNCTIONS_FOUND); - sourceFile.nrFunctionsHit(NR_FUNCTIONS_HIT_TRACEFILE1); - for (int line = FUNC_1_LINE_NR; line < MAX_LINES_IN_FILE; line++) { if (lineExecutionCount[line] >= 0) { @@ -256,9 +253,6 @@ public class LcovMergerTestUtils { } } - sourceFile.nrOfLinesWithNonZeroExecution(NR_LINES_HIT_TRACEFILE1); - sourceFile.nrOfInstrumentedLines(NR_LINES_FOUND); - return sourceFile; } @@ -275,10 +269,6 @@ public class LcovMergerTestUtils { sourceFileCoverage.addLineNumber(FUNC_3, FUNC_3_LINE_NR); sourceFileCoverage.addFunctionExecution(FUNC_3, FUNC_3_NR_EXECUTED_LINES_TRACEFILE2); - sourceFileCoverage.nrFunctionsFound(NR_FUNCTIONS_FOUND); - sourceFileCoverage.nrFunctionsHit(NR_FUNCTIONS_HIT_TRACEFILE2); - - for (int line = FUNC_1_LINE_NR; line < MAX_LINES_IN_FILE; line++) { if (lineExecutionCount[line] >= 0) { sourceFileCoverage.addLine( @@ -286,10 +276,6 @@ public class LcovMergerTestUtils { line, lineExecutionCount[line], null)); } } - - sourceFileCoverage.nrOfLinesWithNonZeroExecution(NR_LINES_HIT_TRACEFILE2); - sourceFileCoverage.nrOfInstrumentedLines(NR_LINES_FOUND); - return sourceFileCoverage; } -- cgit v1.2.3