Add error handling in allocateGraphicsMemoryForImageImpl and improve ULTs

Change-Id: I418a888fe31d5a7f008bdcfa0a3aabb77bc4df39
Signed-off-by: Dunajski, Bartosz <bartosz.dunajski@intel.com>
This commit is contained in:
Dunajski, Bartosz
2019-09-10 11:55:38 +02:00
committed by sys_ocldev
parent fa8fc3fc43
commit 6ab6a06b1b
5 changed files with 44 additions and 8 deletions

View File

@@ -273,7 +273,9 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryForImageImpl(
if (allocationData.imgInfo->linearStorage && allocationData.imgInfo->mipCount == 0) {
alloc = allocateGraphicsMemoryWithAlignment(allocationData);
if (alloc) {
alloc->setDefaultGmm(gmm.release());
}
return alloc;
}

View File

@@ -148,7 +148,8 @@ HWTEST_P(AUBMapImage, MapUpdateUnmapVerify) {
uint8_t *mappedPtrStart;
uint8_t *srcMemoryStart;
if (srcImage->isTiledAllocation()) {
bool isGpuCopy = srcImage->isTiledAllocation() || !MemoryPool::isSystemMemoryPool(srcImage->getGraphicsAllocation()->getMemoryPool());
if (isGpuCopy) {
mappedPtrStart = static_cast<uint8_t *>(mappedPtr);
srcMemoryStart = srcMemory;

View File

@@ -175,7 +175,8 @@ HWTEST_P(AUBReadImage, simpleUnalignedMemory) {
auto imageMemory = srcMemory;
if (!srcImage->isMemObjZeroCopy() && !srcImage->isTiledAllocation()) {
bool isGpuCopy = srcImage->isTiledAllocation() || !MemoryPool::isSystemMemoryPool(srcImage->getGraphicsAllocation()->getMemoryPool());
if (!isGpuCopy) {
imageMemory = (uint8_t *)(srcImage->getCpuAddress());
}

View File

@@ -580,9 +580,9 @@ TEST_P(CreateImageHostPtr, getAddress) {
EXPECT_NE(pHostPtr, address);
}
if (flags & CL_MEM_COPY_HOST_PTR && !image->isTiledAllocation()) {
if (flags & CL_MEM_COPY_HOST_PTR && image->isMemObjZeroCopy()) {
// Buffer should contain a copy of host memory
EXPECT_EQ(0, memcmp(pHostPtr, address, sizeof(testImageDimensions)));
EXPECT_EQ(0, memcmp(pHostPtr, image->getGraphicsAllocation()->getUnderlyingBuffer(), sizeof(testImageDimensions)));
}
}
@@ -645,6 +645,28 @@ TEST_P(CreateImageHostPtr, failedAllocationInjection) {
injectFailures(method, 4); // check only first 5 allocations - avoid checks on writeImg call allocations for tiled imgs
}
TEST_P(CreateImageHostPtr, givenLinearImageWhenFailedAtCreationThenReturnError) {
DebugManagerStateRestore restore;
DebugManager.flags.ForceLinearImages.set(true);
InjectedFunction method = [this](size_t failureIndex) {
// System under test
image = createImage(retVal);
if (MemoryManagement::nonfailingAllocation == failureIndex) {
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, image);
} else {
EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal) << "for allocation " << failureIndex;
EXPECT_EQ(nullptr, image);
}
delete image;
image = nullptr;
};
injectFailures(method, 4); // check only first 5 allocations - avoid checks on writeImg call allocations for tiled imgs
}
TEST_P(CreateImageHostPtr, checkWritingOutsideAllocatedMemoryWhileCreatingImage) {
auto mockMemoryManager = new MockMemoryManager(*pDevice->executionEnvironment);
pDevice->injectMemoryManager(mockMemoryManager);

View File

@@ -28,6 +28,7 @@
#include "runtime/os_interface/os_context.h"
#include "runtime/utilities/tag_allocator.h"
#include "test.h"
#include "unit_tests/helpers/unit_test_helper.h"
#include "unit_tests/mocks/linux/mock_drm_command_stream_receiver.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_gfx_partition.h"
@@ -1128,7 +1129,10 @@ TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenAllocateGraphicsMemoryForImag
memoryManager->freeGraphicsMemory(imageGraphicsAllocation);
}
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) {
HWTEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) {
if (!UnitTestHelper<FamilyType>::tiledImagesSupported) {
GTEST_SKIP();
}
mock->ioctl_expected.gemCreate = 1;
mock->ioctl_expected.gemSetTiling = 1;
mock->ioctl_expected.gemWait = 1;
@@ -1171,7 +1175,10 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountZero
EXPECT_EQ(1u, this->mock->setTilingHandle);
}
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountNonZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) {
HWTEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountNonZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) {
if (!UnitTestHelper<FamilyType>::tiledImagesSupported) {
GTEST_SKIP();
}
mock->ioctl_expected.gemCreate = 1;
mock->ioctl_expected.gemSetTiling = 1;
mock->ioctl_expected.gemWait = 1;
@@ -1248,7 +1255,10 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedAn
mock->ioctl_expected.contextDestroy = static_cast<int>(device->getExecutionEnvironment()->commandStreamReceivers[0].size());
}
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedFromHostPtrThenallocateGraphicsMemoryForImageIsUsed) {
HWTEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedFromHostPtrThenallocateGraphicsMemoryForImageIsUsed) {
if (!UnitTestHelper<FamilyType>::tiledImagesSupported) {
GTEST_SKIP();
}
mock->ioctl_expected.gemCreate = 1;
mock->ioctl_expected.gemSetTiling = 1;
mock->ioctl_expected.gemUserptr = 1;