summaryrefslogtreecommitdiffstats
path: root/Source/CTest/cmCTestRunTest.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2009-09-11 16:26:41 (GMT)
committerBrad King <brad.king@kitware.com>2009-09-11 16:26:41 (GMT)
commit6a7eae718457e8ad9a91729f4c02a666e6ceba98 (patch)
tree511cd299523a20559c4c4a085dd30ec1d0739c81 /Source/CTest/cmCTestRunTest.cxx
parentb6c26cded2965d566ad1ad874f9dac146af4ceac (diff)
downloadCMake-6a7eae718457e8ad9a91729f4c02a666e6ceba98.zip
CMake-6a7eae718457e8ad9a91729f4c02a666e6ceba98.tar.gz
CMake-6a7eae718457e8ad9a91729f4c02a666e6ceba98.tar.bz2
Rewrite CTest child output handling
This commit fixes cmCTestRunTest and cmProcess to more efficiently handle child output. We now use the buffer for each child output pipe to hold at most a partial line plus one new block of data at a time. All complete lines are scanned in-place, and then only the partial line at the end of the buffer is moved back to the beginning before appending new data. We also simplify the cmProcess interface by making GetNextOutputLine the only method that needs to be called while the process is running. This simplifies cmCTestRunTest so that CheckOutput can be called until it returns false when the process is done.
Diffstat (limited to 'Source/CTest/cmCTestRunTest.cxx')
-rw-r--r--Source/CTest/cmCTestRunTest.cxx65
1 files changed, 22 insertions, 43 deletions
diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx
index 86119a2..af472c3 100644
--- a/Source/CTest/cmCTestRunTest.cxx
+++ b/Source/CTest/cmCTestRunTest.cxx
@@ -30,57 +30,36 @@ cmCTestRunTest::~cmCTestRunTest()
{
}
-bool cmCTestRunTest::IsRunning()
+//----------------------------------------------------------------------------
+bool cmCTestRunTest::CheckOutput()
{
- return this->TestProcess->IsRunning();
-}
-
-//---------------------------------------------------------
-//waits .1 sec for output from this process.
-void cmCTestRunTest::CheckOutput()
-{
- std::string out, err;
- bool running = this->TestProcess->CheckOutput(.1);
- //start our timeout for reading the process output
- double clock_start = cmSystemTools::GetTime();
- int pipe;
- bool gotStdOut = false;
- bool gotStdErr = false;
- while((pipe = this->TestProcess->
- GetNextOutputLine(out, err, gotStdOut, gotStdErr, running) )
- != cmsysProcess_Pipe_Timeout)
+ // Read lines for up to 0.1 seconds of total time.
+ double timeout = 0.1;
+ double timeEnd = cmSystemTools::GetTime() + timeout;
+ std::string line;
+ while((timeout = timeEnd - cmSystemTools::GetTime(), timeout > 0))
{
- if(pipe == cmsysProcess_Pipe_STDOUT ||
- pipe == cmsysProcess_Pipe_STDERR ||
- pipe == cmsysProcess_Pipe_None)
+ int p = this->TestProcess->GetNextOutputLine(line, timeout);
+ if(p == cmsysProcess_Pipe_None)
{
- 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";
- }
- if(pipe == cmsysProcess_Pipe_None)
- {
- break;
- }
+ // Process has terminated and all output read.
+ return false;
+ }
+ else if(p == cmsysProcess_Pipe_STDOUT ||
+ p == cmsysProcess_Pipe_STDERR)
+ {
+ // Store this line of output.
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ this->GetIndex() << ": " << line << std::endl);
+ this->ProcessOutput += line;
+ this->ProcessOutput += "\n";
}
- gotStdOut = false;
- gotStdErr = false;
- //timeout while reading process output (could denote infinite output)
- if(cmSystemTools::GetTime() - clock_start > .1)
+ else // if(p == cmsysProcess_Pipe_Timeout)
{
break;
}
}
+ return true;
}
//---------------------------------------------------------