aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar elenairina <elenairina@google.com>2018-07-04 04:48:14 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-04 04:49:52 -0700
commit58689f69b8346ccbc0b358fbc6279a0787e5c8fa (patch)
tree515ba334260e432a85b8ff93cbcc61acf3cbbdca /tools
parent92df8c3f12949547d0a784e9d9e441f31dffd3ee (diff)
[LcovMerger] Make int fields of SourceFileCoverage be dynamically computed.
RELNOTES: None. PiperOrigin-RevId: 203264765
Diffstat (limited to 'tools')
-rw-r--r--tools/test/LcovMerger/java/com/google/devtools/lcovmerger/LcovParser.java12
-rw-r--r--tools/test/LcovMerger/java/com/google/devtools/lcovmerger/SourceFileCoverage.java59
-rw-r--r--tools/test/LcovMerger/javatests/com/google/devtools/lcovmerger/LcovMergerTestUtils.java14
3 files changed, 14 insertions, 71 deletions
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<Integer, BranchCoverage> branches; // line number to branch
private final TreeMap<Integer, LineCoverage> 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<LineCoverage> 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;
}