2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2004-09-09 12:41:05 +00:00
|
|
|
#include "cmCTestCoverageHandler.h"
|
2016-04-29 13:40:20 +00:00
|
|
|
|
2019-05-23 12:49:54 +00:00
|
|
|
#include "cmAlgorithms.h"
|
2016-04-29 14:53:13 +00:00
|
|
|
#include "cmCTest.h"
|
2017-12-12 20:54:01 +00:00
|
|
|
#include "cmDuration.h"
|
2016-04-29 14:53:13 +00:00
|
|
|
#include "cmGeneratedFileStream.h"
|
|
|
|
#include "cmParseBlanketJSCoverage.h"
|
|
|
|
#include "cmParseCacheCoverage.h"
|
2014-06-03 18:30:46 +00:00
|
|
|
#include "cmParseCoberturaCoverage.h"
|
2016-04-29 14:53:13 +00:00
|
|
|
#include "cmParseDelphiCoverage.h"
|
2012-04-25 21:04:28 +00:00
|
|
|
#include "cmParseGTMCoverage.h"
|
2014-05-21 19:19:35 +00:00
|
|
|
#include "cmParseJacocoCoverage.h"
|
2016-04-29 14:53:13 +00:00
|
|
|
#include "cmParsePHPCoverage.h"
|
2019-08-01 10:57:18 +00:00
|
|
|
#include "cmStringAlgorithms.h"
|
2004-10-17 23:45:36 +00:00
|
|
|
#include "cmSystemTools.h"
|
2017-03-01 18:41:50 +00:00
|
|
|
#include "cmWorkingDirectory.h"
|
2015-05-24 19:18:40 +00:00
|
|
|
#include "cmXMLWriter.h"
|
2006-03-21 17:54:31 +00:00
|
|
|
|
2017-04-11 20:00:21 +00:00
|
|
|
#include "cmsys/FStream.hxx"
|
|
|
|
#include "cmsys/Glob.hxx"
|
|
|
|
#include "cmsys/Process.h"
|
|
|
|
#include "cmsys/RegularExpression.hxx"
|
2016-08-24 20:01:40 +00:00
|
|
|
#include <algorithm>
|
2017-11-03 13:25:33 +00:00
|
|
|
#include <chrono>
|
2018-03-04 06:27:09 +00:00
|
|
|
#include <cstring>
|
2016-08-24 20:01:40 +00:00
|
|
|
#include <iomanip>
|
|
|
|
#include <iterator>
|
|
|
|
#include <sstream>
|
|
|
|
#include <stdio.h>
|
2016-04-29 14:53:13 +00:00
|
|
|
#include <stdlib.h>
|
2016-08-24 20:01:40 +00:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
class cmMakefile;
|
2004-09-09 13:31:43 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
#define SAFEDIV(x, y) (((y) != 0) ? ((x) / (y)) : (0))
|
2007-06-01 19:40:07 +00:00
|
|
|
|
|
|
|
class cmCTestRunProcess
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cmCTestRunProcess()
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
|
|
|
this->Process = cmsysProcess_New();
|
|
|
|
this->PipeState = -1;
|
2017-12-12 20:54:01 +00:00
|
|
|
this->TimeOut = cmDuration(-1);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-01 19:40:07 +00:00
|
|
|
~cmCTestRunProcess()
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
|
|
|
if (!(this->PipeState == -1) &&
|
|
|
|
!(this->PipeState == cmsysProcess_Pipe_None) &&
|
|
|
|
!(this->PipeState == cmsysProcess_Pipe_Timeout)) {
|
|
|
|
this->WaitForExit();
|
2007-06-01 19:40:07 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
cmsysProcess_Delete(this->Process);
|
|
|
|
}
|
2019-02-14 16:29:57 +00:00
|
|
|
cmCTestRunProcess(const cmCTestRunProcess&) = delete;
|
|
|
|
cmCTestRunProcess& operator=(const cmCTestRunProcess&) = delete;
|
2007-06-01 19:40:07 +00:00
|
|
|
void SetCommand(const char* command)
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
|
|
|
this->CommandLineStrings.clear();
|
2019-01-16 06:13:07 +00:00
|
|
|
this->CommandLineStrings.emplace_back(command);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-01 19:40:07 +00:00
|
|
|
void AddArgument(const char* arg)
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
|
|
|
if (arg) {
|
2019-01-16 06:13:07 +00:00
|
|
|
this->CommandLineStrings.emplace_back(arg);
|
2007-06-01 19:40:07 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
void SetWorkingDirectory(const char* dir) { this->WorkingDirectory = dir; }
|
2017-12-12 20:54:01 +00:00
|
|
|
void SetTimeout(cmDuration t) { this->TimeOut = t; }
|
2007-06-01 19:40:07 +00:00
|
|
|
bool StartProcess()
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
|
|
|
std::vector<const char*> args;
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& cl : this->CommandLineStrings) {
|
|
|
|
args.push_back(cl.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2017-08-22 21:42:36 +00:00
|
|
|
args.push_back(nullptr); // null terminate
|
2019-02-04 21:56:42 +00:00
|
|
|
cmsysProcess_SetCommand(this->Process, args.data());
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->WorkingDirectory.empty()) {
|
|
|
|
cmsysProcess_SetWorkingDirectory(this->Process,
|
|
|
|
this->WorkingDirectory.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
cmsysProcess_SetOption(this->Process, cmsysProcess_Option_HideWindow, 1);
|
2017-12-12 20:54:01 +00:00
|
|
|
if (this->TimeOut >= cmDuration::zero()) {
|
2017-12-08 13:22:15 +00:00
|
|
|
cmsysProcess_SetTimeout(this->Process, this->TimeOut.count());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
cmsysProcess_Execute(this->Process);
|
|
|
|
this->PipeState = cmsysProcess_GetState(this->Process);
|
|
|
|
// if the process is running or exited return true
|
2016-06-01 21:29:53 +00:00
|
|
|
return this->PipeState == cmsysProcess_State_Executing ||
|
|
|
|
this->PipeState == cmsysProcess_State_Exited;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-01 19:40:07 +00:00
|
|
|
void SetStdoutFile(const char* fname)
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
2007-06-01 19:40:07 +00:00
|
|
|
cmsysProcess_SetPipeFile(this->Process, cmsysProcess_Pipe_STDOUT, fname);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-01 19:40:07 +00:00
|
|
|
void SetStderrFile(const char* fname)
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
2007-06-01 19:40:07 +00:00
|
|
|
cmsysProcess_SetPipeFile(this->Process, cmsysProcess_Pipe_STDERR, fname);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2017-08-22 21:42:36 +00:00
|
|
|
int WaitForExit(double* timeout = nullptr)
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
|
|
|
this->PipeState = cmsysProcess_WaitForExit(this->Process, timeout);
|
|
|
|
return this->PipeState;
|
|
|
|
}
|
|
|
|
int GetProcessState() { return this->PipeState; }
|
2017-05-30 19:37:46 +00:00
|
|
|
|
2007-06-01 19:40:07 +00:00
|
|
|
private:
|
|
|
|
int PipeState;
|
|
|
|
cmsysProcess* Process;
|
|
|
|
std::vector<std::string> CommandLineStrings;
|
|
|
|
std::string WorkingDirectory;
|
2017-12-12 20:54:01 +00:00
|
|
|
cmDuration TimeOut;
|
2007-06-01 19:40:07 +00:00
|
|
|
};
|
|
|
|
|
2019-01-22 22:44:50 +00:00
|
|
|
cmCTestCoverageHandler::cmCTestCoverageHandler() = default;
|
2005-06-17 17:04:56 +00:00
|
|
|
|
|
|
|
void cmCTestCoverageHandler::Initialize()
|
|
|
|
{
|
2005-06-23 17:04:18 +00:00
|
|
|
this->Superclass::Initialize();
|
2009-03-02 20:32:59 +00:00
|
|
|
this->CustomCoverageExclude.clear();
|
|
|
|
this->SourceLabels.clear();
|
2013-10-29 07:13:21 +00:00
|
|
|
this->TargetDirs.clear();
|
2009-03-02 20:32:59 +00:00
|
|
|
this->LabelIdMap.clear();
|
|
|
|
this->Labels.clear();
|
2009-03-02 20:33:18 +00:00
|
|
|
this->LabelFilter.clear();
|
2004-09-09 12:41:05 +00:00
|
|
|
}
|
|
|
|
|
2009-03-11 16:03:47 +00:00
|
|
|
void cmCTestCoverageHandler::CleanCoverageLogFiles(std::ostream& log)
|
|
|
|
{
|
2019-08-22 14:34:40 +00:00
|
|
|
std::string logGlob =
|
|
|
|
cmStrCat(this->CTest->GetCTestConfiguration("BuildDirectory"), "/Testing/",
|
|
|
|
this->CTest->GetCurrentTag(), "/CoverageLog*");
|
2009-03-11 16:03:47 +00:00
|
|
|
cmsys::Glob gl;
|
2014-03-10 23:04:11 +00:00
|
|
|
gl.FindFiles(logGlob);
|
2009-03-11 16:03:47 +00:00
|
|
|
std::vector<std::string> const& files = gl.GetFiles();
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& f : files) {
|
|
|
|
log << "Removing old coverage log: " << f << "\n";
|
|
|
|
cmSystemTools::RemoveFile(f);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-03-11 16:03:47 +00:00
|
|
|
}
|
|
|
|
|
2006-03-09 16:17:10 +00:00
|
|
|
bool cmCTestCoverageHandler::StartCoverageLogFile(
|
|
|
|
cmGeneratedFileStream& covLogFile, int logFileCount)
|
2004-09-09 12:41:05 +00:00
|
|
|
{
|
2004-10-17 23:45:36 +00:00
|
|
|
char covLogFilename[1024];
|
2005-06-23 17:04:18 +00:00
|
|
|
sprintf(covLogFilename, "CoverageLog-%d", logFileCount);
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
"Open file: " << covLogFilename << std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
if (!this->StartResultingXML(cmCTest::PartCoverage, covLogFilename,
|
|
|
|
covLogFile)) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Cannot open log file: " << covLogFilename << std::endl);
|
2004-10-17 23:45:36 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2004-10-17 23:45:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
2004-09-09 12:41:05 +00:00
|
|
|
|
2006-03-09 16:17:10 +00:00
|
|
|
void cmCTestCoverageHandler::EndCoverageLogFile(cmGeneratedFileStream& ostr,
|
2016-05-16 14:34:04 +00:00
|
|
|
int logFileCount)
|
2004-10-17 23:45:36 +00:00
|
|
|
{
|
|
|
|
char covLogFilename[1024];
|
|
|
|
sprintf(covLogFilename, "CoverageLog-%d.xml", logFileCount);
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
"Close file: " << covLogFilename << std::endl,
|
|
|
|
this->Quiet);
|
2005-07-14 13:29:33 +00:00
|
|
|
ostr.Close();
|
2004-10-17 23:45:36 +00:00
|
|
|
}
|
|
|
|
|
2015-05-24 19:18:40 +00:00
|
|
|
void cmCTestCoverageHandler::StartCoverageLogXML(cmXMLWriter& xml)
|
|
|
|
{
|
|
|
|
this->CTest->StartXML(xml, this->AppendXML);
|
|
|
|
xml.StartElement("CoverageLog");
|
|
|
|
xml.Element("StartDateTime", this->CTest->CurrentTime());
|
2017-11-15 18:00:09 +00:00
|
|
|
xml.Element("StartTime", std::chrono::system_clock::now());
|
2015-05-24 19:18:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestCoverageHandler::EndCoverageLogXML(cmXMLWriter& xml)
|
|
|
|
{
|
|
|
|
xml.Element("EndDateTime", this->CTest->CurrentTime());
|
2017-11-15 18:00:09 +00:00
|
|
|
xml.Element("EndTime", std::chrono::system_clock::now());
|
2015-05-24 19:18:40 +00:00
|
|
|
xml.EndElement(); // CoverageLog
|
|
|
|
this->CTest->EndXML(xml);
|
|
|
|
}
|
|
|
|
|
2017-09-19 10:22:50 +00:00
|
|
|
bool cmCTestCoverageHandler::ShouldIDoCoverage(std::string const& file,
|
|
|
|
std::string const& srcDir,
|
|
|
|
std::string const& binDir)
|
2004-10-17 23:45:36 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->IsFilteredOut(file)) {
|
2009-03-02 20:33:18 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-03-02 20:33:18 +00:00
|
|
|
|
2017-09-14 13:11:58 +00:00
|
|
|
for (cmsys::RegularExpression& rx : this->CustomCoverageExcludeRegex) {
|
|
|
|
if (rx.find(file)) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestOptionalLog(
|
|
|
|
this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
" File " << file << " is excluded in CTestCustom.ctest" << std::endl;
|
|
|
|
, this->Quiet);
|
2005-07-14 17:25:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2005-07-14 17:25:40 +00:00
|
|
|
|
2004-10-17 23:45:36 +00:00
|
|
|
std::string fSrcDir = cmSystemTools::CollapseFullPath(srcDir);
|
|
|
|
std::string fBinDir = cmSystemTools::CollapseFullPath(binDir);
|
|
|
|
std::string fFile = cmSystemTools::CollapseFullPath(file);
|
2016-05-16 14:34:04 +00:00
|
|
|
bool sourceSubDir = cmSystemTools::IsSubDirectory(fFile, fSrcDir);
|
|
|
|
bool buildSubDir = cmSystemTools::IsSubDirectory(fFile, fBinDir);
|
2004-10-17 23:45:36 +00:00
|
|
|
// Always check parent directory of the file.
|
2014-03-10 23:04:11 +00:00
|
|
|
std::string fileDir = cmSystemTools::GetFilenamePath(fFile);
|
2004-10-17 23:45:36 +00:00
|
|
|
std::string checkDir;
|
|
|
|
|
|
|
|
// We also need to check the binary/source directory pair.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (sourceSubDir && buildSubDir) {
|
|
|
|
if (fSrcDir.size() > fBinDir.size()) {
|
2004-10-17 23:45:36 +00:00
|
|
|
checkDir = fSrcDir;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2004-10-17 23:45:36 +00:00
|
|
|
checkDir = fBinDir;
|
2004-09-09 12:41:05 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (sourceSubDir) {
|
2004-10-17 23:45:36 +00:00
|
|
|
checkDir = fSrcDir;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (buildSubDir) {
|
2004-10-17 23:45:36 +00:00
|
|
|
checkDir = fBinDir;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
std::string ndc = cmSystemTools::FileExistsInParentDirectories(
|
2019-02-11 23:11:59 +00:00
|
|
|
".NoDartCoverage", fFile, checkDir);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!ndc.empty()) {
|
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
"Found: " << ndc << " so skip coverage of " << file
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
2004-10-17 23:45:36 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2004-09-09 12:41:05 +00:00
|
|
|
|
2004-10-17 23:45:36 +00:00
|
|
|
// By now checkDir should be set to parent directory of the file.
|
|
|
|
// Get the relative path to the file an apply it to the opposite directory.
|
|
|
|
// If it is the same as fileDir, then ignore, otherwise check.
|
2007-06-01 19:40:07 +00:00
|
|
|
std::string relPath;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!checkDir.empty()) {
|
2018-01-31 15:20:02 +00:00
|
|
|
relPath = cmSystemTools::RelativePath(checkDir, fFile);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2007-06-01 19:40:07 +00:00
|
|
|
relPath = fFile;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (checkDir == fSrcDir) {
|
2004-10-17 23:45:36 +00:00
|
|
|
checkDir = fBinDir;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2004-10-17 23:45:36 +00:00
|
|
|
checkDir = fSrcDir;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2004-10-17 23:45:36 +00:00
|
|
|
fFile = checkDir + "/" + relPath;
|
2014-03-10 23:04:11 +00:00
|
|
|
fFile = cmSystemTools::GetFilenamePath(fFile);
|
2004-09-09 12:41:05 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (fileDir == fFile) {
|
2004-10-17 23:45:36 +00:00
|
|
|
// This is in-source build, so we trust the previous check.
|
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2004-10-17 23:45:36 +00:00
|
|
|
|
2019-02-11 23:11:59 +00:00
|
|
|
ndc = cmSystemTools::FileExistsInParentDirectories(".NoDartCoverage", fFile,
|
|
|
|
checkDir);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!ndc.empty()) {
|
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
"Found: " << ndc << " so skip coverage of: " << file
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
2004-10-17 23:45:36 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2004-10-17 23:45:36 +00:00
|
|
|
// Ok, nothing in source tree, nothing in binary tree
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
// clearly it would be nice if this were broken up into a few smaller
|
|
|
|
// functions and commented...
|
2005-01-27 20:54:47 +00:00
|
|
|
int cmCTestCoverageHandler::ProcessHandler()
|
2004-10-17 23:45:36 +00:00
|
|
|
{
|
2009-03-11 17:31:33 +00:00
|
|
|
this->CTest->ClearSubmitFiles(cmCTest::PartCoverage);
|
2004-10-17 23:45:36 +00:00
|
|
|
int error = 0;
|
2006-10-19 14:45:19 +00:00
|
|
|
// do we have time for this
|
2017-11-20 20:55:13 +00:00
|
|
|
if (this->CTest->GetRemainingTimeAllowed() < std::chrono::minutes(2)) {
|
2006-10-19 14:45:19 +00:00
|
|
|
return error;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2007-04-27 03:20:12 +00:00
|
|
|
std::string coverage_start_time = this->CTest->CurrentTime();
|
2017-11-15 18:00:09 +00:00
|
|
|
auto coverage_start_time_time = std::chrono::system_clock::now();
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string sourceDir =
|
|
|
|
this->CTest->GetCTestConfiguration("SourceDirectory");
|
|
|
|
std::string binaryDir = this->CTest->GetCTestConfiguration("BuildDirectory");
|
2004-10-17 23:45:36 +00:00
|
|
|
|
2009-02-13 20:17:06 +00:00
|
|
|
this->LoadLabels();
|
|
|
|
|
2005-06-14 15:42:53 +00:00
|
|
|
cmGeneratedFileStream ofs;
|
2017-11-03 13:25:33 +00:00
|
|
|
auto elapsed_time_start = std::chrono::steady_clock::now();
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->StartLogFile("Coverage", ofs)) {
|
2006-03-10 20:03:09 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Cannot create LastCoverage.log file" << std::endl);
|
|
|
|
}
|
2005-06-14 15:42:53 +00:00
|
|
|
|
2017-11-03 13:25:33 +00:00
|
|
|
ofs << "Performing coverage: "
|
|
|
|
<< elapsed_time_start.time_since_epoch().count() << std::endl;
|
2009-03-11 16:03:47 +00:00
|
|
|
this->CleanCoverageLogFiles(ofs);
|
2005-06-14 15:42:53 +00:00
|
|
|
|
2004-10-17 23:45:36 +00:00
|
|
|
cmSystemTools::ConvertToUnixSlashes(sourceDir);
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(binaryDir);
|
|
|
|
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Performing coverage" << std::endl, this->Quiet);
|
2006-03-09 16:17:10 +00:00
|
|
|
|
2007-04-27 03:20:12 +00:00
|
|
|
cmCTestCoverageHandlerContainer cont;
|
|
|
|
cont.Error = error;
|
|
|
|
cont.SourceDir = sourceDir;
|
|
|
|
cont.BinaryDir = binaryDir;
|
|
|
|
cont.OFS = &ofs;
|
2015-02-17 20:57:26 +00:00
|
|
|
cont.Quiet = this->Quiet;
|
2006-03-09 16:17:10 +00:00
|
|
|
|
2007-06-08 16:29:40 +00:00
|
|
|
// setup the regex exclude stuff
|
2009-03-02 20:32:59 +00:00
|
|
|
this->CustomCoverageExcludeRegex.clear();
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& rex : this->CustomCoverageExclude) {
|
2019-01-16 06:13:07 +00:00
|
|
|
this->CustomCoverageExcludeRegex.emplace_back(rex);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-08 16:29:40 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->HandleBullseyeCoverage(&cont)) {
|
2007-06-01 19:40:07 +00:00
|
|
|
return cont.Error;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
int file_count = 0;
|
|
|
|
file_count += this->HandleGCovCoverage(&cont);
|
2012-04-25 21:04:28 +00:00
|
|
|
error = cont.Error;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (file_count < 0) {
|
2014-02-27 13:37:52 +00:00
|
|
|
return error;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
file_count += this->HandleLCovCoverage(&cont);
|
|
|
|
error = cont.Error;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (file_count < 0) {
|
2007-04-27 03:20:12 +00:00
|
|
|
return error;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
file_count += this->HandleTracePyCoverage(&cont);
|
2012-04-25 21:04:28 +00:00
|
|
|
error = cont.Error;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (file_count < 0) {
|
2010-05-25 13:23:25 +00:00
|
|
|
return error;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-05-25 13:23:25 +00:00
|
|
|
file_count += this->HandlePHPCoverage(&cont);
|
2012-04-25 21:04:28 +00:00
|
|
|
error = cont.Error;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (file_count < 0) {
|
2007-04-27 03:20:12 +00:00
|
|
|
return error;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-06-03 18:30:46 +00:00
|
|
|
file_count += this->HandleCoberturaCoverage(&cont);
|
2013-09-27 14:42:39 +00:00
|
|
|
error = cont.Error;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (file_count < 0) {
|
2013-09-27 14:42:39 +00:00
|
|
|
return error;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-09-27 14:42:39 +00:00
|
|
|
|
2012-05-01 21:00:43 +00:00
|
|
|
file_count += this->HandleMumpsCoverage(&cont);
|
2007-04-27 03:20:12 +00:00
|
|
|
error = cont.Error;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (file_count < 0) {
|
2012-04-25 21:04:28 +00:00
|
|
|
return error;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-03-09 16:17:10 +00:00
|
|
|
|
2014-05-21 19:19:35 +00:00
|
|
|
file_count += this->HandleJacocoCoverage(&cont);
|
|
|
|
error = cont.Error;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (file_count < 0) {
|
2014-10-23 21:03:30 +00:00
|
|
|
return error;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-10-23 21:03:30 +00:00
|
|
|
|
|
|
|
file_count += this->HandleBlanketJSCoverage(&cont);
|
|
|
|
error = cont.Error;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (file_count < 0) {
|
2014-05-21 19:19:35 +00:00
|
|
|
return error;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-05-21 19:19:35 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
file_count += this->HandleDelphiCoverage(&cont);
|
2014-09-29 18:52:10 +00:00
|
|
|
error = cont.Error;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (file_count < 0) {
|
2014-09-29 18:52:10 +00:00
|
|
|
return error;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-04-23 13:16:18 +00:00
|
|
|
std::set<std::string> uncovered = this->FindUncoveredFiles(&cont);
|
2007-04-27 03:20:12 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (file_count == 0 && this->ExtraCoverageGlobs.empty()) {
|
|
|
|
cmCTestOptionalLog(
|
|
|
|
this->CTest, WARNING,
|
2006-10-15 11:54:52 +00:00
|
|
|
" Cannot find any coverage files. Ignoring Coverage request."
|
2016-05-16 14:34:04 +00:00
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
2007-04-27 03:20:12 +00:00
|
|
|
return error;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
cmGeneratedFileStream covSumFile;
|
|
|
|
cmGeneratedFileStream covLogFile;
|
2015-05-24 19:18:40 +00:00
|
|
|
cmXMLWriter covSumXML(covSumFile);
|
|
|
|
cmXMLWriter covLogXML(covLogFile);
|
2005-07-14 17:25:40 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->StartResultingXML(cmCTest::PartCoverage, "Coverage",
|
|
|
|
covSumFile)) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Cannot open coverage summary file." << std::endl);
|
2007-04-27 03:20:12 +00:00
|
|
|
return -1;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-05-24 19:18:40 +00:00
|
|
|
covSumFile.setf(std::ios::fixed, std::ios::floatfield);
|
|
|
|
covSumFile.precision(2);
|
2006-03-09 16:17:10 +00:00
|
|
|
|
2015-05-24 19:18:40 +00:00
|
|
|
this->CTest->StartXML(covSumXML, this->AppendXML);
|
2007-04-27 03:20:12 +00:00
|
|
|
// Produce output xml files
|
2006-03-09 16:17:10 +00:00
|
|
|
|
2015-05-24 19:18:40 +00:00
|
|
|
covSumXML.StartElement("Coverage");
|
|
|
|
covSumXML.Element("StartDateTime", coverage_start_time);
|
|
|
|
covSumXML.Element("StartTime", coverage_start_time_time);
|
2007-04-27 03:20:12 +00:00
|
|
|
int logFileCount = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->StartCoverageLogFile(covLogFile, logFileCount)) {
|
2007-04-27 03:20:12 +00:00
|
|
|
return -1;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-05-24 19:18:40 +00:00
|
|
|
this->StartCoverageLogXML(covLogXML);
|
2007-04-27 03:20:12 +00:00
|
|
|
int cnt = 0;
|
|
|
|
long total_tested = 0;
|
|
|
|
long total_untested = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
// std::string fullSourceDir = sourceDir + "/";
|
|
|
|
// std::string fullBinaryDir = binaryDir + "/";
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, std::endl, this->Quiet);
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestOptionalLog(
|
|
|
|
this->CTest, HANDLER_OUTPUT,
|
2015-02-17 20:57:26 +00:00
|
|
|
" Accumulating results (each . represents one file):" << std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " ", this->Quiet);
|
2007-04-27 03:20:12 +00:00
|
|
|
|
|
|
|
std::vector<std::string> errorsWhileAccumulating;
|
|
|
|
|
|
|
|
file_count = 0;
|
2017-09-14 13:11:58 +00:00
|
|
|
for (auto const& file : cont.TotalCoverage) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "." << std::flush,
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Quiet);
|
|
|
|
file_count++;
|
|
|
|
if (file_count % 50 == 0) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
|
|
|
" processed: " << file_count << " out of "
|
|
|
|
<< cont.TotalCoverage.size()
|
|
|
|
<< std::endl,
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Quiet);
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " ", this->Quiet);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-03-11 17:31:40 +00:00
|
|
|
|
2017-09-14 13:11:58 +00:00
|
|
|
const std::string fullFileName = file.first;
|
2017-09-19 10:22:50 +00:00
|
|
|
bool shouldIDoCoverage =
|
|
|
|
this->ShouldIDoCoverage(fullFileName, sourceDir, binaryDir);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!shouldIDoCoverage) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
".NoDartCoverage found, so skip coverage check for: "
|
|
|
|
<< fullFileName << std::endl,
|
|
|
|
this->Quiet);
|
2009-03-11 17:31:40 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-03-11 17:31:40 +00:00
|
|
|
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Process file: " << fullFileName << std::endl,
|
|
|
|
this->Quiet);
|
2006-03-09 16:17:10 +00:00
|
|
|
|
2018-01-31 15:20:02 +00:00
|
|
|
if (!cmSystemTools::FileExists(fullFileName)) {
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Cannot find file: " << fullFileName << std::endl);
|
2007-04-27 03:20:12 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (++cnt % 100 == 0) {
|
2015-05-24 19:18:40 +00:00
|
|
|
this->EndCoverageLogXML(covLogXML);
|
2009-03-11 17:31:40 +00:00
|
|
|
this->EndCoverageLogFile(covLogFile, logFileCount);
|
2016-05-16 14:34:04 +00:00
|
|
|
logFileCount++;
|
|
|
|
if (!this->StartCoverageLogFile(covLogFile, logFileCount)) {
|
2009-03-11 17:31:40 +00:00
|
|
|
return -1;
|
2007-04-27 03:20:12 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
this->StartCoverageLogXML(covLogXML);
|
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
const std::string fileName = cmSystemTools::GetFilenameName(fullFileName);
|
2009-02-13 20:17:06 +00:00
|
|
|
std::string shortFileName =
|
|
|
|
this->CTest->GetShortPathToFile(fullFileName.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
const cmCTestCoverageHandlerContainer::SingleFileCoverageVector& fcov =
|
2017-09-14 13:11:58 +00:00
|
|
|
file.second;
|
2015-05-24 19:18:40 +00:00
|
|
|
covLogXML.StartElement("File");
|
|
|
|
covLogXML.Attribute("Name", fileName);
|
|
|
|
covLogXML.Attribute("FullPath", shortFileName);
|
|
|
|
covLogXML.StartElement("Report");
|
2007-04-27 03:20:12 +00:00
|
|
|
|
2014-01-04 05:47:13 +00:00
|
|
|
cmsys::ifstream ifs(fullFileName.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!ifs) {
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream ostr;
|
2016-05-16 14:34:04 +00:00
|
|
|
ostr << "Cannot open source file: " << fullFileName;
|
2007-04-27 03:20:12 +00:00
|
|
|
errorsWhileAccumulating.push_back(ostr.str());
|
2016-05-16 14:34:04 +00:00
|
|
|
error++;
|
2007-04-27 03:20:12 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
|
|
|
|
int tested = 0;
|
|
|
|
int untested = 0;
|
|
|
|
|
|
|
|
cmCTestCoverageHandlerContainer::SingleFileCoverageVector::size_type cc;
|
|
|
|
std::string line;
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Actually performing coverage for: " << fullFileName
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
for (cc = 0; cc < fcov.size(); cc++) {
|
|
|
|
if (!cmSystemTools::GetLineFromStream(ifs, line) &&
|
|
|
|
cc != fcov.size() - 1) {
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream ostr;
|
2014-03-11 12:35:32 +00:00
|
|
|
ostr << "Problem reading source file: " << fullFileName
|
2016-05-16 14:34:04 +00:00
|
|
|
<< " line:" << cc << " out total: " << fcov.size() - 1;
|
2007-04-27 03:20:12 +00:00
|
|
|
errorsWhileAccumulating.push_back(ostr.str());
|
2016-05-16 14:34:04 +00:00
|
|
|
error++;
|
2007-04-27 03:20:12 +00:00
|
|
|
break;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-05-24 19:18:40 +00:00
|
|
|
covLogXML.StartElement("Line");
|
|
|
|
covLogXML.Attribute("Number", cc);
|
|
|
|
covLogXML.Attribute("Count", fcov[cc]);
|
|
|
|
covLogXML.Content(line);
|
|
|
|
covLogXML.EndElement(); // Line
|
2016-05-16 14:34:04 +00:00
|
|
|
if (fcov[cc] == 0) {
|
|
|
|
untested++;
|
|
|
|
} else if (fcov[cc] > 0) {
|
|
|
|
tested++;
|
2007-04-27 03:20:12 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (cmSystemTools::GetLineFromStream(ifs, line)) {
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream ostr;
|
2016-05-16 14:34:04 +00:00
|
|
|
ostr << "Looks like there are more lines in the file: " << fullFileName;
|
2007-04-27 03:20:12 +00:00
|
|
|
errorsWhileAccumulating.push_back(ostr.str());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
float cper = 0;
|
|
|
|
float cmet = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (tested + untested > 0) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cper = (100 *
|
|
|
|
SAFEDIV(static_cast<float>(tested),
|
|
|
|
static_cast<float>(tested + untested)));
|
2016-05-16 14:34:04 +00:00
|
|
|
cmet = (SAFEDIV(static_cast<float>(tested + 10),
|
|
|
|
static_cast<float>(tested + untested + 10)));
|
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
total_tested += tested;
|
|
|
|
total_untested += untested;
|
2015-05-24 19:18:40 +00:00
|
|
|
covLogXML.EndElement(); // Report
|
|
|
|
covLogXML.EndElement(); // File
|
|
|
|
covSumXML.StartElement("File");
|
|
|
|
covSumXML.Attribute("Name", fileName);
|
|
|
|
covSumXML.Attribute("FullPath",
|
2016-05-16 14:34:04 +00:00
|
|
|
this->CTest->GetShortPathToFile(fullFileName.c_str()));
|
2015-05-24 19:18:40 +00:00
|
|
|
covSumXML.Attribute("Covered", tested + untested > 0 ? "true" : "false");
|
|
|
|
covSumXML.Element("LOCTested", tested);
|
|
|
|
covSumXML.Element("LOCUnTested", untested);
|
|
|
|
covSumXML.Element("PercentCoverage", cper);
|
|
|
|
covSumXML.Element("CoverageMetric", cmet);
|
|
|
|
this->WriteXMLLabels(covSumXML, shortFileName);
|
|
|
|
covSumXML.EndElement(); // File
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-04-23 13:16:18 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
// Handle all the files in the extra coverage globs that have no cov data
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& u : uncovered) {
|
|
|
|
std::string fileName = cmSystemTools::GetFilenameName(u);
|
|
|
|
std::string fullPath = cont.SourceDir + "/" + u;
|
2010-04-23 15:22:54 +00:00
|
|
|
|
2015-05-24 19:18:40 +00:00
|
|
|
covLogXML.StartElement("File");
|
|
|
|
covLogXML.Attribute("Name", fileName);
|
2017-09-14 13:11:58 +00:00
|
|
|
covLogXML.Attribute("FullPath", u);
|
2015-05-24 19:18:40 +00:00
|
|
|
covLogXML.StartElement("Report");
|
2010-04-23 13:16:18 +00:00
|
|
|
|
2014-01-04 05:47:13 +00:00
|
|
|
cmsys::ifstream ifs(fullPath.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!ifs) {
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream ostr;
|
2016-05-16 14:34:04 +00:00
|
|
|
ostr << "Cannot open source file: " << fullPath;
|
2010-04-23 13:16:18 +00:00
|
|
|
errorsWhileAccumulating.push_back(ostr.str());
|
2016-05-16 14:34:04 +00:00
|
|
|
error++;
|
2017-09-19 09:55:53 +00:00
|
|
|
covLogXML.EndElement(); // Report
|
|
|
|
covLogXML.EndElement(); // File
|
2010-04-23 13:16:18 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-04-23 13:16:18 +00:00
|
|
|
int untested = 0;
|
|
|
|
std::string line;
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2017-09-14 13:11:58 +00:00
|
|
|
"Actually performing coverage for: " << u << std::endl,
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Quiet);
|
|
|
|
while (cmSystemTools::GetLineFromStream(ifs, line)) {
|
2015-05-24 19:18:40 +00:00
|
|
|
covLogXML.StartElement("Line");
|
|
|
|
covLogXML.Attribute("Number", untested);
|
|
|
|
covLogXML.Attribute("Count", 0);
|
|
|
|
covLogXML.Content(line);
|
|
|
|
covLogXML.EndElement(); // Line
|
2016-05-16 14:34:04 +00:00
|
|
|
untested++;
|
|
|
|
}
|
2015-05-24 19:18:40 +00:00
|
|
|
covLogXML.EndElement(); // Report
|
|
|
|
covLogXML.EndElement(); // File
|
2010-04-23 13:16:18 +00:00
|
|
|
|
|
|
|
total_untested += untested;
|
2015-05-24 19:18:40 +00:00
|
|
|
covSumXML.StartElement("File");
|
|
|
|
covSumXML.Attribute("Name", fileName);
|
2017-09-14 13:11:58 +00:00
|
|
|
covSumXML.Attribute("FullPath", u);
|
2015-05-24 19:18:40 +00:00
|
|
|
covSumXML.Attribute("Covered", "true");
|
|
|
|
covSumXML.Element("LOCTested", 0);
|
|
|
|
covSumXML.Element("LOCUnTested", untested);
|
|
|
|
covSumXML.Element("PercentCoverage", 0);
|
|
|
|
covSumXML.Element("CoverageMetric", 0);
|
2017-09-14 13:11:58 +00:00
|
|
|
this->WriteXMLLabels(covSumXML, u);
|
2015-05-24 19:18:40 +00:00
|
|
|
covSumXML.EndElement(); // File
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-05-24 19:18:40 +00:00
|
|
|
|
|
|
|
this->EndCoverageLogXML(covLogXML);
|
2007-04-27 03:20:12 +00:00
|
|
|
this->EndCoverageLogFile(covLogFile, logFileCount);
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!errorsWhileAccumulating.empty()) {
|
2007-04-27 03:20:12 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, std::endl);
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Error(s) while accumulating results:" << std::endl);
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& er : errorsWhileAccumulating) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, " " << er << std::endl);
|
2007-04-27 03:20:12 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
|
2009-01-28 21:56:33 +00:00
|
|
|
long total_lines = total_tested + total_untested;
|
2016-05-16 14:34:04 +00:00
|
|
|
float percent_coverage = 100 *
|
|
|
|
SAFEDIV(static_cast<float>(total_tested), static_cast<float>(total_lines));
|
|
|
|
if (total_lines == 0) {
|
2007-04-27 03:20:12 +00:00
|
|
|
percent_coverage = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
|
|
|
|
std::string end_time = this->CTest->CurrentTime();
|
|
|
|
|
2015-05-24 19:18:40 +00:00
|
|
|
covSumXML.Element("LOCTested", total_tested);
|
|
|
|
covSumXML.Element("LOCUntested", total_untested);
|
|
|
|
covSumXML.Element("LOC", total_lines);
|
|
|
|
covSumXML.Element("PercentCoverage", percent_coverage);
|
|
|
|
covSumXML.Element("EndDateTime", end_time);
|
2017-11-15 18:00:09 +00:00
|
|
|
covSumXML.Element("EndTime", std::chrono::system_clock::now());
|
2017-11-03 13:25:33 +00:00
|
|
|
covSumXML.Element("ElapsedMinutes",
|
|
|
|
std::chrono::duration_cast<std::chrono::minutes>(
|
|
|
|
std::chrono::steady_clock::now() - elapsed_time_start)
|
|
|
|
.count());
|
2015-05-24 19:18:40 +00:00
|
|
|
covSumXML.EndElement(); // Coverage
|
|
|
|
this->CTest->EndXML(covSumXML);
|
2007-04-27 03:20:12 +00:00
|
|
|
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
|
|
|
"" << std::endl
|
|
|
|
<< "\tCovered LOC: " << total_tested << std::endl
|
|
|
|
<< "\tNot covered LOC: " << total_untested << std::endl
|
|
|
|
<< "\tTotal LOC: " << total_lines << std::endl
|
|
|
|
<< "\tPercentage Coverage: "
|
|
|
|
<< std::setiosflags(std::ios::fixed) << std::setprecision(2)
|
|
|
|
<< (percent_coverage) << "%" << std::endl);
|
2007-04-27 03:20:12 +00:00
|
|
|
|
|
|
|
ofs << "\tCovered LOC: " << total_tested << std::endl
|
2016-05-16 14:34:04 +00:00
|
|
|
<< "\tNot covered LOC: " << total_untested << std::endl
|
|
|
|
<< "\tTotal LOC: " << total_lines << std::endl
|
|
|
|
<< "\tPercentage Coverage: " << std::setiosflags(std::ios::fixed)
|
|
|
|
<< std::setprecision(2) << (percent_coverage) << "%" << std::endl;
|
2007-04-27 03:20:12 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (error) {
|
2007-04-27 03:20:12 +00:00
|
|
|
return -1;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void cmCTestCoverageHandler::PopulateCustomVectors(cmMakefile* mf)
|
2007-04-27 03:20:12 +00:00
|
|
|
{
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" Add coverage exclude regular expressions." << std::endl,
|
|
|
|
this->Quiet);
|
2007-04-27 03:20:12 +00:00
|
|
|
this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_COVERAGE_EXCLUDE",
|
2016-05-16 14:34:04 +00:00
|
|
|
this->CustomCoverageExclude);
|
2010-04-23 13:16:18 +00:00
|
|
|
this->CTest->PopulateCustomVector(mf, "CTEST_EXTRA_COVERAGE_GLOB",
|
2016-05-16 14:34:04 +00:00
|
|
|
this->ExtraCoverageGlobs);
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& cce : this->CustomCoverageExclude) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2017-09-14 13:11:58 +00:00
|
|
|
" Add coverage exclude: " << cce << std::endl,
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Quiet);
|
|
|
|
}
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& ecg : this->ExtraCoverageGlobs) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2017-09-14 13:11:58 +00:00
|
|
|
" Add coverage glob: " << ecg << std::endl,
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Quiet);
|
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
}
|
|
|
|
|
2008-07-31 15:28:45 +00:00
|
|
|
// Fix for issue #4971 where the case of the drive letter component of
|
|
|
|
// the filenames might be different when analyzing gcov output.
|
|
|
|
//
|
|
|
|
// Compare file names: fnc(fn1) == fnc(fn2) // fnc == file name compare
|
|
|
|
//
|
|
|
|
#ifdef _WIN32
|
2018-06-01 13:53:41 +00:00
|
|
|
# define fnc(s) cmSystemTools::LowerCase(s)
|
2008-07-31 15:28:45 +00:00
|
|
|
#else
|
2018-06-01 13:53:41 +00:00
|
|
|
# define fnc(s) s
|
2008-07-31 15:28:45 +00:00
|
|
|
#endif
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
bool IsFileInDir(const std::string& infile, const std::string& indir)
|
2009-10-12 18:51:54 +00:00
|
|
|
{
|
2014-10-15 12:54:05 +00:00
|
|
|
std::string file = cmSystemTools::CollapseFullPath(infile);
|
|
|
|
std::string dir = cmSystemTools::CollapseFullPath(indir);
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2016-06-01 21:29:53 +00:00
|
|
|
return file.size() > dir.size() &&
|
|
|
|
fnc(file.substr(0, dir.size())) == fnc(dir) && file[dir.size()] == '/';
|
2009-10-12 18:51:54 +00:00
|
|
|
}
|
|
|
|
|
2010-05-25 13:23:25 +00:00
|
|
|
int cmCTestCoverageHandler::HandlePHPCoverage(
|
|
|
|
cmCTestCoverageHandlerContainer* cont)
|
|
|
|
{
|
|
|
|
cmParsePHPCoverage cov(*cont, this->CTest);
|
|
|
|
std::string coverageDir = this->CTest->GetBinaryDir() + "/xdebugCoverage";
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cmSystemTools::FileIsDirectory(coverageDir)) {
|
2010-05-25 13:23:25 +00:00
|
|
|
cov.ReadPHPCoverageDirectory(coverageDir.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-05-25 13:23:25 +00:00
|
|
|
return static_cast<int>(cont->TotalCoverage.size());
|
|
|
|
}
|
2013-09-27 14:42:39 +00:00
|
|
|
|
2014-06-03 18:30:46 +00:00
|
|
|
int cmCTestCoverageHandler::HandleCoberturaCoverage(
|
2013-09-27 14:42:39 +00:00
|
|
|
cmCTestCoverageHandlerContainer* cont)
|
|
|
|
{
|
2014-06-03 18:30:46 +00:00
|
|
|
cmParseCoberturaCoverage cov(*cont, this->CTest);
|
2013-09-27 14:42:39 +00:00
|
|
|
|
2015-11-16 21:27:57 +00:00
|
|
|
// Assume the coverage.xml is in the binary directory
|
|
|
|
// check for the COBERTURADIR environment variable,
|
|
|
|
// if it doesn't exist or is empty, assume the
|
|
|
|
// binary directory is used.
|
|
|
|
std::string coverageXMLFile;
|
2016-07-07 21:54:05 +00:00
|
|
|
if (!cmSystemTools::GetEnv("COBERTURADIR", coverageXMLFile) ||
|
|
|
|
coverageXMLFile.empty()) {
|
2016-05-16 14:34:04 +00:00
|
|
|
coverageXMLFile = this->CTest->GetBinaryDir();
|
|
|
|
}
|
2015-11-16 21:27:57 +00:00
|
|
|
// build the find file string with the directory from above
|
|
|
|
coverageXMLFile += "/coverage.xml";
|
2013-09-27 14:42:39 +00:00
|
|
|
|
2018-01-31 15:20:02 +00:00
|
|
|
if (cmSystemTools::FileExists(coverageXMLFile)) {
|
2015-11-16 21:27:57 +00:00
|
|
|
// If file exists, parse it
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Parsing Cobertura XML file: " << coverageXMLFile
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
2013-09-27 14:42:39 +00:00
|
|
|
cov.ReadCoverageXML(coverageXMLFile.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" Cannot find Cobertura XML file: " << coverageXMLFile
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
}
|
2013-09-27 14:42:39 +00:00
|
|
|
return static_cast<int>(cont->TotalCoverage.size());
|
|
|
|
}
|
|
|
|
|
2012-05-01 21:00:43 +00:00
|
|
|
int cmCTestCoverageHandler::HandleMumpsCoverage(
|
2012-04-25 21:04:28 +00:00
|
|
|
cmCTestCoverageHandlerContainer* cont)
|
|
|
|
{
|
2012-05-01 21:00:43 +00:00
|
|
|
// try gtm coverage
|
2012-04-25 21:04:28 +00:00
|
|
|
cmParseGTMCoverage cov(*cont, this->CTest);
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string coverageFile =
|
|
|
|
this->CTest->GetBinaryDir() + "/gtm_coverage.mcov";
|
2018-01-31 15:20:02 +00:00
|
|
|
if (cmSystemTools::FileExists(coverageFile)) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Parsing Cache Coverage: " << coverageFile << std::endl,
|
|
|
|
this->Quiet);
|
2012-05-01 17:35:07 +00:00
|
|
|
cov.ReadCoverageFile(coverageFile.c_str());
|
2012-05-01 21:00:43 +00:00
|
|
|
return static_cast<int>(cont->TotalCoverage.size());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2016-08-18 18:04:21 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
" Cannot find GTM coverage file: " << coverageFile
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
2012-05-01 21:00:43 +00:00
|
|
|
cmParseCacheCoverage ccov(*cont, this->CTest);
|
2016-05-16 14:34:04 +00:00
|
|
|
coverageFile = this->CTest->GetBinaryDir() + "/cache_coverage.cmcov";
|
2018-01-31 15:20:02 +00:00
|
|
|
if (cmSystemTools::FileExists(coverageFile)) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Parsing Cache Coverage: " << coverageFile << std::endl,
|
|
|
|
this->Quiet);
|
2012-05-01 21:00:43 +00:00
|
|
|
ccov.ReadCoverageFile(coverageFile.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" Cannot find Cache coverage file: " << coverageFile
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
}
|
2012-04-25 21:04:28 +00:00
|
|
|
return static_cast<int>(cont->TotalCoverage.size());
|
|
|
|
}
|
2011-10-22 14:38:16 +00:00
|
|
|
|
2012-04-16 12:42:11 +00:00
|
|
|
struct cmCTestCoverageHandlerLocale
|
|
|
|
{
|
|
|
|
cmCTestCoverageHandlerLocale()
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
2016-07-07 21:54:05 +00:00
|
|
|
std::string l;
|
|
|
|
if (cmSystemTools::GetEnv("LC_ALL", l)) {
|
2012-04-16 12:42:11 +00:00
|
|
|
lc_all = l;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (lc_all != "C") {
|
2012-04-16 12:42:11 +00:00
|
|
|
cmSystemTools::PutEnv("LC_ALL=C");
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-04-16 12:42:11 +00:00
|
|
|
~cmCTestCoverageHandlerLocale()
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
|
|
|
if (!lc_all.empty()) {
|
2014-11-23 10:05:50 +00:00
|
|
|
cmSystemTools::PutEnv("LC_ALL=" + lc_all);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2012-04-16 12:42:11 +00:00
|
|
|
cmSystemTools::UnsetEnv("LC_ALL");
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2019-02-14 16:29:57 +00:00
|
|
|
cmCTestCoverageHandlerLocale(const cmCTestCoverageHandlerLocale&) = delete;
|
|
|
|
cmCTestCoverageHandlerLocale& operator=(
|
|
|
|
const cmCTestCoverageHandlerLocale&) = delete;
|
2012-04-16 12:42:11 +00:00
|
|
|
std::string lc_all;
|
|
|
|
};
|
|
|
|
|
2014-05-21 19:19:35 +00:00
|
|
|
int cmCTestCoverageHandler::HandleJacocoCoverage(
|
|
|
|
cmCTestCoverageHandlerContainer* cont)
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmParseJacocoCoverage cov = cmParseJacocoCoverage(*cont, this->CTest);
|
2015-10-29 20:08:10 +00:00
|
|
|
|
|
|
|
// Search in the source directory.
|
|
|
|
cmsys::Glob g1;
|
2014-05-21 19:19:35 +00:00
|
|
|
std::vector<std::string> files;
|
2015-10-29 20:08:10 +00:00
|
|
|
g1.SetRecurse(true);
|
2014-05-21 19:19:35 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string SourceDir =
|
|
|
|
this->CTest->GetCTestConfiguration("SourceDirectory");
|
|
|
|
std::string coverageFile = SourceDir + "/*jacoco.xml";
|
2014-05-21 19:19:35 +00:00
|
|
|
|
2015-10-29 20:08:10 +00:00
|
|
|
g1.FindFiles(coverageFile);
|
|
|
|
files = g1.GetFiles();
|
|
|
|
|
|
|
|
// ...and in the binary directory.
|
|
|
|
cmsys::Glob g2;
|
|
|
|
g2.SetRecurse(true);
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string binaryDir = this->CTest->GetCTestConfiguration("BuildDirectory");
|
|
|
|
std::string binCoverageFile = binaryDir + "/*jacoco.xml";
|
2015-10-29 20:08:10 +00:00
|
|
|
g2.FindFiles(binCoverageFile);
|
2019-05-23 12:49:54 +00:00
|
|
|
cmAppend(files, g2.GetFiles());
|
2015-10-29 20:08:10 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!files.empty()) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Found Jacoco Files, Performing Coverage" << std::endl,
|
|
|
|
this->Quiet);
|
2014-05-21 19:19:35 +00:00
|
|
|
cov.LoadCoverageData(files);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" Cannot find Jacoco coverage files: " << coverageFile
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
}
|
2014-05-21 19:19:35 +00:00
|
|
|
return static_cast<int>(cont->TotalCoverage.size());
|
|
|
|
}
|
|
|
|
|
2014-09-29 18:52:10 +00:00
|
|
|
int cmCTestCoverageHandler::HandleDelphiCoverage(
|
|
|
|
cmCTestCoverageHandlerContainer* cont)
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmParseDelphiCoverage cov = cmParseDelphiCoverage(*cont, this->CTest);
|
2014-09-29 18:52:10 +00:00
|
|
|
cmsys::Glob g;
|
|
|
|
std::vector<std::string> files;
|
|
|
|
g.SetRecurse(true);
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string BinDir = this->CTest->GetBinaryDir();
|
|
|
|
std::string coverageFile = BinDir + "/*(*.pas).html";
|
2014-10-23 21:03:30 +00:00
|
|
|
|
2014-09-29 18:52:10 +00:00
|
|
|
g.FindFiles(coverageFile);
|
2016-05-16 14:34:04 +00:00
|
|
|
files = g.GetFiles();
|
|
|
|
if (!files.empty()) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Found Delphi HTML Files, Performing Coverage"
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
2014-09-29 18:52:10 +00:00
|
|
|
cov.LoadCoverageData(files);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" Cannot find Delphi coverage files: " << coverageFile
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
}
|
2014-09-29 18:52:10 +00:00
|
|
|
return static_cast<int>(cont->TotalCoverage.size());
|
|
|
|
}
|
2014-10-23 21:03:30 +00:00
|
|
|
|
2017-09-13 13:32:47 +00:00
|
|
|
static std::string joinCommandLine(const std::vector<std::string>& args)
|
|
|
|
{
|
|
|
|
std::string ret;
|
|
|
|
|
|
|
|
for (std::string const& s : args) {
|
|
|
|
if (s.find(' ') == std::string::npos) {
|
|
|
|
ret += s + ' ';
|
|
|
|
} else {
|
|
|
|
ret += "\"" + s + "\" ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// drop trailing whitespace
|
|
|
|
ret.erase(ret.size() - 1);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-23 21:03:30 +00:00
|
|
|
int cmCTestCoverageHandler::HandleBlanketJSCoverage(
|
|
|
|
cmCTestCoverageHandlerContainer* cont)
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
|
|
|
cmParseBlanketJSCoverage cov = cmParseBlanketJSCoverage(*cont, this->CTest);
|
|
|
|
std::string SourceDir =
|
|
|
|
this->CTest->GetCTestConfiguration("SourceDirectory");
|
2014-10-23 21:03:30 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
// Look for something other than output.json, still JSON extension.
|
|
|
|
std::string coverageFile = SourceDir + "/*.json";
|
2014-10-23 21:03:30 +00:00
|
|
|
cmsys::Glob g;
|
|
|
|
std::vector<std::string> files;
|
2015-11-18 18:01:22 +00:00
|
|
|
std::vector<std::string> blanketFiles;
|
2014-10-23 21:03:30 +00:00
|
|
|
g.FindFiles(coverageFile);
|
2016-05-16 14:34:04 +00:00
|
|
|
files = g.GetFiles();
|
2015-11-18 18:01:22 +00:00
|
|
|
// Ensure that the JSON files found are the result of the
|
|
|
|
// Blanket.js output. Check for the "node-jscoverage"
|
|
|
|
// string on the second line
|
|
|
|
std::string line;
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& fileEntry : files) {
|
|
|
|
cmsys::ifstream in(fileEntry.c_str());
|
2015-11-18 18:01:22 +00:00
|
|
|
cmSystemTools::GetLineFromStream(in, line);
|
|
|
|
cmSystemTools::GetLineFromStream(in, line);
|
2017-05-30 19:37:46 +00:00
|
|
|
if (line.find("node-jscoverage") != std::string::npos) {
|
2017-09-14 13:11:58 +00:00
|
|
|
blanketFiles.push_back(fileEntry);
|
2015-11-18 18:01:22 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-11-18 18:01:22 +00:00
|
|
|
// Take all files with the node-jscoverage string and parse those
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!blanketFiles.empty()) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Found BlanketJS output JSON, Performing Coverage"
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
2014-10-23 21:03:30 +00:00
|
|
|
cov.LoadCoverageData(files);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
|
|
|
cmCTestOptionalLog(
|
|
|
|
this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
" Cannot find BlanketJS coverage files: " << coverageFile << std::endl,
|
|
|
|
this->Quiet);
|
2014-10-23 21:03:30 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
return static_cast<int>(cont->TotalCoverage.size());
|
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
int cmCTestCoverageHandler::HandleGCovCoverage(
|
|
|
|
cmCTestCoverageHandlerContainer* cont)
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string gcovCommand =
|
|
|
|
this->CTest->GetCTestConfiguration("CoverageCommand");
|
|
|
|
if (gcovCommand.empty()) {
|
2018-03-27 18:59:58 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
"Could not find gcov." << std::endl, this->Quiet);
|
2014-02-26 15:01:34 +00:00
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
std::string gcovExtraFlags =
|
|
|
|
this->CTest->GetCTestConfiguration("CoverageExtraFlags");
|
2007-04-27 03:20:12 +00:00
|
|
|
|
2014-02-27 13:37:52 +00:00
|
|
|
// Immediately skip to next coverage option since codecov is only for Intel
|
|
|
|
// compiler
|
2016-05-16 14:34:04 +00:00
|
|
|
if (gcovCommand == "codecov") {
|
2014-02-27 13:37:52 +00:00
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
|
2007-04-27 03:20:12 +00:00
|
|
|
// Style 1
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string st1gcovOutputRex1 =
|
|
|
|
"[0-9]+\\.[0-9]+% of [0-9]+ (source |)lines executed in file (.*)$";
|
2007-04-27 03:20:12 +00:00
|
|
|
std::string st1gcovOutputRex2 = "^Creating (.*\\.gcov)\\.";
|
|
|
|
cmsys::RegularExpression st1re1(st1gcovOutputRex1.c_str());
|
|
|
|
cmsys::RegularExpression st1re2(st1gcovOutputRex2.c_str());
|
|
|
|
|
|
|
|
// Style 2
|
|
|
|
std::string st2gcovOutputRex1 = "^File *[`'](.*)'$";
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string st2gcovOutputRex2 =
|
|
|
|
"Lines executed: *[0-9]+\\.[0-9]+% of [0-9]+$";
|
2012-05-03 20:02:27 +00:00
|
|
|
std::string st2gcovOutputRex3 = "^(.*)reating [`'](.*\\.gcov)'";
|
2007-04-27 03:20:12 +00:00
|
|
|
std::string st2gcovOutputRex4 = "^(.*):unexpected EOF *$";
|
|
|
|
std::string st2gcovOutputRex5 = "^(.*):cannot open source file*$";
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string st2gcovOutputRex6 =
|
|
|
|
"^(.*):source file is newer than graph file `(.*)'$";
|
2007-04-27 03:20:12 +00:00
|
|
|
cmsys::RegularExpression st2re1(st2gcovOutputRex1.c_str());
|
|
|
|
cmsys::RegularExpression st2re2(st2gcovOutputRex2.c_str());
|
|
|
|
cmsys::RegularExpression st2re3(st2gcovOutputRex3.c_str());
|
|
|
|
cmsys::RegularExpression st2re4(st2gcovOutputRex4.c_str());
|
|
|
|
cmsys::RegularExpression st2re5(st2gcovOutputRex5.c_str());
|
|
|
|
cmsys::RegularExpression st2re6(st2gcovOutputRex6.c_str());
|
|
|
|
|
2009-03-09 16:19:56 +00:00
|
|
|
std::vector<std::string> files;
|
|
|
|
this->FindGCovFiles(files);
|
2007-04-27 03:20:12 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (files.empty()) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" Cannot find any GCov coverage files." << std::endl,
|
|
|
|
this->Quiet);
|
2012-08-13 17:42:58 +00:00
|
|
|
// No coverage files is a valid thing, so the exit code is 0
|
2007-04-27 03:20:12 +00:00
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
|
|
|
|
std::string testingDir = this->CTest->GetBinaryDir() + "/Testing";
|
|
|
|
std::string tempDir = testingDir + "/CoverageInfo";
|
2018-03-04 06:27:09 +00:00
|
|
|
if (!cmSystemTools::MakeDirectory(tempDir)) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unable to make directory: " << tempDir << std::endl);
|
|
|
|
cont->Error++;
|
|
|
|
return 0;
|
|
|
|
}
|
2017-03-01 18:41:50 +00:00
|
|
|
cmWorkingDirectory workdir(tempDir);
|
2007-04-27 03:20:12 +00:00
|
|
|
|
|
|
|
int gcovStyle = 0;
|
|
|
|
|
|
|
|
std::set<std::string> missingFiles;
|
|
|
|
|
2016-12-10 13:53:06 +00:00
|
|
|
std::string actualSourceFile;
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestOptionalLog(
|
|
|
|
this->CTest, HANDLER_OUTPUT,
|
2015-02-17 20:57:26 +00:00
|
|
|
" Processing coverage (each . represents one file):" << std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " ", this->Quiet);
|
2007-04-27 03:20:12 +00:00
|
|
|
int file_count = 0;
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2008-05-10 15:12:09 +00:00
|
|
|
// make sure output from gcov is in English!
|
2012-04-16 12:42:11 +00:00
|
|
|
cmCTestCoverageHandlerLocale locale_C;
|
|
|
|
static_cast<void>(locale_C);
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2017-09-13 13:32:47 +00:00
|
|
|
std::vector<std::string> basecovargs =
|
2019-02-20 18:50:00 +00:00
|
|
|
cmSystemTools::ParseArguments(gcovExtraFlags);
|
2017-09-13 13:32:47 +00:00
|
|
|
basecovargs.insert(basecovargs.begin(), gcovCommand);
|
2019-01-16 06:13:07 +00:00
|
|
|
basecovargs.emplace_back("-o");
|
2017-09-13 13:32:47 +00:00
|
|
|
|
2009-10-12 18:51:54 +00:00
|
|
|
// files is a list of *.da and *.gcda files with coverage data in them.
|
|
|
|
// These are binary files that you give as input to gcov so that it will
|
|
|
|
// give us text output we can analyze to summarize coverage.
|
|
|
|
//
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& f : files) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "." << std::flush,
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Quiet);
|
2009-10-12 18:51:54 +00:00
|
|
|
|
|
|
|
// Call gcov to get coverage data for this *.gcda file:
|
|
|
|
//
|
2017-09-14 13:11:58 +00:00
|
|
|
std::string fileDir = cmSystemTools::GetFilenamePath(f);
|
2017-09-13 13:32:47 +00:00
|
|
|
std::vector<std::string> covargs = basecovargs;
|
|
|
|
covargs.push_back(fileDir);
|
|
|
|
covargs.push_back(f);
|
|
|
|
const std::string command = joinCommandLine(covargs);
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-06-06 21:53:32 +00:00
|
|
|
command << std::endl, this->Quiet);
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2016-12-10 13:53:06 +00:00
|
|
|
std::string output;
|
|
|
|
std::string errors;
|
2007-04-27 03:20:12 +00:00
|
|
|
int retVal = 0;
|
2014-03-11 12:35:32 +00:00
|
|
|
*cont->OFS << "* Run coverage for: " << fileDir << std::endl;
|
|
|
|
*cont->OFS << " Command: " << command << std::endl;
|
2017-12-12 20:54:01 +00:00
|
|
|
int res = this->CTest->RunCommand(covargs, &output, &errors, &retVal,
|
|
|
|
tempDir.c_str(),
|
|
|
|
cmDuration::zero() /*this->TimeOut*/);
|
2007-04-27 03:20:12 +00:00
|
|
|
|
2014-03-11 12:35:32 +00:00
|
|
|
*cont->OFS << " Output: " << output << std::endl;
|
|
|
|
*cont->OFS << " Errors: " << errors << std::endl;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!res) {
|
2007-04-27 03:20:12 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2017-09-14 13:11:58 +00:00
|
|
|
"Problem running coverage on file: " << f << std::endl);
|
2007-04-27 03:20:12 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Command produced error: " << errors << std::endl);
|
|
|
|
cont->Error++;
|
2007-04-27 03:20:12 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (retVal != 0) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Coverage command returned: "
|
2017-09-14 13:11:58 +00:00
|
|
|
<< retVal << " while processing: " << f << std::endl);
|
2007-04-27 03:20:12 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Command produced error: " << cont->Error << std::endl);
|
|
|
|
}
|
|
|
|
cmCTestOptionalLog(
|
|
|
|
this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2007-04-27 03:20:12 +00:00
|
|
|
"--------------------------------------------------------------"
|
2016-05-16 14:34:04 +00:00
|
|
|
<< std::endl
|
|
|
|
<< output << std::endl
|
|
|
|
<< "--------------------------------------------------------------"
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2014-02-10 05:21:34 +00:00
|
|
|
std::vector<std::string> lines;
|
2019-02-11 23:11:59 +00:00
|
|
|
cmsys::SystemTools::Split(output, lines);
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& line : lines) {
|
2007-04-27 03:20:12 +00:00
|
|
|
std::string sourceFile;
|
|
|
|
std::string gcovFile;
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, DEBUG,
|
2017-09-14 13:11:58 +00:00
|
|
|
"Line: [" << line << "]" << std::endl, this->Quiet);
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2017-09-14 13:11:58 +00:00
|
|
|
if (line.empty()) {
|
2007-04-27 03:20:12 +00:00
|
|
|
// Ignore empty line; probably style 2
|
2018-08-07 15:27:20 +00:00
|
|
|
} else if (st1re1.find(line)) {
|
2016-05-16 14:34:04 +00:00
|
|
|
if (gcovStyle == 0) {
|
2007-04-27 03:20:12 +00:00
|
|
|
gcovStyle = 1;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (gcovStyle != 1) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unknown gcov output style e1" << std::endl);
|
2016-05-16 14:34:04 +00:00
|
|
|
cont->Error++;
|
2009-10-12 18:51:54 +00:00
|
|
|
break;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
|
2017-09-15 23:26:49 +00:00
|
|
|
actualSourceFile.clear();
|
2007-04-27 03:20:12 +00:00
|
|
|
sourceFile = st1re1.match(2);
|
2018-08-07 15:27:20 +00:00
|
|
|
} else if (st1re2.find(line)) {
|
2016-05-16 14:34:04 +00:00
|
|
|
if (gcovStyle == 0) {
|
2007-04-27 03:20:12 +00:00
|
|
|
gcovStyle = 1;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (gcovStyle != 1) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unknown gcov output style e2" << std::endl);
|
2016-05-16 14:34:04 +00:00
|
|
|
cont->Error++;
|
2009-10-12 18:51:54 +00:00
|
|
|
break;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
|
|
|
|
gcovFile = st1re2.match(1);
|
2018-08-07 15:27:20 +00:00
|
|
|
} else if (st2re1.find(line)) {
|
2016-05-16 14:34:04 +00:00
|
|
|
if (gcovStyle == 0) {
|
2007-04-27 03:20:12 +00:00
|
|
|
gcovStyle = 2;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (gcovStyle != 2) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unknown gcov output style e3" << std::endl);
|
2016-05-16 14:34:04 +00:00
|
|
|
cont->Error++;
|
2009-10-12 18:51:54 +00:00
|
|
|
break;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
|
2017-09-15 23:26:49 +00:00
|
|
|
actualSourceFile.clear();
|
2007-04-27 03:20:12 +00:00
|
|
|
sourceFile = st2re1.match(1);
|
2018-08-07 15:27:20 +00:00
|
|
|
} else if (st2re2.find(line)) {
|
2016-05-16 14:34:04 +00:00
|
|
|
if (gcovStyle == 0) {
|
2005-07-06 19:27:02 +00:00
|
|
|
gcovStyle = 2;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (gcovStyle != 2) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unknown gcov output style e4" << std::endl);
|
2016-05-16 14:34:04 +00:00
|
|
|
cont->Error++;
|
2009-10-12 18:51:54 +00:00
|
|
|
break;
|
2005-07-06 19:27:02 +00:00
|
|
|
}
|
2018-08-07 15:27:20 +00:00
|
|
|
} else if (st2re3.find(line)) {
|
2016-05-16 14:34:04 +00:00
|
|
|
if (gcovStyle == 0) {
|
2005-07-06 19:27:02 +00:00
|
|
|
gcovStyle = 2;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (gcovStyle != 2) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unknown gcov output style e5" << std::endl);
|
2016-05-16 14:34:04 +00:00
|
|
|
cont->Error++;
|
2009-10-12 18:51:54 +00:00
|
|
|
break;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-03-09 16:17:10 +00:00
|
|
|
|
2005-07-06 19:27:02 +00:00
|
|
|
gcovFile = st2re3.match(2);
|
2018-08-07 15:27:20 +00:00
|
|
|
} else if (st2re4.find(line)) {
|
2016-05-16 14:34:04 +00:00
|
|
|
if (gcovStyle == 0) {
|
2005-07-06 19:27:02 +00:00
|
|
|
gcovStyle = 2;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (gcovStyle != 2) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unknown gcov output style e6" << std::endl);
|
2016-05-16 14:34:04 +00:00
|
|
|
cont->Error++;
|
2009-10-12 18:51:54 +00:00
|
|
|
break;
|
2004-09-09 12:41:05 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
|
|
|
|
cmCTestOptionalLog(this->CTest, WARNING,
|
|
|
|
"Warning: " << st2re4.match(1)
|
|
|
|
<< " had unexpected EOF" << std::endl,
|
|
|
|
this->Quiet);
|
2018-08-07 15:27:20 +00:00
|
|
|
} else if (st2re5.find(line)) {
|
2016-05-16 14:34:04 +00:00
|
|
|
if (gcovStyle == 0) {
|
2005-07-06 19:27:02 +00:00
|
|
|
gcovStyle = 2;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (gcovStyle != 2) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unknown gcov output style e7" << std::endl);
|
2016-05-16 14:34:04 +00:00
|
|
|
cont->Error++;
|
2009-10-12 18:51:54 +00:00
|
|
|
break;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-03-09 16:17:10 +00:00
|
|
|
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, WARNING,
|
|
|
|
"Warning: Cannot open file: " << st2re5.match(1)
|
|
|
|
<< std::endl,
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Quiet);
|
2018-08-07 15:27:20 +00:00
|
|
|
} else if (st2re6.find(line)) {
|
2016-05-16 14:34:04 +00:00
|
|
|
if (gcovStyle == 0) {
|
2005-07-06 19:27:02 +00:00
|
|
|
gcovStyle = 2;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (gcovStyle != 2) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unknown gcov output style e8" << std::endl);
|
2016-05-16 14:34:04 +00:00
|
|
|
cont->Error++;
|
2009-10-12 18:51:54 +00:00
|
|
|
break;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-03-09 16:17:10 +00:00
|
|
|
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, WARNING,
|
|
|
|
"Warning: File: " << st2re6.match(1)
|
|
|
|
<< " is newer than "
|
|
|
|
<< st2re6.match(2) << std::endl,
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Quiet);
|
|
|
|
} else {
|
2012-12-10 22:03:57 +00:00
|
|
|
// gcov 4.7 can have output lines saying "No executable lines" and
|
|
|
|
// "Removing 'filename.gcov'"... Don't log those as "errors."
|
2017-09-14 13:11:58 +00:00
|
|
|
if (line != "No executable lines" &&
|
2019-08-01 10:57:18 +00:00
|
|
|
!cmHasLiteralPrefix(line, "Removing ")) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unknown gcov output line: [" << line << "]"
|
|
|
|
<< std::endl);
|
2016-05-16 14:34:04 +00:00
|
|
|
cont->Error++;
|
|
|
|
// abort();
|
2005-07-06 19:27:02 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-10-12 18:51:54 +00:00
|
|
|
|
|
|
|
// If the last line of gcov output gave us a valid value for gcovFile,
|
|
|
|
// and we have an actualSourceFile, then insert a (or add to existing)
|
|
|
|
// SingleFileCoverageVector for actualSourceFile:
|
|
|
|
//
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!gcovFile.empty() && !actualSourceFile.empty()) {
|
|
|
|
cmCTestCoverageHandlerContainer::SingleFileCoverageVector& vec =
|
|
|
|
cont->TotalCoverage[actualSourceFile];
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" in gcovFile: " << gcovFile << std::endl,
|
|
|
|
this->Quiet);
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2014-01-04 05:47:13 +00:00
|
|
|
cmsys::ifstream ifile(gcovFile.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!ifile) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Cannot open file: " << gcovFile << std::endl);
|
|
|
|
} else {
|
2005-07-06 19:27:02 +00:00
|
|
|
long cnt = -1;
|
|
|
|
std::string nl;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (cmSystemTools::GetLineFromStream(ifile, nl)) {
|
|
|
|
cnt++;
|
2006-03-09 16:17:10 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
// TODO: Handle gcov 3.0 non-coverage lines
|
2006-03-09 16:17:10 +00:00
|
|
|
|
2005-07-06 19:27:02 +00:00
|
|
|
// Skip empty lines
|
2016-05-16 14:34:04 +00:00
|
|
|
if (nl.empty()) {
|
2005-07-06 19:27:02 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-03-09 16:17:10 +00:00
|
|
|
|
2005-07-06 19:27:02 +00:00
|
|
|
// Skip unused lines
|
2016-05-16 14:34:04 +00:00
|
|
|
if (nl.size() < 12) {
|
2005-07-06 19:27:02 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2005-07-14 15:24:47 +00:00
|
|
|
|
2006-03-09 16:17:10 +00:00
|
|
|
// Read the coverage count from the beginning of the gcov output
|
|
|
|
// line
|
2005-07-06 19:27:02 +00:00
|
|
|
std::string prefix = nl.substr(0, 12);
|
|
|
|
int cov = atoi(prefix.c_str());
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2006-03-09 16:17:10 +00:00
|
|
|
// Read the line number starting at the 10th character of the gcov
|
|
|
|
// output line
|
2005-07-06 19:27:02 +00:00
|
|
|
std::string lineNumber = nl.substr(10, 5);
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
int lineIdx = atoi(lineNumber.c_str()) - 1;
|
|
|
|
if (lineIdx >= 0) {
|
|
|
|
while (vec.size() <= static_cast<size_t>(lineIdx)) {
|
2009-10-12 18:51:54 +00:00
|
|
|
vec.push_back(-1);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2005-07-14 15:24:47 +00:00
|
|
|
// Initially all entries are -1 (not used). If we get coverage
|
|
|
|
// information, increment it to 0 first.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (vec[lineIdx] < 0) {
|
2017-05-30 19:37:46 +00:00
|
|
|
if (cov > 0 || prefix.find('#') != std::string::npos) {
|
2009-10-12 18:51:54 +00:00
|
|
|
vec[lineIdx] = 0;
|
2005-07-14 15:24:47 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-10-12 18:51:54 +00:00
|
|
|
|
|
|
|
vec[lineIdx] += cov;
|
2004-09-09 12:41:05 +00:00
|
|
|
}
|
|
|
|
}
|
2004-10-17 23:45:36 +00:00
|
|
|
}
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2017-09-15 23:26:49 +00:00
|
|
|
actualSourceFile.clear();
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!sourceFile.empty() && actualSourceFile.empty()) {
|
2017-09-15 23:26:49 +00:00
|
|
|
gcovFile.clear();
|
2008-07-31 15:28:45 +00:00
|
|
|
|
2009-10-12 18:51:54 +00:00
|
|
|
// Is it in the source dir or the binary dir?
|
|
|
|
//
|
2016-05-16 14:34:04 +00:00
|
|
|
if (IsFileInDir(sourceFile, cont->SourceDir)) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" produced s: " << sourceFile << std::endl,
|
|
|
|
this->Quiet);
|
2014-03-11 12:35:32 +00:00
|
|
|
*cont->OFS << " produced in source dir: " << sourceFile
|
2016-05-16 14:34:04 +00:00
|
|
|
<< std::endl;
|
|
|
|
actualSourceFile = cmSystemTools::CollapseFullPath(sourceFile);
|
|
|
|
} else if (IsFileInDir(sourceFile, cont->BinaryDir)) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" produced b: " << sourceFile << std::endl,
|
|
|
|
this->Quiet);
|
2014-03-11 12:35:32 +00:00
|
|
|
*cont->OFS << " produced in binary dir: " << sourceFile
|
2016-05-16 14:34:04 +00:00
|
|
|
<< std::endl;
|
|
|
|
actualSourceFile = cmSystemTools::CollapseFullPath(sourceFile);
|
|
|
|
}
|
2008-07-31 15:28:45 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (actualSourceFile.empty()) {
|
|
|
|
if (missingFiles.find(sourceFile) == missingFiles.end()) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Something went wrong" << std::endl,
|
|
|
|
this->Quiet);
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Cannot find file: [" << sourceFile << "]"
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" in source dir: [" << cont->SourceDir << "]"
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" or binary dir: [" << cont->BinaryDir.size()
|
|
|
|
<< "]" << std::endl,
|
|
|
|
this->Quiet);
|
2008-07-31 18:16:34 +00:00
|
|
|
*cont->OFS << " Something went wrong. Cannot find file: "
|
2016-05-16 14:34:04 +00:00
|
|
|
<< sourceFile << " in source dir: " << cont->SourceDir
|
|
|
|
<< " or binary dir: " << cont->BinaryDir << std::endl;
|
2009-10-12 18:51:54 +00:00
|
|
|
|
|
|
|
missingFiles.insert(sourceFile);
|
2007-04-27 03:20:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-10-12 18:51:54 +00:00
|
|
|
|
|
|
|
file_count++;
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (file_count % 50 == 0) {
|
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
|
|
|
" processed: " << file_count << " out of "
|
|
|
|
<< files.size() << std::endl,
|
|
|
|
this->Quiet);
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " ", this->Quiet);
|
2007-04-27 03:20:12 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-10-12 18:51:54 +00:00
|
|
|
|
2007-04-27 03:20:12 +00:00
|
|
|
return file_count;
|
|
|
|
}
|
2004-10-17 23:45:36 +00:00
|
|
|
|
2014-02-27 13:37:52 +00:00
|
|
|
int cmCTestCoverageHandler::HandleLCovCoverage(
|
|
|
|
cmCTestCoverageHandlerContainer* cont)
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string lcovCommand =
|
|
|
|
this->CTest->GetCTestConfiguration("CoverageCommand");
|
|
|
|
std::string lcovExtraFlags =
|
|
|
|
this->CTest->GetCTestConfiguration("CoverageExtraFlags");
|
|
|
|
if (lcovCommand != "codecov") {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" Not a valid Intel Coverage command." << std::endl,
|
|
|
|
this->Quiet);
|
2014-02-27 13:37:52 +00:00
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
// There is only percentage completed output from LCOV
|
|
|
|
std::string st2lcovOutputRex3 = "[0-9]+%";
|
|
|
|
cmsys::RegularExpression st2re3(st2lcovOutputRex3.c_str());
|
|
|
|
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" This is coverage command: " << lcovCommand << std::endl,
|
|
|
|
this->Quiet);
|
2014-02-27 13:37:52 +00:00
|
|
|
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" These are coverage command flags: " << lcovExtraFlags
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
2014-02-27 13:37:52 +00:00
|
|
|
|
|
|
|
std::vector<std::string> files;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->FindLCovFiles(files)) {
|
2015-08-08 04:28:38 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Error while finding LCov files.\n");
|
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (files.empty()) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" Cannot find any LCov coverage files." << std::endl,
|
|
|
|
this->Quiet);
|
2014-02-27 13:37:52 +00:00
|
|
|
// No coverage files is a valid thing, so the exit code is 0
|
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
std::string testingDir = this->CTest->GetBinaryDir();
|
|
|
|
|
|
|
|
std::set<std::string> missingFiles;
|
|
|
|
|
2016-12-10 13:53:06 +00:00
|
|
|
std::string actualSourceFile;
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestOptionalLog(
|
|
|
|
this->CTest, HANDLER_OUTPUT,
|
2015-02-17 20:57:26 +00:00
|
|
|
" Processing coverage (each . represents one file):" << std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " ", this->Quiet);
|
2014-02-27 13:37:52 +00:00
|
|
|
int file_count = 0;
|
|
|
|
|
|
|
|
// make sure output from lcov is in English!
|
|
|
|
cmCTestCoverageHandlerLocale locale_C;
|
|
|
|
static_cast<void>(locale_C);
|
|
|
|
|
2017-09-13 13:32:47 +00:00
|
|
|
std::vector<std::string> covargs =
|
2019-02-20 18:50:00 +00:00
|
|
|
cmSystemTools::ParseArguments(lcovExtraFlags);
|
2017-09-13 13:32:47 +00:00
|
|
|
covargs.insert(covargs.begin(), lcovCommand);
|
|
|
|
const std::string command = joinCommandLine(covargs);
|
|
|
|
|
2014-02-27 13:37:52 +00:00
|
|
|
// In intel compiler we have to call codecov only once in each executable
|
|
|
|
// directory. It collects all *.dyn files to generate .dpi file.
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& f : files) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "." << std::flush,
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Quiet);
|
2017-09-14 13:11:58 +00:00
|
|
|
std::string fileDir = cmSystemTools::GetFilenamePath(f);
|
2017-03-01 18:41:50 +00:00
|
|
|
cmWorkingDirectory workdir(fileDir);
|
2018-03-04 06:27:09 +00:00
|
|
|
if (workdir.Failed()) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unable to change working directory to "
|
|
|
|
<< fileDir << " : "
|
|
|
|
<< std::strerror(workdir.GetLastResult()) << std::endl);
|
|
|
|
cont->Error++;
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Current coverage dir: " << fileDir << std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-06-06 21:53:32 +00:00
|
|
|
command << std::endl, this->Quiet);
|
2014-02-27 13:37:52 +00:00
|
|
|
|
2016-12-10 13:53:06 +00:00
|
|
|
std::string output;
|
|
|
|
std::string errors;
|
2014-02-27 13:37:52 +00:00
|
|
|
int retVal = 0;
|
2014-11-23 10:05:50 +00:00
|
|
|
*cont->OFS << "* Run coverage for: " << fileDir << std::endl;
|
|
|
|
*cont->OFS << " Command: " << command << std::endl;
|
2017-12-12 20:54:01 +00:00
|
|
|
int res = this->CTest->RunCommand(covargs, &output, &errors, &retVal,
|
|
|
|
fileDir.c_str(),
|
|
|
|
cmDuration::zero() /*this->TimeOut*/);
|
2014-02-27 13:37:52 +00:00
|
|
|
|
2014-11-23 10:05:50 +00:00
|
|
|
*cont->OFS << " Output: " << output << std::endl;
|
|
|
|
*cont->OFS << " Errors: " << errors << std::endl;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!res) {
|
2014-02-27 13:37:52 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2017-09-14 13:11:58 +00:00
|
|
|
"Problem running coverage on file: " << f << std::endl);
|
2014-02-27 13:37:52 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Command produced error: " << errors << std::endl);
|
|
|
|
cont->Error++;
|
2014-02-27 13:37:52 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (retVal != 0) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Coverage command returned: "
|
2017-09-14 13:11:58 +00:00
|
|
|
<< retVal << " while processing: " << f << std::endl);
|
2014-02-27 13:37:52 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Command produced error: " << cont->Error << std::endl);
|
|
|
|
}
|
|
|
|
cmCTestOptionalLog(
|
|
|
|
this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2014-02-27 13:37:52 +00:00
|
|
|
"--------------------------------------------------------------"
|
2016-05-16 14:34:04 +00:00
|
|
|
<< std::endl
|
|
|
|
<< output << std::endl
|
|
|
|
<< "--------------------------------------------------------------"
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
2014-02-27 13:37:52 +00:00
|
|
|
|
|
|
|
std::vector<std::string> lines;
|
2019-02-11 23:11:59 +00:00
|
|
|
cmsys::SystemTools::Split(output, lines);
|
2014-02-27 13:37:52 +00:00
|
|
|
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& line : lines) {
|
2014-02-27 13:37:52 +00:00
|
|
|
std::string sourceFile;
|
|
|
|
std::string lcovFile;
|
|
|
|
|
2017-09-14 13:11:58 +00:00
|
|
|
if (line.empty()) {
|
2014-02-27 13:37:52 +00:00
|
|
|
// Ignore empty line
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
// Look for LCOV files in binary directory
|
|
|
|
// Intel Compiler creates a CodeCoverage dir for each subfolder and
|
|
|
|
// each subfolder has LCOV files
|
|
|
|
cmsys::Glob gl;
|
|
|
|
gl.RecurseOn();
|
|
|
|
gl.RecurseThroughSymlinksOff();
|
|
|
|
std::string dir;
|
|
|
|
std::vector<std::string> lcovFiles;
|
|
|
|
dir = this->CTest->GetBinaryDir();
|
|
|
|
std::string daGlob;
|
2019-08-22 14:34:40 +00:00
|
|
|
daGlob = cmStrCat(dir, "/*.LCOV");
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestOptionalLog(
|
|
|
|
this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2015-02-17 20:57:26 +00:00
|
|
|
" looking for LCOV files in: " << daGlob << std::endl, this->Quiet);
|
2014-02-27 13:37:52 +00:00
|
|
|
gl.FindFiles(daGlob);
|
|
|
|
// Keep a list of all LCOV files
|
2019-05-23 12:49:54 +00:00
|
|
|
cmAppend(lcovFiles, gl.GetFiles());
|
2014-02-27 13:37:52 +00:00
|
|
|
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& file : lcovFiles) {
|
|
|
|
lcovFile = file;
|
2014-02-27 13:37:52 +00:00
|
|
|
cmsys::ifstream srcead(lcovFile.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!srcead) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Cannot open file: " << lcovFile << std::endl);
|
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
std::string srcname;
|
|
|
|
|
|
|
|
int success = cmSystemTools::GetLineFromStream(srcead, srcname);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!success) {
|
2014-02-27 13:37:52 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Error while parsing lcov file '"
|
|
|
|
<< lcovFile << "':"
|
|
|
|
<< " No source file name found!" << std::endl);
|
2014-02-27 13:37:52 +00:00
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
srcname = srcname.substr(18);
|
|
|
|
// We can directly read found LCOV files to determine the source
|
|
|
|
// files
|
|
|
|
sourceFile = srcname;
|
|
|
|
actualSourceFile = srcname;
|
|
|
|
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& t : lcovFiles) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2017-09-14 13:11:58 +00:00
|
|
|
"Found LCOV File: " << t << std::endl,
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Quiet);
|
|
|
|
}
|
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
"SourceFile: " << sourceFile << std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
"lCovFile: " << lcovFile << std::endl, this->Quiet);
|
2014-02-27 13:37:52 +00:00
|
|
|
|
|
|
|
// If we have some LCOV files to process
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!lcovFile.empty() && !actualSourceFile.empty()) {
|
|
|
|
cmCTestCoverageHandlerContainer::SingleFileCoverageVector& vec =
|
|
|
|
cont->TotalCoverage[actualSourceFile];
|
2014-02-27 13:37:52 +00:00
|
|
|
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" in lcovFile: " << lcovFile << std::endl,
|
|
|
|
this->Quiet);
|
2014-02-27 13:37:52 +00:00
|
|
|
|
|
|
|
cmsys::ifstream ifile(lcovFile.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!ifile) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Cannot open file: " << lcovFile << std::endl);
|
|
|
|
} else {
|
2014-02-27 13:37:52 +00:00
|
|
|
long cnt = -1;
|
|
|
|
std::string nl;
|
|
|
|
|
|
|
|
// Skip the first line
|
|
|
|
cmSystemTools::GetLineFromStream(ifile, nl);
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"File is ready, start reading." << std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
while (cmSystemTools::GetLineFromStream(ifile, nl)) {
|
|
|
|
cnt++;
|
2014-02-27 13:37:52 +00:00
|
|
|
|
|
|
|
// Skip empty lines
|
2016-05-16 14:34:04 +00:00
|
|
|
if (nl.empty()) {
|
2014-02-27 13:37:52 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
|
|
|
|
// Skip unused lines
|
2016-05-16 14:34:04 +00:00
|
|
|
if (nl.size() < 12) {
|
2014-02-27 13:37:52 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
|
|
|
|
// Read the coverage count from the beginning of the lcov
|
|
|
|
// output line
|
|
|
|
std::string prefix = nl.substr(0, 17);
|
|
|
|
int cov = atoi(prefix.c_str());
|
|
|
|
|
|
|
|
// Read the line number starting at the 17th character of the
|
|
|
|
// lcov output line
|
|
|
|
std::string lineNumber = nl.substr(17, 7);
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
int lineIdx = atoi(lineNumber.c_str()) - 1;
|
|
|
|
if (lineIdx >= 0) {
|
|
|
|
while (vec.size() <= static_cast<size_t>(lineIdx)) {
|
2014-02-27 13:37:52 +00:00
|
|
|
vec.push_back(-1);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
|
|
|
|
// Initially all entries are -1 (not used). If we get coverage
|
|
|
|
// information, increment it to 0 first.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (vec[lineIdx] < 0) {
|
2017-05-30 19:37:46 +00:00
|
|
|
if (cov > 0 || prefix.find('#') != std::string::npos) {
|
2014-02-27 13:37:52 +00:00
|
|
|
vec[lineIdx] = 0;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
|
|
|
|
vec[lineIdx] += cov;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
|
2017-09-15 23:26:49 +00:00
|
|
|
actualSourceFile.clear();
|
2014-02-27 13:37:52 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
|
|
|
|
file_count++;
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (file_count % 50 == 0) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" processed: " << file_count << " out of "
|
|
|
|
<< files.size() << std::endl,
|
|
|
|
this->Quiet);
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " ", this->Quiet);
|
2014-02-27 13:37:52 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
|
|
|
|
return file_count;
|
|
|
|
}
|
|
|
|
|
2009-03-09 16:19:56 +00:00
|
|
|
void cmCTestCoverageHandler::FindGCovFiles(std::vector<std::string>& files)
|
|
|
|
{
|
|
|
|
cmsys::Glob gl;
|
|
|
|
gl.RecurseOn();
|
|
|
|
gl.RecurseThroughSymlinksOff();
|
|
|
|
|
2017-09-14 13:11:58 +00:00
|
|
|
for (auto const& lm : this->TargetDirs) {
|
2009-03-09 16:19:56 +00:00
|
|
|
// Skip targets containing no interesting labels.
|
2017-09-14 13:11:58 +00:00
|
|
|
if (!this->IntersectsFilter(lm.second)) {
|
2009-03-09 16:19:56 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-03-09 16:19:56 +00:00
|
|
|
|
|
|
|
// Coverage files appear next to their object files in the target
|
|
|
|
// support directory.
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestOptionalLog(
|
|
|
|
this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2017-09-14 13:11:58 +00:00
|
|
|
" globbing for coverage in: " << lm.first << std::endl, this->Quiet);
|
2019-08-22 14:34:40 +00:00
|
|
|
std::string daGlob = cmStrCat(lm.first, "/*.da");
|
2009-03-09 16:19:56 +00:00
|
|
|
gl.FindFiles(daGlob);
|
2019-05-23 12:49:54 +00:00
|
|
|
cmAppend(files, gl.GetFiles());
|
2019-08-22 14:34:40 +00:00
|
|
|
daGlob = cmStrCat(lm.first, "/*.gcda");
|
2009-03-09 16:19:56 +00:00
|
|
|
gl.FindFiles(daGlob);
|
2019-05-23 12:49:54 +00:00
|
|
|
cmAppend(files, gl.GetFiles());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-03-09 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-08 04:28:38 +00:00
|
|
|
bool cmCTestCoverageHandler::FindLCovFiles(std::vector<std::string>& files)
|
2014-02-27 13:37:52 +00:00
|
|
|
{
|
|
|
|
cmsys::Glob gl;
|
|
|
|
gl.RecurseOff(); // No need of recurse if -prof_dir${BUILD_DIR} flag is
|
|
|
|
// used while compiling.
|
|
|
|
gl.RecurseThroughSymlinksOff();
|
2015-08-08 04:28:38 +00:00
|
|
|
std::string buildDir = this->CTest->GetCTestConfiguration("BuildDirectory");
|
2017-03-01 18:41:50 +00:00
|
|
|
cmWorkingDirectory workdir(buildDir);
|
2018-03-04 06:27:09 +00:00
|
|
|
if (workdir.Failed()) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unable to change working directory to " << buildDir
|
|
|
|
<< std::endl);
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
|
|
|
|
// Run profmerge to merge all *.dyn files into dpi files
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!cmSystemTools::RunSingleCommand("profmerge")) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Error while running profmerge.\n");
|
2015-08-08 04:28:38 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-27 13:37:52 +00:00
|
|
|
|
|
|
|
// DPI file should appear in build directory
|
|
|
|
std::string daGlob;
|
2019-08-22 14:34:40 +00:00
|
|
|
daGlob = cmStrCat(buildDir, "/*.dpi");
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" looking for dpi files in: " << daGlob << std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
if (!gl.FindFiles(daGlob)) {
|
2015-08-08 04:28:38 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Error while finding files matching " << daGlob << std::endl);
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2019-05-23 12:49:54 +00:00
|
|
|
cmAppend(files, gl.GetFiles());
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Now searching in: " << daGlob << std::endl, this->Quiet);
|
2015-08-08 04:28:38 +00:00
|
|
|
return true;
|
2014-02-27 13:37:52 +00:00
|
|
|
}
|
|
|
|
|
2007-04-27 03:20:12 +00:00
|
|
|
int cmCTestCoverageHandler::HandleTracePyCoverage(
|
|
|
|
cmCTestCoverageHandlerContainer* cont)
|
|
|
|
{
|
|
|
|
cmsys::Glob gl;
|
|
|
|
gl.RecurseOn();
|
2008-08-20 17:24:16 +00:00
|
|
|
gl.RecurseThroughSymlinksOff();
|
2007-04-27 03:20:12 +00:00
|
|
|
std::string daGlob = cont->BinaryDir + "/*.cover";
|
|
|
|
gl.FindFiles(daGlob);
|
|
|
|
std::vector<std::string> files = gl.GetFiles();
|
2004-09-09 12:41:05 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (files.empty()) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" Cannot find any Python Trace.py coverage files."
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
2012-08-13 17:42:58 +00:00
|
|
|
// No coverage files is a valid thing, so the exit code is 0
|
2007-04-27 03:20:12 +00:00
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2004-09-09 12:41:05 +00:00
|
|
|
|
2007-04-27 03:20:12 +00:00
|
|
|
std::string testingDir = this->CTest->GetBinaryDir() + "/Testing";
|
|
|
|
std::string tempDir = testingDir + "/CoverageInfo";
|
2018-01-31 15:20:02 +00:00
|
|
|
cmSystemTools::MakeDirectory(tempDir);
|
2004-10-17 23:45:36 +00:00
|
|
|
|
2007-04-27 03:20:12 +00:00
|
|
|
int file_count = 0;
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& file : files) {
|
|
|
|
std::string fileName = this->FindFile(cont, file);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (fileName.empty()) {
|
2007-04-27 03:20:12 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Cannot find source Python file corresponding to: "
|
2017-09-14 13:11:58 +00:00
|
|
|
<< file << std::endl);
|
2004-10-17 23:45:36 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2004-10-17 23:45:36 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string actualSourceFile = cmSystemTools::CollapseFullPath(fileName);
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" Check coverage for file: " << actualSourceFile
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
cmCTestCoverageHandlerContainer::SingleFileCoverageVector* vec =
|
|
|
|
&cont->TotalCoverage[actualSourceFile];
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2017-09-14 13:11:58 +00:00
|
|
|
" in file: " << file << std::endl, this->Quiet);
|
|
|
|
cmsys::ifstream ifile(file.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!ifile) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2017-09-14 13:11:58 +00:00
|
|
|
"Cannot open file: " << file << std::endl);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2007-04-27 03:20:12 +00:00
|
|
|
long cnt = -1;
|
|
|
|
std::string nl;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (cmSystemTools::GetLineFromStream(ifile, nl)) {
|
|
|
|
cnt++;
|
2004-09-09 12:41:05 +00:00
|
|
|
|
2007-04-27 03:20:12 +00:00
|
|
|
// Skip empty lines
|
2016-05-16 14:34:04 +00:00
|
|
|
if (nl.empty()) {
|
2007-04-27 03:20:12 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2005-06-14 15:42:53 +00:00
|
|
|
|
2007-04-27 03:20:12 +00:00
|
|
|
// Skip unused lines
|
2016-05-16 14:34:04 +00:00
|
|
|
if (nl.size() < 12) {
|
2007-04-27 03:20:12 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2004-09-09 12:41:05 +00:00
|
|
|
|
2007-04-27 03:20:12 +00:00
|
|
|
// Read the coverage count from the beginning of the Trace.py output
|
|
|
|
// line
|
|
|
|
std::string prefix = nl.substr(0, 6);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (prefix[5] != ' ' && prefix[5] != ':') {
|
2007-04-27 03:20:12 +00:00
|
|
|
// This is a hack. We should really do something more elaborate
|
|
|
|
prefix = nl.substr(0, 7);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (prefix[6] != ' ' && prefix[6] != ':') {
|
2007-04-27 03:20:12 +00:00
|
|
|
prefix = nl.substr(0, 8);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (prefix[7] != ' ' && prefix[7] != ':') {
|
2007-04-27 03:20:12 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Currently the limit is maximum coverage of 999999"
|
|
|
|
<< std::endl);
|
2007-04-27 03:20:12 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
int cov = atoi(prefix.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
if (prefix[prefix.size() - 1] != ':') {
|
2007-04-27 03:20:12 +00:00
|
|
|
// This line does not have ':' so no coverage here. That said,
|
|
|
|
// Trace.py does not handle not covered lines versus comments etc.
|
|
|
|
// So, this will be set to 0.
|
|
|
|
cov = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
cmCTestOptionalLog(
|
|
|
|
this->CTest, DEBUG,
|
|
|
|
"Prefix: " << prefix << " cov: " << cov << std::endl, this->Quiet);
|
2007-04-27 03:20:12 +00:00
|
|
|
// Read the line number starting at the 10th character of the gcov
|
|
|
|
// output line
|
2009-01-29 14:26:40 +00:00
|
|
|
long lineIdx = cnt;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (lineIdx >= 0) {
|
|
|
|
while (vec->size() <= static_cast<size_t>(lineIdx)) {
|
2007-04-27 03:20:12 +00:00
|
|
|
vec->push_back(-1);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
// Initially all entries are -1 (not used). If we get coverage
|
|
|
|
// information, increment it to 0 first.
|
2016-05-16 14:34:04 +00:00
|
|
|
if ((*vec)[lineIdx] < 0) {
|
|
|
|
if (cov >= 0) {
|
2007-04-27 03:20:12 +00:00
|
|
|
(*vec)[lineIdx] = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
(*vec)[lineIdx] += cov;
|
2007-04-27 03:20:12 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-27 20:54:47 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
++file_count;
|
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
return file_count;
|
2004-09-09 12:41:05 +00:00
|
|
|
}
|
2005-07-14 17:25:40 +00:00
|
|
|
|
2007-04-27 03:20:12 +00:00
|
|
|
std::string cmCTestCoverageHandler::FindFile(
|
2016-05-26 19:58:51 +00:00
|
|
|
cmCTestCoverageHandlerContainer* cont, std::string const& fileName)
|
2005-07-14 17:25:40 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string fileNameNoE =
|
|
|
|
cmSystemTools::GetFilenameWithoutLastExtension(fileName);
|
2007-04-27 03:20:12 +00:00
|
|
|
// First check in source and binary directory
|
|
|
|
std::string fullName = cont->SourceDir + "/" + fileNameNoE + ".py";
|
2018-01-31 15:20:02 +00:00
|
|
|
if (cmSystemTools::FileExists(fullName)) {
|
2007-04-27 03:20:12 +00:00
|
|
|
return fullName;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
fullName = cont->BinaryDir + "/" + fileNameNoE + ".py";
|
2018-01-31 15:20:02 +00:00
|
|
|
if (cmSystemTools::FileExists(fullName)) {
|
2007-04-27 03:20:12 +00:00
|
|
|
return fullName;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-04-27 03:20:12 +00:00
|
|
|
return "";
|
2005-07-14 17:25:40 +00:00
|
|
|
}
|
2007-06-01 19:40:07 +00:00
|
|
|
|
|
|
|
// This is a header put on each marked up source file
|
2016-05-16 14:34:04 +00:00
|
|
|
namespace {
|
|
|
|
const char* bullseyeHelp[] = {
|
|
|
|
" Coverage produced by bullseye covbr tool: ",
|
|
|
|
" www.bullseye.com/help/ref_covbr.html",
|
|
|
|
" * An arrow --> indicates incomplete coverage.",
|
|
|
|
" * An X indicates a function that was invoked, a switch label that ",
|
|
|
|
" was exercised, a try-block that finished, or an exception handler ",
|
|
|
|
" that was invoked.",
|
|
|
|
" * A T or F indicates a boolean decision that evaluated true or false,",
|
|
|
|
" respectively.",
|
|
|
|
" * A t or f indicates a boolean condition within a decision if the ",
|
|
|
|
" condition evaluated true or false, respectively.",
|
|
|
|
" * A k indicates a constant decision or condition.",
|
|
|
|
" * The slash / means this probe is excluded from summary results. ",
|
2017-08-22 21:42:36 +00:00
|
|
|
nullptr
|
2016-05-16 14:34:04 +00:00
|
|
|
};
|
2007-06-01 19:40:07 +00:00
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2007-06-01 19:40:07 +00:00
|
|
|
int cmCTestCoverageHandler::RunBullseyeCoverageBranch(
|
|
|
|
cmCTestCoverageHandlerContainer* cont,
|
2016-05-16 14:34:04 +00:00
|
|
|
std::set<std::string>& coveredFileNames, std::vector<std::string>& files,
|
2007-06-01 19:40:07 +00:00
|
|
|
std::vector<std::string>& filesFullPath)
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (files.size() != filesFullPath.size()) {
|
2012-08-13 17:42:58 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2007-06-01 19:40:07 +00:00
|
|
|
"Files and full path files not the same size?:\n");
|
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-01 19:40:07 +00:00
|
|
|
// create the output stream for the CoverageLog-N.xml file
|
|
|
|
cmGeneratedFileStream covLogFile;
|
2015-05-24 19:18:40 +00:00
|
|
|
cmXMLWriter covLogXML(covLogFile);
|
2007-06-01 19:40:07 +00:00
|
|
|
int logFileCount = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->StartCoverageLogFile(covLogFile, logFileCount)) {
|
2007-06-01 19:40:07 +00:00
|
|
|
return -1;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-05-24 19:18:40 +00:00
|
|
|
this->StartCoverageLogXML(covLogXML);
|
2007-06-08 16:29:40 +00:00
|
|
|
// for each file run covbr on that file to get the coverage
|
|
|
|
// information for that file
|
|
|
|
std::string outputFile;
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"run covbr: " << std::endl, this->Quiet);
|
2007-06-08 16:29:40 +00:00
|
|
|
|
2017-08-22 21:42:36 +00:00
|
|
|
if (!this->RunBullseyeCommand(cont, "covbr", nullptr, outputFile)) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"error running covbr for."
|
2016-05-16 14:34:04 +00:00
|
|
|
<< "\n");
|
2007-06-08 16:29:40 +00:00
|
|
|
return -1;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"covbr output in " << outputFile << std::endl,
|
|
|
|
this->Quiet);
|
2007-06-08 16:29:40 +00:00
|
|
|
// open the output file
|
2014-01-04 05:47:13 +00:00
|
|
|
cmsys::ifstream fin(outputFile.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!fin) {
|
2007-06-08 16:29:40 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Cannot open coverage file: " << outputFile << std::endl);
|
2007-06-08 16:29:40 +00:00
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-10 05:21:34 +00:00
|
|
|
std::map<std::string, std::string> fileMap;
|
2007-06-01 19:40:07 +00:00
|
|
|
std::vector<std::string>::iterator fp = filesFullPath.begin();
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::vector<std::string>::iterator f = files.begin(); f != files.end();
|
|
|
|
++f, ++fp) {
|
2007-06-08 16:29:40 +00:00
|
|
|
fileMap[*f] = *fp;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-08 16:29:40 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
int count = 0; // keep count of the number of files
|
2007-06-08 16:29:40 +00:00
|
|
|
// Now parse each line from the bullseye cov log file
|
|
|
|
std::string lineIn;
|
|
|
|
bool valid = false; // are we in a valid output file
|
2016-05-16 14:34:04 +00:00
|
|
|
int line = 0; // line of the current file
|
2014-02-10 05:21:34 +00:00
|
|
|
std::string file;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (cmSystemTools::GetLineFromStream(fin, lineIn)) {
|
2007-06-08 16:29:40 +00:00
|
|
|
bool startFile = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (lineIn.size() > 1 && lineIn[lineIn.size() - 1] == ':') {
|
|
|
|
file = lineIn.substr(0, lineIn.size() - 1);
|
|
|
|
if (coveredFileNames.find(file) != coveredFileNames.end()) {
|
2007-06-08 16:29:40 +00:00
|
|
|
startFile = true;
|
2007-06-01 19:40:07 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (startFile) {
|
2007-06-08 16:29:40 +00:00
|
|
|
// if we are in a valid file close it because a new one started
|
2016-05-16 14:34:04 +00:00
|
|
|
if (valid) {
|
2015-05-24 19:18:40 +00:00
|
|
|
covLogXML.EndElement(); // Report
|
|
|
|
covLogXML.EndElement(); // File
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-08 16:29:40 +00:00
|
|
|
// only allow 100 files in each log file
|
2016-05-16 14:34:04 +00:00
|
|
|
if (count != 0 && count % 100 == 0) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"start a new log file: " << count << std::endl,
|
|
|
|
this->Quiet);
|
2015-05-24 19:18:40 +00:00
|
|
|
this->EndCoverageLogXML(covLogXML);
|
2007-06-08 16:29:40 +00:00
|
|
|
this->EndCoverageLogFile(covLogFile, logFileCount);
|
2016-05-16 14:34:04 +00:00
|
|
|
logFileCount++;
|
|
|
|
if (!this->StartCoverageLogFile(covLogFile, logFileCount)) {
|
2007-06-08 16:29:40 +00:00
|
|
|
return -1;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-05-24 19:18:40 +00:00
|
|
|
this->StartCoverageLogXML(covLogXML);
|
2012-08-13 17:42:58 +00:00
|
|
|
count++; // move on one
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
std::map<std::string, std::string>::iterator i = fileMap.find(file);
|
2007-06-08 16:29:40 +00:00
|
|
|
// if the file should be covered write out the header for that file
|
2016-05-16 14:34:04 +00:00
|
|
|
if (i != fileMap.end()) {
|
2007-06-08 16:29:40 +00:00
|
|
|
// we have a new file so count it in the output
|
|
|
|
count++;
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Produce coverage for file: " << file << " "
|
|
|
|
<< count << std::endl,
|
|
|
|
this->Quiet);
|
2007-06-08 16:29:40 +00:00
|
|
|
// start the file output
|
2015-05-24 19:18:40 +00:00
|
|
|
covLogXML.StartElement("File");
|
|
|
|
covLogXML.Attribute("Name", i->first);
|
2016-05-16 14:34:04 +00:00
|
|
|
covLogXML.Attribute(
|
|
|
|
"FullPath", this->CTest->GetShortPathToFile(i->second.c_str()));
|
2015-05-24 19:18:40 +00:00
|
|
|
covLogXML.StartElement("Report");
|
2007-06-08 16:29:40 +00:00
|
|
|
// write the bullseye header
|
2016-05-16 14:34:04 +00:00
|
|
|
line = 0;
|
2017-08-22 21:42:36 +00:00
|
|
|
for (int k = 0; bullseyeHelp[k] != nullptr; ++k) {
|
2015-05-24 19:18:40 +00:00
|
|
|
covLogXML.StartElement("Line");
|
|
|
|
covLogXML.Attribute("Number", line);
|
|
|
|
covLogXML.Attribute("Count", -1);
|
|
|
|
covLogXML.Content(bullseyeHelp[k]);
|
|
|
|
covLogXML.EndElement(); // Line
|
2007-06-08 16:29:40 +00:00
|
|
|
line++;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
valid = true; // we are in a valid file section
|
|
|
|
} else {
|
2007-06-08 16:29:40 +00:00
|
|
|
// this is not a file that we want coverage for
|
|
|
|
valid = false;
|
2007-06-01 19:40:07 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-08 16:29:40 +00:00
|
|
|
// we are not at a start file, and we are in a valid file output the line
|
2016-05-16 14:34:04 +00:00
|
|
|
else if (valid) {
|
2015-05-24 19:18:40 +00:00
|
|
|
covLogXML.StartElement("Line");
|
|
|
|
covLogXML.Attribute("Number", line);
|
|
|
|
covLogXML.Attribute("Count", -1);
|
|
|
|
covLogXML.Content(lineIn);
|
|
|
|
covLogXML.EndElement(); // Line
|
2007-06-01 19:40:07 +00:00
|
|
|
line++;
|
2007-06-08 16:29:40 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-08 16:29:40 +00:00
|
|
|
// if we ran out of lines a valid file then close that file
|
2016-05-16 14:34:04 +00:00
|
|
|
if (valid) {
|
2015-05-24 19:18:40 +00:00
|
|
|
covLogXML.EndElement(); // Report
|
|
|
|
covLogXML.EndElement(); // File
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-05-24 19:18:40 +00:00
|
|
|
this->EndCoverageLogXML(covLogXML);
|
2007-06-01 19:40:07 +00:00
|
|
|
this->EndCoverageLogFile(covLogFile, logFileCount);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmCTestCoverageHandler::RunBullseyeCommand(
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestCoverageHandlerContainer* cont, const char* cmd, const char* arg,
|
2007-06-01 19:40:07 +00:00
|
|
|
std::string& outputFile)
|
|
|
|
{
|
|
|
|
std::string program = cmSystemTools::FindProgram(cmd);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (program.empty()) {
|
2007-06-01 19:40:07 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot find :" << cmd << "\n");
|
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (arg) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Run : " << program << " " << arg << "\n", this->Quiet);
|
|
|
|
} else {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Run : " << program << "\n", this->Quiet);
|
|
|
|
}
|
2007-06-01 19:40:07 +00:00
|
|
|
// create a process object and start it
|
|
|
|
cmCTestRunProcess runCoverageSrc;
|
|
|
|
runCoverageSrc.SetCommand(program.c_str());
|
|
|
|
runCoverageSrc.AddArgument(arg);
|
2019-08-22 14:34:40 +00:00
|
|
|
std::string stdoutFile =
|
|
|
|
cmStrCat(cont->BinaryDir, "/Testing/Temporary/",
|
|
|
|
this->GetCTestInstance()->GetCurrentTag(), '-', cmd);
|
2007-06-01 19:40:07 +00:00
|
|
|
std::string stderrFile = stdoutFile;
|
2007-06-08 16:29:40 +00:00
|
|
|
stdoutFile += ".stdout";
|
2007-06-01 19:40:07 +00:00
|
|
|
stderrFile += ".stderr";
|
|
|
|
runCoverageSrc.SetStdoutFile(stdoutFile.c_str());
|
|
|
|
runCoverageSrc.SetStderrFile(stderrFile.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!runCoverageSrc.StartProcess()) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Could not run : " << program << " " << arg << "\n"
|
|
|
|
<< "kwsys process state : "
|
|
|
|
<< runCoverageSrc.GetProcessState());
|
2007-06-01 19:40:07 +00:00
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-01 19:40:07 +00:00
|
|
|
// since we set the output file names wait for it to end
|
|
|
|
runCoverageSrc.WaitForExit();
|
|
|
|
outputFile = stdoutFile;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmCTestCoverageHandler::RunBullseyeSourceSummary(
|
|
|
|
cmCTestCoverageHandlerContainer* cont)
|
|
|
|
{
|
|
|
|
// Run the covsrc command and create a temp outputfile
|
|
|
|
std::string outputFile;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->RunBullseyeCommand(cont, "covsrc", "-c", outputFile)) {
|
2007-06-01 19:40:07 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "error running covsrc:\n");
|
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2007-06-01 19:40:07 +00:00
|
|
|
std::ostream& tmpLog = *cont->OFS;
|
|
|
|
// copen the Coverage.xml file in the Testing directory
|
2012-08-13 17:42:58 +00:00
|
|
|
cmGeneratedFileStream covSumFile;
|
2015-05-24 19:18:40 +00:00
|
|
|
cmXMLWriter xml(covSumFile);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->StartResultingXML(cmCTest::PartCoverage, "Coverage",
|
|
|
|
covSumFile)) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Cannot open coverage summary file." << std::endl);
|
2007-06-01 19:40:07 +00:00
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-05-24 19:18:40 +00:00
|
|
|
this->CTest->StartXML(xml, this->AppendXML);
|
2017-11-03 13:25:33 +00:00
|
|
|
auto elapsed_time_start = std::chrono::steady_clock::now();
|
2007-06-01 19:40:07 +00:00
|
|
|
std::string coverage_start_time = this->CTest->CurrentTime();
|
2015-05-24 19:18:40 +00:00
|
|
|
xml.StartElement("Coverage");
|
|
|
|
xml.Element("StartDateTime", coverage_start_time);
|
2017-11-15 18:00:09 +00:00
|
|
|
xml.Element("StartTime", std::chrono::system_clock::now());
|
2007-06-01 19:40:07 +00:00
|
|
|
std::string stdline;
|
|
|
|
std::string errline;
|
|
|
|
// expected output:
|
|
|
|
// first line is:
|
|
|
|
// "Source","Function Coverage","out of","%","C/D Coverage","out of","%"
|
|
|
|
// after that data follows in that format
|
|
|
|
std::string sourceFile;
|
|
|
|
int functionsCalled = 0;
|
|
|
|
int totalFunctions = 0;
|
|
|
|
int percentFunction = 0;
|
|
|
|
int branchCovered = 0;
|
|
|
|
int totalBranches = 0;
|
|
|
|
int percentBranch = 0;
|
|
|
|
double total_tested = 0;
|
|
|
|
double total_untested = 0;
|
|
|
|
double total_functions = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
double percent_coverage = 0;
|
|
|
|
double number_files = 0;
|
2007-06-01 19:40:07 +00:00
|
|
|
std::vector<std::string> coveredFiles;
|
|
|
|
std::vector<std::string> coveredFilesFullPath;
|
|
|
|
// Read and parse the summary output file
|
2014-01-04 05:47:13 +00:00
|
|
|
cmsys::ifstream fin(outputFile.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!fin) {
|
2007-06-01 19:40:07 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Cannot open coverage summary file: " << outputFile
|
|
|
|
<< std::endl);
|
2007-06-01 19:40:07 +00:00
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-10 05:21:34 +00:00
|
|
|
std::set<std::string> coveredFileNames;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (cmSystemTools::GetLineFromStream(fin, stdline)) {
|
2007-06-01 19:40:07 +00:00
|
|
|
// if we have a line of output from stdout
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!stdline.empty()) {
|
2007-06-01 19:40:07 +00:00
|
|
|
// parse the comma separated output
|
2016-05-16 14:34:04 +00:00
|
|
|
this->ParseBullsEyeCovsrcLine(
|
|
|
|
stdline, sourceFile, functionsCalled, totalFunctions, percentFunction,
|
|
|
|
branchCovered, totalBranches, percentBranch);
|
2007-06-01 19:40:07 +00:00
|
|
|
// The first line is the header
|
2016-05-16 14:34:04 +00:00
|
|
|
if (sourceFile == "Source" || sourceFile == "Total") {
|
2007-06-01 19:40:07 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-01 19:40:07 +00:00
|
|
|
std::string file = sourceFile;
|
2007-06-08 16:29:40 +00:00
|
|
|
coveredFileNames.insert(file);
|
2018-01-31 15:20:02 +00:00
|
|
|
if (!cmSystemTools::FileIsFullPath(sourceFile)) {
|
2007-06-01 19:40:07 +00:00
|
|
|
// file will be relative to the binary dir
|
2019-08-22 14:34:40 +00:00
|
|
|
file = cmStrCat(cont->BinaryDir, '/', sourceFile);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-10-15 12:54:05 +00:00
|
|
|
file = cmSystemTools::CollapseFullPath(file);
|
2017-09-19 10:22:50 +00:00
|
|
|
bool shouldIDoCoverage =
|
|
|
|
this->ShouldIDoCoverage(file, cont->SourceDir, cont->BinaryDir);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!shouldIDoCoverage) {
|
|
|
|
cmCTestOptionalLog(
|
|
|
|
this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
".NoDartCoverage found, so skip coverage check for: " << file
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
2007-06-01 19:40:07 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-11 19:36:50 +00:00
|
|
|
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Doing coverage for: " << file << std::endl,
|
|
|
|
this->Quiet);
|
2007-06-01 19:40:07 +00:00
|
|
|
|
|
|
|
coveredFiles.push_back(sourceFile);
|
2007-06-11 19:36:50 +00:00
|
|
|
coveredFilesFullPath.push_back(file);
|
|
|
|
|
2007-06-01 19:40:07 +00:00
|
|
|
number_files++;
|
|
|
|
total_functions += totalFunctions;
|
|
|
|
total_tested += functionsCalled;
|
|
|
|
total_untested += (totalFunctions - functionsCalled);
|
2007-06-11 19:36:50 +00:00
|
|
|
|
2014-03-10 23:04:11 +00:00
|
|
|
std::string fileName = cmSystemTools::GetFilenameName(file);
|
2009-03-02 20:33:03 +00:00
|
|
|
std::string shortFileName =
|
|
|
|
this->CTest->GetShortPathToFile(file.c_str());
|
2007-06-11 19:36:50 +00:00
|
|
|
|
2009-10-01 20:47:08 +00:00
|
|
|
float cper = static_cast<float>(percentBranch + percentFunction);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (totalBranches > 0) {
|
2007-11-05 19:34:36 +00:00
|
|
|
cper /= 2.0f;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-11-11 21:24:51 +00:00
|
|
|
percent_coverage += static_cast<double>(cper);
|
2009-10-01 20:47:08 +00:00
|
|
|
float cmet = static_cast<float>(percentFunction + percentBranch);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (totalBranches > 0) {
|
2007-11-05 19:34:36 +00:00
|
|
|
cmet /= 2.0f;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-11-05 19:34:36 +00:00
|
|
|
cmet /= 100.0f;
|
2014-03-11 12:35:32 +00:00
|
|
|
tmpLog << stdline << "\n";
|
2007-06-01 19:40:07 +00:00
|
|
|
tmpLog << fileName << "\n";
|
2016-05-16 14:34:04 +00:00
|
|
|
tmpLog << "functionsCalled: " << functionsCalled / 100 << "\n";
|
|
|
|
tmpLog << "totalFunctions: " << totalFunctions / 100 << "\n";
|
2007-06-01 19:40:07 +00:00
|
|
|
tmpLog << "percentFunction: " << percentFunction << "\n";
|
|
|
|
tmpLog << "branchCovered: " << branchCovered << "\n";
|
|
|
|
tmpLog << "totalBranches: " << totalBranches << "\n";
|
|
|
|
tmpLog << "percentBranch: " << percentBranch << "\n";
|
|
|
|
tmpLog << "percentCoverage: " << percent_coverage << "\n";
|
|
|
|
tmpLog << "coverage metric: " << cmet << "\n";
|
2015-05-24 19:18:40 +00:00
|
|
|
xml.StartElement("File");
|
|
|
|
xml.Attribute("Name", sourceFile);
|
|
|
|
xml.Attribute("FullPath", shortFileName);
|
|
|
|
xml.Attribute("Covered", cmet > 0 ? "true" : "false");
|
|
|
|
xml.Element("BranchesTested", branchCovered);
|
|
|
|
xml.Element("BranchesUnTested", totalBranches - branchCovered);
|
|
|
|
xml.Element("FunctionsTested", functionsCalled);
|
|
|
|
xml.Element("FunctionsUnTested", totalFunctions - functionsCalled);
|
|
|
|
// Hack for conversion of function to loc assume a function
|
|
|
|
// has 100 lines of code
|
|
|
|
xml.Element("LOCTested", functionsCalled * 100);
|
|
|
|
xml.Element("LOCUnTested", (totalFunctions - functionsCalled) * 100);
|
|
|
|
xml.Element("PercentCoverage", cper);
|
|
|
|
xml.Element("CoverageMetric", cmet);
|
|
|
|
this->WriteXMLLabels(xml, shortFileName);
|
|
|
|
xml.EndElement(); // File
|
2007-06-01 19:40:07 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-01 19:40:07 +00:00
|
|
|
std::string end_time = this->CTest->CurrentTime();
|
2015-05-24 19:18:40 +00:00
|
|
|
xml.Element("LOCTested", total_tested);
|
|
|
|
xml.Element("LOCUntested", total_untested);
|
|
|
|
xml.Element("LOC", total_functions);
|
|
|
|
xml.Element("PercentCoverage", SAFEDIV(percent_coverage, number_files));
|
|
|
|
xml.Element("EndDateTime", end_time);
|
2017-11-15 18:00:09 +00:00
|
|
|
xml.Element("EndTime", std::chrono::system_clock::now());
|
2017-11-03 13:25:33 +00:00
|
|
|
xml.Element("ElapsedMinutes",
|
|
|
|
std::chrono::duration_cast<std::chrono::minutes>(
|
|
|
|
std::chrono::steady_clock::now() - elapsed_time_start)
|
|
|
|
.count());
|
2015-05-24 19:18:40 +00:00
|
|
|
xml.EndElement(); // Coverage
|
|
|
|
this->CTest->EndXML(xml);
|
2010-04-23 13:16:18 +00:00
|
|
|
|
2007-06-01 19:40:07 +00:00
|
|
|
// Now create the coverage information for each file
|
2016-05-16 14:34:04 +00:00
|
|
|
return this->RunBullseyeCoverageBranch(cont, coveredFileNames, coveredFiles,
|
2007-06-01 19:40:07 +00:00
|
|
|
coveredFilesFullPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmCTestCoverageHandler::HandleBullseyeCoverage(
|
|
|
|
cmCTestCoverageHandlerContainer* cont)
|
|
|
|
{
|
2016-07-07 21:54:05 +00:00
|
|
|
std::string covfile;
|
|
|
|
if (!cmSystemTools::GetEnv("COVFILE", covfile) || covfile.empty()) {
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" COVFILE environment variable not found, not running "
|
|
|
|
" bullseye\n",
|
|
|
|
this->Quiet);
|
2007-06-01 19:40:07 +00:00
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
cmCTestOptionalLog(
|
|
|
|
this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
" run covsrc with COVFILE=[" << covfile << "]" << std::endl, this->Quiet);
|
|
|
|
if (!this->RunBullseyeSourceSummary(cont)) {
|
2012-08-13 17:42:58 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2007-06-01 19:40:07 +00:00
|
|
|
"Error running bullseye summary.\n");
|
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
cmCTestOptionalLog(this->CTest, DEBUG,
|
|
|
|
"HandleBullseyeCoverage return 1 " << std::endl,
|
|
|
|
this->Quiet);
|
2007-06-01 19:40:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCTestCoverageHandler::GetNextInt(std::string const& inputLine,
|
|
|
|
std::string::size_type& pos,
|
|
|
|
int& value)
|
2012-08-13 17:42:58 +00:00
|
|
|
{
|
2007-06-01 19:40:07 +00:00
|
|
|
std::string::size_type start = pos;
|
|
|
|
pos = inputLine.find(',', start);
|
|
|
|
value = atoi(inputLine.substr(start, pos).c_str());
|
2017-05-30 19:37:46 +00:00
|
|
|
if (pos == std::string::npos) {
|
2007-06-01 19:40:07 +00:00
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-01 19:40:07 +00:00
|
|
|
pos++;
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2007-06-01 19:40:07 +00:00
|
|
|
bool cmCTestCoverageHandler::ParseBullsEyeCovsrcLine(
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string const& inputLine, std::string& sourceFile, int& functionsCalled,
|
|
|
|
int& totalFunctions, int& percentFunction, int& branchCovered,
|
|
|
|
int& totalBranches, int& percentBranch)
|
2007-06-01 19:40:07 +00:00
|
|
|
{
|
|
|
|
// find the first comma
|
|
|
|
std::string::size_type pos = inputLine.find(',');
|
2017-05-30 19:37:46 +00:00
|
|
|
if (pos == std::string::npos) {
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Error parsing string : " << inputLine << "\n");
|
2007-06-01 19:40:07 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-01 19:40:07 +00:00
|
|
|
// the source file has "" around it so extract out the file name
|
2016-05-16 14:34:04 +00:00
|
|
|
sourceFile = inputLine.substr(1, pos - 2);
|
2007-06-01 19:40:07 +00:00
|
|
|
pos++;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->GetNextInt(inputLine, pos, functionsCalled)) {
|
2007-06-01 19:40:07 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (!this->GetNextInt(inputLine, pos, totalFunctions)) {
|
2007-06-01 19:40:07 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (!this->GetNextInt(inputLine, pos, percentFunction)) {
|
2007-06-01 19:40:07 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (!this->GetNextInt(inputLine, pos, branchCovered)) {
|
2007-06-01 19:40:07 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (!this->GetNextInt(inputLine, pos, totalBranches)) {
|
2007-06-01 19:40:07 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (!this->GetNextInt(inputLine, pos, percentBranch)) {
|
2007-06-01 19:40:07 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-01 19:40:07 +00:00
|
|
|
// should be at the end now
|
2017-05-30 19:37:46 +00:00
|
|
|
if (pos != std::string::npos) {
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Error parsing input : "
|
2016-05-16 14:34:04 +00:00
|
|
|
<< inputLine << " last pos not npos = " << pos << "\n");
|
|
|
|
}
|
2007-06-01 19:40:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-02-13 20:17:06 +00:00
|
|
|
|
|
|
|
int cmCTestCoverageHandler::GetLabelId(std::string const& label)
|
|
|
|
{
|
|
|
|
LabelIdMapType::iterator i = this->LabelIdMap.find(label);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (i == this->LabelIdMap.end()) {
|
2009-02-13 20:17:06 +00:00
|
|
|
int n = int(this->Labels.size());
|
|
|
|
this->Labels.push_back(label);
|
|
|
|
LabelIdMapType::value_type entry(label, n);
|
|
|
|
i = this->LabelIdMap.insert(entry).first;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-02-13 20:17:06 +00:00
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestCoverageHandler::LoadLabels()
|
|
|
|
{
|
2019-08-22 14:34:40 +00:00
|
|
|
std::string fileList =
|
|
|
|
cmStrCat(this->CTest->GetBinaryDir(), "/CMakeFiles/TargetDirectories.txt");
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" target directory list [" << fileList << "]\n",
|
|
|
|
this->Quiet);
|
2014-01-04 05:47:13 +00:00
|
|
|
cmsys::ifstream finList(fileList.c_str());
|
2009-02-13 20:17:06 +00:00
|
|
|
std::string line;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (cmSystemTools::GetLineFromStream(finList, line)) {
|
2009-02-13 20:17:06 +00:00
|
|
|
this->LoadLabels(line.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-02-13 20:17:06 +00:00
|
|
|
}
|
|
|
|
|
2009-03-09 16:19:27 +00:00
|
|
|
void cmCTestCoverageHandler::LoadLabels(const char* dir)
|
2009-02-13 20:17:06 +00:00
|
|
|
{
|
2009-03-09 16:19:56 +00:00
|
|
|
LabelSet& dirLabels = this->TargetDirs[dir];
|
2019-08-22 14:34:40 +00:00
|
|
|
std::string fname = cmStrCat(dir, "/Labels.txt");
|
2014-01-04 05:47:13 +00:00
|
|
|
cmsys::ifstream fin(fname.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!fin) {
|
2009-03-09 16:19:27 +00:00
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-03-09 16:19:27 +00:00
|
|
|
|
2015-02-17 20:57:26 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" loading labels from [" << fname << "]\n", this->Quiet);
|
2009-02-13 20:17:06 +00:00
|
|
|
bool inTarget = true;
|
|
|
|
std::string source;
|
|
|
|
std::string line;
|
|
|
|
std::vector<int> targetLabels;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (cmSystemTools::GetLineFromStream(fin, line)) {
|
|
|
|
if (line.empty() || line[0] == '#') {
|
2009-02-13 20:17:06 +00:00
|
|
|
// Ignore blank and comment lines.
|
|
|
|
continue;
|
2017-04-21 08:06:12 +00:00
|
|
|
}
|
|
|
|
if (line[0] == ' ') {
|
2009-02-13 20:17:06 +00:00
|
|
|
// Label lines appear indented by one space.
|
|
|
|
std::string label = line.substr(1);
|
|
|
|
int id = this->GetLabelId(label);
|
2009-03-09 16:19:56 +00:00
|
|
|
dirLabels.insert(id);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (inTarget) {
|
2009-02-13 20:17:06 +00:00
|
|
|
targetLabels.push_back(id);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2009-02-13 20:17:06 +00:00
|
|
|
this->SourceLabels[source].insert(id);
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2009-02-13 20:17:06 +00:00
|
|
|
// Non-indented lines specify a source file name. The first one
|
|
|
|
// is the end of the target-wide labels.
|
|
|
|
inTarget = false;
|
|
|
|
|
|
|
|
source = this->CTest->GetShortPathToFile(line.c_str());
|
|
|
|
|
|
|
|
// Label the source with the target labels.
|
|
|
|
LabelSet& labelSet = this->SourceLabels[source];
|
2014-11-25 15:33:00 +00:00
|
|
|
labelSet.insert(targetLabels.begin(), targetLabels.end());
|
2009-02-13 20:17:06 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-02-13 20:17:06 +00:00
|
|
|
}
|
|
|
|
|
2015-05-24 19:18:40 +00:00
|
|
|
void cmCTestCoverageHandler::WriteXMLLabels(cmXMLWriter& xml,
|
2009-02-13 20:17:06 +00:00
|
|
|
std::string const& source)
|
|
|
|
{
|
|
|
|
LabelMapType::const_iterator li = this->SourceLabels.find(source);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (li != this->SourceLabels.end() && !li->second.empty()) {
|
2015-05-24 19:18:40 +00:00
|
|
|
xml.StartElement("Labels");
|
2017-09-14 13:11:58 +00:00
|
|
|
for (auto const& ls : li->second) {
|
|
|
|
xml.Element("Label", this->Labels[ls]);
|
2009-02-13 20:17:06 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
xml.EndElement(); // Labels
|
|
|
|
}
|
2009-02-13 20:17:06 +00:00
|
|
|
}
|
2009-03-02 20:33:18 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void cmCTestCoverageHandler::SetLabelFilter(
|
|
|
|
std::set<std::string> const& labels)
|
2009-03-02 20:33:18 +00:00
|
|
|
{
|
|
|
|
this->LabelFilter.clear();
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& l : labels) {
|
|
|
|
this->LabelFilter.insert(this->GetLabelId(l));
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-03-02 20:33:18 +00:00
|
|
|
}
|
|
|
|
|
2009-03-09 16:19:56 +00:00
|
|
|
bool cmCTestCoverageHandler::IntersectsFilter(LabelSet const& labels)
|
|
|
|
{
|
|
|
|
// If there is no label filter then nothing is filtered out.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->LabelFilter.empty()) {
|
2009-03-09 16:19:56 +00:00
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-03-09 16:19:56 +00:00
|
|
|
|
|
|
|
std::vector<int> ids;
|
2016-05-16 14:34:04 +00:00
|
|
|
std::set_intersection(labels.begin(), labels.end(),
|
|
|
|
this->LabelFilter.begin(), this->LabelFilter.end(),
|
|
|
|
std::back_inserter(ids));
|
2009-03-09 16:19:56 +00:00
|
|
|
return !ids.empty();
|
|
|
|
}
|
|
|
|
|
2009-03-02 20:33:18 +00:00
|
|
|
bool cmCTestCoverageHandler::IsFilteredOut(std::string const& source)
|
|
|
|
{
|
|
|
|
// If there is no label filter then nothing is filtered out.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->LabelFilter.empty()) {
|
2009-03-02 20:33:18 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-03-02 20:33:18 +00:00
|
|
|
|
|
|
|
// The source is filtered out if it does not have any labels in
|
|
|
|
// common with the filter set.
|
|
|
|
std::string shortSrc = this->CTest->GetShortPathToFile(source.c_str());
|
|
|
|
LabelMapType::const_iterator li = this->SourceLabels.find(shortSrc);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (li != this->SourceLabels.end()) {
|
2009-03-09 16:19:56 +00:00
|
|
|
return !this->IntersectsFilter(li->second);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-03-09 16:19:56 +00:00
|
|
|
return true;
|
2009-03-02 20:33:18 +00:00
|
|
|
}
|
2010-04-23 13:16:18 +00:00
|
|
|
|
|
|
|
std::set<std::string> cmCTestCoverageHandler::FindUncoveredFiles(
|
|
|
|
cmCTestCoverageHandlerContainer* cont)
|
|
|
|
{
|
|
|
|
std::set<std::string> extraMatches;
|
|
|
|
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& ecg : this->ExtraCoverageGlobs) {
|
2010-04-23 13:16:18 +00:00
|
|
|
cmsys::Glob gl;
|
|
|
|
gl.RecurseOn();
|
|
|
|
gl.RecurseThroughSymlinksOff();
|
2017-09-14 13:11:58 +00:00
|
|
|
std::string glob = cont->SourceDir + "/" + ecg;
|
2010-04-23 13:16:18 +00:00
|
|
|
gl.FindFiles(glob);
|
|
|
|
std::vector<std::string> files = gl.GetFiles();
|
2017-09-14 13:11:58 +00:00
|
|
|
for (std::string const& f : files) {
|
2017-09-19 10:22:50 +00:00
|
|
|
if (this->ShouldIDoCoverage(f, cont->SourceDir, cont->BinaryDir)) {
|
2017-09-14 13:11:58 +00:00
|
|
|
extraMatches.insert(this->CTest->GetShortPathToFile(f.c_str()));
|
2010-05-07 15:00:21 +00:00
|
|
|
}
|
2010-04-23 13:16:18 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-04-23 13:16:18 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!extraMatches.empty()) {
|
2017-09-14 13:11:58 +00:00
|
|
|
for (auto const& i : cont->TotalCoverage) {
|
|
|
|
std::string shortPath = this->CTest->GetShortPathToFile(i.first.c_str());
|
2010-05-07 15:00:21 +00:00
|
|
|
extraMatches.erase(shortPath);
|
2010-04-23 13:16:18 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-04-23 13:16:18 +00:00
|
|
|
return extraMatches;
|
|
|
|
}
|