From eb0273d6ffbfdfb8d7abd91f26d6c0a3199855d1 Mon Sep 17 00:00:00 2001 From: Mateusz Hoppe Date: Thu, 1 Sep 2022 12:58:13 +0000 Subject: [PATCH] L0Debug - add debug message when ZE_AFFINITY_MASK is used Related-To: NEO-6980 Signed-off-by: Mateusz Hoppe --- .../tools/source/debug/debug_handlers.cpp | 10 +++++++ .../sources/debug/test_debug_api.cpp | 29 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/level_zero/tools/source/debug/debug_handlers.cpp b/level_zero/tools/source/debug/debug_handlers.cpp index 48f05c2a91..43aff90154 100644 --- a/level_zero/tools/source/debug/debug_handlers.cpp +++ b/level_zero/tools/source/debug/debug_handlers.cpp @@ -7,6 +7,8 @@ #include "level_zero/tools/source/debug/debug_handlers.h" +#include "shared/source/os_interface/debug_env_reader.h" + #include "level_zero/core/source/device/device_imp.h" #include "level_zero/tools/source/debug/debug_session.h" @@ -22,6 +24,14 @@ ze_result_t debugAttach(zet_device_handle_t hDevice, const zet_debug_config_t *c return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } + NEO::EnvironmentVariableReader envReader; + auto affinityMask = envReader.getSetting("ZE_AFFINITY_MASK", std::string("")); + + if (!affinityMask.empty()) { + NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stdout, + "%s", "ZE_AFFINITY_MASK is not recommended while using program debug API\n"); + } + auto session = L0::Device::fromHandle(hDevice)->getDebugSession(*config); std::unique_lock lock(debugSessionMutex); diff --git a/level_zero/tools/test/unit_tests/sources/debug/test_debug_api.cpp b/level_zero/tools/test/unit_tests/sources/debug/test_debug_api.cpp index d780f4bcf6..c3286d469c 100644 --- a/level_zero/tools/test/unit_tests/sources/debug/test_debug_api.cpp +++ b/level_zero/tools/test/unit_tests/sources/debug/test_debug_api.cpp @@ -5,7 +5,10 @@ * */ +#include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/variable_backup.h" #include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_io_functions.h" #include "shared/test/common/mocks/mock_sip.h" #include "shared/test/common/test_macros/hw_test.h" @@ -313,7 +316,7 @@ TEST(DebugSessionTest, givenDeviceWithDebugSessionWhenRemoveCalledThenSessionIsN EXPECT_EQ(nullptr, deviceImp.debugSession.get()); } -TEST(DebugSessionTest, givenSubDeviceWhenCreateingSessionThenNullptrReturned) { +TEST(DebugSessionTest, givenSubDeviceWhenCreatingSessionThenNullptrReturned) { zet_debug_config_t config = {}; config.pid = 0x1234; @@ -328,7 +331,7 @@ TEST(DebugSessionTest, givenSubDeviceWhenCreateingSessionThenNullptrReturned) { EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, result); } -TEST(DebugSessionTest, givenRootDeviceWhenCreateingSessionThenResultReturnedIsCorrect) { +TEST(DebugSessionTest, givenRootDeviceWhenCreatingSessionThenResultReturnedIsCorrect) { zet_debug_config_t config = {}; config.pid = 0x1234; @@ -348,5 +351,27 @@ TEST(DebugSessionTest, givenRootDeviceWhenCreateingSessionThenResultReturnedIsCo EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, result); } +TEST_F(DebugApiTest, givenZeAffinityMaskAndEnabledDebugMessagesWhenDebugAttachCalledThenMessageIsPrinted) { + DebugManagerStateRestore restorer; + NEO::DebugManager.flags.PrintDebugMessages.set(1); + + VariableBackup mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0); + std::unordered_map mockableEnvs = {{"ZE_AFFINITY_MASK", "0.1"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); + + zet_debug_config_t config = {}; + config.pid = 0x1234; + + Mock deviceImp(neoDevice, neoDevice->getExecutionEnvironment()); + deviceImp.debugSession.reset(new DebugSessionMock(config, &deviceImp)); + + testing::internal::CaptureStdout(); + zet_debug_session_handle_t debugSession = nullptr; + zetDebugAttach(deviceImp.toHandle(), &config, &debugSession); + + std::string output = testing::internal::GetCapturedStdout(); + EXPECT_EQ(std::string("ZE_AFFINITY_MASK is not recommended while using program debug API\n"), output); +} + } // namespace ult } // namespace L0