mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-10 12:53:42 +08:00
Fix read of 64bit enviroment variables
change atoi to atoll Signed-off-by: Cencelewska, Katarzyna <katarzyna.cencelewska@intel.com>
This commit is contained in:

committed by
Compute-Runtime-Automation

parent
69c9a4e86c
commit
9b19014cf1
@ -70,6 +70,14 @@ TEST_F(RegistryReaderTest, givenRegistryReaderWhenEnvironmentIntVariableExistsTh
|
|||||||
EXPECT_EQ(1234, registryReader.getSetting(envVar, value));
|
EXPECT_EQ(1234, registryReader.getSetting(envVar, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RegistryReaderTest, givenRegistryReaderWhenEnvironmentInt64VariableExistsThenReturnCorrectValue) {
|
||||||
|
const char *envVar = "TestedEnvironmentInt64Variable";
|
||||||
|
int64_t expectedValue = 9223372036854775807;
|
||||||
|
int64_t defaultValue = 0;
|
||||||
|
TestedRegistryReader registryReader("");
|
||||||
|
EXPECT_EQ(expectedValue, registryReader.getSetting(envVar, defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
struct DebugReaderWithRegistryAndEnvTest : ::testing::Test {
|
struct DebugReaderWithRegistryAndEnvTest : ::testing::Test {
|
||||||
VariableBackup<uint32_t> openRegCountBackup{&SysCalls::regOpenKeySuccessCount};
|
VariableBackup<uint32_t> openRegCountBackup{&SysCalls::regOpenKeySuccessCount};
|
||||||
VariableBackup<uint32_t> queryRegCountBackup{&SysCalls::regQueryValueSuccessCount};
|
VariableBackup<uint32_t> queryRegCountBackup{&SysCalls::regQueryValueSuccessCount};
|
||||||
|
@ -27,6 +27,8 @@ class TestedRegistryReader : public RegistryReader {
|
|||||||
return "TestedEnvironmentVariableValue";
|
return "TestedEnvironmentVariableValue";
|
||||||
} else if (strcmp(envVar, "TestedEnvironmentIntVariable") == 0) {
|
} else if (strcmp(envVar, "TestedEnvironmentIntVariable") == 0) {
|
||||||
return "1234";
|
return "1234";
|
||||||
|
} else if (strcmp(envVar, "TestedEnvironmentInt64Variable") == 0) {
|
||||||
|
return "9223372036854775807";
|
||||||
} else if (strcmp(envVar, "settingSourceString") == 0) {
|
} else if (strcmp(envVar, "settingSourceString") == 0) {
|
||||||
return "environment";
|
return "environment";
|
||||||
} else if (strcmp(envVar, "settingSourceInt") == 0) {
|
} else if (strcmp(envVar, "settingSourceInt") == 0) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2020-2021 Intel Corporation
|
* Copyright (C) 2020-2022 Intel Corporation
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
@ -29,7 +29,7 @@ int64_t EnvironmentVariableReader::getSetting(const char *settingName, int64_t d
|
|||||||
|
|
||||||
envValue = IoFunctions::getenvPtr(settingName);
|
envValue = IoFunctions::getenvPtr(settingName);
|
||||||
if (envValue) {
|
if (envValue) {
|
||||||
value = atoi(envValue);
|
value = atoll(envValue);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018-2021 Intel Corporation
|
* Copyright (C) 2018-2022 Intel Corporation
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
@ -82,7 +82,7 @@ int64_t RegistryReader::getSetting(const char *settingName, int64_t defaultValue
|
|||||||
if (readSettingFromEnv) {
|
if (readSettingFromEnv) {
|
||||||
const char *envValue = getenv(settingName);
|
const char *envValue = getenv(settingName);
|
||||||
if (envValue) {
|
if (envValue) {
|
||||||
value = atoi(envValue);
|
value = atoll(envValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +65,20 @@ TEST_F(DebugEnvReaderTests, GivenSetVariableThenSetValueIsReturned) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(DebugEnvReaderTests, givenMaxInt64AsEnvWhenGetSettingThenProperValueIsReturned) {
|
||||||
|
const char *testingVariableName = "TestingVariable";
|
||||||
|
const char *testingVariableValue = "9223372036854775807";
|
||||||
|
int64_t expectedValue = 9223372036854775807;
|
||||||
|
int64_t defaultValue = 0;
|
||||||
|
|
||||||
|
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
|
||||||
|
std::unordered_map<std::string, std::string> mockableEnvs = {{testingVariableName, testingVariableValue}};
|
||||||
|
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||||
|
|
||||||
|
EXPECT_EQ(expectedValue, evr->getSetting(testingVariableName, defaultValue));
|
||||||
|
EXPECT_EQ(1u, IoFunctions::mockGetenvCalled);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(DebugEnvReaderTests, GivenUnsetVariableThenDefaultValueIsReturned) {
|
TEST_F(DebugEnvReaderTests, GivenUnsetVariableThenDefaultValueIsReturned) {
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
std::string retString;
|
std::string retString;
|
||||||
|
Reference in New Issue
Block a user