Allowed tests to pull more than one line of output in their quantum. Fixed uninitialized variables in the case that the test process could not start.

This commit is contained in:
Zach Mullen 2009-09-03 15:33:44 -04:00
parent f686dbecb6
commit d4adde13d7
5 changed files with 104 additions and 93 deletions

View File

@ -100,7 +100,8 @@ void cmCTestMultiProcessHandler::StartTestProcess(int test)
} }
else else
{ {
testRun->EndTest(this->Completed, this->Total); this->Completed++;
testRun->EndTest(this->Completed, this->Total, false);
} }
} }
@ -209,7 +210,7 @@ bool cmCTestMultiProcessHandler::CheckOutput()
cmCTestRunTest* p = *i; cmCTestRunTest* p = *i;
int test = p->GetIndex(); int test = p->GetIndex();
if(p->EndTest(this->Completed, this->Total)) if(p->EndTest(this->Completed, this->Total, true))
{ {
this->Passed->push_back(p->GetTestProperties()->Name); this->Passed->push_back(p->GetTestProperties()->Name);
} }

View File

@ -38,25 +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, out, err); int pipe = this->TestProcess->CheckOutput(.1);
if(pipe == cmsysProcess_Pipe_STDOUT) //start our timeout for reading the process output
double clock_start = cmSystemTools::GetTime();
while(this->TestProcess->GetNextOutputLine(out, err))
{ {
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
this->GetIndex() << ": " << out << std::endl); if(pipe == cmsysProcess_Pipe_STDOUT)
this->ProcessOutput += out; {
this->ProcessOutput += "\n"; cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
} this->GetIndex() << ": " << out << std::endl);
else if(pipe == cmsysProcess_Pipe_STDERR) this->ProcessOutput += out;
{ this->ProcessOutput += "\n";
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, }
this->GetIndex() << ": " << err << std::endl); else if(pipe == cmsysProcess_Pipe_STDERR)
this->ProcessOutput += err; {
this->ProcessOutput += "\n"; cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
this->GetIndex() << ": " << err << std::endl);
this->ProcessOutput += err;
this->ProcessOutput += "\n";
}
//timeout while reading process output (could denote infinite output)
if(cmSystemTools::GetTime() - clock_start > .1)
{
break;
}
} }
} }
//--------------------------------------------------------- //---------------------------------------------------------
bool cmCTestRunTest::EndTest(size_t completed, size_t total) bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
{ {
//restore the old environment //restore the old environment
if (this->ModifyEnv) if (this->ModifyEnv)
@ -240,12 +251,14 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total)
<< "----------------------------------------------------------" << "----------------------------------------------------------"
<< std::endl << std::endl; << std::endl << std::endl;
} }
this->TestResult.Output = this->ProcessOutput; if(started)
this->TestResult.ReturnValue = this->TestProcess->GetExitValue(); {
this->TestResult.CompletionStatus = "Completed"; this->TestResult.Output = this->ProcessOutput;
this->TestResult.ExecutionTime = this->TestProcess->GetTotalTime(); this->TestResult.ReturnValue = this->TestProcess->GetExitValue();
this->TestHandler->TestResults.push_back( this->TestResult ); this->TestResult.CompletionStatus = "Completed";
this->TestResult.ExecutionTime = this->TestProcess->GetTotalTime();
this->TestHandler->TestResults.push_back( this->TestResult );
}
this->MemCheckPostProcess(); this->MemCheckPostProcess();
delete this->TestProcess; delete this->TestProcess;
@ -290,6 +303,7 @@ bool cmCTestRunTest::StartTest()
this->TestResult.Properties = this->TestProperties; this->TestResult.Properties = this->TestProperties;
this->TestResult.ExecutionTime = 0; this->TestResult.ExecutionTime = 0;
this->TestResult.ReturnValue = -1; this->TestResult.ReturnValue = -1;
this->TestResult.CompletionStatus = "Not Run";
this->TestResult.Status = cmCTestTestHandler::NOT_RUN; this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
this->TestResult.TestCount = this->TestProperties->Index; this->TestResult.TestCount = this->TestProperties->Index;
this->TestResult.Name = this->TestProperties->Name; this->TestResult.Name = this->TestProperties->Name;

