forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LcovMerger is a tool that merges all the intermediate lcov tracefiles (with .dat extension) found under a coverage directory and prints the merged tracefile to a given output file. A custom implementation for merging lcov tracefiles is needed because the merging functionality of lcov itself is very slow. LcovMerger is required to get a single coverage report (lcov tracefile) from a bazel coverage command that executes multiple tests. ATM LcovMerger is only invoked by tools/test/collect_coverage.sh that collects and merges the tracefiles from a single test invocation. It will also be used from a CoverageReportAction. Progress on bazelbuild#5246. PiperOrigin-RevId: 200054506
- Loading branch information
Showing
25 changed files
with
2,507 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
tools/test/LcovMerger/java/com/google/devtools/lcovmerger/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package( | ||
default_visibility = [ | ||
"//tools/test/LcovMerger/javatests/com/google/devtools/lcovmerger:__pkg__", | ||
], | ||
) | ||
|
||
licenses(["notice"]) # Apache 2.0 | ||
|
||
java_library( | ||
name = "BranchCoverage", | ||
srcs = ["BranchCoverage.java"], | ||
deps = [ | ||
"//third_party:auto_value", | ||
], | ||
) | ||
|
||
java_library( | ||
name = "LineCoverage", | ||
srcs = ["LineCoverage.java"], | ||
deps = [ | ||
"//third_party:auto_value", | ||
"//third_party:jsr305", | ||
], | ||
) | ||
|
||
java_library( | ||
name = "SourceFileCoverage", | ||
srcs = ["SourceFileCoverage.java"], | ||
deps = [ | ||
":BranchCoverage", | ||
":LineCoverage", | ||
"//third_party:auto_value", | ||
"//third_party:guava", | ||
"//third_party:jsr305", | ||
], | ||
) | ||
|
||
java_library( | ||
name = "LcovPrinter", | ||
srcs = ["LcovPrinter.java"], | ||
deps = [ | ||
":BranchCoverage", | ||
":Coverage", | ||
":LcovConstants", | ||
":LineCoverage", | ||
":SourceFileCoverage", | ||
"//third_party:guava", | ||
], | ||
) | ||
|
||
java_library( | ||
name = "LcovConstants", | ||
srcs = ["LcovConstants.java"], | ||
) | ||
|
||
java_library( | ||
name = "LcovParser", | ||
srcs = ["LcovParser.java"], | ||
deps = [ | ||
":BranchCoverage", | ||
":LcovConstants", | ||
":LineCoverage", | ||
":SourceFileCoverage", | ||
], | ||
) | ||
|
||
java_library( | ||
name = "Coverage", | ||
srcs = ["Coverage.java"], | ||
deps = [":SourceFileCoverage"], | ||
) | ||
|
||
java_library( | ||
name = "MainLibrary", | ||
srcs = ["Main.java"], | ||
deps = [ | ||
":Coverage", | ||
":LcovConstants", | ||
":LcovParser", | ||
":LcovPrinter", | ||
":SourceFileCoverage", | ||
"//third_party:guava", | ||
], | ||
) | ||
|
||
java_binary( | ||
name = "Main", | ||
srcs = ["Main.java"], | ||
main_class = "com.google.devtools.lcovmerger.Main", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
":Coverage", | ||
":LcovConstants", | ||
":LcovParser", | ||
":LcovPrinter", | ||
":MainLibrary", | ||
":SourceFileCoverage", | ||
"//third_party:guava", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = glob(["**"]), | ||
visibility = ["//visibility:public"], | ||
) |
57 changes: 57 additions & 0 deletions
57
tools/test/LcovMerger/java/com/google/devtools/lcovmerger/BranchCoverage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2018 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.lcovmerger; | ||
|
||
import com.google.auto.value.AutoValue; | ||
|
||
/** | ||
* Stores branch coverage information. | ||
*/ | ||
@AutoValue | ||
abstract class BranchCoverage { | ||
|
||
static BranchCoverage create( | ||
int lineNumber, int blockNumber, int branchNumber, boolean wasExecuted, int nrOfExecutions) { | ||
assert (wasExecuted && nrOfExecutions > 0) || (!wasExecuted && nrOfExecutions == 0); | ||
return new AutoValue_BranchCoverage( | ||
lineNumber, blockNumber, branchNumber, wasExecuted, nrOfExecutions); | ||
} | ||
|
||
/** | ||
* Merges two given instances of {@link BranchCoverage}. | ||
* | ||
* Calling {@code lineNumber()}, {@code blockNumber()} and {@code branchNumber()} must return the | ||
* same values for {@code first} and {@code second}. | ||
*/ | ||
static BranchCoverage merge(BranchCoverage first, BranchCoverage second) { | ||
assert first.lineNumber() == second.lineNumber(); | ||
assert first.blockNumber() == second.blockNumber(); | ||
assert first.branchNumber() == second.branchNumber(); | ||
|
||
return create( | ||
first.lineNumber(), | ||
first.blockNumber(), | ||
first.branchNumber(), | ||
first.wasExecuted() || second.wasExecuted(), | ||
first.nrOfExecutions() + second.nrOfExecutions()); | ||
} | ||
|
||
abstract int lineNumber(); | ||
// The two numbers below should be -1 for non-gcc emitted coverage (e.g. Java). | ||
abstract int blockNumber(); // internal gcc internal ID for the branch | ||
abstract int branchNumber(); // internal gcc internal ID for the branch | ||
abstract boolean wasExecuted(); | ||
abstract int nrOfExecutions(); | ||
} |
40 changes: 40 additions & 0 deletions
40
tools/test/LcovMerger/java/com/google/devtools/lcovmerger/Coverage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2018 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.lcovmerger; | ||
|
||
import java.util.Collection; | ||
import java.util.TreeMap; | ||
|
||
class Coverage { | ||
private final TreeMap<String, SourceFileCoverage> sourceFiles; | ||
|
||
Coverage() { | ||
sourceFiles = new TreeMap<>(); | ||
} | ||
|
||
void add(SourceFileCoverage input) { | ||
String sourceFilename = input.sourceFileName(); | ||
if (sourceFiles.containsKey(sourceFilename)) { | ||
SourceFileCoverage old = sourceFiles.get(sourceFilename); | ||
sourceFiles.put(sourceFilename, SourceFileCoverage.merge(old, input)); | ||
} else { | ||
sourceFiles.put(sourceFilename, input); | ||
} | ||
} | ||
|
||
Collection<SourceFileCoverage> getAllSourceFiles() { | ||
return sourceFiles.values(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tools/test/LcovMerger/java/com/google/devtools/lcovmerger/LcovConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2018 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.lcovmerger; | ||
|
||
/** | ||
* Stores markers used by the lcov tracefile. See | ||
* <a href="http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php"> lcov documentation</a> | ||
*/ | ||
class LcovConstants { | ||
static final String SF_MARKER = "SF:"; | ||
static final String FN_MARKER = "FN:"; | ||
static final String FNDA_MARKER = "FNDA:"; | ||
static final String FNF_MARKER = "FNF:"; | ||
static final String FNH_MARKER = "FNH:"; | ||
static final String BRDA_MARKER = "BRDA:"; | ||
static final String BA_MARKER = "BA:"; | ||
static final String BRF_MARKER = "BRF:"; | ||
static final String BRH_MARKER = "BRH:"; | ||
static final String DA_MARKER = "DA:"; | ||
static final String LH_MARKER = "LH:"; | ||
static final String LF_MARKER = "LF:"; | ||
static final String END_OF_RECORD_MARKER = "end_of_record"; | ||
static final String LCOV_DELIMITER = ","; | ||
static final String TAKEN = "-"; | ||
static final String TRACEFILE_EXTENSION = ".dat"; | ||
} |
Oops, something went wrong.