mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 23:03:02 +08:00
fix: compiler cache file extension and path creation
* When env variables did not have trailing slash, directory creation could fail. * If .cache in $HOME did not exist cache would have been disabled. Signed-off-by: Kacper Kasper <kacper.k.kasper@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
f1fc273cfc
commit
ba4867c3d0
@@ -712,7 +712,7 @@ 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) {
|
||||
if (path.find("xdg/directory") != path.npos) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -736,6 +736,20 @@ TEST(CompilerCacheHelper, GivenXdgEnvWhenNeoCompilerCacheNotExistsThenCreateNeoC
|
||||
EXPECT_EQ(cacheDir, "xdg/directory/neo_compiler_cache");
|
||||
}
|
||||
|
||||
TEST(CompilerCacheHelper, GivenXdgEnvWithoutTrailingSlashWhenNeoCompilerCacheNotExistsThenCreateNeoCompilerCacheFolder) {
|
||||
std::unique_ptr<SettingsReader> settingsReader(SettingsReader::createOsReader(false, ""));
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
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);
|
||||
|
||||
std::string cacheDir = "";
|
||||
EXPECT_TRUE(checkDefaultCacheDirSettings(cacheDir, settingsReader.get()));
|
||||
EXPECT_EQ(cacheDir, "xdg/directory/neo_compiler_cache");
|
||||
}
|
||||
|
||||
namespace HomePathIsSetAndNeedToCreate {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("home/directory/.cache/neo_compiler_cache") != path.npos) {
|
||||
@@ -751,6 +765,21 @@ int mkdirMock(const std::string &dir) {
|
||||
}
|
||||
} // namespace HomePathIsSetAndNeedToCreate
|
||||
|
||||
TEST(CompilerCacheHelper, GivenHomeCachePathSetWithoutTrailingSlashWhenCheckDefaultCacheDirSettingsThenProperDirectoryIsCreated) {
|
||||
std::unique_ptr<SettingsReader> settingsReader(SettingsReader::createOsReader(false, ""));
|
||||
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
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::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, HomePathIsSetAndNeedToCreate::mkdirMock);
|
||||
|
||||
std::string cacheDir = "";
|
||||
EXPECT_TRUE(checkDefaultCacheDirSettings(cacheDir, settingsReader.get()));
|
||||
EXPECT_EQ(cacheDir, "home/directory/.cache/neo_compiler_cache");
|
||||
}
|
||||
|
||||
TEST(CompilerCacheHelper, GivenHomeCachePathSetWhenCheckDefaultCacheDirSettingsThenProperDirectoryIsCreated) {
|
||||
std::unique_ptr<SettingsReader> settingsReader(SettingsReader::createOsReader(false, ""));
|
||||
|
||||
@@ -846,3 +875,19 @@ TEST(CompilerCacheHelper, GivenNotExistingPathWhenGettingFileSizeThenZeroIsRetur
|
||||
|
||||
EXPECT_EQ(getFileSize("/tmp/file1"), 0u);
|
||||
}
|
||||
|
||||
TEST(CompilerCacheHelper, makePathGivenEmptyRhsThenLhsIsReturned) {
|
||||
EXPECT_STREQ(makePath("", "path").c_str(), "path");
|
||||
}
|
||||
|
||||
TEST(CompilerCacheHelper, makePathGivenEmptyLhsThenRhsIsReturned) {
|
||||
EXPECT_STREQ(makePath("path", "").c_str(), "path");
|
||||
}
|
||||
|
||||
TEST(CompilerCacheHelper, makePathGivenPathWithTrailingSlashThenSlashIsNotAdded) {
|
||||
EXPECT_STREQ(makePath("path/", "test").c_str(), "path/test");
|
||||
}
|
||||
|
||||
TEST(CompilerCacheHelper, makePathGivenPathWithoutTrailingSlashThenSlashIsAdded) {
|
||||
EXPECT_STREQ(makePath("path", "test").c_str(), "path/test");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user