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
|
@ -89,30 +89,24 @@ void DebugSettingsManager<DebugLevel>::getStringWithFlags(std::string &allFlags,
|
|||
std::ostringstream changedFlagsStream;
|
||||
changedFlagsStream.str("");
|
||||
|
||||
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \
|
||||
{ \
|
||||
char neoFinal[MAX_NEO_KEY_LENGTH]; \
|
||||
const char *prefix = convPrefixToString(flags.variableName.getPrefixType()); \
|
||||
strcpy_s(neoFinal, strlen(prefix) + 1, prefix); \
|
||||
strcpy_s(neoFinal + strlen(prefix), strlen(#variableName) + 1, #variableName); \
|
||||
const char *neoKey = neoFinal; \
|
||||
allFlagsStream << getNonReleaseKeyName(neoKey) << " = " << flags.variableName.get() << '\n'; \
|
||||
dumpNonDefaultFlag<dataType>(getNonReleaseKeyName(neoKey), flags.variableName.get(), defaultValue, changedFlagsStream); \
|
||||
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \
|
||||
{ \
|
||||
std::string neoKey = convPrefixToString(flags.variableName.getPrefixType()); \
|
||||
neoKey += getNonReleaseKeyName(#variableName); \
|
||||
allFlagsStream << neoKey.c_str() << " = " << flags.variableName.get() << '\n'; \
|
||||
dumpNonDefaultFlag<dataType>(neoKey.c_str(), flags.variableName.get(), defaultValue, changedFlagsStream); \
|
||||
}
|
||||
if (registryReadAvailable() || isDebugKeysReadEnabled()) {
|
||||
#include "debug_variables.inl"
|
||||
}
|
||||
#undef DECLARE_DEBUG_VARIABLE
|
||||
|
||||
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \
|
||||
{ \
|
||||
char neoFinal[MAX_NEO_KEY_LENGTH]; \
|
||||
const char *prefix = convPrefixToString(flags.variableName.getPrefixType()); \
|
||||
strcpy_s(neoFinal, strlen(prefix) + 1, prefix); \
|
||||
strcpy_s(neoFinal + strlen(prefix), strlen(#variableName) + 1, #variableName); \
|
||||
const char *neoKey = neoFinal; \
|
||||
allFlagsStream << neoKey << " = " << flags.variableName.get() << '\n'; \
|
||||
dumpNonDefaultFlag<dataType>(neoKey, flags.variableName.get(), defaultValue, changedFlagsStream); \
|
||||
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \
|
||||
{ \
|
||||
std::string neoKey = convPrefixToString(flags.variableName.getPrefixType()); \
|
||||
neoKey += #variableName; \
|
||||
allFlagsStream << neoKey.c_str() << " = " << flags.variableName.get() << '\n'; \
|
||||
dumpNonDefaultFlag<dataType>(neoKey.c_str(), flags.variableName.get(), defaultValue, changedFlagsStream); \
|
||||
}
|
||||
#include "release_variables.inl"
|
||||
#undef DECLARE_DEBUG_VARIABLE
|
||||
|
|
|
@ -172,8 +172,6 @@ class DebugSettingsManager {
|
|||
|
||||
extern DebugSettingsManager<globalDebugFunctionalityLevel> DebugManager;
|
||||
|
||||
#define MAX_NEO_KEY_LENGTH 256
|
||||
|
||||
#define PRINT_DEBUGGER_LOG_TO_FILE(...) \
|
||||
NEO::DebugManager.logLazyEvaluateArgs([&] { \
|
||||
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<NEO::DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
||||
char neoFinal[MAX_NEO_KEY_LENGTH];
|
||||
uint32_t i = 0;
|
||||
|
||||
for (const auto &prefix : prefixString) {
|
||||
strcpy_s(neoFinal, strlen(prefix) + 1, prefix);
|
||||
strcpy_s(neoFinal + strlen(prefix), strlen(settingName) + 1, settingName);
|
||||
envValue = IoFunctions::getenvPtr(neoFinal);
|
||||
std::string neoKey = prefix;
|
||||
neoKey += settingName;
|
||||
envValue = IoFunctions::getenvPtr(neoKey.c_str());
|
||||
if (envValue) {
|
||||
value = atoll(envValue);
|
||||
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<DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
||||
|
||||
char neoFinal[MAX_NEO_KEY_LENGTH];
|
||||
uint32_t i = 0;
|
||||
for (const auto &prefix : prefixString) {
|
||||
strcpy_s(neoFinal, strlen(prefix) + 1, prefix);
|
||||
strcpy_s(neoFinal + strlen(prefix), strlen(settingName) + 1, settingName);
|
||||
envValue = IoFunctions::getenvPtr(neoFinal);
|
||||
std::string neoKey = prefix;
|
||||
neoKey += settingName;
|
||||
envValue = IoFunctions::getenvPtr(neoKey.c_str());
|
||||
if (envValue) {
|
||||
keyValue.assign(envValue);
|
||||
type = prefixType[i];
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
@ -12,8 +12,4 @@ namespace NEO {
|
|||
SettingsReader *SettingsReader::createOsReader(bool userScope, const std::string ®Key) {
|
||||
return new EnvironmentVariableReader;
|
||||
}
|
||||
|
||||
char *SettingsReader::getenv(const char *settingName) {
|
||||
return ::getenv(settingName);
|
||||
}
|
||||
} // namespace NEO
|
||||
|
|
|
@ -21,10 +21,6 @@ SettingsReader *SettingsReader::createOsReader(bool userScope, const std::string
|
|||
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) {
|
||||
hkeyType = userScope ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
|
||||
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<DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
||||
|
||||
char neoFinal[MAX_NEO_KEY_LENGTH];
|
||||
uint32_t i = 0;
|
||||
for (const auto &prefix : prefixString) {
|
||||
strcpy_s(neoFinal, strlen(prefix) + 1, prefix);
|
||||
strcpy_s(neoFinal + strlen(prefix), strlen(settingName) + 1, settingName);
|
||||
envValue = getenv(neoFinal);
|
||||
std::string neoKey = prefix;
|
||||
neoKey += settingName;
|
||||
envValue = IoFunctions::getenvPtr(neoKey.c_str());
|
||||
if (envValue) {
|
||||
value = atoll(envValue);
|
||||
type = prefixType[i];
|
||||
|
@ -121,7 +116,7 @@ int64_t RegistryReader::getSetting(const char *settingName, int64_t defaultValue
|
|||
int64_t value = defaultValue;
|
||||
|
||||
if (!(getSettingIntCommon(settingName, value))) {
|
||||
const char *envValue = getenv(settingName);
|
||||
const char *envValue = IoFunctions::getenvPtr(settingName);
|
||||
if (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<DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
||||
|
||||
char neoFinal[MAX_NEO_KEY_LENGTH];
|
||||
uint32_t i = 0;
|
||||
for (const auto &prefix : prefixString) {
|
||||
strcpy_s(neoFinal, strlen(prefix) + 1, prefix);
|
||||
strcpy_s(neoFinal + strlen(prefix), strlen(settingName) + 1, settingName);
|
||||
envValue = strcmp(processName.c_str(), neoFinal) ? getenv(neoFinal) : getenv("cl_cache_dir");
|
||||
std::string neoKey = prefix;
|
||||
neoKey += settingName;
|
||||
envValue = strcmp(processName.c_str(), neoKey.c_str()) ? IoFunctions::getenvPtr(neoKey.c_str()) : IoFunctions::getenvPtr("cl_cache_dir");
|
||||
if (envValue) {
|
||||
keyValue.assign(envValue);
|
||||
type = prefixType[i];
|
||||
|
@ -220,7 +214,7 @@ std::string RegistryReader::getSetting(const char *settingName, const std::strin
|
|||
std::string keyValue = value;
|
||||
|
||||
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) {
|
||||
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<DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
||||
|
||||
char neoFinal[MAX_NEO_KEY_LENGTH];
|
||||
uint32_t i = 0;
|
||||
for (const auto &prefix : prefixString) {
|
||||
strcpy_s(neoFinal, strlen(prefix) + 1, prefix);
|
||||
strcpy_s(neoFinal + strlen(prefix), strlen(settingName) + 1, settingName);
|
||||
std::map<std::string, std::string>::iterator it = settingStringMap.find(std::string(neoFinal));
|
||||
std::string neoKey = prefix;
|
||||
neoKey += settingName;
|
||||
std::map<std::string, std::string>::iterator it = settingStringMap.find(neoKey);
|
||||
if (it != settingStringMap.end()) {
|
||||
value = strtoll(it->second.c_str(), nullptr, 0);
|
||||
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<DebugVarPrefix> prefixType = ApiSpecificConfig::getPrefixTypes();
|
||||
|
||||
char neoFinal[MAX_NEO_KEY_LENGTH];
|
||||
uint32_t i = 0;
|
||||
for (const auto &prefix : prefixString) {
|
||||
strcpy_s(neoFinal, strlen(prefix) + 1, prefix);
|
||||
strcpy_s(neoFinal + strlen(prefix), strlen(settingName) + 1, settingName);
|
||||
std::map<std::string, std::string>::iterator it = settingStringMap.find(std::string(neoFinal));
|
||||
std::string neoKey = prefix;
|
||||
neoKey += settingName;
|
||||
std::map<std::string, std::string>::iterator it = settingStringMap.find(neoKey);
|
||||
if (it != settingStringMap.end()) {
|
||||
returnValue = it->second;
|
||||
type = prefixType[i];
|
||||
|
|
|
@ -36,6 +36,5 @@ class SettingsReader {
|
|||
virtual const char *appSpecificLocation(const std::string &name) = 0;
|
||||
static const char *settingsFileName;
|
||||
static const char *neoSettingsFileName;
|
||||
MOCKABLE_VIRTUAL char *getenv(const char *settingName);
|
||||
};
|
||||
}; // namespace NEO
|
||||
|
|
|
@ -9,45 +9,41 @@
|
|||
|
||||
#include "shared/source/helpers/api_specific_config.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 {
|
||||
class TestedRegistryReader : public RegistryReader {
|
||||
public:
|
||||
TestedRegistryReader(bool userScope) : RegistryReader(userScope, ApiSpecificConfig::getRegistryPath()){};
|
||||
TestedRegistryReader(std::string regKey) : RegistryReader(false, regKey){};
|
||||
TestedRegistryReader(bool userScope) : RegistryReader(userScope, ApiSpecificConfig::getRegistryPath()) {
|
||||
initEnv();
|
||||
};
|
||||
TestedRegistryReader(std::string regKey) : RegistryReader(false, regKey) {
|
||||
initEnv();
|
||||
};
|
||||
HKEY getHkeyType() const {
|
||||
return hkeyType;
|
||||
}
|
||||
using RegistryReader::getSetting;
|
||||
using RegistryReader::processName;
|
||||
|
||||
char *getenv(const char *envVar) override {
|
||||
if (strcmp(envVar, "TestedEnvironmentVariable") == 0) {
|
||||
return "TestedEnvironmentVariableValue";
|
||||
} else if (strcmp(envVar, "NEO_TestedEnvironmentVariableWithPrefix") == 0) {
|
||||
return "TestedEnvironmentVariableValueWithPrefix";
|
||||
} else if (strcmp(envVar, "TestedEnvironmentIntVariable") == 0) {
|
||||
return "1234";
|
||||
} else if (strcmp(envVar, "NEO_TestedEnvironmentIntVariableWithPrefix") == 0) {
|
||||
return "5678";
|
||||
} else if (strcmp(envVar, "TestedEnvironmentInt64Variable") == 0) {
|
||||
return "9223372036854775807";
|
||||
} else if (strcmp(envVar, "NEO_TestedEnvironmentInt64VariableWithPrefix") == 0) {
|
||||
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;
|
||||
}
|
||||
void initEnv() {
|
||||
|
||||
IoFunctions::mockableEnvValues->insert({"TestedEnvironmentVariable", "TestedEnvironmentVariableValue"});
|
||||
IoFunctions::mockableEnvValues->insert({"NEO_TestedEnvironmentVariableWithPrefix", "TestedEnvironmentVariableValueWithPrefix"});
|
||||
IoFunctions::mockableEnvValues->insert({"TestedEnvironmentIntVariable", "1234"});
|
||||
IoFunctions::mockableEnvValues->insert({"NEO_TestedEnvironmentIntVariableWithPrefix", "5678"});
|
||||
IoFunctions::mockableEnvValues->insert({"TestedEnvironmentInt64Variable", "9223372036854775807"});
|
||||
IoFunctions::mockableEnvValues->insert({"NEO_TestedEnvironmentInt64VariableWithPrefix", "9223372036854775806"});
|
||||
IoFunctions::mockableEnvValues->insert({"settingSourceString", "environment"});
|
||||
IoFunctions::mockableEnvValues->insert({"settingSourceInt", "2"});
|
||||
IoFunctions::mockableEnvValues->insert({"processName", "processName"});
|
||||
IoFunctions::mockableEnvValues->insert({"cl_cache_dir", "./tested_cl_cache_dir"});
|
||||
}
|
||||
const char *getRegKey() const {
|
||||
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
|
||||
|
|
|
@ -114,9 +114,3 @@ TEST(SettingsReader, GivenFalseWhenPrintingDebugStringThenNoOutput) {
|
|||
std::string output = testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.c_str(), "");
|
||||
}
|
||||
|
||||
TEST(SettingsReader, givenNonExistingEnvVarWhenGettingEnvThenNullptrIsReturned) {
|
||||
MockSettingsReader reader;
|
||||
auto value = reader.getenv("ThisEnvVarDoesNotExist");
|
||||
EXPECT_EQ(nullptr, value);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue