From 93c0384f48899d2443a37027dc843d98ea28cd05 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Fri, 8 Jun 2007 12:29:40 -0400 Subject: [PATCH] ENH: use new covbr that does not stop on error --- Source/CTest/cmCTestCoverageHandler.cxx | 200 ++++++++++++++++-------- Source/CTest/cmCTestCoverageHandler.h | 1 + 2 files changed, 139 insertions(+), 62 deletions(-) diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index bfb9e58c9..2090b2f09 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -37,6 +37,7 @@ public: { this->Process = cmsysProcess_New(); this->PipeState = -1; + this->TimeOut = -1; } ~cmCTestRunProcess() { @@ -55,7 +56,10 @@ public: } void AddArgument(const char* arg) { - this->CommandLineStrings.push_back(arg); + if(arg) + { + this->CommandLineStrings.push_back(arg); + } } void SetWorkingDirectory(const char* dir) { @@ -326,6 +330,18 @@ int cmCTestCoverageHandler::ProcessHandler() cont.BinaryDir = binaryDir; cont.OFS = &ofs; + // setup the regex exclude stuff + this->CustomCoverageExcludeRegex.empty(); + std::vector::iterator rexIt; + for ( rexIt = this->CustomCoverageExclude.begin(); + rexIt != this->CustomCoverageExclude.end(); + ++ rexIt ) + { + this->CustomCoverageExcludeRegex.push_back( + cmsys::RegularExpression(rexIt->c_str())); + } + + if(this->HandleBullseyeCoverage(&cont)) { return cont.Error; @@ -665,16 +681,6 @@ int cmCTestCoverageHandler::HandleGCovCoverage( cmSystemTools::MakeDirectory(tempDir.c_str()); cmSystemTools::ChangeDirectory(tempDir.c_str()); - this->CustomCoverageExcludeRegex.empty(); - std::vector::iterator rexIt; - for ( rexIt = this->CustomCoverageExclude.begin(); - rexIt != this->CustomCoverageExclude.end(); - ++ rexIt ) - { - this->CustomCoverageExcludeRegex.push_back( - cmsys::RegularExpression(rexIt->c_str())); - } - int gcovStyle = 0; std::set missingFiles; @@ -1176,10 +1182,11 @@ namespace " * The slash / means this probe is excluded from summary results. ", 0}; } - + //---------------------------------------------------------------------- int cmCTestCoverageHandler::RunBullseyeCoverageBranch( cmCTestCoverageHandlerContainer* cont, + std::set& coveredFileNames, std::vector& files, std::vector& filesFullPath) { @@ -1196,67 +1203,125 @@ int cmCTestCoverageHandler::RunBullseyeCoverageBranch( { return -1; } - int count =0; // keep count of the number of files - // loop over all files + // for each file run covbr on that file to get the coverage + // information for that file + std::string outputFile; + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + "run covbr: " + << std::endl); + + if(!this->RunBullseyeCommand(cont, "covbr", 0, outputFile)) + { + cmCTestLog(this->CTest, ERROR_MESSAGE, "error running covbr for." << "\n"); + return -1; + } + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + "covbr output in " << outputFile + << std::endl); + // open the output file + std::ifstream fin(outputFile.c_str()); + if(!fin) + { + cmCTestLog(this->CTest, ERROR_MESSAGE, + "Cannot open coverage file: " << + outputFile.c_str() << std::endl); + return 0; + } + std::map fileMap; std::vector::iterator fp = filesFullPath.begin(); - for(std::vector::iterator f = files.begin(); + for(std::vector::iterator f = files.begin(); f != files.end(); ++f, ++fp) { - // only allow 100 files in each log file - if ( count != 0 && count % 100 == 0 ) + fileMap[*f] = *fp; + } + + int count =0; // keep count of the number of files + // Now parse each line from the bullseye cov log file + std::string lineIn; + bool valid = false; // are we in a valid output file + int line = 0; // line of the current file + cmStdString file; + while(cmSystemTools::GetLineFromStream(fin, lineIn)) + { + bool startFile = false; + if(lineIn.size() > 1 && lineIn[lineIn.size()-1] == ':') { - this->EndCoverageLogFile(covLogFile, logFileCount); - logFileCount ++; - if ( !this->StartCoverageLogFile(covLogFile, logFileCount) ) + file = lineIn.substr(0, lineIn.size()-1); + if(coveredFileNames.find(file) != coveredFileNames.end()) { - return -1; + startFile = true; } } - // for each file run covbr on that file to get the coverage - // information for that file - std::string outputFile; - if(!this->RunBullseyeCommand(cont, "covbr", f->c_str(), outputFile)) + if(startFile) { - cmCTestLog(this->CTest, ERROR_MESSAGE, "error running covbr for:" << - f->c_str() << "\n"); - continue; + // if we are in a valid file close it because a new one started + if(valid) + { + covLogFile << "\t\t" << std::endl + << "\t" << std::endl; + } + // only allow 100 files in each log file + if ( count != 0 && count % 100 == 0 ) + { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + "start a new log file: " + << count + << std::endl); + this->EndCoverageLogFile(covLogFile, logFileCount); + logFileCount ++; + if ( !this->StartCoverageLogFile(covLogFile, logFileCount) ) + { + return -1; + } + count++; // move on one + } + std::map::iterator + i = fileMap.find(file); + // if the file should be covered write out the header for that file + if(i != fileMap.end()) + { + // we have a new file so count it in the output + count++; + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + "Produce coverage for file: " + << file.c_str() << " " << count + << std::endl); + // start the file output + covLogFile << "\tCTest->MakeXMLSafe(file.c_str()) + << "\" FullPath=\"" << this->CTest->MakeXMLSafe( + this->CTest->GetShortPathToFile( + i->second.c_str())) << "\">" << std::endl + << "\t\t" << std::endl; + // write the bullseye header + line =0; + for(int k =0; bullseyeHelp[k] != 0; ++k) + { + covLogFile << "\t\t" + << this->CTest->MakeXMLSafe(bullseyeHelp[k]) + << "" << std::endl; + line++; + } + valid = true; // we are in a valid file section + } + else + { + // this is not a file that we want coverage for + valid = false; + } } - // open the output file - std::ifstream fin(outputFile.c_str()); - if(!fin) - { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot open coverage file: " << - outputFile.c_str() << std::endl); - return 0; - } - // we have good data so we can count it - count++; - // start the file output - covLogFile << "\tCTest->MakeXMLSafe(f->c_str()) - << "\" FullPath=\"" << this->CTest->MakeXMLSafe( - this->CTest->GetShortPathToFile( - fp->c_str())) << "\">" << std::endl - << "\t\t" << std::endl; - // write the bullseye header - int line =0; - for(int k =0; bullseyeHelp[k] != 0; ++k) - { - covLogFile << "\t\t" - << this->CTest->MakeXMLSafe(bullseyeHelp[k]) - << "" << std::endl; - line++; - } - // Now copy each line from the bullseye file into the cov log file - std::string lineIn; - while(cmSystemTools::GetLineFromStream(fin, lineIn)) + // we are not at a start file, and we are in a valid file output the line + else if(valid) { covLogFile << "\t\t" << this->CTest->MakeXMLSafe(lineIn.c_str()) << "" << std::endl; line++; } + } + // if we ran out of lines a valid file then close that file + if(valid) + { covLogFile << "\t\t" << std::endl << "\t" << std::endl; } @@ -1277,18 +1342,26 @@ int cmCTestCoverageHandler::RunBullseyeCommand( cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot find :" << cmd << "\n"); return 0; } - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Run : " << program.c_str() << " " << arg << "\n"); + if(arg) + { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + "Run : " << program.c_str() << " " << arg << "\n"); + } + else + { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + "Run : " << program.c_str() << "\n"); + } // create a process object and start it cmCTestRunProcess runCoverageSrc; runCoverageSrc.SetCommand(program.c_str()); runCoverageSrc.AddArgument(arg); std::string stdoutFile = cont->BinaryDir + "/Testing/Temporary/"; stdoutFile += this->GetCTestInstance()->GetCurrentTag(); - stdoutFile + "-"; + stdoutFile += "-"; stdoutFile += cmd; std::string stderrFile = stdoutFile; - stdoutFile + ".stdout"; + stdoutFile += ".stdout"; stderrFile += ".stderr"; runCoverageSrc.SetStdoutFile(stdoutFile.c_str()); runCoverageSrc.SetStderrFile(stderrFile.c_str()); @@ -1363,6 +1436,7 @@ int cmCTestCoverageHandler::RunBullseyeSourceSummary( outputFile.c_str() << std::endl); return 0; } + std::set coveredFileNames; while(cmSystemTools::GetLineFromStream(fin, stdline)) { // if we have a line of output from stdout @@ -1383,6 +1457,7 @@ int cmCTestCoverageHandler::RunBullseyeSourceSummary( continue; } std::string file = sourceFile; + coveredFileNames.insert(file); if(!cmSystemTools::FileIsFullPath(sourceFile.c_str())) { // file will be relative to the binary dir @@ -1478,6 +1553,7 @@ int cmCTestCoverageHandler::RunBullseyeSourceSummary( this->CTest->EndXML(covSumFile); // Now create the coverage information for each file return this->RunBullseyeCoverageBranch(cont, + coveredFileNames, coveredFiles, coveredFilesFullPath); } diff --git a/Source/CTest/cmCTestCoverageHandler.h b/Source/CTest/cmCTestCoverageHandler.h index 99b85d3a5..658ab7845 100644 --- a/Source/CTest/cmCTestCoverageHandler.h +++ b/Source/CTest/cmCTestCoverageHandler.h @@ -63,6 +63,7 @@ private: int HandleBullseyeCoverage(cmCTestCoverageHandlerContainer* cont); int RunBullseyeSourceSummary(cmCTestCoverageHandlerContainer* cont); int RunBullseyeCoverageBranch(cmCTestCoverageHandlerContainer* cont, + std::set& coveredFileNames, std::vector& files, std::vector& filesFullPath); int RunBullseyeCommand(