2016-04-29 16:40:20 +03:00
|
|
|
#include "cmParseCacheCoverage.h"
|
|
|
|
|
2016-08-24 23:01:40 +03:00
|
|
|
#include "cmCTest.h"
|
|
|
|
#include "cmCTestCoverageHandler.h"
|
2012-05-02 01:00:43 +04:00
|
|
|
#include "cmSystemTools.h"
|
2016-08-24 23:01:40 +03:00
|
|
|
|
2012-05-02 01:00:43 +04:00
|
|
|
#include <cmsys/Directory.hxx>
|
2014-01-04 09:47:13 +04:00
|
|
|
#include <cmsys/FStream.hxx>
|
2016-08-24 23:01:40 +03:00
|
|
|
#include <map>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-08-24 23:01:40 +03:00
|
|
|
#include <utility>
|
2012-05-02 01:00:43 +04:00
|
|
|
|
2012-05-02 01:32:23 +04:00
|
|
|
cmParseCacheCoverage::cmParseCacheCoverage(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCTestCoverageHandlerContainer& cont, cmCTest* ctest)
|
|
|
|
: cmParseMumpsCoverage(cont, ctest)
|
2012-05-02 01:00:43 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmParseCacheCoverage::LoadCoverageData(const char* d)
|
|
|
|
{
|
|
|
|
// load all the .mcov files in the specified directory
|
|
|
|
cmsys::Directory dir;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!dir.Load(d)) {
|
2012-05-02 01:00:43 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-02 01:00:43 +04:00
|
|
|
size_t numf;
|
|
|
|
unsigned int i;
|
|
|
|
numf = dir.GetNumberOfFiles();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (i = 0; i < numf; i++) {
|
2012-05-02 01:00:43 +04:00
|
|
|
std::string file = dir.GetFile(i);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (file != "." && file != ".." && !cmSystemTools::FileIsDirectory(file)) {
|
2012-05-02 01:00:43 +04:00
|
|
|
std::string path = d;
|
|
|
|
path += "/";
|
|
|
|
path += file;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::GetFilenameLastExtension(path) == ".cmcov") {
|
|
|
|
if (!this->ReadCMCovFile(path.c_str())) {
|
2012-05-02 01:00:43 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-02 01:00:43 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-11 23:22:25 +04:00
|
|
|
// not currently used, but leave it in case we want it in the future
|
2012-05-03 01:23:01 +04:00
|
|
|
void cmParseCacheCoverage::RemoveUnCoveredFiles()
|
|
|
|
{
|
|
|
|
// loop over the coverage data computed and remove all files
|
|
|
|
// that only have -1 or 0 for the lines.
|
|
|
|
cmCTestCoverageHandlerContainer::TotalCoverageMap::iterator ci =
|
|
|
|
this->Coverage.TotalCoverage.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
while (ci != this->Coverage.TotalCoverage.end()) {
|
|
|
|
cmCTestCoverageHandlerContainer::SingleFileCoverageVector& v = ci->second;
|
2012-05-03 01:23:01 +04:00
|
|
|
bool nothing = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cmCTestCoverageHandlerContainer::SingleFileCoverageVector::iterator
|
|
|
|
i = v.begin();
|
|
|
|
i != v.end(); ++i) {
|
|
|
|
if (*i > 0) {
|
2012-05-03 01:23:01 +04:00
|
|
|
nothing = false;
|
|
|
|
break;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (nothing) {
|
2015-02-17 23:57:26 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 17:34:04 +03:00
|
|
|
"No coverage found in: " << ci->first << std::endl,
|
|
|
|
this->Coverage.Quiet);
|
2012-05-03 01:23:01 +04:00
|
|
|
this->Coverage.TotalCoverage.erase(ci++);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2012-05-03 01:23:01 +04:00
|
|
|
++ci;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-03 01:23:01 +04:00
|
|
|
}
|
|
|
|
|
2012-05-02 01:00:43 +04:00
|
|
|
bool cmParseCacheCoverage::SplitString(std::vector<std::string>& args,
|
|
|
|
std::string const& line)
|
|
|
|
{
|
|
|
|
std::string::size_type pos1 = 0;
|
|
|
|
std::string::size_type pos2 = line.find(',', 0);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (pos2 == std::string::npos) {
|
2012-05-02 01:00:43 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-02 01:00:43 +04:00
|
|
|
std::string arg;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (pos2 != std::string::npos) {
|
|
|
|
arg = line.substr(pos1, pos2 - pos1);
|
2012-05-02 01:00:43 +04:00
|
|
|
args.push_back(arg);
|
2016-05-16 17:34:04 +03:00
|
|
|
pos1 = pos2 + 1;
|
|
|
|
pos2 = line.find(',', pos1);
|
|
|
|
}
|
2012-05-02 01:00:43 +04:00
|
|
|
arg = line.substr(pos1);
|
|
|
|
args.push_back(arg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmParseCacheCoverage::ReadCMCovFile(const char* file)
|
|
|
|
{
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream in(file);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!in) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Can not open : " << file << "\n");
|
2012-05-02 01:00:43 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-02 01:00:43 +04:00
|
|
|
std::string line;
|
|
|
|
std::vector<std::string> separateLine;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::GetLineFromStream(in, line)) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Empty file : "
|
|
|
|
<< file << " referenced in this line of cmcov data:\n"
|
|
|
|
"["
|
|
|
|
<< line << "]\n");
|
2012-05-02 01:00:43 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-02 01:00:43 +04:00
|
|
|
separateLine.clear();
|
|
|
|
this->SplitString(separateLine, line);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (separateLine.size() != 4 || separateLine[0] != "Routine" ||
|
|
|
|
separateLine[1] != "Line" || separateLine[2] != "RtnLine" ||
|
|
|
|
separateLine[3] != "Code") {
|
2012-05-02 01:00:43 +04:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Bad first line of cmcov file : " << file << " line:\n"
|
|
|
|
"["
|
|
|
|
<< line << "]\n");
|
|
|
|
}
|
2012-05-02 01:00:43 +04:00
|
|
|
std::string routine;
|
|
|
|
std::string filepath;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(in, line)) {
|
2012-05-02 01:00:43 +04:00
|
|
|
// clear out line argument vector
|
|
|
|
separateLine.clear();
|
|
|
|
// parse the comma separated line
|
|
|
|
this->SplitString(separateLine, line);
|
|
|
|
// might have more because code could have a quoted , in it
|
|
|
|
// but we only care about the first 3 args anyway
|
2016-05-16 17:34:04 +03:00
|
|
|
if (separateLine.size() < 4) {
|
2012-05-02 01:00:43 +04:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Bad line of cmcov file expected at least 4 found: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< separateLine.size() << " " << file << " line:\n"
|
|
|
|
"["
|
|
|
|
<< line << "]\n");
|
|
|
|
for (std::string::size_type i = 0; i < separateLine.size(); ++i) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "" << separateLine[1] << " ");
|
|
|
|
}
|
2012-05-02 01:00:43 +04:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "\n");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-02 01:00:43 +04:00
|
|
|
// if we do not have a routine yet, then it should be
|
|
|
|
// the first argument in the vector
|
2016-05-16 17:34:04 +03:00
|
|
|
if (routine.empty()) {
|
2012-05-02 01:00:43 +04:00
|
|
|
routine = separateLine[0];
|
|
|
|
// Find the full path to the file
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->FindMumpsFile(routine, filepath)) {
|
2012-05-02 01:00:43 +04:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Could not find mumps file for routine: " << routine
|
|
|
|
<< "\n");
|
2012-05-02 01:00:43 +04:00
|
|
|
filepath = "";
|
|
|
|
continue; // move to next line
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-02 01:00:43 +04:00
|
|
|
// if we have a routine name, check for end of routine
|
2016-05-16 17:34:04 +03:00
|
|
|
else {
|
2012-05-02 01:00:43 +04:00
|
|
|
// Totals in arg 0 marks the end of a routine
|
2016-05-16 17:34:04 +03:00
|
|
|
if (separateLine[0].substr(0, 6) == "Totals") {
|
2012-05-02 01:00:43 +04:00
|
|
|
routine = ""; // at the end of this routine
|
|
|
|
filepath = "";
|
|
|
|
continue; // move to next line
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-02 01:00:43 +04:00
|
|
|
// if the file path was not found for the routine
|
|
|
|
// move to next line. We should have already warned
|
|
|
|
// after the call to FindMumpsFile that we did not find
|
|
|
|
// it, so don't report again to cut down on output
|
2016-05-16 17:34:04 +03:00
|
|
|
if (filepath.empty()) {
|
2012-05-02 01:00:43 +04:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-02 01:00:43 +04:00
|
|
|
// now we are ready to set the coverage from the line of data
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCTestCoverageHandlerContainer::SingleFileCoverageVector& coverageVector =
|
|
|
|
this->Coverage.TotalCoverage[filepath];
|
|
|
|
std::string::size_type linenumber = atoi(separateLine[1].c_str()) - 1;
|
2012-05-02 01:00:43 +04:00
|
|
|
int count = atoi(separateLine[2].c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (linenumber > coverageVector.size()) {
|
2012-05-02 01:00:43 +04:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Parse error line is greater than number of lines in file: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< linenumber << " " << filepath << "\n");
|
2012-05-02 01:00:43 +04:00
|
|
|
continue; // skip setting count to avoid crash
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-02 01:00:43 +04:00
|
|
|
// now add to count for linenumber
|
2012-05-02 01:32:23 +04:00
|
|
|
// for some reason the cache coverage adds extra lines to the
|
|
|
|
// end of the file in some cases. Since they do not exist, we will
|
|
|
|
// mark them as non executable
|
2016-05-16 17:34:04 +03:00
|
|
|
while (linenumber >= coverageVector.size()) {
|
2012-05-02 01:32:23 +04:00
|
|
|
coverageVector.push_back(-1);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-05-14 17:28:07 +04:00
|
|
|
// Accounts for lines that were previously marked
|
|
|
|
// as non-executable code (-1). if the parser comes back with
|
|
|
|
// a non-zero count, increase the count by 1 to push the line
|
|
|
|
// into the executable code set in addition to the count found.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (coverageVector[linenumber] == -1 && count > 0) {
|
|
|
|
coverageVector[linenumber] += count + 1;
|
|
|
|
} else {
|
|
|
|
coverageVector[linenumber] += count;
|
2012-05-02 01:00:43 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-02 01:00:43 +04:00
|
|
|
return true;
|
|
|
|
}
|