2004-09-09 16:41:05 +04:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
|
|
|
|
2006-03-09 19:17:10 +03:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
2004-09-09 16:41:05 +04:00
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
|
|
|
|
#include "cmCTestCoverageHandler.h"
|
|
|
|
|
|
|
|
#include "cmCTest.h"
|
|
|
|
#include "cmake.h"
|
2004-10-18 03:45:36 +04:00
|
|
|
#include "cmSystemTools.h"
|
2005-01-27 18:15:01 +03:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2006-03-21 20:54:31 +03:00
|
|
|
|
2004-09-09 16:41:05 +04:00
|
|
|
#include <cmsys/Process.h>
|
2004-10-18 03:45:36 +04:00
|
|
|
#include <cmsys/RegularExpression.hxx>
|
2006-03-21 20:54:31 +03:00
|
|
|
#include <cmsys/Glob.hxx>
|
2004-09-09 16:41:05 +04:00
|
|
|
|
2006-03-09 19:17:10 +03:00
|
|
|
#include <stdlib.h>
|
2004-09-09 17:31:43 +04:00
|
|
|
#include <math.h>
|
|
|
|
#include <float.h>
|
|
|
|
|
2004-09-09 16:41:05 +04:00
|
|
|
#define SAFEDIV(x,y) (((y)!=0)?((x)/(y)):(0))
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
cmCTestCoverageHandler::cmCTestCoverageHandler()
|
|
|
|
{
|
2005-06-17 21:04:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void cmCTestCoverageHandler::Initialize()
|
|
|
|
{
|
2005-06-23 21:04:18 +04:00
|
|
|
this->Superclass::Initialize();
|
2006-03-10 23:03:09 +03:00
|
|
|
this->CustomCoverageExclude.empty();
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2006-03-09 19:17:10 +03:00
|
|
|
bool cmCTestCoverageHandler::StartCoverageLogFile(
|
|
|
|
cmGeneratedFileStream& covLogFile, int logFileCount)
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2004-10-18 03:45:36 +04:00
|
|
|
char covLogFilename[1024];
|
2005-06-23 21:04:18 +04:00
|
|
|
sprintf(covLogFilename, "CoverageLog-%d", logFileCount);
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Open file: "
|
|
|
|
<< covLogFilename << std::endl);
|
2005-06-23 21:04:18 +04:00
|
|
|
if (!this->StartResultingXML(covLogFilename, covLogFile) )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open log file: "
|
2006-03-09 19:17:10 +03:00
|
|
|
<< covLogFilename << std::endl);
|
2004-10-18 03:45:36 +04:00
|
|
|
return false;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2006-03-10 23:03:09 +03:00
|
|
|
std::string local_start_time = this->CTest->CurrentTime();
|
|
|
|
this->CTest->StartXML(covLogFile);
|
2004-10-18 03:45:36 +04:00
|
|
|
covLogFile << "<CoverageLog>" << std::endl
|
2006-03-09 19:17:10 +03:00
|
|
|
<< "\t<StartDateTime>" << local_start_time << "</StartDateTime>"
|
|
|
|
<< std::endl;
|
2004-10-18 03:45:36 +04:00
|
|
|
return true;
|
|
|
|
}
|
2004-09-09 16:41:05 +04:00
|
|
|
|
2004-10-18 03:45:36 +04:00
|
|
|
//----------------------------------------------------------------------
|
2006-03-09 19:17:10 +03:00
|
|
|
void cmCTestCoverageHandler::EndCoverageLogFile(cmGeneratedFileStream& ostr,
|
|
|
|
int logFileCount)
|
2004-10-18 03:45:36 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
std::string local_end_time = this->CTest->CurrentTime();
|
2004-10-18 03:45:36 +04:00
|
|
|
ostr << "\t<EndDateTime>" << local_end_time << "</EndDateTime>" << std::endl
|
|
|
|
<< "</CoverageLog>" << std::endl;
|
2006-03-10 23:03:09 +03:00
|
|
|
this->CTest->EndXML(ostr);
|
2004-10-18 03:45:36 +04:00
|
|
|
char covLogFilename[1024];
|
|
|
|
sprintf(covLogFilename, "CoverageLog-%d.xml", logFileCount);
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Close file: "
|
2006-03-09 19:17:10 +03:00
|
|
|
<< covLogFilename << std::endl);
|
2005-07-14 17:29:33 +04:00
|
|
|
ostr.Close();
|
2004-10-18 03:45:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2006-03-09 19:17:10 +03:00
|
|
|
bool cmCTestCoverageHandler::ShouldIDoCoverage(const char* file,
|
|
|
|
const char* srcDir,
|
2005-06-01 01:32:40 +04:00
|
|
|
const char* binDir)
|
2004-10-18 03:45:36 +04:00
|
|
|
{
|
2005-07-14 21:25:40 +04:00
|
|
|
std::vector<cmsys::RegularExpression>::iterator sit;
|
2006-03-10 23:03:09 +03:00
|
|
|
for ( sit = this->CustomCoverageExcludeRegex.begin();
|
|
|
|
sit != this->CustomCoverageExcludeRegex.end(); ++ sit )
|
2005-07-14 21:25:40 +04:00
|
|
|
{
|
|
|
|
if ( sit->find(file) )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " File " << file
|
2005-07-14 21:25:40 +04:00
|
|
|
<< " is excluded in CTestCustom.ctest" << std::endl;);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-18 03:45:36 +04:00
|
|
|
std::string fSrcDir = cmSystemTools::CollapseFullPath(srcDir);
|
|
|
|
std::string fBinDir = cmSystemTools::CollapseFullPath(binDir);
|
|
|
|
std::string fFile = cmSystemTools::CollapseFullPath(file);
|
2006-03-09 19:17:10 +03:00
|
|
|
bool sourceSubDir = cmSystemTools::IsSubDirectory(fFile.c_str(),
|
|
|
|
fSrcDir.c_str());
|
|
|
|
bool buildSubDir = cmSystemTools::IsSubDirectory(fFile.c_str(),
|
|
|
|
fBinDir.c_str());
|
2004-10-18 03:45:36 +04:00
|
|
|
// Always check parent directory of the file.
|
|
|
|
std::string fileDir = cmSystemTools::GetFilenamePath(fFile.c_str());
|
|
|
|
std::string checkDir;
|
|
|
|
|
|
|
|
// We also need to check the binary/source directory pair.
|
|
|
|
if ( sourceSubDir && buildSubDir )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2004-10-18 03:45:36 +04:00
|
|
|
if ( fSrcDir.size() > fBinDir.size() )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2004-10-18 03:45:36 +04:00
|
|
|
checkDir = fSrcDir;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2004-10-18 03:45:36 +04:00
|
|
|
else
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2004-10-18 03:45:36 +04:00
|
|
|
checkDir = fBinDir;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
|
|
|
}
|
2004-10-18 03:45:36 +04:00
|
|
|
else if ( sourceSubDir )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2004-10-18 03:45:36 +04:00
|
|
|
checkDir = fSrcDir;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2004-10-18 03:45:36 +04:00
|
|
|
else if ( buildSubDir )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2004-10-18 03:45:36 +04:00
|
|
|
checkDir = fBinDir;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2004-10-18 03:45:36 +04:00
|
|
|
std::string ndc
|
|
|
|
= cmSystemTools::FileExistsInParentDirectories(".NoDartCoverage",
|
|
|
|
fFile.c_str(), checkDir.c_str());
|
|
|
|
if ( ndc.size() )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Found: " << ndc.c_str()
|
2006-03-09 19:17:10 +03:00
|
|
|
<< " so skip coverage of " << file << std::endl);
|
2004-10-18 03:45:36 +04:00
|
|
|
return false;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
|
|
|
|
2004-10-18 03:45:36 +04:00
|
|
|
// By now checkDir should be set to parent directory of the file.
|
|
|
|
// Get the relative path to the file an apply it to the opposite directory.
|
|
|
|
// If it is the same as fileDir, then ignore, otherwise check.
|
|
|
|
std::string relPath = cmSystemTools::RelativePath(checkDir.c_str(),
|
|
|
|
fFile.c_str());
|
|
|
|
if ( checkDir == fSrcDir )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2004-10-18 03:45:36 +04:00
|
|
|
checkDir = fBinDir;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2004-10-18 03:45:36 +04:00
|
|
|
else
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2004-10-18 03:45:36 +04:00
|
|
|
checkDir = fSrcDir;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2004-10-18 03:45:36 +04:00
|
|
|
fFile = checkDir + "/" + relPath;
|
|
|
|
fFile = cmSystemTools::GetFilenamePath(fFile.c_str());
|
2004-09-09 16:41:05 +04:00
|
|
|
|
2004-10-18 03:45:36 +04:00
|
|
|
if ( fileDir == fFile )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2004-10-18 03:45:36 +04:00
|
|
|
// This is in-source build, so we trust the previous check.
|
|
|
|
return true;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2004-10-18 03:45:36 +04:00
|
|
|
|
|
|
|
ndc = cmSystemTools::FileExistsInParentDirectories(".NoDartCoverage",
|
|
|
|
fFile.c_str(), checkDir.c_str());
|
|
|
|
if ( ndc.size() )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Found: " << ndc.c_str()
|
2006-03-09 19:17:10 +03:00
|
|
|
<< " so skip coverage of: " << file << std::endl);
|
2004-10-18 03:45:36 +04:00
|
|
|
return false;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2004-10-18 03:45:36 +04:00
|
|
|
// Ok, nothing in source tree, nothing in binary tree
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//clearly it would be nice if this were broken up into a few smaller
|
|
|
|
//functions and commented...
|
2005-01-27 23:54:47 +03:00
|
|
|
int cmCTestCoverageHandler::ProcessHandler()
|
2004-10-18 03:45:36 +04:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
2006-10-19 18:45:19 +04:00
|
|
|
// do we have time for this
|
|
|
|
if (this->CTest->GetRemainingTimeAllowed() < 120)
|
|
|
|
{
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
std::string sourceDir
|
|
|
|
= this->CTest->GetCTestConfiguration("SourceDirectory");
|
|
|
|
std::string binaryDir
|
|
|
|
= this->CTest->GetCTestConfiguration("BuildDirectory");
|
|
|
|
std::string gcovCommand
|
|
|
|
= this->CTest->GetCTestConfiguration("CoverageCommand");
|
2004-10-18 03:45:36 +04:00
|
|
|
|
2005-06-14 19:42:53 +04:00
|
|
|
cmGeneratedFileStream ofs;
|
|
|
|
double elapsed_time_start = cmSystemTools::GetTime();
|
2005-06-23 21:04:18 +04:00
|
|
|
if ( !this->StartLogFile("Coverage", ofs) )
|
2005-06-14 19:42:53 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Cannot create LastCoverage.log file" << std::endl);
|
2005-06-14 19:42:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ofs << "Performing coverage: " << elapsed_time_start << std::endl;
|
|
|
|
|
2004-10-18 03:45:36 +04:00
|
|
|
cmSystemTools::ConvertToUnixSlashes(sourceDir);
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(binaryDir);
|
|
|
|
|
2005-07-06 23:27:02 +04:00
|
|
|
std::string asfGlob = sourceDir + "/*";
|
|
|
|
std::string abfGlob = binaryDir + "/*";
|
2006-03-09 19:17:10 +03:00
|
|
|
|
|
|
|
|
2005-07-06 23:27:02 +04:00
|
|
|
// Style 1
|
2006-03-09 19:17:10 +03:00
|
|
|
std::string st1gcovOutputRex1
|
|
|
|
= "[0-9]+\\.[0-9]+% of [0-9]+ (source |)lines executed in file (.*)$";
|
2005-07-06 23:27:02 +04:00
|
|
|
std::string st1gcovOutputRex2 = "^Creating (.*\\.gcov)\\.";
|
|
|
|
cmsys::RegularExpression st1re1(st1gcovOutputRex1.c_str());
|
|
|
|
cmsys::RegularExpression st1re2(st1gcovOutputRex2.c_str());
|
2006-03-09 19:17:10 +03:00
|
|
|
|
|
|
|
|
2005-07-06 23:27:02 +04:00
|
|
|
// Style 2
|
2005-08-03 21:34:13 +04:00
|
|
|
std::string st2gcovOutputRex1 = "^File *[`'](.*)'$";
|
2006-03-09 19:17:10 +03:00
|
|
|
std::string st2gcovOutputRex2
|
|
|
|
= "Lines executed: *[0-9]+\\.[0-9]+% of [0-9]+$";
|
2005-08-03 22:15:17 +04:00
|
|
|
std::string st2gcovOutputRex3 = "^(.*):creating [`'](.*\\.gcov)'";
|
2005-07-06 23:27:02 +04:00
|
|
|
std::string st2gcovOutputRex4 = "^(.*):unexpected EOF *$";
|
|
|
|
std::string st2gcovOutputRex5 = "^(.*):cannot open source file*$";
|
2006-03-09 19:17:10 +03:00
|
|
|
std::string st2gcovOutputRex6
|
|
|
|
= "^(.*):source file is newer than graph file `(.*)'$";
|
2005-07-06 23:27:02 +04:00
|
|
|
cmsys::RegularExpression st2re1(st2gcovOutputRex1.c_str());
|
|
|
|
cmsys::RegularExpression st2re2(st2gcovOutputRex2.c_str());
|
|
|
|
cmsys::RegularExpression st2re3(st2gcovOutputRex3.c_str());
|
|
|
|
cmsys::RegularExpression st2re4(st2gcovOutputRex4.c_str());
|
|
|
|
cmsys::RegularExpression st2re5(st2gcovOutputRex5.c_str());
|
|
|
|
cmsys::RegularExpression st2re6(st2gcovOutputRex6.c_str());
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Performing coverage" << std::endl);
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
std::string coverage_start_time = this->CTest->CurrentTime();
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
std::string testingDir = this->CTest->GetBinaryDir() + "/Testing";
|
2004-10-18 03:45:36 +04:00
|
|
|
std::string tempDir = testingDir + "/CoverageInfo";
|
|
|
|
std::string currentDirectory = cmSystemTools::GetCurrentWorkingDirectory();
|
|
|
|
cmSystemTools::MakeDirectory(tempDir.c_str());
|
|
|
|
cmSystemTools::ChangeDirectory(tempDir.c_str());
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2006-03-21 20:54:31 +03:00
|
|
|
cmsys::Glob gl;
|
2004-10-18 03:45:36 +04:00
|
|
|
gl.RecurseOn();
|
2005-08-03 19:56:00 +04:00
|
|
|
std::string daGlob = binaryDir + "/*.da";
|
2004-10-18 03:45:36 +04:00
|
|
|
gl.FindFiles(daGlob);
|
|
|
|
std::vector<std::string> files = gl.GetFiles();
|
2005-08-03 19:56:00 +04:00
|
|
|
daGlob = binaryDir + "/*.gcda";
|
|
|
|
gl.FindFiles(daGlob);
|
|
|
|
std::vector<std::string>& moreFiles = gl.GetFiles();
|
|
|
|
files.insert(files.end(), moreFiles.begin(), moreFiles.end());
|
2004-10-18 03:45:36 +04:00
|
|
|
std::vector<std::string>::iterator it;
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-10-18 03:45:36 +04:00
|
|
|
if ( files.size() == 0 )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2006-10-15 15:54:52 +04:00
|
|
|
cmCTestLog(this->CTest, WARNING,
|
|
|
|
" Cannot find any coverage files. Ignoring Coverage request."
|
2006-03-09 19:17:10 +03:00
|
|
|
<< std::endl);
|
2006-10-06 01:53:09 +04:00
|
|
|
// No coverage files is a valid thing, so the exit code is 0
|
|
|
|
cmSystemTools::ChangeDirectory(currentDirectory.c_str());
|
2004-10-18 03:45:36 +04:00
|
|
|
return 0;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2005-07-14 21:25:40 +04:00
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
this->CustomCoverageExcludeRegex.empty();
|
2005-07-14 21:25:40 +04:00
|
|
|
std::vector<cmStdString>::iterator rexIt;
|
2006-03-10 23:03:09 +03:00
|
|
|
for ( rexIt = this->CustomCoverageExclude.begin();
|
|
|
|
rexIt != this->CustomCoverageExclude.end();
|
2005-07-14 21:25:40 +04:00
|
|
|
++ rexIt )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->CustomCoverageExcludeRegex.push_back(
|
2006-03-09 19:17:10 +03:00
|
|
|
cmsys::RegularExpression(rexIt->c_str()));
|
2005-07-14 21:25:40 +04:00
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-10-18 03:45:36 +04:00
|
|
|
typedef std::vector<int> singleFileCoverageVector;
|
|
|
|
typedef std::map<std::string, singleFileCoverageVector> totalCoverageMap;
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-10-18 03:45:36 +04:00
|
|
|
totalCoverageMap totalCoverage;
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2005-07-06 23:27:02 +04:00
|
|
|
int gcovStyle = 0;
|
2005-07-14 19:24:47 +04:00
|
|
|
|
|
|
|
std::set<std::string> missingFiles;
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2005-07-06 23:27:02 +04:00
|
|
|
std::string actualSourceFile = "";
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
2006-03-09 19:17:10 +03:00
|
|
|
" Processing coverage (each . represents one file):" << std::endl);
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
|
2005-07-14 19:24:47 +04:00
|
|
|
int file_count = 0;
|
2004-10-18 03:45:36 +04:00
|
|
|
for ( it = files.begin(); it != files.end(); ++ it )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush);
|
2004-10-18 03:45:36 +04:00
|
|
|
std::string fileDir = cmSystemTools::GetFilenamePath(it->c_str());
|
2006-03-09 19:17:10 +03:00
|
|
|
std::string command = "\"" + gcovCommand + "\" -l -o \"" + fileDir
|
|
|
|
+ "\" \"" + *it + "\"";
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, command.c_str()
|
|
|
|
<< std::endl);
|
2004-10-18 03:45:36 +04:00
|
|
|
std::string output = "";
|
2005-06-14 19:42:53 +04:00
|
|
|
std::string errors = "";
|
2004-10-18 03:45:36 +04:00
|
|
|
int retVal = 0;
|
2005-06-14 19:42:53 +04:00
|
|
|
ofs << "* Run coverage for: " << fileDir.c_str() << std::endl;
|
|
|
|
ofs << " Command: " << command.c_str() << std::endl;
|
2006-03-10 23:03:09 +03:00
|
|
|
int res = this->CTest->RunCommand(command.c_str(), &output, &errors,
|
|
|
|
&retVal, tempDir.c_str(), 0 /*this->TimeOut*/);
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2005-06-14 19:42:53 +04:00
|
|
|
ofs << " Output: " << output.c_str() << std::endl;
|
|
|
|
ofs << " Errors: " << errors.c_str() << std::endl;
|
2004-10-18 03:45:36 +04:00
|
|
|
if ( ! res )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Problem running coverage on file: " << it->c_str() << std::endl);
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Command produced error: " << errors << std::endl);
|
2004-10-18 03:45:36 +04:00
|
|
|
error ++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ( retVal != 0 )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Coverage command returned: "
|
2006-03-09 19:17:10 +03:00
|
|
|
<< retVal << " while processing: " << it->c_str() << std::endl);
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Command produced error: " << error << std::endl);
|
2004-10-18 03:45:36 +04:00
|
|
|
}
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2006-03-09 19:17:10 +03:00
|
|
|
"--------------------------------------------------------------"
|
|
|
|
<< std::endl
|
2005-07-06 23:27:02 +04:00
|
|
|
<< output << std::endl
|
2006-03-09 19:17:10 +03:00
|
|
|
<< "--------------------------------------------------------------"
|
|
|
|
<< std::endl);
|
2004-10-18 03:45:36 +04:00
|
|
|
std::vector<cmStdString> lines;
|
|
|
|
std::vector<cmStdString>::iterator line;
|
2006-03-09 19:17:10 +03:00
|
|
|
|
|
|
|
|
2005-07-06 23:27:02 +04:00
|
|
|
// Globals for storing current source file and current gcov file;
|
2004-10-18 03:45:36 +04:00
|
|
|
cmSystemTools::Split(output.c_str(), lines);
|
|
|
|
for ( line = lines.begin(); line != lines.end(); ++line)
|
|
|
|
{
|
2005-07-06 23:27:02 +04:00
|
|
|
std::string sourceFile;
|
|
|
|
std::string gcovFile;
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, DEBUG, "Line: [" << line->c_str() << "]"
|
2006-03-09 19:17:10 +03:00
|
|
|
<< std::endl);
|
2005-07-06 23:27:02 +04:00
|
|
|
if ( line->size() == 0 )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2005-07-06 23:27:02 +04:00
|
|
|
// Ignore empty line; probably style 2
|
|
|
|
}
|
|
|
|
else if ( st1re1.find(line->c_str()) )
|
|
|
|
{
|
|
|
|
if ( gcovStyle != 0 )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2005-07-06 23:27:02 +04:00
|
|
|
if ( gcovStyle != 1 )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style"
|
2006-03-09 19:17:10 +03:00
|
|
|
<< std::endl);
|
2005-07-06 23:27:02 +04:00
|
|
|
error ++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gcovStyle = 1;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2005-07-06 23:27:02 +04:00
|
|
|
actualSourceFile = "";
|
|
|
|
sourceFile = st1re1.match(2);
|
|
|
|
}
|
|
|
|
else if ( st1re2.find(line->c_str() ) )
|
|
|
|
{
|
|
|
|
if ( gcovStyle != 0 )
|
|
|
|
{
|
|
|
|
if ( gcovStyle != 1 )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style"
|
2006-03-09 19:17:10 +03:00
|
|
|
<< std::endl);
|
2005-07-06 23:27:02 +04:00
|
|
|
error ++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gcovStyle = 1;
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2005-07-06 23:27:02 +04:00
|
|
|
gcovFile = st1re2.match(1);
|
|
|
|
}
|
|
|
|
else if ( st2re1.find(line->c_str() ) )
|
|
|
|
{
|
|
|
|
if ( gcovStyle != 0 )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2005-07-06 23:27:02 +04:00
|
|
|
if ( gcovStyle != 2 )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style"
|
2006-03-09 19:17:10 +03:00
|
|
|
<< std::endl);
|
2005-07-06 23:27:02 +04:00
|
|
|
error ++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gcovStyle = 2;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2005-07-06 23:27:02 +04:00
|
|
|
actualSourceFile = "";
|
|
|
|
sourceFile = st2re1.match(1);
|
|
|
|
}
|
|
|
|
else if ( st2re2.find(line->c_str() ) )
|
|
|
|
{
|
|
|
|
if ( gcovStyle != 0 )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2005-07-06 23:27:02 +04:00
|
|
|
if ( gcovStyle != 2 )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style"
|
2006-03-09 19:17:10 +03:00
|
|
|
<< std::endl);
|
2005-07-06 23:27:02 +04:00
|
|
|
error ++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gcovStyle = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( st2re3.find(line->c_str() ) )
|
|
|
|
{
|
|
|
|
if ( gcovStyle != 0 )
|
|
|
|
{
|
|
|
|
if ( gcovStyle != 2 )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style"
|
2006-03-09 19:17:10 +03:00
|
|
|
<< std::endl);
|
2005-07-06 23:27:02 +04:00
|
|
|
error ++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gcovStyle = 2;
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2005-07-06 23:27:02 +04:00
|
|
|
gcovFile = st2re3.match(2);
|
|
|
|
}
|
|
|
|
else if ( st2re4.find(line->c_str() ) )
|
|
|
|
{
|
|
|
|
if ( gcovStyle != 0 )
|
|
|
|
{
|
|
|
|
if ( gcovStyle != 2 )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style"
|
2006-03-09 19:17:10 +03:00
|
|
|
<< std::endl);
|
2005-07-06 23:27:02 +04:00
|
|
|
error ++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gcovStyle = 2;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, WARNING, "Warning: " << st2re4.match(1)
|
2006-03-09 19:17:10 +03:00
|
|
|
<< " had unexpected EOF" << std::endl);
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2005-07-06 23:27:02 +04:00
|
|
|
else if ( st2re5.find(line->c_str() ) )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2005-07-06 23:27:02 +04:00
|
|
|
if ( gcovStyle != 0 )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2005-07-06 23:27:02 +04:00
|
|
|
if ( gcovStyle != 2 )
|
2004-10-18 03:45:36 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style"
|
2006-03-09 19:17:10 +03:00
|
|
|
<< std::endl);
|
2005-07-06 23:27:02 +04:00
|
|
|
error ++;
|
|
|
|
break;
|
2004-10-18 03:45:36 +04:00
|
|
|
}
|
2005-07-06 23:27:02 +04:00
|
|
|
gcovStyle = 2;
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, WARNING, "Warning: Cannot open file: "
|
2006-03-09 19:17:10 +03:00
|
|
|
<< st2re5.match(1) << std::endl);
|
2005-07-06 23:27:02 +04:00
|
|
|
}
|
|
|
|
else if ( st2re6.find(line->c_str() ) )
|
|
|
|
{
|
|
|
|
if ( gcovStyle != 0 )
|
|
|
|
{
|
|
|
|
if ( gcovStyle != 2 )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style"
|
2006-03-09 19:17:10 +03:00
|
|
|
<< std::endl);
|
2005-07-06 23:27:02 +04:00
|
|
|
error ++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gcovStyle = 2;
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, WARNING, "Warning: File: " << st2re6.match(1)
|
2005-07-06 23:27:02 +04:00
|
|
|
<< " is newer than " << st2re6.match(2) << std::endl);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unknown line: [" << line->c_str() << "]" << std::endl);
|
2005-07-06 23:27:02 +04:00
|
|
|
error ++;
|
|
|
|
//abort();
|
|
|
|
}
|
|
|
|
if ( !gcovFile.empty() && actualSourceFile.size() )
|
|
|
|
{
|
|
|
|
singleFileCoverageVector* vec = &totalCoverage[actualSourceFile];
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " in file: "
|
2006-03-09 19:17:10 +03:00
|
|
|
<< gcovFile << std::endl);
|
2005-07-06 23:27:02 +04:00
|
|
|
std::ifstream ifile(gcovFile.c_str());
|
|
|
|
if ( ! ifile )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open file: "
|
2006-03-09 19:17:10 +03:00
|
|
|
<< gcovFile << std::endl);
|
2005-07-06 23:27:02 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
long cnt = -1;
|
|
|
|
std::string nl;
|
|
|
|
while ( cmSystemTools::GetLineFromStream(ifile, nl) )
|
|
|
|
{
|
|
|
|
cnt ++;
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2005-07-06 23:27:02 +04:00
|
|
|
//TODO: Handle gcov 3.0 non-coverage lines
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2005-07-06 23:27:02 +04:00
|
|
|
// Skip empty lines
|
|
|
|
if ( !nl.size() )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2005-07-06 23:27:02 +04:00
|
|
|
// Skip unused lines
|
2005-07-14 19:24:47 +04:00
|
|
|
if ( nl.size() < 12 )
|
2005-07-06 23:27:02 +04:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2005-07-14 19:24:47 +04:00
|
|
|
|
2006-03-09 19:17:10 +03:00
|
|
|
// Read the coverage count from the beginning of the gcov output
|
|
|
|
// line
|
2005-07-06 23:27:02 +04:00
|
|
|
std::string prefix = nl.substr(0, 12);
|
|
|
|
int cov = atoi(prefix.c_str());
|
2006-03-09 19:17:10 +03:00
|
|
|
// Read the line number starting at the 10th character of the gcov
|
|
|
|
// output line
|
2005-07-06 23:27:02 +04:00
|
|
|
std::string lineNumber = nl.substr(10, 5);
|
2005-07-14 19:24:47 +04:00
|
|
|
int lineIdx = atoi(lineNumber.c_str())-1;
|
|
|
|
if ( lineIdx >= 0 )
|
|
|
|
{
|
2006-03-09 19:17:10 +03:00
|
|
|
while ( vec->size() <=
|
|
|
|
static_cast<singleFileCoverageVector::size_type>(lineIdx) )
|
2005-07-14 19:24:47 +04:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
|
|
|
}
|
2005-07-06 23:27:02 +04:00
|
|
|
actualSourceFile = "";
|
2004-10-18 03:45:36 +04:00
|
|
|
}
|
2005-07-06 23:27:02 +04:00
|
|
|
if ( !sourceFile.empty() && actualSourceFile.empty() )
|
2004-10-18 03:45:36 +04:00
|
|
|
{
|
2005-07-06 23:27:02 +04:00
|
|
|
gcovFile = "";
|
|
|
|
// Is it in the source dir?
|
|
|
|
if ( sourceFile.size() > sourceDir.size() &&
|
|
|
|
sourceFile.substr(0, sourceDir.size()) == sourceDir &&
|
|
|
|
sourceFile[sourceDir.size()] == '/' )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " produced s: "
|
2006-03-09 19:17:10 +03:00
|
|
|
<< sourceFile.c_str() << std::endl);
|
|
|
|
ofs << " produced in source dir: " << sourceFile.c_str()
|
|
|
|
<< std::endl;
|
|
|
|
actualSourceFile
|
|
|
|
= cmSystemTools::CollapseFullPath(sourceFile.c_str());
|
2005-07-06 23:27:02 +04:00
|
|
|
}
|
|
|
|
// Binary dir?
|
|
|
|
if ( sourceFile.size() > binaryDir.size() &&
|
|
|
|
sourceFile.substr(0, binaryDir.size()) == binaryDir &&
|
|
|
|
sourceFile[binaryDir.size()] == '/' )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " produced b: "
|
2006-03-09 19:17:10 +03:00
|
|
|
<< sourceFile.c_str() << std::endl);
|
|
|
|
ofs << " produced in binary dir: " << sourceFile.c_str()
|
|
|
|
<< std::endl;
|
|
|
|
actualSourceFile
|
|
|
|
= cmSystemTools::CollapseFullPath(sourceFile.c_str());
|
2005-07-06 23:27:02 +04:00
|
|
|
}
|
|
|
|
if ( actualSourceFile.empty() )
|
|
|
|
{
|
2005-07-14 19:24:47 +04:00
|
|
|
if ( missingFiles.find(actualSourceFile) == missingFiles.end() )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
"Something went wrong" << std::endl);
|
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "File: ["
|
2006-03-09 19:17:10 +03:00
|
|
|
<< sourceFile.c_str() << "]" << std::endl);
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "s: ["
|
2006-03-09 19:17:10 +03:00
|
|
|
<< sourceFile.substr(0, sourceDir.size()) << "]" << std::endl);
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "b: ["
|
2006-03-09 19:17:10 +03:00
|
|
|
<< sourceFile.substr(0, binaryDir.size()) << "]" << std::endl);
|
|
|
|
ofs << " Something went wrong. Cannot find: "
|
|
|
|
<< sourceFile.c_str()
|
2005-07-14 19:24:47 +04:00
|
|
|
<< " in source dir: " << sourceDir.c_str()
|
|
|
|
<< " or binary dir: " << binaryDir.c_str() << std::endl;
|
|
|
|
missingFiles.insert(actualSourceFile);
|
|
|
|
}
|
2005-07-06 23:27:02 +04:00
|
|
|
}
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
|
|
|
}
|
2005-07-14 19:24:47 +04:00
|
|
|
file_count ++;
|
|
|
|
if ( file_count % 50 == 0 )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, " processed: " << file_count
|
2006-03-09 19:17:10 +03:00
|
|
|
<< " out of " << files.size() << std::endl);
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
|
2005-07-14 19:24:47 +04:00
|
|
|
}
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2005-01-27 18:15:01 +03:00
|
|
|
cmGeneratedFileStream covSumFile;
|
|
|
|
cmGeneratedFileStream covLogFile;
|
2004-10-18 03:45:36 +04:00
|
|
|
|
2005-06-23 21:04:18 +04:00
|
|
|
if (!this->StartResultingXML("Coverage", covSumFile))
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Cannot open coverage summary file." << std::endl);
|
2006-10-06 01:53:09 +04:00
|
|
|
cmSystemTools::ChangeDirectory(currentDirectory.c_str());
|
2005-01-27 23:54:47 +03:00
|
|
|
return -1;
|
2004-10-18 03:45:36 +04:00
|
|
|
}
|
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
this->CTest->StartXML(covSumFile);
|
2004-10-18 03:45:36 +04:00
|
|
|
// Produce output xml files
|
2004-09-09 16:41:05 +04:00
|
|
|
|
2004-10-18 03:45:36 +04:00
|
|
|
covSumFile << "<Coverage>" << std::endl
|
2006-03-09 19:17:10 +03:00
|
|
|
<< "\t<StartDateTime>" << coverage_start_time << "</StartDateTime>"
|
|
|
|
<< std::endl;
|
2004-10-18 03:45:36 +04:00
|
|
|
int logFileCount = 0;
|
2005-06-23 21:04:18 +04:00
|
|
|
if ( !this->StartCoverageLogFile(covLogFile, logFileCount) )
|
2004-10-18 03:45:36 +04:00
|
|
|
{
|
2006-10-06 01:53:09 +04:00
|
|
|
cmSystemTools::ChangeDirectory(currentDirectory.c_str());
|
2005-01-27 23:54:47 +03:00
|
|
|
return -1;
|
2004-10-18 03:45:36 +04:00
|
|
|
}
|
|
|
|
totalCoverageMap::iterator fileIterator;
|
|
|
|
int cnt = 0;
|
|
|
|
long total_tested = 0;
|
|
|
|
long total_untested = 0;
|
2005-05-04 19:13:35 +04:00
|
|
|
//std::string fullSourceDir = sourceDir + "/";
|
|
|
|
//std::string fullBinaryDir = binaryDir + "/";
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
2006-03-09 19:17:10 +03:00
|
|
|
" Acumulating results (each . represents one file):" << std::endl);
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
|
2005-07-14 22:15:51 +04:00
|
|
|
|
|
|
|
std::vector<std::string> errorsWhileAccumulating;
|
|
|
|
|
|
|
|
file_count = 0;
|
2004-10-18 03:45:36 +04:00
|
|
|
for ( fileIterator = totalCoverage.begin();
|
|
|
|
fileIterator != totalCoverage.end();
|
|
|
|
++fileIterator )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush);
|
2005-07-14 22:15:51 +04:00
|
|
|
file_count ++;
|
|
|
|
if ( file_count % 50 == 0 )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, " processed: " << file_count
|
2006-03-09 19:17:10 +03:00
|
|
|
<< " out of "
|
2005-07-14 22:15:51 +04:00
|
|
|
<< totalCoverage.size() << std::endl);
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
|
2005-07-14 22:15:51 +04:00
|
|
|
}
|
|
|
|
if ( cnt % 100 == 0 )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2005-06-23 21:04:18 +04:00
|
|
|
this->EndCoverageLogFile(covLogFile, logFileCount);
|
2004-10-18 03:45:36 +04:00
|
|
|
logFileCount ++;
|
2005-06-23 21:04:18 +04:00
|
|
|
if ( !this->StartCoverageLogFile(covLogFile, logFileCount) )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2006-10-06 01:53:09 +04:00
|
|
|
cmSystemTools::ChangeDirectory(currentDirectory.c_str());
|
2005-01-27 23:54:47 +03:00
|
|
|
return -1;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2004-10-18 03:45:36 +04:00
|
|
|
}
|
|
|
|
const std::string fullFileName = fileIterator->first;
|
2006-03-09 19:17:10 +03:00
|
|
|
const std::string fileName
|
|
|
|
= cmSystemTools::GetFilenameName(fullFileName.c_str());
|
|
|
|
std::string fullFilePath
|
|
|
|
= cmSystemTools::GetFilenamePath(fullFileName.c_str());
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Process file: "
|
2006-03-09 19:17:10 +03:00
|
|
|
<< fullFileName << std::endl);
|
2004-10-18 03:45:36 +04:00
|
|
|
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(fullFilePath);
|
2004-09-09 16:41:05 +04:00
|
|
|
|
2004-10-18 03:45:36 +04:00
|
|
|
if ( !cmSystemTools::FileExists(fullFileName.c_str()) )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot find file: "
|
2006-03-09 19:17:10 +03:00
|
|
|
<< fullFileName.c_str() << std::endl);
|
2004-10-18 03:45:36 +04:00
|
|
|
continue;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
|
|
|
|
2004-10-18 03:45:36 +04:00
|
|
|
bool shouldIDoCoverage
|
|
|
|
= this->ShouldIDoCoverage(fullFileName.c_str(),
|
2005-06-01 01:32:40 +04:00
|
|
|
sourceDir.c_str(), binaryDir.c_str());
|
2004-10-18 03:45:36 +04:00
|
|
|
if ( !shouldIDoCoverage )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2006-03-09 19:17:10 +03:00
|
|
|
".NoDartCoverage found, so skip coverage check for: "
|
2005-06-01 01:32:40 +04:00
|
|
|
<< fullFileName.c_str()
|
|
|
|
<< std::endl);
|
2004-09-09 16:41:05 +04:00
|
|
|
continue;
|
|
|
|
}
|
2004-10-18 03:45:36 +04:00
|
|
|
|
|
|
|
const singleFileCoverageVector& fcov = fileIterator->second;
|
|
|
|
covLogFile << "\t<File Name=\""
|
2006-03-10 23:03:09 +03:00
|
|
|
<< this->CTest->MakeXMLSafe(fileName.c_str())
|
|
|
|
<< "\" FullPath=\"" << this->CTest->MakeXMLSafe(
|
|
|
|
this->CTest->GetShortPathToFile(
|
2004-10-18 06:47:44 +04:00
|
|
|
fileIterator->first.c_str())) << "\">" << std::endl
|
2004-10-18 03:45:36 +04:00
|
|
|
<< "\t\t<Report>" << std::endl;
|
|
|
|
|
|
|
|
std::ifstream ifs(fullFileName.c_str());
|
|
|
|
if ( !ifs)
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2005-07-14 22:15:51 +04:00
|
|
|
cmOStringStream ostr;
|
|
|
|
ostr << "Cannot open source file: " << fullFileName.c_str();
|
|
|
|
errorsWhileAccumulating.push_back(ostr.str());
|
2004-10-18 03:45:36 +04:00
|
|
|
error ++;
|
|
|
|
continue;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2004-10-18 03:45:36 +04:00
|
|
|
|
|
|
|
int tested = 0;
|
|
|
|
int untested = 0;
|
|
|
|
|
|
|
|
singleFileCoverageVector::size_type cc;
|
|
|
|
std::string line;
|
|
|
|
for ( cc= 0; cc < fcov.size(); cc ++ )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2004-10-18 03:45:36 +04:00
|
|
|
if ( !cmSystemTools::GetLineFromStream(ifs, line) )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2005-07-14 22:15:51 +04:00
|
|
|
cmOStringStream ostr;
|
2006-03-09 19:17:10 +03:00
|
|
|
ostr << "Problem reading source file: " << fullFileName.c_str()
|
|
|
|
<< " line:" << cc;
|
2005-07-14 22:15:51 +04:00
|
|
|
errorsWhileAccumulating.push_back(ostr.str());
|
2004-10-18 03:45:36 +04:00
|
|
|
error ++;
|
|
|
|
break;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
covLogFile << "\t\t<Line Number=\"" << cc << "\" Count=\"" << fcov[cc]
|
|
|
|
<< "\">"
|
2006-03-10 23:03:09 +03:00
|
|
|
<< this->CTest->MakeXMLSafe(line.c_str()) << "</Line>" << std::endl;
|
2004-10-18 03:45:36 +04:00
|
|
|
if ( fcov[cc] == 0 )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2004-10-18 03:45:36 +04:00
|
|
|
untested ++;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2004-10-18 03:45:36 +04:00
|
|
|
else if ( fcov[cc] > 0 )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2004-10-18 03:45:36 +04:00
|
|
|
tested ++;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
|
|
|
}
|
2004-10-18 03:45:36 +04:00
|
|
|
if ( cmSystemTools::GetLineFromStream(ifs, line) )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2005-07-14 22:15:51 +04:00
|
|
|
cmOStringStream ostr;
|
|
|
|
ostr << "Looks like there are more lines in the file: " << line;
|
|
|
|
errorsWhileAccumulating.push_back(ostr.str());
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
|
|
|
float cper = 0;
|
|
|
|
float cmet = 0;
|
2004-10-18 03:45:36 +04:00
|
|
|
if ( tested + untested > 0 )
|
2004-09-09 16:41:05 +04:00
|
|
|
{
|
2004-10-18 03:45:36 +04:00
|
|
|
cper = (100 * SAFEDIV(static_cast<float>(tested),
|
|
|
|
static_cast<float>(tested + untested)));
|
|
|
|
cmet = ( SAFEDIV(static_cast<float>(tested + 10),
|
|
|
|
static_cast<float>(tested + untested + 10)));
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2004-10-18 03:45:36 +04:00
|
|
|
total_tested += tested;
|
|
|
|
total_untested += untested;
|
|
|
|
covLogFile << "\t\t</Report>" << std::endl
|
|
|
|
<< "\t</File>" << std::endl;
|
2006-03-10 23:03:09 +03:00
|
|
|
covSumFile << "\t<File Name=\"" << this->CTest->MakeXMLSafe(fileName)
|
|
|
|
<< "\" FullPath=\"" << this->CTest->MakeXMLSafe(
|
|
|
|
this->CTest->GetShortPathToFile(fullFileName.c_str()))
|
2004-09-09 16:41:05 +04:00
|
|
|
<< "\" Covered=\"" << (cmet>0?"true":"false") << "\">\n"
|
2004-10-18 03:45:36 +04:00
|
|
|
<< "\t\t<LOCTested>" << tested << "</LOCTested>\n"
|
|
|
|
<< "\t\t<LOCUnTested>" << untested << "</LOCUnTested>\n"
|
2004-09-09 16:41:05 +04:00
|
|
|
<< "\t\t<PercentCoverage>";
|
2004-10-18 03:45:36 +04:00
|
|
|
covSumFile.setf(std::ios::fixed, std::ios::floatfield);
|
|
|
|
covSumFile.precision(2);
|
|
|
|
covSumFile << (cper) << "</PercentCoverage>\n"
|
2004-09-09 16:41:05 +04:00
|
|
|
<< "\t\t<CoverageMetric>";
|
2004-10-18 03:45:36 +04:00
|
|
|
covSumFile.setf(std::ios::fixed, std::ios::floatfield);
|
|
|
|
covSumFile.precision(2);
|
|
|
|
covSumFile << (cmet) << "</CoverageMetric>\n"
|
2004-09-09 16:41:05 +04:00
|
|
|
<< "\t</File>" << std::endl;
|
2004-10-18 03:45:36 +04:00
|
|
|
cnt ++;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2005-06-23 21:04:18 +04:00
|
|
|
this->EndCoverageLogFile(covLogFile, logFileCount);
|
2004-09-09 16:41:05 +04:00
|
|
|
|
2005-07-14 22:15:51 +04:00
|
|
|
if ( errorsWhileAccumulating.size() > 0 )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, std::endl);
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Error(s) while acumulating results:" << std::endl);
|
2005-07-14 22:15:51 +04:00
|
|
|
std::vector<std::string>::iterator erIt;
|
|
|
|
for ( erIt = errorsWhileAccumulating.begin();
|
|
|
|
erIt != errorsWhileAccumulating.end();
|
|
|
|
++ erIt )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
" " << erIt->c_str() << std::endl);
|
2005-07-14 22:15:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-09 16:41:05 +04:00
|
|
|
int total_lines = total_tested + total_untested;
|
|
|
|
float percent_coverage = 100 * SAFEDIV(static_cast<float>(total_tested),
|
|
|
|
static_cast<float>(total_lines));
|
|
|
|
if ( total_lines == 0 )
|
|
|
|
{
|
|
|
|
percent_coverage = 0;
|
|
|
|
}
|
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
std::string end_time = this->CTest->CurrentTime();
|
2004-09-09 16:41:05 +04:00
|
|
|
|
2004-10-18 03:45:36 +04:00
|
|
|
covSumFile << "\t<LOCTested>" << total_tested << "</LOCTested>\n"
|
|
|
|
<< "\t<LOCUntested>" << total_untested << "</LOCUntested>\n"
|
|
|
|
<< "\t<LOC>" << total_lines << "</LOC>\n"
|
|
|
|
<< "\t<PercentCoverage>";
|
|
|
|
covSumFile.setf(std::ios::fixed, std::ios::floatfield);
|
|
|
|
covSumFile.precision(2);
|
|
|
|
covSumFile << (percent_coverage)<< "</PercentCoverage>\n"
|
|
|
|
<< "\t<EndDateTime>" << end_time << "</EndDateTime>\n";
|
2006-03-09 19:17:10 +03:00
|
|
|
covSumFile << "<ElapsedMinutes>" <<
|
2004-09-09 16:41:05 +04:00
|
|
|
static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
|
2004-10-18 03:45:36 +04:00
|
|
|
<< "</ElapsedMinutes>"
|
|
|
|
<< "</Coverage>" << std::endl;
|
2006-03-10 23:03:09 +03:00
|
|
|
this->CTest->EndXML(covSumFile);
|
2004-09-09 16:41:05 +04:00
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "\tCovered LOC: "
|
2006-03-09 19:17:10 +03:00
|
|
|
<< total_tested << std::endl
|
2004-10-18 03:45:36 +04:00
|
|
|
<< "\tNot covered LOC: " << total_untested << std::endl
|
|
|
|
<< "\tTotal LOC: " << total_lines << std::endl
|
2006-03-09 19:17:10 +03:00
|
|
|
<< "\tPercentage Coverage: "
|
2005-06-01 01:32:40 +04:00
|
|
|
<< std::setiosflags(std::ios::fixed)
|
|
|
|
<< std::setprecision(2)
|
|
|
|
<< (percent_coverage) << "%" << std::endl);
|
2004-09-09 16:41:05 +04:00
|
|
|
|
2005-06-14 19:42:53 +04:00
|
|
|
ofs << "\tCovered LOC: " << total_tested << std::endl
|
|
|
|
<< "\tNot covered LOC: " << total_untested << std::endl
|
|
|
|
<< "\tTotal LOC: " << total_lines << std::endl
|
2006-03-09 19:17:10 +03:00
|
|
|
<< "\tPercentage Coverage: "
|
2005-06-14 19:42:53 +04:00
|
|
|
<< std::setiosflags(std::ios::fixed)
|
|
|
|
<< std::setprecision(2)
|
|
|
|
<< (percent_coverage) << "%" << std::endl;
|
|
|
|
|
2004-10-18 03:45:36 +04:00
|
|
|
cmSystemTools::ChangeDirectory(currentDirectory.c_str());
|
2004-09-09 16:41:05 +04:00
|
|
|
|
2005-01-27 23:54:47 +03:00
|
|
|
if ( error )
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2004-09-09 16:41:05 +04:00
|
|
|
}
|
2005-07-14 21:25:40 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void cmCTestCoverageHandler::PopulateCustomVectors(cmMakefile *mf)
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2006-03-09 19:17:10 +03:00
|
|
|
" Add coverage exclude regular expressions." << std::endl);
|
2006-03-29 21:01:24 +04:00
|
|
|
this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_COVERAGE_EXCLUDE",
|
2006-03-10 23:03:09 +03:00
|
|
|
this->CustomCoverageExclude);
|
2005-07-14 22:15:51 +04:00
|
|
|
std::vector<cmStdString>::iterator it;
|
2006-03-10 23:03:09 +03:00
|
|
|
for ( it = this->CustomCoverageExclude.begin();
|
|
|
|
it != this->CustomCoverageExclude.end();
|
2005-07-14 22:15:51 +04:00
|
|
|
++ it )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Add coverage exclude: "
|
2006-03-09 19:17:10 +03:00
|
|
|
<< it->c_str() << std::endl);
|
2005-07-14 22:15:51 +04:00
|
|
|
}
|
2005-07-14 21:25:40 +04:00
|
|
|
}
|