mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
fix: cl_cache L0 env vars + refactor code structure
Added support for new Compiler Cache environment variables in Level Zero. Moved `opencl/source/compiler_interface/default_cache_config.cpp` `level_zero/core/source/compiler_interface/default_cache_config.cpp` to shared directory `source/compiler_interface/default_cache_config.cpp` Switched enabling cache by default from per OS to per API. Changed default state of cl_cache in Level Zero to disabled. Related-To: NEO-10045 Signed-off-by: Fabian Zwolinski <fabian.zwolinski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
51ae76a25f
commit
52430762ac
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (C) 2019-2023 Intel Corporation
|
||||
# Copyright (C) 2019-2024 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
@@ -17,6 +17,7 @@ set(NEO_CORE_COMPILER_INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}compiler_options_extra.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/compiler_warnings/compiler_warnings.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/create_main.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/default_cache_config.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/default_cache_config.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external_functions.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external_functions.h
|
||||
|
||||
74
shared/source/compiler_interface/default_cache_config.cpp
Normal file
74
shared/source/compiler_interface/default_cache_config.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/compiler_interface/default_cache_config.h"
|
||||
|
||||
#include "shared/source/compiler_interface/os_compiler_cache_helper.h"
|
||||
#include "shared/source/helpers/api_specific_config.h"
|
||||
#include "shared/source/helpers/constants.h"
|
||||
#include "shared/source/os_interface/debug_env_reader.h"
|
||||
#include "shared/source/os_interface/sys_calls_common.h"
|
||||
#include "shared/source/utilities/debug_settings_reader.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
const std::string neoCachePersistent = "NEO_CACHE_PERSISTENT";
|
||||
const std::string neoCacheMaxSize = "NEO_CACHE_MAX_SIZE";
|
||||
const std::string neoCacheDir = "NEO_CACHE_DIR";
|
||||
|
||||
const int64_t neoCacheMaxSizeDefault = static_cast<int64_t>(MemoryConstants::gigaByte);
|
||||
|
||||
CompilerCacheConfig getDefaultCompilerCacheConfig() {
|
||||
CompilerCacheConfig ret;
|
||||
NEO::EnvironmentVariableReader envReader;
|
||||
|
||||
if (envReader.getSetting(neoCachePersistent.c_str(), ApiSpecificConfig::compilerCacheDefaultEnabled()) != 0) {
|
||||
ret.enabled = true;
|
||||
std::string emptyString = "";
|
||||
ret.cacheDir = envReader.getSetting(neoCacheDir.c_str(), emptyString);
|
||||
|
||||
if (ret.cacheDir.empty()) {
|
||||
if (!checkDefaultCacheDirSettings(ret.cacheDir, envReader)) {
|
||||
ret.enabled = false;
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
if (!NEO::SysCalls::pathExists(ret.cacheDir)) {
|
||||
ret.cacheDir = "";
|
||||
ret.enabled = false;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
ret.cacheFileExtension = ApiSpecificConfig::compilerCacheFileExtension();
|
||||
ret.cacheSize = static_cast<size_t>(envReader.getSetting(neoCacheMaxSize.c_str(), neoCacheMaxSizeDefault));
|
||||
|
||||
if (ret.cacheSize == 0u) {
|
||||
ret.cacheSize = std::numeric_limits<size_t>::max();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret.cacheDir = envReader.getSetting(ApiSpecificConfig::compilerCacheDir().c_str(), ApiSpecificConfig::compilerCacheLocation());
|
||||
|
||||
if (NEO::SysCalls::pathExists(ret.cacheDir)) {
|
||||
ret.enabled = true;
|
||||
ret.cacheSize = static_cast<size_t>(neoCacheMaxSizeDefault);
|
||||
ret.cacheFileExtension = ApiSpecificConfig::compilerCacheFileExtension();
|
||||
} else {
|
||||
ret.enabled = false;
|
||||
ret.cacheSize = 0u;
|
||||
ret.cacheFileExtension = ApiSpecificConfig::compilerCacheFileExtension();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
* Copyright (C) 2023-2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -18,10 +18,6 @@
|
||||
#include <link.h>
|
||||
|
||||
namespace NEO {
|
||||
int64_t defaultCacheEnabled() {
|
||||
return 1l;
|
||||
}
|
||||
|
||||
bool createCompilerCachePath(std::string &cacheDir) {
|
||||
if (NEO::SysCalls::pathExists(cacheDir)) {
|
||||
if (NEO::SysCalls::pathExists(joinPath(cacheDir, "neo_compiler_cache"))) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
* Copyright (C) 2023-2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
namespace NEO {
|
||||
class EnvironmentVariableReader;
|
||||
int64_t defaultCacheEnabled();
|
||||
bool checkDefaultCacheDirSettings(std::string &cacheDir, NEO::EnvironmentVariableReader &reader);
|
||||
time_t getFileModificationTime(const std::string &path);
|
||||
size_t getFileSize(const std::string &path);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
* Copyright (C) 2023-2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -15,10 +15,6 @@
|
||||
#include <algorithm>
|
||||
|
||||
namespace NEO {
|
||||
int64_t defaultCacheEnabled() {
|
||||
return 1l;
|
||||
}
|
||||
|
||||
std::string getKnownFolderPath(REFKNOWNFOLDERID rfid) {
|
||||
PWSTR path = nullptr;
|
||||
auto result = SysCalls::shGetKnownFolderPath(rfid, 0, nullptr, &path);
|
||||
|
||||
@@ -35,5 +35,9 @@ struct ApiSpecificConfig {
|
||||
return (getName() + "_");
|
||||
}
|
||||
static bool isSharedAllocPrefetchEnabled();
|
||||
static std::string compilerCacheDir();
|
||||
static std::string compilerCacheLocation();
|
||||
static std::string compilerCacheFileExtension();
|
||||
static int64_t compilerCacheDefaultEnabled();
|
||||
};
|
||||
} // namespace NEO
|
||||
|
||||
@@ -78,4 +78,20 @@ const StackVec<DebugVarPrefix, 4> &ApiSpecificConfig::getPrefixTypes() {
|
||||
}
|
||||
}
|
||||
|
||||
std::string ApiSpecificConfig::compilerCacheDir() {
|
||||
return "cl_cache_dir";
|
||||
}
|
||||
|
||||
std::string ApiSpecificConfig::compilerCacheLocation() {
|
||||
return "cl_cache";
|
||||
}
|
||||
|
||||
std::string ApiSpecificConfig::compilerCacheFileExtension() {
|
||||
return ".cl_cache";
|
||||
}
|
||||
|
||||
int64_t ApiSpecificConfig::compilerCacheDefaultEnabled() {
|
||||
return 1l;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (C) 2019-2023 Intel Corporation
|
||||
# Copyright (C) 2019-2024 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
@@ -17,9 +17,11 @@ target_sources(neo_shared_tests PRIVATE
|
||||
if(WIN32)
|
||||
target_sources(neo_shared_tests PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/windows/compiler_cache_tests_windows.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/windows/default_cl_cache_config_tests.cpp
|
||||
)
|
||||
else()
|
||||
target_sources(neo_shared_tests PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/linux/compiler_cache_tests_linux.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/linux/default_cl_cache_config_tests.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,368 @@
|
||||
/*
|
||||
* Copyright (C) 2023-2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/compiler_interface/default_cache_config.h"
|
||||
#include "shared/source/helpers/api_specific_config.h"
|
||||
#include "shared/source/os_interface/sys_calls_common.h"
|
||||
#include "shared/source/utilities/io_functions.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/helpers/variable_backup.h"
|
||||
#include "shared/test/common/mocks/mock_io_functions.h"
|
||||
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
|
||||
#include "shared/test/common/test_macros/test.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
namespace SysCalls {
|
||||
extern bool pathExistsMock;
|
||||
}
|
||||
|
||||
namespace LegacyPathWorksIfNewEnvIsSetToDisabled {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find(ApiSpecificConfig::compilerCacheLocation().c_str()) != path.npos)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
} // namespace LegacyPathWorksIfNewEnvIsSetToDisabled
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenDefaultClCacheConfigWithPathExistsAndNewEnvSetToDisabledThenValuesAreProperlyPopulated) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "0";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, LegacyPathWorksIfNewEnvIsSetToDisabled::pathExistsMock);
|
||||
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
EXPECT_STREQ(ApiSpecificConfig::compilerCacheLocation().c_str(), cacheConfig.cacheDir.c_str());
|
||||
EXPECT_STREQ(ApiSpecificConfig::compilerCacheFileExtension().c_str(), cacheConfig.cacheFileExtension.c_str());
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
}
|
||||
|
||||
namespace NewEnvIsDisabledAndLegacyPathDoesNotExist {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
return false;
|
||||
}
|
||||
} // namespace NewEnvIsDisabledAndLegacyPathDoesNotExist
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenDefaultClCacheConfigWithNotExistingPathAndNewEnvSetToDisabledThenValuesAreProperlyPopulated) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "0";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, NewEnvIsDisabledAndLegacyPathDoesNotExist::pathExistsMock);
|
||||
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
EXPECT_STREQ(ApiSpecificConfig::compilerCacheLocation().c_str(), cacheConfig.cacheDir.c_str());
|
||||
EXPECT_STREQ(ApiSpecificConfig::compilerCacheFileExtension().c_str(), cacheConfig.cacheFileExtension.c_str());
|
||||
EXPECT_FALSE(cacheConfig.enabled);
|
||||
}
|
||||
|
||||
namespace AllVariablesCorrectlySet {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("ult/directory/") != path.npos)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
} // namespace AllVariablesCorrectlySet
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenAllEnvVarWhenProperlySetThenProperConfigIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["NEO_CACHE_DIR"] = "ult/directory/";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, AllVariablesCorrectlySet::pathExistsMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "ult/directory/");
|
||||
}
|
||||
|
||||
namespace NonExistingPathIsSet {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
return false;
|
||||
}
|
||||
} // namespace NonExistingPathIsSet
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenNonExistingPathWhenGetCompilerCacheConfigThenConfigWithDisabledCacheIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["NEO_CACHE_DIR"] = "ult/directory/";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, NonExistingPathIsSet::pathExistsMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_FALSE(cacheConfig.enabled);
|
||||
EXPECT_TRUE(cacheConfig.cacheDir.empty());
|
||||
}
|
||||
|
||||
namespace XDGEnvPathIsSet {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("xdg/directory/neo_compiler_cache") != path.npos) {
|
||||
return true;
|
||||
}
|
||||
if (path.find("xdg/directory") != path.npos) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace XDGEnvPathIsSet
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenXdgCachePathSetWhenGetCompilerCacheConfigThenConfigWithEnabledCacheIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["XDG_CACHE_HOME"] = "xdg/directory/";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, XDGEnvPathIsSet::pathExistsMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "xdg/directory/neo_compiler_cache");
|
||||
}
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenXdgCachePathWithoutTrailingSlashSetWhenGetCompilerCacheConfigThenConfigWithEnabledCacheIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["XDG_CACHE_HOME"] = "xdg/directory";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, XDGEnvPathIsSet::pathExistsMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "xdg/directory/neo_compiler_cache");
|
||||
}
|
||||
|
||||
namespace HomeEnvPathIsSet {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("home/directory/.cache/neo_compiler_cache") != path.npos) {
|
||||
return true;
|
||||
}
|
||||
if (path.find("home/directory/.cache/") != path.npos) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace HomeEnvPathIsSet
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenHomeCachePathSetWhenGetCompilerCacheConfigThenConfigWithEnabledCacheIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["HOME"] = "home/directory/";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, HomeEnvPathIsSet::pathExistsMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "home/directory/.cache/neo_compiler_cache");
|
||||
}
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenHomeCachePathWithoutTrailingSlashSetWhenGetCompilerCacheConfigThenConfigWithEnabledCacheIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["HOME"] = "home/directory";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, HomeEnvPathIsSet::pathExistsMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "home/directory/.cache/neo_compiler_cache");
|
||||
}
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenCacheMaxSizeSetTo0WhenGetDefaultConfigThenCacheSizeIsSetToMaxSize) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "0";
|
||||
mockableEnvs["NEO_CACHE_DIR"] = "ult/directory/";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, AllVariablesCorrectlySet::pathExistsMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, std::numeric_limits<size_t>::max());
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "ult/directory/");
|
||||
}
|
||||
|
||||
namespace HomeEnvPathIsSetButDotCacheDoesNotExist {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
static bool called = false;
|
||||
if (path.find("home/directory/.cache/neo_compiler_cache") != path.npos) {
|
||||
return true;
|
||||
}
|
||||
if (path.find("home/directory/.cache/") != path.npos) {
|
||||
bool result = called;
|
||||
called = true;
|
||||
return result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int mkdirMock(const std::string &dir) {
|
||||
return 0;
|
||||
}
|
||||
} // namespace HomeEnvPathIsSetButDotCacheDoesNotExist
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenHomeCachePathSetWithoutExistingDotCacheWhenGetCompilerCacheConfigThenConfigWithEnabledCacheIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["HOME"] = "home/directory/";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, HomeEnvPathIsSetButDotCacheDoesNotExist::pathExistsMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, HomeEnvPathIsSetButDotCacheDoesNotExist::mkdirMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "home/directory/.cache/neo_compiler_cache");
|
||||
}
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenHomeCachePathWithoutExistingDotCacheWithoutTrailingSlashSetWhenGetCompilerCacheConfigThenConfigWithEnabledCacheIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["HOME"] = "home/directory";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, HomeEnvPathIsSetButDotCacheDoesNotExist::pathExistsMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, HomeEnvPathIsSetButDotCacheDoesNotExist::mkdirMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "home/directory/.cache/neo_compiler_cache");
|
||||
}
|
||||
|
||||
namespace XdgPathIsSetAndNeedToCreate {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("xdg/directory/neo_compiler_cache") != path.npos) {
|
||||
return false;
|
||||
}
|
||||
if (path.find("xdg/directory") != path.npos) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int mkdirMock(const std::string &dir) {
|
||||
return 0;
|
||||
}
|
||||
} // namespace XdgPathIsSetAndNeedToCreate
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenXdgEnvWhenNeoCompilerCacheNotExistsThenCreateNeoCompilerCacheFolder) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["XDG_CACHE_HOME"] = "xdg/directory/";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, XdgPathIsSetAndNeedToCreate::pathExistsMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, XdgPathIsSetAndNeedToCreate::mkdirMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "xdg/directory/neo_compiler_cache");
|
||||
}
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenXdgEnvWithoutTrailingSlashWhenNeoCompilerCacheNotExistsThenCreateNeoCompilerCacheFolder) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["XDG_CACHE_HOME"] = "xdg/directory";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, XdgPathIsSetAndNeedToCreate::pathExistsMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, XdgPathIsSetAndNeedToCreate::mkdirMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "xdg/directory/neo_compiler_cache");
|
||||
}
|
||||
|
||||
namespace XdgPathIsSetAndOtherProcessCreatesPath {
|
||||
bool mkdirCalled = false;
|
||||
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("xdg/directory/neo_compiler_cache") != path.npos) {
|
||||
return false;
|
||||
}
|
||||
if (path.find("xdg/directory/") != path.npos) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int mkdirMock(const std::string &dir) {
|
||||
if (dir.find("xdg/directory/neo_compiler_cache") != dir.npos) {
|
||||
mkdirCalled = true;
|
||||
errno = EEXIST;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} // namespace XdgPathIsSetAndOtherProcessCreatesPath
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenXdgEnvWhenOtherProcessCreatesNeoCompilerCacheFolderThenProperConfigIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["XDG_CACHE_HOME"] = "xdg/directory/";
|
||||
bool mkdirCalledTemp = false;
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, XdgPathIsSetAndOtherProcessCreatesPath::pathExistsMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, XdgPathIsSetAndOtherProcessCreatesPath::mkdirMock);
|
||||
VariableBackup<bool> mkdirCalledBackup(&XdgPathIsSetAndOtherProcessCreatesPath::mkdirCalled, mkdirCalledTemp);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "xdg/directory/neo_compiler_cache");
|
||||
EXPECT_TRUE(XdgPathIsSetAndOtherProcessCreatesPath::mkdirCalled);
|
||||
}
|
||||
} // namespace NEO
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2023 Intel Corporation
|
||||
* Copyright (C) 2019-2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -986,10 +986,6 @@ TEST_F(CompilerCacheWindowsTest, givenCacheBinaryWhenRenameTempFileBinaryToPrope
|
||||
EXPECT_EQ(0u, SysCalls::writeFileCalled);
|
||||
}
|
||||
|
||||
TEST(CompilerCacheHelperWindowsTest, whenDefaultCacheEnabledIsCalledThenReturnCorrectValue) {
|
||||
EXPECT_EQ(1l, NEO::defaultCacheEnabled());
|
||||
}
|
||||
|
||||
TEST(CompilerCacheHelperWindowsTest, givenFindFirstFileASuccessWhenGetFileModificationTimeThenFindCloseIsCalled) {
|
||||
VariableBackup<HANDLE> findFirstFileAResultBackup(&SysCalls::findFirstFileAResult, reinterpret_cast<HANDLE>(0x1234));
|
||||
VariableBackup<size_t> findCloseCalledBackup(&SysCalls::findCloseCalled, 0u);
|
||||
|
||||
@@ -0,0 +1,292 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/compiler_interface/default_cache_config.h"
|
||||
#include "shared/source/helpers/api_specific_config.h"
|
||||
#include "shared/source/helpers/constants.h"
|
||||
#include "shared/source/os_interface/sys_calls_common.h"
|
||||
#include "shared/source/os_interface/windows/sys_calls.h"
|
||||
#include "shared/source/utilities/debug_settings_reader.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/helpers/variable_backup.h"
|
||||
#include "shared/test/common/mocks/mock_io_functions.h"
|
||||
#include "shared/test/common/test_macros/test.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
namespace SysCalls {
|
||||
extern DWORD getLastErrorResult;
|
||||
|
||||
extern bool pathExistsMock;
|
||||
extern const size_t pathExistsPathsSize;
|
||||
extern std::string pathExistsPaths[];
|
||||
|
||||
extern size_t createDirectoryACalled;
|
||||
extern BOOL createDirectoryAResult;
|
||||
|
||||
extern HRESULT shGetKnownFolderPathResult;
|
||||
extern const size_t shGetKnownFolderSetPathSize;
|
||||
extern wchar_t shGetKnownFolderSetPath[];
|
||||
} // namespace SysCalls
|
||||
|
||||
struct ClCacheDefaultConfigWindowsTest : public ::testing::Test {
|
||||
ClCacheDefaultConfigWindowsTest()
|
||||
: mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs),
|
||||
getLastErrorResultBackup(&SysCalls::getLastErrorResult),
|
||||
shGetKnownFolderPathResultBackup(&SysCalls::shGetKnownFolderPathResult),
|
||||
createDirectoryACalledBackup(&SysCalls::createDirectoryACalled),
|
||||
createDirectoryAResultBackup(&SysCalls::createDirectoryAResult) {}
|
||||
|
||||
void SetUp() override {
|
||||
SysCalls::createDirectoryACalled = 0u;
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
std::wmemset(SysCalls::shGetKnownFolderSetPath, 0, SysCalls::shGetKnownFolderSetPathSize);
|
||||
for (size_t i = 0; i < SysCalls::pathExistsPathsSize; i++) {
|
||||
std::string().swap(SysCalls::pathExistsPaths[i]);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup;
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
|
||||
VariableBackup<DWORD> getLastErrorResultBackup;
|
||||
VariableBackup<HRESULT> shGetKnownFolderPathResultBackup;
|
||||
VariableBackup<size_t> createDirectoryACalledBackup;
|
||||
VariableBackup<BOOL> createDirectoryAResultBackup;
|
||||
};
|
||||
|
||||
TEST_F(ClCacheDefaultConfigWindowsTest, GivenDefaultClCacheConfigWithPathExistsThenValuesAreProperlyPopulated) {
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "0";
|
||||
|
||||
bool pathExistsMock = true;
|
||||
VariableBackup<bool> pathExistsMockBackup(&NEO::SysCalls::pathExistsMock, pathExistsMock);
|
||||
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
EXPECT_STREQ(ApiSpecificConfig::compilerCacheLocation().c_str(), cacheConfig.cacheDir.c_str());
|
||||
EXPECT_STREQ(ApiSpecificConfig::compilerCacheFileExtension().c_str(), cacheConfig.cacheFileExtension.c_str());
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
}
|
||||
|
||||
TEST_F(ClCacheDefaultConfigWindowsTest, GivenDefaultClCacheConfigWithNonExistingPathThenValuesAreProperlyPopulated) {
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "0";
|
||||
|
||||
bool pathExistsMock = false;
|
||||
VariableBackup<bool> pathExistsMockBackup(&NEO::SysCalls::pathExistsMock, pathExistsMock);
|
||||
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
EXPECT_STREQ(ApiSpecificConfig::compilerCacheLocation().c_str(), cacheConfig.cacheDir.c_str());
|
||||
EXPECT_STREQ(ApiSpecificConfig::compilerCacheFileExtension().c_str(), cacheConfig.cacheFileExtension.c_str());
|
||||
EXPECT_FALSE(cacheConfig.enabled);
|
||||
}
|
||||
|
||||
TEST_F(ClCacheDefaultConfigWindowsTest, GivenAllEnvVarWhenProperlySetThenCorrectConfigIsReturned) {
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["NEO_CACHE_DIR"] = "ult\\directory\\";
|
||||
|
||||
bool pathExistsMock = true;
|
||||
VariableBackup<bool> pathExistsMockBackup(&NEO::SysCalls::pathExistsMock, pathExistsMock);
|
||||
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "ult\\directory\\");
|
||||
}
|
||||
|
||||
TEST_F(ClCacheDefaultConfigWindowsTest, GivenNonExistingPathWhenGetCompilerCacheConfigThenConfigWithDisabledCacheIsReturned) {
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["NEO_CACHE_DIR"] = "ult\\directory\\";
|
||||
|
||||
bool pathExistsMock = false;
|
||||
VariableBackup<bool> pathExistsMockBackup(&NEO::SysCalls::pathExistsMock, pathExistsMock);
|
||||
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_FALSE(cacheConfig.enabled);
|
||||
EXPECT_TRUE(cacheConfig.cacheDir.empty());
|
||||
}
|
||||
|
||||
TEST_F(ClCacheDefaultConfigWindowsTest, GivenLocalAppDataCachePathSetWhenGetCompilerCacheConfigThenConfigWithEnabledCacheIsReturned) {
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
|
||||
SysCalls::pathExistsPaths[0] = "C:\\Users\\user1\\AppData\\Local\\NEO";
|
||||
SysCalls::pathExistsPaths[1] = "C:\\Users\\user1\\AppData\\Local\\NEO\\neo_compiler_cache";
|
||||
|
||||
SysCalls::shGetKnownFolderPathResult = S_OK;
|
||||
|
||||
const wchar_t *localAppDataPath = L"C:\\Users\\user1\\AppData\\Local";
|
||||
wcscpy(SysCalls::shGetKnownFolderSetPath, localAppDataPath);
|
||||
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
|
||||
const std::string expectedCacheDirPath = "C:\\Users\\user1\\AppData\\Local\\NEO\\neo_compiler_cache";
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, expectedCacheDirPath);
|
||||
}
|
||||
|
||||
TEST_F(ClCacheDefaultConfigWindowsTest, GivenNeoCacheDirNotSetAndLocalAppDataCachePathNotSetWhenGetCompilerCacheConfigThenConfigWithDisabledCacheIsReturned) {
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
|
||||
SysCalls::shGetKnownFolderPathResult = S_FALSE;
|
||||
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_FALSE(cacheConfig.enabled);
|
||||
EXPECT_TRUE(cacheConfig.cacheDir.empty());
|
||||
}
|
||||
|
||||
TEST_F(ClCacheDefaultConfigWindowsTest, GivenLocalAppDataSetAndNonExistingNeoDirectoryWhenGetCompilerCacheConfigThenNeoDirectoryIsCreatedAndConfigWithEnabledCacheIsReturned) {
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
|
||||
SysCalls::pathExistsPaths[0] = "C:\\Users\\user1\\AppData\\Local\\NEO\\neo_compiler_cache";
|
||||
SysCalls::shGetKnownFolderPathResult = S_OK;
|
||||
|
||||
const wchar_t *localAppDataPath = L"C:\\Users\\user1\\AppData\\Local";
|
||||
wcscpy(SysCalls::shGetKnownFolderSetPath, localAppDataPath);
|
||||
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
|
||||
const std::string expectedCacheDirPath = "C:\\Users\\user1\\AppData\\Local\\NEO\\neo_compiler_cache";
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, expectedCacheDirPath);
|
||||
EXPECT_EQ(1u, SysCalls::createDirectoryACalled);
|
||||
}
|
||||
|
||||
TEST_F(ClCacheDefaultConfigWindowsTest, GivenLocalAppDataSetAndNonExistingNeoDirectoryWhenGetCompilerCacheConfigAndNeoDirCreationFailsThenConfigWithDisabledCacheIsReturned) {
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
|
||||
SysCalls::pathExistsPaths[0] = "C:\\Users\\user1\\AppData\\Local\\NEO\\neo_compiler_cache";
|
||||
SysCalls::shGetKnownFolderPathResult = S_OK;
|
||||
SysCalls::createDirectoryAResult = FALSE;
|
||||
|
||||
const wchar_t *localAppDataPath = L"C:\\Users\\user1\\AppData\\Local";
|
||||
wcscpy(SysCalls::shGetKnownFolderSetPath, localAppDataPath);
|
||||
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_FALSE(cacheConfig.enabled);
|
||||
EXPECT_TRUE(cacheConfig.cacheDir.empty());
|
||||
EXPECT_EQ(1u, SysCalls::createDirectoryACalled);
|
||||
}
|
||||
|
||||
TEST_F(ClCacheDefaultConfigWindowsTest, GivenLocalAppDataSetAndNonExistingNeoCompilerCacheDirectoryWhenGetCompilerCacheConfigThenNeoCompilerCacheDirectoryIsCreatedAndConfigWithEnabledCacheIsReturned) {
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
|
||||
SysCalls::pathExistsPaths[0] = "C:\\Users\\user1\\AppData\\Local\\NEO";
|
||||
|
||||
SysCalls::shGetKnownFolderPathResult = S_OK;
|
||||
|
||||
const wchar_t *localAppDataPath = L"C:\\Users\\user1\\AppData\\Local";
|
||||
wcscpy(SysCalls::shGetKnownFolderSetPath, localAppDataPath);
|
||||
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
|
||||
const std::string expectedCacheDirPath = "C:\\Users\\user1\\AppData\\Local\\NEO\\neo_compiler_cache";
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, expectedCacheDirPath);
|
||||
EXPECT_EQ(1u, SysCalls::createDirectoryACalled);
|
||||
}
|
||||
|
||||
TEST_F(ClCacheDefaultConfigWindowsTest, GivenLocalAppDataSetAndNonExistingNeoCompilerCacheDirectoryWhenGetCompilerCacheConfigAndDirectoryCreationFailsThenConfigWithDisabledCacheIsReturned) {
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
|
||||
SysCalls::pathExistsPaths[0] = "C:\\Users\\user1\\AppData\\Local\\NEO";
|
||||
|
||||
SysCalls::shGetKnownFolderPathResult = S_OK;
|
||||
SysCalls::createDirectoryAResult = FALSE;
|
||||
SysCalls::getLastErrorResult = ERROR_ALREADY_EXISTS + 1;
|
||||
|
||||
const wchar_t *localAppDataPath = L"C:\\Users\\user1\\AppData\\Local";
|
||||
wcscpy(SysCalls::shGetKnownFolderSetPath, localAppDataPath);
|
||||
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_FALSE(cacheConfig.enabled);
|
||||
EXPECT_TRUE(cacheConfig.cacheDir.empty());
|
||||
EXPECT_EQ(1u, SysCalls::createDirectoryACalled);
|
||||
}
|
||||
|
||||
TEST_F(ClCacheDefaultConfigWindowsTest, GivenLocalAppDataSetWhenGetCompilerCacheConfigAndNeoCompilerCacheDirectoryAlreadyExistsThenConfigWithEnabledCacheIsReturned) {
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
|
||||
SysCalls::pathExistsPaths[0] = "C:\\Users\\user1\\AppData\\Local\\NEO";
|
||||
|
||||
SysCalls::shGetKnownFolderPathResult = S_OK;
|
||||
SysCalls::createDirectoryAResult = FALSE;
|
||||
SysCalls::getLastErrorResult = ERROR_ALREADY_EXISTS;
|
||||
|
||||
const wchar_t *localAppDataPath = L"C:\\Users\\user1\\AppData\\Local";
|
||||
wcscpy(SysCalls::shGetKnownFolderSetPath, localAppDataPath);
|
||||
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
|
||||
const std::string expectedCacheDirPath = "C:\\Users\\user1\\AppData\\Local\\NEO\\neo_compiler_cache";
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, expectedCacheDirPath);
|
||||
EXPECT_EQ(1u, SysCalls::createDirectoryACalled);
|
||||
}
|
||||
|
||||
TEST_F(ClCacheDefaultConfigWindowsTest, GivenCacheMaxSizeSetTo0WhenGetDefaultConfigThenCacheSizeIsSetToMaxSize) {
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "0";
|
||||
mockableEnvs["NEO_CACHE_DIR"] = "ult\\directory\\";
|
||||
|
||||
SysCalls::pathExistsPaths[0] = "ult\\directory\\";
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, std::numeric_limits<size_t>::max());
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "ult\\directory\\");
|
||||
}
|
||||
|
||||
TEST_F(ClCacheDefaultConfigWindowsTest, GivenCachePathExistsAndNoEnvVarsSetWhenGetDefaultCompilerCacheConfigThenCacheIsEnabled) {
|
||||
bool pathExistsMock = true;
|
||||
VariableBackup<bool> pathExistsMockBackup(&NEO::SysCalls::pathExistsMock, pathExistsMock);
|
||||
|
||||
SysCalls::shGetKnownFolderPathResult = S_OK;
|
||||
|
||||
const wchar_t *localAppDataPath = L"C:\\Users\\user1\\AppData\\Local";
|
||||
wcscpy(SysCalls::shGetKnownFolderSetPath, localAppDataPath);
|
||||
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
|
||||
const std::string expectedCacheDirPath = "C:\\Users\\user1\\AppData\\Local\\NEO\\neo_compiler_cache";
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ApiSpecificConfig::compilerCacheFileExtension().c_str());
|
||||
EXPECT_EQ(cacheConfig.cacheSize, static_cast<size_t>(MemoryConstants::gigaByte));
|
||||
EXPECT_EQ(cacheConfig.cacheDir, expectedCacheDirPath);
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2023 Intel Corporation
|
||||
* Copyright (C) 2021-2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -35,7 +35,6 @@ void PageFaultManager::transferToGpu(void *ptr, void *cmdQ) {
|
||||
}
|
||||
void PageFaultManager::allowCPUMemoryEviction(void *ptr, PageFaultData &pageFaultData) {
|
||||
}
|
||||
CompilerCacheConfig getDefaultCompilerCacheConfig() { return {}; }
|
||||
const char *getAdditionalBuiltinAsString(EBuiltInOps::Type builtin) { return nullptr; }
|
||||
|
||||
void RootDeviceEnvironment::initApiGfxCoreHelper() {
|
||||
|
||||
Reference in New Issue
Block a user