diff --git a/runtime/os_interface/linux/CMakeLists.txt b/runtime/os_interface/linux/CMakeLists.txt index b44fa76656..929ae32d1b 100644 --- a/runtime/os_interface/linux/CMakeLists.txt +++ b/runtime/os_interface/linux/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2018 Intel Corporation +# Copyright (C) 2018-2019 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -14,6 +14,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/device_factory_linux.cpp ${CMAKE_CURRENT_SOURCE_DIR}/driver_info.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_32bit_memory.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drm_allocation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_allocation.h ${CMAKE_CURRENT_SOURCE_DIR}/drm_buffer_object.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_buffer_object.h diff --git a/runtime/os_interface/linux/drm_allocation.cpp b/runtime/os_interface/linux/drm_allocation.cpp new file mode 100644 index 0000000000..e6b75f50fe --- /dev/null +++ b/runtime/os_interface/linux/drm_allocation.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/os_interface/linux/drm_allocation.h" +#include "runtime/os_interface/linux/drm_buffer_object.h" + +#include + +namespace OCLRT { +std::string DrmAllocation::getAllocationInfoString() const { + std::stringstream ss; + if (bo != nullptr) { + ss << " Handle: " << bo->peekHandle(); + } + return ss.str(); +} +} // namespace OCLRT diff --git a/runtime/os_interface/linux/drm_allocation.h b/runtime/os_interface/linux/drm_allocation.h index 99e9532b38..0d81897aaf 100644 --- a/runtime/os_interface/linux/drm_allocation.h +++ b/runtime/os_interface/linux/drm_allocation.h @@ -24,6 +24,8 @@ class DrmAllocation : public GraphicsAllocation { this->memoryPool = pool; } + std::string getAllocationInfoString() const override; + BufferObject *getBO() const { if (fragmentsStorage.fragmentCount) { return fragmentsStorage.fragmentStorageData[0].osHandleStorage->bo; diff --git a/runtime/os_interface/windows/wddm_allocation.h b/runtime/os_interface/windows/wddm_allocation.h index 3169c6a672..f5f606ea1b 100644 --- a/runtime/os_interface/windows/wddm_allocation.h +++ b/runtime/os_interface/windows/wddm_allocation.h @@ -83,10 +83,9 @@ class WddmAllocation : public GraphicsAllocation { void setCpuAddress(void *cpuPtr) { this->cpuPtr = cpuPtr; } bool needsMakeResidentBeforeLock = false; - std::string getAllocationInfoString() const { + std::string getAllocationInfoString() const override { std::stringstream ss; ss << " Handle: " << handle; - ss << std::endl; return ss.str(); } diff --git a/unit_tests/mocks/CMakeLists.txt b/unit_tests/mocks/CMakeLists.txt index 37f001668a..9ddcebc17b 100644 --- a/unit_tests/mocks/CMakeLists.txt +++ b/unit_tests/mocks/CMakeLists.txt @@ -86,6 +86,7 @@ if(WIN32) ) else() list(APPEND IGDRCL_SRCS_tests_mocks + ${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_allocation.h ${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_memory_manager.h ${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_command_stream_receiver.h ) diff --git a/unit_tests/mocks/linux/mock_drm_allocation.h b/unit_tests/mocks/linux/mock_drm_allocation.h new file mode 100644 index 0000000000..b12ed3ce5f --- /dev/null +++ b/unit_tests/mocks/linux/mock_drm_allocation.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "runtime/os_interface/linux/drm_allocation.h" +#include "runtime/os_interface/linux/drm_buffer_object.h" + +namespace OCLRT { + +class MockBufferObject : public BufferObject { + public: + using BufferObject::handle; + + MockBufferObject() : BufferObject(nullptr, 0, false) { + } +}; + +class MockDrmAllocation : public DrmAllocation { + public: + using DrmAllocation::bo; + using DrmAllocation::memoryPool; + + MockDrmAllocation() : DrmAllocation(nullptr, nullptr, 0, static_cast(0), MemoryPool::MemoryNull, false) { + } +}; + +} // namespace OCLRT diff --git a/unit_tests/os_interface/debug_settings_manager_tests.cpp b/unit_tests/os_interface/debug_settings_manager_tests.cpp index a3eb93d2a2..f76bd44a68 100644 --- a/unit_tests/os_interface/debug_settings_manager_tests.cpp +++ b/unit_tests/os_interface/debug_settings_manager_tests.cpp @@ -901,7 +901,7 @@ TEST_P(AllocationTypeLogging, givenGraphicsAllocationTypeWhenConvertingToStringT FullyEnabledTestDebugManager debugManager; auto input = GetParam(); - MockGraphicsAllocation graphicsAllocation; + GraphicsAllocation graphicsAllocation(nullptr, 0u, 0, true); graphicsAllocation.setAllocationType(input.type); auto result = debugManager.getAllocationTypeString(&graphicsAllocation); @@ -916,7 +916,7 @@ INSTANTIATE_TEST_CASE_P(AllAllocationTypes, TEST(AllocationTypeLoggingSingle, givenGraphicsAllocationTypeWhenConvertingToStringIllegalValueThenILLEGAL_VALUEIsReturned) { FullyEnabledTestDebugManager debugManager; - MockGraphicsAllocation graphicsAllocation; + GraphicsAllocation graphicsAllocation(nullptr, 0u, 0, true); graphicsAllocation.setAllocationType(static_cast(999)); auto result = debugManager.getAllocationTypeString(&graphicsAllocation); @@ -927,10 +927,15 @@ TEST(AllocationTypeLoggingSingle, givenGraphicsAllocationTypeWhenConvertingToStr TEST(AllocationTypeLoggingSingle, givenGraphicsAllocationTypeWhenDebugManagerDisabledThennullptrReturned) { FullyDisabledTestDebugManager debugManager; - MockGraphicsAllocation graphicsAllocation; + GraphicsAllocation graphicsAllocation(nullptr, 0u, 0, true); graphicsAllocation.setAllocationType(OCLRT::GraphicsAllocation::AllocationType::BUFFER); auto result = debugManager.getAllocationTypeString(&graphicsAllocation); EXPECT_STREQ(result, nullptr); } + +TEST(AllocationInfoLogging, givenBaseGraphicsAllocationWhenGettingImplementationSpecificAllocationInfoThenReturnEmptyInfoString) { + GraphicsAllocation graphicsAllocation(nullptr, 0u, 0, true); + EXPECT_STREQ(graphicsAllocation.getAllocationInfoString().c_str(), ""); +} diff --git a/unit_tests/os_interface/linux/debug_settings_manager_linux_tests.cpp b/unit_tests/os_interface/linux/debug_settings_manager_linux_tests.cpp index c7c46d2086..4949a5849a 100644 --- a/unit_tests/os_interface/linux/debug_settings_manager_linux_tests.cpp +++ b/unit_tests/os_interface/linux/debug_settings_manager_linux_tests.cpp @@ -6,8 +6,9 @@ */ #include "runtime/os_interface/debug_settings_manager.h" -#include "unit_tests/mocks/mock_graphics_allocation.h" +#include "unit_tests/mocks/linux/mock_drm_allocation.h" #include "unit_tests/os_interface/debug_settings_manager_fixture.h" + #include "test.h" TEST(DebugSettingsManager, GivenDebugSettingsManagerWithLogAllocationsThenLogsCorrectInfo) { @@ -19,9 +20,14 @@ TEST(DebugSettingsManager, GivenDebugSettingsManagerWithLogAllocationsThenLogsCo debugManager.flags.LogAllocationMemoryPool.set(true); - MockGraphicsAllocation allocation; + MockDrmAllocation allocation; allocation.setAllocationType(GraphicsAllocation::AllocationType::BUFFER); - allocation.overrideMemoryPool(MemoryPool::System64KBPages); + allocation.memoryPool = MemoryPool::System64KBPages; + + MockBufferObject bo; + bo.handle = 4; + + allocation.bo = &bo; debugManager.logAllocation(&allocation); @@ -38,6 +44,39 @@ TEST(DebugSettingsManager, GivenDebugSettingsManagerWithLogAllocationsThenLogsCo EXPECT_TRUE(str.find(threadIDCheck.str()) != std::string::npos); EXPECT_TRUE(str.find(memoryPoolCheck.str()) != std::string::npos); EXPECT_TRUE(str.find("AllocationType: BUFFER") != std::string::npos); + EXPECT_TRUE(str.find("Handle: 4") != std::string::npos); + } +} + +TEST(DebugSettingsManager, GivenDebugSettingsManagerWithDrmAllocationWithoutBOThenNoHandleLogged) { + FullyEnabledTestDebugManager debugManager; + + // Log file not created + bool logFileCreated = fileExists(debugManager.getLogFileName()); + EXPECT_FALSE(logFileCreated); + + debugManager.flags.LogAllocationMemoryPool.set(true); + + MockDrmAllocation allocation; + allocation.setAllocationType(GraphicsAllocation::AllocationType::BUFFER); + allocation.memoryPool = MemoryPool::System64KBPages; + + debugManager.logAllocation(&allocation); + + std::thread::id thisThread = std::this_thread::get_id(); + + std::stringstream threadIDCheck; + threadIDCheck << " ThreadID: " << thisThread; + + std::stringstream memoryPoolCheck; + memoryPoolCheck << " MemoryPool: " << allocation.getMemoryPool(); + + if (debugManager.wasFileCreated(debugManager.getLogFileName())) { + auto str = debugManager.getFileString(debugManager.getLogFileName()); + EXPECT_TRUE(str.find(threadIDCheck.str()) != std::string::npos); + EXPECT_TRUE(str.find(memoryPoolCheck.str()) != std::string::npos); + EXPECT_TRUE(str.find("AllocationType: BUFFER") != std::string::npos); + EXPECT_FALSE(str.find("Handle: 4") != std::string::npos); } } @@ -50,9 +89,9 @@ TEST(DebugSettingsManager, GivenDebugSettingsManagerWithoutLogAllocationsThenAll debugManager.flags.LogAllocationMemoryPool.set(false); - MockGraphicsAllocation allocation; + MockDrmAllocation allocation; allocation.setAllocationType(GraphicsAllocation::AllocationType::BUFFER); - allocation.overrideMemoryPool(MemoryPool::System64KBPages); + allocation.memoryPool = MemoryPool::System64KBPages; debugManager.logAllocation(&allocation);