fix: setup correct non-release key name in getStringWithFlags
unify function for getting env Related-To: NEO-8347 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
parent
cbbcbc94b1
commit
46288b8efd
|
@ -91,13 +91,10 @@ void DebugSettingsManager<DebugLevel>::getStringWithFlags(std::string &allFlags,
|
||||||
|
|
||||||
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \
|
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \
|
||||||
{ \
|
{ \
|
||||||
char neoFinal[MAX_NEO_KEY_LENGTH]; \
|
std::string neoKey = convPrefixToString(flags.variableName.getPrefixType()); \
|
||||||
const char *prefix = convPrefixToString(flags.variableName.getPrefixType()); \
|
neoKey += getNonReleaseKeyName(#variableName); \
|
||||||
strcpy_s(neoFinal, strlen(prefix) + 1, prefix); \
|
allFlagsStream << neoKey.c_str() << " = " << flags.variableName.get() << '\n'; \
|
||||||
strcpy_s(neoFinal + strlen(prefix), strlen(#variableName) + 1, #variableName); \
|
dumpNonDefaultFlag<dataType>(neoKey.c_str(), flags.variableName.get(), defaultValue, changedFlagsStream); \
|
||||||
const char *neoKey = neoFinal; \
|
|
||||||
allFlagsStream << getNonReleaseKeyName(neoKey) << " = " << flags.variableName.get() << '\n'; \
|
|
||||||
dumpNonDefaultFlag<dataType>(getNonReleaseKeyName(neoKey), flags.variableName.get(), defaultValue, changedFlagsStream); \
|
|
||||||
}
|
}
|
||||||
if (registryReadAvailable() || isDebugKeysReadEnabled()) {
|
if (registryReadAvailable() || isDebugKeysReadEnabled()) {
|
||||||
#include "debug_variables.inl"
|
#include "debug_variables.inl"
|
||||||
|
@ -106,13 +103,10 @@ void DebugSettingsManager<DebugLevel>::getStringWithFlags(std::string &allFlags,
|
||||||
|
|
||||||
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \
|
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \
|
||||||
{ \
|
{ \
|
||||||
char neoFinal[MAX_NEO_KEY_LENGTH]; \
|
std::string neoKey = convPrefixToString(flags.variableName.getPrefixType()); \
|
||||||
const char *prefix = convPrefixToString(flags.variableName.getPrefixType()); \
|
neoKey += #variableName; \
|
||||||
strcpy_s(neoFinal, strlen(prefix) + 1, prefix); \
|
allFlagsStream << neoKey.c_str() << " = " << flags.variableName.get() << '\n'; \
|
||||||
strcpy_s(neoFinal + strlen(prefix), strlen(#variableName) + 1, #variableName); \
|
dumpNonDefaultFlag<dataType>(neoKey.c_str(), flags.variableName.get(), defaultValue, changedFlagsStream); \
|
||||||
const char *neoKey = neoFinal; \
|
|
||||||
allFlagsStream << neoKey << " = " << flags.variableName.get() << '\n'; \
|
|
||||||
dumpNonDefaultFlag<dataType>(neoKey, flags.variableName.get(), defaultValue, changedFlagsStream); \
|
|
||||||
}
|
}
|
||||||
#include "release_variables.inl"
|
#include "release_variables.inl"
|
||||||
#undef DECLARE_DEBUG_VARIABLE
|
#undef DECLARE_DEBUG_VARIABLE
|
||||||
|
|
|
@ -172,8 +172,6 @@ class DebugSettingsManager {
|
||||||
|
|
||||||
extern DebugSettingsManager<globalDebugFunctionalityLevel> DebugManager;
|
extern DebugSettingsManager<globalDebugFunctionalityLevel> DebugManager;
|
||||||
|
|
||||||
#define MAX_NEO_KEY_LENGTH 256
|
|
||||||
|
|
||||||
#define PRINT_DEBUGGER_LOG_TO_FILE(...) \
|
#define PRINT_DEBUGGER_LOG_TO_FILE(...) \
|
||||||
NEO::DebugManager.logLazyEvaluateArgs([&] { \
|
NEO::DebugManager.logLazyEvaluateArgs([&] { \
|
||||||
char temp[4000]; \
|
char temp[4000]; \
|
||||||
|
|
|
@ -40,13 +40,12 @@ int64_t EnvironmentVariableReader::getSetting(const char *settingName, int64_t d
|
||||||
|
|
||||||
const std::vector<const char *> prefixString = ApiSpecificConfig::getPrefixStrings();
|
const std::vector<const char *> prefixString = ApiSpecificConfig::getPrefixStrings();
|
||||||
const std::vector<NEO::DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
const std::vector<NEO::DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
||||||
char neoFinal[MAX_NEO_KEY_LENGTH];
|
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
|
|
||||||
for (const auto &prefix : prefixString) {
|
for (const auto &prefix : prefixString) {
|
||||||
strcpy_s(neoFinal, strlen(prefix) + 1, prefix);
|
std::string neoKey = prefix;
|
||||||
strcpy_s(neoFinal + strlen(prefix), strlen(settingName) + 1, settingName);
|
neoKey += settingName;
|
||||||
envValue = IoFunctions::getenvPtr(neoFinal);
|
envValue = IoFunctions::getenvPtr(neoKey.c_str());
|
||||||
if (envValue) {
|
if (envValue) {
|
||||||
value = atoll(envValue);
|
value = atoll(envValue);
|
||||||
type = prefixType[i];
|
type = prefixType[i];
|
||||||
|
@ -77,12 +76,11 @@ std::string EnvironmentVariableReader::getSetting(const char *settingName, const
|
||||||
const std::vector<const char *> prefixString = ApiSpecificConfig::getPrefixStrings();
|
const std::vector<const char *> prefixString = ApiSpecificConfig::getPrefixStrings();
|
||||||
const std::vector<DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
const std::vector<DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
||||||
|
|
||||||
char neoFinal[MAX_NEO_KEY_LENGTH];
|
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
for (const auto &prefix : prefixString) {
|
for (const auto &prefix : prefixString) {
|
||||||
strcpy_s(neoFinal, strlen(prefix) + 1, prefix);
|
std::string neoKey = prefix;
|
||||||
strcpy_s(neoFinal + strlen(prefix), strlen(settingName) + 1, settingName);
|
neoKey += settingName;
|
||||||
envValue = IoFunctions::getenvPtr(neoFinal);
|
envValue = IoFunctions::getenvPtr(neoKey.c_str());
|
||||||
if (envValue) {
|
if (envValue) {
|
||||||
keyValue.assign(envValue);
|
keyValue.assign(envValue);
|
||||||
type = prefixType[i];
|
type = prefixType[i];
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2020 Intel Corporation
|
* Copyright (C) 2020-2023 Intel Corporation
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
|
@ -12,8 +12,4 @@ namespace NEO {
|
||||||
SettingsReader *SettingsReader::createOsReader(bool userScope, const std::string ®Key) {
|
SettingsReader *SettingsReader::createOsReader(bool userScope, const std::string ®Key) {
|
||||||
return new EnvironmentVariableReader;
|
return new EnvironmentVariableReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *SettingsReader::getenv(const char *settingName) {
|
|
||||||
return ::getenv(settingName);
|
|
||||||
}
|
|
||||||
} // namespace NEO
|
} // namespace NEO
|
||||||
|
|
|
@ -21,10 +21,6 @@ SettingsReader *SettingsReader::createOsReader(bool userScope, const std::string
|
||||||
return new RegistryReader(userScope, regKey);
|
return new RegistryReader(userScope, regKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *SettingsReader::getenv(const char *settingName) {
|
|
||||||
return IoFunctions::getenvPtr(settingName);
|
|
||||||
}
|
|
||||||
|
|
||||||
RegistryReader::RegistryReader(bool userScope, const std::string ®Key) : registryReadRootKey(regKey) {
|
RegistryReader::RegistryReader(bool userScope, const std::string ®Key) : registryReadRootKey(regKey) {
|
||||||
hkeyType = userScope ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
|
hkeyType = userScope ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
|
||||||
setUpProcessName();
|
setUpProcessName();
|
||||||
|
@ -99,12 +95,11 @@ int64_t RegistryReader::getSetting(const char *settingName, int64_t defaultValue
|
||||||
const std::vector<const char *> prefixString = ApiSpecificConfig::getPrefixStrings();
|
const std::vector<const char *> prefixString = ApiSpecificConfig::getPrefixStrings();
|
||||||
const std::vector<DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
const std::vector<DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
||||||
|
|
||||||
char neoFinal[MAX_NEO_KEY_LENGTH];
|
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
for (const auto &prefix : prefixString) {
|
for (const auto &prefix : prefixString) {
|
||||||
strcpy_s(neoFinal, strlen(prefix) + 1, prefix);
|
std::string neoKey = prefix;
|
||||||
strcpy_s(neoFinal + strlen(prefix), strlen(settingName) + 1, settingName);
|
neoKey += settingName;
|
||||||
envValue = getenv(neoFinal);
|
envValue = IoFunctions::getenvPtr(neoKey.c_str());
|
||||||
if (envValue) {
|
if (envValue) {
|
||||||
value = atoll(envValue);
|
value = atoll(envValue);
|
||||||
type = prefixType[i];
|
type = prefixType[i];
|
||||||
|
@ -121,7 +116,7 @@ int64_t RegistryReader::getSetting(const char *settingName, int64_t defaultValue
|
||||||
int64_t value = defaultValue;
|
int64_t value = defaultValue;
|
||||||
|
|
||||||
if (!(getSettingIntCommon(settingName, value))) {
|
if (!(getSettingIntCommon(settingName, value))) {
|
||||||
const char *envValue = getenv(settingName);
|
const char *envValue = IoFunctions::getenvPtr(settingName);
|
||||||
if (envValue) {
|
if (envValue) {
|
||||||
value = atoll(envValue);
|
value = atoll(envValue);
|
||||||
}
|
}
|
||||||
|
@ -198,12 +193,11 @@ std::string RegistryReader::getSetting(const char *settingName, const std::strin
|
||||||
const std::vector<const char *> prefixString = ApiSpecificConfig::getPrefixStrings();
|
const std::vector<const char *> prefixString = ApiSpecificConfig::getPrefixStrings();
|
||||||
const std::vector<DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
const std::vector<DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
||||||
|
|
||||||
char neoFinal[MAX_NEO_KEY_LENGTH];
|
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
for (const auto &prefix : prefixString) {
|
for (const auto &prefix : prefixString) {
|
||||||
strcpy_s(neoFinal, strlen(prefix) + 1, prefix);
|
std::string neoKey = prefix;
|
||||||
strcpy_s(neoFinal + strlen(prefix), strlen(settingName) + 1, settingName);
|
neoKey += settingName;
|
||||||
envValue = strcmp(processName.c_str(), neoFinal) ? getenv(neoFinal) : getenv("cl_cache_dir");
|
envValue = strcmp(processName.c_str(), neoKey.c_str()) ? IoFunctions::getenvPtr(neoKey.c_str()) : IoFunctions::getenvPtr("cl_cache_dir");
|
||||||
if (envValue) {
|
if (envValue) {
|
||||||
keyValue.assign(envValue);
|
keyValue.assign(envValue);
|
||||||
type = prefixType[i];
|
type = prefixType[i];
|
||||||
|
@ -220,7 +214,7 @@ std::string RegistryReader::getSetting(const char *settingName, const std::strin
|
||||||
std::string keyValue = value;
|
std::string keyValue = value;
|
||||||
|
|
||||||
if (!(getSettingStringCommon(settingName, keyValue))) {
|
if (!(getSettingStringCommon(settingName, keyValue))) {
|
||||||
const char *envValue = strcmp(processName.c_str(), settingName) ? getenv(settingName) : getenv("cl_cache_dir");
|
const char *envValue = strcmp(processName.c_str(), settingName) ? IoFunctions::getenvPtr(settingName) : IoFunctions::getenvPtr("cl_cache_dir");
|
||||||
if (envValue) {
|
if (envValue) {
|
||||||
keyValue.assign(envValue);
|
keyValue.assign(envValue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,12 +45,11 @@ int64_t SettingsFileReader::getSetting(const char *settingName, int64_t defaultV
|
||||||
const std::vector<const char *> prefixString = ApiSpecificConfig::getPrefixStrings();
|
const std::vector<const char *> prefixString = ApiSpecificConfig::getPrefixStrings();
|
||||||
const std::vector<DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
const std::vector<DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
||||||
|
|
||||||
char neoFinal[MAX_NEO_KEY_LENGTH];
|
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
for (const auto &prefix : prefixString) {
|
for (const auto &prefix : prefixString) {
|
||||||
strcpy_s(neoFinal, strlen(prefix) + 1, prefix);
|
std::string neoKey = prefix;
|
||||||
strcpy_s(neoFinal + strlen(prefix), strlen(settingName) + 1, settingName);
|
neoKey += settingName;
|
||||||
std::map<std::string, std::string>::iterator it = settingStringMap.find(std::string(neoFinal));
|
std::map<std::string, std::string>::iterator it = settingStringMap.find(neoKey);
|
||||||
if (it != settingStringMap.end()) {
|
if (it != settingStringMap.end()) {
|
||||||
value = strtoll(it->second.c_str(), nullptr, 0);
|
value = strtoll(it->second.c_str(), nullptr, 0);
|
||||||
type = prefixType[i];
|
type = prefixType[i];
|
||||||
|
@ -87,12 +86,11 @@ std::string SettingsFileReader::getSetting(const char *settingName, const std::s
|
||||||
const std::vector<const char *> prefixString = ApiSpecificConfig::getPrefixStrings();
|
const std::vector<const char *> prefixString = ApiSpecificConfig::getPrefixStrings();
|
||||||
const std::vector<DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
const std::vector<DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
||||||
|
|
||||||
char neoFinal[MAX_NEO_KEY_LENGTH];
|
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
for (const auto &prefix : prefixString) {
|
for (const auto &prefix : prefixString) {
|
||||||
strcpy_s(neoFinal, strlen(prefix) + 1, prefix);
|
std::string neoKey = prefix;
|
||||||
strcpy_s(neoFinal + strlen(prefix), strlen(settingName) + 1, settingName);
|
neoKey += settingName;
|
||||||
std::map<std::string, std::string>::iterator it = settingStringMap.find(std::string(neoFinal));
|
std::map<std::string, std::string>::iterator it = settingStringMap.find(neoKey);
|
||||||
if (it != settingStringMap.end()) {
|
if (it != settingStringMap.end()) {
|
||||||
returnValue = it->second;
|
returnValue = it->second;
|
||||||
type = prefixType[i];
|
type = prefixType[i];
|
||||||
|
|
|
@ -36,6 +36,5 @@ class SettingsReader {
|
||||||
virtual const char *appSpecificLocation(const std::string &name) = 0;
|
virtual const char *appSpecificLocation(const std::string &name) = 0;
|
||||||
static const char *settingsFileName;
|
static const char *settingsFileName;
|
||||||
static const char *neoSettingsFileName;
|
static const char *neoSettingsFileName;
|
||||||
MOCKABLE_VIRTUAL char *getenv(const char *settingName);
|
|
||||||
};
|
};
|
||||||
}; // namespace NEO
|
}; // namespace NEO
|
||||||
|
|
|
@ -9,45 +9,41 @@
|
||||||
|
|
||||||
#include "shared/source/helpers/api_specific_config.h"
|
#include "shared/source/helpers/api_specific_config.h"
|
||||||
#include "shared/source/os_interface/windows/debug_registry_reader.h"
|
#include "shared/source/os_interface/windows/debug_registry_reader.h"
|
||||||
|
#include "shared/test/common/helpers/variable_backup.h"
|
||||||
|
#include "shared/test/common/mocks/mock_io_functions.h"
|
||||||
|
|
||||||
namespace NEO {
|
namespace NEO {
|
||||||
class TestedRegistryReader : public RegistryReader {
|
class TestedRegistryReader : public RegistryReader {
|
||||||
public:
|
public:
|
||||||
TestedRegistryReader(bool userScope) : RegistryReader(userScope, ApiSpecificConfig::getRegistryPath()){};
|
TestedRegistryReader(bool userScope) : RegistryReader(userScope, ApiSpecificConfig::getRegistryPath()) {
|
||||||
TestedRegistryReader(std::string regKey) : RegistryReader(false, regKey){};
|
initEnv();
|
||||||
|
};
|
||||||
|
TestedRegistryReader(std::string regKey) : RegistryReader(false, regKey) {
|
||||||
|
initEnv();
|
||||||
|
};
|
||||||
HKEY getHkeyType() const {
|
HKEY getHkeyType() const {
|
||||||
return hkeyType;
|
return hkeyType;
|
||||||
}
|
}
|
||||||
using RegistryReader::getSetting;
|
using RegistryReader::getSetting;
|
||||||
using RegistryReader::processName;
|
using RegistryReader::processName;
|
||||||
|
|
||||||
char *getenv(const char *envVar) override {
|
void initEnv() {
|
||||||
if (strcmp(envVar, "TestedEnvironmentVariable") == 0) {
|
|
||||||
return "TestedEnvironmentVariableValue";
|
IoFunctions::mockableEnvValues->insert({"TestedEnvironmentVariable", "TestedEnvironmentVariableValue"});
|
||||||
} else if (strcmp(envVar, "NEO_TestedEnvironmentVariableWithPrefix") == 0) {
|
IoFunctions::mockableEnvValues->insert({"NEO_TestedEnvironmentVariableWithPrefix", "TestedEnvironmentVariableValueWithPrefix"});
|
||||||
return "TestedEnvironmentVariableValueWithPrefix";
|
IoFunctions::mockableEnvValues->insert({"TestedEnvironmentIntVariable", "1234"});
|
||||||
} else if (strcmp(envVar, "TestedEnvironmentIntVariable") == 0) {
|
IoFunctions::mockableEnvValues->insert({"NEO_TestedEnvironmentIntVariableWithPrefix", "5678"});
|
||||||
return "1234";
|
IoFunctions::mockableEnvValues->insert({"TestedEnvironmentInt64Variable", "9223372036854775807"});
|
||||||
} else if (strcmp(envVar, "NEO_TestedEnvironmentIntVariableWithPrefix") == 0) {
|
IoFunctions::mockableEnvValues->insert({"NEO_TestedEnvironmentInt64VariableWithPrefix", "9223372036854775806"});
|
||||||
return "5678";
|
IoFunctions::mockableEnvValues->insert({"settingSourceString", "environment"});
|
||||||
} else if (strcmp(envVar, "TestedEnvironmentInt64Variable") == 0) {
|
IoFunctions::mockableEnvValues->insert({"settingSourceInt", "2"});
|
||||||
return "9223372036854775807";
|
IoFunctions::mockableEnvValues->insert({"processName", "processName"});
|
||||||
} else if (strcmp(envVar, "NEO_TestedEnvironmentInt64VariableWithPrefix") == 0) {
|
IoFunctions::mockableEnvValues->insert({"cl_cache_dir", "./tested_cl_cache_dir"});
|
||||||
return "9223372036854775806";
|
|
||||||
} else if (strcmp(envVar, "settingSourceString") == 0) {
|
|
||||||
return "environment";
|
|
||||||
} else if (strcmp(envVar, "settingSourceInt") == 0) {
|
|
||||||
return "2";
|
|
||||||
} else if (strcmp(envVar, "processName") == 0) {
|
|
||||||
return "processName";
|
|
||||||
} else if (strcmp(envVar, "cl_cache_dir") == 0) {
|
|
||||||
return "./tested_cl_cache_dir";
|
|
||||||
} else {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const char *getRegKey() const {
|
const char *getRegKey() const {
|
||||||
return registryReadRootKey.c_str();
|
return registryReadRootKey.c_str();
|
||||||
}
|
}
|
||||||
|
std::unordered_map<std::string, std::string> mockEnvironment{};
|
||||||
|
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup{&IoFunctions::mockableEnvValues, &mockEnvironment};
|
||||||
};
|
};
|
||||||
} // namespace NEO
|
} // namespace NEO
|
||||||
|
|
|
@ -114,9 +114,3 @@ TEST(SettingsReader, GivenFalseWhenPrintingDebugStringThenNoOutput) {
|
||||||
std::string output = testing::internal::GetCapturedStdout();
|
std::string output = testing::internal::GetCapturedStdout();
|
||||||
EXPECT_STREQ(output.c_str(), "");
|
EXPECT_STREQ(output.c_str(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SettingsReader, givenNonExistingEnvVarWhenGettingEnvThenNullptrIsReturned) {
|
|
||||||
MockSettingsReader reader;
|
|
||||||
auto value = reader.getenv("ThisEnvVarDoesNotExist");
|
|
||||||
EXPECT_EQ(nullptr, value);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue