Prevent null allocation in createSharedUnifiedMemoryAllocation

Related-To: NEO-3860
Change-Id: I3954279414b226ea332da4a3fd1580853e59bd54
Signed-off-by: Gibala <krzysztof.gibala@intel.com>
This commit is contained in:
Gibala
2019-10-22 19:35:36 +02:00
committed by sys_ocldev
parent 472b1627a2
commit e22ce2f757
2 changed files with 18 additions and 1 deletions

View File

@@ -126,7 +126,9 @@ void *SVMAllocsManager::createSharedUnifiedMemoryAllocation(size_t size, const U
if (supportDualStorageSharedMemory) {
auto unifiedMemoryPointer = createUnifiedAllocationWithDeviceStorage(size, {});
UNRECOVERABLE_IF(unifiedMemoryPointer == nullptr);
if (!unifiedMemoryPointer) {
return nullptr;
}
auto unifiedMemoryAllocation = this->getSVMAlloc(unifiedMemoryPointer);
unifiedMemoryAllocation->memoryType = memoryProperties.memoryType;
unifiedMemoryAllocation->allocationFlagsProperty = memoryProperties.allocationFlags;

View File

@@ -203,6 +203,21 @@ TEST_F(SVMMemoryAllocatorTest, whenHostAllocationIsCreatedThenItIsStoredWithProp
svmManager->freeSVMAlloc(ptr);
}
TEST_F(SVMMemoryAllocatorTest, whenCouldNotAllocateInMemoryManagerThenCreateSharedUnifiedMemoryAllocationReturnsNullAndDoesNotChangeAllocsMap) {
MockCommandQueue cmdQ;
DebugManagerStateRestore restore;
DebugManager.flags.AllocateSharedAllocationsWithCpuAndGpuStorage.set(true);
FailMemoryManager failMemoryManager(executionEnvironment);
svmManager->memoryManager = &failMemoryManager;
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties;
unifiedMemoryProperties.memoryType = InternalMemoryType::SHARED_UNIFIED_MEMORY;
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(4096u, unifiedMemoryProperties, &cmdQ);
EXPECT_EQ(nullptr, ptr);
EXPECT_EQ(0u, svmManager->SVMAllocs.getNumAllocs());
svmManager->freeSVMAlloc(ptr);
}
TEST_F(SVMMemoryAllocatorTest, whenSharedAllocationIsCreatedThenItIsStoredWithProperTypeInAllocationMap) {
MockCommandQueue cmdQ;
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties;