[Cmake-commits] [cmake-commits] david.cole committed cmCTestCoverageHandler.cxx 1.75 1.76
cmake-commits at cmake.org
cmake-commits at cmake.org
Mon Oct 12 14:51:57 EDT 2009
Update of /cvsroot/CMake/CMake/Source/CTest
In directory public:/mounts/ram/cvs-serv27120
Modified Files:
cmCTestCoverageHandler.cxx
Log Message:
Fix issue #5668 - use CollapseFullPath when determining if covered file is within source or binary tree. Allows gcc/gcov coverage analysis using MinGW on Windows.
Index: cmCTestCoverageHandler.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestCoverageHandler.cxx,v
retrieving revision 1.75
retrieving revision 1.76
diff -C 2 -d -r1.75 -r1.76
*** cmCTestCoverageHandler.cxx 4 Oct 2009 15:40:02 -0000 1.75
--- cmCTestCoverageHandler.cxx 12 Oct 2009 18:51:54 -0000 1.76
***************
*** 678,681 ****
--- 678,699 ----
//----------------------------------------------------------------------
+ bool IsFileInDir(const std::string &infile, const std::string &indir)
+ {
+ std::string file = cmSystemTools::CollapseFullPath(infile.c_str());
+ std::string dir = cmSystemTools::CollapseFullPath(indir.c_str());
+
+ if (
+ file.size() > dir.size() &&
+ (fnc(file.substr(0, dir.size())) == fnc(dir)) &&
+ file[dir.size()] == '/'
+ )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ //----------------------------------------------------------------------
int cmCTestCoverageHandler::HandleGCovCoverage(
cmCTestCoverageHandlerContainer* cont)
***************
*** 736,749 ****
--- 754,778 ----
cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
int file_count = 0;
+
// make sure output from gcov is in English!
cmSystemTools::PutEnv("LC_ALL=POSIX");
+
+ // 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.
+ //
for ( it = files.begin(); it != files.end(); ++ it )
{
cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush);
+
+ // Call gcov to get coverage data for this *.gcda file:
+ //
std::string fileDir = cmSystemTools::GetFilenamePath(it->c_str());
std::string command = "\"" + gcovCommand + "\" -l -o \"" + fileDir
+ "\" \"" + *it + "\"";
+
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, command.c_str()
<< std::endl);
+
std::string output = "";
std::string errors = "";
***************
*** 778,793 ****
<< "--------------------------------------------------------------"
<< std::endl);
std::vector<cmStdString> lines;
std::vector<cmStdString>::iterator line;
-
- // Globals for storing current source file and current gcov file;
cmSystemTools::Split(output.c_str(), lines);
for ( line = lines.begin(); line != lines.end(); ++line)
{
std::string sourceFile;
std::string gcovFile;
cmCTestLog(this->CTest, DEBUG, "Line: [" << line->c_str() << "]"
<< std::endl);
if ( line->size() == 0 )
{
--- 807,824 ----
<< "--------------------------------------------------------------"
<< std::endl);
+
std::vector<cmStdString> lines;
std::vector<cmStdString>::iterator line;
cmSystemTools::Split(output.c_str(), lines);
+
for ( line = lines.begin(); line != lines.end(); ++line)
{
std::string sourceFile;
std::string gcovFile;
+
cmCTestLog(this->CTest, DEBUG, "Line: [" << line->c_str() << "]"
<< std::endl);
+
if ( line->size() == 0 )
{
***************
*** 796,810 ****
else if ( st1re1.find(line->c_str()) )
{
! if ( gcovStyle != 0 )
{
- if ( gcovStyle != 1 )
- {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style"
- << std::endl);
- cont->Error ++;
- break;
- }
gcovStyle = 1;
}
actualSourceFile = "";
--- 827,841 ----
else if ( st1re1.find(line->c_str()) )
{
! if ( gcovStyle == 0 )
{
gcovStyle = 1;
}
+ if ( gcovStyle != 1 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e1"
+ << std::endl);
+ cont->Error ++;
+ break;
+ }
actualSourceFile = "";
***************
*** 813,827 ****
else if ( st1re2.find(line->c_str() ) )
{
! if ( gcovStyle != 0 )
{
- if ( gcovStyle != 1 )
- {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style"
- << std::endl);
- cont->Error ++;
- break;
- }
gcovStyle = 1;
}
gcovFile = st1re2.match(1);
--- 844,858 ----
else if ( st1re2.find(line->c_str() ) )
{
! if ( gcovStyle == 0 )
{
gcovStyle = 1;
}
+ if ( gcovStyle != 1 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e2"
+ << std::endl);
+ cont->Error ++;
+ break;
+ }
gcovFile = st1re2.match(1);
***************
*** 829,843 ****
else if ( st2re1.find(line->c_str() ) )
{
! if ( gcovStyle != 0 )
{
- if ( gcovStyle != 2 )
- {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style"
- << std::endl);
- cont->Error ++;
- break;
- }
gcovStyle = 2;
}
actualSourceFile = "";
--- 860,874 ----
else if ( st2re1.find(line->c_str() ) )
{
! if ( gcovStyle == 0 )
{
gcovStyle = 2;
}
+ if ( gcovStyle != 2 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e3"
+ << std::endl);
+ cont->Error ++;
+ break;
+ }
actualSourceFile = "";
***************
*** 846,874 ****
else if ( st2re2.find(line->c_str() ) )
{
! if ( gcovStyle != 0 )
{
- if ( gcovStyle != 2 )
- {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style"
- << std::endl);
- cont->Error ++;
- break;
- }
gcovStyle = 2;
}
}
else if ( st2re3.find(line->c_str() ) )
{
! if ( gcovStyle != 0 )
{
- if ( gcovStyle != 2 )
- {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style"
- << std::endl);
- cont->Error ++;
- break;
- }
gcovStyle = 2;
}
gcovFile = st2re3.match(2);
--- 877,905 ----
else if ( st2re2.find(line->c_str() ) )
{
! if ( gcovStyle == 0 )
{
gcovStyle = 2;
}
+ if ( gcovStyle != 2 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e4"
+ << std::endl);
+ cont->Error ++;
+ break;
+ }
}
else if ( st2re3.find(line->c_str() ) )
{
! if ( gcovStyle == 0 )
{
gcovStyle = 2;
}
+ if ( gcovStyle != 2 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e5"
+ << std::endl);
+ cont->Error ++;
+ break;
+ }
gcovFile = st2re3.match(2);
***************
*** 876,890 ****
else if ( st2re4.find(line->c_str() ) )
{
! if ( gcovStyle != 0 )
{
- if ( gcovStyle != 2 )
- {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style"
- << std::endl);
- cont->Error ++;
- break;
- }
gcovStyle = 2;
}
cmCTestLog(this->CTest, WARNING, "Warning: " << st2re4.match(1)
--- 907,921 ----
else if ( st2re4.find(line->c_str() ) )
{
! if ( gcovStyle == 0 )
{
gcovStyle = 2;
}
+ if ( gcovStyle != 2 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e6"
+ << std::endl);
+ cont->Error ++;
+ break;
+ }
cmCTestLog(this->CTest, WARNING, "Warning: " << st2re4.match(1)
***************
*** 893,907 ****
else if ( st2re5.find(line->c_str() ) )
{
! if ( gcovStyle != 0 )
{
- if ( gcovStyle != 2 )
- {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style"
- << std::endl);
- cont->Error ++;
- break;
- }
gcovStyle = 2;
}
cmCTestLog(this->CTest, WARNING, "Warning: Cannot open file: "
--- 924,938 ----
else if ( st2re5.find(line->c_str() ) )
{
! if ( gcovStyle == 0 )
{
gcovStyle = 2;
}
+ if ( gcovStyle != 2 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e7"
+ << std::endl);
+ cont->Error ++;
+ break;
+ }
cmCTestLog(this->CTest, WARNING, "Warning: Cannot open file: "
***************
*** 910,924 ****
else if ( st2re6.find(line->c_str() ) )
{
! if ( gcovStyle != 0 )
{
- if ( gcovStyle != 2 )
- {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style"
- << std::endl);
- cont->Error ++;
- break;
- }
gcovStyle = 2;
}
cmCTestLog(this->CTest, WARNING, "Warning: File: " << st2re6.match(1)
--- 941,955 ----
else if ( st2re6.find(line->c_str() ) )
{
! if ( gcovStyle == 0 )
{
gcovStyle = 2;
}
+ if ( gcovStyle != 2 )
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e8"
+ << std::endl);
+ cont->Error ++;
+ break;
+ }
cmCTestLog(this->CTest, WARNING, "Warning: File: " << st2re6.match(1)
***************
*** 928,941 ****
{
cmCTestLog(this->CTest, ERROR_MESSAGE,
! "Unknown line: [" << line->c_str() << "]" << std::endl);
cont->Error ++;
//abort();
}
! if ( !gcovFile.empty() && actualSourceFile.size() )
{
! cmCTestCoverageHandlerContainer::SingleFileCoverageVector* vec
! = &cont->TotalCoverage[actualSourceFile];
! cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " in file: "
<< gcovFile << std::endl);
std::ifstream ifile(gcovFile.c_str());
if ( ! ifile )
--- 959,980 ----
{
cmCTestLog(this->CTest, ERROR_MESSAGE,
! "Unknown gcov output line: [" << line->c_str() << "]" << std::endl);
cont->Error ++;
//abort();
}
!
!
! // 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:
! //
! if ( !gcovFile.empty() && !actualSourceFile.empty() )
{
! cmCTestCoverageHandlerContainer::SingleFileCoverageVector& vec
! = cont->TotalCoverage[actualSourceFile];
!
! cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " in gcovFile: "
<< gcovFile << std::endl);
+
std::ifstream ifile(gcovFile.c_str());
if ( ! ifile )
***************
*** 970,1008 ****
std::string prefix = nl.substr(0, 12);
int cov = atoi(prefix.c_str());
// Read the line number starting at the 10th character of the gcov
// output line
std::string lineNumber = nl.substr(10, 5);
int lineIdx = atoi(lineNumber.c_str())-1;
if ( lineIdx >= 0 )
{
! while ( vec->size() <=
! static_cast<size_t>(lineIdx) )
{
! vec->push_back(-1);
}
// Initially all entries are -1 (not used). If we get coverage
// information, increment it to 0 first.
! if ( (*vec)[lineIdx] < 0 )
{
if ( cov > 0 || prefix.find("#") != prefix.npos )
{
! (*vec)[lineIdx] = 0;
}
}
! (*vec)[lineIdx] += cov;
}
}
}
actualSourceFile = "";
}
if ( !sourceFile.empty() && actualSourceFile.empty() )
{
gcovFile = "";
! // Is it in the source dir?
! if ( sourceFile.size() > cont->SourceDir.size() &&
! (fnc(sourceFile.substr(0, cont->SourceDir.size())) ==
! fnc(cont->SourceDir)) &&
! sourceFile[cont->SourceDir.size()] == '/' )
{
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " produced s: "
--- 1009,1051 ----
std::string prefix = nl.substr(0, 12);
int cov = atoi(prefix.c_str());
+
// Read the line number starting at the 10th character of the gcov
// output line
std::string lineNumber = nl.substr(10, 5);
+
int lineIdx = atoi(lineNumber.c_str())-1;
if ( lineIdx >= 0 )
{
! while ( vec.size() <= static_cast<size_t>(lineIdx) )
{
! vec.push_back(-1);
}
+
// Initially all entries are -1 (not used). If we get coverage
// information, increment it to 0 first.
! if ( vec[lineIdx] < 0 )
{
if ( cov > 0 || prefix.find("#") != prefix.npos )
{
! vec[lineIdx] = 0;
}
}
!
! vec[lineIdx] += cov;
}
}
}
+
actualSourceFile = "";
}
+
+
if ( !sourceFile.empty() && actualSourceFile.empty() )
{
gcovFile = "";
! // Is it in the source dir or the binary dir?
! //
! if ( IsFileInDir(sourceFile, cont->SourceDir) )
{
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " produced s: "
***************
*** 1013,1022 ****
= cmSystemTools::CollapseFullPath(sourceFile.c_str());
}
!
! // Binary dir?
! if ( sourceFile.size() > cont->BinaryDir.size() &&
! (fnc(sourceFile.substr(0, cont->BinaryDir.size())) ==
! fnc(cont->BinaryDir)) &&
! sourceFile[cont->BinaryDir.size()] == '/' )
{
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " produced b: "
--- 1056,1060 ----
= cmSystemTools::CollapseFullPath(sourceFile.c_str());
}
! else if ( IsFileInDir(sourceFile, cont->BinaryDir) )
{
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " produced b: "
***************
*** 1030,1034 ****
if ( actualSourceFile.empty() )
{
! if ( missingFiles.find(actualSourceFile) == missingFiles.end() )
{
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
--- 1068,1072 ----
if ( actualSourceFile.empty() )
{
! if ( missingFiles.find(sourceFile) == missingFiles.end() )
{
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
***************
*** 1049,1058 ****
<< " in source dir: " << cont->SourceDir.c_str()
<< " or binary dir: " << cont->BinaryDir.c_str() << std::endl;
! missingFiles.insert(actualSourceFile);
}
}
}
}
! file_count ++;
if ( file_count % 50 == 0 )
{
--- 1087,1099 ----
<< " in source dir: " << cont->SourceDir.c_str()
<< " or binary dir: " << cont->BinaryDir.c_str() << std::endl;
!
! missingFiles.insert(sourceFile);
}
}
}
}
!
! file_count++;
!
if ( file_count % 50 == 0 )
{
***************
*** 1062,1065 ****
--- 1103,1107 ----
}
}
+
cmSystemTools::ChangeDirectory(currentDirectory.c_str());
return file_count;
More information about the Cmake-commits
mailing list