diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index 5fe8e44f9..520cd92e5 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -171,8 +171,8 @@ cmCTestBuildHandler::cmCTestBuildHandler() } else { - std::cout << "Problem Compiling regular expression: " - << cmCTestWarningErrorFileLine[cc].m_RegularExpressionString << std::endl; + cmCTestLog(m_CTest, ERROR, "Problem Compiling regular expression: " + << cmCTestWarningErrorFileLine[cc].m_RegularExpressionString << std::endl); } } } @@ -196,17 +196,17 @@ void cmCTestBuildHandler::PopulateCustomVectors(cmMakefile *mf) //functions and commented... int cmCTestBuildHandler::ProcessHandler() { - std::cout << "Build project" << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, "Build project" << std::endl); const std::string &makeCommand = m_CTest->GetCTestConfiguration("MakeCommand"); if ( makeCommand.size() == 0 ) { - std::cerr << "Cannot find MakeCommand key in the DartConfiguration.tcl" << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot find MakeCommand key in the DartConfiguration.tcl" << std::endl); return -1; } const std::string &buildDirectory = m_CTest->GetCTestConfiguration("BuildDirectory"); if ( buildDirectory.size() == 0 ) { - std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl); return -1; } @@ -214,7 +214,7 @@ int cmCTestBuildHandler::ProcessHandler() double elapsed_time_start = cmSystemTools::GetTime(); if ( !m_CTest->OpenOutputFile("Temporary", "LastBuild.log", ofs) ) { - std::cerr << "Cannot create LastBuild.log file" << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot create LastBuild.log file" << std::endl); } m_StartBuild = m_CTest->CurrentTime(); @@ -224,18 +224,17 @@ int cmCTestBuildHandler::ProcessHandler() if ( !m_CTest->GetShowOnly() ) { res = m_CTest->RunMakeCommand(makeCommand.c_str(), &output, - &retVal, buildDirectory.c_str(), - m_Verbose, 0, ofs); + &retVal, buildDirectory.c_str(), 0, ofs); } else { - std::cout << "Build with command: " << makeCommand << std::endl; + cmCTestLog(m_CTest, DEBUG, "Build with command: " << makeCommand << std::endl); } m_EndBuild = m_CTest->CurrentTime(); double elapsed_build_time = cmSystemTools::GetTime() - elapsed_time_start; if (res != cmsysProcess_State_Exited || retVal ) { - std::cerr << "Error(s) when building project" << std::endl; + cmCTestLog(m_CTest, ERROR, "Error(s) when building project" << std::endl); } std::vector::size_type cc; @@ -382,13 +381,13 @@ int cmCTestBuildHandler::ProcessHandler() bool found = false; if ( markedLines[kk] == 1 ) { - //std::cout << "Error: " << lines[kk] << std::endl; + cmCTestLog(m_CTest, DEBUG, "Error: " << lines[kk] << std::endl); errorwarning.m_Error = true; found = true; } else if ( markedLines[kk] > 1 ) { - //std::cout << "Warning: " << lines[kk] << std::endl; + cmCTestLog(m_CTest, DEBUG, "Warning: " << lines[kk] << std::endl); errorwarning.m_Error = false; found = true; } @@ -433,13 +432,12 @@ int cmCTestBuildHandler::ProcessHandler() } } - std::cout << " " << errors << " Compiler errors" << std::endl; - std::cout << " " << warnings << " Compiler warnings" << std::endl; - + cmCTestLog(m_CTest, HANDLER_OUTPUT, " " << errors << " Compiler errors" << std::endl); + cmCTestLog(m_CTest, HANDLER_OUTPUT, " " << warnings << " Compiler warnings" << std::endl); cmGeneratedFileStream xofs; if( !m_CTest->OpenOutputFile(m_CTest->GetCurrentTag(), "Build.xml", xofs, true) ) { - std::cerr << "Cannot create build XML file" << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot create build XML file" << std::endl); return -1; } this->GenerateDartBuildOutput(xofs, errorsWarnings, elapsed_build_time); diff --git a/Source/CTest/cmCTestConfigureHandler.cxx b/Source/CTest/cmCTestConfigureHandler.cxx index 1f6cc8b15..4e8d2dbec 100644 --- a/Source/CTest/cmCTestConfigureHandler.cxx +++ b/Source/CTest/cmCTestConfigureHandler.cxx @@ -26,7 +26,6 @@ //---------------------------------------------------------------------- cmCTestConfigureHandler::cmCTestConfigureHandler() { - m_Verbose = false; m_CTest = 0; } @@ -36,19 +35,19 @@ cmCTestConfigureHandler::cmCTestConfigureHandler() //functions and commented... int cmCTestConfigureHandler::ProcessHandler() { - std::cout << "Configure project" << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, "Configure project" << std::endl); std::string cCommand = m_CTest->GetCTestConfiguration("ConfigureCommand"); if ( cCommand.size() == 0 ) { - std::cerr << "Cannot find ConfigureCommand key in the DartConfiguration.tcl" - << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot find ConfigureCommand key in the DartConfiguration.tcl" + << std::endl); return -1; } std::string buildDirectory = m_CTest->GetCTestConfiguration("BuildDirectory"); if ( buildDirectory.size() == 0 ) { - std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl); return -1; } @@ -61,7 +60,7 @@ int cmCTestConfigureHandler::ProcessHandler() cmGeneratedFileStream os; if ( !m_CTest->OpenOutputFile(m_CTest->GetCurrentTag(), "Configure.xml", os, true) ) { - std::cerr << "Cannot open configure file" << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot open configure file" << std::endl); return 1; } std::string start_time = m_CTest->CurrentTime(); @@ -70,7 +69,7 @@ int cmCTestConfigureHandler::ProcessHandler() m_CTest->OpenOutputFile("Temporary", "LastConfigure.log", ofs); res = m_CTest->RunMakeCommand(cCommand.c_str(), &output, &retVal, buildDirectory.c_str(), - m_Verbose, 0, ofs); + 0, ofs); if ( ofs ) { @@ -87,7 +86,7 @@ int cmCTestConfigureHandler::ProcessHandler() os << retVal; } os << "" << cCommand.c_str() << "" << std::endl; - //std::cout << "End" << std::endl; + cmCTestLog(m_CTest, DEBUG, "End" << std::endl); os << "" << cmCTest::MakeXMLSafe(output) << "" << std::endl; std::string end_time = m_CTest->CurrentTime(); os << "\t" << retVal << "\n" @@ -102,11 +101,11 @@ int cmCTestConfigureHandler::ProcessHandler() } else { - std::cout << "Configure with command: " << cCommand << std::endl; + cmCTestLog(m_CTest, DEBUG, "Configure with command: " << cCommand << std::endl); } if (! res || retVal ) { - std::cerr << "Error(s) when updating the project" << std::endl; + cmCTestLog(m_CTest, ERROR, "Error(s) when updating the project" << std::endl); return -1; } return 0; diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index de42576e4..7043fbd55 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -34,7 +34,6 @@ //---------------------------------------------------------------------- cmCTestCoverageHandler::cmCTestCoverageHandler() { - m_Verbose = false; m_CTest = 0; } @@ -43,11 +42,11 @@ bool cmCTestCoverageHandler::StartLogFile(cmGeneratedFileStream& covLogFile, int { char covLogFilename[1024]; sprintf(covLogFilename, "CoverageLog-%d.xml", logFileCount); - std::cout << "Open file: " << covLogFilename << std::endl; + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Open file: " << covLogFilename << std::endl); if (!m_CTest->OpenOutputFile(m_CTest->GetCurrentTag(), covLogFilename, covLogFile, true)) { - std::cerr << "Cannot open log file: " << covLogFilename << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot open log file: " << covLogFilename << std::endl); return false; } std::string local_start_time = m_CTest->CurrentTime(); @@ -66,13 +65,13 @@ void cmCTestCoverageHandler::EndLogFile(cmGeneratedFileStream& ostr, int logFile m_CTest->EndXML(ostr); char covLogFilename[1024]; sprintf(covLogFilename, "CoverageLog-%d.xml", logFileCount); - std::cout << "Close file: " << covLogFilename << std::endl; + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Close file: " << covLogFilename << std::endl); ostr.close(); } //---------------------------------------------------------------------- bool cmCTestCoverageHandler::ShouldIDoCoverage(const char* file, const char* srcDir, - const char* binDir, bool verbose) + const char* binDir) { std::string fSrcDir = cmSystemTools::CollapseFullPath(srcDir); std::string fBinDir = cmSystemTools::CollapseFullPath(binDir); @@ -108,10 +107,7 @@ bool cmCTestCoverageHandler::ShouldIDoCoverage(const char* file, const char* src fFile.c_str(), checkDir.c_str()); if ( ndc.size() ) { - if ( verbose ) - { - std::cout << "Found: " << ndc.c_str() << " so skip coverage of " << file << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Found: " << ndc.c_str() << " so skip coverage of " << file << std::endl); return false; } @@ -141,10 +137,7 @@ bool cmCTestCoverageHandler::ShouldIDoCoverage(const char* file, const char* src fFile.c_str(), checkDir.c_str()); if ( ndc.size() ) { - if ( verbose ) - { - std::cout << "Found: " << ndc.c_str() << " so skip coverage of: " << file << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Found: " << ndc.c_str() << " so skip coverage of: " << file << std::endl); return false; } // Ok, nothing in source tree, nothing in binary tree @@ -171,7 +164,7 @@ int cmCTestCoverageHandler::ProcessHandler() std::string gcovOutputRex = "[0-9]+\\.[0-9]+% of [0-9]+ (source |)lines executed in file (.*)$"; std::string gcovOutputRex2 = "^Creating (.*\\.gcov)\\."; - std::cout << "Performing coverage" << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, "Performing coverage" << std::endl); double elapsed_time_start = cmSystemTools::GetTime(); std::string coverage_start_time = m_CTest->CurrentTime(); @@ -190,7 +183,7 @@ int cmCTestCoverageHandler::ProcessHandler() if ( files.size() == 0 ) { - std::cerr << " Cannot find any coverage files." << std::endl; + cmCTestLog(m_CTest, ERROR, " Cannot find any coverage files." << std::endl); // No coverage files is a valid thing, so the exit code is 0 return 0; } @@ -209,10 +202,7 @@ int cmCTestCoverageHandler::ProcessHandler() { std::string fileDir = cmSystemTools::GetFilenamePath(it->c_str()); std::string command = "\"" + gcovCommand + "\" -l -o \"" + fileDir + "\" \"" + *it + "\""; - if ( m_Verbose ) - { - std::cout << command.c_str() << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, command.c_str() << std::endl); std::string output = ""; int retVal = 0; int res = cmSystemTools::RunSingleCommand(command.c_str(), &output, @@ -220,13 +210,13 @@ int cmCTestCoverageHandler::ProcessHandler() false, 0 /*m_TimeOut*/); if ( ! res ) { - std::cerr << "Problem running coverage on file: " << it->c_str() << std::endl; + cmCTestLog(m_CTest, ERROR, "Problem running coverage on file: " << it->c_str() << std::endl); error ++; continue; } if ( retVal != 0 ) { - std::cerr << "Coverage command returned: " << retVal << " while processing: " << it->c_str() << std::endl; + cmCTestLog(m_CTest, ERROR, "Coverage command returned: " << retVal << " while processing: " << it->c_str() << std::endl); } std::vector lines; std::vector::iterator line; @@ -242,10 +232,7 @@ int cmCTestCoverageHandler::ProcessHandler() file.substr(0, sourceDir.size()) == sourceDir && file[sourceDir.size()] == '/' ) { - if ( m_Verbose ) - { - std::cout << " produced s: " << file << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, " produced s: " << file << std::endl); cfile = file; } // Binary dir? @@ -253,18 +240,15 @@ int cmCTestCoverageHandler::ProcessHandler() file.substr(0, binaryDir.size()) == binaryDir && file[binaryDir.size()] == '/' ) { - if ( m_Verbose ) - { - std::cout << " produce b: " << file << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, " produce b: " << file << std::endl); cfile = file; } if ( cfile.empty() ) { - std::cerr << "Something went wrong" << std::endl; - std::cerr << "File: [" << file << "]" << std::endl; - std::cerr << "s: [" << file.substr(0, sourceDir.size()) << "]" << std::endl; - std::cerr << "b: [" << file.substr(0, binaryDir.size()) << "]" << std::endl; + cmCTestLog(m_CTest, ERROR, "Something went wrong" << std::endl); + cmCTestLog(m_CTest, ERROR, "File: [" << file << "]" << std::endl); + cmCTestLog(m_CTest, ERROR, "s: [" << file.substr(0, sourceDir.size()) << "]" << std::endl); + cmCTestLog(m_CTest, ERROR, "b: [" << file.substr(0, binaryDir.size()) << "]" << std::endl); } } else if ( re2.find(line->c_str() ) ) @@ -273,14 +257,11 @@ int cmCTestCoverageHandler::ProcessHandler() if ( cfile.size() ) { singleFileCoverageVector* vec = &totalCoverage[cfile]; - if ( m_Verbose ) - { - std::cout << " in file: " << fname << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, " in file: " << fname << std::endl); std::ifstream ifile(fname.c_str()); if ( ! ifile ) { - std::cerr << "Cannot open file: " << fname << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot open file: " << fname << std::endl); } else { @@ -317,7 +298,7 @@ int cmCTestCoverageHandler::ProcessHandler() } else { - std::cerr << "Unknown line: " << line->c_str() << std::endl; + cmCTestLog(m_CTest, ERROR, "Unknown line: " << line->c_str() << std::endl); error ++; } } @@ -329,7 +310,8 @@ int cmCTestCoverageHandler::ProcessHandler() if (!m_CTest->OpenOutputFile(m_CTest->GetCurrentTag(), "Coverage.xml", covSumFile, true)) { - std::cerr << "Cannot open coverage summary file: Coverage.xml" << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot open coverage summary file: Coverage.xml" << std::endl); + return -1; } @@ -366,30 +348,24 @@ int cmCTestCoverageHandler::ProcessHandler() const std::string fullFileName = fileIterator->first; const std::string fileName = cmSystemTools::GetFilenameName(fullFileName.c_str()); std::string fullFilePath = cmSystemTools::GetFilenamePath(fullFileName.c_str()); - if ( m_Verbose ) - { - std::cerr << "Process file: " << fullFileName << std::endl; - } + cmCTestLog(m_CTest, ERROR, "Process file: " << fullFileName << std::endl); cmSystemTools::ConvertToUnixSlashes(fullFilePath); if ( !cmSystemTools::FileExists(fullFileName.c_str()) ) { - std::cerr << "Cannot find file: " << fullFileName.c_str() << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot find file: " << fullFileName.c_str() << std::endl); continue; } bool shouldIDoCoverage = this->ShouldIDoCoverage(fullFileName.c_str(), - sourceDir.c_str(), binaryDir.c_str(), m_Verbose); + sourceDir.c_str(), binaryDir.c_str()); if ( !shouldIDoCoverage ) { - if ( m_Verbose ) - { - std::cerr << ".NoDartCoverage found, so skip coverage check for: " - << fullFileName.c_str() - << std::endl; - } + cmCTestLog(m_CTest, ERROR, ".NoDartCoverage found, so skip coverage check for: " + << fullFileName.c_str() + << std::endl); continue; } @@ -403,7 +379,7 @@ int cmCTestCoverageHandler::ProcessHandler() std::ifstream ifs(fullFileName.c_str()); if ( !ifs) { - std::cerr << "Cannot open source file: " << fullFileName.c_str() << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot open source file: " << fullFileName.c_str() << std::endl); error ++; continue; } @@ -417,7 +393,7 @@ int cmCTestCoverageHandler::ProcessHandler() { if ( !cmSystemTools::GetLineFromStream(ifs, line) ) { - std::cerr << "Problem reading source file: " << fullFileName.c_str() << " line:" << cc << std::endl; + cmCTestLog(m_CTest, ERROR, "Problem reading source file: " << fullFileName.c_str() << " line:" << cc << std::endl); error ++; break; } @@ -434,7 +410,7 @@ int cmCTestCoverageHandler::ProcessHandler() } if ( cmSystemTools::GetLineFromStream(ifs, line) ) { - std::cerr << "Looks like there are more lines in the file: " << line << std::endl; + cmCTestLog(m_CTest, ERROR, "Looks like there are more lines in the file: " << line << std::endl); } float cper = 0; float cmet = 0; @@ -492,14 +468,13 @@ int cmCTestCoverageHandler::ProcessHandler() << "" << std::endl; m_CTest->EndXML(covSumFile); - std::cout << "\tCovered LOC: " << total_tested << std::endl + cmCTestLog(m_CTest, HANDLER_OUTPUT, "\tCovered LOC: " << total_tested << std::endl << "\tNot covered LOC: " << total_untested << std::endl << "\tTotal LOC: " << total_lines << std::endl - << "\tPercentage Coverage: "; - - std::cout.setf(std::ios::fixed, std::ios::floatfield); - std::cout.precision(2); - std::cout << (percent_coverage) << "%" << std::endl; + << "\tPercentage Coverage: " + << std::setiosflags(std::ios::fixed) + << std::setprecision(2) + << (percent_coverage) << "%" << std::endl); cmSystemTools::ChangeDirectory(currentDirectory.c_str()); diff --git a/Source/CTest/cmCTestCoverageHandler.h b/Source/CTest/cmCTestCoverageHandler.h index d303ff1b8..fc11df6d2 100644 --- a/Source/CTest/cmCTestCoverageHandler.h +++ b/Source/CTest/cmCTestCoverageHandler.h @@ -41,7 +41,7 @@ public: private: bool ShouldIDoCoverage(const char* file, const char* srcDir, - const char* binDir, bool verbose); + const char* binDir); bool StartLogFile(cmGeneratedFileStream& ostr, int logFileCount); void EndLogFile(cmGeneratedFileStream& ostr, int logFileCount); diff --git a/Source/CTest/cmCTestGenericHandler.cxx b/Source/CTest/cmCTestGenericHandler.cxx index 0fa6d07ac..0f480625f 100644 --- a/Source/CTest/cmCTestGenericHandler.cxx +++ b/Source/CTest/cmCTestGenericHandler.cxx @@ -19,7 +19,7 @@ cmCTestGenericHandler::cmCTestGenericHandler() { - m_Verbose = false; + m_HandlerVerbose = false; m_CTest = 0; } diff --git a/Source/CTest/cmCTestGenericHandler.h b/Source/CTest/cmCTestGenericHandler.h index a40974c3c..f5b203e8e 100644 --- a/Source/CTest/cmCTestGenericHandler.h +++ b/Source/CTest/cmCTestGenericHandler.h @@ -34,7 +34,7 @@ public: /** * If verbose then more informaiton is printed out */ - void SetVerbose(bool val) { m_Verbose = val; } + void SetVerbose(bool val) { m_HandlerVerbose = val; } /** * Populate internals from CTest custom scripts @@ -51,6 +51,7 @@ public: * Set the CTest instance */ void SetCTestInstance(cmCTest* ctest) { m_CTest = ctest; } + cmCTest* GetCTestInstance() { return m_CTest; } /** * Construct handler @@ -64,7 +65,7 @@ public: const char* GetOption(const char* op); protected: - bool m_Verbose; + bool m_HandlerVerbose; cmCTest *m_CTest; t_StringToString m_Options; }; diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index ef56428bf..aea9641c9 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -100,7 +100,7 @@ int cmCTestMemCheckHandler::PreProcessHandler() if ( !this->ExecuteCommands(m_CustomPreMemCheck) ) { - std::cerr << "Problem executing pre-memcheck command(s)." << std::endl; + cmCTestLog(m_CTest, ERROR, "Problem executing pre-memcheck command(s)." << std::endl); return 0; } return 1; @@ -111,7 +111,7 @@ int cmCTestMemCheckHandler::PostProcessHandler() { if ( !this->ExecuteCommands(m_CustomPostMemCheck) ) { - std::cerr << "Problem executing post-memcheck command(s)." << std::endl; + cmCTestLog(m_CTest, ERROR, "Problem executing post-memcheck command(s)." << std::endl); return 0; } return 1; @@ -130,10 +130,7 @@ void cmCTestMemCheckHandler::GenerateTestCommand(std::vector& args) memcheckcommand += " "; memcheckcommand += cmSystemTools::EscapeSpaces(m_MemoryTesterOptionsParsed[pp].c_str()); } - if ( m_Verbose ) - { - std::cout << "Memory check command: " << memcheckcommand << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Memory check command: " << memcheckcommand << std::endl); } //---------------------------------------------------------------------- @@ -188,7 +185,7 @@ void cmCTestMemCheckHandler::GenerateDartOutput(std::ostream& os) << "" << std::endl; } os << "\t\n"; - std::cout << "-- Processing memory checking output: "; + cmCTestLog(m_CTest, HANDLER_OUTPUT, "-- Processing memory checking output: "); unsigned int total = m_TestResults.size(); unsigned int step = total / 10; unsigned int current = 0; @@ -244,21 +241,24 @@ void cmCTestMemCheckHandler::GenerateDartOutput(std::ostream& os) << "\t" << std::endl; if ( current < cc ) { - std::cout << "#"; - std::cout.flush(); + cmCTestLog(m_CTest, HANDLER_OUTPUT, "#" << std::flush); current += step; } } - std::cout << std::endl; - std::cerr << "Memory checking results:" << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, std::endl); + cmCTestLog(m_CTest, HANDLER_OUTPUT, "Memory checking results:" << std::endl); os << "\t" << std::endl; for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ ) { if ( m_MemoryTesterGlobalResults[cc] ) { +#ifdef cerr +# undef cerr +#endif std::cerr.width(35); - std::cerr << cmCTestMemCheckResultLongStrings[cc] << " - " - << m_MemoryTesterGlobalResults[cc] << std::endl; +#define cerr no_cerr + cmCTestLog(m_CTest, HANDLER_OUTPUT, cmCTestMemCheckResultLongStrings[cc] << " - " + << m_MemoryTesterGlobalResults[cc] << std::endl); os << "\t\t" << std::endl; } } @@ -296,8 +296,8 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() } else { - std::cerr << "Memory checker (MemoryCheckCommand) not set, or cannot find the specified program." - << std::endl; + cmCTestLog(m_CTest, ERROR, "Memory checker (MemoryCheckCommand) not set, or cannot find the specified program." + << std::endl); return false; } @@ -330,8 +330,8 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() { if ( !cmSystemTools::FileExists(m_CTest->GetCTestConfiguration("MemoryCheckSuppressionFile").c_str()) ) { - std::cerr << "Cannot find memory checker suppression file: " - << m_CTest->GetCTestConfiguration("MemoryCheckSuppressionFile").c_str() << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot find memory checker suppression file: " + << m_CTest->GetCTestConfiguration("MemoryCheckSuppressionFile").c_str() << std::endl); return false; } m_MemoryTesterOptions += " --suppressions=" + cmSystemTools::EscapeSpaces(m_CTest->GetCTestConfiguration("MemoryCheckSuppressionFile").c_str()) + ""; @@ -349,12 +349,12 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() else if ( m_MemoryTester.find("boundschecker") != std::string::npos ) { m_MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER; - std::cerr << "Bounds checker not yet implemented" << std::endl; + cmCTestLog(m_CTest, ERROR, "Bounds checker not yet implemented" << std::endl); return false; } else { - std::cerr << "Do not understand memory checker: " << m_MemoryTester.c_str() << std::endl; + cmCTestLog(m_CTest, ERROR, "Do not understand memory checker: " << m_MemoryTester.c_str() << std::endl); return false; } @@ -409,7 +409,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckPurifyOutput( if ( !cmSystemTools::FileExists(m_MemoryTesterOutputFile.c_str()) ) { log = "Cannot find Purify output file: " + m_MemoryTesterOutputFile; - std::cerr << log.c_str() << std::endl; + cmCTestLog(m_CTest, ERROR, log.c_str() << std::endl); return false; } @@ -417,7 +417,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckPurifyOutput( if ( !ifs ) { log = "Cannot read Purify output file: " + m_MemoryTesterOutputFile; - std::cerr << log.c_str() << std::endl; + cmCTestLog(m_CTest, ERROR, log.c_str() << std::endl); return false; } @@ -445,7 +445,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckPurifyOutput( } if ( cc == cmCTestMemCheckHandler::NO_MEMORY_FAULT ) { - std::cerr<< "Unknown Purify memory fault: " << pfW.match(1) << std::endl; + cmCTestLog(m_CTest, ERROR, "Unknown Purify memory fault: " << pfW.match(1) << std::endl); ostr << "*** Unknown Purify memory fault: " << pfW.match(1) << std::endl; } } @@ -508,8 +508,8 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput( cmsys::RegularExpression vgIPW("== .*Invalid write of size [0-9]"); cmsys::RegularExpression vgABR("== .*pthread_mutex_unlock: mutex is locked by a different thread"); - //double sttime = cmSystemTools::GetTime(); - //std::cout << "Start test: " << lines.size() << std::endl; + double sttime = cmSystemTools::GetTime(); + cmCTestLog(m_CTest, DEBUG, "Start test: " << lines.size() << std::endl); for ( cc = 0; cc < lines.size(); cc ++ ) { if ( valgrindLine.find(lines[cc]) ) @@ -538,7 +538,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput( ostr << cmCTest::MakeXMLSafe(lines[cc]) << std::endl; } } - //std::cout << "End test (elapsed: " << (cmSystemTools::GetTime() - sttime) << std::endl; + cmCTestLog(m_CTest, DEBUG, "End test (elapsed: " << (cmSystemTools::GetTime() - sttime) << std::endl); log = ostr.str(); if ( defects ) { diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index 1be590768..212c1b805 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -80,7 +80,6 @@ IsFunctionBlocked(const cmListFileFunction& , cmMakefile &) //---------------------------------------------------------------------- cmCTestScriptHandler::cmCTestScriptHandler() { - m_Verbose = false; m_Backup = false; m_EmptyBinDir = false; m_EmptyBinDirOnce = false; @@ -463,13 +462,10 @@ int cmCTestScriptHandler::CheckOutSourceDir() { // we must now checkout the src dir output = ""; - if ( m_Verbose ) - { - std::cerr << "Run cvs: " << m_CVSCheckOut << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Run cvs: " << m_CVSCheckOut << std::endl); res = cmSystemTools::RunSingleCommand(m_CVSCheckOut.c_str(), &output, &retVal, m_CTestRoot.c_str(), - m_Verbose, 0 /*m_TimeOut*/); + m_HandlerVerbose, 0 /*m_TimeOut*/); if (!res || retVal != 0) { cmSystemTools::Error("Unable to perform cvs checkout:\n", @@ -543,13 +539,10 @@ int cmCTestScriptHandler::PerformExtraUpdates() fullCommand += cvsArgs[1]; output = ""; retVal = 0; - if ( m_Verbose ) - { - std::cerr << "Run CVS: " << fullCommand.c_str() << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Run CVS: " << fullCommand.c_str() << std::endl); res = cmSystemTools::RunSingleCommand(fullCommand.c_str(), &output, &retVal, cvsArgs[0].c_str(), - m_Verbose, 0 /*m_TimeOut*/); + m_HandlerVerbose, 0 /*m_TimeOut*/); if (!res || retVal != 0) { cmSystemTools::Error("Unable to perform extra cvs updates:\n", @@ -592,7 +585,7 @@ int cmCTestScriptHandler::RunConfigurationDashboard() { if ( !cmCTestScriptHandler::EmptyBinaryDirectory(m_BinaryDir.c_str()) ) { - std::cerr << "Problem removing the binary directory" << std::endl; + cmCTestLog(m_CTest, ERROR, "Problem removing the binary directory" << std::endl); } } @@ -669,13 +662,10 @@ int cmCTestScriptHandler::RunConfigurationDashboard() output = ""; command += "\""; retVal = 0; - if ( m_Verbose ) - { - std::cerr << "Run cmake command: " << command.c_str() << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Run cmake command: " << command.c_str() << std::endl); res = cmSystemTools::RunSingleCommand(command.c_str(), &output, &retVal, m_BinaryDir.c_str(), - m_Verbose, 0 /*m_TimeOut*/); + m_HandlerVerbose, 0 /*m_TimeOut*/); if ( !m_CMOutFile.empty() ) { @@ -685,11 +675,8 @@ int cmCTestScriptHandler::RunConfigurationDashboard() cmakeOutputFile = m_BinaryDir + "/" + cmakeOutputFile; } - if ( m_Verbose ) - { - std::cerr << "Write CMake output to file: " << cmakeOutputFile.c_str() - << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Write CMake output to file: " << cmakeOutputFile.c_str() + << std::endl); cmGeneratedFileStream fout(cmakeOutputFile.c_str()); if ( fout ) { @@ -697,8 +684,8 @@ int cmCTestScriptHandler::RunConfigurationDashboard() } else { - cmSystemTools::Error("Cannot open CMake output file: ", - cmakeOutputFile.c_str(), " for writing"); + cmCTestLog(m_CTest, ERROR, "Cannot open CMake output file: " + << cmakeOutputFile.c_str() << " for writing" << std::endl); } } if (!res || retVal != 0) @@ -718,13 +705,10 @@ int cmCTestScriptHandler::RunConfigurationDashboard() command = ctestCommands[i]; output = ""; retVal = 0; - if ( m_Verbose ) - { - std::cerr << "Run ctest command: " << command.c_str() << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Run ctest command: " << command.c_str() << std::endl); res = cmSystemTools::RunSingleCommand(command.c_str(), &output, &retVal, m_BinaryDir.c_str(), - m_Verbose, 0 /*m_TimeOut*/); + m_HandlerVerbose, 0 /*m_TimeOut*/); // did something critical fail in ctest if (!res || cmakeFailed || @@ -733,11 +717,12 @@ int cmCTestScriptHandler::RunConfigurationDashboard() this->RestoreBackupDirectories(); if (cmakeFailed) { - cmSystemTools::Error("Unable to run cmake:\n", - cmakeFailedOuput.c_str()); + cmCTestLog(m_CTest, ERROR, "Unable to run cmake:" << std::endl + << cmakeFailedOuput.c_str() << std::endl); return 10; } - cmSystemTools::Error("Unable to run ctest:\n", output.c_str()); + cmCTestLog(m_CTest, ERROR, "Unable to run ctest:" << std::endl + << output.c_str() << std::endl); if (!res) { return 11; diff --git a/Source/CTest/cmCTestStartCommand.cxx b/Source/CTest/cmCTestStartCommand.cxx index fe81fd4d2..096be9e21 100644 --- a/Source/CTest/cmCTestStartCommand.cxx +++ b/Source/CTest/cmCTestStartCommand.cxx @@ -64,15 +64,15 @@ bool cmCTestStartCommand::InitialPass( this->SetError("binary directory not specified. Specify binary directory as an argument or set CTEST_BINARY_DIRECTORY"); return false; } - std::cout << "Run dashboard with model " << smodel - << " for src dir: " << src_dir << " and binary dir: " << bld_dir << std::endl; + cmCTestLog(m_CTest, OUTPUT, "Run dashboard with model " << smodel + << " for src dir: " << src_dir << " and binary dir: " << bld_dir << std::endl); std::string fname = src_dir; fname += "/CTestConfig.cmake"; cmSystemTools::ConvertToUnixSlashes(fname); if ( cmSystemTools::FileExists(fname.c_str()) ) { - std::cout << " Reading ctest configuration file: " << fname.c_str() << std::endl; + cmCTestLog(m_CTest, OUTPUT, " Reading ctest configuration file: " << fname.c_str() << std::endl); bool readit = m_Makefile->ReadListFile(m_Makefile->GetCurrentListFile(), fname.c_str() ); if(!readit) diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx index 28f861225..5bb298ab3 100644 --- a/Source/CTest/cmCTestSubmitHandler.cxx +++ b/Source/CTest/cmCTestSubmitHandler.cxx @@ -33,10 +33,23 @@ PURPOSE. See the above copyright notices for more information. #include +typedef std::vector cmCTestSubmitHandlerVectorOfChar; + +static size_t +cmCTestSubmitHandlerWriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) +{ + register int realsize = size * nmemb; + + cmCTestSubmitHandlerVectorOfChar *vec = static_cast(data); + const char* chPtr = static_cast(ptr); + vec->insert(vec->end(), chPtr, chPtr + realsize); + + return realsize; +} + //---------------------------------------------------------------------------- cmCTestSubmitHandler::cmCTestSubmitHandler() : m_HTTPProxy(), m_FTPProxy() { - m_Verbose = false; m_HTTPProxy = ""; m_HTTPProxyType = 0; m_HTTPProxyAuth = ""; @@ -107,11 +120,11 @@ cmCTestSubmitHandler::cmCTestSubmitHandler() : m_HTTPProxy(), m_FTPProxy() } if ( m_HTTPProxy.size() > 0 ) { - std::cout << " Use HTTP Proxy: " << m_HTTPProxy << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Use HTTP Proxy: " << m_HTTPProxy << std::endl); } if ( m_FTPProxy.size() > 0 ) { - std::cout << " Use FTP Proxy: " << m_FTPProxy << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Use FTP Proxy: " << m_FTPProxy << std::endl); } } @@ -168,13 +181,11 @@ bool cmCTestSubmitHandler::SubmitUsingFTP(const cmStdString& localprefix, ftpfile = ::fopen(local_file.c_str(), "rb"); *m_LogFile << "\tUpload file: " << local_file.c_str() << " to " << upload_as.c_str() << std::endl; - if ( m_Verbose ) - { - std::cout << " Upload file: " << local_file.c_str() << " to " - << upload_as.c_str() << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, " Upload file: " << local_file.c_str() << " to " + << upload_as.c_str() << std::endl); - if ( m_Verbose ) + ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 0); + if ( m_HandlerVerbose ) { ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); } @@ -187,24 +198,39 @@ bool cmCTestSubmitHandler::SubmitUsingFTP(const cmStdString& localprefix, // and give the size of the upload (optional) ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, static_cast(st.st_size)); + // and give curl the buffer for errors ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer); + // specify handler for output + ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cmCTestSubmitHandlerWriteMemoryCallback); + + /* we pass our 'chunk' struct to the callback function */ + cmCTestSubmitHandlerVectorOfChar chunk; + ::curl_easy_setopt(curl, CURLOPT_FILE, (void *)&chunk); + // Now run off and do what you've been told! res = ::curl_easy_perform(curl); + + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "CURL output: [" + << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]" << std::endl); + fclose(ftpfile); if ( res ) { - std::cerr << " Error when uploading file: " << local_file.c_str() << std::endl; - std::cerr << " Error message was: " << error_buffer << std::endl; + cmCTestLog(m_CTest, ERROR, " Error when uploading file: " << local_file.c_str() << std::endl); + cmCTestLog(m_CTest, ERROR, " Error message was: " << error_buffer << std::endl); *m_LogFile << " Error when uploading file: " << local_file.c_str() << std::endl - << " Error message was: " << error_buffer << std::endl; + << " Error message was: " << error_buffer << std::endl + << " Curl output was: " << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << std::endl; + cmCTestLog(m_CTest, ERROR, "CURL output: [" + << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]" << std::endl); ::curl_easy_cleanup(curl); ::curl_global_cleanup(); return false; } // always cleanup ::curl_easy_cleanup(curl); - std::cout << " Uploaded: " + local_file << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Uploaded: " + local_file << std::endl); } } ::curl_global_cleanup(); @@ -261,7 +287,8 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const cmStdString& localprefix, /* HTTP PUT please */ curl_easy_setopt(curl, CURLOPT_PUT, 1); - if ( m_Verbose ) + ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 0); + if ( m_HandlerVerbose ) { ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); } @@ -306,11 +333,8 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const cmStdString& localprefix, } ftpfile = ::fopen(local_file.c_str(), "rb"); - if ( m_Verbose ) - { - std::cout << " Upload file: " << local_file.c_str() << " to " - << upload_as.c_str() << " Size: " << st.st_size << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, " Upload file: " << local_file.c_str() << " to " + << upload_as.c_str() << " Size: " << st.st_size << std::endl); // specify target @@ -325,22 +349,36 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const cmStdString& localprefix, // and give curl the buffer for errors ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer); + // specify handler for output + ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cmCTestSubmitHandlerWriteMemoryCallback); + + /* we pass our 'chunk' struct to the callback function */ + cmCTestSubmitHandlerVectorOfChar chunk; + ::curl_easy_setopt(curl, CURLOPT_FILE, (void *)&chunk); + // Now run off and do what you've been told! res = ::curl_easy_perform(curl); + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "CURL output: [" + << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]" << std::endl); + fclose(ftpfile); if ( res ) { - std::cerr << " Error when uploading file: " << local_file.c_str() << std::endl; + cmCTestLog(m_CTest, ERROR, " Error when uploading file: " << local_file.c_str() << std::endl); + cmCTestLog(m_CTest, ERROR, " Error message was: " << error_buffer << std::endl); *m_LogFile << " Error when uploading file: " << local_file.c_str() << std::endl - << " Error message was: " << error_buffer << std::endl; + << " Error message was: " << error_buffer << std::endl + << " Curl output was: " << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << std::endl; + cmCTestLog(m_CTest, ERROR, "CURL output: [" + << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]" << std::endl); ::curl_easy_cleanup(curl); ::curl_global_cleanup(); return false; } // always cleanup ::curl_easy_cleanup(curl); - std::cout << " Uploaded: " + local_file << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Uploaded: " + local_file << std::endl); } } ::curl_global_cleanup(); @@ -388,7 +426,7 @@ bool cmCTestSubmitHandler::TriggerUsingHTTP(const std::vector& file } ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 0); - if ( m_Verbose ) + if ( m_HandlerVerbose ) { ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); } @@ -396,6 +434,13 @@ bool cmCTestSubmitHandler::TriggerUsingHTTP(const std::vector& file // and give curl the buffer for errors ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer); + // specify handler for output + ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cmCTestSubmitHandlerWriteMemoryCallback); + + /* we pass our 'chunk' struct to the callback function */ + cmCTestSubmitHandlerVectorOfChar chunk; + ::curl_easy_setopt(curl, CURLOPT_FILE, (void *)&chunk); + cmStdString file = remoteprefix + files[cc]; cmStdString ofile = ""; for ( kk = 0; kk < file.size(); kk ++ ) @@ -424,26 +469,32 @@ bool cmCTestSubmitHandler::TriggerUsingHTTP(const std::vector& file = url + ((url.find("?",0) == cmStdString::npos) ? "?" : "&") + "xmlfile=" + ofile; *m_LogFile << "Trigger url: " << turl.c_str() << std::endl; - if ( m_Verbose ) - { - std::cout << " Trigger url: " << turl.c_str() << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, " Trigger url: " << turl.c_str() << std::endl); curl_easy_setopt(curl, CURLOPT_URL, turl.c_str()); if ( curl_easy_perform(curl) ) { - std::cerr << " Error when triggering: " << turl.c_str() << std::endl; - *m_LogFile << "\tTrigerring failed with error: " << error_buffer << std::endl; + cmCTestLog(m_CTest, ERROR, " Error when triggering: " << turl.c_str() << std::endl); + cmCTestLog(m_CTest, ERROR, " Error message was: " << error_buffer << std::endl); + *m_LogFile << "\tTrigerring failed with error: " << error_buffer << std::endl + << " Error message was: " << error_buffer << std::endl + << " Curl output was: " << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << std::endl; + cmCTestLog(m_CTest, ERROR, "CURL output: [" + << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]" << std::endl); ::curl_easy_cleanup(curl); ::curl_global_cleanup(); return false; } + + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "CURL output: [" + << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]" << std::endl); + // always cleanup ::curl_easy_cleanup(curl); - std::cout << std::endl; + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, std::endl); } } ::curl_global_cleanup(); - std::cout << " Dart server triggered..." << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Dart server triggered..." << std::endl); return true; } @@ -486,11 +537,8 @@ bool cmCTestSubmitHandler::SubmitUsingSCP( argv[1] = lfname.c_str(); std::string rfname = url + "/" + remoteprefix + *it; argv[2] = rfname.c_str(); - if ( m_Verbose ) - { - std::cout << "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \"" - << argv[2] << "\"" << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \"" + << argv[2] << "\"" << std::endl); *m_LogFile << "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \"" << argv[2] << "\"" << std::endl; cmsysProcess_SetCommand(cp, &*argv.begin()); @@ -499,7 +547,7 @@ bool cmCTestSubmitHandler::SubmitUsingSCP( int length; while(cmsysProcess_WaitForData(cp, &data, &length, 0)) { - std::cout.write(data, length); + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, cmCTestLogWrite(data, length)); } cmsysProcess_WaitForExit(cp, 0); int result = cmsysProcess_GetState(cp); @@ -509,10 +557,7 @@ bool cmCTestSubmitHandler::SubmitUsingSCP( retVal = cmsysProcess_GetExitValue(cp); if ( retVal != 0 ) { - if ( m_Verbose ) - { - std::cout << "\tSCP returned: " << retVal << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "\tSCP returned: " << retVal << std::endl); *m_LogFile << "\tSCP returned: " << retVal << std::endl; problems ++; } @@ -520,29 +565,20 @@ bool cmCTestSubmitHandler::SubmitUsingSCP( else if(result == cmsysProcess_State_Exception) { retVal = cmsysProcess_GetExitException(cp); - if ( m_Verbose ) - { - std::cerr << "\tThere was an exception: " << retVal << std::endl; - } + cmCTestLog(m_CTest, ERROR, "\tThere was an exception: " << retVal << std::endl); *m_LogFile << "\tThere was an exception: " << retVal << std::endl; problems ++; } else if(result == cmsysProcess_State_Expired) { - if ( m_Verbose ) - { - std::cerr << "\tThere was a timeout" << std::endl; - } + cmCTestLog(m_CTest, ERROR, "\tThere was a timeout" << std::endl); *m_LogFile << "\tThere was a timeout" << std::endl; problems ++; } else if(result == cmsysProcess_State_Error) { - if ( m_Verbose ) - { - std::cerr << "\tError executing SCP: " - << cmsysProcess_GetErrorString(cp) << std::endl; - } + cmCTestLog(m_CTest, ERROR, "\tError executing SCP: " + << cmsysProcess_GetErrorString(cp) << std::endl); *m_LogFile << "\tError executing SCP: " << cmsysProcess_GetErrorString(cp) << std::endl; problems ++; @@ -574,14 +610,14 @@ bool cmCTestSubmitHandler::SubmitUsingXMLRPC(const cmStdString& localprefix, xmlrpc_env_init(&env); /* Call the famous server at UserLand. */ - std::cout << " Submitting to: " << realURL.c_str() << " (" << remoteprefix.c_str() << ")" << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Submitting to: " << realURL.c_str() << " (" << remoteprefix.c_str() << ")" << std::endl); std::vector::const_iterator it; for ( it = files.begin(); it != files.end(); ++it ) { xmlrpc_value *result; std::string local_file = localprefix + "/" + *it; - std::cout << " Submit file: " << local_file.c_str() << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Submit file: " << local_file.c_str() << std::endl); struct stat st; if ( ::stat(local_file.c_str(), &st) ) { @@ -613,7 +649,7 @@ bool cmCTestSubmitHandler::SubmitUsingXMLRPC(const cmStdString& localprefix, if ( env.fault_occurred ) { - std::cerr << " Submission problem: " << env.fault_string << " (" << env.fault_code << ")" << std::endl; + cmCTestLog(m_CTest, ERROR, " Submission problem: " << env.fault_string << " (" << env.fault_code << ")" << std::endl); xmlrpc_env_clean(&env); xmlrpc_client_cleanup(); return false; @@ -637,7 +673,7 @@ int cmCTestSubmitHandler::ProcessHandler() const std::string &buildDirectory = m_CTest->GetCTestConfiguration("BuildDirectory"); if ( buildDirectory.size() == 0 ) { - std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl); return -1; } @@ -658,20 +694,20 @@ int cmCTestSubmitHandler::ProcessHandler() std::string gpath = buildDirectory + "/Testing/" + m_CTest->GetCurrentTag(); std::string::size_type glen = gpath.size() + 1; gpath = gpath + "/CoverageLog*"; - //std::cout << "Globbing for: " << gpath.c_str() << std::endl; + cmCTestLog(m_CTest, DEBUG, "Globbing for: " << gpath.c_str() << std::endl); if ( cmSystemTools::SimpleGlob(gpath, gfiles, 1) ) { size_t cc; for ( cc = 0; cc < gfiles.size(); cc ++ ) { gfiles[cc] = gfiles[cc].substr(glen); - //std::cout << "Glob file: " << gfiles[cc].c_str() << std::endl; + cmCTestLog(m_CTest, DEBUG, "Glob file: " << gfiles[cc].c_str() << std::endl); files.push_back(gfiles[cc]); } } else { - std::cerr << "Problem globbing" << std::endl; + cmCTestLog(m_CTest, ERROR, "Problem globbing" << std::endl); } } m_CTest->AddIfExists(files, "DynamicAnalysis.xml"); @@ -689,14 +725,14 @@ int cmCTestSubmitHandler::ProcessHandler() cnt ++; } } - std::cout << "Submit files (using " << m_CTest->GetCTestConfiguration("DropMethod") << ")" - << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, "Submit files (using " << m_CTest->GetCTestConfiguration("DropMethod") << ")" + << std::endl); this->SetLogFile(&ofs); if ( m_CTest->GetCTestConfiguration("DropMethod") == "" || m_CTest->GetCTestConfiguration("DropMethod") == "ftp" ) { ofs << "Using drop method: FTP" << std::endl; - std::cout << " Using FTP submit method" << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Using FTP submit method" << std::endl); std::string url = "ftp://"; url += cmCTest::MakeURLSafe(m_CTest->GetCTestConfiguration("DropSiteUser")) + ":" + cmCTest::MakeURLSafe(m_CTest->GetCTestConfiguration("DropSitePassword")) + "@" + @@ -705,24 +741,24 @@ int cmCTestSubmitHandler::ProcessHandler() if ( !this->SubmitUsingFTP(buildDirectory+"/Testing/"+m_CTest->GetCurrentTag(), files, prefix, url) ) { - std::cerr << " Problems when submitting via FTP" << std::endl; + cmCTestLog(m_CTest, ERROR, " Problems when submitting via FTP" << std::endl); ofs << " Problems when submitting via FTP" << std::endl; return -1; } if ( !this->TriggerUsingHTTP(files, prefix, m_CTest->GetCTestConfiguration("TriggerSite")) ) { - std::cerr << " Problems when triggering via HTTP" << std::endl; + cmCTestLog(m_CTest, ERROR, " Problems when triggering via HTTP" << std::endl); ofs << " Problems when triggering via HTTP" << std::endl; return -1; } - std::cout << " Submission successful" << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Submission successful" << std::endl); ofs << " Submission successful" << std::endl; return 0; } else if ( m_CTest->GetCTestConfiguration("DropMethod") == "http" ) { ofs << "Using drop method: HTTP" << std::endl; - std::cout << " Using HTTP submit method" << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Using HTTP submit method" << std::endl); std::string url = "http://"; if ( m_CTest->GetCTestConfiguration("DropSiteUser").size() > 0 ) { @@ -736,33 +772,33 @@ int cmCTestSubmitHandler::ProcessHandler() url += m_CTest->GetCTestConfiguration("DropSite") + m_CTest->GetCTestConfiguration("DropLocation"); if ( !this->SubmitUsingHTTP(buildDirectory +"/Testing/"+m_CTest->GetCurrentTag(), files, prefix, url) ) { - std::cerr << " Problems when submitting via HTTP" << std::endl; + cmCTestLog(m_CTest, ERROR, " Problems when submitting via HTTP" << std::endl); ofs << " Problems when submitting via HTTP" << std::endl; return -1; } if ( !this->TriggerUsingHTTP(files, prefix, m_CTest->GetCTestConfiguration("TriggerSite")) ) { - std::cerr << " Problems when triggering via HTTP" << std::endl; + cmCTestLog(m_CTest, ERROR, " Problems when triggering via HTTP" << std::endl); ofs << " Problems when triggering via HTTP" << std::endl; return -1; } - std::cout << " Submission successful" << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Submission successful" << std::endl); ofs << " Submission successful" << std::endl; return 0; } else if ( m_CTest->GetCTestConfiguration("DropMethod") == "xmlrpc" ) { ofs << "Using drop method: XML-RPC" << std::endl; - std::cout << " Using XML-RPC submit method" << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Using XML-RPC submit method" << std::endl); std::string url = m_CTest->GetCTestConfiguration("DropSite"); prefix = m_CTest->GetCTestConfiguration("DropLocation"); if ( !this->SubmitUsingXMLRPC(buildDirectory+"/Testing/"+m_CTest->GetCurrentTag(), files, prefix, url) ) { - std::cerr << " Problems when submitting via XML-RPC" << std::endl; + cmCTestLog(m_CTest, ERROR, " Problems when submitting via XML-RPC" << std::endl); ofs << " Problems when submitting via XML-RPC" << std::endl; return -1; } - std::cout << " Submission successful" << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Submission successful" << std::endl); ofs << " Submission successful" << std::endl; return 0; } @@ -778,14 +814,14 @@ int cmCTestSubmitHandler::ProcessHandler() if ( !this->SubmitUsingSCP(m_CTest->GetCTestConfiguration("ScpCommand"), buildDirectory+"/Testing/"+m_CTest->GetCurrentTag(), files, prefix, url) ) { - std::cerr << " Problems when submitting via SCP" << std::endl; + cmCTestLog(m_CTest, ERROR, " Problems when submitting via SCP" << std::endl); ofs << " Problems when submitting via SCP" << std::endl; return -1; } - std::cout << " Submission successful" << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Submission successful" << std::endl); ofs << " Submission successful" << std::endl; } - std::cout << " Unknown submission method: \"" << m_CTest->GetCTestConfiguration("DropMethod") << "\"" << std::endl; + cmCTestLog(m_CTest, ERROR, " Unknown submission method: \"" << m_CTest->GetCTestConfiguration("DropMethod") << "\"" << std::endl); return -1; } diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 4c6e1da09..8b65c3273 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -177,7 +177,7 @@ int cmCTestTestHandler::PreProcessHandler() { if ( !this->ExecuteCommands(m_CustomPreTest) ) { - std::cerr << "Problem executing pre-test command(s)." << std::endl; + cmCTestLog(m_CTest, ERROR, "Problem executing pre-test command(s)." << std::endl); return 0; } return 1; @@ -188,7 +188,7 @@ int cmCTestTestHandler::PostProcessHandler() { if ( !this->ExecuteCommands(m_CustomPostTest) ) { - std::cerr << "Problem executing post-test command(s)." << std::endl; + cmCTestLog(m_CTest, ERROR, "Problem executing post-test command(s)." << std::endl); return 0; } return 1; @@ -218,7 +218,7 @@ int cmCTestTestHandler::ProcessHandler() m_TestResults.clear(); - std::cout << (m_MemCheck ? "Memory check" : "Test") << " project" << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, (m_MemCheck ? "Memory check" : "Test") << " project" << std::endl); if ( ! this->PreProcessHandler() ) { return -1; @@ -236,19 +236,19 @@ int cmCTestTestHandler::ProcessHandler() { if ( !m_CTest->GetShowOnly() ) { - std::cerr << "No tests were found!!!\n"; + cmCTestLog(m_CTest, ERROR, "No tests were found!!!" << std::endl); } } else { - if (m_Verbose && passed.size() && + if (m_HandlerVerbose && passed.size() && (m_UseIncludeRegExp || m_UseExcludeRegExp)) { - std::cerr << "\nThe following tests passed:\n"; + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, std::endl << "The following tests passed:" << std::endl); for(std::vector::iterator j = passed.begin(); j != passed.end(); ++j) { - std::cerr << "\t" << *j << "\n"; + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "\t" << *j << std::endl); } } @@ -257,14 +257,16 @@ int cmCTestTestHandler::ProcessHandler() { percent = 99; } - fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n", - percent, int(failed.size()), total); + cmCTestLog(m_CTest, HANDLER_OUTPUT, std::endl << std::setprecision(0) << percent << "% tests passed, " + << failed.size() << " tests failed out of " << total << std::endl); + //fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n", + // percent, int(failed.size()), total); if (failed.size()) { cmGeneratedFileStream ofs; - std::cerr << "\nThe following tests FAILED:\n"; + cmCTestLog(m_CTest, ERROR, std::endl << "The following tests FAILED:" << std::endl); m_CTest->OpenOutputFile("Temporary", "LastTestsFailed.log", ofs); std::vector::iterator ftit; @@ -274,8 +276,9 @@ int cmCTestTestHandler::ProcessHandler() if ( ftit->m_Status != cmCTestTestHandler::COMPLETED ) { ofs << ftit->m_TestCount << ":" << ftit->m_Name << std::endl; - fprintf(stderr, "\t%3d - %s (%s)\n", ftit->m_TestCount, ftit->m_Name.c_str(), - this->GetTestStatus(ftit->m_Status)); + cmCTestLog(m_CTest, HANDLER_OUTPUT, "\t" << std::setw(3) << ftit->m_TestCount << " - " << ftit->m_Name.c_str() << " (" << this->GetTestStatus(ftit->m_Status) << ")" << std::endl); + //fprintf(stderr, "\t%3d - %s (%s)\n", ftit->m_TestCount, ftit->m_Name.c_str(), + // this->GetTestStatus(ftit->m_Status)); } } @@ -288,8 +291,8 @@ int cmCTestTestHandler::ProcessHandler() if( !m_CTest->OpenOutputFile(m_CTest->GetCurrentTag(), (m_MemCheck ? "DynamicAnalysis.xml" : "Test.xml"), xmlfile, true) ) { - std::cerr << "Cannot create " << (m_MemCheck ? "memory check" : "testing") - << " XML file" << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot create " << (m_MemCheck ? "memory check" : "testing") + << " XML file" << std::endl); return 1; } this->GenerateDartOutput(xmlfile); @@ -374,11 +377,8 @@ void cmCTestTestHandler::ProcessDirectory(std::vector &passed, if (!(last_directory == it->m_Directory)) { - if ( m_Verbose ) - { - std::cerr << "Changing directory into " - << it->m_Directory.c_str() << "\n"; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Changing directory into " + << it->m_Directory.c_str() << "\n"); last_directory = it->m_Directory; cmSystemTools::ChangeDirectory(it->m_Directory.c_str()); } @@ -405,25 +405,22 @@ void cmCTestTestHandler::ProcessDirectory(std::vector &passed, continue; } } - - std::cerr.width(3); - std::cerr << cnt << "/"; - std::cerr.width(3); - std::cerr << tmsize << " Testing "; + + cmCTestLog(m_CTest, HANDLER_OUTPUT, std::setw(3) << cnt << "/"); + cmCTestLog(m_CTest, HANDLER_OUTPUT, std::setw(3) << tmsize << " Testing "); std::string outname = testname; outname.resize(30, ' '); if ( m_CTest->GetShowOnly() ) { - std::cerr << outname.c_str() << "\n"; + cmCTestLog(m_CTest, HANDLER_OUTPUT, outname.c_str() << std::endl); } else { - std::cerr << outname.c_str(); - std::cerr.flush(); + cmCTestLog(m_CTest, HANDLER_OUTPUT, outname.c_str()); } - //std::cerr << "Testing " << args[0] << " ... "; + cmCTestLog(m_CTest, DEBUG, "Testing " << args[0].Value.c_str() << " ... "); // find the test executable std::string actualCommand = this->FindTheExecutable(args[1].Value.c_str()); std::string testCommand = cmSystemTools::ConvertToOutputPath(actualCommand.c_str()); @@ -431,8 +428,8 @@ void cmCTestTestHandler::ProcessDirectory(std::vector &passed, // continue if we did not find the executable if (testCommand == "") { - std::cerr << "Unable to find executable: " << - args[1].Value.c_str() << "\n"; + cmCTestLog(m_CTest, ERROR, "Unable to find executable: " + << args[1].Value.c_str() << std::endl); if ( !m_CTest->GetShowOnly() ) { cres.m_FullCommandLine = actualCommand; @@ -464,10 +461,7 @@ void cmCTestTestHandler::ProcessDirectory(std::vector &passed, int retVal = 0; - if ( m_Verbose ) - { - std::cout << std::endl << (m_MemCheck?"MemCheck":"Test") << " command: " << testCommand << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, std::endl << (m_MemCheck?"MemCheck":"Test") << " command: " << testCommand << std::endl); if ( olog ) { *olog << cnt << "/" << tmsize @@ -524,7 +518,7 @@ void cmCTestTestHandler::ProcessDirectory(std::vector &passed, { if (res == cmsysProcess_State_Exited && retVal == 0) { - std::cerr << " Passed\n"; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Passed" << std::endl); passed.push_back(testname); cres.m_Status = cmCTestTestHandler::COMPLETED; } @@ -533,44 +527,44 @@ void cmCTestTestHandler::ProcessDirectory(std::vector &passed, cres.m_Status = cmCTestTestHandler::FAILED; if ( res == cmsysProcess_State_Expired ) { - std::cerr << "***Timeout\n"; + cmCTestLog(m_CTest, HANDLER_OUTPUT, "***Timeout" << std::endl); cres.m_Status = cmCTestTestHandler::TIMEOUT; } else if ( res == cmsysProcess_State_Exception ) { - std::cerr << "***Exception: "; + cmCTestLog(m_CTest, HANDLER_OUTPUT, "***Exception: "); switch ( retVal ) { case cmsysProcess_Exception_Fault: - std::cerr << "SegFault"; + cmCTestLog(m_CTest, HANDLER_OUTPUT, "SegFault"); cres.m_Status = cmCTestTestHandler::SEGFAULT; break; case cmsysProcess_Exception_Illegal: - std::cerr << "Illegal"; + cmCTestLog(m_CTest, HANDLER_OUTPUT, "Illegal"); cres.m_Status = cmCTestTestHandler::ILLEGAL; break; case cmsysProcess_Exception_Interrupt: - std::cerr << "Interrupt"; + cmCTestLog(m_CTest, HANDLER_OUTPUT, "Interrupt"); cres.m_Status = cmCTestTestHandler::INTERRUPT; break; case cmsysProcess_Exception_Numerical: - std::cerr << "Numerical"; + cmCTestLog(m_CTest, HANDLER_OUTPUT, "Numerical"); cres.m_Status = cmCTestTestHandler::NUMERICAL; break; default: - std::cerr << "Other"; + cmCTestLog(m_CTest, HANDLER_OUTPUT, "Other"); cres.m_Status = cmCTestTestHandler::OTHER_FAULT; } - std::cerr << "\n"; + cmCTestLog(m_CTest, HANDLER_OUTPUT, std::endl); } else if ( res == cmsysProcess_State_Error ) { - std::cerr << "***Bad command " << res << "\n"; + cmCTestLog(m_CTest, HANDLER_OUTPUT, "***Bad command " << res << std::endl); cres.m_Status = cmCTestTestHandler::BAD_COMMAND; } else { - std::cerr << "***Failed\n"; + cmCTestLog(m_CTest, HANDLER_OUTPUT, "***Failed" << std::endl); } failed.push_back(testname); } @@ -707,14 +701,11 @@ int cmCTestTestHandler::ExecuteCommands(std::vector& vec) for ( it = vec.begin(); it != vec.end(); ++it ) { int retVal = 0; - if ( m_Verbose ) - { - std::cout << "Run command: " << *it << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Run command: " << *it << std::endl); if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0, true /*m_Verbose*/) || retVal != 0 ) { - std::cerr << "Problem running command: " << *it << std::endl; + cmCTestLog(m_CTest, ERROR, "Problem running command: " << *it << std::endl); return 0; } } @@ -874,10 +865,7 @@ void cmCTestTestHandler::GetListOfTests(tm_ListOfTests* testlist) } if ( found ) { - if ( m_Verbose ) - { - std::cout << "Ignore memcheck: " << *it << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Ignore memcheck: " << *it << std::endl); continue; } } @@ -896,10 +884,7 @@ void cmCTestTestHandler::GetListOfTests(tm_ListOfTests* testlist) } if ( found ) { - if ( m_Verbose ) - { - std::cout << "Ignore test: " << *it << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Ignore test: " << *it << std::endl); continue; } } @@ -1181,7 +1166,7 @@ std::string cmCTestTestHandler::GenerateRegressionImages( << " text=\"text/string\"" << ">File " << filename.c_str() << " not found" << std::endl; - std::cout << "File \"" << filename.c_str() << "\" not found." << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, "File \"" << filename.c_str() << "\" not found." << std::endl); } cxml.erase(measurementfile.start(), measurementfile.end() - measurementfile.start()); } diff --git a/Source/CTest/cmCTestUpdateHandler.cxx b/Source/CTest/cmCTestUpdateHandler.cxx index bbbca97ec..41261d6e3 100644 --- a/Source/CTest/cmCTestUpdateHandler.cxx +++ b/Source/CTest/cmCTestUpdateHandler.cxx @@ -51,7 +51,7 @@ public: std::string m_Message; }; cmCTestUpdateHandlerSVNXMLParser(cmCTestUpdateHandler* up) - : cmXMLParser(), m_UpdateHandler(up), m_MinRevision(-1), m_MaxRevision(-1), m_Verbose(false) + : cmXMLParser(), m_UpdateHandler(up), m_MinRevision(-1), m_MaxRevision(-1) { } @@ -73,8 +73,6 @@ public: int GetMinRevision() { return m_MinRevision; } int GetMaxRevision() { return m_MaxRevision; } - void SetVerbose(bool v) { m_Verbose = v; } - protected: void StartElement(const char* name, const char** atts) { @@ -101,13 +99,10 @@ protected: { if ( strcmp(name, "logentry") == 0 ) { - if ( m_Verbose ) - { - std::cout << "\tRevision: " << m_CommitLog.m_Revision<< std::endl; - std::cout << "\tAuthor: " << m_CommitLog.m_Author.c_str() << std::endl; - std::cout << "\tDate: " << m_CommitLog.m_Date.c_str() << std::endl; - std::cout << "\tMessage: " << m_CommitLog.m_Message.c_str() << std::endl; - } + cmCTestLog(m_UpdateHandler->GetCTestInstance(), HANDLER_VERBOSE_OUTPUT, "\tRevision: " << m_CommitLog.m_Revision<< std::endl + << "\tAuthor: " << m_CommitLog.m_Author.c_str() << std::endl + << "\tDate: " << m_CommitLog.m_Date.c_str() << std::endl + << "\tMessage: " << m_CommitLog.m_Message.c_str() << std::endl); m_Commits.push_back(m_CommitLog); } else if ( strcmp(name, "author") == 0 ) @@ -154,7 +149,6 @@ private: t_VectorOfCommits m_Commits; int m_MinRevision; int m_MaxRevision; - bool m_Verbose; }; //********************************************************************** //---------------------------------------------------------------------- @@ -162,7 +156,6 @@ private: //---------------------------------------------------------------------- cmCTestUpdateHandler::cmCTestUpdateHandler() { - m_Verbose = false; m_CTest = 0; } @@ -211,11 +204,11 @@ int cmCTestUpdateHandler::ProcessHandler() const char* sourceDirectory = this->GetOption("SourceDirectory"); if ( !sourceDirectory ) { - std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl); return -1; } - std::cout << "Updating the repository: " << sourceDirectory << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, "Updating the repository: " << sourceDirectory << std::endl); // Get update command std::string updateCommand = m_CTest->GetCTestConfiguration("UpdateCommand"); @@ -227,7 +220,7 @@ int cmCTestUpdateHandler::ProcessHandler() updateCommand = m_CTest->GetCTestConfiguration("SVNCommand"); if ( updateCommand.empty() ) { - std::cerr << "Cannot find CVSCommand, SVNCommand, or UpdateCommand key in the DartConfiguration.tcl" << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot find CVSCommand, SVNCommand, or UpdateCommand key in the DartConfiguration.tcl" << std::endl); return -1; } else @@ -264,8 +257,8 @@ int cmCTestUpdateHandler::ProcessHandler() std::string extra_update_opts; if ( m_CTest->GetTestModel() == cmCTest::NIGHTLY ) { - struct tm* t = cmCTest::GetNightlyTime(m_CTest->GetCTestConfiguration("NightlyStartTime"), - m_Verbose, m_CTest->GetTomorrowTag()); + struct tm* t = m_CTest->GetNightlyTime(m_CTest->GetCTestConfiguration("NightlyStartTime"), + m_CTest->GetTomorrowTag()); char current_time[1024]; sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d", t->tm_year + 1900, @@ -324,15 +317,12 @@ int cmCTestUpdateHandler::ProcessHandler() // if ( !command.empty() ) { - if ( m_Verbose ) - { - std::cout << "* Get repository information: " << command.c_str() << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "* Get repository information: " << command.c_str() << std::endl); if ( !m_CTest->GetShowOnly() ) { res = cmSystemTools::RunSingleCommand(command.c_str(), &goutput, &retVal, sourceDirectory, - m_Verbose, 0 /*m_TimeOut*/); + m_HandlerVerbose, 0 /*m_TimeOut*/); if ( ofs ) { ofs << "--- Update information ---" << std::endl; @@ -350,7 +340,7 @@ int cmCTestUpdateHandler::ProcessHandler() { std::string currentRevisionString = current_revision_regex.match(1); svn_current_revision = atoi(currentRevisionString.c_str()); - std::cout << " Old revision of repository is: " << svn_current_revision << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Old revision of repository is: " << svn_current_revision << std::endl); } } break; @@ -358,7 +348,7 @@ int cmCTestUpdateHandler::ProcessHandler() } else { - std::cout << "Update with command: " << command << std::endl; + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Update with command: " << command << std::endl); } } @@ -369,15 +359,12 @@ int cmCTestUpdateHandler::ProcessHandler() cmGeneratedFileStream os; if ( !m_CTest->OpenOutputFile(m_CTest->GetCurrentTag(), "Update.xml", os, true) ) { - std::cerr << "Cannot open log file" << std::endl; + cmCTestLog(m_CTest, ERROR, "Cannot open log file" << std::endl); } std::string start_time = m_CTest->CurrentTime(); double elapsed_time_start = cmSystemTools::GetTime(); - if ( m_Verbose ) - { - std::cout << "* Update repository: " << command.c_str() << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "* Update repository: " << command.c_str() << std::endl); if ( !m_CTest->GetShowOnly() ) { command = ""; @@ -388,7 +375,7 @@ int cmCTestUpdateHandler::ProcessHandler() " " + extra_update_opts; res = cmSystemTools::RunSingleCommand(command.c_str(), &goutput, &retVal, sourceDirectory, - m_Verbose, 0 /*m_TimeOut*/); + m_HandlerVerbose, 0 /*m_TimeOut*/); break; case cmCTestUpdateHandler::e_SVN: { @@ -397,11 +384,11 @@ int cmCTestUpdateHandler::ProcessHandler() " " + extra_update_opts; bool res1 = cmSystemTools::RunSingleCommand(command.c_str(), &partialOutput, &retVal, sourceDirectory, - m_Verbose, 0 /*m_TimeOut*/); + m_HandlerVerbose, 0 /*m_TimeOut*/); command = updateCommand + " status"; res = cmSystemTools::RunSingleCommand(command.c_str(), &partialOutput, &retVal, sourceDirectory, - m_Verbose, 0 /*m_TimeOut*/); + m_HandlerVerbose, 0 /*m_TimeOut*/); goutput += partialOutput; res = res && res1; } @@ -465,26 +452,21 @@ int cmCTestUpdateHandler::ProcessHandler() } if ( updateType == cmCTestUpdateHandler::e_SVN ) { - std::cout << " Current revision of repository is: " << svn_latest_revision << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Current revision of repository is: " << svn_latest_revision << std::endl); } - std::cout << " Gathering version information (each . represents one updated file):" << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Gathering version information (each . represents one updated file):" << std::endl); int file_count = 0; for ( cc= 0 ; cc < lines.size(); cc ++ ) { const char* line = lines[cc].c_str(); if ( file_update_line.find(line) ) { - if ( !m_Verbose ) + if ( file_count == 0 ) { - if ( file_count == 0 ) - { - std::cout << " "; - std::cout.flush(); - } - std::cout << "."; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " " << std::flush); } - std::cout.flush(); + cmCTestLog(m_CTest, HANDLER_OUTPUT, "." << std::flush); std::string upChar = file_update_line.match(1); std::string upFile = file_update_line.match(2); char mod = upChar[0]; @@ -495,7 +477,7 @@ int cmCTestUpdateHandler::ProcessHandler() modifiedOrConflict = true; } const char* file = upFile.c_str(); - //std::cout << "Line" << cc << ": " << mod << " - " << file << std::endl; + cmCTestLog(m_CTest, DEBUG, "Line" << cc << ": " << mod << " - " << file << std::endl); std::string output; if ( modifiedOrConflict ) @@ -521,14 +503,11 @@ int cmCTestUpdateHandler::ProcessHandler() } break; } - //std::cout << "Do log: " << logcommand << std::endl; - if ( m_Verbose ) - { - std::cout << "* Get file update information: " << logcommand.c_str() << std::endl; - } + cmCTestLog(m_CTest, DEBUG, "Do log: " << logcommand << std::endl); + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "* Get file update information: " << logcommand.c_str() << std::endl); res = cmSystemTools::RunSingleCommand(logcommand.c_str(), &output, &retVal, sourceDirectory, - m_Verbose, 0 /*m_TimeOut*/); + m_HandlerVerbose, 0 /*m_TimeOut*/); if ( ofs ) { ofs << output << std::endl; @@ -536,7 +515,7 @@ int cmCTestUpdateHandler::ProcessHandler() } if ( res && retVal == 0) { - //std::cout << output << std::endl; + cmCTestLog(m_CTest, DEBUG, output << std::endl); std::string::size_type sline = 0; std::string srevision1 = "Unknown"; std::string sdate1 = "Unknown"; @@ -618,11 +597,11 @@ int cmCTestUpdateHandler::ProcessHandler() srevision1 = str.str(); if (!svn_status_line_regex.find(output)) { - std::cerr << "Bad output from SVN status command: " << output << std::endl; + cmCTestLog(m_CTest, ERROR, "Bad output from SVN status command: " << output << std::endl); } else if ( svn_status_line_regex.match(4) != file ) { - std::cerr << "Bad output from SVN status command. The file name returned: \"" << svn_status_line_regex.match(4) << "\" was different than the file specified: \"" << file << "\"" << std::endl; + cmCTestLog(m_CTest, ERROR, "Bad output from SVN status command. The file name returned: \"" << svn_status_line_regex.match(4) << "\" was different than the file specified: \"" << file << "\"" << std::endl); } else { @@ -638,7 +617,6 @@ int cmCTestUpdateHandler::ProcessHandler() else { cmCTestUpdateHandlerSVNXMLParser parser(this); - parser.SetVerbose(m_Verbose); if ( parser.Parse(output.c_str()) ) { int minrev = parser.GetMinRevision(); @@ -719,12 +697,9 @@ int cmCTestUpdateHandler::ProcessHandler() { srevision2 = srevision1; } - if ( m_Verbose ) - { - std::cout << "File: " << path.c_str() << " / " << fname.c_str() << " was updated by " - << sauthor1.c_str() << " to revision: " << srevision1.c_str() - << " from revision: " << srevision2.c_str() << std::endl; - } + cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "File: " << path.c_str() << " / " << fname.c_str() << " was updated by " + << sauthor1.c_str() << " to revision: " << srevision1.c_str() + << " from revision: " << srevision2.c_str() << std::endl); os << "\t\t" << cmCTest::MakeXMLSafe(fname) << "\n" << "\t\t" << cmCTest::MakeXMLSafe(path) << "\n" @@ -785,25 +760,25 @@ int cmCTestUpdateHandler::ProcessHandler() } if ( file_count ) { - std::cout << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, std::endl); } if ( num_updated ) { - std::cout << " Found " << num_updated << " updated files" << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Found " << num_updated << " updated files" << std::endl); } if ( num_modified ) { - std::cout << " Found " << num_modified << " locally modified files" - << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Found " << num_modified << " locally modified files" + << std::endl); } if ( num_conflicting ) { - std::cout << " Found " << num_conflicting << " conflicting files" - << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Found " << num_conflicting << " conflicting files" + << std::endl); } if ( num_modified == 0 && num_conflicting == 0 && num_updated == 0 ) { - std::cout << " Project is up-to-date" << std::endl; + cmCTestLog(m_CTest, HANDLER_OUTPUT, " Project is up-to-date" << std::endl); } if ( !first_file ) { @@ -826,7 +801,7 @@ int cmCTestUpdateHandler::ProcessHandler() os << "\t" << std::endl; } - //std::cout << "End" << std::endl; + cmCTestLog(m_CTest, DEBUG, "End" << std::endl); std::string end_time = m_CTest->CurrentTime(); os << "\t" << end_time << "\n" << "" << @@ -836,13 +811,13 @@ int cmCTestUpdateHandler::ProcessHandler() if ( num_modified > 0 || num_conflicting > 0 ) { os << "Update error: There are modified or conflicting files in the repository"; - std::cerr << " There are modified or conflicting files in the repository" << std::endl; + cmCTestLog(m_CTest, ERROR, " There are modified or conflicting files in the repository" << std::endl); } if ( updateProducedError ) { os << "Update error: "; os << m_CTest->MakeXMLSafe(goutput); - std::cerr << " Update with command: " << command << " failed" << std::endl; + cmCTestLog(m_CTest, ERROR, " Update with command: " << command << " failed" << std::endl); } os << "" << std::endl; os << "" << std::endl; @@ -854,8 +829,8 @@ int cmCTestUpdateHandler::ProcessHandler() if (! res || retVal ) { - std::cerr << "Error(s) when updating the project" << std::endl; - std::cerr << "Output: " << goutput << std::endl; + cmCTestLog(m_CTest, ERROR, "Error(s) when updating the project" << std::endl); + cmCTestLog(m_CTest, ERROR, "Output: " << goutput << std::endl); return -1; } return count; diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 0ee953e03..af0318531 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -50,16 +50,12 @@ #define DEBUGERR std::cerr << __LINE__ << " "; std::cerr struct tm* cmCTest::GetNightlyTime(std::string str, - bool verbose, bool tomorrowtag) { struct tm* lctime; time_t tctime = time(0); - if ( verbose ) - { - std::cout << "Determine Nightly Start Time" << std::endl; - std::cout << " Specified time: " << str.c_str() << std::endl; - } + cmCTestLog(this, OUTPUT, "Determine Nightly Start Time" << std::endl + << " Specified time: " << str.c_str() << std::endl); //Convert the nightly start time to seconds. Since we are //providing only a time and a timezone, the current date of //the local machine is assumed. Consequently, nightlySeconds @@ -67,18 +63,12 @@ struct tm* cmCTest::GetNightlyTime(std::string str, //will be opened on the date of the current client machine. //As such, this time may be in the past or in the future. time_t ntime = curl_getdate(str.c_str(), &tctime); - if ( verbose ) - { - std::cout << " Get curl time: " << ntime << std::endl; - } + cmCTestLog(this, DEBUG, " Get curl time: " << ntime << std::endl); tctime = time(0); - if ( verbose ) - { - std::cout << " Get the current time: " << tctime << std::endl; - } + cmCTestLog(this, DEBUG, " Get the current time: " << tctime << std::endl); const int dayLength = 24 * 60 * 60; - //std::cout << "Seconds: " << tctime << std::endl; + cmCTestLog(this, DEBUG, "Seconds: " << tctime << std::endl); while ( ntime > tctime ) { // If nightlySeconds is in the past, this is the current @@ -87,29 +77,20 @@ struct tm* cmCTest::GetNightlyTime(std::string str, // dashboard to be opened, so subtract 24 hours to get the // time of the current open dashboard ntime -= dayLength; - //std::cout << "Pick yesterday" << std::endl; - if ( verbose ) - { - std::cout << " Future time, subtract day: " << ntime << std::endl; - } + cmCTestLog(this, DEBUG, "Pick yesterday" << std::endl); + cmCTestLog(this, DEBUG, " Future time, subtract day: " << ntime << std::endl); } while ( tctime > (ntime + dayLength) ) { ntime += dayLength; - if ( verbose ) - { - std::cout << " Past time, add day: " << ntime << std::endl; - } - } - //std::cout << "nightlySeconds: " << ntime << std::endl; - if ( verbose ) - { - std::cout << " Current time: " << tctime - << " Nightly time: " << ntime << std::endl; + cmCTestLog(this, DEBUG, " Past time, add day: " << ntime << std::endl); } + cmCTestLog(this, DEBUG, "nightlySeconds: " << ntime << std::endl); + cmCTestLog(this, DEBUG, " Current time: " << tctime + << " Nightly time: " << ntime << std::endl); if ( tomorrowtag ) { - std::cout << "Use future tag, Add a day" << std::endl; + cmCTestLog(this, OUTPUT, " Use future tag, Add a day" << std::endl); ntime += dayLength; } lctime = gmtime(&ntime); @@ -145,7 +126,7 @@ std::string cmCTest::CurrentTime() { strftime(current_time, 1000, "%a %b %d %H:%M:%S %Z %Y", t); } - //std::cout << "Current_Time: " << current_time << std::endl; + cmCTestLog(this, DEBUG, " Current_Time: " << current_time << std::endl); return cmCTest::MakeXMLSafe(cmCTest::CleanString(current_time)); } @@ -227,6 +208,8 @@ cmCTest::cmCTest() m_BuildNoClean = false; m_BuildTwoConfig = false; m_Verbose = false; + m_Debug = false; + m_Quiet = false; m_ExtraVerbose = false; m_ProduceXML = false; m_ShowOnly = false; @@ -258,6 +241,8 @@ cmCTest::cmCTest() { it->second->SetCTestInstance(this); } + m_OutputLogFile = 0; + m_OutputLogFileLastTag = -1; } cmCTest::~cmCTest() @@ -268,6 +253,7 @@ cmCTest::~cmCTest() delete it->second; it->second = 0; } + this->SetOutputLogFileName(0); } int cmCTest::Initialize(const char* binary_dir, bool new_tag) @@ -291,8 +277,8 @@ int cmCTest::Initialize(const char* binary_dir, bool new_tag) { if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) ) { - std::cerr << "File " << testingDir << " is in the place of the testing directory" - << std::endl; + cmCTestLog(this, ERROR, "File " << testingDir << " is in the place of the testing directory" + << std::endl); return 0; } } @@ -300,8 +286,8 @@ int cmCTest::Initialize(const char* binary_dir, bool new_tag) { if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) ) { - std::cerr << "Cannot create directory " << testingDir - << std::endl; + cmCTestLog(this, ERROR, "Cannot create directory " << testingDir + << std::endl); return 0; } } @@ -341,13 +327,11 @@ int cmCTest::Initialize(const char* binary_dir, bool new_tag) } if ( tag.size() == 0 || new_tag || m_Tests[cmCTest::START_TEST] || m_Tests[ALL_TEST]) { - //std::cout << "TestModel: " << this->GetTestModelString() << std::endl; - //std::cout << "TestModel: " << m_TestModel << std::endl; + cmCTestLog(this, DEBUG, "TestModel: " << this->GetTestModelString() << std::endl); + cmCTestLog(this, DEBUG, "TestModel: " << m_TestModel << std::endl); if ( m_TestModel == cmCTest::NIGHTLY ) { - lctime = cmCTest::GetNightlyTime(m_CTestConfiguration["NightlyStartTime"], - m_ExtraVerbose, - m_TomorrowTag); + lctime = this->GetNightlyTime(m_CTestConfiguration["NightlyStartTime"], m_TomorrowTag); } char datestring[100]; sprintf(datestring, "%04d%02d%02d-%02d%02d", @@ -364,8 +348,8 @@ int cmCTest::Initialize(const char* binary_dir, bool new_tag) ofs << this->GetTestModelString() << std::endl; } ofs.close(); - std::cout << "Create new tag: " << tag << " - " - << this->GetTestModelString() << std::endl; + cmCTestLog(this, OUTPUT, "Create new tag: " << tag << " - " + << this->GetTestModelString() << std::endl); } m_CurrentTag = tag; } @@ -389,7 +373,7 @@ bool cmCTest::UpdateCTestConfiguration() } if ( !cmSystemTools::FileExists(fileName.c_str()) ) { - std::cerr << "Cannot find file: " << fileName.c_str() << std::endl; + cmCTestLog(this, ERROR, "Cannot find file: " << fileName.c_str() << std::endl); return false; } // parse the dart test file @@ -501,7 +485,7 @@ bool cmCTest::SetTest(const char* ttype, bool report) { if ( report ) { - std::cerr << "Don't know about test \"" << ttype << "\" yet..." << std::endl; + cmCTestLog(this, ERROR, "Don't know about test \"" << ttype << "\" yet..." << std::endl); } return false; } @@ -527,9 +511,9 @@ bool cmCTest::OpenOutputFile(const std::string& path, { if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) ) { - std::cerr << "File " << testingDir + cmCTestLog(this, ERROR, "File " << testingDir << " is in the place of the testing directory" - << std::endl; + << std::endl); return false; } } @@ -537,8 +521,8 @@ bool cmCTest::OpenOutputFile(const std::string& path, { if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) ) { - std::cerr << "Cannot create directory " << testingDir - << std::endl; + cmCTestLog(this, ERROR, "Cannot create directory " << testingDir + << std::endl); return false; } } @@ -546,7 +530,7 @@ bool cmCTest::OpenOutputFile(const std::string& path, stream.Open(filename.c_str()); if( !stream ) { - std::cerr << "Problem opening file: " << filename << std::endl; + cmCTestLog(this, ERROR, "Problem opening file: " << filename << std::endl); return false; } if ( compress ) @@ -751,7 +735,7 @@ int cmCTest::GetTestModelFromString(const char* str) } int cmCTest::RunMakeCommand(const char* command, std::string* output, - int* retVal, const char* dir, bool verbose, int timeout, std::ofstream& ofs) + int* retVal, const char* dir, int timeout, std::ofstream& ofs) { std::vector args = cmSystemTools::ParseArguments(command); @@ -786,11 +770,8 @@ int cmCTest::RunMakeCommand(const char* command, std::string* output, char* data; int length; - if ( !verbose ) - { - std::cout << " Each . represents " << tick_len << " bytes of output" << std::endl; - std::cout << " " << std::flush; - } + cmCTestLog(this, HANDLER_OUTPUT, " Each . represents " << tick_len << " bytes of output" << std::endl + << " " << std::flush); while(cmsysProcess_WaitForData(cp, &data, &length, 0)) { if ( output ) @@ -804,34 +785,26 @@ int cmCTest::RunMakeCommand(const char* command, std::string* output, } output->append(data, length); - if ( !verbose ) + while ( output->size() > (tick * tick_len) ) { - while ( output->size() > (tick * tick_len) ) + tick ++; + cmCTestLog(this, HANDLER_OUTPUT, "." << std::flush); + if ( tick % tick_line_len == 0 && tick > 0 ) { - tick ++; - std::cout << "." << std::flush; - if ( tick % tick_line_len == 0 && tick > 0 ) - { - std::cout << " Size: "; - std::cout << int((output->size() / 1024.0) + 1) << "K" << std::endl; - std::cout << " " << std::flush; - } + cmCTestLog(this, HANDLER_OUTPUT, " Size: " + << int((output->size() / 1024.0) + 1) << "K" << std::endl + << " " << std::flush); } } } - if(verbose) - { - std::cout.write(data, length); - std::cout.flush(); - } + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, cmCTestLogWrite(data, length)); if ( ofs ) { - ofs.write(data, length); - ofs.flush(); + ofs << cmCTestLogWrite(data, length); } } - std::cout << " Size of output: "; - std::cout << int(output->size() / 1024.0) << "K" << std::endl; + cmCTestLog(this, OUTPUT, " Size of output: " + << int(output->size() / 1024.0) << "K" << std::endl); cmsysProcess_WaitForExit(cp, 0); @@ -844,11 +817,11 @@ int cmCTest::RunMakeCommand(const char* command, std::string* output, else if(result == cmsysProcess_State_Exception) { *retVal = cmsysProcess_GetExitException(cp); - std::cout << "There was an exception: " << *retVal << std::endl; + cmCTestLog(this, WARNING, "There was an exception: " << *retVal << std::endl); } else if(result == cmsysProcess_State_Expired) { - std::cout << "There was a timeout" << std::endl; + cmCTestLog(this, WARNING, "There was a timeout" << std::endl); } else if(result == cmsysProcess_State_Error) { @@ -892,11 +865,8 @@ int cmCTest::RunTest(std::vector argv, } cmSystemTools::ChangeDirectory(oldpath.c_str()); - if(m_ExtraVerbose) - { - std::cout << "Internal cmCTest object used to run test.\n"; - std::cout << *output << "\n"; - } + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Internal cmCTest object used to run test." << std::endl + << *output << std::endl); return cmsysProcess_State_Exited; } std::vector tempOutput; @@ -907,7 +877,7 @@ int cmCTest::RunTest(std::vector argv, cmsysProcess* cp = cmsysProcess_New(); cmsysProcess_SetCommand(cp, &*argv.begin()); - // std::cout << "Command is: " << argv[0] << std::endl; + cmCTestLog(this, DEBUG, "Command is: " << argv[0] << std::endl); if(cmSystemTools::GetRunCommandHideConsole()) { cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1); @@ -923,15 +893,10 @@ int cmCTest::RunTest(std::vector argv, { tempOutput.insert(tempOutput.end(), data, data+length); } - if ( m_ExtraVerbose ) - { - std::cout.write(data, length); - std::cout.flush(); - } + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, cmCTestLogWrite(data, length)); if ( log ) { log->write(data, length); - log->flush(); } } @@ -940,10 +905,7 @@ int cmCTest::RunTest(std::vector argv, { output->append(&*tempOutput.begin(), tempOutput.size()); } - if ( m_ExtraVerbose ) - { - std::cout << "-- Process completed" << std::endl; - } + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "-- Process completed" << std::endl); int result = cmsysProcess_GetState(cp); @@ -957,22 +919,14 @@ int cmCTest::RunTest(std::vector argv, std::string outerr = "\n*** Exception executing: "; outerr += cmsysProcess_GetExceptionString(cp); *output += outerr; - if ( m_ExtraVerbose ) - { - std::cout << outerr.c_str() << "\n"; - std::cout.flush(); - } + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr.c_str() << std::endl << std::flush); } else if(result == cmsysProcess_State_Error) { std::string outerr = "\n*** ERROR executing: "; outerr += cmsysProcess_GetErrorString(cp); *output += outerr; - if ( m_ExtraVerbose ) - { - std::cout << outerr.c_str() << "\n"; - std::cout.flush(); - } + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr.c_str() << std::endl << std::flush); } cmsysProcess_Delete(cp); @@ -1009,7 +963,7 @@ int cmCTest::GenerateCTestNotesOutput(std::ostream& os, const cmCTest::tm_Vector for ( it = files.begin(); it != files.end(); it ++ ) { - std::cout << "\tAdd file: " << it->c_str() << std::endl; + cmCTestLog(this, OUTPUT, "\tAdd file: " << it->c_str() << std::endl); std::string note_time = this->CurrentTime(); os << "MakeXMLSafe(it->c_str()) << "\">\n" << "" << note_time << "\n" @@ -1027,7 +981,7 @@ int cmCTest::GenerateCTestNotesOutput(std::ostream& os, const cmCTest::tm_Vector else { os << "Problem reading file: " << it->c_str() << std::endl; - std::cerr << "Problem reading file: " << it->c_str() << " while creating notes" << std::endl; + cmCTestLog(this, ERROR, "Problem reading file: " << it->c_str() << " while creating notes" << std::endl); } os << "\n" << "" << std::endl; @@ -1042,7 +996,7 @@ int cmCTest::GenerateNotesFile(const std::vector &files) cmGeneratedFileStream ofs; if ( !this->OpenOutputFile(m_CurrentTag, "Notes.xml", ofs) ) { - std::cerr << "Cannot open notes file" << std::endl; + cmCTestLog(this, ERROR, "Cannot open notes file" << std::endl); return 1; } @@ -1059,7 +1013,7 @@ int cmCTest::GenerateNotesFile(const char* cfiles) std::vector files; - std::cout << "Create notes file" << std::endl; + cmCTestLog(this, OUTPUT, "Create notes file" << std::endl); files = cmSystemTools::SplitString(cfiles, ';'); if ( files.size() == 0 ) @@ -1092,6 +1046,10 @@ int cmCTest::Run(std::vectorconst& args, std::string* output) cmSystemTools::ReplaceString(this->m_ConfigType, ".\\", ""); } + if( arg.find("-Q",0) == 0 || arg.find("--quiet",0) == 0 ) + { + this->m_Quiet = true; + } if( arg.find("-V",0) == 0 || arg.find("--verbose",0) == 0 ) { this->m_Verbose = true; @@ -1115,6 +1073,12 @@ int cmCTest::Run(std::vectorconst& args, std::string* output) ch->AddConfigurationScript(args[i].c_str()); } + if( ( arg.find("-O",0) == 0 || arg.find("--output-log") == 0 ) && i < args.size() - 1 ) + { + i++; + this->SetOutputLogFileName(args[i].c_str()); + } + if( arg.find("--tomorrow-tag",0) == 0 ) { m_TomorrowTag = true; @@ -1312,8 +1276,8 @@ int cmCTest::Run(std::vectorconst& args, std::string* output) else { performSomeTest = false; - std::cerr << "CTest -D called with incorrect option: " << targ << std::endl; - std::cerr << "Available options are:" << std::endl + cmCTestLog(this, ERROR, "CTest -D called with incorrect option: " << targ << std::endl); + cmCTestLog(this, ERROR, "Available options are:" << std::endl << " " << ctestExec << " -D Continuous" << std::endl << " " << ctestExec << " -D Continuous(Start|Update|Configure|Build)" << std::endl << " " << ctestExec << " -D Continuous(Test|Coverage|MemCheck|Submit)" << std::endl @@ -1323,8 +1287,7 @@ int cmCTest::Run(std::vectorconst& args, std::string* output) << " " << ctestExec << " -D Nightly" << std::endl << " " << ctestExec << " -D Nightly(Start|Update|Configure|Build)" << std::endl << " " << ctestExec << " -D Nightly(Test|Coverage|MemCheck|Submit)" << std::endl - << " " << ctestExec << " -D NightlyMemoryCheck" << std::endl; - ; + << " " << ctestExec << " -D NightlyMemoryCheck" << std::endl); } } @@ -1336,8 +1299,8 @@ int cmCTest::Run(std::vectorconst& args, std::string* output) if ( !this->SetTest(args[i].c_str(), false) ) { performSomeTest = false; - std::cerr << "CTest -T called with incorrect option: " << args[i].c_str() << std::endl; - std::cerr << "Available options are:" << std::endl + cmCTestLog(this, ERROR, "CTest -T called with incorrect option: " << args[i].c_str() << std::endl); + cmCTestLog(this, ERROR, "Available options are:" << std::endl << " " << ctestExec << " -T all" << std::endl << " " << ctestExec << " -T start" << std::endl << " " << ctestExec << " -T update" << std::endl @@ -1347,7 +1310,7 @@ int cmCTest::Run(std::vectorconst& args, std::string* output) << " " << ctestExec << " -T coverage" << std::endl << " " << ctestExec << " -T memcheck" << std::endl << " " << ctestExec << " -T notes" << std::endl - << " " << ctestExec << " -T submit" << std::endl; + << " " << ctestExec << " -T submit" << std::endl); } } @@ -1371,11 +1334,11 @@ int cmCTest::Run(std::vectorconst& args, std::string* output) else { performSomeTest = false; - std::cerr << "CTest -M called with incorrect option: " << str.c_str() << std::endl; - std::cerr << "Available options are:" << std::endl + cmCTestLog(this, ERROR, "CTest -M called with incorrect option: " << str.c_str() << std::endl); + cmCTestLog(this, ERROR, "Available options are:" << std::endl << " " << ctestExec << " -M Continuous" << std::endl << " " << ctestExec << " -M Experimental" << std::endl - << " " << ctestExec << " -M Nightly" << std::endl; + << " " << ctestExec << " -M Nightly" << std::endl); } } @@ -1425,7 +1388,7 @@ int cmCTest::Run(std::vectorconst& args, std::string* output) } else { - std::cerr << "--build-and-test must have source and binary dir\n"; + cmCTestLog(this, ERROR, "--build-and-test must have source and binary dir" << std::endl); } } if(arg.find("--build-target",0) == 0 && i < args.size() - 1) @@ -1530,6 +1493,7 @@ int cmCTest::Run(std::vectorconst& args, std::string* output) else { m_ExtraVerbose = m_Verbose; + m_Verbose = true; cmCTest::t_TestingHandlers::iterator it; for ( it = m_TestingHandlers.begin(); it != m_TestingHandlers.end(); ++ it ) { @@ -1666,7 +1630,7 @@ int cmCTest::RunCMake(std::string* outstring, cmOStringStream &out, } else { - std::cerr << out.str() << "\n"; + cmCTestLog(this, ERROR, out.str() << std::endl); } return 1; } @@ -1685,7 +1649,7 @@ int cmCTest::RunCMake(std::string* outstring, cmOStringStream &out, } else { - std::cerr << out.str() << "\n"; + cmCTestLog(this, ERROR, out.str() << std::endl); } return 1; } @@ -1874,7 +1838,7 @@ int cmCTest::RunCMakeAndTest(std::string* outstring) } else { - std::cerr << out.str(); + cmCTestLog(this, ERROR, out.str()); } // return to the original directory cmSystemTools::ChangeDirectory(cwd.c_str()); @@ -1917,7 +1881,7 @@ int cmCTest::RunCMakeAndTest(std::string* outstring) } else { - std::cout << out.str() << "\n"; + cmCTestLog(this, OUTPUT, out.str() << std::endl); } return retval; } @@ -1952,7 +1916,7 @@ int cmCTest::ReadCustomConfigurationFileTree(const char* dir) (!lg->GetMakefile()->ReadListFile(0, fname.c_str()) || cmSystemTools::GetErrorOccuredFlag() ) ) { - std::cerr << "Problem reading custom configuration" << std::endl; + cmCTestLog(this, ERROR, "Problem reading custom configuration" << std::endl); } dirs.erase(dirs.end()-1, dirs.end()); cmSystemTools::SimpleGlob(rexpr, ndirs, -1); @@ -2117,3 +2081,109 @@ bool cmCTest::SetCTestConfigurationFromCMakeVariable(cmMakefile* mf, const char* this->SetCTestConfiguration(dconfig, ctvar); return true; } + +void cmCTest::SetOutputLogFileName(const char* name) +{ + if ( m_OutputLogFile) + { + delete m_OutputLogFile; + m_OutputLogFile= 0; + } + if ( name ) + { + m_OutputLogFile = new cmGeneratedFileStream(name); + } +} + +static const char* cmCTestStringLogType[] = +{ + "DEBUG", + "OUTPUT", + "HANDLER_OUTPUT", + "HANDLER_VERBOSE_OUTPUT", + "WARNING", + "ERROR", + 0 +}; + +#ifdef cerr +# undef cerr +#endif +#ifdef cout +# undef cout +#endif + +void cmCTest::Log(int logType, const char* msg) +{ + if ( !msg || !*msg ) + { + return; + } + if ( m_OutputLogFile ) + { + bool display = true; + if ( logType == cmCTest::DEBUG && !m_Debug ) { display = false; } + if ( logType == cmCTest::HANDLER_VERBOSE_OUTPUT && !m_Debug && !m_ExtraVerbose ) { display = false; } + if ( display ) + { + if ( logType != m_OutputLogFileLastTag ) + { + *m_OutputLogFile << "["; + if ( logType >= OTHER || logType < 0 ) + { + *m_OutputLogFile << "OTHER"; + } + else + { + *m_OutputLogFile << cmCTestStringLogType[logType]; + } + *m_OutputLogFile << "] " << std::endl << std::flush; + } + *m_OutputLogFile << msg << std::flush; + if ( logType != m_OutputLogFileLastTag ) + { + *m_OutputLogFile << std::endl << std::flush; + m_OutputLogFileLastTag = logType; + } + } + } + if ( !m_Quiet ) + { + switch ( logType ) + { + case DEBUG: + if ( m_Debug ) + { + std::cout << msg; + std::cout.flush(); + } + break; + case OUTPUT: case HANDLER_OUTPUT: + if ( m_Debug || m_Verbose ) + { + std::cout << msg; + std::cout.flush(); + } + break; + case HANDLER_VERBOSE_OUTPUT: + if ( m_Debug || m_ExtraVerbose ) + { + std::cout << msg; + std::cout.flush(); + } + break; + case WARNING: + std::cerr << msg; + std::cerr.flush(); + break; + case ERROR: + std::cerr << msg; + std::cerr.flush(); + break; + default: + std::cout << msg; + std::cout.flush(); + } + } +} + diff --git a/Source/cmCTest.h b/Source/cmCTest.h index b3996ffc5..33144b5f6 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -18,7 +18,6 @@ #ifndef cmCTest_h #define cmCTest_h - #include "cmStandardIncludes.h" #include "cmListFileCache.h" #include @@ -28,6 +27,23 @@ class cmMakefile; class cmCTestGenericHandler; class cmGeneratedFileStream; +#define cmCTestLog(ctSelf, logType, msg) \ + do { \ + cmOStringStream cmCTestLog_msg; \ + cmCTestLog_msg << msg; \ + (ctSelf)->Log(cmCTest::logType, cmCTestLog_msg.str().c_str());\ + } while ( 0 ) + +#ifdef cerr +# undef cerr +#endif +#define cerr no_cerr_use_cmCTestLog + +#ifdef cout +# undef cout +#endif +#define cout no_cout_use_cmCTestLog + class cmCTest { public: @@ -57,9 +73,8 @@ public: /* * A utility function that returns the nightly time */ - static struct tm* GetNightlyTime(std::string str, - bool verbose, - bool tomorrowtag); + struct tm* GetNightlyTime(std::string str, + bool tomorrowtag); /* * Is the tomorrow tag set? @@ -134,7 +149,7 @@ public: //! Run command specialized for make and configure. Returns process status // and retVal is return value or exception. int RunMakeCommand(const char* command, std::string* output, - int* retVal, const char* dir, bool verbose, int timeout, + int* retVal, const char* dir, int timeout, std::ofstream& ofs); /* @@ -206,6 +221,24 @@ public: //! Create XML file that contains all the notes specified int GenerateNotesFile(const std::vector &files); + + //! Set the output log file name + void SetOutputLogFileName(const char* name); + + //! Various log types + enum { + DEBUG = 0, + OUTPUT, + HANDLER_OUTPUT, + HANDLER_VERBOSE_OUTPUT, + WARNING, + ERROR, + OTHER + }; + + //! Add log to the output + void Log(int logType, const char* msg); + private: std::string m_ConfigType; bool m_Verbose; @@ -302,6 +335,29 @@ private: void FindRunningCMake(const char* arg0); bool m_SuppressUpdatingCTestConfiguration; + + bool m_Debug; + bool m_Quiet; + + + cmGeneratedFileStream* m_OutputLogFile; + int m_OutputLogFileLastTag; }; +class cmCTestLogWrite +{ +public: + cmCTestLogWrite(const char* data, size_t length) : Data(data), Length(length) {} + + const char* Data; + size_t Length; +}; + +inline std::ostream& operator<< (std::ostream& os, const cmCTestLogWrite& c) +{ + os.write(c.Data, c.Length); + os.flush(); + return os; +} + #endif diff --git a/Source/ctest.cxx b/Source/ctest.cxx index d26257027..cfcf5ce4b 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -59,6 +59,12 @@ static const cmDocumentationEntry cmDocumentationOptions[] = {"-V,--verbose", "Enable verbose output from tests.", "Test output is normally suppressed and only summary information is " "displayed. This option will show all test output."}, + {"-Q,--quiet", "Make ctest quiet.", + "This option will suppress all the output. The output log file will still be " + "generated if the --output-log is specified. Options such as --verbose, " + "--extra-verbose, and --debug are ignored if --quiet is specified."}, + {"-O , --output-log ", "Output to log file", + "This option tells ctest to write all its output to a log file."}, {"-N,--show-only", "Disable actual execution of tests.", "This option tells ctest to list the tests that would be run but not " "actually run them. Useful in conjunction with the -R and -E options."}, @@ -158,10 +164,11 @@ int main (int argc, char *argv[]) { cmSystemTools::EnableMSVCDebugHook(); int nocwd = 0; + cmCTest inst; if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 ) { - std::cerr << "Current working directory cannot be established." << std::endl; + cmCTestLog(&inst, ERROR, "Current working directory cannot be established." << std::endl); nocwd = 1; } @@ -175,9 +182,9 @@ int main (int argc, char *argv[]) { if(argc == 1) { - std::cout << "*********************************" << std::endl; - std::cout << "No test configuration file found!" << std::endl; - std::cout << "*********************************" << std::endl; + cmCTestLog(&inst, ERROR, "*********************************" << std::endl + << "No test configuration file found!" << std::endl + << "*********************************" << std::endl); } cmDocumentation doc; if(doc.CheckOptions(argc, argv) || nocwd) @@ -189,7 +196,11 @@ int main (int argc, char *argv[]) doc.SetDescriptionSection(cmDocumentationDescription); doc.SetOptionsSection(cmDocumentationOptions); doc.SetSeeAlsoList(cmDocumentationSeeAlso); +#ifdef cout +# undef cout +#endif return doc.PrintRequestedDocumentation(std::cout)? 0:1; +#define cout no_cout_use_cmCTestLog } } @@ -198,7 +209,6 @@ int main (int argc, char *argv[]) std::string comspec = "cmw9xcom.exe"; cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str()); #endif - cmCTest inst; // copy the args to a vector std::vector args; for(int i =0; i < argc; ++i) @@ -208,7 +218,7 @@ int main (int argc, char *argv[]) // run ctest std::string output; int res = inst.Run(args,&output); - std::cout << output; + cmCTestLog(&inst, OUTPUT, output); cmListFileCache::ClearCache(); return res;