Fix intermingling of test environments when tests run in parallel.

The SaveRestoreEnvironment helper object makes sure that the
original environment is restored immediately after the
StartProcess call returns rather than waiting for the end
of the test. When tests are executed in parallel, there is
no guarantee about the ordering of EndTest calls relative
to StartTest calls. In fact, it would be odd for them to
be nested nicely. Therefore, to avoid the corruption of
the calling ctest's environment, the original environment
must be restored before ForkProcess returns.
This commit is contained in:
David Cole 2010-03-30 14:08:31 -04:00
parent d0b510900d
commit 003ffe5908
2 changed files with 6 additions and 16 deletions

View File

@ -23,7 +23,6 @@ cmCTestRunTest::cmCTestRunTest(cmCTestTestHandler* handler)
{ {
this->CTest = handler->CTest; this->CTest = handler->CTest;
this->TestHandler = handler; this->TestHandler = handler;
this->ModifyEnv = false;
this->TestProcess = 0; this->TestProcess = 0;
this->TestResult.ExecutionTime =0; this->TestResult.ExecutionTime =0;
this->TestResult.ReturnValue = 0; this->TestResult.ReturnValue = 0;
@ -139,11 +138,6 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
this->CompressOutput(); this->CompressOutput();
} }
//restore the old environment
if (this->ModifyEnv)
{
cmSystemTools::RestoreEnv(this->OrigEnv);
}
this->WriteLogOutputTop(completed, total); this->WriteLogOutputTop(completed, total);
std::string reason; std::string reason;
bool passed = true; bool passed = true;
@ -593,9 +587,6 @@ bool cmCTestRunTest::ForkProcess(double testTimeOut,
this->TestProcess->SetCommand(this->ActualCommand.c_str()); this->TestProcess->SetCommand(this->ActualCommand.c_str());
this->TestProcess->SetCommandArguments(this->Arguments); this->TestProcess->SetCommandArguments(this->Arguments);
std::vector<std::string> origEnv;
this->ModifyEnv = (environment && environment->size()>0);
// determine how much time we have // determine how much time we have
double timeout = this->CTest->GetRemainingTimeAllowed() - 120; double timeout = this->CTest->GetRemainingTimeAllowed() - 120;
if (this->CTest->GetTimeOut() > 0 && this->CTest->GetTimeOut() < timeout) if (this->CTest->GetTimeOut() > 0 && this->CTest->GetTimeOut() < timeout)
@ -618,9 +609,13 @@ bool cmCTestRunTest::ForkProcess(double testTimeOut,
this->TestProcess->SetTimeout(timeout); this->TestProcess->SetTimeout(timeout);
if (this->ModifyEnv) #ifdef CMAKE_BUILD_WITH_CMAKE
cmSystemTools::SaveRestoreEnvironment sre;
#endif
if (environment && environment->size()>0)
{ {
this->OrigEnv = cmSystemTools::AppendEnv(environment); cmSystemTools::AppendEnv(environment);
} }
return this->TestProcess->StartProcess(); return this->TestProcess->StartProcess();

View File

@ -77,14 +77,9 @@ private:
//if this option is set to false.) //if this option is set to false.)
//bool OptimizeForCTest; //bool OptimizeForCTest;
//flag for whether the env was modified for this run
bool ModifyEnv;
bool UsePrefixCommand; bool UsePrefixCommand;
std::string PrefixCommand; std::string PrefixCommand;
//stores the original environment if we are modifying it
std::vector<std::string> OrigEnv;
std::string ProcessOutput; std::string ProcessOutput;
std::string CompressedOutput; std::string CompressedOutput;
double CompressionRatio; double CompressionRatio;