View File

@ -56,7 +56,7 @@ public:
//launch the test process, return whether it started correctly //launch the test process, return whether it started correctly
bool StartTest(); bool StartTest();
//capture and report the test results //capture and report the test results
bool EndTest(size_t completed, size_t total); bool EndTest(size_t completed, size_t total, bool started);
//Called by ctest -N to log the command string //Called by ctest -N to log the command string
void ComputeArguments(); void ComputeArguments();
private: private:

View File

@ -68,72 +68,80 @@ bool cmProcess::StartProcess()
return (cmsysProcess_GetState(this->Process) return (cmsysProcess_GetState(this->Process)
== cmsysProcess_State_Executing); == cmsysProcess_State_Executing);
} }
// return true if there is a new line of data bool cmProcess::GetNextOutputLine(std::string& stdOutLine,
// return false if there is no new data
int cmProcess::CheckOutput(double timeout,
std::string& stdOutLine,
std::string& stdErrLine) std::string& stdErrLine)
{ {
if(this->StdErrorBuffer.empty() && this->StdOutBuffer.empty())
{
return false;
}
stdOutLine = ""; stdOutLine = "";
stdErrLine = ""; stdErrLine = "";
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 =
this->StdErrorBuffer.begin(); this->StdErrorBuffer.begin();
// Check for a newline in stdout.
for(;outiter != this->StdOutBuffer.end(); ++outiter)
{
if((*outiter == '\r') && ((outiter+1) == this->StdOutBuffer.end()))
{
break;
}
else if(*outiter == '\n' || *outiter == '\0')
{
int length = outiter-this->StdOutBuffer.begin();
if(length > 1 && *(outiter-1) == '\r')
{
--length;
}
if(length > 0)
{
stdOutLine.append(&this->StdOutBuffer[0], length);
}
this->StdOutBuffer.erase(this->StdOutBuffer.begin(), outiter+1);
this->LastOutputPipe = cmsysProcess_Pipe_STDOUT;
return true;
}
}
// Check for a newline in stderr.
for(;erriter != this->StdErrorBuffer.end(); ++erriter)
{
if((*erriter == '\r') && ((erriter+1) == this->StdErrorBuffer.end()))
{
break;
}
else if(*erriter == '\n' || *erriter == '\0')
{
int length = erriter-this->StdErrorBuffer.begin();
if(length > 1 && *(erriter-1) == '\r')
{
--length;
}
if(length > 0)
{
stdErrLine.append(&this->StdErrorBuffer[0], length);
}
this->StdErrorBuffer.erase(this->StdErrorBuffer.begin(), erriter+1);
this->LastOutputPipe = cmsysProcess_Pipe_STDERR;
return true;
}
}
//If we get here, we have stuff waiting in the buffers, but no newline
return false;
}
// return true if there is a new line of data
// return false if there is no new data
int cmProcess::CheckOutput(double timeout)
{
// Wait for data from the process.
int length;
char* data;
while(1) while(1)
{ {
// Check for a newline in stdout.
for(;outiter != this->StdOutBuffer.end(); ++outiter)
{
if((*outiter == '\r') && ((outiter+1) == this->StdOutBuffer.end()))
{
break;
}
else if(*outiter == '\n' || *outiter == '\0')
{
int length = outiter-this->StdOutBuffer.begin();
if(length > 1 && *(outiter-1) == '\r')
{
--length;
}
if(length > 0)
{
stdOutLine.append(&this->StdOutBuffer[0], length);
}
this->StdOutBuffer.erase(this->StdOutBuffer.begin(), outiter+1);
this->LastOutputPipe = cmsysProcess_Pipe_STDOUT;
return this->LastOutputPipe;;
}
}
// Check for a newline in stderr.
for(;erriter != this->StdErrorBuffer.end(); ++erriter)
{
if((*erriter == '\r') && ((erriter+1) == this->StdErrorBuffer.end()))
{
break;
}
else if(*erriter == '\n' || *erriter == '\0')
{
int length = erriter-this->StdErrorBuffer.begin();
if(length > 1 && *(erriter-1) == '\r')
{
--length;
}
if(length > 0)
{
stdErrLine.append(&this->StdErrorBuffer[0], length);
}
this->StdErrorBuffer.erase(this->StdErrorBuffer.begin(), erriter+1);
this->LastOutputPipe = cmsysProcess_Pipe_STDERR;
return this->LastOutputPipe;
}
}
// No newlines found. Wait for more data from the process.
int length;
char* data;
int pipe = cmsysProcess_WaitForData(this->Process, &data, int pipe = cmsysProcess_WaitForData(this->Process, &data,
&length, &timeout); &length, &timeout);
if(pipe == cmsysProcess_Pipe_Timeout) if(pipe == cmsysProcess_Pipe_Timeout)
@ -147,7 +155,6 @@ int cmProcess::CheckOutput(double timeout,
// Append to the stdout buffer. // Append to the stdout buffer.
std::vector<char>::size_type size = this->StdOutBuffer.size(); std::vector<char>::size_type size = this->StdOutBuffer.size();
this->StdOutBuffer.insert(this->StdOutBuffer.end(), data, data+length); this->StdOutBuffer.insert(this->StdOutBuffer.end(), data, data+length);
outiter = this->StdOutBuffer.begin()+size;
} }
else if(pipe == cmsysProcess_Pipe_STDERR) else if(pipe == cmsysProcess_Pipe_STDERR)
{ {
@ -155,26 +162,17 @@ int cmProcess::CheckOutput(double timeout,
std::vector<char>::size_type size = this->StdErrorBuffer.size(); std::vector<char>::size_type size = this->StdErrorBuffer.size();
this->StdErrorBuffer.insert(this->StdErrorBuffer.end(), this->StdErrorBuffer.insert(this->StdErrorBuffer.end(),
data, data+length); data, data+length);
erriter = this->StdErrorBuffer.begin()+size;
} }
else if(pipe == cmsysProcess_Pipe_None) else if(pipe == cmsysProcess_Pipe_None)
{ {
// Both stdout and stderr pipes have broken. Return leftover data. // Both stdout and stderr pipes have broken. Return leftover data.
if(!this->StdOutBuffer.empty()) if(!this->StdOutBuffer.empty())
{ {
stdOutLine.append(&this->StdOutBuffer[0],
outiter-this->StdOutBuffer.begin());
this->StdOutBuffer.erase(this->StdOutBuffer.begin(),
this->StdOutBuffer.end());
this->LastOutputPipe = cmsysProcess_Pipe_STDOUT; this->LastOutputPipe = cmsysProcess_Pipe_STDOUT;
return this->LastOutputPipe; return this->LastOutputPipe;
} }
else if(!this->StdErrorBuffer.empty()) else if(!this->StdErrorBuffer.empty())
{ {
stdErrLine.append(&this->StdErrorBuffer[0],
erriter-this->StdErrorBuffer.begin());
this->StdErrorBuffer.erase(this->StdErrorBuffer.begin(),
this->StdErrorBuffer.end());
this->LastOutputPipe = cmsysProcess_Pipe_STDERR; this->LastOutputPipe = cmsysProcess_Pipe_STDERR;
return this->LastOutputPipe; return this->LastOutputPipe;
} }
@ -187,7 +185,6 @@ int cmProcess::CheckOutput(double timeout,
} }
} }
// return the process status // return the process status
int cmProcess::GetProcessStatus() int cmProcess::GetProcessStatus()
{ {

View File

@ -41,9 +41,7 @@ public:
bool StartProcess(); bool StartProcess();
// return process state // return process state
int CheckOutput(double timeout, int CheckOutput(double timeout);
std::string& stdOutLine,
std::string& stdErrLine);
// 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
@ -54,6 +52,7 @@ 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);
private: private:
int LastOutputPipe; int LastOutputPipe;
double Timeout; double Timeout;