diff --git a/shared/source/compiler_interface/compiler_cache.h b/shared/source/compiler_interface/compiler_cache.h index a1defdeba1..dafd36e1d3 100644 --- a/shared/source/compiler_interface/compiler_cache.h +++ b/shared/source/compiler_interface/compiler_cache.h @@ -7,10 +7,9 @@ #pragma once +#include "shared/source/os_interface/os_handle.h" #include "shared/source/utilities/arrayref.h" -#include "os_handle.h" - #include #include #include @@ -52,7 +51,7 @@ class CompilerCache { MOCKABLE_VIRTUAL bool evictCache(); MOCKABLE_VIRTUAL bool renameTempFileBinaryToProperName(const std::string &oldName, const std::string &kernelFileHash); MOCKABLE_VIRTUAL bool createUniqueTempFileAndWriteData(char *tmpFilePathTemplate, const char *pBinary, size_t binarySize); - MOCKABLE_VIRTUAL void lockConfigFileAndReadSize(const std::string &configFilePath, HandleType &fd, size_t &directorySize); + MOCKABLE_VIRTUAL void lockConfigFileAndReadSize(const std::string &configFilePath, UnifiedHandle &fd, size_t &directorySize); static std::mutex cacheAccessMtx; CompilerCacheConfig config; diff --git a/shared/source/compiler_interface/linux/compiler_cache_linux.cpp b/shared/source/compiler_interface/linux/compiler_cache_linux.cpp index d4e72ca64b..0a51959816 100644 --- a/shared/source/compiler_interface/linux/compiler_cache_linux.cpp +++ b/shared/source/compiler_interface/linux/compiler_cache_linux.cpp @@ -12,9 +12,9 @@ #include "shared/source/helpers/path.h" #include "shared/source/helpers/string.h" #include "shared/source/os_interface/linux/sys_calls.h" +#include "shared/source/os_interface/os_handle.h" #include "shared/source/utilities/io_functions.h" -#include "os_handle.h" #include "os_inc.h" #include @@ -127,16 +127,16 @@ void unlockFileAndClose(int fd) { NEO::SysCalls::close(fd); } -void CompilerCache::lockConfigFileAndReadSize(const std::string &configFilePath, HandleType &fd, size_t &directorySize) { +void CompilerCache::lockConfigFileAndReadSize(const std::string &configFilePath, UnifiedHandle &fd, size_t &directorySize) { bool countDirectorySize = false; errno = 0; - fd = NEO::SysCalls::open(configFilePath.c_str(), O_RDWR); + std::get(fd) = NEO::SysCalls::open(configFilePath.c_str(), O_RDWR); - if (fd < 0) { + if (std::get(fd) < 0) { if (errno == ENOENT) { - fd = NEO::SysCalls::openWithMode(configFilePath.c_str(), O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); - if (fd < 0) { - fd = NEO::SysCalls::open(configFilePath.c_str(), O_RDWR); + std::get(fd) = NEO::SysCalls::openWithMode(configFilePath.c_str(), O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); + if (std::get(fd) < 0) { + std::get(fd) = NEO::SysCalls::open(configFilePath.c_str(), O_RDWR); } else { countDirectorySize = true; } @@ -146,12 +146,12 @@ void CompilerCache::lockConfigFileAndReadSize(const std::string &configFilePath, } } - int lockErr = NEO::SysCalls::flock(fd, LOCK_EX); + int lockErr = NEO::SysCalls::flock(std::get(fd), LOCK_EX); if (lockErr < 0) { NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "PID %d [Cache failure]: Lock config file failed! errno: %d\n", NEO::SysCalls::getProcessId(), errno); - NEO::SysCalls::close(fd); - fd = -1; + NEO::SysCalls::close(std::get(fd)); + std::get(fd) = -1; return; } @@ -162,9 +162,9 @@ void CompilerCache::lockConfigFileAndReadSize(const std::string &configFilePath, int filesCount = NEO::SysCalls::scandir(config.cacheDir.c_str(), &files, filterFunction, NULL); if (filesCount == -1) { - unlockFileAndClose(fd); + unlockFileAndClose(std::get(fd)); NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "PID %d [Cache failure]: Scandir failed! errno: %d\n", NEO::SysCalls::getProcessId(), errno); - fd = -1; + std::get(fd) = -1; return; } @@ -191,13 +191,13 @@ void CompilerCache::lockConfigFileAndReadSize(const std::string &configFilePath, } } else { - ssize_t readErr = NEO::SysCalls::pread(fd, &directorySize, sizeof(directorySize), 0); + ssize_t readErr = NEO::SysCalls::pread(std::get(fd), &directorySize, sizeof(directorySize), 0); if (readErr < 0) { directorySize = 0; NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "PID %d [Cache failure]: Read config failed! errno: %d\n", NEO::SysCalls::getProcessId(), errno); - unlockFileAndClose(fd); - fd = -1; + unlockFileAndClose(std::get(fd)); + std::get(fd) = -1; } } } @@ -213,18 +213,18 @@ bool CompilerCache::cacheBinary(const std::string &kernelFileHash, const char *p std::string configFilePath = joinPath(config.cacheDir, configFileName.data()); std::string filePath = joinPath(config.cacheDir, kernelFileHash + config.cacheFileExtension); - int fd = -1; + UnifiedHandle fd{-1}; size_t directorySize = 0u; lockConfigFileAndReadSize(configFilePath, fd, directorySize); - if (fd < 0) { + if (std::get(fd) < 0) { return false; } struct stat statbuf = {}; if (NEO::SysCalls::stat(filePath, &statbuf) == 0) { - unlockFileAndClose(fd); + unlockFileAndClose(std::get(fd)); return true; } @@ -232,7 +232,7 @@ bool CompilerCache::cacheBinary(const std::string &kernelFileHash, const char *p if (maxSize < directorySize + binarySize) { if (!evictCache()) { - unlockFileAndClose(fd); + unlockFileAndClose(std::get(fd)); return false; } } @@ -242,20 +242,20 @@ bool CompilerCache::cacheBinary(const std::string &kernelFileHash, const char *p std::string tmpFilePath = joinPath(config.cacheDir, tmpFileName); if (!createUniqueTempFileAndWriteData(tmpFilePath.data(), pBinary, binarySize)) { - unlockFileAndClose(fd); + unlockFileAndClose(std::get(fd)); return false; } if (!renameTempFileBinaryToProperName(tmpFilePath, filePath)) { - unlockFileAndClose(fd); + unlockFileAndClose(std::get(fd)); return false; } directorySize += binarySize; - NEO::SysCalls::pwrite(fd, &directorySize, sizeof(directorySize), 0); + NEO::SysCalls::pwrite(std::get(fd), &directorySize, sizeof(directorySize), 0); - unlockFileAndClose(fd); + unlockFileAndClose(std::get(fd)); return true; } diff --git a/shared/source/compiler_interface/windows/compiler_cache_windows.cpp b/shared/source/compiler_interface/windows/compiler_cache_windows.cpp index 13ecb78a84..1e15ea8c20 100644 --- a/shared/source/compiler_interface/windows/compiler_cache_windows.cpp +++ b/shared/source/compiler_interface/windows/compiler_cache_windows.cpp @@ -63,15 +63,15 @@ std::vector getFiles(const std::string &path) { return files; } -void unlockFileAndClose(HandleType handle) { +void unlockFileAndClose(UnifiedHandle handle) { OVERLAPPED overlapped = {0}; - auto result = NEO::SysCalls::unlockFileEx(handle, 0, MAXDWORD, MAXDWORD, &overlapped); + auto result = NEO::SysCalls::unlockFileEx(std::get(handle), 0, MAXDWORD, MAXDWORD, &overlapped); if (!result) { NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "PID %d [Cache failure]: Unlock file failed! error code: %lu\n", NEO::SysCalls::getProcessId(), SysCalls::getLastError()); } - NEO::SysCalls::closeHandle(handle); + NEO::SysCalls::closeHandle(std::get(handle)); } bool CompilerCache::evictCache() { @@ -91,41 +91,41 @@ bool CompilerCache::evictCache() { return true; } -void CompilerCache::lockConfigFileAndReadSize(const std::string &configFilePath, HandleType &handle, size_t &directorySize) { +void CompilerCache::lockConfigFileAndReadSize(const std::string &configFilePath, UnifiedHandle &handle, size_t &directorySize) { bool countDirectorySize = false; - handle = NEO::SysCalls::createFileA(configFilePath.c_str(), - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); + std::get(handle) = NEO::SysCalls::createFileA(configFilePath.c_str(), + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); - if (handle == INVALID_HANDLE_VALUE) { - handle = NEO::SysCalls::createFileA(configFilePath.c_str(), - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - CREATE_NEW, - FILE_ATTRIBUTE_NORMAL, - NULL); + if (std::get(handle) == INVALID_HANDLE_VALUE) { + std::get(handle) = NEO::SysCalls::createFileA(configFilePath.c_str(), + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + CREATE_NEW, + FILE_ATTRIBUTE_NORMAL, + NULL); - if (handle == INVALID_HANDLE_VALUE) { - handle = NEO::SysCalls::createFileA(configFilePath.c_str(), - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); + if (std::get(handle) == INVALID_HANDLE_VALUE) { + std::get(handle) = NEO::SysCalls::createFileA(configFilePath.c_str(), + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); } else { countDirectorySize = true; } } OVERLAPPED overlapped = {0}; - auto result = NEO::SysCalls::lockFileEx(handle, + auto result = NEO::SysCalls::lockFileEx(std::get(handle), LOCKFILE_EXCLUSIVE_LOCK, 0, MAXDWORD, @@ -134,11 +134,11 @@ void CompilerCache::lockConfigFileAndReadSize(const std::string &configFilePath, if (result == FALSE && SysCalls::getLastError() == ERROR_IO_PENDING) { // if file is already locked by somebody else DWORD numberOfBytesTransmitted = 0; - result = NEO::SysCalls::getOverlappedResult(handle, &overlapped, &numberOfBytesTransmitted, TRUE); + result = NEO::SysCalls::getOverlappedResult(std::get(handle), &overlapped, &numberOfBytesTransmitted, TRUE); } if (!result) { - handle = INVALID_HANDLE_VALUE; + std::get(handle) = INVALID_HANDLE_VALUE; NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "PID %d [Cache failure]: Lock config file failed! error code: %lu\n", NEO::SysCalls::getProcessId(), SysCalls::getLastError()); return; } @@ -151,12 +151,12 @@ void CompilerCache::lockConfigFileAndReadSize(const std::string &configFilePath, } } else { memset(&overlapped, 0, sizeof(overlapped)); - result = NEO::SysCalls::readFileEx(handle, &directorySize, sizeof(directorySize), &overlapped, NULL); + result = NEO::SysCalls::readFileEx(std::get(handle), &directorySize, sizeof(directorySize), &overlapped, NULL); if (!result) { directorySize = 0; - unlockFileAndClose(handle); - handle = INVALID_HANDLE_VALUE; + unlockFileAndClose(std::get(handle)); + std::get(handle) = INVALID_HANDLE_VALUE; NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "PID %d [Cache failure]: Read config failed! error code: %lu\n", NEO::SysCalls::getProcessId(), SysCalls::getLastError()); } } @@ -207,7 +207,7 @@ bool CompilerCache::renameTempFileBinaryToProperName(const std::string &oldName, class HandleGuard { public: HandleGuard() = delete; - explicit HandleGuard(HandleType &h) : handle(h) {} + explicit HandleGuard(void *&h) : handle(h) {} ~HandleGuard() { if (handle) { unlockFileAndClose(handle); @@ -215,7 +215,7 @@ class HandleGuard { } private: - HandleType handle = nullptr; + void *handle = nullptr; }; bool CompilerCache::cacheBinary(const std::string &kernelFileHash, const char *pBinary, size_t binarySize) { @@ -229,16 +229,16 @@ bool CompilerCache::cacheBinary(const std::string &kernelFileHash, const char *p std::string configFilePath = joinPath(config.cacheDir, configFileName.data()); std::string cacheFilePath = joinPath(config.cacheDir, kernelFileHash + config.cacheFileExtension); - HandleType hConfigFile = INVALID_HANDLE_VALUE; + UnifiedHandle hConfigFile{INVALID_HANDLE_VALUE}; size_t directorySize = 0u; lockConfigFileAndReadSize(configFilePath, hConfigFile, directorySize); - if (hConfigFile == INVALID_HANDLE_VALUE) { + if (std::get(hConfigFile) == INVALID_HANDLE_VALUE) { return false; } - HandleGuard configGuard(hConfigFile); + HandleGuard configGuard(std::get(hConfigFile)); DWORD cacheFileAttr = 0; cacheFileAttr = NEO::SysCalls::getFileAttributesA(cacheFilePath.c_str()); @@ -270,7 +270,7 @@ bool CompilerCache::cacheBinary(const std::string &kernelFileHash, const char *p directorySize += binarySize; DWORD sizeWritten = 0; - auto result = NEO::SysCalls::writeFile(hConfigFile, + auto result = NEO::SysCalls::writeFile(std::get(hConfigFile), &directorySize, (DWORD)sizeof(directorySize), &sizeWritten, @@ -289,4 +289,4 @@ std::unique_ptr CompilerCache::loadCachedBinary(const std::string &kerne std::string filePath = joinPath(config.cacheDir, kernelFileHash + config.cacheFileExtension); return loadDataFromFile(filePath.c_str(), cachedBinarySize); } -} // namespace NEO \ No newline at end of file +} // namespace NEO diff --git a/shared/source/os_interface/CMakeLists.txt b/shared/source/os_interface/CMakeLists.txt index d8b92ac05c..27a87d8739 100644 --- a/shared/source/os_interface/CMakeLists.txt +++ b/shared/source/os_interface/CMakeLists.txt @@ -30,6 +30,7 @@ set(NEO_CORE_OS_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/os_context.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_context.h ${CMAKE_CURRENT_SOURCE_DIR}/os_environment.h + ${CMAKE_CURRENT_SOURCE_DIR}/os_handle.h ${CMAKE_CURRENT_SOURCE_DIR}/os_interface.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_interface.h ${CMAKE_CURRENT_SOURCE_DIR}/os_library.h diff --git a/shared/source/os_interface/linux/CMakeLists.txt b/shared/source/os_interface/linux/CMakeLists.txt index bc20dfe13e..4b82c4e597 100644 --- a/shared/source/os_interface/linux/CMakeLists.txt +++ b/shared/source/os_interface/linux/CMakeLists.txt @@ -62,7 +62,6 @@ set(NEO_CORE_OS_INTERFACE_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/memory_info.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_context_linux.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_context_linux.h - ${CMAKE_CURRENT_SOURCE_DIR}/os_handle.h ${CMAKE_CURRENT_SOURCE_DIR}/os_inc.h ${CMAKE_CURRENT_SOURCE_DIR}/os_interface_linux.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_interface_linux.h diff --git a/shared/source/os_interface/linux/os_handle.h b/shared/source/os_interface/os_handle.h similarity index 66% rename from shared/source/os_interface/linux/os_handle.h rename to shared/source/os_interface/os_handle.h index cc97702463..3a2f3bd80b 100644 --- a/shared/source/os_interface/linux/os_handle.h +++ b/shared/source/os_interface/os_handle.h @@ -7,6 +7,8 @@ #pragma once +#include + namespace NEO { -using HandleType = int; +using UnifiedHandle = std::variant; }; // namespace NEO diff --git a/shared/source/os_interface/windows/CMakeLists.txt b/shared/source/os_interface/windows/CMakeLists.txt index 4aad61a3b5..af00f09b28 100644 --- a/shared/source/os_interface/windows/CMakeLists.txt +++ b/shared/source/os_interface/windows/CMakeLists.txt @@ -21,7 +21,6 @@ set(NEO_CORE_OS_INTERFACE_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/environment_variables.h ${CMAKE_CURRENT_SOURCE_DIR}/product_helper_drm_stub.cpp ${CMAKE_CURRENT_SOURCE_DIR}/kmd_notify_properties_windows.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/os_handle.h ${CMAKE_CURRENT_SOURCE_DIR}/os_inc.h ${CMAKE_CURRENT_SOURCE_DIR}/os_interface_win.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_library_win.cpp diff --git a/shared/source/os_interface/windows/os_handle.h b/shared/source/os_interface/windows/os_handle.h deleted file mode 100644 index c300f26afd..0000000000 --- a/shared/source/os_interface/windows/os_handle.h +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (C) 2023 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once - -namespace NEO { -using HandleType = void *; -}; // namespace NEO diff --git a/shared/test/unit_test/compiler_interface/linux/compiler_cache_tests_linux.cpp b/shared/test/unit_test/compiler_interface/linux/compiler_cache_tests_linux.cpp index 483324e2b2..d96e2c7dbf 100644 --- a/shared/test/unit_test/compiler_interface/linux/compiler_cache_tests_linux.cpp +++ b/shared/test/unit_test/compiler_interface/linux/compiler_cache_tests_linux.cpp @@ -236,12 +236,12 @@ TEST(CompilerCacheTests, GivenCompilerCacheWhenConfigFileIsInacessibleThenFdIsSe VariableBackup openBackup(&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int { errno = EACCES; return -1; }); - int configFileDescriptor = 0; + UnifiedHandle configFileDescriptor{0}; size_t directory = 0; cache.lockConfigFileAndReadSize("config.file", configFileDescriptor, directory); - EXPECT_EQ(configFileDescriptor, -1); + EXPECT_EQ(std::get(configFileDescriptor), -1); } TEST(CompilerCacheTests, GivenCompilerCacheWhenCannotLockConfigFileThenFdIsSetToNegativeNumber) { @@ -250,12 +250,12 @@ TEST(CompilerCacheTests, GivenCompilerCacheWhenCannotLockConfigFileThenFdIsSetTo VariableBackup flockBackup(&NEO::SysCalls::flockRetVal, flockRetVal); - int configFileDescriptor = 0; + UnifiedHandle configFileDescriptor{0}; size_t directory = 0; cache.lockConfigFileAndReadSize("config.file", configFileDescriptor, directory); - EXPECT_EQ(configFileDescriptor, -1); + EXPECT_EQ(std::get(configFileDescriptor), -1); } #include @@ -284,12 +284,12 @@ TEST(CompilerCacheTests, GivenCompilerCacheWhenScandirFailInLockConfigFileThenFd VariableBackup openWithModeBackup(&NEO::SysCalls::sysCallsOpenWithMode, LockConfigFileAndReadSize::openWithMode); VariableBackup openBackup(&NEO::SysCalls::sysCallsOpen, LockConfigFileAndReadSize::open); - int configFileDescriptor = 0; + UnifiedHandle configFileDescriptor{0}; size_t directory = 0; cache.lockConfigFileAndReadSize("config.file", configFileDescriptor, directory); - EXPECT_EQ(configFileDescriptor, -1); + EXPECT_EQ(std::get(configFileDescriptor), -1); } namespace lockConfigFileAndReadSizeMocks { @@ -350,12 +350,12 @@ TEST(CompilerCacheTests, GivenCompilerCacheWhenLockConfigFileWithFileCreationThe VariableBackup openWithModeBackup(&NEO::SysCalls::sysCallsOpenWithMode, LockConfigFileAndReadSize::openWithMode); VariableBackup openBackup(&NEO::SysCalls::sysCallsOpen, LockConfigFileAndReadSize::open); - int configFileDescriptor = 0; + UnifiedHandle configFileDescriptor{0}; size_t directory = 0; cache.lockConfigFileAndReadSize("config.file", configFileDescriptor, directory); - EXPECT_EQ(configFileDescriptor, 1); + EXPECT_EQ(std::get(configFileDescriptor), 1); EXPECT_EQ(NEO::SysCalls::scandirCalled, 1); EXPECT_EQ(directory, MemoryConstants::megaByte); } @@ -399,12 +399,12 @@ TEST(CompilerCacheTests, GivenCompilerCacheWhenLockConfigFileAndOtherProcessCrea VariableBackup openWithModeBackup(&NEO::SysCalls::sysCallsOpenWithMode, LockConfigFileAndConfigFileIsCreatedInMeantime::openWithMode); VariableBackup openBackup(&NEO::SysCalls::sysCallsOpen, LockConfigFileAndConfigFileIsCreatedInMeantime::open); - int configFileDescriptor = 0; + UnifiedHandle configFileDescriptor{0}; size_t directory = 0; cache.lockConfigFileAndReadSize("config.file", configFileDescriptor, directory); - EXPECT_EQ(configFileDescriptor, 1); + EXPECT_EQ(std::get(configFileDescriptor), 1); EXPECT_EQ(NEO::SysCalls::scandirCalled, 0); EXPECT_EQ(directory, LockConfigFileAndConfigFileIsCreatedInMeantime::configSize); } @@ -416,12 +416,12 @@ TEST(CompilerCacheTests, GivenCompilerCacheWhenLockConfigFileThenFdIsSetProperSi VariableBackup scandirCalledBackup(&NEO::SysCalls::scandirCalled, scandirCalledTimes); VariableBackup preadBackup(&NEO::SysCalls::sysCallsPread, LockConfigFileAndConfigFileIsCreatedInMeantime::pread); - int configFileDescriptor = 0; + UnifiedHandle configFileDescriptor{0}; size_t directory = 0; cache.lockConfigFileAndReadSize("config.file", configFileDescriptor, directory); - EXPECT_EQ(configFileDescriptor, NEO::SysCalls::fakeFileDescriptor); + EXPECT_EQ(std::get(configFileDescriptor), NEO::SysCalls::fakeFileDescriptor); EXPECT_EQ(NEO::SysCalls::scandirCalled, 0); EXPECT_EQ(directory, LockConfigFileAndConfigFileIsCreatedInMeantime::configSize); } @@ -434,8 +434,8 @@ class CompilerCacheFailingLokcConfigFileAndReadSizeLinux : public CompilerCache using CompilerCache::lockConfigFileAndReadSize; using CompilerCache::renameTempFileBinaryToProperName; - void lockConfigFileAndReadSize(const std::string &configFilePath, int &fd, size_t &directorySize) override { - fd = -1; + void lockConfigFileAndReadSize(const std::string &configFilePath, UnifiedHandle &fd, size_t &directorySize) override { + std::get(fd) = -1; return; } }; @@ -454,8 +454,8 @@ class CompilerCacheLinuxReturnTrueIfAnotherProcessCreateCacheFile : public Compi using CompilerCache::lockConfigFileAndReadSize; using CompilerCache::renameTempFileBinaryToProperName; - void lockConfigFileAndReadSize(const std::string &configFilePath, int &fd, size_t &directorySize) override { - fd = 1; + void lockConfigFileAndReadSize(const std::string &configFilePath, UnifiedHandle &fd, size_t &directorySize) override { + std::get(fd) = 1; return; } }; @@ -476,9 +476,9 @@ class CompilerCacheLinuxReturnFalseOnCacheBinaryIfEvictFailed : public CompilerC using CompilerCache::lockConfigFileAndReadSize; using CompilerCache::renameTempFileBinaryToProperName; - void lockConfigFileAndReadSize(const std::string &configFilePath, int &fd, size_t &directorySize) override { + void lockConfigFileAndReadSize(const std::string &configFilePath, UnifiedHandle &fd, size_t &directorySize) override { directorySize = MemoryConstants::megaByte; - fd = 1; + std::get(fd) = 1; return; } @@ -503,9 +503,9 @@ class CompilerCacheLinuxReturnFalseOnCacheBinaryIfCreateUniqueFileFailed : publi using CompilerCache::lockConfigFileAndReadSize; using CompilerCache::renameTempFileBinaryToProperName; - void lockConfigFileAndReadSize(const std::string &configFilePath, int &fd, size_t &directorySize) override { + void lockConfigFileAndReadSize(const std::string &configFilePath, UnifiedHandle &fd, size_t &directorySize) override { directorySize = MemoryConstants::megaByte; - fd = 1; + std::get(fd) = 1; return; } @@ -534,9 +534,9 @@ class CompilerCacheLinuxReturnFalseOnCacheBinaryIfRenameFileFailed : public Comp using CompilerCache::lockConfigFileAndReadSize; using CompilerCache::renameTempFileBinaryToProperName; - void lockConfigFileAndReadSize(const std::string &configFilePath, int &fd, size_t &directorySize) override { + void lockConfigFileAndReadSize(const std::string &configFilePath, UnifiedHandle &fd, size_t &directorySize) override { directorySize = MemoryConstants::megaByte; - fd = 1; + std::get(fd) = 1; return; } @@ -569,9 +569,9 @@ class CompilerCacheLinuxReturnTrueOnCacheBinary : public CompilerCache { using CompilerCache::lockConfigFileAndReadSize; using CompilerCache::renameTempFileBinaryToProperName; - void lockConfigFileAndReadSize(const std::string &configFilePath, int &fd, size_t &directorySize) override { + void lockConfigFileAndReadSize(const std::string &configFilePath, UnifiedHandle &fd, size_t &directorySize) override { directorySize = MemoryConstants::megaByte; - fd = 1; + std::get(fd) = 1; return; } diff --git a/shared/test/unit_test/compiler_interface/windows/compiler_cache_tests_windows.cpp b/shared/test/unit_test/compiler_interface/windows/compiler_cache_tests_windows.cpp index 5e823902d5..dedd156734 100644 --- a/shared/test/unit_test/compiler_interface/windows/compiler_cache_tests_windows.cpp +++ b/shared/test/unit_test/compiler_interface/windows/compiler_cache_tests_windows.cpp @@ -69,17 +69,17 @@ class CompilerCacheMockWindows : public CompilerCache { size_t evictCacheCalled = 0u; bool evictCacheResult = true; - void lockConfigFileAndReadSize(const std::string &configFilePath, HandleType &handle, size_t &directorySize) override { + void lockConfigFileAndReadSize(const std::string &configFilePath, UnifiedHandle &handle, size_t &directorySize) override { lockConfigFileAndReadSizeCalled++; if (callBaseLockConfigFileAndReadSize) { return CompilerCache::lockConfigFileAndReadSize(configFilePath, handle, directorySize); } - handle = lockConfigFileAndReadSizeHandle; + std::get(handle) = lockConfigFileAndReadSizeHandle; } bool callBaseLockConfigFileAndReadSize = true; size_t lockConfigFileAndReadSizeCalled = 0u; - HandleType lockConfigFileAndReadSizeHandle = INVALID_HANDLE_VALUE; + void *lockConfigFileAndReadSizeHandle = INVALID_HANDLE_VALUE; }; TEST(CompilerCacheHelper, GivenHomeEnvWhenOtherProcessCreatesNeoCompilerCacheFolderThenProperDirectoryIsReturned) { @@ -264,7 +264,7 @@ TEST_F(CompilerCacheWindowsTest, givenLockConfigFileAndReadSizeWhenOpenExistingC const size_t cacheSize = MemoryConstants::megaByte - 2u; CompilerCacheMockWindows cache({true, ".cl_cache", "somePath\\cl_cache", cacheSize}); - HANDLE configFileHandle = nullptr; + UnifiedHandle configFileHandle{nullptr}; size_t directorySize = 0u; cache.lockConfigFileAndReadSize("somePath\\cl_cache\\config.file", configFileHandle, directorySize); @@ -291,7 +291,7 @@ TEST_F(CompilerCacheWindowsTest, givenLockConfigFileAndReadSizeWhenOpenExistingC const size_t cacheSize = MemoryConstants::megaByte - 2u; CompilerCacheMockWindows cache({true, ".cl_cache", "somePath\\cl_cache", cacheSize}); - HANDLE configFileHandle = nullptr; + UnifiedHandle configFileHandle{nullptr}; size_t directorySize = 0u; ::testing::internal::CaptureStderr(); @@ -323,7 +323,7 @@ TEST_F(CompilerCacheWindowsTest, givenLockConfigFileAndReadSizeWhenOpenExistingC const size_t cacheSize = MemoryConstants::megaByte - 2u; CompilerCacheMockWindows cache({true, ".cl_cache", "somePath\\cl_cache", cacheSize}); - HANDLE configFileHandle = nullptr; + UnifiedHandle configFileHandle{nullptr}; size_t directorySize = 0u; ::testing::internal::CaptureStderr(); @@ -373,7 +373,7 @@ TEST_F(CompilerCacheWindowsTest, givenLockConfigFileAndReadSizeWhenOpenExistingC const size_t cacheSize = MemoryConstants::megaByte - 2u; CompilerCacheMockWindows cache({true, ".cl_cache", "somePath\\cl_cache", cacheSize}); - HANDLE configFileHandle = nullptr; + UnifiedHandle configFileHandle{nullptr}; size_t directorySize = 0u; cache.lockConfigFileAndReadSize("somePath\\cl_cache\\config.file", configFileHandle, directorySize);