cmCTestCoverageHandler: Port to cmXMLWriter

This commit is contained in:
Daniel Pfeifer 2015-05-24 21:18:40 +02:00 committed by Brad King
parent 82455a9d3a
commit 8fbc509a48
2 changed files with 151 additions and 156 deletions

View File

@ -22,7 +22,7 @@
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmSystemTools.h" #include "cmSystemTools.h"
#include "cmGeneratedFileStream.h" #include "cmGeneratedFileStream.h"
#include "cmXMLSafe.h" #include "cmXMLWriter.h"
#include <cmsys/Process.h> #include <cmsys/Process.h>
#include <cmsys/RegularExpression.hxx> #include <cmsys/RegularExpression.hxx>
@ -185,14 +185,6 @@ bool cmCTestCoverageHandler::StartCoverageLogFile(
<< covLogFilename << std::endl); << covLogFilename << std::endl);
return false; return false;
} }
std::string local_start_time = this->CTest->CurrentTime();
this->CTest->StartXML(covLogFile, this->AppendXML);
covLogFile << "<CoverageLog>" << std::endl
<< "\t<StartDateTime>" << local_start_time << "</StartDateTime>"
<< "\t<StartTime>"
<< static_cast<unsigned int>(cmSystemTools::GetTime())
<< "</StartTime>"
<< std::endl;
return true; return true;
} }
@ -200,13 +192,6 @@ bool cmCTestCoverageHandler::StartCoverageLogFile(
void cmCTestCoverageHandler::EndCoverageLogFile(cmGeneratedFileStream& ostr, void cmCTestCoverageHandler::EndCoverageLogFile(cmGeneratedFileStream& ostr,
int logFileCount) int logFileCount)
{ {
std::string local_end_time = this->CTest->CurrentTime();
ostr << "\t<EndDateTime>" << local_end_time << "</EndDateTime>" << std::endl
<< "\t<EndTime>" <<
static_cast<unsigned int>(cmSystemTools::GetTime())
<< "</EndTime>" << std::endl
<< "</CoverageLog>" << std::endl;
this->CTest->EndXML(ostr);
char covLogFilename[1024]; char covLogFilename[1024];
sprintf(covLogFilename, "CoverageLog-%d.xml", logFileCount); sprintf(covLogFilename, "CoverageLog-%d.xml", logFileCount);
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Close file: " cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Close file: "
@ -214,6 +199,25 @@ void cmCTestCoverageHandler::EndCoverageLogFile(cmGeneratedFileStream& ostr,
ostr.Close(); ostr.Close();
} }
//----------------------------------------------------------------------
void cmCTestCoverageHandler::StartCoverageLogXML(cmXMLWriter& xml)
{
this->CTest->StartXML(xml, this->AppendXML);
xml.StartElement("CoverageLog");
xml.Element("StartDateTime", this->CTest->CurrentTime());
xml.Element("StartTime",
static_cast<unsigned int>(cmSystemTools::GetTime()));
}
//----------------------------------------------------------------------
void cmCTestCoverageHandler::EndCoverageLogXML(cmXMLWriter& xml)
{
xml.Element("EndDateTime", this->CTest->CurrentTime());
xml.Element("EndTime", static_cast<unsigned int>(cmSystemTools::GetTime()));
xml.EndElement(); // CoverageLog
this->CTest->EndXML(xml);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool cmCTestCoverageHandler::ShouldIDoCoverage(const char* file, bool cmCTestCoverageHandler::ShouldIDoCoverage(const char* file,
const char* srcDir, const char* srcDir,
@ -451,6 +455,8 @@ int cmCTestCoverageHandler::ProcessHandler()
} }
cmGeneratedFileStream covSumFile; cmGeneratedFileStream covSumFile;
cmGeneratedFileStream covLogFile; cmGeneratedFileStream covLogFile;
cmXMLWriter covSumXML(covSumFile);
cmXMLWriter covLogXML(covLogFile);
if(!this->StartResultingXML(cmCTest::PartCoverage, "Coverage", covSumFile)) if(!this->StartResultingXML(cmCTest::PartCoverage, "Coverage", covSumFile))
{ {
@ -458,20 +464,21 @@ int cmCTestCoverageHandler::ProcessHandler()
"Cannot open coverage summary file." << std::endl); "Cannot open coverage summary file." << std::endl);
return -1; return -1;
} }
covSumFile.setf(std::ios::fixed, std::ios::floatfield);
covSumFile.precision(2);
this->CTest->StartXML(covSumFile, this->AppendXML); this->CTest->StartXML(covSumXML, this->AppendXML);
// Produce output xml files // Produce output xml files
covSumFile << "<Coverage>" << std::endl covSumXML.StartElement("Coverage");
<< "\t<StartDateTime>" << coverage_start_time << "</StartDateTime>" covSumXML.Element("StartDateTime", coverage_start_time);
<< std::endl covSumXML.Element("StartTime", coverage_start_time_time);
<< "\t<StartTime>" << coverage_start_time_time << "</StartTime>"
<< std::endl;
int logFileCount = 0; int logFileCount = 0;
if ( !this->StartCoverageLogFile(covLogFile, logFileCount) ) if ( !this->StartCoverageLogFile(covLogFile, logFileCount) )
{ {
return -1; return -1;
} }
this->StartCoverageLogXML(covLogXML);
cmCTestCoverageHandlerContainer::TotalCoverageMap::iterator fileIterator; cmCTestCoverageHandlerContainer::TotalCoverageMap::iterator fileIterator;
int cnt = 0; int cnt = 0;
long total_tested = 0; long total_tested = 0;
@ -528,12 +535,14 @@ int cmCTestCoverageHandler::ProcessHandler()
if ( ++cnt % 100 == 0 ) if ( ++cnt % 100 == 0 )
{ {
this->EndCoverageLogXML(covLogXML);
this->EndCoverageLogFile(covLogFile, logFileCount); this->EndCoverageLogFile(covLogFile, logFileCount);
logFileCount ++; logFileCount ++;
if ( !this->StartCoverageLogFile(covLogFile, logFileCount) ) if ( !this->StartCoverageLogFile(covLogFile, logFileCount) )
{ {
return -1; return -1;
} }
this->StartCoverageLogXML(covLogXML);
} }
const std::string fileName const std::string fileName
@ -542,9 +551,10 @@ int cmCTestCoverageHandler::ProcessHandler()
this->CTest->GetShortPathToFile(fullFileName.c_str()); this->CTest->GetShortPathToFile(fullFileName.c_str());
const cmCTestCoverageHandlerContainer::SingleFileCoverageVector& fcov const cmCTestCoverageHandlerContainer::SingleFileCoverageVector& fcov
= fileIterator->second; = fileIterator->second;
covLogFile << "\t<File Name=\"" << cmXMLSafe(fileName) covLogXML.StartElement("File");
<< "\" FullPath=\"" << cmXMLSafe(shortFileName) << "\">\n" covLogXML.Attribute("Name", fileName);
<< "\t\t<Report>" << std::endl; covLogXML.Attribute("FullPath", shortFileName);
covLogXML.StartElement("Report");
cmsys::ifstream ifs(fullFileName.c_str()); cmsys::ifstream ifs(fullFileName.c_str());
if ( !ifs) if ( !ifs)
@ -576,9 +586,11 @@ int cmCTestCoverageHandler::ProcessHandler()
error ++; error ++;
break; break;
} }
covLogFile << "\t\t<Line Number=\"" << cc << "\" Count=\"" << fcov[cc] covLogXML.StartElement("Line");
<< "\">" covLogXML.Attribute("Number", cc);
<< cmXMLSafe(line) << "</Line>" << std::endl; covLogXML.Attribute("Count", fcov[cc]);
covLogXML.Content(line);
covLogXML.EndElement(); // Line
if ( fcov[cc] == 0 ) if ( fcov[cc] == 0 )
{ {
untested ++; untested ++;
@ -605,24 +617,19 @@ int cmCTestCoverageHandler::ProcessHandler()
} }
total_tested += tested; total_tested += tested;
total_untested += untested; total_untested += untested;
covLogFile << "\t\t</Report>" << std::endl covLogXML.EndElement(); // Report
<< "\t</File>" << std::endl; covLogXML.EndElement(); // File
covSumFile << "\t<File Name=\"" << cmXMLSafe(fileName) covSumXML.StartElement("File");
<< "\" FullPath=\"" << cmXMLSafe( covSumXML.Attribute("Name", fileName);
this->CTest->GetShortPathToFile(fullFileName.c_str())) covSumXML.Attribute("FullPath",
<< "\" Covered=\"" << (tested+untested > 0 ? "true":"false") << "\">\n" this->CTest->GetShortPathToFile(fullFileName.c_str()));
<< "\t\t<LOCTested>" << tested << "</LOCTested>\n" covSumXML.Attribute("Covered", tested + untested > 0 ? "true" : "false");
<< "\t\t<LOCUnTested>" << untested << "</LOCUnTested>\n" covSumXML.Element("LOCTested", tested);
<< "\t\t<PercentCoverage>"; covSumXML.Element("LOCUnTested", untested);
covSumFile.setf(std::ios::fixed, std::ios::floatfield); covSumXML.Element("PercentCoverage", cper);
covSumFile.precision(2); covSumXML.Element("CoverageMetric", cmet);
covSumFile << (cper) << "</PercentCoverage>\n" this->WriteXMLLabels(covSumXML, shortFileName);
<< "\t\t<CoverageMetric>"; covSumXML.EndElement(); // File
covSumFile.setf(std::ios::fixed, std::ios::floatfield);
covSumFile.precision(2);
covSumFile << (cmet) << "</CoverageMetric>\n";
this->WriteXMLLabels(covSumFile, shortFileName);
covSumFile << "\t</File>" << std::endl;
} }
//Handle all the files in the extra coverage globs that have no cov data //Handle all the files in the extra coverage globs that have no cov data
@ -632,9 +639,10 @@ int cmCTestCoverageHandler::ProcessHandler()
std::string fileName = cmSystemTools::GetFilenameName(*i); std::string fileName = cmSystemTools::GetFilenameName(*i);
std::string fullPath = cont.SourceDir + "/" + *i; std::string fullPath = cont.SourceDir + "/" + *i;
covLogFile << "\t<File Name=\"" << cmXMLSafe(fileName) covLogXML.StartElement("File");
<< "\" FullPath=\"" << cmXMLSafe(*i) << "\">\n" covLogXML.Attribute("Name", fileName);
<< "\t\t<Report>" << std::endl; covLogXML.Attribute("FullPath", *i);
covLogXML.StartElement("Report");
cmsys::ifstream ifs(fullPath.c_str()); cmsys::ifstream ifs(fullPath.c_str());
if (!ifs) if (!ifs)
@ -651,24 +659,30 @@ int cmCTestCoverageHandler::ProcessHandler()
"Actually performing coverage for: " << *i << std::endl, this->Quiet); "Actually performing coverage for: " << *i << std::endl, this->Quiet);
while (cmSystemTools::GetLineFromStream(ifs, line)) while (cmSystemTools::GetLineFromStream(ifs, line))
{ {
covLogFile << "\t\t<Line Number=\"" << untested << "\" Count=\"0\">" covLogXML.StartElement("Line");
<< cmXMLSafe(line) << "</Line>" << std::endl; covLogXML.Attribute("Number", untested);
covLogXML.Attribute("Count", 0);
covLogXML.Content(line);
covLogXML.EndElement(); // Line
untested ++; untested ++;
} }
covLogFile << "\t\t</Report>\n\t</File>" << std::endl; covLogXML.EndElement(); // Report
covLogXML.EndElement(); // File
total_untested += untested; total_untested += untested;
covSumFile << "\t<File Name=\"" << cmXMLSafe(fileName) covSumXML.StartElement("File");
<< "\" FullPath=\"" << cmXMLSafe(i->c_str()) covSumXML.Attribute("Name", fileName);
<< "\" Covered=\"true\">\n" covSumXML.Attribute("FullPath", *i);
<< "\t\t<LOCTested>0</LOCTested>\n" covSumXML.Attribute("Covered", "true");
<< "\t\t<LOCUnTested>" << untested << "</LOCUnTested>\n" covSumXML.Element("LOCTested", 0);
<< "\t\t<PercentCoverage>0</PercentCoverage>\n" covSumXML.Element("LOCUnTested", untested);
<< "\t\t<CoverageMetric>0</CoverageMetric>\n"; covSumXML.Element("PercentCoverage", 0);
this->WriteXMLLabels(covSumFile, *i); covSumXML.Element("CoverageMetric", 0);
covSumFile << "\t</File>" << std::endl; this->WriteXMLLabels(covSumXML, *i);
covSumXML.EndElement(); // File
} }
this->EndCoverageLogXML(covLogXML);
this->EndCoverageLogFile(covLogFile, logFileCount); this->EndCoverageLogFile(covLogFile, logFileCount);
if (!errorsWhileAccumulating.empty()) if (!errorsWhileAccumulating.empty())
@ -696,22 +710,17 @@ int cmCTestCoverageHandler::ProcessHandler()
std::string end_time = this->CTest->CurrentTime(); std::string end_time = this->CTest->CurrentTime();
covSumFile << "\t<LOCTested>" << total_tested << "</LOCTested>\n" covSumXML.Element("LOCTested", total_tested);
<< "\t<LOCUntested>" << total_untested << "</LOCUntested>\n" covSumXML.Element("LOCUntested", total_untested);
<< "\t<LOC>" << total_lines << "</LOC>\n" covSumXML.Element("LOC", total_lines);
<< "\t<PercentCoverage>"; covSumXML.Element("PercentCoverage", percent_coverage);
covSumFile.setf(std::ios::fixed, std::ios::floatfield); covSumXML.Element("EndDateTime", end_time);
covSumFile.precision(2); covSumXML.Element("EndTime",
covSumFile << (percent_coverage)<< "</PercentCoverage>\n" static_cast<unsigned int>(cmSystemTools::GetTime()));
<< "\t<EndDateTime>" << end_time << "</EndDateTime>\n" covSumXML.Element("ElapsedMinutes",
<< "\t<EndTime>" << static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0);
static_cast<unsigned int>(cmSystemTools::GetTime()) covSumXML.EndElement(); // Coverage
<< "</EndTime>\n"; this->CTest->EndXML(covSumXML);
covSumFile << "<ElapsedMinutes>" <<
static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
<< "</ElapsedMinutes>"
<< "</Coverage>" << std::endl;
this->CTest->EndXML(covSumFile);
cmCTestLog(this->CTest, HANDLER_OUTPUT, "" << std::endl cmCTestLog(this->CTest, HANDLER_OUTPUT, "" << std::endl
<< "\tCovered LOC: " << "\tCovered LOC: "
@ -1952,11 +1961,13 @@ int cmCTestCoverageHandler::RunBullseyeCoverageBranch(
} }
// create the output stream for the CoverageLog-N.xml file // create the output stream for the CoverageLog-N.xml file
cmGeneratedFileStream covLogFile; cmGeneratedFileStream covLogFile;
cmXMLWriter covLogXML(covLogFile);
int logFileCount = 0; int logFileCount = 0;
if ( !this->StartCoverageLogFile(covLogFile, logFileCount) ) if ( !this->StartCoverageLogFile(covLogFile, logFileCount) )
{ {
return -1; return -1;
} }
this->StartCoverageLogXML(covLogXML);
// for each file run covbr on that file to get the coverage // for each file run covbr on that file to get the coverage
// information for that file // information for that file
std::string outputFile; std::string outputFile;
@ -2009,20 +2020,22 @@ int cmCTestCoverageHandler::RunBullseyeCoverageBranch(
// if we are in a valid file close it because a new one started // if we are in a valid file close it because a new one started
if(valid) if(valid)
{ {
covLogFile << "\t\t</Report>" << std::endl covLogXML.EndElement(); // Report
<< "\t</File>" << std::endl; covLogXML.EndElement(); // File
} }
// only allow 100 files in each log file // only allow 100 files in each log file
if ( count != 0 && count % 100 == 0 ) if ( count != 0 && count % 100 == 0 )
{ {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"start a new log file: " << count << std::endl, this->Quiet); "start a new log file: " << count << std::endl, this->Quiet);
this->EndCoverageLogXML(covLogXML);
this->EndCoverageLogFile(covLogFile, logFileCount); this->EndCoverageLogFile(covLogFile, logFileCount);
logFileCount ++; logFileCount ++;
if ( !this->StartCoverageLogFile(covLogFile, logFileCount) ) if ( !this->StartCoverageLogFile(covLogFile, logFileCount) )
{ {
return -1; return -1;
} }
this->StartCoverageLogXML(covLogXML);
count++; // move on one count++; // move on one
} }
std::map<std::string, std::string>::iterator std::map<std::string, std::string>::iterator
@ -2036,19 +2049,20 @@ int cmCTestCoverageHandler::RunBullseyeCoverageBranch(
"Produce coverage for file: " << file << " " << count "Produce coverage for file: " << file << " " << count
<< std::endl, this->Quiet); << std::endl, this->Quiet);
// start the file output // start the file output
covLogFile << "\t<File Name=\"" covLogXML.StartElement("File");
<< cmXMLSafe(i->first) covLogXML.Attribute("Name", i->first);
<< "\" FullPath=\"" << cmXMLSafe( covLogXML.Attribute("FullPath",
this->CTest->GetShortPathToFile( this->CTest->GetShortPathToFile(i->second.c_str()));
i->second.c_str())) << "\">" << std::endl covLogXML.StartElement("Report");
<< "\t\t<Report>" << std::endl;
// write the bullseye header // write the bullseye header
line =0; line =0;
for(int k =0; bullseyeHelp[k] != 0; ++k) for(int k =0; bullseyeHelp[k] != 0; ++k)
{ {
covLogFile << "\t\t<Line Number=\"" << line << "\" Count=\"-1\">" covLogXML.StartElement("Line");
<< cmXMLSafe(bullseyeHelp[k]) covLogXML.Attribute("Number", line);
<< "</Line>" << std::endl; covLogXML.Attribute("Count", -1);
covLogXML.Content(bullseyeHelp[k]);
covLogXML.EndElement(); // Line
line++; line++;
} }
valid = true; // we are in a valid file section valid = true; // we are in a valid file section
@ -2062,18 +2076,21 @@ int cmCTestCoverageHandler::RunBullseyeCoverageBranch(
// we are not at a start file, and we are in a valid file output the line // we are not at a start file, and we are in a valid file output the line
else if(valid) else if(valid)
{ {
covLogFile << "\t\t<Line Number=\"" << line << "\" Count=\"-1\">" covLogXML.StartElement("Line");
<< cmXMLSafe(lineIn) covLogXML.Attribute("Number", line);
<< "</Line>" << std::endl; covLogXML.Attribute("Count", -1);
covLogXML.Content(lineIn);
covLogXML.EndElement(); // Line
line++; line++;
} }
} }
// if we ran out of lines a valid file then close that file // if we ran out of lines a valid file then close that file
if(valid) if(valid)
{ {
covLogFile << "\t\t</Report>" << std::endl covLogXML.EndElement(); // Report
<< "\t</File>" << std::endl; covLogXML.EndElement(); // File
} }
this->EndCoverageLogXML(covLogXML);
this->EndCoverageLogFile(covLogFile, logFileCount); this->EndCoverageLogFile(covLogFile, logFileCount);
return 1; return 1;
} }
@ -2143,23 +2160,20 @@ int cmCTestCoverageHandler::RunBullseyeSourceSummary(
std::ostream& tmpLog = *cont->OFS; std::ostream& tmpLog = *cont->OFS;
// copen the Coverage.xml file in the Testing directory // copen the Coverage.xml file in the Testing directory
cmGeneratedFileStream covSumFile; cmGeneratedFileStream covSumFile;
cmXMLWriter xml(covSumFile);
if(!this->StartResultingXML(cmCTest::PartCoverage, "Coverage", covSumFile)) if(!this->StartResultingXML(cmCTest::PartCoverage, "Coverage", covSumFile))
{ {
cmCTestLog(this->CTest, ERROR_MESSAGE, cmCTestLog(this->CTest, ERROR_MESSAGE,
"Cannot open coverage summary file." << std::endl); "Cannot open coverage summary file." << std::endl);
return 0; return 0;
} }
this->CTest->StartXML(covSumFile, this->AppendXML); this->CTest->StartXML(xml, this->AppendXML);
double elapsed_time_start = cmSystemTools::GetTime(); double elapsed_time_start = cmSystemTools::GetTime();
std::string coverage_start_time = this->CTest->CurrentTime(); std::string coverage_start_time = this->CTest->CurrentTime();
covSumFile << "<Coverage>" << std::endl xml.StartElement("Coverage");
<< "\t<StartDateTime>" xml.Element("StartDateTime", coverage_start_time);
<< coverage_start_time << "</StartDateTime>" xml.Element("StartTime",
<< std::endl static_cast<unsigned int>(cmSystemTools::GetTime()));
<< "\t<StartTime>"
<< static_cast<unsigned int>(cmSystemTools::GetTime())
<< "</StartTime>"
<< std::endl;
std::string stdline; std::string stdline;
std::string errline; std::string errline;
// expected output: // expected output:
@ -2271,58 +2285,35 @@ int cmCTestCoverageHandler::RunBullseyeSourceSummary(
tmpLog << "percentBranch: " << percentBranch << "\n"; tmpLog << "percentBranch: " << percentBranch << "\n";
tmpLog << "percentCoverage: " << percent_coverage << "\n"; tmpLog << "percentCoverage: " << percent_coverage << "\n";
tmpLog << "coverage metric: " << cmet << "\n"; tmpLog << "coverage metric: " << cmet << "\n";
covSumFile << "\t<File Name=\"" << cmXMLSafe(sourceFile) xml.StartElement("File");
<< "\" FullPath=\"" << cmXMLSafe(shortFileName) xml.Attribute("Name", sourceFile);
<< "\" Covered=\"" << (cmet>0?"true":"false") << "\">\n" xml.Attribute("FullPath", shortFileName);
<< "\t\t<BranchesTested>" xml.Attribute("Covered", cmet > 0 ? "true" : "false");
<< branchCovered xml.Element("BranchesTested", branchCovered);
<< "</BranchesTested>\n" xml.Element("BranchesUnTested", totalBranches - branchCovered);
<< "\t\t<BranchesUnTested>" xml.Element("FunctionsTested", functionsCalled);
<< totalBranches - branchCovered xml.Element("FunctionsUnTested", totalFunctions - functionsCalled);
<< "</BranchesUnTested>\n" // Hack for conversion of function to loc assume a function
<< "\t\t<FunctionsTested>" // has 100 lines of code
<< functionsCalled xml.Element("LOCTested", functionsCalled * 100);
<< "</FunctionsTested>\n" xml.Element("LOCUnTested", (totalFunctions - functionsCalled) * 100);
<< "\t\t<FunctionsUnTested>" xml.Element("PercentCoverage", cper);
<< totalFunctions - functionsCalled xml.Element("CoverageMetric", cmet);
<< "</FunctionsUnTested>\n" this->WriteXMLLabels(xml, shortFileName);
// Hack for conversion of function to loc assume a function xml.EndElement(); // File
// has 100 lines of code
<< "\t\t<LOCTested>" << functionsCalled *100
<< "</LOCTested>\n"
<< "\t\t<LOCUnTested>"
<< (totalFunctions - functionsCalled)*100
<< "</LOCUnTested>\n"
<< "\t\t<PercentCoverage>";
covSumFile.setf(std::ios::fixed, std::ios::floatfield);
covSumFile.precision(2);
covSumFile << (cper) << "</PercentCoverage>\n"
<< "\t\t<CoverageMetric>";
covSumFile.setf(std::ios::fixed, std::ios::floatfield);
covSumFile.precision(2);
covSumFile << (cmet) << "</CoverageMetric>\n";
this->WriteXMLLabels(covSumFile, shortFileName);
covSumFile << "\t</File>" << std::endl;
} }
} }
std::string end_time = this->CTest->CurrentTime(); std::string end_time = this->CTest->CurrentTime();
covSumFile << "\t<LOCTested>" << total_tested << "</LOCTested>\n" xml.Element("LOCTested", total_tested);
<< "\t<LOCUntested>" << total_untested << "</LOCUntested>\n" xml.Element("LOCUntested", total_untested);
<< "\t<LOC>" << total_functions << "</LOC>\n" xml.Element("LOC", total_functions);
<< "\t<PercentCoverage>"; xml.Element("PercentCoverage", SAFEDIV(percent_coverage, number_files));
covSumFile.setf(std::ios::fixed, std::ios::floatfield); xml.Element("EndDateTime", end_time);
covSumFile.precision(2); xml.Element("EndTime", static_cast<unsigned int>(cmSystemTools::GetTime()));
covSumFile xml.Element("ElapsedMinutes",
<< SAFEDIV(percent_coverage,number_files)<< "</PercentCoverage>\n" static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0);
<< "\t<EndDateTime>" << end_time << "</EndDateTime>\n" xml.EndElement(); // Coverage
<< "\t<EndTime>" << static_cast<unsigned int>(cmSystemTools::GetTime()) this->CTest->EndXML(xml);
<< "</EndTime>\n";
covSumFile
<< "<ElapsedMinutes>" <<
static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
<< "</ElapsedMinutes>"
<< "</Coverage>" << std::endl;
this->CTest->EndXML(covSumFile);
// Now create the coverage information for each file // Now create the coverage information for each file
return this->RunBullseyeCoverageBranch(cont, return this->RunBullseyeCoverageBranch(cont,
@ -2514,19 +2505,19 @@ void cmCTestCoverageHandler::LoadLabels(const char* dir)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void cmCTestCoverageHandler::WriteXMLLabels(std::ostream& os, void cmCTestCoverageHandler::WriteXMLLabels(cmXMLWriter& xml,
std::string const& source) std::string const& source)
{ {
LabelMapType::const_iterator li = this->SourceLabels.find(source); LabelMapType::const_iterator li = this->SourceLabels.find(source);
if(li != this->SourceLabels.end() && !li->second.empty()) if(li != this->SourceLabels.end() && !li->second.empty())
{ {
os << "\t\t<Labels>\n"; xml.StartElement("Labels");
for(LabelSet::const_iterator lsi = li->second.begin(); for(LabelSet::const_iterator lsi = li->second.begin();
lsi != li->second.end(); ++lsi) lsi != li->second.end(); ++lsi)
{ {
os << "\t\t\t<Label>" << cmXMLSafe(this->Labels[*lsi]) << "</Label>\n"; xml.Element("Label", this->Labels[*lsi]);
} }
os << "\t\t</Labels>\n"; xml.EndElement(); // Labels
} }
} }

View File

@ -20,6 +20,7 @@
#include <cmsys/RegularExpression.hxx> #include <cmsys/RegularExpression.hxx>
class cmGeneratedFileStream; class cmGeneratedFileStream;
class cmXMLWriter;
class cmCTestCoverageHandlerContainer class cmCTestCoverageHandlerContainer
{ {
public: public:
@ -65,6 +66,9 @@ private:
bool StartCoverageLogFile(cmGeneratedFileStream& ostr, int logFileCount); bool StartCoverageLogFile(cmGeneratedFileStream& ostr, int logFileCount);
void EndCoverageLogFile(cmGeneratedFileStream& ostr, int logFileCount); void EndCoverageLogFile(cmGeneratedFileStream& ostr, int logFileCount);
void StartCoverageLogXML(cmXMLWriter& xml);
void EndCoverageLogXML(cmXMLWriter& xml);
//! Handle coverage using GCC's GCov //! Handle coverage using GCC's GCov
int HandleGCovCoverage(cmCTestCoverageHandlerContainer* cont); int HandleGCovCoverage(cmCTestCoverageHandlerContainer* cont);
void FindGCovFiles(std::vector<std::string>& files); void FindGCovFiles(std::vector<std::string>& files);
@ -146,7 +150,7 @@ private:
// Label reading and writing methods. // Label reading and writing methods.
void LoadLabels(); void LoadLabels();
void LoadLabels(const char* dir); void LoadLabels(const char* dir);
void WriteXMLLabels(std::ostream& os, std::string const& source); void WriteXMLLabels(cmXMLWriter& xml, std::string const& source);
// Label-based filtering. // Label-based filtering.
std::set<int> LabelFilter; std::set<int> LabelFilter;