Refactor: Provide more detailed error information from TryAllocateResources()

This commit is contained in:
Kyle Edwards
2020-02-24 10:53:32 -05:00
parent f1c34443b7
commit f0df3ed5b9
2 changed files with 37 additions and 16 deletions
+27 -14
View File
@@ -196,7 +196,7 @@ bool cmCTestMultiProcessHandler::StartTestProcess(int test)
// working directory because FinishTestProcess() will try to unlock them // working directory because FinishTestProcess() will try to unlock them
this->LockResources(test); this->LockResources(test);
if (!this->TestsHaveSufficientResources[test]) { if (!this->ResourceAllocationErrors[test].empty()) {
testRun->StartFailure("Insufficient resources", "Failed to start"); testRun->StartFailure("Insufficient resources", "Failed to start");
this->FinishTestProcess(testRun, false); this->FinishTestProcess(testRun, false);
return false; return false;
@@ -250,7 +250,8 @@ bool cmCTestMultiProcessHandler::AllocateResources(int index)
bool cmCTestMultiProcessHandler::TryAllocateResources( bool cmCTestMultiProcessHandler::TryAllocateResources(
int index, int index,
std::map<std::string, std::vector<cmCTestBinPackerAllocation>>& allocations) std::map<std::string, std::vector<cmCTestBinPackerAllocation>>& allocations,
std::map<std::string, ResourceAllocationError>* errors)
{ {
allocations.clear(); allocations.clear();
@@ -265,18 +266,28 @@ bool cmCTestMultiProcessHandler::TryAllocateResources(
++processIndex; ++processIndex;
} }
bool result = true;
auto const& availableResources = this->ResourceAllocator.GetResources(); auto const& availableResources = this->ResourceAllocator.GetResources();
for (auto& it : allocations) { for (auto& it : allocations) {
if (!availableResources.count(it.first)) { if (!availableResources.count(it.first)) {
return false; if (errors) {
} (*errors)[it.first] = ResourceAllocationError::NoResourceType;
if (!cmAllocateCTestResourcesRoundRobin(availableResources.at(it.first), result = false;
it.second)) { } else {
return false; return false;
}
} else if (!cmAllocateCTestResourcesRoundRobin(
availableResources.at(it.first), it.second)) {
if (errors) {
(*errors)[it.first] = ResourceAllocationError::InsufficientResources;
result = false;
} else {
return false;
}
} }
} }
return true; return result;
} }
void cmCTestMultiProcessHandler::DeallocateResources(int index) void cmCTestMultiProcessHandler::DeallocateResources(int index)
@@ -317,11 +328,13 @@ bool cmCTestMultiProcessHandler::AllResourcesAvailable()
void cmCTestMultiProcessHandler::CheckResourcesAvailable() void cmCTestMultiProcessHandler::CheckResourcesAvailable()
{ {
for (auto test : this->SortedTests) { if (this->TestHandler->UseResourceSpec) {
std::map<std::string, std::vector<cmCTestBinPackerAllocation>> allocations; for (auto test : this->SortedTests) {
this->TestsHaveSufficientResources[test] = std::map<std::string, std::vector<cmCTestBinPackerAllocation>>
!this->TestHandler->UseResourceSpec || allocations;
this->TryAllocateResources(test, allocations); this->TryAllocateResources(test, allocations,
&this->ResourceAllocationErrors[test]);
}
} }
} }
@@ -408,7 +421,7 @@ bool cmCTestMultiProcessHandler::StartTest(int test)
} }
// Allocate resources // Allocate resources
if (this->TestsHaveSufficientResources[test] && if (this->ResourceAllocationErrors[test].empty() &&
!this->AllocateResources(test)) { !this->AllocateResources(test)) {
this->DeallocateResources(test); this->DeallocateResources(test);
return false; return false;
+10 -2
View File
@@ -143,11 +143,18 @@ protected:
void LockResources(int index); void LockResources(int index);
void UnlockResources(int index); void UnlockResources(int index);
enum class ResourceAllocationError
{
NoResourceType,
InsufficientResources,
};
bool AllocateResources(int index); bool AllocateResources(int index);
bool TryAllocateResources( bool TryAllocateResources(
int index, int index,
std::map<std::string, std::vector<cmCTestBinPackerAllocation>>& std::map<std::string, std::vector<cmCTestBinPackerAllocation>>&
allocations); allocations,
std::map<std::string, ResourceAllocationError>* errors = nullptr);
void DeallocateResources(int index); void DeallocateResources(int index);
bool AllResourcesAvailable(); bool AllResourcesAvailable();
@@ -174,7 +181,8 @@ protected:
std::map<int, std::map<int,
std::vector<std::map<std::string, std::vector<ResourceAllocation>>>> std::vector<std::map<std::string, std::vector<ResourceAllocation>>>>
AllocatedResources; AllocatedResources;
std::map<int, bool> TestsHaveSufficientResources; std::map<int, std::map<std::string, ResourceAllocationError>>
ResourceAllocationErrors;
cmCTestResourceAllocator ResourceAllocator; cmCTestResourceAllocator ResourceAllocator;
std::vector<cmCTestTestHandler::cmCTestTestResult>* TestResults; std::vector<cmCTestTestHandler::cmCTestTestResult>* TestResults;
size_t ParallelLevel; // max number of process that can be run at once size_t ParallelLevel; // max number of process that can be run at once