From 5517e17bf936ad243536e793dc792f4dfccf2497 Mon Sep 17 00:00:00 2001 From: Zach Mullen Date: Fri, 4 Sep 2009 13:50:06 -0400 Subject: [PATCH] Fixed ctest output processing. Should now display output as it occurs, as well as be able to consume multiple lines if they exist within the timeout. --- Source/CTest/cmCTestRunTest.cxx | 40 ++++++++++++++++++++------------- Source/CTest/cmProcess.cxx | 32 ++++++++++++++------------ Source/CTest/cmProcess.h | 5 +++-- 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 85e8601d2b..d471c6c3f4 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -38,26 +38,36 @@ bool cmCTestRunTest::IsRunning() void cmCTestRunTest::CheckOutput() { std::string out, err; - int pipe = this->TestProcess->CheckOutput(.1); + this->TestProcess->CheckOutput(.1); //start our timeout for reading the process output double clock_start = cmSystemTools::GetTime(); - while(this->TestProcess->GetNextOutputLine(out, err)) + int pipe; + bool gotStdOut = false; + bool gotStdErr = false; + while((pipe = this->TestProcess-> + GetNextOutputLine(out, err, gotStdOut, gotStdErr) ) + != cmsysProcess_Pipe_Timeout) { - - if(pipe == cmsysProcess_Pipe_STDOUT) + if(pipe == cmsysProcess_Pipe_STDOUT || + pipe == cmsysProcess_Pipe_STDERR) { - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - this->GetIndex() << ": " << out << std::endl); - this->ProcessOutput += out; - this->ProcessOutput += "\n"; - } - else if(pipe == cmsysProcess_Pipe_STDERR) - { - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - this->GetIndex() << ": " << err << std::endl); - this->ProcessOutput += err; - this->ProcessOutput += "\n"; + if(gotStdErr) + { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + this->GetIndex() << ": " << err << std::endl); + this->ProcessOutput += err; + this->ProcessOutput += "\n"; + } + if(gotStdOut) + { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + this->GetIndex() << ": " << out << std::endl); + this->ProcessOutput += out; + this->ProcessOutput += "\n"; + } } + gotStdOut = false; + gotStdErr = false; //timeout while reading process output (could denote infinite output) if(cmSystemTools::GetTime() - clock_start > .1) { diff --git a/Source/CTest/cmProcess.cxx b/Source/CTest/cmProcess.cxx index 8f5b1127c9..ed1c531dc5 100644 --- a/Source/CTest/cmProcess.cxx +++ b/Source/CTest/cmProcess.cxx @@ -74,15 +74,19 @@ bool cmProcess::StartProcess() == cmsysProcess_State_Executing); } -bool cmProcess::GetNextOutputLine(std::string& stdOutLine, - std::string& stdErrLine) +int cmProcess::GetNextOutputLine(std::string& stdOutLine, + std::string& stdErrLine, + bool& gotStdOut, + bool& gotStdErr) { if(this->StdErrorBuffer.empty() && this->StdOutBuffer.empty()) { - return false; + return cmsysProcess_Pipe_Timeout; } stdOutLine = ""; stdErrLine = ""; + + this->LastOutputPipe = cmsysProcess_Pipe_Timeout; std::vector::iterator outiter = this->StdOutBuffer.begin(); std::vector::iterator erriter = @@ -107,7 +111,8 @@ bool cmProcess::GetNextOutputLine(std::string& stdOutLine, } this->StdOutBuffer.erase(this->StdOutBuffer.begin(), outiter+1); this->LastOutputPipe = cmsysProcess_Pipe_STDOUT; - return true; + gotStdOut = true; + break; } } @@ -131,15 +136,16 @@ bool cmProcess::GetNextOutputLine(std::string& stdOutLine, } this->StdErrorBuffer.erase(this->StdErrorBuffer.begin(), erriter+1); this->LastOutputPipe = cmsysProcess_Pipe_STDERR; - return true; + gotStdErr = true; + break; } } //If we get here, we have stuff waiting in the buffers, but no newline - return false; + return this->LastOutputPipe; } // return true if there is a new line of data // return false if there is no new data -int cmProcess::CheckOutput(double timeout) +void cmProcess::CheckOutput(double timeout) { // Wait for data from the process. int length; @@ -153,14 +159,13 @@ int cmProcess::CheckOutput(double timeout) { // Timeout has been exceeded. this->LastOutputPipe = pipe; - return pipe; + return; } else if(pipe == cmsysProcess_Pipe_STDOUT) { - // Append to the stdout buffer. + // Append to the stdout buffer. this->StdOutBuffer.insert(this->StdOutBuffer.end(), data, data+length); this->LastOutputPipe = pipe; - return pipe; } else if(pipe == cmsysProcess_Pipe_STDERR) { @@ -168,7 +173,6 @@ int cmProcess::CheckOutput(double timeout) this->StdErrorBuffer.insert(this->StdErrorBuffer.end(), data, data+length); this->LastOutputPipe = pipe; - return pipe; } else if(pipe == cmsysProcess_Pipe_None) { @@ -176,17 +180,17 @@ int cmProcess::CheckOutput(double timeout) if(!this->StdOutBuffer.empty()) { this->LastOutputPipe = cmsysProcess_Pipe_STDOUT; - return this->LastOutputPipe; + return; } else if(!this->StdErrorBuffer.empty()) { this->LastOutputPipe = cmsysProcess_Pipe_STDERR; - return this->LastOutputPipe; + return; } else { this->LastOutputPipe = cmsysProcess_Pipe_None; - return this->LastOutputPipe; + return; } } } diff --git a/Source/CTest/cmProcess.h b/Source/CTest/cmProcess.h index 9def3908fe..2d11e61863 100644 --- a/Source/CTest/cmProcess.h +++ b/Source/CTest/cmProcess.h @@ -41,7 +41,7 @@ public: bool StartProcess(); // return process state - int CheckOutput(double timeout); + void CheckOutput(double timeout); // return the process status int GetProcessStatus(); // return true if the process is running @@ -52,7 +52,8 @@ public: void SetId(int id) { this->Id = id;} int GetExitValue() { return this->ExitValue;} double GetTotalTime() { return this->TotalTime;} - bool GetNextOutputLine(std::string& stdOutLine, std::string& stdErrLine); + int GetNextOutputLine(std::string& stdOutLine, std::string& stdErrLine, + bool& gotStdOut, bool& gotStdErr); private: int LastOutputPipe; double Timeout;