Skip to content

Commit 09cb9b1

Browse files
Alexey Utkinalexey-utkin
authored andcommitted
UTBotCpp-173 [coreutils] Collection of coverage takes too long
- Fix changes the `llvm-cov export` call by extension of parameters set: adding the tested files as sources to restrict the coverage report JSON output. In case of `coreutils` it reduces the JSON size from 100M to 2M. - The command line for `llvm-cov export` was optimized by removing identical `-object BIN` switches. Related problem (not fixed): `Paths::testPathToSourcePath` does not work for `*.cpp` files.
1 parent df75518 commit 09cb9b1

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

server/src/coverage/LlvmCoverageTool.cpp

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ LlvmCoverageTool::getCoverageCommands(const vector<UnitTest> &testsToLaunch) {
7373

7474
auto testFilenames = CollectionUtils::transformTo<CollectionUtils::FileSet>(
7575
testsToLaunch, [](UnitTest const &test) { return test.testFilePath; });
76-
auto objectFiles = CollectionUtils::transformTo<std::vector<fs::path>>(
76+
auto objectFiles = CollectionUtils::transformTo<std::unordered_set<std::string>>(
7777
testFilenames, [this](fs::path const &testFilePath) {
7878
fs::path sourcePath = Paths::testPathToSourcePath(projectContext, testFilePath);
7979
fs::path makefile =
@@ -102,11 +102,44 @@ LlvmCoverageTool::getCoverageCommands(const vector<UnitTest> &testsToLaunch) {
102102
fs::path coverageJsonPath = Paths::getCoverageJsonPath(projectContext);
103103
fs::create_directories(coverageJsonPath.parent_path());
104104
std::vector<std::string> exportArguments = { "export" };
105-
for (const fs::path &objectFile : objectFiles) {
106-
exportArguments.emplace_back("-object");
107-
exportArguments.emplace_back(objectFile.string());
105+
106+
// From documentation:
107+
// llvm-cov export [options] -instr-profile PROFILE BIN [-object BIN,...] [[-object BIN]] [SOURCES]
108+
bool firstBIN = true; // the first BIN need to be mentioned without `-object`
109+
for (const std::string &objectFile : objectFiles) {
110+
if (firstBIN) {
111+
firstBIN = false;
112+
}
113+
else {
114+
exportArguments.emplace_back("-object");
115+
}
116+
exportArguments.emplace_back(objectFile);
108117
}
109118
exportArguments.emplace_back("-instr-profile=" + mainProfdataPath.string());
119+
120+
try {
121+
auto sourcePaths = CollectionUtils::transformTo<
122+
std::unordered_set<std::string>>(testFilenames, [this](fs::path const &testFilePath) {
123+
fs::path sourcePath = Paths::testPathToSourcePath(projectContext, testFilePath);
124+
if (!fs::exists(sourcePath)) {
125+
throw CoverageGenerationException(
126+
"Coverage generation: Source file `"
127+
+ sourcePath.string()
128+
+ "` does not exist. Wrongly restored from test file `"
129+
+ testFilePath.string()
130+
+ "`.");
131+
}
132+
return sourcePath.string();
133+
});
134+
for (const std::string &sourcePath : sourcePaths) {
135+
exportArguments.emplace_back(sourcePath);
136+
}
137+
}
138+
catch (const CoverageGenerationException &ce) {
139+
LOG_S(WARNING) << "Skip Coverage filtering for tested source files: "
140+
<< ce.what();
141+
}
142+
110143
auto exportTask = ShellExecTask::getShellCommandTask(Paths::getLLVMcov(), exportArguments);
111144
exportTask.setLogFilePath(coverageJsonPath);
112145
exportTask.setRetainOutputFile(true);

0 commit comments

Comments
 (0)