diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c3da1653e..4dcda426ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,6 +127,13 @@ if(NOT KMDAF_HEADERS_DIR) endif() endif(NOT KMDAF_HEADERS_DIR) +if(NOT SOURCE_LEVEL_DEBUGGER_HEADERS_DIR) + if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../internal/source_level_debugger/igfx_debug_interchange_types.h") + get_filename_component(SOURCE_LEVEL_DEBUGGER_HEADERS_DIR "../internal/source_level_debugger/" ABSOLUTE) + message(STATUS "Source Level Debugger headers dir: ${SOURCE_LEVEL_DEBUGGER_HEADERS_DIR}") + endif() +endif(NOT SOURCE_LEVEL_DEBUGGER_HEADERS_DIR) + if(LIBDRM_DIR) get_filename_component(I915_INCLUDES_DIR "${LIBDRM_DIR}/include" ABSOLUTE) else() diff --git a/manifests/manifest.yml b/manifests/manifest.yml index ac22c58c34..bf1550fb07 100644 --- a/manifests/manifest.yml +++ b/manifests/manifest.yml @@ -36,7 +36,7 @@ components: internal: branch: master dest_dir: internal - revision: 5f0194eb176cce396b9bed04c98bf2f4c7779ded + revision: 16a7c3b8a4aff96b1911e3b0c917a14d1f8fe582 type: git khronos: branch: master diff --git a/offline_compiler/CMakeLists.txt b/offline_compiler/CMakeLists.txt index 71959a9a39..e9981f4141 100644 --- a/offline_compiler/CMakeLists.txt +++ b/offline_compiler/CMakeLists.txt @@ -37,12 +37,12 @@ set(CLOC_SRCS_LIB if(WIN32) list(APPEND CLOC_SRCS_LIB ${IGDRCL_SOURCE_DIR}/runtime/os_interface/windows/os_library.cpp - ${IGDRCL_SOURCE_DIR}/runtime/os_interface/windows/options.cpp + ${IGDRCL_SOURCE_DIR}/runtime/dll/windows/options.cpp ) else() list(APPEND CLOC_SRCS_LIB ${IGDRCL_SOURCE_DIR}/runtime/os_interface/linux/os_library.cpp - ${IGDRCL_SOURCE_DIR}/runtime/os_interface/linux/options.cpp + ${IGDRCL_SOURCE_DIR}/runtime/dll/linux/options.cpp ) endif() diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 0a9cef6f52..47032383d7 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -83,6 +83,7 @@ target_include_directories(${NEO_STATIC_LIB_NAME} PUBLIC ${IGDRCL__IGC_INCLUDE_DIR} ${THIRD_PARTY_DIR} ${UMKM_SHAREDDATA_INCLUDE_PATHS} + ${SOURCE_LEVEL_DEBUGGER_HEADERS_DIR} ) if(WIN32) diff --git a/runtime/dll/CMakeLists.txt b/runtime/dll/CMakeLists.txt index 9286f76df3..c4cd73217a 100644 --- a/runtime/dll/CMakeLists.txt +++ b/runtime/dll/CMakeLists.txt @@ -30,6 +30,7 @@ set(RUNTIME_SRCS_DLL_BASE ${CMAKE_CURRENT_SOURCE_DIR}/create_deferred_deleter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/create_tbx_sockets.cpp ${CMAKE_CURRENT_SOURCE_DIR}/options.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger.cpp ${IGDRCL_SOURCE_DIR}/runtime/api/api.cpp ${IGDRCL_SOURCE_DIR}/runtime/gmm_helper/resource_info.cpp @@ -44,10 +45,12 @@ set(RUNTIME_SRCS_DLL_BASE ) set(RUNTIME_SRCS_DLL_LINUX + ${CMAKE_CURRENT_SOURCE_DIR}/linux/options.cpp ${CMAKE_CURRENT_SOURCE_DIR}/linux/drm_neo_create.cpp ) set(RUNTIME_SRCS_DLL_WINDOWS + ${CMAKE_CURRENT_SOURCE_DIR}/windows/options.cpp ${IGDRCL_SOURCE_DIR}/runtime/gmm_helper/gmm_memory.cpp ${IGDRCL_SOURCE_DIR}/runtime/gmm_helper/page_table_mngr.cpp ${IGDRCL_SOURCE_DIR}/runtime/os_interface/windows/sys_calls.cpp diff --git a/runtime/os_interface/linux/options.cpp b/runtime/dll/linux/options.cpp similarity index 100% rename from runtime/os_interface/linux/options.cpp rename to runtime/dll/linux/options.cpp diff --git a/runtime/dll/source_level_debugger.cpp b/runtime/dll/source_level_debugger.cpp new file mode 100644 index 0000000000..24bfc878cd --- /dev/null +++ b/runtime/dll/source_level_debugger.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "runtime/source_level_debugger/source_level_debugger.h" + +using namespace std; + +namespace OCLRT { + +OsLibrary *SourceLevelDebugger::loadDebugger() { + return OsLibrary::load(SourceLevelDebugger::dllName); +} +} // namespace OCLRT diff --git a/runtime/os_interface/windows/options.cpp b/runtime/dll/windows/options.cpp similarity index 95% rename from runtime/os_interface/windows/options.cpp rename to runtime/dll/windows/options.cpp index 0d0756de56..63ad28be4c 100644 --- a/runtime/os_interface/windows/options.cpp +++ b/runtime/dll/windows/options.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -30,4 +30,4 @@ const char *igcDllName = "igc32.dll"; #endif const char *gdiDllName = "gdi32.dll"; -} +} // namespace Os diff --git a/runtime/os_interface/linux/CMakeLists.txt b/runtime/os_interface/linux/CMakeLists.txt index 19b05e55f1..d055e818aa 100644 --- a/runtime/os_interface/linux/CMakeLists.txt +++ b/runtime/os_interface/linux/CMakeLists.txt @@ -44,7 +44,6 @@ set(RUNTIME_SRCS_OS_INTERFACE_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/drm_null_device.h ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config.cpp ${CMAKE_CURRENT_SOURCE_DIR}/linux_inc.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/options.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_inc.h ${CMAKE_CURRENT_SOURCE_DIR}/os_interface.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_interface.h @@ -55,6 +54,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/performance_counters_linux.cpp ${CMAKE_CURRENT_SOURCE_DIR}/performance_counters_linux.h ${CMAKE_CURRENT_SOURCE_DIR}/print.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_linux.cpp ) if(UNIX) diff --git a/runtime/os_interface/linux/os_interface.cpp b/runtime/os_interface/linux/os_interface.cpp index f01ed75197..8fe8b3e592 100644 --- a/runtime/os_interface/linux/os_interface.cpp +++ b/runtime/os_interface/linux/os_interface.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -42,4 +42,8 @@ bool OSInterface::are64kbPagesEnabled() { return osEnabled64kbPages; } +uint32_t OSInterface::getDeviceHandle() const { + return 0; +} + } // namespace OCLRT \ No newline at end of file diff --git a/runtime/os_interface/linux/source_level_debugger_linux.cpp b/runtime/os_interface/linux/source_level_debugger_linux.cpp new file mode 100644 index 0000000000..a0bbf9d15a --- /dev/null +++ b/runtime/os_interface/linux/source_level_debugger_linux.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "runtime/source_level_debugger/source_level_debugger.h" + +const char *OCLRT::SourceLevelDebugger::dllName = "libigfxdbgxchg64.so"; diff --git a/runtime/os_interface/os_interface.h b/runtime/os_interface/os_interface.h index acb617d011..42ec68fd5c 100644 --- a/runtime/os_interface/os_interface.h +++ b/runtime/os_interface/os_interface.h @@ -39,6 +39,7 @@ class OSInterface { unsigned int getHwContextId() const; static bool osEnabled64kbPages; static bool are64kbPagesEnabled(); + unsigned int getDeviceHandle() const; protected: OSInterfaceImpl *osInterfaceImpl = nullptr; diff --git a/runtime/os_interface/windows/CMakeLists.txt b/runtime/os_interface/windows/CMakeLists.txt index 727c5865d6..7188ed79c4 100644 --- a/runtime/os_interface/windows/CMakeLists.txt +++ b/runtime/os_interface/windows/CMakeLists.txt @@ -41,7 +41,6 @@ set(RUNTIME_SRCS_OS_INTERFACE_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/gdi_interface.h ${CMAKE_CURRENT_SOURCE_DIR}/kmdaf_listener${KMDAF_FILE_SUFFIX}.cpp ${CMAKE_CURRENT_SOURCE_DIR}/kmdaf_listener.h - ${CMAKE_CURRENT_SOURCE_DIR}/options.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_inc.h ${CMAKE_CURRENT_SOURCE_DIR}/os_interface.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_interface.h @@ -54,6 +53,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/performance_counters_win.h ${CMAKE_CURRENT_SOURCE_DIR}/print.cpp ${CMAKE_CURRENT_SOURCE_DIR}/registry_reader.h + ${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_windows.cpp ${CMAKE_CURRENT_SOURCE_DIR}/sys_calls.h ${CMAKE_CURRENT_SOURCE_DIR}/thk_wrapper.h ${CMAKE_CURRENT_SOURCE_DIR}/wddm.cpp diff --git a/runtime/os_interface/windows/os_interface.cpp b/runtime/os_interface/windows/os_interface.cpp index 9496e17eac..bef34892ce 100644 --- a/runtime/os_interface/windows/os_interface.cpp +++ b/runtime/os_interface/windows/os_interface.cpp @@ -41,6 +41,10 @@ uint32_t OSInterface::getHwContextId() const { return osInterfaceImpl->getHwContextId(); } +uint32_t OSInterface::getDeviceHandle() const { + return static_cast(osInterfaceImpl->getDeviceHandle()); +} + OSInterface::OSInterfaceImpl::OSInterfaceImpl() { wddm = nullptr; } diff --git a/runtime/os_interface/windows/source_level_debugger_windows.cpp b/runtime/os_interface/windows/source_level_debugger_windows.cpp new file mode 100644 index 0000000000..eaacb74b91 --- /dev/null +++ b/runtime/os_interface/windows/source_level_debugger_windows.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "runtime/source_level_debugger/source_level_debugger.h" + +#if defined(_WIN64) +const char *OCLRT::SourceLevelDebugger::dllName = "igfxdbgxchg64.dll"; +#else +const char *OCLRT::SourceLevelDebugger::dllName = "igfxdbgxchg.dll"; +#endif diff --git a/runtime/source_level_debugger/CMakeLists.txt b/runtime/source_level_debugger/CMakeLists.txt new file mode 100644 index 0000000000..c4e2c5b7b9 --- /dev/null +++ b/runtime/source_level_debugger/CMakeLists.txt @@ -0,0 +1,34 @@ +# Copyright (c) 2018, Intel Corporation +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. + +if(SOURCE_LEVEL_DEBUGGER_HEADERS_DIR) + set(RUNTIME_SRCS_SOURCE_LEVEL_DEBUGGER + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger.h + ) +else() + set(RUNTIME_SRCS_SOURCE_LEVEL_DEBUGGER + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger.h + ) +endif() + +target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_SOURCE_LEVEL_DEBUGGER}) diff --git a/runtime/source_level_debugger/source_level_debugger.cpp b/runtime/source_level_debugger/source_level_debugger.cpp new file mode 100644 index 0000000000..e87757681e --- /dev/null +++ b/runtime/source_level_debugger/source_level_debugger.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "igfx_debug_interchange_types.h" + +#include "runtime/helpers/debug_helpers.h" +#include "runtime/source_level_debugger/source_level_debugger.h" +#include "runtime/os_interface/os_interface.h" + +namespace OCLRT { +const char *SourceLevelDebugger::notifyNewDeviceSymbol = "notifyNewDevice"; +const char *SourceLevelDebugger::notifySourceCodeSymbol = "notifySourceCode"; +const char *SourceLevelDebugger::getDebuggerOptionSymbol = "getDebuggerOption"; +const char *SourceLevelDebugger::notifyKernelDebugDataSymbol = "notifyKernelDebugData"; +const char *SourceLevelDebugger::initSymbol = "init"; + +class SourceLevelDebugger::SourceLevelDebuggerInterface { + public: + SourceLevelDebuggerInterface() = default; + ~SourceLevelDebuggerInterface() = default; + + typedef int (*pfNotifyNewDevice)(GfxDbgNewDeviceData *data); + typedef int (*pfNotifySourceCode)(GfxDbgSourceCode *data); + typedef int (*pfGetDebuggerOption)(GfxDbgOption *); + typedef int (*pfNotifyKernelDebugData)(GfxDbgKernelDebugData *data); + typedef int (*pfInit)(GfxDbgTargetCaps *data); + + pfNotifyNewDevice fNotifyNewDevice = nullptr; + pfNotifySourceCode fNotifySourceCode = nullptr; + pfGetDebuggerOption fGetDebuggerOption = nullptr; + pfNotifyKernelDebugData fNotifyKernelDebugData = nullptr; + pfInit fInit = nullptr; +}; + +SourceLevelDebugger::SourceLevelDebugger() { + debuggerLibrary.reset(SourceLevelDebugger::loadDebugger()); + + if (debuggerLibrary.get() == nullptr) { + return; + } + interface = new SourceLevelDebuggerInterface; + getFunctions(); + isActive = true; +} + +SourceLevelDebugger::~SourceLevelDebugger() { + if (interface) { + delete interface; + } +} + +bool SourceLevelDebugger::isDebuggerActive() { + return isActive; +} + +void SourceLevelDebugger::getFunctions() { + UNRECOVERABLE_IF(debuggerLibrary.get() == nullptr); + + interface->fNotifyNewDevice = reinterpret_cast(debuggerLibrary->getProcAddress(notifyNewDeviceSymbol)); + interface->fNotifySourceCode = reinterpret_cast(debuggerLibrary->getProcAddress(notifySourceCodeSymbol)); + interface->fGetDebuggerOption = reinterpret_cast(debuggerLibrary->getProcAddress(getDebuggerOptionSymbol)); + interface->fNotifyKernelDebugData = reinterpret_cast(debuggerLibrary->getProcAddress(notifyKernelDebugDataSymbol)); + interface->fInit = reinterpret_cast(debuggerLibrary->getProcAddress(initSymbol)); +} + +void SourceLevelDebugger::notifyNewDevice(uint32_t deviceHandle) const { + if (isActive) { + GfxDbgNewDeviceData newDevice; + newDevice.version = IGFXDBG_CURRENT_VERSION; + newDevice.dh = reinterpret_cast(static_cast(deviceHandle)); + newDevice.udh = GfxDeviceHandle(0); + interface->fNotifyNewDevice(&newDevice); + } +} +void SourceLevelDebugger::notifySourceCode(uint32_t deviceHandle, const char *source, size_t sourceSize) const { + if (isActive) { + GfxDbgSourceCode sourceCode; + char fileName[FILENAME_MAX] = ""; + + sourceCode.version = IGFXDBG_CURRENT_VERSION; + sourceCode.hDevice = reinterpret_cast(static_cast(deviceHandle)); + sourceCode.sourceCode = source; + sourceCode.sourceCodeSize = static_cast(sourceSize); + sourceCode.sourceName = &fileName[0]; + sourceCode.sourceNameMaxLen = sizeof(fileName); + + interface->fNotifySourceCode(&sourceCode); + } +} + +bool SourceLevelDebugger::isOptimizationDisabled() const { + if (isActive) { + char value; + GfxDbgOption option; + option.version = IGFXDBG_CURRENT_VERSION; + option.optionName = DBG_OPTION_IS_OPTIMIZATION_DISABLED; + option.valueLen = sizeof(value); + option.value = &value; + + int result = interface->fGetDebuggerOption(&option); + if (result == 1) { + if (option.value[0] == '1') { + return true; + } + } + } + return false; +} + +void SourceLevelDebugger::notifyKernelDebugData() const { + GfxDbgKernelDebugData kernelDebugData; + interface->fNotifyKernelDebugData(&kernelDebugData); +} +} // namespace OCLRT diff --git a/runtime/source_level_debugger/source_level_debugger.h b/runtime/source_level_debugger/source_level_debugger.h new file mode 100644 index 0000000000..92dfa0c495 --- /dev/null +++ b/runtime/source_level_debugger/source_level_debugger.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#include "runtime/os_interface/os_library.h" +#include + +namespace OCLRT { +class SourceLevelDebugger { + public: + SourceLevelDebugger(); + ~SourceLevelDebugger(); + SourceLevelDebugger(const SourceLevelDebugger &ref) = delete; + SourceLevelDebugger &operator=(const SourceLevelDebugger &) = delete; + + bool isDebuggerActive(); + void notifyNewDevice(uint32_t deviceHandle) const; + void notifySourceCode(uint32_t deviceHandle, const char *sourceCode, size_t size) const; + bool isOptimizationDisabled() const; + void notifyKernelDebugData() const; + + protected: + class SourceLevelDebuggerInterface; + SourceLevelDebuggerInterface *interface = nullptr; + + static OsLibrary *loadDebugger(); + void getFunctions(); + + std::unique_ptr debuggerLibrary; + bool isActive = false; + + static const char *notifyNewDeviceSymbol; + static const char *notifySourceCodeSymbol; + static const char *getDebuggerOptionSymbol; + static const char *notifyKernelDebugDataSymbol; + static const char *initSymbol; + // OS specific library name + static const char *dllName; +}; +} // namespace OCLRT diff --git a/unit_tests/libult/CMakeLists.txt b/unit_tests/libult/CMakeLists.txt index c76468d3a8..213b730e3d 100644 --- a/unit_tests/libult/CMakeLists.txt +++ b/unit_tests/libult/CMakeLists.txt @@ -39,6 +39,8 @@ apply_macro_for_each_gen("TESTED") set(IGDRCL_SRCS_LIB_ULT ${IGDRCL_SOURCE_DIR}/unit_tests/abort.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/helpers/built_ins_helper.cpp + ${IGDRCL_SOURCE_DIR}/unit_tests/libult/create_tbx_sockets.cpp + ${IGDRCL_SOURCE_DIR}/unit_tests/libult/ult_command_stream_receiver.h ${IGDRCL_SOURCE_DIR}/unit_tests/helpers/debug_helpers.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/helpers/memory_management.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/helpers/memory_management.h @@ -51,6 +53,14 @@ set(IGDRCL_SRCS_LIB_ULT ${CMAKE_CURRENT_SOURCE_DIR}/mock_gfx_family.cpp ) +if(SOURCE_LEVEL_DEBUGGER_HEADERS_DIR) + list(APPEND IGDRCL_SRCS_LIB_ULT + ${IGDRCL_SOURCE_DIR}/unit_tests/libult/source_level_debugger.cpp + ${IGDRCL_SOURCE_DIR}/unit_tests/libult/source_level_debugger_library.cpp + ${IGDRCL_SOURCE_DIR}/unit_tests/libult/source_level_debugger_library.h + ) +endif() + add_library (igdrcl_libult OBJECT ${IGDRCL_SRCS_LIB_ULT} ${IGDRCL_SRCS_ENABLE_TESTED_HW} diff --git a/unit_tests/libult/source_level_debugger.cpp b/unit_tests/libult/source_level_debugger.cpp new file mode 100644 index 0000000000..f0ad681fd0 --- /dev/null +++ b/unit_tests/libult/source_level_debugger.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "runtime/source_level_debugger/source_level_debugger.h" +#include "unit_tests/libult/source_level_debugger_library.h" + +namespace OCLRT { +OsLibrary *SourceLevelDebugger::loadDebugger() { + return DebuggerLibrary::load(SourceLevelDebugger::dllName); +} + +} // namespace OCLRT diff --git a/unit_tests/libult/source_level_debugger_library.cpp b/unit_tests/libult/source_level_debugger_library.cpp new file mode 100644 index 0000000000..9e71ccbc2e --- /dev/null +++ b/unit_tests/libult/source_level_debugger_library.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "source_level_debugger_library.h" +#include "runtime/helpers/string.h" + +using namespace OCLRT; + +bool DebuggerLibrary::isDebuggerActive = false; +bool DebuggerLibrary::isLibraryAvailable = false; +DebuggerLibraryInterceptor *DebuggerLibrary::interceptor = nullptr; + +void *DebuggerLibrary::getProcAddress(const std::string &procName) { + if (procName == "notifyNewDevice") { + return reinterpret_cast(notifyNewDevice); + } else if (procName == "notifySourceCode") { + return reinterpret_cast(notifySourceCode); + } else if (procName == "getDebuggerOption") { + return reinterpret_cast(getDebuggerOption); + } else if (procName == "notifyKernelDebugData") { + return reinterpret_cast(notifyKernelDebugData); + } else if (procName == "init") { + return reinterpret_cast(init); + } + return nullptr; +} + +OsLibrary *DebuggerLibrary::load(const std::string &name) { + if (isLibraryAvailable) { + return new DebuggerLibrary(); + } + return nullptr; +} + +int DebuggerLibrary::notifyNewDevice(GfxDbgNewDeviceData *newDevice) { + if (interceptor) { + interceptor->newDeviceArgIn = *newDevice; + interceptor->newDeviceCalled = true; + } + return 0; +} + +int DebuggerLibrary::notifySourceCode(GfxDbgSourceCode *sourceCode) { + if (interceptor) { + interceptor->sourceCodeArgIn = *sourceCode; + interceptor->sourceCodeCalled = true; + } + return 0; +} + +int DebuggerLibrary::getDebuggerOption(GfxDbgOption *option) { + if (interceptor) { + interceptor->optionArgIn = *option; + interceptor->optionCalled = true; + + if (interceptor->optionArgOut && option->valueLen > 0) { + memcpy_s(option->value, option->valueLen, interceptor->optionArgOut->value, interceptor->optionArgOut->valueLen); + } + return interceptor->optionRetVal; + } + return true; +} + +int DebuggerLibrary::notifyKernelDebugData(GfxDbgKernelDebugData *kernelDebugData) { + if (interceptor) { + interceptor->kernelDebugDataArgIn = *kernelDebugData; + interceptor->kernelDebugDataCalled = true; + } + return 0; +} + +int DebuggerLibrary::init(GfxDbgTargetCaps *targetCaps) { + if (interceptor) { + interceptor->targetCapsArgIn = *targetCaps; + interceptor->targetCapsCalled = true; + } + return 0; +} diff --git a/unit_tests/libult/source_level_debugger_library.h b/unit_tests/libult/source_level_debugger_library.h new file mode 100644 index 0000000000..d2d858c413 --- /dev/null +++ b/unit_tests/libult/source_level_debugger_library.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "igfx_debug_interchange_types.h" + +#include "runtime/os_interface/os_library.h" + +#include + +struct DebuggerLibraryInterceptor { + GfxDbgNewDeviceData newDeviceArgIn; + GfxDbgSourceCode sourceCodeArgIn; + GfxDbgOption optionArgIn; + GfxDbgKernelDebugData kernelDebugDataArgIn; + GfxDbgTargetCaps targetCapsArgIn; + + GfxDbgNewDeviceData *newDeviceArgOut = nullptr; + GfxDbgSourceCode *sourceCodeArgOut = nullptr; + GfxDbgOption *optionArgOut = nullptr; + GfxDbgKernelDebugData *kernelDebugDataArgOut = nullptr; + GfxDbgTargetCaps *targetCapsArgOut = nullptr; + + bool newDeviceCalled = false; + bool sourceCodeCalled = false; + bool optionCalled = false; + bool kernelDebugDataCalled = false; + bool targetCapsCalled = false; + + int newDeviceRetVal = 0; + int sourceCodeRetVal = 0; + int optionRetVal = 0; + int kernelDebugDataRetVal = 0; + int targetCapsRetVal = 0; +}; + +class DebuggerLibrary : public OCLRT::OsLibrary { + public: + DebuggerLibrary() = default; + void *getProcAddress(const std::string &procName) override; + + static OsLibrary *load(const std::string &name); + + bool isLoaded() override { + return true; + } + + static void setDebuggerActive(bool active) { + isDebuggerActive = active; + } + + static bool getDebuggerActive() { + return isDebuggerActive; + } + + static void setLibraryAvailable(bool available) { + isLibraryAvailable = available; + } + + static bool getLibraryAvailable() { + return isLibraryAvailable; + } + + static void injectDebuggerLibraryInterceptor(DebuggerLibraryInterceptor *interceptorArg) { + interceptor = interceptorArg; + } + + static void clearDebuggerLibraryInterceptor() { + interceptor = nullptr; + } + + static DebuggerLibraryInterceptor *interceptor; + + protected: + static int notifyNewDevice(GfxDbgNewDeviceData *); + static int notifySourceCode(GfxDbgSourceCode *); + static int getDebuggerOption(GfxDbgOption *); + static int notifyKernelDebugData(GfxDbgKernelDebugData *); + static int init(GfxDbgTargetCaps *); + + static bool isLibraryAvailable; + static bool isDebuggerActive; +}; diff --git a/unit_tests/linux/CMakeLists.txt b/unit_tests/linux/CMakeLists.txt index d7ab327ab4..cb6d9dfbf4 100644 --- a/unit_tests/linux/CMakeLists.txt +++ b/unit_tests/linux/CMakeLists.txt @@ -21,6 +21,7 @@ set(IGDRCL_SRCS_linux_tests ${CMAKE_CURRENT_SOURCE_DIR}/main_linux.cpp + ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/linux/options.cpp ) set(IGDRCL_SRCS_linux_dll_tests @@ -30,6 +31,7 @@ set(IGDRCL_SRCS_linux_dll_tests ${CMAKE_CURRENT_SOURCE_DIR}/mock_os_layer.h ${IGDRCL_SOURCE_DIR}/runtime/os_interface/debug_settings_manager.cpp ${IGDRCL_SOURCE_DIR}/runtime/dll/linux/drm_neo_create.cpp + ${IGDRCL_SOURCE_DIR}/runtime/dll/linux/options.cpp ) if(LIBVA_FOUND) diff --git a/unit_tests/os_interface/linux/os_interface_tests.cpp b/unit_tests/os_interface/linux/os_interface_tests.cpp index a94a8c7c35..a4c1004b7f 100644 --- a/unit_tests/os_interface/linux/os_interface_tests.cpp +++ b/unit_tests/os_interface/linux/os_interface_tests.cpp @@ -1,6 +1,6 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -29,4 +29,9 @@ namespace OCLRT { TEST(OsInterfaceTest, GivenLinuxWhenare64kbPagesEnabledThenFalse) { EXPECT_FALSE(OSInterface::are64kbPagesEnabled()); } -} \ No newline at end of file + +TEST(OsInterfaceTest, GivenLinuxOsInterfaceWhenDeviceHandleQueriedthenZeroIsReturned) { + OSInterface osInterface; + EXPECT_EQ(0u, osInterface.getDeviceHandle()); +} +} // namespace OCLRT \ No newline at end of file diff --git a/unit_tests/source_level_debugger/CMakeLists.txt b/unit_tests/source_level_debugger/CMakeLists.txt index 512cea51c1..30cbced8cb 100644 --- a/unit_tests/source_level_debugger/CMakeLists.txt +++ b/unit_tests/source_level_debugger/CMakeLists.txt @@ -25,3 +25,7 @@ set(IGDRCL_SRCS_tests_source_level_debugger ${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_preamble_test.inl ) target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_source_level_debugger}) + +if(SOURCE_LEVEL_DEBUGGER_HEADERS_DIR) + target_sources(igdrcl_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_tests.cpp) +endif() \ No newline at end of file diff --git a/unit_tests/source_level_debugger/source_level_debugger_tests.cpp b/unit_tests/source_level_debugger/source_level_debugger_tests.cpp new file mode 100644 index 0000000000..63d84450e4 --- /dev/null +++ b/unit_tests/source_level_debugger/source_level_debugger_tests.cpp @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "runtime/source_level_debugger/source_level_debugger.h" +#include "unit_tests/libult/source_level_debugger_library.h" + +#include + +using namespace OCLRT; + +class DebuggerLibraryRestorer { + public: + DebuggerLibraryRestorer() { + restoreActiveState = DebuggerLibrary::getDebuggerActive(); + restoreAvailableState = DebuggerLibrary::getLibraryAvailable(); + } + ~DebuggerLibraryRestorer() { + DebuggerLibrary::clearDebuggerLibraryInterceptor(); + DebuggerLibrary::setDebuggerActive(restoreActiveState); + DebuggerLibrary::setLibraryAvailable(restoreAvailableState); + } + bool restoreActiveState = false; + bool restoreAvailableState = false; +}; + +class MockSourceLevelDebugger : public SourceLevelDebugger { + public: + using SourceLevelDebugger::debuggerLibrary; + MockSourceLevelDebugger() = default; + void setActive(bool active) { + isActive = active; + } +}; + +TEST(SourceLevelDebugger, givenNoKernelDebuggerLibraryWhenSourceLevelDebuggerIsCreatedThenLibraryIsNotLoaded) { + DebuggerLibraryRestorer restorer; + DebuggerLibrary::setLibraryAvailable(false); + + MockSourceLevelDebugger debugger; + EXPECT_EQ(nullptr, debugger.debuggerLibrary.get()); +} + +TEST(SourceLevelDebugger, givenKernelDebuggerLibraryAvailableWhenIsDebuggerActiveIsCalledThenLibraryIsLoadedAndFalseIsReturned) { + DebuggerLibraryRestorer restorer; + DebuggerLibrary::setLibraryAvailable(true); + + MockSourceLevelDebugger debugger; + EXPECT_NE(nullptr, debugger.debuggerLibrary.get()); +} + +TEST(SourceLevelDebugger, givenKernelDebuggerLibraryAvailableWhenIsDebuggerActiveIsCalledThenTrueIsReturned) { + DebuggerLibraryRestorer restorer; + DebuggerLibrary::setLibraryAvailable(true); + + MockSourceLevelDebugger debugger; + bool active = debugger.isDebuggerActive(); + EXPECT_TRUE(active); +} + +TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotAvailableWhenIsDebuggerActiveIsCalledThenFalseIsReturned) { + DebuggerLibraryRestorer restorer; + DebuggerLibrary::setLibraryAvailable(false); + + MockSourceLevelDebugger debugger; + bool active = debugger.isDebuggerActive(); + EXPECT_FALSE(active); +} + +TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenNotifySourceCodeIsCalledThenDebuggerLibraryFunctionIsCalled) { + DebuggerLibraryRestorer restorer; + + DebuggerLibraryInterceptor interceptor; + DebuggerLibrary::setLibraryAvailable(true); + DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor); + + MockSourceLevelDebugger debugger; + + const char source[] = "sourceCode"; + debugger.notifySourceCode(4, source, sizeof(source)); + + EXPECT_TRUE(interceptor.sourceCodeCalled); + EXPECT_EQ(reinterpret_cast(static_cast(4u)), interceptor.sourceCodeArgIn.hDevice); + EXPECT_EQ(source, interceptor.sourceCodeArgIn.sourceCode); + EXPECT_EQ(sizeof(source), interceptor.sourceCodeArgIn.sourceCodeSize); + EXPECT_NE(nullptr, interceptor.sourceCodeArgIn.sourceName); + EXPECT_NE(0u, interceptor.sourceCodeArgIn.sourceNameMaxLen); +} + +TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotActiveWhenNotifySourceCodeIsCalledThenDebuggerLibraryFunctionIsNotCalled) { + DebuggerLibraryRestorer restorer; + + DebuggerLibraryInterceptor interceptor; + DebuggerLibrary::setLibraryAvailable(true); + DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor); + + MockSourceLevelDebugger debugger; + + debugger.setActive(false); + + const char source[] = "sourceCode"; + debugger.notifySourceCode(4, source, sizeof(source)); + EXPECT_FALSE(interceptor.sourceCodeCalled); +} + +TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenNotifyNewDeviceIsCalledThenDebuggerLibraryFunctionIsCalled) { + DebuggerLibraryRestorer restorer; + + DebuggerLibraryInterceptor interceptor; + DebuggerLibrary::setLibraryAvailable(true); + DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor); + + MockSourceLevelDebugger debugger; + debugger.notifyNewDevice(4); + + EXPECT_TRUE(interceptor.newDeviceCalled); + EXPECT_EQ(reinterpret_cast(static_cast(4u)), interceptor.newDeviceArgIn.dh); +} + +TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotActiveWhenNotifyNewDeviceIsCalledThenDebuggerLibraryFunctionIsNotCalled) { + DebuggerLibraryRestorer restorer; + + DebuggerLibraryInterceptor interceptor; + DebuggerLibrary::setLibraryAvailable(true); + DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor); + + MockSourceLevelDebugger debugger; + + debugger.setActive(false); + debugger.notifyNewDevice(4); + EXPECT_FALSE(interceptor.newDeviceCalled); +} + +TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenIsOptimizationDisabledIsCalledThenDebuggerLibraryFunctionIsCalled) { + DebuggerLibraryRestorer restorer; + + DebuggerLibraryInterceptor interceptor; + DebuggerLibrary::setLibraryAvailable(true); + DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor); + + MockSourceLevelDebugger debugger; + bool isOptDisabled = debugger.isOptimizationDisabled(); + EXPECT_FALSE(isOptDisabled); + + EXPECT_TRUE(interceptor.optionCalled); + EXPECT_EQ(GfxDbgOptionNames::DBG_OPTION_IS_OPTIMIZATION_DISABLED, interceptor.optionArgIn.optionName); + EXPECT_NE(nullptr, interceptor.optionArgIn.value); + EXPECT_LT(0u, interceptor.optionArgIn.valueLen); +} + +TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotActiveWhenIsOptimizationDisabledIsCalledThenDebuggerLibraryFunctionIsNotCalled) { + DebuggerLibraryRestorer restorer; + + DebuggerLibraryInterceptor interceptor; + DebuggerLibrary::setLibraryAvailable(true); + DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor); + + MockSourceLevelDebugger debugger; + + debugger.setActive(false); + bool isOptDisabled = debugger.isOptimizationDisabled(); + EXPECT_FALSE(isOptDisabled); + EXPECT_FALSE(interceptor.optionCalled); +} + +TEST(SourceLevelDebugger, givenActiveDebuggerWhenGetDebuggerOptionReturnsZeroThenIsOptimizationDisabledReturnsFalse) { + DebuggerLibraryRestorer restorer; + + DebuggerLibraryInterceptor interceptor; + DebuggerLibrary::setLibraryAvailable(true); + DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor); + + char value = '1'; + GfxDbgOption optionArgOut; + interceptor.optionArgOut = &optionArgOut; + interceptor.optionArgOut->value = &value; + interceptor.optionArgOut->valueLen = sizeof(value); + interceptor.optionRetVal = 0; + + MockSourceLevelDebugger debugger; + bool isOptDisabled = debugger.isOptimizationDisabled(); + EXPECT_FALSE(isOptDisabled); +} + +TEST(SourceLevelDebugger, givenActiveDebuggerAndOptDisabledWhenGetDebuggerOptionReturnsNonZeroAndOneInValueThenIsOptimizationDisabledReturnsTrue) { + DebuggerLibraryRestorer restorer; + + DebuggerLibraryInterceptor interceptor; + DebuggerLibrary::setLibraryAvailable(true); + DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor); + + char value = '1'; + GfxDbgOption optionArgOut; + interceptor.optionArgOut = &optionArgOut; + interceptor.optionArgOut->value = &value; + interceptor.optionArgOut->valueLen = sizeof(value); + interceptor.optionRetVal = 1; + + MockSourceLevelDebugger debugger; + bool isOptDisabled = debugger.isOptimizationDisabled(); + EXPECT_TRUE(isOptDisabled); +} + +TEST(SourceLevelDebugger, givenActiveDebuggerAndOptDisabledWhenGetDebuggerOptionReturnsNonZeroAndZeroInValueThenIsOptimizationDisabledReturnsFalse) { + DebuggerLibraryRestorer restorer; + + DebuggerLibraryInterceptor interceptor; + DebuggerLibrary::setLibraryAvailable(true); + DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor); + + char value = '0'; + GfxDbgOption optionArgOut; + interceptor.optionArgOut = &optionArgOut; + interceptor.optionArgOut->value = &value; + interceptor.optionArgOut->valueLen = sizeof(value); + interceptor.optionRetVal = 1; + + MockSourceLevelDebugger debugger; + bool isOptDisabled = debugger.isOptimizationDisabled(); + EXPECT_FALSE(isOptDisabled); +} + +TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenNotifyKernelDebugDataIsCalledThenDebuggerLibraryFunctionIsCalled) { + DebuggerLibraryRestorer restorer; + + DebuggerLibraryInterceptor interceptor; + DebuggerLibrary::setLibraryAvailable(true); + DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor); + + MockSourceLevelDebugger debugger; + debugger.notifyKernelDebugData(); + + EXPECT_TRUE(interceptor.kernelDebugDataCalled); +} \ No newline at end of file diff --git a/unit_tests/tbx/CMakeLists.txt b/unit_tests/tbx/CMakeLists.txt index e6da9b68ef..a9d6de12cf 100644 --- a/unit_tests/tbx/CMakeLists.txt +++ b/unit_tests/tbx/CMakeLists.txt @@ -33,10 +33,15 @@ if(WIN32) ${IGDRCL_SOURCE_DIR}/unit_tests/mocks${BRANCH_DIR_SUFFIX} ) target_sources(igdrcl_tbx_tests PRIVATE + ${IGDRCL_SOURCE_DIR}/runtime/dll/windows/options.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/sys_calls.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/wddm_create.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/ult_dxgi_factory.cpp ) +else() + target_sources(igdrcl_tbx_tests PRIVATE + ${IGDRCL_SOURCE_DIR}/runtime/dll/linux/options.cpp + ) endif() target_include_directories(igdrcl_tbx_tests PRIVATE