Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions server/src/building/ProjectBuildDatabse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,18 @@ ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath,
throw CompilationDatabaseException("Couldn't open link_commands.json or compile_commands.json files");
}

auto linkCommandsJson = JsonUtils::getJsonFromFile(linkCommandsJsonPath);
auto compileCommandsJson = JsonUtils::getJsonFromFile(compileCommandsJsonPath);

initObjects(compileCommandsJson);
initInfo(linkCommandsJson);
filterInstalledFiles();
addLocalSharedLibraries();
fillTargetInfoParents();
createClangCompileCommandsJson();
try {
auto linkCommandsJson = JsonUtils::getJsonFromFile(linkCommandsJsonPath);
auto compileCommandsJson = JsonUtils::getJsonFromFile(compileCommandsJsonPath);
initObjects(compileCommandsJson);
initInfo(linkCommandsJson);
filterInstalledFiles();
addLocalSharedLibraries();
fillTargetInfoParents();
createClangCompileCommandsJson();
} catch (const std::exception &e) {
return;
}
}

ProjectBuildDatabase::ProjectBuildDatabase(utbot::ProjectContext projectContext) : ProjectBuildDatabase(
Expand Down
2 changes: 1 addition & 1 deletion server/src/commands/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ namespace Commands {
bool generateForStaticFunctions = true;
bool verbose = false;
int32_t timeoutPerFunction = 30;
int32_t timeoutPerTest = 0;
int32_t timeoutPerTest = 30;
bool noDeterministicSearcher = false;
bool noStubs = false;
};
Expand Down
20 changes: 12 additions & 8 deletions server/src/coverage/GcovCoverageTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,19 @@ CoverageMap GcovCoverageTool::getCoverageInfo() const {
ExecUtils::doWorkWithProgress(
FileSystemUtils::DirectoryIterator(covJsonDirPath), progressWriter,
"Reading coverage files", [&coverageMap](auto const &entry) {
auto jsonPath = entry.path();
auto coverageJson = JsonUtils::getJsonFromFile(jsonPath);
for (const nlohmann::json &jsonFile : coverageJson.at("files")) {
fs::path filePath(std::filesystem::path(jsonFile.at("file")));
if (Paths::isGtest(filePath)) {
continue;
try {
auto jsonPath = entry.path();
auto coverageJson = JsonUtils::getJsonFromFile(jsonPath);
for (const nlohmann::json &jsonFile: coverageJson.at("files")) {
fs::path filePath(std::filesystem::path(jsonFile.at("file")));
if (Paths::isGtest(filePath)) {
continue;
}
setLineNumbers(jsonFile, coverageMap[filePath]);
setFunctionBorders(jsonFile, coverageMap[filePath]);
}
setLineNumbers(jsonFile, coverageMap[filePath]);
setFunctionBorders(jsonFile, coverageMap[filePath]);
} catch (const std::exception &e) {
return;
}
});
return coverageMap;
Expand Down
86 changes: 49 additions & 37 deletions server/src/coverage/LlvmCoverageTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,43 +153,46 @@ Coverage::CoverageMap LlvmCoverageTool::getCoverageInfo() const {
LOG_S(ERROR) << "Can't found coverage.json at " << covJsonPath.string();
throw CoverageGenerationException("Can't found coverage.json at " + covJsonPath.string());
}
LOG_S(INFO) << "Reading coverage.json";

nlohmann::json coverageJson = JsonUtils::getJsonFromFile(covJsonPath);

// Parsing is based on LLVM coverage mapping format
ExecUtils::doWorkWithProgress(
coverageJson.at("data"), progressWriter, "Reading coverage.json",
[&coverageMap](const nlohmann::json &data) {
for (const nlohmann::json &function : data.at("functions")) {
std::string filename = function.at("filenames").at(0);
// no need to show coverage for gtest library
if (Paths::isGtest(filename)) {
continue;
}
for (const nlohmann::json &region : function.at("regions")) {
// In an LLVM coverage mapping format a region is an array with line and
// character position
FileCoverage::SourcePosition startPosition{ region.at(0).get<uint32_t>() - 1,
region.at(1).get<uint32_t>() - 1 };
FileCoverage::SourcePosition endPosition{ region.at(2).get<uint32_t>() - 1,
region.at(3).get<uint32_t>() - 1 };
FileCoverage::SourceRange sourceRange{ startPosition, endPosition };
// The 4th element in LLVM coverage mapping format of a region
if (region.at(4).get<int>() == 0) {
coverageMap[filename].uncoveredRanges.push_back(sourceRange);
} else if (region.at(4).get<int>() >= 1) {
coverageMap[filename].coveredRanges.push_back(sourceRange);
try {
LOG_S(INFO) << "Reading coverage.json";
nlohmann::json coverageJson = JsonUtils::getJsonFromFile(covJsonPath);

// Parsing is based on LLVM coverage mapping format
ExecUtils::doWorkWithProgress(
coverageJson.at("data"), progressWriter, "Reading coverage.json",
[&coverageMap](const nlohmann::json &data) {
for (const nlohmann::json &function: data.at("functions")) {
std::string filename = function.at("filenames").at(0);
// no need to show coverage for gtest library
if (Paths::isGtest(filename)) {
continue;
}
for (const nlohmann::json &region: function.at("regions")) {
// In an LLVM coverage mapping format a region is an array with line and
// character position
FileCoverage::SourcePosition startPosition{region.at(0).get<uint32_t>() - 1,
region.at(1).get<uint32_t>() - 1};
FileCoverage::SourcePosition endPosition{region.at(2).get<uint32_t>() - 1,
region.at(3).get<uint32_t>() - 1};
FileCoverage::SourceRange sourceRange{startPosition, endPosition};
// The 4th element in LLVM coverage mapping format of a region
if (region.at(4).get<int>() == 0) {
coverageMap[filename].uncoveredRanges.push_back(sourceRange);
} else if (region.at(4).get<int>() >= 1) {
coverageMap[filename].coveredRanges.push_back(sourceRange);
}
}
}
}
}
});
});

for (const auto &item : coverageMap) {
countLineCoverage(coverageMap, item.first);
}
for (const auto &item: coverageMap) {
countLineCoverage(coverageMap, item.first);
}

return coverageMap;
return coverageMap;
} catch (const std::exception &e) {
throw CoverageGenerationException("Can't parse coverage.json at " + covJsonPath.string());
}
}

void LlvmCoverageTool::countLineCoverage(Coverage::CoverageMap &coverageMap,
Expand Down Expand Up @@ -223,9 +226,18 @@ void LlvmCoverageTool::checkLineForPartial(Coverage::FileCoverage::SourceLine li
}

nlohmann::json LlvmCoverageTool::getTotals() const {
fs::path covJsonPath = Paths::getCoverageJsonPath(projectContext);
nlohmann::json coverageJson = JsonUtils::getJsonFromFile(covJsonPath);
return coverageJson.at("data").back().at("totals");
try {
fs::path covJsonPath = Paths::getCoverageJsonPath(projectContext);
nlohmann::json coverageJson = JsonUtils::getJsonFromFile(covJsonPath);
return coverageJson.at("data").back().at("totals");
} catch (const std::exception &e) {
return {{
"lines", {
{"count", 0},
{"covered", 0},
{"percent", (double) 0.0}
}}};
}
}


Expand Down
18 changes: 11 additions & 7 deletions server/src/coverage/TestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,18 @@ testsgen::TestResultObject TestRunner::runTest(const BuildRunCommand &command,
testRes.set_status(testsgen::TEST_DEATH);
return testRes;
}
nlohmann::json gtestResultsJson = JsonUtils::getJsonFromFile(Paths::getGTestResultsJsonPath(projectContext));
if (!google::protobuf::util::TimeUtil::FromString(gtestResultsJson["time"], testRes.mutable_executiontime())) {
LOG_S(WARNING) << "Cannot parse duration of test execution";
}
if (gtestResultsJson["failures"] != 0) {
try {
nlohmann::json gtestResultsJson = JsonUtils::getJsonFromFile(Paths::getGTestResultsJsonPath(projectContext));
if (!google::protobuf::util::TimeUtil::FromString(gtestResultsJson["time"], testRes.mutable_executiontime())) {
LOG_S(WARNING) << "Cannot parse duration of test execution";
}
if (gtestResultsJson["failures"] != 0) {
testRes.set_status(testsgen::TEST_FAILED);
} else {
testRes.set_status(testsgen::TEST_PASSED);
}
} catch (const std::exception &e) {
testRes.set_status(testsgen::TEST_FAILED);
} else {
testRes.set_status(testsgen::TEST_PASSED);
}
return testRes;
}
Expand Down