cmParseMumpsCoverage.cxx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #include "cmStandardIncludes.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "cmSystemTools.h"
  5. #include "cmParseGTMCoverage.h"
  6. #include <cmsys/Directory.hxx>
  7. #include <cmsys/Glob.hxx>
  8. cmParseMumpsCoverage::cmParseMumpsCoverage(
  9. cmCTestCoverageHandlerContainer& cont,
  10. cmCTest* ctest)
  11. :Coverage(cont), CTest(ctest)
  12. {
  13. }
  14. cmParseMumpsCoverage::~cmParseMumpsCoverage()
  15. {
  16. }
  17. bool cmParseMumpsCoverage::ReadCoverageFile(const char* file)
  18. {
  19. // Read the gtm_coverage.mcov file, that has two lines of data:
  20. // packages:/full/path/to/Vista/Packages
  21. // coverage_dir:/full/path/to/dir/with/*.mcov
  22. std::ifstream in(file);
  23. if(!in)
  24. {
  25. return false;
  26. }
  27. std::string line;
  28. while(cmSystemTools::GetLineFromStream(in, line))
  29. {
  30. std::string::size_type pos = line.find(':', 0);
  31. std::string packages;
  32. if(pos != std::string::npos)
  33. {
  34. std::string type = line.substr(0, pos);
  35. std::string path = line.substr(pos+1);
  36. if(type == "packages")
  37. {
  38. this->LoadPackages(path.c_str());
  39. }
  40. else if(type == "coverage_dir")
  41. {
  42. this->LoadCoverageData(path.c_str());
  43. }
  44. else
  45. {
  46. cmCTestLog(this->CTest, ERROR_MESSAGE,
  47. "Parse Error in Mumps coverage file :\n"
  48. << file <<
  49. "\ntype: [" << type << "]\npath:[" << path << "]\n"
  50. "input line: [" << line << "]\n");
  51. }
  52. }
  53. }
  54. return true;
  55. }
  56. void cmParseMumpsCoverage::InitializeMumpsFile(std::string& file)
  57. {
  58. // initialize the coverage information for a given mumps file
  59. std::ifstream in(file.c_str());
  60. if(!in)
  61. {
  62. return;
  63. }
  64. std::string line;
  65. cmCTestCoverageHandlerContainer::SingleFileCoverageVector&
  66. coverageVector = this->Coverage.TotalCoverage[file];
  67. if(!cmSystemTools::GetLineFromStream(in, line))
  68. {
  69. return;
  70. }
  71. // first line of a .m file can never be run
  72. coverageVector.push_back(-1);
  73. while( cmSystemTools::GetLineFromStream(in, line) )
  74. {
  75. // putting in a 0 for a line means it is executable code
  76. // putting in a -1 for a line means it is not executable code
  77. int val = -1; // assume line is not executable
  78. bool found = false;
  79. std::string::size_type i = 0;
  80. // (1) Search for the first whitespace or semicolon character on a line.
  81. //This will skip over labels if the line starts with one, or will simply
  82. //be the first character on the line for non-label lines.
  83. for(; i < line.size(); ++i)
  84. {
  85. if(line[i] == ' ' || line[i] == '\t' || line[i] == ';')
  86. {
  87. found = true;
  88. break;
  89. }
  90. }
  91. if(found)
  92. {
  93. // (2) If the first character found above is whitespace then continue the
  94. // search for the first following non-whitespace character.
  95. if(line[i] == ' ' || line[i] == '\t')
  96. {
  97. while(i < line.size() && (line[i] == ' ' || line[i] == '\t'))
  98. {
  99. i++;
  100. }
  101. }
  102. // (3) If the character found is not a semicolon then the line counts for
  103. // coverage.
  104. if(i < line.size() && line[i] != ';')
  105. {
  106. val = 0;
  107. }
  108. }
  109. coverageVector.push_back(val);
  110. }
  111. }
  112. bool cmParseMumpsCoverage::LoadPackages(const char* d)
  113. {
  114. cmsys::Glob glob;
  115. glob.RecurseOn();
  116. std::string pat = d;
  117. pat += "/*.m";
  118. glob.FindFiles(pat.c_str());
  119. std::vector<std::string>& files = glob.GetFiles();
  120. std::vector<std::string>::iterator fileIt;
  121. for ( fileIt = files.begin(); fileIt != files.end();
  122. ++ fileIt )
  123. {
  124. std::string name = cmSystemTools::GetFilenameName(*fileIt);
  125. this->RoutineToDirectory[name.substr(0, name.size()-2)] = *fileIt;
  126. // initialze each file, this is left out until CDash is fixed
  127. // to handle large numbers of files
  128. this->InitializeMumpsFile(*fileIt);
  129. }
  130. return true;
  131. }
  132. bool cmParseMumpsCoverage::FindMumpsFile(std::string const& routine,
  133. std::string& filepath)
  134. {
  135. std::map<cmStdString, cmStdString>::iterator i =
  136. this->RoutineToDirectory.find(routine);
  137. if(i != this->RoutineToDirectory.end())
  138. {
  139. filepath = i->second;
  140. return true;
  141. }
  142. else
  143. {
  144. // try some alternate names
  145. const char* tryname[] = {"GUX", "GTM", "ONT", 0};
  146. for(int k=0; tryname[k] != 0; k++)
  147. {
  148. std::string routine2 = routine + tryname[k];
  149. i = this->RoutineToDirectory.find(routine2);
  150. if(i != this->RoutineToDirectory.end())
  151. {
  152. filepath = i->second;
  153. return true;
  154. }
  155. }
  156. }
  157. return false;
  158. }