ULT: Move aub mem dump tests to shared

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2022-11-07 12:07:18 +00:00
committed by Compute-Runtime-Automation
parent 67af920281
commit 2e06634d91
4 changed files with 152 additions and 119 deletions

View File

@ -1,11 +1,11 @@
#
# Copyright (C) 2018-2021 Intel Corporation
# Copyright (C) 2018-2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(IGDRCL_SRCS_aub_mem_dump_tests
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/aub_alloc_dump_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cl_aub_alloc_dump_tests.cpp
)
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_aub_mem_dump_tests})

View File

@ -6,16 +6,14 @@
*/
#include "shared/source/aub_mem_dump/aub_alloc_dump.h"
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/mocks/mock_allocation_properties.h"
#include "shared/test/common/mocks/mock_gmm.h"
#include "shared/test/common/mocks/mock_gmm_resource_info.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "shared/test/common/test_macros/test.h"
#include "shared/test/common/test_macros/hw_test.h"
#include "opencl/source/mem_obj/buffer.h"
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
#include "opencl/test/unit_test/fixtures/image_fixture.h"
#include "opencl/test/unit_test/mocks/mock_buffer.h"
@ -38,120 +36,6 @@ struct AubFileStreamMock : public AubMemDump::AubFileStream {
std::vector<char> buffer;
};
HWTEST_F(AubAllocDumpTests, givenBufferOrImageWhenGraphicsAllocationIsKnownThenItsTypeCanBeCheckedIfItIsWritable) {
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{pDevice->getRootDeviceIndex(), MemoryConstants::pageSize});
gfxAllocation->setAllocationType(AllocationType::BUFFER);
EXPECT_FALSE(gfxAllocation->isMemObjectsAllocationWithWritableFlags());
EXPECT_FALSE(AubAllocDump::isWritableBuffer(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::BUFFER);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::BUFFER_HOST_MEMORY);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(false);
EXPECT_FALSE(AubAllocDump::isWritableBuffer(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::BUFFER_HOST_MEMORY);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::EXTERNAL_HOST_PTR);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(false);
EXPECT_FALSE(AubAllocDump::isWritableBuffer(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::EXTERNAL_HOST_PTR);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::MAP_ALLOCATION);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(false);
EXPECT_FALSE(AubAllocDump::isWritableBuffer(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::MAP_ALLOCATION);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::IMAGE);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(false);
EXPECT_FALSE(AubAllocDump::isWritableImage(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::IMAGE);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableImage(*gfxAllocation));
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubAllocDumpTests, givenImageResourceWhenGmmResourceInfoIsAvailableThenImageSurfaceTypeCanBeDeducedFromGmmResourceType) {
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_1D, AubAllocDump::getImageSurfaceTypeFromGmmResourceType<FamilyType>(GMM_RESOURCE_TYPE::RESOURCE_1D));
EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_2D, AubAllocDump::getImageSurfaceTypeFromGmmResourceType<FamilyType>(GMM_RESOURCE_TYPE::RESOURCE_2D));
EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_3D, AubAllocDump::getImageSurfaceTypeFromGmmResourceType<FamilyType>(GMM_RESOURCE_TYPE::RESOURCE_3D));
EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_NULL, AubAllocDump::getImageSurfaceTypeFromGmmResourceType<FamilyType>(GMM_RESOURCE_TYPE::RESOURCE_INVALID));
}
HWTEST_F(AubAllocDumpTests, givenGraphicsAllocationWhenDumpAllocationIsCalledInDefaultModeThenGraphicsAllocationShouldNotBeDumped) {
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{pDevice->getRootDeviceIndex(), MemoryConstants::pageSize});
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
auto format = AubAllocDump::getDumpFormat(*gfxAllocation);
AubAllocDump::dumpAllocation<FamilyType>(format, *gfxAllocation, mockAubFileStream.get(), 0);
EXPECT_EQ(0u, mockAubFileStream->getSize());
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubAllocDumpTests, givenGraphicsAllocationWhenDumpAllocationIsCalledButDumpFormatIsUnspecifiedThenGraphicsAllocationShouldNotBeDumped) {
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{pDevice->getRootDeviceIndex(), MemoryConstants::pageSize});
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
auto format = AubAllocDump::getDumpFormat(*gfxAllocation);
AubAllocDump::dumpAllocation<FamilyType>(format, *gfxAllocation, mockAubFileStream.get(), 0);
EXPECT_EQ(0u, mockAubFileStream->getSize());
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubAllocDumpTests, givenNonWritableBufferWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenBufferShouldNotBeDumped) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, AllocationType::BUFFER, pDevice->getDeviceBitfield()});
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
auto format = AubAllocDump::getDumpFormat(*gfxAllocation);
AubAllocDump::dumpAllocation<FamilyType>(format, *gfxAllocation, mockAubFileStream.get(), 0);
EXPECT_EQ(0u, mockAubFileStream->getSize());
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubAllocDumpTests, givenNonWritableImageWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenImageShouldNotBeDumped) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("BMP");
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = MockGmm::allocateImage2d(*memoryManager);
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
auto format = AubAllocDump::getDumpFormat(*gfxAllocation);
AubAllocDump::dumpAllocation<FamilyType>(format, *gfxAllocation, mockAubFileStream.get(), 0);
EXPECT_EQ(0u, mockAubFileStream->getSize());
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubAllocDumpTests, givenWritableBufferWhenDumpAllocationIsCalledAndAubDumpBufferFormatIsNotSetThenBufferShouldNotBeDumped) {
MockContext context;
size_t bufferSize = 10;

View File

@ -6,5 +6,6 @@
target_sources(neo_shared_tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/aub_alloc_dump_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/lrca_helper_tests.cpp
)

View File

@ -0,0 +1,148 @@
/*
* Copyright (C) 2019-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/aub_mem_dump/aub_alloc_dump.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/test/common/fixtures/device_fixture.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/mocks/mock_allocation_properties.h"
#include "shared/test/common/mocks/mock_gmm.h"
#include "shared/test/common/mocks/mock_gmm_resource_info.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "shared/test/common/test_macros/hw_test.h"
using namespace NEO;
using AubAllocDumpTests = Test<DeviceFixture>;
struct AubFileStreamMock : public AubMemDump::AubFileStream {
void write(const char *data, size_t size) override {
buffer.resize(size);
memcpy(buffer.data(), data, size);
}
char *getData() {
return buffer.data();
}
size_t getSize() {
return buffer.size();
}
std::vector<char> buffer;
};
HWTEST_F(AubAllocDumpTests, givenBufferOrImageWhenGraphicsAllocationIsKnownThenItsTypeCanBeCheckedIfItIsWritable) {
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{pDevice->getRootDeviceIndex(), MemoryConstants::pageSize});
gfxAllocation->setAllocationType(AllocationType::BUFFER);
EXPECT_FALSE(gfxAllocation->isMemObjectsAllocationWithWritableFlags());
EXPECT_FALSE(AubAllocDump::isWritableBuffer(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::BUFFER);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::BUFFER_HOST_MEMORY);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(false);
EXPECT_FALSE(AubAllocDump::isWritableBuffer(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::BUFFER_HOST_MEMORY);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::EXTERNAL_HOST_PTR);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(false);
EXPECT_FALSE(AubAllocDump::isWritableBuffer(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::EXTERNAL_HOST_PTR);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::MAP_ALLOCATION);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(false);
EXPECT_FALSE(AubAllocDump::isWritableBuffer(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::MAP_ALLOCATION);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::IMAGE);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(false);
EXPECT_FALSE(AubAllocDump::isWritableImage(*gfxAllocation));
gfxAllocation->setAllocationType(AllocationType::IMAGE);
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableImage(*gfxAllocation));
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubAllocDumpTests, givenImageResourceWhenGmmResourceInfoIsAvailableThenImageSurfaceTypeCanBeDeducedFromGmmResourceType) {
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_1D, AubAllocDump::getImageSurfaceTypeFromGmmResourceType<FamilyType>(GMM_RESOURCE_TYPE::RESOURCE_1D));
EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_2D, AubAllocDump::getImageSurfaceTypeFromGmmResourceType<FamilyType>(GMM_RESOURCE_TYPE::RESOURCE_2D));
EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_3D, AubAllocDump::getImageSurfaceTypeFromGmmResourceType<FamilyType>(GMM_RESOURCE_TYPE::RESOURCE_3D));
EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_NULL, AubAllocDump::getImageSurfaceTypeFromGmmResourceType<FamilyType>(GMM_RESOURCE_TYPE::RESOURCE_INVALID));
}
HWTEST_F(AubAllocDumpTests, givenGraphicsAllocationWhenDumpAllocationIsCalledInDefaultModeThenGraphicsAllocationShouldNotBeDumped) {
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{pDevice->getRootDeviceIndex(), MemoryConstants::pageSize});
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
auto format = AubAllocDump::getDumpFormat(*gfxAllocation);
AubAllocDump::dumpAllocation<FamilyType>(format, *gfxAllocation, mockAubFileStream.get(), 0);
EXPECT_EQ(0u, mockAubFileStream->getSize());
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubAllocDumpTests, givenGraphicsAllocationWhenDumpAllocationIsCalledButDumpFormatIsUnspecifiedThenGraphicsAllocationShouldNotBeDumped) {
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{pDevice->getRootDeviceIndex(), MemoryConstants::pageSize});
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
auto format = AubAllocDump::getDumpFormat(*gfxAllocation);
AubAllocDump::dumpAllocation<FamilyType>(format, *gfxAllocation, mockAubFileStream.get(), 0);
EXPECT_EQ(0u, mockAubFileStream->getSize());
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubAllocDumpTests, givenNonWritableBufferWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenBufferShouldNotBeDumped) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, AllocationType::BUFFER, pDevice->getDeviceBitfield()});
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
auto format = AubAllocDump::getDumpFormat(*gfxAllocation);
AubAllocDump::dumpAllocation<FamilyType>(format, *gfxAllocation, mockAubFileStream.get(), 0);
EXPECT_EQ(0u, mockAubFileStream->getSize());
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubAllocDumpTests, givenNonWritableImageWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenImageShouldNotBeDumped) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("BMP");
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = MockGmm::allocateImage2d(*memoryManager);
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
auto format = AubAllocDump::getDumpFormat(*gfxAllocation);
AubAllocDump::dumpAllocation<FamilyType>(format, *gfxAllocation, mockAubFileStream.get(), 0);
EXPECT_EQ(0u, mockAubFileStream->getSize());
memoryManager->freeGraphicsMemory(gfxAllocation);
}