mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 14:55:24 +08:00
fix: move pathExists out of sys calls and do not mock it
Moved pathExists from SysCalls to path.h. In ULTs, use unchanged pathExists and mock stat, getFileAttributesA instead. Add Windows and Linux ULTs for pathExists. Signed-off-by: Fabian Zwoliński <fabian.zwolinski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
9bdd7b784a
commit
ea5b586c37
@@ -33,11 +33,6 @@
|
||||
#include <memory>
|
||||
|
||||
using namespace NEO;
|
||||
namespace NEO {
|
||||
namespace SysCalls {
|
||||
extern bool pathExistsMock;
|
||||
} // namespace SysCalls
|
||||
} // namespace NEO
|
||||
|
||||
TEST(HashGeneration, givenMisalignedBufferWhenPassedToUpdateFunctionThenProperPtrDataIsUsed) {
|
||||
Hash hash;
|
||||
@@ -384,27 +379,6 @@ TEST(CompilerCacheTests, GivenNonExistantConfigWhenLoadingFromCacheThenNullIsRet
|
||||
EXPECT_EQ(0U, size);
|
||||
}
|
||||
|
||||
TEST(CompilerCacheTests, GivenPrintDebugMessagesWhenCacheIsEnabledThenMessageWithPathIsPrintedToStdout) {
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.PrintDebugMessages.set(true);
|
||||
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
|
||||
bool pathExistsMock = true;
|
||||
VariableBackup<bool> pathExistsMockBackup(&NEO::SysCalls::pathExistsMock, pathExistsMock);
|
||||
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_DIR"] = "ult\\directory\\";
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
std::string output = testing::internal::GetCapturedStdout();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_STREQ(output.c_str(), "NEO_CACHE_PERSISTENT is enabled. Cache is located in: ult\\directory\\\n\n");
|
||||
}
|
||||
|
||||
TEST(CompilerInterfaceCachedTests, GivenNoCachedBinaryWhenBuildingThenErrorIsReturned) {
|
||||
TranslationInput inputArgs{IGC::CodeType::oclC, IGC::CodeType::oclGenBin};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2023 Intel Corporation
|
||||
* Copyright (C) 2019-2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -779,8 +779,8 @@ TEST(CompilerCacheTests, GivenCompilerCacheWhenAllFunctionsSuccedThenCacheBinary
|
||||
}
|
||||
|
||||
namespace NonExistingPathIsSet {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
return false;
|
||||
int statMock(const std::string &filePath, struct stat *statbuf) noexcept {
|
||||
return -1;
|
||||
}
|
||||
} // namespace NonExistingPathIsSet
|
||||
|
||||
@@ -791,22 +791,27 @@ TEST(CompilerCacheHelper, GivenNonExistingPathWhenCheckDefaultCacheDirSettingsTh
|
||||
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);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statMockBackup(&NEO::SysCalls::sysCallsStat, NonExistingPathIsSet::statMock);
|
||||
|
||||
std::string cacheDir = "";
|
||||
EXPECT_FALSE(checkDefaultCacheDirSettings(cacheDir, envReader));
|
||||
}
|
||||
|
||||
namespace XDGEnvPathIsSet {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("xdg/directory/neo_compiler_cache") != path.npos) {
|
||||
return true;
|
||||
int statMock(const std::string &filePath, struct stat *statbuf) noexcept {
|
||||
if (filePath.find("xdg/directory/neo_compiler_cache") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
if (path.find("xdg/directory/") != path.npos) {
|
||||
return true;
|
||||
|
||||
if (filePath.find("xdg/directory/") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
return false;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
} // namespace XDGEnvPathIsSet
|
||||
|
||||
TEST(CompilerCacheHelper, GivenXdgCachePathSetWhenCheckDefaultCacheDirSettingsThenProperPathIsReturned) {
|
||||
@@ -816,7 +821,7 @@ TEST(CompilerCacheHelper, GivenXdgCachePathSetWhenCheckDefaultCacheDirSettingsTh
|
||||
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);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statMockBackup(&NEO::SysCalls::sysCallsStat, XDGEnvPathIsSet::statMock);
|
||||
|
||||
std::string cacheDir = "";
|
||||
|
||||
@@ -825,14 +830,18 @@ TEST(CompilerCacheHelper, GivenXdgCachePathSetWhenCheckDefaultCacheDirSettingsTh
|
||||
}
|
||||
|
||||
namespace HomeEnvPathIsSet {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("home/directory/.cache/neo_compiler_cache") != path.npos) {
|
||||
return true;
|
||||
int statMock(const std::string &filePath, struct stat *statbuf) noexcept {
|
||||
if (filePath.find("home/directory/.cache/neo_compiler_cache") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
if (path.find("home/directory/.cache/") != path.npos) {
|
||||
return true;
|
||||
|
||||
if (filePath.find("home/directory/.cache/") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
return false;
|
||||
|
||||
return -1;
|
||||
}
|
||||
} // namespace HomeEnvPathIsSet
|
||||
|
||||
@@ -843,7 +852,7 @@ TEST(CompilerCacheHelper, GivenHomeCachePathSetWhenCheckDefaultCacheDirSettingsT
|
||||
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);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statMockBackup(&NEO::SysCalls::sysCallsStat, HomeEnvPathIsSet::statMock);
|
||||
|
||||
std::string cacheDir = "";
|
||||
EXPECT_TRUE(checkDefaultCacheDirSettings(cacheDir, envReader));
|
||||
@@ -853,15 +862,19 @@ TEST(CompilerCacheHelper, GivenHomeCachePathSetWhenCheckDefaultCacheDirSettingsT
|
||||
namespace XdgPathIsSetAndOtherProcessCreatesPath {
|
||||
bool mkdirCalled = false;
|
||||
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("xdg/directory/neo_compiler_cache") != path.npos) {
|
||||
return false;
|
||||
int statMock(const std::string &filePath, struct stat *statbuf) noexcept {
|
||||
if (filePath.find("xdg/directory/neo_compiler_cache") != filePath.npos) {
|
||||
return -1;
|
||||
}
|
||||
if (path.find("xdg/directory/") != path.npos) {
|
||||
return true;
|
||||
|
||||
if (filePath.find("xdg/directory/") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
return false;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mkdirMock(const std::string &dir) {
|
||||
if (dir.find("xdg/directory/neo_compiler_cache") != dir.npos) {
|
||||
mkdirCalled = true;
|
||||
@@ -880,7 +893,7 @@ TEST(CompilerCacheHelper, GivenXdgEnvWhenOtherProcessCreatesNeoCompilerCacheFold
|
||||
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::sysCallsStat)> statMockBackup(&NEO::SysCalls::sysCallsStat, XdgPathIsSetAndOtherProcessCreatesPath::statMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, XdgPathIsSetAndOtherProcessCreatesPath::mkdirMock);
|
||||
VariableBackup<bool> mkdirCalledBackup(&XdgPathIsSetAndOtherProcessCreatesPath::mkdirCalled, mkdirCalledTemp);
|
||||
|
||||
@@ -891,15 +904,19 @@ TEST(CompilerCacheHelper, GivenXdgEnvWhenOtherProcessCreatesNeoCompilerCacheFold
|
||||
}
|
||||
|
||||
namespace XdgPathIsSetAndNeedToCreate {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("xdg/directory/neo_compiler_cache") != path.npos) {
|
||||
return false;
|
||||
int statMock(const std::string &filePath, struct stat *statbuf) noexcept {
|
||||
if (filePath.find("xdg/directory/neo_compiler_cache") != filePath.npos) {
|
||||
return -1;
|
||||
}
|
||||
if (path.find("xdg/directory") != path.npos) {
|
||||
return true;
|
||||
|
||||
if (filePath.find("xdg/directory") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
return false;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mkdirMock(const std::string &dir) {
|
||||
return 0;
|
||||
}
|
||||
@@ -912,7 +929,7 @@ TEST(CompilerCacheHelper, GivenXdgEnvWhenNeoCompilerCacheNotExistsThenCreateNeoC
|
||||
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::sysCallsStat)> statMockBackup(&NEO::SysCalls::sysCallsStat, XdgPathIsSetAndNeedToCreate::statMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, XdgPathIsSetAndNeedToCreate::mkdirMock);
|
||||
|
||||
std::string cacheDir = "";
|
||||
@@ -927,7 +944,7 @@ TEST(CompilerCacheHelper, GivenXdgEnvWithoutTrailingSlashWhenNeoCompilerCacheNot
|
||||
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::sysCallsStat)> statMockBackup(&NEO::SysCalls::sysCallsStat, XdgPathIsSetAndNeedToCreate::statMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, XdgPathIsSetAndNeedToCreate::mkdirMock);
|
||||
|
||||
std::string cacheDir = "";
|
||||
@@ -936,15 +953,19 @@ TEST(CompilerCacheHelper, GivenXdgEnvWithoutTrailingSlashWhenNeoCompilerCacheNot
|
||||
}
|
||||
|
||||
namespace HomePathIsSetAndNeedToCreate {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("home/directory/.cache/neo_compiler_cache") != path.npos) {
|
||||
return false;
|
||||
int statMock(const std::string &filePath, struct stat *statbuf) noexcept {
|
||||
if (filePath.find("home/directory/.cache/neo_compiler_cache") != filePath.npos) {
|
||||
return -1;
|
||||
}
|
||||
if (path.find("home/directory/.cache/") != path.npos) {
|
||||
return true;
|
||||
|
||||
if (filePath.find("home/directory/.cache/") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
return false;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mkdirMock(const std::string &dir) {
|
||||
return 0;
|
||||
}
|
||||
@@ -957,7 +978,7 @@ TEST(CompilerCacheHelper, GivenHomeCachePathSetWithoutTrailingSlashWhenCheckDefa
|
||||
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, HomePathIsSetAndNeedToCreate::pathExistsMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statMockBackup(&NEO::SysCalls::sysCallsStat, HomePathIsSetAndNeedToCreate::statMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, HomePathIsSetAndNeedToCreate::mkdirMock);
|
||||
|
||||
std::string cacheDir = "";
|
||||
@@ -972,7 +993,7 @@ TEST(CompilerCacheHelper, GivenHomeCachePathSetWhenCheckDefaultCacheDirSettingsT
|
||||
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, HomePathIsSetAndNeedToCreate::pathExistsMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statMockBackup(&NEO::SysCalls::sysCallsStat, HomePathIsSetAndNeedToCreate::statMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, HomePathIsSetAndNeedToCreate::mkdirMock);
|
||||
|
||||
std::string cacheDir = "";
|
||||
@@ -983,15 +1004,19 @@ TEST(CompilerCacheHelper, GivenHomeCachePathSetWhenCheckDefaultCacheDirSettingsT
|
||||
namespace HomePathIsSetAndOtherProcessCreatesPath {
|
||||
bool mkdirCalled = false;
|
||||
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("home/directory/.cache/neo_compiler_cache") != path.npos) {
|
||||
return false;
|
||||
int statMock(const std::string &filePath, struct stat *statbuf) noexcept {
|
||||
if (filePath.find("home/directory/.cache/neo_compiler_cache") != filePath.npos) {
|
||||
return -1;
|
||||
}
|
||||
if (path.find("home/directory/.cache/") != path.npos) {
|
||||
return true;
|
||||
|
||||
if (filePath.find("home/directory/.cache/") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
return false;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mkdirMock(const std::string &dir) {
|
||||
if (dir.find("home/directory/.cache/neo_compiler_cache") != dir.npos) {
|
||||
mkdirCalled = true;
|
||||
@@ -1010,7 +1035,7 @@ TEST(CompilerCacheHelper, GivenHomeEnvWhenOtherProcessCreatesNeoCompilerCacheFol
|
||||
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, HomePathIsSetAndOtherProcessCreatesPath::pathExistsMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statMockBackup(&NEO::SysCalls::sysCallsStat, HomePathIsSetAndOtherProcessCreatesPath::statMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, HomePathIsSetAndOtherProcessCreatesPath::mkdirMock);
|
||||
VariableBackup<bool> mkdirCalledBackup(&HomePathIsSetAndOtherProcessCreatesPath::mkdirCalled, mkdirCalledTemp);
|
||||
|
||||
|
||||
@@ -17,16 +17,41 @@
|
||||
|
||||
namespace NEO {
|
||||
|
||||
namespace SysCalls {
|
||||
extern bool pathExistsMock;
|
||||
namespace AllPathsExist {
|
||||
int statMock(const std::string &filePath, struct stat *statbuf) noexcept {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
} // namespace AllPathsExist
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenPrintDebugMessagesWhenCacheIsEnabledThenMessageWithPathIsPrintedToStdout) {
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.PrintDebugMessages.set(true);
|
||||
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, AllPathsExist::statMock);
|
||||
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_DIR"] = "ult\\directory\\";
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
std::string output = testing::internal::GetCapturedStdout();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_STREQ(output.c_str(), "NEO_CACHE_PERSISTENT is enabled. Cache is located in: ult\\directory\\\n\n");
|
||||
}
|
||||
|
||||
namespace AllVariablesCorrectlySet {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("ult/directory/") != path.npos)
|
||||
return true;
|
||||
int statMock(const std::string &filePath, struct stat *statbuf) noexcept {
|
||||
if (filePath.find("ult/directory/") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
} // namespace AllVariablesCorrectlySet
|
||||
|
||||
@@ -37,7 +62,7 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenAllEnvVarWhenProperlySetThenProperConfi
|
||||
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);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, AllVariablesCorrectlySet::statMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
@@ -48,9 +73,10 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenAllEnvVarWhenProperlySetThenProperConfi
|
||||
}
|
||||
|
||||
namespace NonExistingPathIsSet {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
return false;
|
||||
int statMock(const std::string &filePath, struct stat *statbuf) noexcept {
|
||||
return -1;
|
||||
}
|
||||
|
||||
} // namespace NonExistingPathIsSet
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenNonExistingPathWhenGetCompilerCacheConfigThenConfigWithDisabledCacheIsReturned) {
|
||||
@@ -60,7 +86,7 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenNonExistingPathWhenGetCompilerCacheConf
|
||||
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);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, NonExistingPathIsSet::statMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
@@ -69,14 +95,18 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenNonExistingPathWhenGetCompilerCacheConf
|
||||
}
|
||||
|
||||
namespace XDGEnvPathIsSet {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("xdg/directory/neo_compiler_cache") != path.npos) {
|
||||
return true;
|
||||
int statMock(const std::string &filePath, struct stat *statbuf) noexcept {
|
||||
if (filePath.find("xdg/directory/neo_compiler_cache") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
if (path.find("xdg/directory") != path.npos) {
|
||||
return true;
|
||||
|
||||
if (filePath.find("xdg/directory") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
return false;
|
||||
|
||||
return -1;
|
||||
}
|
||||
} // namespace XDGEnvPathIsSet
|
||||
|
||||
@@ -87,7 +117,7 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenXdgCachePathSetWhenGetCompilerCacheConf
|
||||
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);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, XDGEnvPathIsSet::statMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
@@ -104,7 +134,7 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenXdgCachePathWithoutTrailingSlashSetWhen
|
||||
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);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, XDGEnvPathIsSet::statMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
@@ -115,15 +145,20 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenXdgCachePathWithoutTrailingSlashSetWhen
|
||||
}
|
||||
|
||||
namespace HomeEnvPathIsSet {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("home/directory/.cache/neo_compiler_cache") != path.npos) {
|
||||
return true;
|
||||
int statMock(const std::string &filePath, struct stat *statbuf) noexcept {
|
||||
if (filePath.find("home/directory/.cache/neo_compiler_cache") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
if (path.find("home/directory/.cache/") != path.npos) {
|
||||
return true;
|
||||
|
||||
if (filePath.find("home/directory/.cache/") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
return false;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
} // namespace HomeEnvPathIsSet
|
||||
|
||||
TEST(ClCacheDefaultConfigLinuxTest, GivenHomeCachePathSetWhenGetCompilerCacheConfigThenConfigWithEnabledCacheIsReturned) {
|
||||
@@ -133,7 +168,7 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenHomeCachePathSetWhenGetCompilerCacheCon
|
||||
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);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, HomeEnvPathIsSet::statMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
@@ -150,7 +185,7 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenHomeCachePathWithoutTrailingSlashSetWhe
|
||||
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);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, HomeEnvPathIsSet::statMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
@@ -167,7 +202,7 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenCacheMaxSizeSetTo0WhenGetDefaultConfigT
|
||||
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);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, AllVariablesCorrectlySet::statMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
@@ -178,18 +213,27 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenCacheMaxSizeSetTo0WhenGetDefaultConfigT
|
||||
}
|
||||
|
||||
namespace HomeEnvPathIsSetButDotCacheDoesNotExist {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
int statMock(const std::string &filePath, struct stat *statbuf) noexcept {
|
||||
static bool called = false;
|
||||
if (path.find("home/directory/.cache/neo_compiler_cache") != path.npos) {
|
||||
return true;
|
||||
|
||||
if (filePath.find("home/directory/.cache/neo_compiler_cache") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
if (path.find("home/directory/.cache/") != path.npos) {
|
||||
bool result = called;
|
||||
called = true;
|
||||
return result;
|
||||
|
||||
if (filePath.find("home/directory/.cache/") != filePath.npos) {
|
||||
if (!called) {
|
||||
called = true;
|
||||
return -1;
|
||||
}
|
||||
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
return false;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mkdirMock(const std::string &dir) {
|
||||
return 0;
|
||||
}
|
||||
@@ -202,7 +246,7 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenHomeCachePathSetWithoutExistingDotCache
|
||||
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::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, HomeEnvPathIsSetButDotCacheDoesNotExist::statMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, HomeEnvPathIsSetButDotCacheDoesNotExist::mkdirMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
@@ -220,7 +264,7 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenHomeCachePathWithoutExistingDotCacheWit
|
||||
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::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, HomeEnvPathIsSetButDotCacheDoesNotExist::statMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, HomeEnvPathIsSetButDotCacheDoesNotExist::mkdirMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
@@ -232,15 +276,20 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenHomeCachePathWithoutExistingDotCacheWit
|
||||
}
|
||||
|
||||
namespace XdgPathIsSetAndNeedToCreate {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("xdg/directory/neo_compiler_cache") != path.npos) {
|
||||
return false;
|
||||
int statMock(const std::string &filePath, struct stat *statbuf) noexcept {
|
||||
if (filePath.find("xdg/directory/neo_compiler_cache") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
if (path.find("xdg/directory") != path.npos) {
|
||||
return true;
|
||||
|
||||
if (filePath.find("xdg/directory") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
return false;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mkdirMock(const std::string &dir) {
|
||||
return 0;
|
||||
}
|
||||
@@ -253,7 +302,7 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenXdgEnvWhenNeoCompilerCacheNotExistsThen
|
||||
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::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, XdgPathIsSetAndNeedToCreate::statMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, XdgPathIsSetAndNeedToCreate::mkdirMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
@@ -271,7 +320,7 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenXdgEnvWithoutTrailingSlashWhenNeoCompil
|
||||
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::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, XdgPathIsSetAndNeedToCreate::statMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, XdgPathIsSetAndNeedToCreate::mkdirMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
@@ -285,15 +334,19 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenXdgEnvWithoutTrailingSlashWhenNeoCompil
|
||||
namespace XdgPathIsSetAndOtherProcessCreatesPath {
|
||||
bool mkdirCalled = false;
|
||||
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("xdg/directory/neo_compiler_cache") != path.npos) {
|
||||
return false;
|
||||
int statMock(const std::string &filePath, struct stat *statbuf) noexcept {
|
||||
if (filePath.find("xdg/directory/neo_compiler_cache") != filePath.npos) {
|
||||
return -1;
|
||||
}
|
||||
if (path.find("xdg/directory/") != path.npos) {
|
||||
return true;
|
||||
|
||||
if (filePath.find("xdg/directory/") != filePath.npos) {
|
||||
statbuf->st_mode = S_IFDIR;
|
||||
return 0;
|
||||
}
|
||||
return false;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mkdirMock(const std::string &dir) {
|
||||
if (dir.find("xdg/directory/neo_compiler_cache") != dir.npos) {
|
||||
mkdirCalled = true;
|
||||
@@ -312,7 +365,7 @@ TEST(ClCacheDefaultConfigLinuxTest, GivenXdgEnvWhenOtherProcessCreatesNeoCompile
|
||||
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::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, XdgPathIsSetAndOtherProcessCreatesPath::statMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, XdgPathIsSetAndOtherProcessCreatesPath::mkdirMock);
|
||||
VariableBackup<bool> mkdirCalledBackup(&XdgPathIsSetAndOtherProcessCreatesPath::mkdirCalled, mkdirCalledTemp);
|
||||
|
||||
|
||||
@@ -21,16 +21,15 @@ 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[];
|
||||
|
||||
extern DWORD getFileAttributesResult;
|
||||
extern std::unordered_map<std::string, DWORD> pathAttributes;
|
||||
} // namespace SysCalls
|
||||
|
||||
struct ClCacheDefaultConfigWindowsTest : public ::testing::Test {
|
||||
@@ -47,9 +46,7 @@ struct ClCacheDefaultConfigWindowsTest : public ::testing::Test {
|
||||
|
||||
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]);
|
||||
}
|
||||
SysCalls::pathAttributes.clear();
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -67,8 +64,8 @@ TEST_F(ClCacheDefaultConfigWindowsTest, GivenAllEnvVarWhenProperlySetThenCorrect
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["NEO_CACHE_DIR"] = "ult\\directory\\";
|
||||
|
||||
bool pathExistsMock = true;
|
||||
VariableBackup<bool> pathExistsMockBackup(&NEO::SysCalls::pathExistsMock, pathExistsMock);
|
||||
DWORD getFileAttributesResultMock = FILE_ATTRIBUTE_DIRECTORY;
|
||||
VariableBackup<DWORD> pathExistsMockBackup(&NEO::SysCalls::getFileAttributesResult, getFileAttributesResultMock);
|
||||
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
|
||||
@@ -83,8 +80,8 @@ TEST_F(ClCacheDefaultConfigWindowsTest, GivenNonExistingPathWhenGetCompilerCache
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["NEO_CACHE_DIR"] = "ult\\directory\\";
|
||||
|
||||
bool pathExistsMock = false;
|
||||
VariableBackup<bool> pathExistsMockBackup(&NEO::SysCalls::pathExistsMock, pathExistsMock);
|
||||
DWORD getFileAttributesResultMock = INVALID_FILE_ATTRIBUTES;
|
||||
VariableBackup<DWORD> pathExistsMockBackup(&NEO::SysCalls::getFileAttributesResult, getFileAttributesResultMock);
|
||||
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
|
||||
@@ -96,8 +93,8 @@ TEST_F(ClCacheDefaultConfigWindowsTest, GivenLocalAppDataCachePathSetWhenGetComp
|
||||
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::pathAttributes["C:\\Users\\user1\\AppData\\Local\\NEO"] = FILE_ATTRIBUTE_DIRECTORY;
|
||||
SysCalls::pathAttributes["C:\\Users\\user1\\AppData\\Local\\NEO\\neo_compiler_cache"] = FILE_ATTRIBUTE_DIRECTORY;
|
||||
|
||||
SysCalls::shGetKnownFolderPathResult = S_OK;
|
||||
|
||||
@@ -130,7 +127,7 @@ TEST_F(ClCacheDefaultConfigWindowsTest, GivenLocalAppDataSetAndNonExistingNeoDir
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
|
||||
SysCalls::pathExistsPaths[0] = "C:\\Users\\user1\\AppData\\Local\\NEO\\neo_compiler_cache";
|
||||
SysCalls::pathAttributes["C:\\Users\\user1\\AppData\\Local\\NEO\\neo_compiler_cache"] = FILE_ATTRIBUTE_DIRECTORY;
|
||||
SysCalls::shGetKnownFolderPathResult = S_OK;
|
||||
|
||||
const wchar_t *localAppDataPath = L"C:\\Users\\user1\\AppData\\Local";
|
||||
@@ -151,7 +148,7 @@ TEST_F(ClCacheDefaultConfigWindowsTest, GivenLocalAppDataSetAndNonExistingNeoDir
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
|
||||
SysCalls::pathExistsPaths[0] = "C:\\Users\\user1\\AppData\\Local\\NEO\\neo_compiler_cache";
|
||||
SysCalls::pathAttributes["C:\\Users\\user1\\AppData\\Local\\NEO\\neo_compiler_cache"] = FILE_ATTRIBUTE_DIRECTORY;
|
||||
SysCalls::shGetKnownFolderPathResult = S_OK;
|
||||
SysCalls::createDirectoryAResult = FALSE;
|
||||
|
||||
@@ -169,7 +166,7 @@ TEST_F(ClCacheDefaultConfigWindowsTest, GivenLocalAppDataSetAndNonExistingNeoCom
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
|
||||
SysCalls::pathExistsPaths[0] = "C:\\Users\\user1\\AppData\\Local\\NEO";
|
||||
SysCalls::pathAttributes["C:\\Users\\user1\\AppData\\Local\\NEO"] = FILE_ATTRIBUTE_DIRECTORY;
|
||||
|
||||
SysCalls::shGetKnownFolderPathResult = S_OK;
|
||||
|
||||
@@ -191,7 +188,7 @@ TEST_F(ClCacheDefaultConfigWindowsTest, GivenLocalAppDataSetAndNonExistingNeoCom
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
|
||||
SysCalls::pathExistsPaths[0] = "C:\\Users\\user1\\AppData\\Local\\NEO";
|
||||
SysCalls::pathAttributes["C:\\Users\\user1\\AppData\\Local\\NEO"] = FILE_ATTRIBUTE_DIRECTORY;
|
||||
|
||||
SysCalls::shGetKnownFolderPathResult = S_OK;
|
||||
SysCalls::createDirectoryAResult = FALSE;
|
||||
@@ -211,7 +208,7 @@ TEST_F(ClCacheDefaultConfigWindowsTest, GivenLocalAppDataSetWhenGetCompilerCache
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
|
||||
SysCalls::pathExistsPaths[0] = "C:\\Users\\user1\\AppData\\Local\\NEO";
|
||||
SysCalls::pathAttributes["C:\\Users\\user1\\AppData\\Local\\NEO"] = FILE_ATTRIBUTE_DIRECTORY;
|
||||
|
||||
SysCalls::shGetKnownFolderPathResult = S_OK;
|
||||
SysCalls::createDirectoryAResult = FALSE;
|
||||
@@ -236,7 +233,7 @@ TEST_F(ClCacheDefaultConfigWindowsTest, GivenCacheMaxSizeSetTo0WhenGetDefaultCon
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "0";
|
||||
mockableEnvs["NEO_CACHE_DIR"] = "ult\\directory\\";
|
||||
|
||||
SysCalls::pathExistsPaths[0] = "ult\\directory\\";
|
||||
SysCalls::pathAttributes["ult\\directory\\"] = FILE_ATTRIBUTE_DIRECTORY;
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
@@ -247,8 +244,8 @@ TEST_F(ClCacheDefaultConfigWindowsTest, GivenCacheMaxSizeSetTo0WhenGetDefaultCon
|
||||
}
|
||||
|
||||
TEST_F(ClCacheDefaultConfigWindowsTest, GivenCachePathExistsAndNoEnvVarsSetWhenGetDefaultCompilerCacheConfigThenCacheIsEnabled) {
|
||||
bool pathExistsMock = true;
|
||||
VariableBackup<bool> pathExistsMockBackup(&NEO::SysCalls::pathExistsMock, pathExistsMock);
|
||||
DWORD getFileAttributesResultMock = FILE_ATTRIBUTE_DIRECTORY;
|
||||
VariableBackup<DWORD> pathExistsMockBackup(&NEO::SysCalls::getFileAttributesResult, getFileAttributesResultMock);
|
||||
|
||||
SysCalls::shGetKnownFolderPathResult = S_OK;
|
||||
|
||||
@@ -273,4 +270,23 @@ TEST_F(ClCacheDefaultConfigWindowsTest, GivenNeoCachePersistentSetToZeroWhenGetD
|
||||
EXPECT_FALSE(cacheConfig.enabled);
|
||||
}
|
||||
|
||||
TEST_F(ClCacheDefaultConfigWindowsTest, GivenPrintDebugMessagesWhenCacheIsEnabledThenMessageWithPathIsPrintedToStdout) {
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.PrintDebugMessages.set(true);
|
||||
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["NEO_CACHE_DIR"] = "ult\\directory\\";
|
||||
|
||||
DWORD getFileAttributesResultMock = FILE_ATTRIBUTE_DIRECTORY;
|
||||
VariableBackup<DWORD> pathExistsMockBackup(&NEO::SysCalls::getFileAttributesResult, getFileAttributesResultMock);
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
std::string output = testing::internal::GetCapturedStdout();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_STREQ(output.c_str(), "NEO_CACHE_PERSISTENT is enabled. Cache is located in: ult\\directory\\\n\n");
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
Reference in New Issue
Block a user