diff --git a/level_zero/tools/source/sysman/linux/fs_access.cpp b/level_zero/tools/source/sysman/linux/fs_access.cpp index 1b8e833b39..df951a3b0f 100644 --- a/level_zero/tools/source/sysman/linux/fs_access.cpp +++ b/level_zero/tools/source/sysman/linux/fs_access.cpp @@ -31,6 +31,30 @@ static ze_result_t getResult(int err) { } } +template +ze_result_t FsAccess::readValue(const std::string file, T &val) { + + std::string readVal(64, '\0'); + int fd = NEO::SysCalls::open(file.c_str(), O_RDONLY); + if (fd < 0) { + return getResult(errno); + } + + ssize_t bytesRead = NEO::SysCalls::pread(fd, readVal.data(), readVal.size(), 0); + NEO::SysCalls::close(fd); + if (bytesRead < 0) { + return getResult(errno); + } + + std::istringstream stream(readVal); + stream >> val; + if (stream.fail()) { + return ZE_RESULT_ERROR_UNKNOWN; + } + + return ZE_RESULT_SUCCESS; +} + // Generic Filesystem Access FsAccess::FsAccess() { } @@ -40,72 +64,21 @@ FsAccess *FsAccess::create() { } ze_result_t FsAccess::read(const std::string file, uint64_t &val) { - // Read a single line from text file without trailing newline - std::ifstream fs; - - fs.open(file.c_str()); - if (fs.fail()) { - return getResult(errno); - } - fs >> val; - if (fs.fail()) { - fs.close(); - return getResult(errno); - } - fs.close(); - return ZE_RESULT_SUCCESS; + return readValue(file, val); } ze_result_t FsAccess::read(const std::string file, double &val) { - // Read a single line from text file without trailing newline - std::ifstream fs; - - fs.open(file.c_str()); - if (fs.fail()) { - return getResult(errno); - } - fs >> val; - if (fs.fail()) { - fs.close(); - return getResult(errno); - } - fs.close(); - return ZE_RESULT_SUCCESS; + return readValue(file, val); } ze_result_t FsAccess::read(const std::string file, int32_t &val) { - // Read a single line from text file without trailing newline - std::ifstream fs; - - fs.open(file.c_str()); - if (fs.fail()) { - return getResult(errno); - } - fs >> val; - if (fs.fail()) { - fs.close(); - return getResult(errno); - } - fs.close(); - return ZE_RESULT_SUCCESS; + return readValue(file, val); } ze_result_t FsAccess::read(const std::string file, uint32_t &val) { - // Read a single line from text file without trailing newline - std::ifstream fs; - - fs.open(file.c_str()); - if (fs.fail()) { - return getResult(errno); - } - fs >> val; - if (fs.fail()) { - fs.close(); - return getResult(errno); - } - fs.close(); - return ZE_RESULT_SUCCESS; + return readValue(file, val); } + ze_result_t FsAccess::read(const std::string file, std::string &val) { // Read a single line from text file without trailing newline std::ifstream fs; @@ -125,6 +98,7 @@ ze_result_t FsAccess::read(const std::string file, std::string &val) { if (val.back() == '\n') { val.pop_back(); } + return ZE_RESULT_SUCCESS; } @@ -154,18 +128,22 @@ ze_result_t FsAccess::read(const std::string file, std::vector &val } ze_result_t FsAccess::write(const std::string file, const std::string val) { - std::ofstream sysfs; - sysfs.open(file.c_str()); - if (sysfs.fail()) { + int fd = NEO::SysCalls::open(file.c_str(), O_WRONLY); + if (fd < 0) { return getResult(errno); } - sysfs << val << std::endl; - if (sysfs.fail()) { - sysfs.close(); + + ssize_t bytesWritten = NEO::SysCalls::pwrite(fd, val.data(), val.size(), 0); + NEO::SysCalls::close(fd); + if (bytesWritten < 0) { return getResult(errno); } - sysfs.close(); + + if (bytesWritten != static_cast(val.size())) { + return ZE_RESULT_ERROR_UNKNOWN; + } + return ZE_RESULT_SUCCESS; } @@ -192,7 +170,7 @@ ze_result_t FsAccess::canWrite(const std::string file) { } bool FsAccess::fileExists(const std::string file) { - if (access(file.c_str(), F_OK)) { + if (NEO::SysCalls::access(file.c_str(), F_OK)) { return false; } return true; @@ -422,79 +400,23 @@ ze_result_t SysfsAccess::getFileMode(const std::string file, ::mode_t &mode) { ze_result_t SysfsAccess::read(const std::string file, std::string &val) { // Prepend sysfs directory path and call the base read - return FsAccess::read(fullPath(file).c_str(), val); + return FsAccess::read(fullPath(file), val); } ze_result_t SysfsAccess::read(const std::string file, int32_t &val) { - std::string str; - ze_result_t result; - - result = FsAccess::read(fullPath(file), str); - if (ZE_RESULT_SUCCESS != result) { - return result; - } - - std::istringstream stream(str); - stream >> val; - - if (stream.fail()) { - return ZE_RESULT_ERROR_UNKNOWN; - } - return ZE_RESULT_SUCCESS; + return FsAccess::read(fullPath(file), val); } ze_result_t SysfsAccess::read(const std::string file, uint32_t &val) { - std::string str; - ze_result_t result; - - result = FsAccess::read(fullPath(file), str); - if (ZE_RESULT_SUCCESS != result) { - return result; - } - - std::istringstream stream(str); - stream >> val; - - if (stream.fail()) { - return ZE_RESULT_ERROR_UNKNOWN; - } - return ZE_RESULT_SUCCESS; + return FsAccess::read(fullPath(file), val); } ze_result_t SysfsAccess::read(const std::string file, double &val) { - std::string str; - ze_result_t result; - - result = FsAccess::read(fullPath(file), str); - if (ZE_RESULT_SUCCESS != result) { - return result; - } - - std::istringstream stream(str); - stream >> val; - - if (stream.fail()) { - return ZE_RESULT_ERROR_UNKNOWN; - } - return ZE_RESULT_SUCCESS; + return FsAccess::read(fullPath(file), val); } ze_result_t SysfsAccess::read(const std::string file, uint64_t &val) { - std::string str; - ze_result_t result; - - result = FsAccess::read(fullPath(file), str); - if (ZE_RESULT_SUCCESS != result) { - return result; - } - - std::istringstream stream(str); - stream >> val; - - if (stream.fail()) { - return ZE_RESULT_ERROR_UNKNOWN; - } - return ZE_RESULT_SUCCESS; + return FsAccess::read(fullPath(file), val); } ze_result_t SysfsAccess::read(const std::string file, std::vector &val) { @@ -504,7 +426,7 @@ ze_result_t SysfsAccess::read(const std::string file, std::vector & ze_result_t SysfsAccess::write(const std::string file, const std::string val) { // Prepend sysfs directory path and call the base write - return FsAccess::write(fullPath(file).c_str(), val); + return FsAccess::write(fullPath(file), val); } ze_result_t SysfsAccess::write(const std::string file, const int val) { @@ -539,17 +461,17 @@ ze_result_t SysfsAccess::write(const std::string file, const uint64_t val) { ze_result_t SysfsAccess::scanDirEntries(const std::string path, std::vector &list) { list.clear(); - return FsAccess::listDirectory(fullPath(path).c_str(), list); + return FsAccess::listDirectory(fullPath(path), list); } ze_result_t SysfsAccess::readSymLink(const std::string path, std::string &val) { // Prepend sysfs directory path and call the base readSymLink - return FsAccess::readSymLink(fullPath(path).c_str(), val); + return FsAccess::readSymLink(fullPath(path), val); } ze_result_t SysfsAccess::getRealPath(const std::string path, std::string &val) { // Prepend sysfs directory path and call the base getRealPath - return FsAccess::getRealPath(fullPath(path).c_str(), val); + return FsAccess::getRealPath(fullPath(path), val); } ze_result_t SysfsAccess::bindDevice(std::string device) { @@ -562,11 +484,11 @@ ze_result_t SysfsAccess::unbindDevice(std::string device) { bool SysfsAccess::fileExists(const std::string file) { // Prepend sysfs directory path and call the base fileExists - return FsAccess::fileExists(fullPath(file).c_str()); + return FsAccess::fileExists(fullPath(file)); } bool SysfsAccess::directoryExists(const std::string path) { - return FsAccess::directoryExists(fullPath(path).c_str()); + return FsAccess::directoryExists(fullPath(path)); } bool SysfsAccess::isMyDeviceFile(const std::string dev) { diff --git a/level_zero/tools/source/sysman/linux/fs_access.h b/level_zero/tools/source/sysman/linux/fs_access.h index 5dd85e4203..6293301040 100644 --- a/level_zero/tools/source/sysman/linux/fs_access.h +++ b/level_zero/tools/source/sysman/linux/fs_access.h @@ -12,6 +12,7 @@ #include "level_zero/ze_api.h" #include "level_zero/zet_api.h" +#include #include #include #include @@ -56,6 +57,10 @@ class FsAccess { FsAccess(); decltype(&NEO::SysCalls::access) accessSyscall = NEO::SysCalls::access; decltype(&stat) statSyscall = stat; + + private: + template + ze_result_t readValue(const std::string file, T &val); }; class ProcfsAccess : private FsAccess { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h b/level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h index 951d41f10b..58be59c499 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h @@ -172,6 +172,7 @@ class PublicFsAccess : public L0::FsAccess { class PublicSysfsAccess : public L0::SysfsAccess { public: using SysfsAccess::accessSyscall; + using SysfsAccess::statSyscall; }; class UdevLibMock : public UdevLib { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/linux/test_sysman.cpp b/level_zero/tools/test/unit_tests/sources/sysman/linux/test_sysman.cpp index cc9bf5964b..b0c1f90dcb 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/linux/test_sysman.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/linux/test_sysman.cpp @@ -6,6 +6,7 @@ */ #include "shared/test/common/mocks/mock_driver_info.h" +#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h" #include "shared/test/common/test_macros/test.h" #include "level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.h" @@ -14,6 +15,12 @@ #include "level_zero/tools/source/sysman/ras/ras_imp.h" #include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h" +namespace NEO { +namespace SysCalls { +extern bool allowFakeDevicePath; +} // namespace SysCalls +} // namespace NEO + namespace L0 { namespace ult { @@ -245,6 +252,7 @@ TEST_F(SysmanDeviceFixture, GivenPublicFsAccessClassWhenCallingCanWriteWithInval } TEST_F(SysmanDeviceFixture, GivenValidPathnameWhenCallingFsAccessExistsThenSuccessIsReturned) { + VariableBackup allowFakeDevicePathBackup(&SysCalls::allowFakeDevicePath, true); auto fsAccess = pLinuxSysmanImp->getFsAccess(); char cwd[PATH_MAX]; @@ -259,6 +267,253 @@ TEST_F(SysmanDeviceFixture, GivenInvalidPathnameWhenCallingFsAccessExistsThenErr EXPECT_FALSE(fsAccess.fileExists(path)); } +TEST_F(SysmanDeviceFixture, GivenSysfsAccessAndValidDeviceNameWhenCallingBindDeviceThenSuccessIsReturned) { + + std::string deviceName = "card0"; + + VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int { + return 1; + }); + + VariableBackup mockPwrite(&NEO::SysCalls::sysCallsPwrite, [](int fd, const void *buf, size_t count, off_t offset) -> ssize_t { + std::string deviceName = "card0"; + return static_cast(deviceName.size()); + }); + + PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess(); + + EXPECT_EQ(ZE_RESULT_SUCCESS, tempSysfsAccess->bindDevice(deviceName)); + delete tempSysfsAccess; +} + +TEST_F(SysmanDeviceFixture, GivenSysfsAccessAndValidDeviceNameWhenCallingUnbindDeviceThenSuccessIsReturned) { + + std::string deviceName = "card0"; + + VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int { + return 1; + }); + + VariableBackup mockPwrite(&NEO::SysCalls::sysCallsPwrite, [](int fd, const void *buf, size_t count, off_t offset) -> ssize_t { + std::string deviceName = "card0"; + return static_cast(deviceName.size()); + }); + + PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess(); + + EXPECT_EQ(ZE_RESULT_SUCCESS, tempSysfsAccess->unbindDevice(deviceName)); + delete tempSysfsAccess; +} + +TEST_F(SysmanDeviceFixture, GivenValidPathnameWhenCallingSysfsAccessGetFileModeThenSuccessIsReturned) { + PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess(); + + char cwd[PATH_MAX]; + ::mode_t mode; + std::string path = getcwd(cwd, PATH_MAX); + EXPECT_EQ(ZE_RESULT_SUCCESS, tempSysfsAccess->getFileMode(path, mode)); + delete tempSysfsAccess; +} + +TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassWhenCallingCanWriteWithUserHavingWritePermissionsThenSuccessIsReturned) { + PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess(); + tempSysfsAccess->statSyscall = mockStatSuccess; + char cwd[PATH_MAX]; + std::string path = getcwd(cwd, PATH_MAX); + EXPECT_EQ(ZE_RESULT_SUCCESS, tempSysfsAccess->canWrite(path)); + delete tempSysfsAccess; +} + +TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassWhenCallingCanReadWithInvalidPathThenErrorIsReturned) { + PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess(); + tempSysfsAccess->statSyscall = mockStatFailure; + std::string path = "invalidPath"; + EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, tempSysfsAccess->canRead(path)); + delete tempSysfsAccess; +} + +TEST_F(SysmanDeviceFixture, GivenValidPathnameWhenCallingSysfsAccessExistsThenSuccessIsReturned) { + VariableBackup allowFakeDevicePathBackup(&SysCalls::allowFakeDevicePath, true); + PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess(); + char cwd[PATH_MAX]; + std::string path = getcwd(cwd, PATH_MAX); + EXPECT_TRUE(tempSysfsAccess->fileExists(path)); + delete tempSysfsAccess; +} + +TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassAndValidDirectoryWhenCallingscanDirEntriesThenSuccessIsReturned) { + PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess(); + char cwd[PATH_MAX]; + std::string path = getcwd(cwd, PATH_MAX); + std::vector dir; + EXPECT_EQ(ZE_RESULT_SUCCESS, tempSysfsAccess->scanDirEntries(path, dir)); + delete tempSysfsAccess; +} + +TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassAndConstantStringWhenCallingWriteThenSuccessIsReturned) { + const std::string fileName = "mockFile.txt"; + const std::string str = "Mock String"; + + VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int { + return 1; + }); + + VariableBackup mockPwrite(&NEO::SysCalls::sysCallsPwrite, [](int fd, const void *buf, size_t count, off_t offset) -> ssize_t { + const std::string str = "Mock String"; + return static_cast(str.size()); + }); + + PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess(); + + EXPECT_EQ(ZE_RESULT_SUCCESS, tempSysfsAccess->write(fileName, str)); + delete tempSysfsAccess; +} + +TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassAndConstantIntegerWhenCallingWriteThenSuccessIsReturned) { + + const std::string fileName = "mockFile.txt"; + const int iVal32 = 0; + + VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int { + return 1; + }); + + VariableBackup mockPwrite(&NEO::SysCalls::sysCallsPwrite, [](int fd, const void *buf, size_t count, off_t offset) -> ssize_t { + const int iVal32 = 0; + std::ostringstream stream; + stream << iVal32; + return static_cast(stream.str().size()); + }); + + PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess(); + + EXPECT_EQ(ZE_RESULT_SUCCESS, tempSysfsAccess->write(fileName, iVal32)); + delete tempSysfsAccess; +} + +TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassAndIntegerWhenCallingReadThenSuccessIsReturned) { + + VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int { + return 1; + }); + + VariableBackup mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t { + std::string value = "123"; + memcpy(buf, value.data(), value.size()); + return value.size(); + }); + + PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess(); + const std::string fileName = "mockFile.txt"; + int iVal32; + + EXPECT_EQ(ZE_RESULT_SUCCESS, tempSysfsAccess->read(fileName, iVal32)); + delete tempSysfsAccess; +} + +TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassAndUnsignedIntegerWhenCallingReadThenSuccessIsReturned) { + + VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int { + return 1; + }); + + VariableBackup mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t { + std::string value = "123"; + memcpy(buf, value.data(), value.size()); + return value.size(); + }); + + PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess(); + const std::string fileName = "mockFile.txt"; + uint32_t uVal32; + + EXPECT_EQ(ZE_RESULT_SUCCESS, tempSysfsAccess->read(fileName, uVal32)); + delete tempSysfsAccess; +} + +TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassAndConstantDoubleValueWhenCallingWriteThenSuccessIsReturned) { + + const std::string fileName = "mockFile.txt"; + const double dVal = 0.0; + + VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int { + return 1; + }); + + VariableBackup mockPwrite(&NEO::SysCalls::sysCallsPwrite, [](int fd, const void *buf, size_t count, off_t offset) -> ssize_t { + const double dVal = 0.0; + std::ostringstream stream; + stream << dVal; + return static_cast(stream.str().size()); + }); + + PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess(); + + EXPECT_EQ(ZE_RESULT_SUCCESS, tempSysfsAccess->write(fileName, dVal)); + delete tempSysfsAccess; +} + +TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassAndDoubleWhenCallingReadThenSuccessIsReturned) { + + VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int { + return 1; + }); + + VariableBackup mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t { + std::string value = "123"; + memcpy(buf, value.data(), value.size()); + return value.size(); + }); + + PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess(); + const std::string fileName = "mockFile.txt"; + double dVal; + + EXPECT_EQ(ZE_RESULT_SUCCESS, tempSysfsAccess->read(fileName, dVal)); + delete tempSysfsAccess; +} + +TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassAndUnsignedLongValueWhenCallingWriteThenSuccessIsReturned) { + const std::string fileName = "mockFile.txt"; + const uint64_t uVal64 = 0; + + VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int { + return 1; + }); + + VariableBackup mockPwrite(&NEO::SysCalls::sysCallsPwrite, [](int fd, const void *buf, size_t count, off_t offset) -> ssize_t { + const uint64_t uVal64 = 0; + std::ostringstream stream; + stream << uVal64; + return static_cast(stream.str().size()); + }); + + PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess(); + + EXPECT_EQ(ZE_RESULT_SUCCESS, tempSysfsAccess->write(fileName, uVal64)); + delete tempSysfsAccess; +} + +TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassAndUnsignedLongWhenCallingReadThenSuccessIsReturned) { + + VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int { + return 1; + }); + + VariableBackup mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t { + std::string value = "123"; + memcpy(buf, value.data(), value.size()); + return value.size(); + }); + + PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess(); + const std::string fileName = "mockFile.txt"; + uint64_t uVal64; + + EXPECT_EQ(ZE_RESULT_SUCCESS, tempSysfsAccess->read(fileName, uVal64)); + delete tempSysfsAccess; +} + TEST_F(SysmanDeviceFixture, GivenCreateSysfsAccessHandleWhenCallinggetSysfsAccessThenCreatedSysfsAccessHandleHandleWillBeRetrieved) { if (pLinuxSysmanImp->pSysfsAccess != nullptr) { // delete previously allocated pSysfsAccess @@ -269,6 +524,28 @@ TEST_F(SysmanDeviceFixture, GivenCreateSysfsAccessHandleWhenCallinggetSysfsAcces EXPECT_EQ(&pLinuxSysmanImp->getSysfsAccess(), pLinuxSysmanImp->pSysfsAccess); } +TEST_F(SysmanDeviceFixture, GivenValidPidWhenCallingProcfsAccessGetFileDescriptorsThenSuccessIsReturned) { + auto procfsAccess = pLinuxSysmanImp->getProcfsAccess(); + + ::pid_t processID = getpid(); + std::vector listFiles; + EXPECT_EQ(ZE_RESULT_SUCCESS, procfsAccess.getFileDescriptors(processID, listFiles)); +} + +TEST_F(SysmanDeviceFixture, GivenValidProcfsAccessHandleWhenCallingListProcessesThenSuccessIsReturned) { + auto procfsAccess = pLinuxSysmanImp->getProcfsAccess(); + + std::vector<::pid_t> listPid; + EXPECT_EQ(ZE_RESULT_SUCCESS, procfsAccess.listProcesses(listPid)); +} + +TEST_F(SysmanDeviceFixture, GivenValidProcfsAccessHandleAndKillProcessWhenCallingIsAliveThenErrorIsReturned) { + auto procfsAccess = pLinuxSysmanImp->getProcfsAccess(); + int pid = NEO::SysCalls::getProcessId(); + procfsAccess.kill(pid); + EXPECT_FALSE(procfsAccess.isAlive(pid)); +} + TEST_F(SysmanDeviceFixture, GivenCreateProcfsAccessHandleWhenCallinggetProcfsAccessThenCreatedProcfsAccessHandleWillBeRetrieved) { if (pLinuxSysmanImp->pProcfsAccess != nullptr) { // delete previously allocated pProcfsAccess @@ -280,6 +557,7 @@ TEST_F(SysmanDeviceFixture, GivenCreateProcfsAccessHandleWhenCallinggetProcfsAcc } TEST_F(SysmanDeviceFixture, GivenValidPidWhenCallingProcfsAccessIsAliveThenSuccessIsReturned) { + VariableBackup allowFakeDevicePathBackup(&SysCalls::allowFakeDevicePath, true); auto procfsAccess = pLinuxSysmanImp->getProcfsAccess(); EXPECT_TRUE(procfsAccess.isAlive(getpid())); diff --git a/shared/test/common/os_interface/linux/sys_calls_linux_ult.cpp b/shared/test/common/os_interface/linux/sys_calls_linux_ult.cpp index 9fb70c324b..688b4e4d89 100644 --- a/shared/test/common/os_interface/linux/sys_calls_linux_ult.cpp +++ b/shared/test/common/os_interface/linux/sys_calls_linux_ult.cpp @@ -55,6 +55,7 @@ uint32_t munmapFuncCalled = 0u; int (*sysCallsOpen)(const char *pathname, int flags) = nullptr; ssize_t (*sysCallsPread)(int fd, void *buf, size_t count, off_t offset) = nullptr; +ssize_t (*sysCallsPwrite)(int fd, const void *buf, size_t count, off_t offset) = nullptr; int (*sysCallsReadlink)(const char *path, char *buf, size_t bufsize) = nullptr; int (*sysCallsIoctl)(int fileDescriptor, unsigned long int request, void *arg) = nullptr; int (*sysCallsPoll)(struct pollfd *pollFd, unsigned long int numberOfFds, int timeout) = nullptr; @@ -189,6 +190,9 @@ ssize_t pread(int fd, void *buf, size_t count, off_t offset) { } ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) { + if (sysCallsPwrite != nullptr) { + return sysCallsPwrite(fd, buf, count, offset); + } pwriteFuncCalled++; return 0; } diff --git a/shared/test/common/os_interface/linux/sys_calls_linux_ult.h b/shared/test/common/os_interface/linux/sys_calls_linux_ult.h index 8d086be1dd..ebebe65176 100644 --- a/shared/test/common/os_interface/linux/sys_calls_linux_ult.h +++ b/shared/test/common/os_interface/linux/sys_calls_linux_ult.h @@ -17,6 +17,7 @@ namespace SysCalls { extern int (*sysCallsOpen)(const char *pathname, int flags); extern ssize_t (*sysCallsPread)(int fd, void *buf, size_t count, off_t offset); +extern ssize_t (*sysCallsPwrite)(int fd, const void *buf, size_t count, off_t offset); extern int (*sysCallsReadlink)(const char *path, char *buf, size_t bufsize); extern int (*sysCallsIoctl)(int fileDescriptor, unsigned long int request, void *arg); extern int (*sysCallsPoll)(struct pollfd *pollFd, unsigned long int numberOfFds, int timeout);