2016-04-29 16:40:20 +03:00
|
|
|
#include "cmParseGTMCoverage.h"
|
|
|
|
|
2012-05-01 21:35:07 +04:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include <cmsys/Directory.hxx>
|
2014-01-04 09:47:13 +04:00
|
|
|
#include <cmsys/FStream.hxx>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmsys/Glob.hxx>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2012-05-01 21:35:07 +04:00
|
|
|
|
|
|
|
cmParseMumpsCoverage::cmParseMumpsCoverage(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCTestCoverageHandlerContainer& cont, cmCTest* ctest)
|
|
|
|
: Coverage(cont)
|
|
|
|
, CTest(ctest)
|
2012-05-01 21:35:07 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-01 22:36:18 +04:00
|
|
|
cmParseMumpsCoverage::~cmParseMumpsCoverage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-01 21:35:07 +04:00
|
|
|
bool cmParseMumpsCoverage::ReadCoverageFile(const char* file)
|
|
|
|
{
|
|
|
|
// Read the gtm_coverage.mcov file, that has two lines of data:
|
|
|
|
// packages:/full/path/to/Vista/Packages
|
|
|
|
// coverage_dir:/full/path/to/dir/with/*.mcov
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream in(file);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!in) {
|
2012-05-01 21:35:07 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-01 21:35:07 +04:00
|
|
|
std::string line;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(in, line)) {
|
2012-05-03 00:47:24 +04:00
|
|
|
std::string::size_type pos = line.find(':', 0);
|
|
|
|
std::string packages;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (pos != std::string::npos) {
|
2012-05-03 00:47:24 +04:00
|
|
|
std::string type = line.substr(0, pos);
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string path = line.substr(pos + 1);
|
|
|
|
if (type == "packages") {
|
2012-05-03 00:47:24 +04:00
|
|
|
this->LoadPackages(path.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (type == "coverage_dir") {
|
2012-05-03 00:47:24 +04:00
|
|
|
this->LoadCoverageData(path.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2012-05-03 00:47:24 +04:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Parse Error in Mumps coverage file :\n"
|
2016-05-16 17:34:04 +03:00
|
|
|
<< file << "\ntype: [" << type << "]\npath:[" << path
|
|
|
|
<< "]\n"
|
|
|
|
"input line: ["
|
|
|
|
<< line << "]\n");
|
2012-05-03 00:47:24 +04:00
|
|
|
}
|
2012-05-01 21:35:07 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-01 21:35:07 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmParseMumpsCoverage::InitializeMumpsFile(std::string& file)
|
|
|
|
{
|
|
|
|
// initialize the coverage information for a given mumps file
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream in(file.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!in) {
|
2012-05-01 21:35:07 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-01 21:35:07 +04:00
|
|
|
std::string line;
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCTestCoverageHandlerContainer::SingleFileCoverageVector& coverageVector =
|
|
|
|
this->Coverage.TotalCoverage[file];
|
|
|
|
if (!cmSystemTools::GetLineFromStream(in, line)) {
|
2012-05-01 21:35:07 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-01 21:35:07 +04:00
|
|
|
// first line of a .m file can never be run
|
|
|
|
coverageVector.push_back(-1);
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(in, line)) {
|
2012-05-01 21:35:07 +04:00
|
|
|
// putting in a 0 for a line means it is executable code
|
|
|
|
// putting in a -1 for a line means it is not executable code
|
|
|
|
int val = -1; // assume line is not executable
|
|
|
|
bool found = false;
|
|
|
|
std::string::size_type i = 0;
|
|
|
|
// (1) Search for the first whitespace or semicolon character on a line.
|
2016-05-16 17:34:04 +03:00
|
|
|
// This will skip over labels if the line starts with one, or will simply
|
|
|
|
// be the first character on the line for non-label lines.
|
|
|
|
for (; i < line.size(); ++i) {
|
|
|
|
if (line[i] == ' ' || line[i] == '\t' || line[i] == ';') {
|
2012-05-01 21:35:07 +04:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (found) {
|
2014-08-15 18:50:36 +04:00
|
|
|
// (2) If the first character found above is whitespace or a period
|
|
|
|
// then continue the search for the first following non-whitespace
|
|
|
|
// character.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (line[i] == ' ' || line[i] == '\t') {
|
|
|
|
while (i < line.size() &&
|
|
|
|
(line[i] == ' ' || line[i] == '\t' || line[i] == '.')) {
|
2012-05-01 21:35:07 +04:00
|
|
|
i++;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-01 21:35:07 +04:00
|
|
|
// (3) If the character found is not a semicolon then the line counts for
|
|
|
|
// coverage.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (i < line.size() && line[i] != ';') {
|
2012-05-01 21:35:07 +04:00
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
coverageVector.push_back(val);
|
|
|
|
}
|
2012-05-01 21:35:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmParseMumpsCoverage::LoadPackages(const char* d)
|
|
|
|
{
|
|
|
|
cmsys::Glob glob;
|
|
|
|
glob.RecurseOn();
|
|
|
|
std::string pat = d;
|
|
|
|
pat += "/*.m";
|
2014-03-11 03:04:11 +04:00
|
|
|
glob.FindFiles(pat);
|
2012-05-01 21:35:07 +04:00
|
|
|
std::vector<std::string>& files = glob.GetFiles();
|
|
|
|
std::vector<std::string>::iterator fileIt;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (fileIt = files.begin(); fileIt != files.end(); ++fileIt) {
|
2012-05-01 21:35:07 +04:00
|
|
|
std::string name = cmSystemTools::GetFilenameName(*fileIt);
|
2016-05-16 17:34:04 +03:00
|
|
|
this->RoutineToDirectory[name.substr(0, name.size() - 2)] = *fileIt;
|
2012-05-01 21:35:07 +04:00
|
|
|
// initialze each file, this is left out until CDash is fixed
|
|
|
|
// to handle large numbers of files
|
2012-05-11 23:22:25 +04:00
|
|
|
this->InitializeMumpsFile(*fileIt);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-01 21:35:07 +04:00
|
|
|
return true;
|
|
|
|
}
|
2012-05-02 01:00:43 +04:00
|
|
|
|
|
|
|
bool cmParseMumpsCoverage::FindMumpsFile(std::string const& routine,
|
|
|
|
std::string& filepath)
|
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, std::string>::iterator i =
|
2012-05-02 01:00:43 +04:00
|
|
|
this->RoutineToDirectory.find(routine);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (i != this->RoutineToDirectory.end()) {
|
2012-05-02 01:00:43 +04:00
|
|
|
filepath = i->second;
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2012-05-02 01:00:43 +04:00
|
|
|
// try some alternate names
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* tryname[] = { "GUX", "GTM", "ONT", 0 };
|
|
|
|
for (int k = 0; tryname[k] != 0; k++) {
|
2012-05-02 01:00:43 +04:00
|
|
|
std::string routine2 = routine + tryname[k];
|
|
|
|
i = this->RoutineToDirectory.find(routine2);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (i != this->RoutineToDirectory.end()) {
|
2012-05-02 01:00:43 +04:00
|
|
|
filepath = i->second;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-02 01:00:43 +04:00
|
|
|
return false;
|
|
|
|
}
|