diff --git a/opencl/test/unit_test/aub_mem_dump/CMakeLists.txt b/opencl/test/unit_test/aub_mem_dump/CMakeLists.txt index cf40e0fa78..d03c3b6385 100644 --- a/opencl/test/unit_test/aub_mem_dump/CMakeLists.txt +++ b/opencl/test/unit_test/aub_mem_dump/CMakeLists.txt @@ -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}) diff --git a/opencl/test/unit_test/aub_mem_dump/aub_alloc_dump_tests.cpp b/opencl/test/unit_test/aub_mem_dump/cl_aub_alloc_dump_tests.cpp similarity index 75% rename from opencl/test/unit_test/aub_mem_dump/aub_alloc_dump_tests.cpp rename to opencl/test/unit_test/aub_mem_dump/cl_aub_alloc_dump_tests.cpp index 77f32343c3..dcedf5e2d3 100644 --- a/opencl/test/unit_test/aub_mem_dump/aub_alloc_dump_tests.cpp +++ b/opencl/test/unit_test/aub_mem_dump/cl_aub_alloc_dump_tests.cpp @@ -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 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(GMM_RESOURCE_TYPE::RESOURCE_1D)); - EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_2D, AubAllocDump::getImageSurfaceTypeFromGmmResourceType(GMM_RESOURCE_TYPE::RESOURCE_2D)); - EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_3D, AubAllocDump::getImageSurfaceTypeFromGmmResourceType(GMM_RESOURCE_TYPE::RESOURCE_3D)); - EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_NULL, AubAllocDump::getImageSurfaceTypeFromGmmResourceType(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 mockAubFileStream(new AubFileStreamMock()); - auto format = AubAllocDump::getDumpFormat(*gfxAllocation); - AubAllocDump::dumpAllocation(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 mockAubFileStream(new AubFileStreamMock()); - auto format = AubAllocDump::getDumpFormat(*gfxAllocation); - AubAllocDump::dumpAllocation(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 mockAubFileStream(new AubFileStreamMock()); - auto format = AubAllocDump::getDumpFormat(*gfxAllocation); - AubAllocDump::dumpAllocation(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 mockAubFileStream(new AubFileStreamMock()); - auto format = AubAllocDump::getDumpFormat(*gfxAllocation); - AubAllocDump::dumpAllocation(format, *gfxAllocation, mockAubFileStream.get(), 0); - - EXPECT_EQ(0u, mockAubFileStream->getSize()); - - memoryManager->freeGraphicsMemory(gfxAllocation); -} - HWTEST_F(AubAllocDumpTests, givenWritableBufferWhenDumpAllocationIsCalledAndAubDumpBufferFormatIsNotSetThenBufferShouldNotBeDumped) { MockContext context; size_t bufferSize = 10; diff --git a/shared/test/unit_test/aub_mem_dump/CMakeLists.txt b/shared/test/unit_test/aub_mem_dump/CMakeLists.txt index 22bcd84853..13949d5f8a 100644 --- a/shared/test/unit_test/aub_mem_dump/CMakeLists.txt +++ b/shared/test/unit_test/aub_mem_dump/CMakeLists.txt @@ -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 ) diff --git a/shared/test/unit_test/aub_mem_dump/aub_alloc_dump_tests.cpp b/shared/test/unit_test/aub_mem_dump/aub_alloc_dump_tests.cpp new file mode 100644 index 0000000000..ef88f91dcc --- /dev/null +++ b/shared/test/unit_test/aub_mem_dump/aub_alloc_dump_tests.cpp @@ -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; + +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 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(GMM_RESOURCE_TYPE::RESOURCE_1D)); + EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_2D, AubAllocDump::getImageSurfaceTypeFromGmmResourceType(GMM_RESOURCE_TYPE::RESOURCE_2D)); + EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_3D, AubAllocDump::getImageSurfaceTypeFromGmmResourceType(GMM_RESOURCE_TYPE::RESOURCE_3D)); + EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_NULL, AubAllocDump::getImageSurfaceTypeFromGmmResourceType(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 mockAubFileStream(new AubFileStreamMock()); + auto format = AubAllocDump::getDumpFormat(*gfxAllocation); + AubAllocDump::dumpAllocation(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 mockAubFileStream(new AubFileStreamMock()); + auto format = AubAllocDump::getDumpFormat(*gfxAllocation); + AubAllocDump::dumpAllocation(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 mockAubFileStream(new AubFileStreamMock()); + auto format = AubAllocDump::getDumpFormat(*gfxAllocation); + AubAllocDump::dumpAllocation(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 mockAubFileStream(new AubFileStreamMock()); + auto format = AubAllocDump::getDumpFormat(*gfxAllocation); + AubAllocDump::dumpAllocation(format, *gfxAllocation, mockAubFileStream.get(), 0); + + EXPECT_EQ(0u, mockAubFileStream->getSize()); + + memoryManager->freeGraphicsMemory(gfxAllocation); +}