From b0b5ffcf5caf85cc47ec6a38e3f3e801f8c73bb0 Mon Sep 17 00:00:00 2001 From: Zach Mullen Date: Fri, 28 Aug 2009 15:08:03 -0400 Subject: [PATCH] MemCheck should now work again in ctest --- Source/CTest/cmCTestMemCheckHandler.cxx | 26 +------- Source/CTest/cmCTestMemCheckHandler.h | 11 +--- Source/CTest/cmCTestMultiProcessHandler.cxx | 4 +- Source/CTest/cmCTestRunTest.cxx | 67 +++++++++++++++++---- Source/CTest/cmCTestRunTest.h | 2 + Source/CTest/cmCTestTestHandler.cxx | 9 +-- Source/CTest/cmCTestTestHandler.h | 13 +--- 7 files changed, 67 insertions(+), 65 deletions(-) diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index a0d74a3048..60b82e7122 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -249,15 +249,14 @@ int cmCTestMemCheckHandler::PostProcessHandler() //---------------------------------------------------------------------- void cmCTestMemCheckHandler::GenerateTestCommand( - std::vector& args) + std::vector& args) { std::vector::size_type pp; - args.push_back(this->MemoryTester.c_str()); std::string memcheckcommand = ""; memcheckcommand = this->MemoryTester; for ( pp = 0; pp < this->MemoryTesterOptionsParsed.size(); pp ++ ) { - args.push_back(this->MemoryTesterOptionsParsed[pp].c_str()); + args.push_back(this->MemoryTesterOptionsParsed[pp]); memcheckcommand += " "; memcheckcommand += cmSystemTools::EscapeSpaces( this->MemoryTesterOptionsParsed[pp].c_str()); @@ -867,27 +866,6 @@ bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput( } return true; } -//TODO ZACH move this logic into cmCTestRunTest -void -cmCTestMemCheckHandler::ProcessOneTest(cmCTestTestProperties *props, - std::vector &passed, - std::vector &failed, - int count, int tmsize) -{ - // run parent test - cmCTestTestHandler::ProcessOneTest(props, passed, failed, count, tmsize); - cmCTestTestResult& res = this->TestResults[this->TestResults.size()-1]; - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "process test output now: " - << props->Name.c_str() << " " << res.Name.c_str() << std::endl); - if( this->MemoryTesterStyle == cmCTestMemCheckHandler::BOUNDS_CHECKER) - { - this->PostProcessBoundsCheckerTest(res); - } - else if(this->MemoryTesterStyle == cmCTestMemCheckHandler::PURIFY ) - { - this->PostProcessPurifyTest(res); - } -} // This method puts the bounds checker output file into the output // for the test diff --git a/Source/CTest/cmCTestMemCheckHandler.h b/Source/CTest/cmCTestMemCheckHandler.h index 8a9e4e7a56..c50d0ffffd 100644 --- a/Source/CTest/cmCTestMemCheckHandler.h +++ b/Source/CTest/cmCTestMemCheckHandler.h @@ -30,6 +30,7 @@ class cmMakefile; */ class cmCTestMemCheckHandler : public cmCTestTestHandler { + friend class cmCTestRunTest; public: cmTypeMacro(cmCTestMemCheckHandler, cmCTestTestHandler); @@ -41,7 +42,7 @@ public: protected: virtual int PreProcessHandler(); virtual int PostProcessHandler(); - virtual void GenerateTestCommand(std::vector& args); + virtual void GenerateTestCommand(std::vector& args); private: @@ -121,13 +122,7 @@ private: std::string& log, int* results); bool ProcessMemCheckBoundsCheckerOutput(const std::string& str, std::string& log, int* results); - /** - * Run one test - */ - virtual void ProcessOneTest(cmCTestTestProperties *props, - std::vector &passed, - std::vector &failed, - int count, int tmsize); + void PostProcessPurifyTest(cmCTestTestResult& res); void PostProcessBoundsCheckerTest(cmCTestTestResult& res); }; diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index 88d16963b1..157e18767e 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -247,9 +247,9 @@ void cmCTestMultiProcessHandler::PrintTestList() testRun.SetTestProperties(&p); testRun.ComputeArguments(); //logs the command in verbose mode - cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(3) + cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(3) << count << "/"); - cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(3) + cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(3) << this->Total << " "); if (this->TestHandler->MemCheck) { diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 9214a95574..bbc23b2644 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -16,6 +16,7 @@ =========================================================================*/ #include "cmCTestRunTest.h" +#include "cmCTestMemCheckHandler.h" #include "cmCTest.h" #include "cmSystemTools.h" @@ -245,10 +246,35 @@ bool cmCTestRunTest::EndTest(int completed, int total) this->TestResult.ExecutionTime = this->TestProcess->GetTotalTime(); this->TestHandler->TestResults.push_back( this->TestResult ); + this->MemCheckPostProcess(); + delete this->TestProcess; return passed; } +//-------------------------------------------------------------- +void cmCTestRunTest::MemCheckPostProcess() +{ + if(!this->TestHandler->MemCheck) + { + return; + } + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index + << ": process test output now: " + << this->TestProperties->Name.c_str() << " " + << this->TestResult.Name.c_str() << std::endl); + cmCTestMemCheckHandler * handler = static_cast + (this->TestHandler); + if(handler->MemoryTesterStyle == cmCTestMemCheckHandler::BOUNDS_CHECKER) + { + handler->PostProcessBoundsCheckerTest(this->TestResult); + } + else if(handler->MemoryTesterStyle == cmCTestMemCheckHandler::PURIFY) + { + handler->PostProcessPurifyTest(this->TestResult); + } +} + void cmCTestRunTest::SetTestHandler(cmCTestTestHandler * handler) { this->TestHandler = handler; @@ -292,21 +318,36 @@ bool cmCTestRunTest::StartTest() void cmCTestRunTest::ComputeArguments() { - std::vector& args = this->TestProperties->Args; - // find the test executable - this->ActualCommand - = this->TestHandler->FindTheExecutable(args[1].c_str()); - this->TestCommand - = cmSystemTools::ConvertToOutputPath(this->ActualCommand.c_str()); - // add the arguments std::vector::const_iterator j = this->TestProperties->Args.begin(); ++j; // skip test name - ++j; // skip command as it is in actualCommand - //TODO ZACH the problem is here for memcheck. We need to call -//memcheckhandler.GenerateTestCommand BEFORE we run the process. -// this->TestHandler->GenerateTestCommand(this->Arguments); + // find the test executable + if(this->TestHandler->MemCheck) + { + cmCTestMemCheckHandler * handler = static_cast + (this->TestHandler); + this->ActualCommand = handler->MemoryTester.c_str(); + } + else + { + this->ActualCommand = + this->TestHandler->FindTheExecutable( + this->TestProperties->Args[1].c_str()); + ++j; //skip the executable (it will be actualCommand) + } + this->TestCommand + = cmSystemTools::ConvertToOutputPath(this->ActualCommand.c_str()); + + //Prepends memcheck args to our command string + this->TestHandler->GenerateTestCommand(this->Arguments); + for(std::vector::iterator i = this->Arguments.begin(); + i != this->Arguments.end(); ++i) + { + this->TestCommand += " "; + this->TestCommand += cmSystemTools::EscapeSpaces(j->c_str()); + } + for(;j != this->TestProperties->Args.end(); ++j) { this->TestCommand += " "; @@ -413,10 +454,10 @@ void cmCTestRunTest::WriteLogOutputTop(int completed, int total) std::string outname = this->TestProperties->Name + " "; outname.resize(maxTestNameWidth, '.'); - *this->TestHandler->LogFile << this->TestProperties->Index << "/" + *this->TestHandler->LogFile << this->TestProperties->Index << "/" << this->TestHandler->TotalNumberOfTests << " Testing: " << this->TestProperties->Name << std::endl; - *this->TestHandler->LogFile << this->TestProperties->Index << "/" + *this->TestHandler->LogFile << this->TestProperties->Index << "/" << this->TestHandler->TotalNumberOfTests << " Test: " << this->TestProperties->Name.c_str() << std::endl; *this->TestHandler->LogFile << "Command: \"" << this->ActualCommand << "\""; diff --git a/Source/CTest/cmCTestRunTest.h b/Source/CTest/cmCTestRunTest.h index 521759afad..1fbe5bb48d 100644 --- a/Source/CTest/cmCTestRunTest.h +++ b/Source/CTest/cmCTestRunTest.h @@ -64,6 +64,8 @@ private: bool CreateProcess(double testTimeOut, std::vector* environment); void WriteLogOutputTop(int completed, int total); + //Run post processing of the process output for MemCheck + void MemCheckPostProcess(); cmCTestTestHandler::cmCTestTestProperties * TestProperties; //Pointer back to the "parent"; the handler that invoked this test run diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index f2e917a7c3..af7c222602 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -709,7 +709,7 @@ void cmCTestTestHandler::PrintLabelSummary() } } } - +/* //---------------------------------------------------------------------- void cmCTestTestHandler::ProcessOneTest(cmCTestTestProperties *it, std::vector &passed, @@ -791,9 +791,6 @@ void cmCTestTestHandler::ProcessOneTest(cmCTestTestProperties *it, } arguments.push_back(0); - /** - * Run an executable command and put the stdout in output. - */ std::string output; int retVal = 0; @@ -1026,7 +1023,7 @@ void cmCTestTestHandler::ProcessOneTest(cmCTestTestProperties *it, cres.CompletionStatus = "Completed"; this->TestResults.push_back( cres ); } - +*/ //---------------------------------------------------------------------- void cmCTestTestHandler::CheckLabelFilterInclude(cmCTestTestProperties& it) { @@ -1363,7 +1360,7 @@ void cmCTestTestHandler::ProcessDirectory(std::vector &passed, } //---------------------------------------------------------------------- -void cmCTestTestHandler::GenerateTestCommand(std::vector&) +void cmCTestTestHandler::GenerateTestCommand(std::vector&) { } diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index 55fb853e31..4c7cbc83a0 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -135,7 +135,7 @@ protected: // comput a final test list virtual int PreProcessHandler(); virtual int PostProcessHandler(); - virtual void GenerateTestCommand(std::vector& args); + virtual void GenerateTestCommand(std::vector& args); int ExecuteCommands(std::vector& vec); void WriteTestResultHeader(std::ostream& os, cmCTestTestResult* result); @@ -157,17 +157,6 @@ protected: bool MemCheck; int CustomMaximumPassedTestOutputSize; int CustomMaximumFailedTestOutputSize; -protected: - /** - * Run one test - */ - virtual void ProcessOneTest(cmCTestTestProperties *props, - std::vector &passed, - std::vector &failed, - int count, int tmsize); - - - public: enum { // Program statuses NOT_RUN = 0,