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.

This commit is contained in:
Zach Mullen 2009-09-04 13:50:06 -04:00
parent 7d190a65ca
commit 5517e17bf9
3 changed files with 46 additions and 31 deletions

View File

@ -38,26 +38,36 @@ bool cmCTestRunTest::IsRunning()
void cmCTestRunTest::CheckOutput() void cmCTestRunTest::CheckOutput()
{ {
std::string out, err; std::string out, err;
int pipe = this->TestProcess->CheckOutput(.1); this->TestProcess->CheckOutput(.1);
//start our timeout for reading the process output //start our timeout for reading the process output
double clock_start = cmSystemTools::GetTime(); 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, if(gotStdErr)
this->GetIndex() << ": " << out << std::endl); {
this->ProcessOutput += out; cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
this->ProcessOutput += "\n"; this->GetIndex() << ": " << err << std::endl);
} this->ProcessOutput += err;
else if(pipe == cmsysProcess_Pipe_STDERR) this->ProcessOutput += "\n";
{ }
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, if(gotStdOut)
this->GetIndex() << ": " << err << std::endl); {
this->ProcessOutput += err; cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
this->ProcessOutput += "\n"; this->GetIndex() << ": " << out << std::endl);
this->ProcessOutput += out;
this->ProcessOutput += "\n";
}
} }
gotStdOut = false;
gotStdErr = false;
//timeout while reading process output (could denote infinite output) //timeout while reading process output (could denote infinite output)
if(cmSystemTools::GetTime() - clock_start > .1) if(cmSystemTools::GetTime() - clock_start > .1)
{ {

View File

@ -74,15 +74,19 @@ bool cmProcess::StartProcess()
== cmsysProcess_State_Executing); == cmsysProcess_State_Executing);
} }
bool cmProcess::GetNextOutputLine(std::string& stdOutLine, int cmProcess::GetNextOutputLine(std::string& stdOutLine,
std::string& stdErrLine) std::string& stdErrLine,
bool& gotStdOut,
bool& gotStdErr)
{ {
if(this->StdErrorBuffer.empty() && this->StdOutBuffer.empty()) if(this->StdErrorBuffer.empty() && this->StdOutBuffer.empty())
{ {
return false; return cmsysProcess_Pipe_Timeout;
} }
stdOutLine = ""; stdOutLine = "";
stdErrLine = ""; stdErrLine = "";
this->LastOutputPipe = cmsysProcess_Pipe_Timeout;
std::vector<char>::iterator outiter = std::vector<char>::iterator outiter =
this->StdOutBuffer.begin(); this->StdOutBuffer.begin();
std::vector<char>::iterator erriter = std::vector<char>::iterator erriter =
@ -107,7 +111,8 @@ bool cmProcess::GetNextOutputLine(std::string& stdOutLine,
} }
this->StdOutBuffer.erase(this->StdOutBuffer.begin(), outiter+1); this->StdOutBuffer.erase(this->StdOutBuffer.begin(), outiter+1);
this->LastOutputPipe = cmsysProcess_Pipe_STDOUT; 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->StdErrorBuffer.erase(this->StdErrorBuffer.begin(), erriter+1);
this->LastOutputPipe = cmsysProcess_Pipe_STDERR; this->LastOutputPipe = cmsysProcess_Pipe_STDERR;
return true; gotStdErr = true;
break;
} }
} }
//If we get here, we have stuff waiting in the buffers, but no newline //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 true if there is a new line of data
// return false if there is no new 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. // Wait for data from the process.
int length; int length;
@ -153,14 +159,13 @@ int cmProcess::CheckOutput(double timeout)
{ {
// Timeout has been exceeded. // Timeout has been exceeded.
this->LastOutputPipe = pipe; this->LastOutputPipe = pipe;
return pipe; return;
} }
else if(pipe == cmsysProcess_Pipe_STDOUT) 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->StdOutBuffer.insert(this->StdOutBuffer.end(), data, data+length);
this->LastOutputPipe = pipe; this->LastOutputPipe = pipe;
return pipe;
} }
else if(pipe == cmsysProcess_Pipe_STDERR) else if(pipe == cmsysProcess_Pipe_STDERR)
{ {
@ -168,7 +173,6 @@ int cmProcess::CheckOutput(double timeout)
this->StdErrorBuffer.insert(this->StdErrorBuffer.end(), this->StdErrorBuffer.insert(this->StdErrorBuffer.end(),
data, data+length); data, data+length);
this->LastOutputPipe = pipe; this->LastOutputPipe = pipe;
return pipe;
} }
else if(pipe == cmsysProcess_Pipe_None) else if(pipe == cmsysProcess_Pipe_None)
{ {
@ -176,17 +180,17 @@ int cmProcess::CheckOutput(double timeout)
if(!this->StdOutBuffer.empty()) if(!this->StdOutBuffer.empty())
{ {
this->LastOutputPipe = cmsysProcess_Pipe_STDOUT; this->LastOutputPipe = cmsysProcess_Pipe_STDOUT;
return this->LastOutputPipe; return;
} }
else if(!this->StdErrorBuffer.empty()) else if(!this->StdErrorBuffer.empty())
{ {
this->LastOutputPipe = cmsysProcess_Pipe_STDERR; this->LastOutputPipe = cmsysProcess_Pipe_STDERR;
return this->LastOutputPipe; return;
} }
else else
{ {
this->LastOutputPipe = cmsysProcess_Pipe_None; this->LastOutputPipe = cmsysProcess_Pipe_None;
return this->LastOutputPipe; return;
} }
} }
} }

View File

@ -41,7 +41,7 @@ public:
bool StartProcess(); bool StartProcess();
// return process state // return process state
int CheckOutput(double timeout); void CheckOutput(double timeout);
// return the process status // return the process status
int GetProcessStatus(); int GetProcessStatus();
// return true if the process is running // return true if the process is running
@ -52,7 +52,8 @@ public:
void SetId(int id) { this->Id = id;} void SetId(int id) { this->Id = id;}
int GetExitValue() { return this->ExitValue;} int GetExitValue() { return this->ExitValue;}
double GetTotalTime() { return this->TotalTime;} 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: private:
int LastOutputPipe; int LastOutputPipe;
double Timeout; double Timeout;