cmCTestMultiProcessHandler: Refactor RUN_SERIAL implementation

The original implementation of the RUN_SERIAL test property worked by
having such a test consume all available processors.  Instead use an
explicit flag to indicate that a serial test is running.  This avoids
artificially inflating the number of processors a test is expected to
consume.
This commit is contained in:
Zack Galbreath 2015-06-01 09:42:44 -04:00 committed by Brad King
parent 8bf5a80b96
commit 07c550caa2
2 changed files with 32 additions and 4 deletions

View File

@ -44,6 +44,7 @@ cmCTestMultiProcessHandler::cmCTestMultiProcessHandler()
this->RunningCount = 0; this->RunningCount = 0;
this->StopTimePassed = false; this->StopTimePassed = false;
this->HasCycles = false; this->HasCycles = false;
this->SerialTestRunning = false;
} }
cmCTestMultiProcessHandler::~cmCTestMultiProcessHandler() cmCTestMultiProcessHandler::~cmCTestMultiProcessHandler()
@ -172,6 +173,11 @@ void cmCTestMultiProcessHandler::LockResources(int index)
this->LockedResources.insert( this->LockedResources.insert(
this->Properties[index]->LockedResources.begin(), this->Properties[index]->LockedResources.begin(),
this->Properties[index]->LockedResources.end()); this->Properties[index]->LockedResources.end());
if (this->Properties[index]->RunSerial)
{
this->SerialTestRunning = true;
}
} }
//--------------------------------------------------------- //---------------------------------------------------------
@ -198,11 +204,9 @@ inline size_t cmCTestMultiProcessHandler::GetProcessorsUsed(int test)
{ {
size_t processors = size_t processors =
static_cast<int>(this->Properties[test]->Processors); static_cast<int>(this->Properties[test]->Processors);
//If this is set to run serially, it must run alone. //If processors setting is set higher than the -j
//Also, if processors setting is set higher than the -j
//setting, we default to using all of the process slots. //setting, we default to using all of the process slots.
if(this->Properties[test]->RunSerial if (processors > this->ParallelLevel)
|| processors > this->ParallelLevel)
{ {
processors = this->ParallelLevel; processors = this->ParallelLevel;
} }
@ -248,9 +252,27 @@ void cmCTestMultiProcessHandler::StartNextTests()
return; return;
} }
// Don't start any new tests if one with the RUN_SERIAL property
// is already running.
if (this->SerialTestRunning)
{
return;
}
TestList copy = this->SortedTests; TestList copy = this->SortedTests;
for(TestList::iterator test = copy.begin(); test != copy.end(); ++test) for(TestList::iterator test = copy.begin(); test != copy.end(); ++test)
{ {
// Take a nap if we're currently performing a RUN_SERIAL test.
if (this->SerialTestRunning)
{
break;
}
// We can only start a RUN_SERIAL test if no other tests are also running.
if (this->Properties[*test]->RunSerial && this->RunningCount > 0)
{
continue;
}
size_t processors = GetProcessorsUsed(*test); size_t processors = GetProcessorsUsed(*test);
if(processors <= numToStart && this->StartTest(*test)) if(processors <= numToStart && this->StartTest(*test))
@ -319,6 +341,11 @@ bool cmCTestMultiProcessHandler::CheckOutput()
this->WriteCheckpoint(test); this->WriteCheckpoint(test);
this->UnlockResources(test); this->UnlockResources(test);
this->RunningCount -= GetProcessorsUsed(test); this->RunningCount -= GetProcessorsUsed(test);
if (this->Properties[test]->RunSerial)
{
this->SerialTestRunning = false;
}
delete p; delete p;
} }
return true; return true;

View File

@ -121,6 +121,7 @@ protected:
cmCTest* CTest; cmCTest* CTest;
bool HasCycles; bool HasCycles;
bool Quiet; bool Quiet;
bool SerialTestRunning;
}; };
#endif #endif