From ca7d47598a63959d42750c62a2981e08ffa392a1 Mon Sep 17 00:00:00 2001 From: Daniel Chabrowski Date: Mon, 28 Feb 2022 13:56:41 +0000 Subject: [PATCH] Reintroduce prelim DRM debug support It was verified that the issue existed before the failing commit. Signed-off-by: Daniel Chabrowski daniel.chabrowski@intel.com Related-To: NEO-6591 --- .../os_interface/linux/CMakeLists.txt | 3 +- .../os_interface/linux/drm_uuid_tests.cpp | 44 +++- .../source/os_interface/linux/CMakeLists.txt | 3 +- .../source/os_interface/linux/drm_debug.cpp | 88 ++++++- shared/source/os_interface/linux/drm_debug.h | 69 +++++ .../source/os_interface/linux/ioctl_helper.h | 20 ++ .../linux/ioctl_helper_prelim.cpp | 50 ++++ .../linux/ioctl_helper_upstream.cpp | 32 ++- .../libult/linux/drm_mock_prelim_context.cpp | 47 ++++ .../libult/linux/drm_mock_prelim_context.h | 20 ++ .../test/common/libult/linux/drm_query_mock.h | 1 + .../os_interface/linux/CMakeLists.txt | 2 + .../linux/drm_debug_prelim_tests.cpp | 236 ++++++++++++++++++ .../os_interface/linux/drm_debug_tests.cpp | 37 +-- .../linux/ioctl_helper_tests_prelim.cpp | 1 + .../linux/ioctl_helper_tests_upstream.cpp | 43 ++++ 16 files changed, 665 insertions(+), 31 deletions(-) create mode 100644 shared/source/os_interface/linux/drm_debug.h create mode 100644 shared/test/unit_test/os_interface/linux/drm_debug_prelim_tests.cpp rename {opencl => shared}/test/unit_test/os_interface/linux/drm_debug_tests.cpp (56%) diff --git a/opencl/test/unit_test/os_interface/linux/CMakeLists.txt b/opencl/test/unit_test/os_interface/linux/CMakeLists.txt index a78357903d957..2b6d4ee5b8272 100644 --- a/opencl/test/unit_test/os_interface/linux/CMakeLists.txt +++ b/opencl/test/unit_test/os_interface/linux/CMakeLists.txt @@ -15,7 +15,6 @@ set(IGDRCL_SRCS_tests_os_interface_linux ${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_mm_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_tests_1.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_tests_2.cpp - ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_debug_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_gem_close_worker_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_mapper_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_tests.cpp @@ -24,7 +23,7 @@ set(IGDRCL_SRCS_tests_os_interface_linux ${CMAKE_CURRENT_SOURCE_DIR}/drm_residency_handler_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_system_info_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_uuid_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drm_uuid_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/file_logger_linux_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_linux_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_linux_tests.h diff --git a/opencl/test/unit_test/os_interface/linux/drm_uuid_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_uuid_tests.cpp index 95f47067af69d..d44c93d7b0069 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_uuid_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_uuid_tests.cpp @@ -5,6 +5,7 @@ * */ +#include "shared/source/os_interface/linux/drm_debug.h" #include "shared/test/common/libult/linux/drm_mock.h" #include "gtest/gtest.h" @@ -32,8 +33,49 @@ TEST(DrmUuidTest, GivenDrmWhenGeneratingElfUUIDThenCorrectStringsAreReturned) { auto executionEnvironment = std::make_unique(); executionEnvironment->prepareRootDeviceEnvironments(1); DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; + + std::string elfClassUuid = classNamesToUuid[static_cast(Drm::ResourceClass::Elf)].second; + std::string Uuid1stElfClass = elfClassUuid.substr(0, 18); + char data[] = "abc"; auto uuid1 = drm.generateElfUUID(static_cast(data)); + std::string Uuid1stElfBin1 = uuid1.substr(0, 18); + EXPECT_STREQ(Uuid1stElfClass.c_str(), Uuid1stElfBin1.c_str()); - EXPECT_STREQ("00000000-0000-0000-0000-000000000001", uuid1.c_str()); + char data2[] = "123"; + auto uuid2 = drm.generateElfUUID(static_cast(data2)); + std::string Uuid1stElfBin2 = uuid2.substr(0, 18); + EXPECT_STREQ(Uuid1stElfClass.c_str(), Uuid1stElfBin2.c_str()); + + auto uuid3 = drm.generateElfUUID(reinterpret_cast(0xFFFFFFFFFFFFFFFF)); + std::string UuidElf = Uuid1stElfClass + "-ffff-ffffffffffff"; + EXPECT_STREQ(UuidElf.c_str(), uuid3.c_str()); +} + +TEST(DrmUuidTest, whenResourceClassIsUsedToIndexClassNamesThenCorrectNamesAreReturned) { + EXPECT_STREQ(classNamesToUuid[static_cast(Drm::ResourceClass::Elf)].first, "I915_UUID_CLASS_ELF_BINARY"); + EXPECT_STREQ(classNamesToUuid[static_cast(Drm::ResourceClass::Isa)].first, "I915_UUID_CLASS_ISA_BYTECODE"); + EXPECT_STREQ(classNamesToUuid[static_cast(Drm::ResourceClass::ContextSaveArea)].first, "I915_UUID_L0_SIP_AREA"); + EXPECT_STREQ(classNamesToUuid[static_cast(Drm::ResourceClass::ModuleHeapDebugArea)].first, "I915_UUID_L0_MODULE_AREA"); + EXPECT_STREQ(classNamesToUuid[static_cast(Drm::ResourceClass::SbaTrackingBuffer)].first, "I915_UUID_L0_SBA_AREA"); + EXPECT_STREQ(classNamesToUuid[static_cast(Drm::ResourceClass::L0ZebinModule)].first, "L0_ZEBIN_MODULE"); +} + +TEST(DrmUuidTest, givenUuidStringWhenGettingClassIndexThenCorrectIndexForValidStringsIsReturned) { + uint32_t index = 100; + auto validUuid = DrmUuid::getClassUuidIndex(classNamesToUuid[static_cast(Drm::ResourceClass::ContextSaveArea)].second, index); + + EXPECT_TRUE(validUuid); + EXPECT_EQ(static_cast(Drm::ResourceClass::ContextSaveArea), index); + + validUuid = DrmUuid::getClassUuidIndex(classNamesToUuid[static_cast(Drm::ResourceClass::ModuleHeapDebugArea)].second, index); + + EXPECT_TRUE(validUuid); + EXPECT_EQ(static_cast(Drm::ResourceClass::ModuleHeapDebugArea), index); + + index = 100; + validUuid = DrmUuid::getClassUuidIndex("invalid", index); + + EXPECT_FALSE(validUuid); + EXPECT_EQ(100u, index); } diff --git a/shared/source/os_interface/linux/CMakeLists.txt b/shared/source/os_interface/linux/CMakeLists.txt index 2b8d44f3954fd..523ace60bf998 100644 --- a/shared/source/os_interface/linux/CMakeLists.txt +++ b/shared/source/os_interface/linux/CMakeLists.txt @@ -24,7 +24,8 @@ set(NEO_CORE_OS_INTERFACE_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream.h ${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream.inl ${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_bdw_and_later.inl - ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_debug.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drm_debug.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drm_debug.h ${CMAKE_CURRENT_SOURCE_DIR}/drm_gem_close_worker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_gem_close_worker.h ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager.cpp diff --git a/shared/source/os_interface/linux/drm_debug.cpp b/shared/source/os_interface/linux/drm_debug.cpp index 654f4db43f742..ca69f3e236d95 100644 --- a/shared/source/os_interface/linux/drm_debug.cpp +++ b/shared/source/os_interface/linux/drm_debug.cpp @@ -5,23 +5,68 @@ * */ -#include "drm_neo.h" +#include "shared/source/os_interface/linux/drm_debug.h" + +#include "shared/source/helpers/string.h" +#include "shared/source/os_interface/linux/drm_neo.h" + +#include +#include namespace NEO { bool Drm::registerResourceClasses() { - return false; + for (auto classNameUUID : classNamesToUuid) { + auto className = classNameUUID.first; + auto uuid = classNameUUID.second; + + const auto result = ioctlHelper->registerStringClassUuid(this, uuid, (uintptr_t)className, strnlen_s(className, 100)); + if (result.retVal != 0) { + return false; + } + + classHandles.push_back(result.handle); + } + return true; } uint32_t Drm::registerResource(ResourceClass classType, const void *data, size_t size) { - return 0; + if (classHandles.size() < static_cast(classType)) { + return 0; + } + + std::string uuid; + if (classType == NEO::Drm::ResourceClass::Elf) { + uuid = generateElfUUID(data); + } else { + uuid = generateUUID(); + } + + const auto uuidClass = classHandles[static_cast(classType)]; + const auto ptr = size > 0 ? (uintptr_t)data : 0; + const auto result = ioctlHelper->registerUuid(this, uuid, uuidClass, ptr, size); + + PRINT_DEBUGGER_INFO_LOG("PRELIM_DRM_IOCTL_I915_UUID_REGISTER: classType = %d, uuid = %s, data = %p, handle = %lu, ret = %d\n", (int)classType, std::string(uuid, 36).c_str(), ptr, result.handle, result.retVal); + DEBUG_BREAK_IF(result.retVal != 0); + + return result.handle; } uint32_t Drm::registerIsaCookie(uint32_t isaHandle) { - return 0; + auto uuid = generateUUID(); + + const auto result = ioctlHelper->registerUuid(this, uuid, isaHandle, 0, 0); + + PRINT_DEBUGGER_INFO_LOG("PRELIM_DRM_IOCTL_I915_UUID_REGISTER: isa handle = %lu, uuid = %s, data = %p, handle = %lu, ret = %d\n", isaHandle, std::string(uuid, 36).c_str(), 0, result.handle, result.retVal); + DEBUG_BREAK_IF(result.retVal != 0); + + return result.handle; } void Drm::unregisterResource(uint32_t handle) { + PRINT_DEBUGGER_INFO_LOG("PRELIM_DRM_IOCTL_I915_UUID_UNREGISTER: handle = %lu\n", handle); + [[maybe_unused]] const auto ret = ioctlHelper->unregisterUuid(this, handle); + DEBUG_BREAK_IF(ret != 0); } std::string Drm::generateUUID() { @@ -40,12 +85,37 @@ std::string Drm::generateUUID() { } std::string Drm::generateElfUUID(const void *data) { - return generateUUID(); + std::string elf_class_uuid = classNamesToUuid[static_cast(Drm::ResourceClass::Elf)].second; + std::string UUID1st = elf_class_uuid.substr(0, 18); + + const char uuidString[] = "%s-%04" SCNx64 "-%012" SCNx64; + char buffer[36 + 1] = "00000000-0000-0000-0000-000000000000"; + + uint64_t parts[2] = {0, 0}; + parts[0] = reinterpret_cast(data) & 0xFFFFFFFFFFFF; + parts[1] = (reinterpret_cast(data) & 0xFFFF000000000000) >> 48; + snprintf(buffer, sizeof(buffer), uuidString, UUID1st.c_str(), parts[1], parts[0]); + + return std::string(buffer, 36); +} + +void Drm::checkContextDebugSupport() { + contextDebugSupported = ioctlHelper->isContextDebugSupported(this); +} + +void Drm::setContextDebugFlag(uint32_t drmContextId) { + [[maybe_unused]] const auto retVal = ioctlHelper->setContextDebugFlag(this, drmContextId); + DEBUG_BREAK_IF(retVal != 0 && contextDebugSupported); } -void Drm::checkContextDebugSupport() {} -void Drm::setContextDebugFlag(uint32_t drmContextId) {} -uint32_t Drm::notifyFirstCommandQueueCreated() { return 0; } -void Drm::notifyLastCommandQueueDestroyed(uint32_t handle) {} +uint32_t Drm::notifyFirstCommandQueueCreated() { + const auto result = ioctlHelper->registerStringClassUuid(this, uuidL0CommandQueueHash, (uintptr_t)uuidL0CommandQueueName, strnlen_s(uuidL0CommandQueueName, 100)); + DEBUG_BREAK_IF(result.retVal); + return result.handle; +} + +void Drm::notifyLastCommandQueueDestroyed(uint32_t handle) { + unregisterResource(handle); +} } // namespace NEO diff --git a/shared/source/os_interface/linux/drm_debug.h b/shared/source/os_interface/linux/drm_debug.h new file mode 100644 index 0000000000000..b34e4609303b1 --- /dev/null +++ b/shared/source/os_interface/linux/drm_debug.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/linux/drm_neo.h" + +#include +#include + +namespace NEO { + +/* + +UUIDs: Deterministic generation + +$ python -q # Version 3.x +>>> import uuid +>>> +>>> I915_UUID_NAMESPACE = uuid.UUID(bytes = b'i915' * 4); +>>> I915_UUID_NAMESPACE +UUID('69393135-6939-3135-6939-313569393135') +>>> +>>> +>>> I915_UUID = lambda x: uuid.uuid5(I915_UUID_NAMESPACE, x) +>>> I915_UUID('I915_UUID_CLASS_CUSTOM') +UUID('74644f12-6a2c-59e6-ac92-ea7f2ef530eb') +>>> +>>> +>>> L0_UUID_NAMESPACE = uuid.UUID(bytes = b'L0' * 8); +>>> L0_UUID_NAMESPACE +UUID('4c304c30-4c30-4c30-4c30-4c304c304c30') +>>> +>>> +>>> L0_UUID = lambda x: uuid.uuid5(L0_UUID_NAMESPACE, x) +>>> L0_UUID('L0_ZEBIN_MODULE') +UUID('88d347c1-c79b-530a-b68f-e0db7d575e04') +>>> +>>> +>>> L0_UUID('L0_COMMAND_QUEUE') +UUID('285208b2-c5e0-5fcb-90bb-7576ed7a9697') + +*/ + +using ClassNamesArray = std::array, size_t(Drm::ResourceClass::MaxSize)>; +const ClassNamesArray classNamesToUuid = {std::make_pair("I915_UUID_CLASS_ELF_BINARY", "31203221-8069-5a0a-9d43-94a4d3395ee1"), + std::make_pair("I915_UUID_CLASS_ISA_BYTECODE", "53baed0a-12c3-5d19-aa69-ab9c51aa1039"), + std::make_pair("I915_UUID_L0_MODULE_AREA", "a411e82e-16c9-58b7-bfb5-b209b8601d5f"), + std::make_pair("I915_UUID_L0_SIP_AREA", "21fd6baf-f918-53cc-ba74-f09aaaea2dc0"), + std::make_pair("I915_UUID_L0_SBA_AREA", "ec45189d-97d3-58e2-80d1-ab52c72fdcc1"), + std::make_pair("L0_ZEBIN_MODULE", "88d347c1-c79b-530a-b68f-e0db7d575e04")}; + +constexpr auto uuidL0CommandQueueName = "L0_COMMAND_QUEUE"; +constexpr auto uuidL0CommandQueueHash = "285208b2-c5e0-5fcb-90bb-7576ed7a9697"; // L0_UUID('L0_COMMAND_QUEUE') + +struct DrmUuid { + static bool getClassUuidIndex(std::string uuid, uint32_t &index) { + for (uint32_t i = 0; i < uint32_t(Drm::ResourceClass::MaxSize); i++) { + if (uuid == classNamesToUuid[i].second) { + index = i; + return true; + } + } + return false; + } +}; +} // namespace NEO diff --git a/shared/source/os_interface/linux/ioctl_helper.h b/shared/source/os_interface/linux/ioctl_helper.h index 8e048cf17b62b..b96d24b3429a8 100644 --- a/shared/source/os_interface/linux/ioctl_helper.h +++ b/shared/source/os_interface/linux/ioctl_helper.h @@ -66,6 +66,11 @@ struct VmBindParams { uint64_t extensions; }; +struct UuidRegisterResult { + uint32_t retVal; + uint32_t handle; +}; + using MemRegionsVec = StackVec; class IoctlHelper { @@ -114,6 +119,11 @@ class IoctlHelper { virtual int vmUnbind(Drm *drm, const VmBindParams &vmBindParams) = 0; virtual bool getEuStallProperties(std::array &properties, uint64_t dssBufferSize, uint64_t samplingRate, uint64_t pollPeriod, uint64_t engineInstance) = 0; virtual uint32_t getEuStallFdParameter() = 0; + virtual UuidRegisterResult registerUuid(Drm *drm, const std::string &uuid, uint32_t uuidClass, uint64_t ptr, uint64_t size) = 0; + virtual UuidRegisterResult registerStringClassUuid(Drm *drm, const std::string &uuid, uint64_t ptr, uint64_t size) = 0; + virtual int unregisterUuid(Drm *drm, uint32_t handle) = 0; + virtual bool isContextDebugSupported(Drm *drm) = 0; + virtual int setContextDebugFlag(Drm *drm, uint32_t drmContextId) = 0; }; class IoctlHelperUpstream : public IoctlHelper { @@ -159,6 +169,11 @@ class IoctlHelperUpstream : public IoctlHelper { int vmUnbind(Drm *drm, const VmBindParams &vmBindParams) override; bool getEuStallProperties(std::array &properties, uint64_t dssBufferSize, uint64_t samplingRate, uint64_t pollPeriod, uint64_t engineInstance) override; uint32_t getEuStallFdParameter() override; + UuidRegisterResult registerUuid(Drm *drm, const std::string &uuid, uint32_t uuidClass, uint64_t ptr, uint64_t size) override; + UuidRegisterResult registerStringClassUuid(Drm *drm, const std::string &uuid, uint64_t ptr, uint64_t size) override; + int unregisterUuid(Drm *drm, uint32_t handle) override; + bool isContextDebugSupported(Drm *drm) override; + int setContextDebugFlag(Drm *drm, uint32_t drmContextId) override; }; template @@ -217,6 +232,11 @@ class IoctlHelperPrelim20 : public IoctlHelper { int vmUnbind(Drm *drm, const VmBindParams &vmBindParams) override; bool getEuStallProperties(std::array &properties, uint64_t dssBufferSize, uint64_t samplingRate, uint64_t pollPeriod, uint64_t engineInstance) override; uint32_t getEuStallFdParameter() override; + UuidRegisterResult registerUuid(Drm *drm, const std::string &uuid, uint32_t uuidClass, uint64_t ptr, uint64_t size) override; + UuidRegisterResult registerStringClassUuid(Drm *drm, const std::string &uuid, uint64_t ptr, uint64_t size) override; + int unregisterUuid(Drm *drm, uint32_t handle) override; + bool isContextDebugSupported(Drm *drm) override; + int setContextDebugFlag(Drm *drm, uint32_t drmContextId) override; }; } // namespace NEO diff --git a/shared/source/os_interface/linux/ioctl_helper_prelim.cpp b/shared/source/os_interface/linux/ioctl_helper_prelim.cpp index 6ccb71523f911..83b9ae2848e0a 100644 --- a/shared/source/os_interface/linux/ioctl_helper_prelim.cpp +++ b/shared/source/os_interface/linux/ioctl_helper_prelim.cpp @@ -10,6 +10,7 @@ #include "shared/source/helpers/hw_helper.h" #include "shared/source/helpers/hw_info.h" #include "shared/source/helpers/ptr_math.h" +#include "shared/source/helpers/string.h" #include "shared/source/os_interface/linux/cache_info.h" #include "shared/source/os_interface/linux/ioctl_helper.h" @@ -319,6 +320,7 @@ int32_t IoctlHelperPrelim20::getComputeEngineClass() { std::optional IoctlHelperPrelim20::getHasPageFaultParamId() { return PRELIM_I915_PARAM_HAS_PAGE_FAULT; }; + bool IoctlHelperPrelim20::getEuStallProperties(std::array &properties, uint64_t dssBufferSize, uint64_t samplingRate, uint64_t pollPeriod, uint64_t engineInstance) { properties[0] = PRELIM_DRM_I915_EU_STALL_PROP_BUF_SZ; properties[1] = dssBufferSize; @@ -472,4 +474,52 @@ int IoctlHelperPrelim20::vmUnbind(Drm *drm, const VmBindParams &vmBindParams) { auto prelimVmBind = translateVmBindParamsToPrelimStruct(vmBindParams); return IoctlHelper::ioctl(drm, PRELIM_DRM_IOCTL_I915_GEM_VM_UNBIND, &prelimVmBind); } + +UuidRegisterResult IoctlHelperPrelim20::registerUuid(Drm *drm, const std::string &uuid, uint32_t uuidClass, uint64_t ptr, uint64_t size) { + prelim_drm_i915_uuid_control uuidControl = {}; + memcpy_s(uuidControl.uuid, sizeof(uuidControl.uuid), uuid.c_str(), uuid.size()); + uuidControl.uuid_class = uuidClass; + uuidControl.ptr = ptr; + uuidControl.size = size; + + const auto retVal = IoctlHelper::ioctl(drm, PRELIM_DRM_IOCTL_I915_UUID_REGISTER, &uuidControl); + + return { + retVal, + uuidControl.handle, + }; +} + +UuidRegisterResult IoctlHelperPrelim20::registerStringClassUuid(Drm *drm, const std::string &uuid, uint64_t ptr, uint64_t size) { + return registerUuid(drm, uuid, PRELIM_I915_UUID_CLASS_STRING, ptr, size); +} + +int IoctlHelperPrelim20::unregisterUuid(Drm *drm, uint32_t handle) { + prelim_drm_i915_uuid_control uuidControl = {}; + uuidControl.handle = handle; + + return IoctlHelper::ioctl(drm, PRELIM_DRM_IOCTL_I915_UUID_UNREGISTER, &uuidControl); +} + +bool IoctlHelperPrelim20::isContextDebugSupported(Drm *drm) { + drm_i915_gem_context_param ctxParam = {}; + ctxParam.size = 0; + ctxParam.param = PRELIM_I915_CONTEXT_PARAM_DEBUG_FLAGS; + ctxParam.ctx_id = 0; + ctxParam.value = 0; + + const auto retVal = IoctlHelper::ioctl(drm, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &ctxParam); + return retVal == 0 && ctxParam.value == (PRELIM_I915_CONTEXT_PARAM_DEBUG_FLAG_SIP << 32); +} + +int IoctlHelperPrelim20::setContextDebugFlag(Drm *drm, uint32_t drmContextId) { + drm_i915_gem_context_param ctxParam = {}; + ctxParam.size = 0; + ctxParam.param = PRELIM_I915_CONTEXT_PARAM_DEBUG_FLAGS; + ctxParam.ctx_id = drmContextId; + ctxParam.value = PRELIM_I915_CONTEXT_PARAM_DEBUG_FLAG_SIP << 32 | PRELIM_I915_CONTEXT_PARAM_DEBUG_FLAG_SIP; + + return IoctlHelper::ioctl(drm, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &ctxParam); +} + } // namespace NEO diff --git a/shared/source/os_interface/linux/ioctl_helper_upstream.cpp b/shared/source/os_interface/linux/ioctl_helper_upstream.cpp index a7156ec4e805b..d024ad9c72735 100644 --- a/shared/source/os_interface/linux/ioctl_helper_upstream.cpp +++ b/shared/source/os_interface/linux/ioctl_helper_upstream.cpp @@ -120,6 +120,7 @@ uint32_t IoctlHelperUpstream::getComputeSlicesIoctlVal() { std::unique_ptr IoctlHelperUpstream::prepareVmBindExt(const StackVec &bindExtHandles) { return {}; } + uint64_t IoctlHelperUpstream::getFlagsForVmBind(bool bindCapture, bool bindImmediate, bool bindMakeResident) { return 0u; } @@ -151,7 +152,7 @@ int32_t IoctlHelperUpstream::getComputeEngineClass() { uint16_t IoctlHelperUpstream::getWaitUserFenceSoftFlag() { return 0; -}; +} int IoctlHelperUpstream::execBuffer(Drm *drm, drm_i915_gem_execbuffer2 *execBuffer, uint64_t completionGpuAddress, uint32_t counterValue) { return ioctl(drm, DRM_IOCTL_I915_GEM_EXECBUFFER2, execBuffer); @@ -164,6 +165,7 @@ bool IoctlHelperUpstream::completionFenceExtensionSupported(const HardwareInfo & std::optional IoctlHelperUpstream::getHasPageFaultParamId() { return std::nullopt; }; + bool IoctlHelperUpstream::getEuStallProperties(std::array &properties, uint64_t dssBufferSize, uint64_t samplingRate, uint64_t pollPeriod, uint64_t engineInstance) { return false; } @@ -183,17 +185,21 @@ uint32_t IoctlHelperUpstream::getFlagsForVmCreate(bool disableScratch, bool enab uint32_t IoctlHelperUpstream::createContextWithAccessCounters(Drm *drm, drm_i915_gem_context_create_ext &gcc) { return EINVAL; } + uint32_t IoctlHelperUpstream::createCooperativeContext(Drm *drm, drm_i915_gem_context_create_ext &gcc) { return EINVAL; } std::unique_ptr IoctlHelperUpstream::createVmBindExtSetPat() { return {}; -}; +} + void IoctlHelperUpstream::fillVmBindExtSetPat(const std::unique_ptr &vmBindExtSetPat, uint64_t patIndex, uint64_t nextExtension) {} + std::unique_ptr IoctlHelperUpstream::createVmBindExtSyncFence() { return {}; } + void IoctlHelperUpstream::fillVmBindExtSyncFence(const std::unique_ptr &vmBindExtSyncFence, uint64_t fenceAddress, uint64_t fenceValue, uint64_t nextExtension) {} std::optional IoctlHelperUpstream::getCopyClassSaturatePCIECapability() { @@ -207,7 +213,29 @@ std::optional IoctlHelperUpstream::getCopyClassSaturateLinkCapability( int IoctlHelperUpstream::vmBind(Drm *drm, const VmBindParams &vmBindParams) { return 0; } + int IoctlHelperUpstream::vmUnbind(Drm *drm, const VmBindParams &vmBindParams) { return 0; } + +UuidRegisterResult IoctlHelperUpstream::registerUuid(Drm *drm, const std::string &uuid, uint32_t uuidClass, uint64_t ptr, uint64_t size) { + return {0, 0}; +} + +UuidRegisterResult IoctlHelperUpstream::registerStringClassUuid(Drm *drm, const std::string &uuid, uint64_t ptr, uint64_t size) { + return {0, 0}; +} + +int IoctlHelperUpstream::unregisterUuid(Drm *drm, uint32_t handle) { + return 0; +} + +bool IoctlHelperUpstream::isContextDebugSupported(Drm *drm) { + return false; +} + +int IoctlHelperUpstream::setContextDebugFlag(Drm *drm, uint32_t drmContextId) { + return 0; +} + } // namespace NEO diff --git a/shared/test/common/libult/linux/drm_mock_prelim_context.cpp b/shared/test/common/libult/linux/drm_mock_prelim_context.cpp index 00e41f4ee51b9..44f51210fc2e6 100644 --- a/shared/test/common/libult/linux/drm_mock_prelim_context.cpp +++ b/shared/test/common/libult/linux/drm_mock_prelim_context.cpp @@ -9,6 +9,7 @@ #include "shared/source/helpers/basic_math.h" #include "shared/source/helpers/ptr_math.h" +#include "shared/source/helpers/string.h" #include "shared/source/os_interface/linux/cache_info_impl.h" #include "shared/test/common/libult/linux/drm_mock_helper.h" @@ -47,6 +48,13 @@ int DrmMockPrelimContext::handlePrelimRequest(unsigned long request, void *arg) return vmBindQueryReturn; } } break; + case DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM: { + auto gp = static_cast(arg); + if (gp->param == PRELIM_I915_CONTEXT_PARAM_DEBUG_FLAGS) { + gp->value = contextDebugSupported ? PRELIM_I915_CONTEXT_PARAM_DEBUG_FLAG_SIP << 32 : 0; + return 0; + } + } break; case PRELIM_DRM_IOCTL_I915_GEM_CLOS_RESERVE: { auto closReserveArg = static_cast(arg); closIndex++; @@ -86,6 +94,41 @@ int DrmMockPrelimContext::handlePrelimRequest(unsigned long request, void *arg) vmUnbindCalled++; return vmUnbindReturn; } break; + case PRELIM_DRM_IOCTL_I915_UUID_REGISTER: { + auto uuidControl = reinterpret_cast(arg); + + if (uuidControl->uuid_class != uint32_t(PRELIM_I915_UUID_CLASS_STRING) && uuidControl->uuid_class > uuidHandle) { + return -1; + } + + uuidControl->handle = uuidHandle++; + + receivedRegisterUuid = UuidControl{ + {}, + uuidControl->uuid_class, + reinterpret_cast(uuidControl->ptr), + uuidControl->size, + uuidControl->handle, + uuidControl->flags, + uuidControl->extensions, + }; + memcpy_s(receivedRegisterUuid->uuid, sizeof(receivedRegisterUuid->uuid), uuidControl->uuid, sizeof(uuidControl->uuid)); + return uuidControlReturn; + } break; + case PRELIM_DRM_IOCTL_I915_UUID_UNREGISTER: { + auto uuidControl = reinterpret_cast(arg); + receivedUnregisterUuid = UuidControl{ + {}, + uuidControl->uuid_class, + reinterpret_cast(uuidControl->ptr), + uuidControl->size, + uuidControl->handle, + uuidControl->flags, + uuidControl->extensions, + }; + memcpy_s(receivedUnregisterUuid->uuid, sizeof(receivedUnregisterUuid->uuid), uuidControl->uuid, sizeof(uuidControl->uuid)); + return uuidControlReturn; + } break; default: return -1; @@ -257,3 +300,7 @@ uint32_t DrmPrelimHelper::getDistanceInfoQueryId() { uint32_t DrmPrelimHelper::getComputeEngineClass() { return PRELIM_I915_ENGINE_CLASS_COMPUTE; } + +uint32_t DrmPrelimHelper::getStringUuidClass() { + return PRELIM_I915_UUID_CLASS_STRING; +} diff --git a/shared/test/common/libult/linux/drm_mock_prelim_context.h b/shared/test/common/libult/linux/drm_mock_prelim_context.h index afa553c60cace..01ef19add7d15 100644 --- a/shared/test/common/libult/linux/drm_mock_prelim_context.h +++ b/shared/test/common/libult/linux/drm_mock_prelim_context.h @@ -11,14 +11,27 @@ #include "shared/source/helpers/hw_info.h" #include "shared/source/os_interface/linux/cache_info.h" +#include + using namespace NEO; +struct UuidControl { + char uuid[36]{}; + uint32_t uuidClass{0}; + void *ptr{nullptr}; + uint64_t size{0}; + uint32_t handle{0}; + uint32_t flags{0}; + uint64_t extensions{0}; +}; + struct DrmMockPrelimContext { const HardwareInfo *hwInfo; const RootDeviceEnvironment &rootDeviceEnvironment; const CacheInfo *cacheInfo; const bool &failRetTopology; const BcsInfoMask &supportedCopyEnginesMask; + const bool &contextDebugSupported; uint16_t closIndex{0}; uint16_t maxNumWays{32}; @@ -37,6 +50,12 @@ struct DrmMockPrelimContext { int hasPageFaultQueryValue{0}; int hasPageFaultQueryReturn{0}; + uint32_t uuidHandle{1}; + std::optional receivedRegisterUuid{}; + std::optional receivedUnregisterUuid{}; + + int uuidControlReturn{0}; + bool failDistanceInfoQuery{false}; bool disableCcsSupport{false}; @@ -48,4 +67,5 @@ namespace DrmPrelimHelper { uint32_t getQueryComputeSlicesIoctl(); uint32_t getDistanceInfoQueryId(); uint32_t getComputeEngineClass(); +uint32_t getStringUuidClass(); }; // namespace DrmPrelimHelper diff --git a/shared/test/common/libult/linux/drm_query_mock.h b/shared/test/common/libult/linux/drm_query_mock.h index 806d6c5d451a8..a85a3ae7bcf1b 100644 --- a/shared/test/common/libult/linux/drm_query_mock.h +++ b/shared/test/common/libult/linux/drm_query_mock.h @@ -43,6 +43,7 @@ class DrmQueryMock : public DrmMock { getCacheInfo(), failRetTopology, supportedCopyEnginesMask, + contextDebugSupported, }; static constexpr uint32_t maxEngineCount{9}; diff --git a/shared/test/unit_test/os_interface/linux/CMakeLists.txt b/shared/test/unit_test/os_interface/linux/CMakeLists.txt index 24b6dc4c9589c..bc75eb4b750f9 100644 --- a/shared/test/unit_test/os_interface/linux/CMakeLists.txt +++ b/shared/test/unit_test/os_interface/linux/CMakeLists.txt @@ -10,6 +10,7 @@ set(NEO_CORE_OS_INTERFACE_TESTS_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/device_factory_tests_linux.h ${CMAKE_CURRENT_SOURCE_DIR}/drm_bind_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_l0_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_debug_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_engine_info_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_memory_info_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_mock_impl.h @@ -23,6 +24,7 @@ set(NEO_CORE_OS_INTERFACE_TESTS_LINUX if(NEO_ENABLE_i915_PRELIM_DETECTION) list(APPEND NEO_CORE_OS_INTERFACE_TESTS_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/drm_cache_info_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drm_debug_prelim_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_query_topology_prelim_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_with_prelim_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_tests_prelim.cpp diff --git a/shared/test/unit_test/os_interface/linux/drm_debug_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_debug_prelim_tests.cpp new file mode 100644 index 0000000000000..f04ebca8acd78 --- /dev/null +++ b/shared/test/unit_test/os_interface/linux/drm_debug_prelim_tests.cpp @@ -0,0 +1,236 @@ +/* + * Copyright (C) 2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/linux/drm_debug.h" +#include "shared/test/common/libult/linux/drm_query_mock.h" +#include "shared/test/common/test_macros/matchers.h" +#include "shared/test/common/test_macros/test.h" + +#include "gtest/gtest.h" + +using namespace NEO; + +struct DrmDebugPrelimTest : public ::testing::Test { + public: + void SetUp() override { + executionEnvironment = std::make_unique(); + executionEnvironment->prepareRootDeviceEnvironments(1); + executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(NEO::defaultHwInfo.get()); + } + + void TearDown() override { + } + + protected: + std::unique_ptr executionEnvironment; +}; + +TEST_F(DrmDebugPrelimTest, GivenDrmWhenRegisteringClassesThenHandlesAreStored) { + DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]); + + auto handle = drm.context.uuidHandle; + + EXPECT_EQ(0u, drm.classHandles.size()); + auto result = drm.registerResourceClasses(); + + EXPECT_TRUE(result); + EXPECT_EQ(classNamesToUuid.size(), drm.classHandles.size()); + + for (size_t i = 0; i < classNamesToUuid.size(); i++) { + EXPECT_EQ(drm.classHandles[i], handle); + handle++; + } + ASSERT_TRUE(drm.context.receivedRegisterUuid); + EXPECT_THAT(drm.context.receivedRegisterUuid->uuid, testing::HasSubstr(classNamesToUuid[classNamesToUuid.size() - 1].second)); +} + +TEST_F(DrmDebugPrelimTest, GivenUnsupportedUUIDRegisterIoctlWhenRegisteringClassesThenErrorIsReturnedAndClassHandlesAreEmpty) { + DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]); + + drm.context.uuidControlReturn = -1; + + EXPECT_EQ(0u, drm.classHandles.size()); + auto result = drm.registerResourceClasses(); + + EXPECT_FALSE(result); + EXPECT_EQ(0u, drm.classHandles.size()); +} + +TEST_F(DrmDebugPrelimTest, GivenNoClassesRegisteredWhenRegisteringResourceThenRegisterUUIDIoctlIsNotCalledAndZeroHandleReturned) { + DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]); + + auto registeredHandle = drm.registerResource(Drm::ResourceClass::Isa, nullptr, 0); + EXPECT_EQ(0u, registeredHandle); + EXPECT_EQ(0u, drm.ioctlCallsCount); +} + +TEST_F(DrmDebugPrelimTest, GivenDrmWhenRegisteringResourceWithoutDataThenRegisterUUIDIoctlIsCalled) { + DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]); + + const auto result = drm.registerResourceClasses(); + EXPECT_TRUE(result); + + const auto handle = drm.context.uuidHandle; + auto registeredHandle = drm.registerResource(Drm::ResourceClass::Isa, nullptr, 0); + + EXPECT_EQ(handle + 1, drm.context.uuidHandle); + EXPECT_EQ(handle, registeredHandle); + + const auto &receivedUuid = drm.context.receivedRegisterUuid; + ASSERT_TRUE(receivedUuid); + + EXPECT_EQ(nullptr, receivedUuid->ptr); + EXPECT_EQ(0u, receivedUuid->size); + EXPECT_THAT(receivedUuid->uuid, testing::HasSubstr(std::string("00000000-0000-0000"))); + EXPECT_EQ(drm.classHandles[static_cast(Drm::ResourceClass::Isa)], receivedUuid->uuidClass); +} + +TEST_F(DrmDebugPrelimTest, GivenDrmWhenRegisteringResourceWithDataThenRegisterUUIDIoctlIsCalledWithCorrectData) { + DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]); + + auto result = drm.registerResourceClasses(); + EXPECT_TRUE(result); + + auto handle = drm.context.uuidHandle; + uint64_t data = 0x12345678; + + auto registeredHandle = drm.registerResource(Drm::ResourceClass::Isa, &data, sizeof(uint64_t)); + + EXPECT_EQ(handle + 1, drm.context.uuidHandle); + EXPECT_EQ(handle, registeredHandle); + + const auto &receivedUuid = drm.context.receivedRegisterUuid; + ASSERT_TRUE(receivedUuid); + + EXPECT_EQ(&data, receivedUuid->ptr); + EXPECT_EQ(sizeof(uint64_t), receivedUuid->size); + EXPECT_THAT(receivedUuid->uuid, testing::HasSubstr(std::string("00000000-0000-0000"))); + EXPECT_EQ(drm.classHandles[static_cast(Drm::ResourceClass::Isa)], receivedUuid->uuidClass); + EXPECT_EQ(0u, receivedUuid->flags); + EXPECT_EQ(0u, receivedUuid->extensions); +} + +TEST_F(DrmDebugPrelimTest, GivenDrmWhenUnregisteringResourceThenUnregisterUUIDIoctlIsCalled) { + DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]); + + auto result = drm.registerResourceClasses(); + EXPECT_TRUE(result); + + uint64_t data = 0x12345678; + auto registeredHandle = drm.registerResource(Drm::ResourceClass::Isa, &data, sizeof(uint64_t)); + + drm.unregisterResource(registeredHandle); + + const auto &receivedUuid = drm.context.receivedUnregisterUuid; + ASSERT_TRUE(receivedUuid); + + EXPECT_EQ(registeredHandle, receivedUuid->handle); + EXPECT_EQ(nullptr, receivedUuid->ptr); + EXPECT_EQ(0u, receivedUuid->size); + EXPECT_EQ(0u, receivedUuid->uuidClass); + EXPECT_EQ(0u, receivedUuid->flags); + EXPECT_EQ(0u, receivedUuid->extensions); +} + +TEST_F(DrmDebugPrelimTest, GivenDrmWhenNotifyFirstCommandQueueCreatedCalledThenCorrectUuidIsRegisteredWithCorrectData) { + DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]); + + auto handle = drm.context.uuidHandle; + auto registeredHandle = drm.notifyFirstCommandQueueCreated(); + + EXPECT_EQ(handle + 1, drm.context.uuidHandle); + EXPECT_EQ(handle, registeredHandle); + + const auto &receivedUuid = drm.context.receivedRegisterUuid; + ASSERT_TRUE(receivedUuid); + EXPECT_EQ(DrmPrelimHelper::getStringUuidClass(), receivedUuid->uuidClass); + EXPECT_EQ(receivedUuid->size, strlen(uuidL0CommandQueueName)); + EXPECT_EQ(0, memcmp(reinterpret_cast(receivedUuid->ptr), uuidL0CommandQueueName, receivedUuid->size)); + EXPECT_EQ(0, memcmp(receivedUuid->uuid, uuidL0CommandQueueHash, sizeof(receivedUuid->uuid))); +} + +TEST_F(DrmDebugPrelimTest, GivenDrmWhenNotifyLastCommandQueueDestroyedCalledThenCorrectUuidIsUnregistered) { + DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]); + + drm.notifyLastCommandQueueDestroyed(1234u); + EXPECT_EQ(1234u, drm.context.receivedUnregisterUuid->handle); +} + +TEST_F(DrmDebugPrelimTest, GivenDrmWhenRegisteringIsaCookieThenRegisterUUIDIoctlIsCalled) { + DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]); + + auto result = drm.registerResourceClasses(); + EXPECT_TRUE(result); + + auto prevIoctls = drm.ioctlCallsCount; + auto registeredHandle = drm.registerIsaCookie(3); + + EXPECT_EQ(prevIoctls + 1u, drm.ioctlCallsCount); + EXPECT_EQ(drm.context.uuidHandle - 1, registeredHandle); + EXPECT_EQ(3u, drm.context.receivedRegisterUuid->uuidClass); +} + +TEST_F(DrmDebugPrelimTest, GivenDrmWhenRegisteringElfResourceWithoutDataThenRegisterUUIDIoctlIsCalled) { + DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]); + + auto result = drm.registerResourceClasses(); + EXPECT_TRUE(result); + + auto handle = drm.context.uuidHandle; + auto registeredHandle = drm.registerResource(Drm::ResourceClass::Elf, nullptr, 0); + + EXPECT_EQ(handle + 1, drm.context.uuidHandle); + EXPECT_EQ(handle, registeredHandle); + + EXPECT_EQ(nullptr, drm.context.receivedRegisterUuid->ptr); + EXPECT_EQ(0u, drm.context.receivedRegisterUuid->size); +} + +TEST(DrmPrelimTest, givenContextDebugAvailableWhenCheckedForSupportThenTrueIsReturned) { + auto executionEnvironment = std::make_unique(); + executionEnvironment->setDebuggingEnabled(); + executionEnvironment->prepareRootDeviceEnvironments(1); + executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get()); + executionEnvironment->calculateMaxOsContextCount(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + + auto *drm = new DrmQueryMock(*executionEnvironment->rootDeviceEnvironments[0]); + drm->contextDebugSupported = true; + executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); + + auto prevIoctls = drm->ioctlCallsCount; + + auto contextParamCallsBefore = drm->receivedContextParamRequestCount; + drm->checkContextDebugSupport(); + EXPECT_EQ(prevIoctls + 1u, drm->ioctlCallsCount); + EXPECT_EQ(contextParamCallsBefore + 1u, drm->receivedContextParamRequestCount); + + EXPECT_TRUE(drm->isContextDebugSupported()); + EXPECT_EQ(prevIoctls + 1u, drm->ioctlCallsCount); +} + +TEST(DrmPrelimTest, givenContextDebugNotAvailableWhenCheckedForSupportThenTrueIsReturned) { + auto executionEnvironment = std::make_unique(); + executionEnvironment->setDebuggingEnabled(); + executionEnvironment->prepareRootDeviceEnvironments(1); + executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get()); + executionEnvironment->calculateMaxOsContextCount(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + + auto *drm = new DrmQueryMock(*executionEnvironment->rootDeviceEnvironments[0]); + drm->contextDebugSupported = false; + executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); + + auto prevIoctls = drm->ioctlCallsCount; + auto contextParamCallsBefore = drm->receivedContextParamRequestCount; + drm->checkContextDebugSupport(); + EXPECT_EQ(prevIoctls + 1u, drm->ioctlCallsCount); + EXPECT_EQ(contextParamCallsBefore + 1u, drm->receivedContextParamRequestCount); + + EXPECT_FALSE(drm->isContextDebugSupported()); + EXPECT_EQ(prevIoctls + 1u, drm->ioctlCallsCount); +} diff --git a/opencl/test/unit_test/os_interface/linux/drm_debug_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_debug_tests.cpp similarity index 56% rename from opencl/test/unit_test/os_interface/linux/drm_debug_tests.cpp rename to shared/test/unit_test/os_interface/linux/drm_debug_tests.cpp index 05b069f2e732d..574aed3533ae2 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_debug_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_debug_tests.cpp @@ -12,18 +12,29 @@ using namespace NEO; -TEST(DrmTest, whenRegisterResourceClassesCalledThenFalseIsReturned) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); +struct DrmDebugTest : public ::testing::Test { + public: + void SetUp() override { + executionEnvironment = std::make_unique(); + executionEnvironment->prepareRootDeviceEnvironments(1); + executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(NEO::defaultHwInfo.get()); + } + + void TearDown() override { + } + + protected: + std::unique_ptr executionEnvironment; +}; + +TEST_F(DrmDebugTest, whenRegisterResourceClassesCalledThenTrueIsReturned) { DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]); auto result = drmMock.registerResourceClasses(); - EXPECT_FALSE(result); + EXPECT_TRUE(result); } -TEST(DrmTest, whenRegisterResourceCalledThenImplementationIsEmpty) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); +TEST_F(DrmDebugTest, whenRegisterResourceCalledThenImplementationIsEmpty) { DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]); auto handle = drmMock.registerResource(Drm::ResourceClass::MaxSize, nullptr, 0); @@ -32,9 +43,7 @@ TEST(DrmTest, whenRegisterResourceCalledThenImplementationIsEmpty) { EXPECT_EQ(0u, drmMock.ioctlCallsCount); } -TEST(DrmTest, whenRegisterIsaCookieCalledThenImplementationIsEmpty) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); +TEST_F(DrmDebugTest, whenRegisterIsaCookieCalledThenImplementationIsEmpty) { DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]); const uint32_t isaHandle = 2; @@ -43,9 +52,7 @@ TEST(DrmTest, whenRegisterIsaCookieCalledThenImplementationIsEmpty) { EXPECT_EQ(0u, drmMock.ioctlCallsCount); } -TEST(DrmTest, whenCheckingContextDebugSupportThenNoIoctlIsCalled) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); +TEST_F(DrmDebugTest, whenCheckingContextDebugSupportThenNoIoctlIsCalled) { DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]); drmMock.checkContextDebugSupport(); EXPECT_FALSE(drmMock.isContextDebugSupported()); @@ -53,9 +60,7 @@ TEST(DrmTest, whenCheckingContextDebugSupportThenNoIoctlIsCalled) { EXPECT_EQ(0u, drmMock.ioctlCallsCount); } -TEST(DrmTest, whenNotifyCommandQueueCreateDestroyAreCalledThenImplementationsAreEmpty) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); +TEST_F(DrmDebugTest, whenNotifyCommandQueueCreateDestroyAreCalledThenImplementationsAreEmpty) { DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]); auto handle = drmMock.notifyFirstCommandQueueCreated(); diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp index 86f091fcf89d4..256543b090439 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp @@ -7,6 +7,7 @@ #include "shared/source/os_interface/linux/ioctl_helper.h" #include "shared/source/os_interface/linux/ioctl_strings.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/test_macros/test.h" #include "third_party/uapi/prelim/drm/i915_drm.h" diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp index 798d40484aab2..6adbe1f4d656e 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp @@ -327,3 +327,46 @@ TEST(IoctlHelperTestsUpstream, givenUpstreamWhenGettingEuStallFdParameterThenZer IoctlHelperUpstream ioctlHelper{}; EXPECT_EQ(0u, ioctlHelper.getEuStallFdParameter()); } + +TEST(IoctlHelperTestsUpstream, whenRegisterUuidIsCalledThenReturnNullHandle) { + auto executionEnvironment = std::make_unique(); + auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + + IoctlHelperUpstream ioctlHelper{}; + + { + const auto [retVal, handle] = ioctlHelper.registerUuid(drm.get(), "", 0, 0, 0); + EXPECT_EQ(0u, retVal); + EXPECT_EQ(0u, handle); + } + + { + const auto [retVal, handle] = ioctlHelper.registerStringClassUuid(drm.get(), "", 0, 0); + EXPECT_EQ(0u, retVal); + EXPECT_EQ(0u, handle); + } +} + +TEST(IoctlHelperTestsUpstream, whenUnregisterUuidIsCalledThenZeroIsReturned) { + auto executionEnvironment = std::make_unique(); + auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + + IoctlHelperUpstream ioctlHelper{}; + EXPECT_EQ(0, ioctlHelper.unregisterUuid(drm.get(), 0)); +} + +TEST(IoctlHelperTestsUpstream, whenIsContextDebugSupportedIsCalledThenFalseIsReturned) { + auto executionEnvironment = std::make_unique(); + auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + + IoctlHelperUpstream ioctlHelper{}; + EXPECT_EQ(false, ioctlHelper.isContextDebugSupported(drm.get())); +} + +TEST(IoctlHelperTestsUpstream, whenSetContextDebugFlagIsCalledThenZeroIsReturned) { + auto executionEnvironment = std::make_unique(); + auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + + IoctlHelperUpstream ioctlHelper{}; + EXPECT_EQ(0, ioctlHelper.setContextDebugFlag(drm.get(), 0)); +}