From a199ae4d8b4ea025066725d00a5eb7b713eb8da8 Mon Sep 17 00:00:00 2001 From: Konstanty Misiak Date: Thu, 20 Aug 2020 12:10:51 +0200 Subject: [PATCH] Add linux-only switch to enable debug env variables read Related-To: NEO-4941 Change-Id: I47ebddd5a902f20b79c37e18a49f0bba652fd119 Signed-off-by: Konstanty Misiak --- shared/source/debug_settings/CMakeLists.txt | 11 +++ .../debug_settings/debug_settings_manager.cpp | 5 +- .../debug_settings/debug_variables_helper.h | 14 ++++ .../linux/debug_variables_helper.cpp | 19 +++++ .../windows/debug_variables_helper.cpp | 16 ++++ .../unit_test/debug_settings/CMakeLists.txt | 11 +++ .../debug_settings_manager_tests.cpp | 13 +++ .../debug_settings_manager_linux_tests.cpp | 79 +++++++++++++++++++ .../debug_variables_helper_linux_tests.cpp | 35 ++++++++ .../debug_variables_helper_windows_tests.cpp | 18 +++++ 10 files changed, 219 insertions(+), 2 deletions(-) create mode 100644 shared/source/debug_settings/debug_variables_helper.h create mode 100644 shared/source/debug_settings/linux/debug_variables_helper.cpp create mode 100644 shared/source/debug_settings/windows/debug_variables_helper.cpp create mode 100644 shared/test/unit_test/debug_settings/linux/debug_settings_manager_linux_tests.cpp create mode 100644 shared/test/unit_test/debug_settings/linux/debug_variables_helper_linux_tests.cpp create mode 100644 shared/test/unit_test/debug_settings/windows/debug_variables_helper_windows_tests.cpp diff --git a/shared/source/debug_settings/CMakeLists.txt b/shared/source/debug_settings/CMakeLists.txt index f1a0d3c7a8..056431a6ae 100644 --- a/shared/source/debug_settings/CMakeLists.txt +++ b/shared/source/debug_settings/CMakeLists.txt @@ -9,10 +9,21 @@ set(NEO_CORE_DEBUG_SETTINGS ${CMAKE_CURRENT_SOURCE_DIR}/debug_settings_manager.h ${CMAKE_CURRENT_SOURCE_DIR}/debug_settings_manager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/debug_variables_base.inl + ${CMAKE_CURRENT_SOURCE_DIR}/debug_variables_helper.h ${CMAKE_CURRENT_SOURCE_DIR}/release_variables.inl ${CMAKE_CURRENT_SOURCE_DIR}/definitions${BRANCH_DIR_SUFFIX}/debug_variables.inl ${CMAKE_CURRENT_SOURCE_DIR}/definitions${BRANCH_DIR_SUFFIX}/translate_debug_settings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/definitions/translate_debug_settings.h ) +if(WIN32) + list(APPEND NEO_CORE_DEBUG_SETTINGS + ${CMAKE_CURRENT_SOURCE_DIR}/windows/debug_variables_helper.cpp + ) +elseif(UNIX) + list(APPEND NEO_CORE_DEBUG_SETTINGS + ${CMAKE_CURRENT_SOURCE_DIR}/linux/debug_variables_helper.cpp + ) +endif() + set_property(GLOBAL PROPERTY NEO_CORE_DEBUG_SETTINGS ${NEO_CORE_DEBUG_SETTINGS}) diff --git a/shared/source/debug_settings/debug_settings_manager.cpp b/shared/source/debug_settings/debug_settings_manager.cpp index 66c63c3f55..9656ec5c58 100644 --- a/shared/source/debug_settings/debug_settings_manager.cpp +++ b/shared/source/debug_settings/debug_settings_manager.cpp @@ -7,6 +7,7 @@ #include "debug_settings_manager.h" +#include "shared/source/debug_settings/debug_variables_helper.h" #include "shared/source/debug_settings/definitions/translate_debug_settings.h" #include "shared/source/helpers/debug_helpers.h" #include "shared/source/helpers/ptr_math.h" @@ -73,7 +74,7 @@ void DebugSettingsManager::dumpFlags() const { #define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \ settingsDumpFile << #variableName << " = " << flags.variableName.get() << '\n'; \ dumpNonDefaultFlag(#variableName, flags.variableName.get(), defaultValue); - if (registryReadAvailable()) { + if (registryReadAvailable() || isDebugKeysReadEnabled()) { #include "debug_variables.inl" } #include "release_variables.inl" @@ -89,7 +90,7 @@ void DebugSettingsManager::injectSettingsFromReader() { flags.variableName.set(tempData); \ } - if (registryReadAvailable()) { + if (registryReadAvailable() || isDebugKeysReadEnabled()) { #include "debug_variables.inl" } #include "release_variables.inl" diff --git a/shared/source/debug_settings/debug_variables_helper.h b/shared/source/debug_settings/debug_variables_helper.h new file mode 100644 index 0000000000..f06d421c0f --- /dev/null +++ b/shared/source/debug_settings/debug_variables_helper.h @@ -0,0 +1,14 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +namespace NEO { + +bool isDebugKeysReadEnabled(); + +} // namespace NEO diff --git a/shared/source/debug_settings/linux/debug_variables_helper.cpp b/shared/source/debug_settings/linux/debug_variables_helper.cpp new file mode 100644 index 0000000000..74dc333fe0 --- /dev/null +++ b/shared/source/debug_settings/linux/debug_variables_helper.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/debug_settings/debug_variables_helper.h" + +#include "shared/source/os_interface/debug_env_reader.h" + +namespace NEO { + +bool isDebugKeysReadEnabled() { + EnvironmentVariableReader envReader; + return envReader.getSetting("NEOReadDebugKeys", false); +} + +} // namespace NEO diff --git a/shared/source/debug_settings/windows/debug_variables_helper.cpp b/shared/source/debug_settings/windows/debug_variables_helper.cpp new file mode 100644 index 0000000000..6a475deeff --- /dev/null +++ b/shared/source/debug_settings/windows/debug_variables_helper.cpp @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/debug_settings/debug_variables_helper.h" + +namespace NEO { + +bool isDebugKeysReadEnabled() { + return false; +} + +} // namespace NEO diff --git a/shared/test/unit_test/debug_settings/CMakeLists.txt b/shared/test/unit_test/debug_settings/CMakeLists.txt index 3576b28b04..26e624ded3 100644 --- a/shared/test/unit_test/debug_settings/CMakeLists.txt +++ b/shared/test/unit_test/debug_settings/CMakeLists.txt @@ -10,3 +10,14 @@ target_sources(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/debug_settings_manager_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/debug_settings_manager_tests.cpp ) + +if(WIN32) + target_sources(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/windows/debug_variables_helper_windows_tests.cpp + ) +elseif(UNIX) + target_sources(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/linux/debug_settings_manager_linux_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linux/debug_variables_helper_linux_tests.cpp + ) +endif() diff --git a/shared/test/unit_test/debug_settings/debug_settings_manager_tests.cpp b/shared/test/unit_test/debug_settings/debug_settings_manager_tests.cpp index fe6d5ecd0d..987806096c 100644 --- a/shared/test/unit_test/debug_settings/debug_settings_manager_tests.cpp +++ b/shared/test/unit_test/debug_settings/debug_settings_manager_tests.cpp @@ -141,6 +141,19 @@ TEST(DebugSettingsManager, givenPrintDebugSettingsEnabledWhenCallingDumpFlagsThe EXPECT_NE(std::string::npos, output.find("Non-default value of debug variable: Enable64kbpages = 1")); } +TEST(DebugSettingsManager, givenPrintDebugSettingsEnabledOnDisabledDebugManagerWhenCallingDumpFlagsThenFlagsAreNotWrittenToDumpFile) { + testing::internal::CaptureStdout(); + FullyDisabledTestDebugManager debugManager; + debugManager.flags.PrintDebugSettings.set(true); + + std::remove(FullyDisabledTestDebugManager::settingsDumpFileName); + debugManager.dumpFlags(); + std::remove(FullyDisabledTestDebugManager::settingsDumpFileName); + + std::string output = testing::internal::GetCapturedStdout(); + ASSERT_EQ(0u, output.size()); +} + TEST(AllocationInfoLogging, givenBaseGraphicsAllocationWhenGettingImplementationSpecificAllocationInfoThenReturnEmptyInfoString) { GraphicsAllocation graphicsAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0ull, 0ull, 0, MemoryPool::MemoryNull); EXPECT_STREQ(graphicsAllocation.getAllocationInfoString().c_str(), ""); diff --git a/shared/test/unit_test/debug_settings/linux/debug_settings_manager_linux_tests.cpp b/shared/test/unit_test/debug_settings/linux/debug_settings_manager_linux_tests.cpp new file mode 100644 index 0000000000..7750f3ff64 --- /dev/null +++ b/shared/test/unit_test/debug_settings/linux/debug_settings_manager_linux_tests.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/helpers/file_io.h" +#include "shared/source/utilities/debug_file_reader.h" +#include "shared/test/unit_test/debug_settings/debug_settings_manager_fixture.h" +#include "shared/test/unit_test/helpers/variable_backup.h" + +#include "opencl/test/unit_test/mocks/mock_io_functions.h" +#include "test.h" + +#include + +namespace NEO { + +TEST(DebugSettingsManager, givenDisabledDebugManagerAndMockEnvVariableWhenCreateThenAllVariablesAreRead) { + bool settingsFileExists = fileExists(SettingsReader::settingsFileName); + if (!settingsFileExists) { + const char data[] = "LogApiCalls = 1\nMakeAllBuffersResident = 1"; + writeDataToFile(SettingsReader::settingsFileName, &data, sizeof(data)); + } + + SettingsReader *reader = SettingsReader::createFileReader(); + EXPECT_NE(nullptr, reader); + + VariableBackup mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0); + std::unordered_map mockableEnvs = {{"NEOReadDebugKeys", "1"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); + + FullyDisabledTestDebugManager debugManager; + debugManager.setReaderImpl(reader); + debugManager.injectSettingsFromReader(); + + EXPECT_EQ(1, debugManager.flags.MakeAllBuffersResident.get()); + EXPECT_EQ(1, debugManager.flags.LogApiCalls.get()); + + if (!settingsFileExists) { + remove(SettingsReader::settingsFileName); + } +} + +TEST(DebugSettingsManager, givenPrintDebugSettingsAndDebugKeysReadEnabledOnDisabledDebugManagerWhenCallingDumpFlagsThenFlagsAreWrittenToDumpFile) { + testing::internal::CaptureStdout(); + FullyDisabledTestDebugManager debugManager; + debugManager.flags.PrintDebugSettings.set(true); + debugManager.flags.LoopAtDriverInit.set(true); + debugManager.flags.Enable64kbpages.set(1); + debugManager.flags.TbxServer.set("192.168.0.1"); + + VariableBackup mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0); + std::unordered_map mockableEnvs = {{"NEOReadDebugKeys", "1"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); + + // Clear dump files and generate new + std::remove(FullyDisabledTestDebugManager::settingsDumpFileName); + debugManager.dumpFlags(); + + // Validate allSettingsDumpFile + SettingsFileReader allSettingsReader{FullyDisabledTestDebugManager::settingsDumpFileName}; +#define DECLARE_DEBUG_VARIABLE(dataType, varName, defaultValue, description) \ + EXPECT_EQ(debugManager.flags.varName.get(), allSettingsReader.getSetting(#varName, defaultValue)); + +#include "debug_variables.inl" +#undef DECLARE_DEBUG_VARIABLE + std::remove(FullyDisabledTestDebugManager::settingsDumpFileName); + std::string output = testing::internal::GetCapturedStdout(); + ASSERT_NE(0u, output.size()); + + EXPECT_NE(std::string::npos, output.find("Non-default value of debug variable: TbxServer = 192.168.0.1")); + EXPECT_NE(std::string::npos, output.find("Non-default value of debug variable: LoopAtDriverInit = 1")); + EXPECT_NE(std::string::npos, output.find("Non-default value of debug variable: PrintDebugSettings = 1")); + EXPECT_NE(std::string::npos, output.find("Non-default value of debug variable: Enable64kbpages = 1")); +} + +} // namespace NEO diff --git a/shared/test/unit_test/debug_settings/linux/debug_variables_helper_linux_tests.cpp b/shared/test/unit_test/debug_settings/linux/debug_variables_helper_linux_tests.cpp new file mode 100644 index 0000000000..f6d4d4b2b4 --- /dev/null +++ b/shared/test/unit_test/debug_settings/linux/debug_variables_helper_linux_tests.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/debug_settings/debug_variables_helper.h" +#include "shared/test/unit_test/helpers/variable_backup.h" + +#include "opencl/test/unit_test/mocks/mock_io_functions.h" +#include "test.h" + +#include + +namespace NEO { + +TEST(DebugVariablesHelperTests, whenIsDebugKeysReadEnableIsCalledThenProperValueIsReturned) { + { + VariableBackup mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0); + std::unordered_map mockableEnvs = {{"NEOReadDebugKeys", "1"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); + + EXPECT_TRUE(isDebugKeysReadEnabled()); + } + { + VariableBackup mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0); + std::unordered_map mockableEnvs = {{"NEOReadDebugKeys", "0"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); + + EXPECT_FALSE(isDebugKeysReadEnabled()); + } +} + +} // namespace NEO diff --git a/shared/test/unit_test/debug_settings/windows/debug_variables_helper_windows_tests.cpp b/shared/test/unit_test/debug_settings/windows/debug_variables_helper_windows_tests.cpp new file mode 100644 index 0000000000..12b2a1c3df --- /dev/null +++ b/shared/test/unit_test/debug_settings/windows/debug_variables_helper_windows_tests.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/debug_settings/debug_variables_helper.h" + +#include "test.h" + +namespace NEO { + +TEST(DebugVariablesHelperTests, whenIsDebugKeysReadEnableIsCalledThenFalseIsReturned) { + EXPECT_FALSE(NEO::isDebugKeysReadEnabled()); +} + +} // namespace NEO