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:
parent
7d190a65ca
commit
5517e17bf9
@ -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)
|
||||
{
|
||||
|
@ -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<char>::iterator outiter =
|
||||
this->StdOutBuffer.begin();
|
||||
std::vector<char>::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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user