cmake/Source/CTest/cmParseMumpsCoverage.cxx

145 lines
4.3 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
#include "cmParseMumpsCoverage.h"
2016-07-09 11:21:54 +02:00
2016-10-30 18:24:19 +01:00
#include <map>
#include <string>
#include <utility>
2019-11-11 23:01:05 +01:00
#include <vector>
2012-06-27 20:52:58 +03:00
2020-02-01 23:06:01 +01:00
#include "cmsys/FStream.hxx"
#include "cmsys/Glob.hxx"
#include "cmCTest.h"
#include "cmCTestCoverageHandler.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
2012-06-27 20:52:58 +03:00
cmParseMumpsCoverage::cmParseMumpsCoverage(
2016-07-09 11:21:54 +02:00
cmCTestCoverageHandlerContainer& cont, cmCTest* ctest)
: Coverage(cont)
, CTest(ctest)
2012-06-27 20:52:58 +03:00
{
}
2019-11-11 23:01:05 +01:00
cmParseMumpsCoverage::~cmParseMumpsCoverage() = default;
2012-06-27 20:52:58 +03: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-08-03 19:52:23 +02:00
cmsys::ifstream in(file);
2016-07-09 11:21:54 +02:00
if (!in) {
2012-06-27 20:52:58 +03:00
return false;
2016-07-09 11:21:54 +02:00
}
2012-06-27 20:52:58 +03:00
std::string line;
2016-07-09 11:21:54 +02:00
while (cmSystemTools::GetLineFromStream(in, line)) {
2012-06-27 20:52:58 +03:00
std::string::size_type pos = line.find(':', 0);
std::string packages;
2016-07-09 11:21:54 +02:00
if (pos != std::string::npos) {
2012-06-27 20:52:58 +03:00
std::string type = line.substr(0, pos);
2016-07-09 11:21:54 +02:00
std::string path = line.substr(pos + 1);
if (type == "packages") {
2020-08-30 11:54:41 +02:00
this->LoadPackages(path);
2016-07-09 11:21:54 +02:00
} else if (type == "coverage_dir") {
2020-08-30 11:54:41 +02:00
this->LoadCoverageData(path);
2016-07-09 11:21:54 +02:00
} else {
2012-06-27 20:52:58 +03:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Parse Error in Mumps coverage file :\n"
2016-07-09 11:21:54 +02:00
<< file << "\ntype: [" << type << "]\npath:[" << path
<< "]\n"
"input line: ["
<< line << "]\n");
2012-06-27 20:52:58 +03:00
}
}
2016-07-09 11:21:54 +02:00
}
2012-06-27 20:52:58 +03:00
return true;
}
void cmParseMumpsCoverage::InitializeMumpsFile(std::string& file)
{
// initialize the coverage information for a given mumps file
2014-08-03 19:52:23 +02:00
cmsys::ifstream in(file.c_str());
2016-07-09 11:21:54 +02:00
if (!in) {
2012-06-27 20:52:58 +03:00
return;
2016-07-09 11:21:54 +02:00
}
2012-06-27 20:52:58 +03:00
std::string line;
2016-07-09 11:21:54 +02:00
cmCTestCoverageHandlerContainer::SingleFileCoverageVector& coverageVector =
this->Coverage.TotalCoverage[file];
if (!cmSystemTools::GetLineFromStream(in, line)) {
2012-06-27 20:52:58 +03:00
return;
2016-07-09 11:21:54 +02:00
}
2012-06-27 20:52:58 +03:00
// first line of a .m file can never be run
coverageVector.push_back(-1);
2016-07-09 11:21:54 +02:00
while (cmSystemTools::GetLineFromStream(in, line)) {
2012-06-27 20:52:58 +03: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-07-09 11:21:54 +02: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-06-27 20:52:58 +03:00
found = true;
break;
}
2016-07-09 11:21:54 +02:00
}
if (found) {
2015-04-27 22:25:09 +02: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-07-09 11:21:54 +02:00
if (line[i] == ' ' || line[i] == '\t') {
while (i < line.size() &&
(line[i] == ' ' || line[i] == '\t' || line[i] == '.')) {
2012-06-27 20:52:58 +03:00
i++;
}
2016-07-09 11:21:54 +02:00
}
2012-06-27 20:52:58 +03:00
// (3) If the character found is not a semicolon then the line counts for
// coverage.
2016-07-09 11:21:54 +02:00
if (i < line.size() && line[i] != ';') {
2012-06-27 20:52:58 +03:00
val = 0;
}
}
2016-07-09 11:21:54 +02:00
coverageVector.push_back(val);
}
2012-06-27 20:52:58 +03:00
}
2020-08-30 11:54:41 +02:00
bool cmParseMumpsCoverage::LoadPackages(std::string const& d)
2012-06-27 20:52:58 +03:00
{
cmsys::Glob glob;
glob.RecurseOn();
2020-02-01 23:06:01 +01:00
std::string pat = cmStrCat(d, "/*.m");
2015-04-27 22:25:09 +02:00
glob.FindFiles(pat);
2018-01-26 17:06:56 +01:00
for (std::string& file : glob.GetFiles()) {
std::string name = cmSystemTools::GetFilenameName(file);
2020-08-30 11:54:41 +02:00
name.erase(name.size() - 2);
this->RoutineToDirectory[name] = file;
2018-04-23 21:13:27 +02:00
// initialize each file, this is left out until CDash is fixed
2012-06-27 20:52:58 +03:00
// to handle large numbers of files
2018-01-26 17:06:56 +01:00
this->InitializeMumpsFile(file);
2016-07-09 11:21:54 +02:00
}
2012-06-27 20:52:58 +03:00
return true;
}
bool cmParseMumpsCoverage::FindMumpsFile(std::string const& routine,
std::string& filepath)
{
2020-02-01 23:06:01 +01:00
auto i = this->RoutineToDirectory.find(routine);
2016-07-09 11:21:54 +02:00
if (i != this->RoutineToDirectory.end()) {
2012-06-27 20:52:58 +03:00
filepath = i->second;
return true;
2016-10-30 18:24:19 +01:00
}
// try some alternate names
2018-01-26 17:06:56 +01:00
const char* tryname[] = { "GUX", "GTM", "ONT", nullptr };
for (int k = 0; tryname[k] != nullptr; k++) {
2016-10-30 18:24:19 +01:00
std::string routine2 = routine + tryname[k];
i = this->RoutineToDirectory.find(routine2);
if (i != this->RoutineToDirectory.end()) {
filepath = i->second;
return true;
2012-06-27 20:52:58 +03:00
}
2016-07-09 11:21:54 +02:00
}
2012-06-27 20:52:58 +03:00
return false;
}