Fix for Metric Api test that attempts OS (fstat) function.

Signed-off-by: Piotr Maciejewski <piotr.maciejewski@intel.com>
This commit is contained in:
Piotr Maciejewski 2021-03-29 12:01:37 +00:00 committed by Compute-Runtime-Automation
parent d182d77a41
commit 08210f8be5
6 changed files with 41 additions and 3 deletions

View File

@ -7,6 +7,7 @@
#include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/os_interface/linux/os_interface.h"
#include "shared/source/os_interface/linux/sys_calls.h"
#include "level_zero/tools/source/metrics/metric_enumeration_imp.h"
@ -25,7 +26,7 @@ bool MetricEnumeration::getAdapterId(uint32_t &adapterMajor, uint32_t &adapterMi
auto drmFile = drm->getFileDescriptor();
struct stat drmStat = {};
int32_t result = fstat(drmFile, &drmStat);
int32_t result = NEO::SysCalls::fstat(drmFile, &drmStat);
adapterMajor = major(drmStat.st_rdev);
adapterMinor = minor(drmStat.st_rdev);

View File

@ -7,6 +7,7 @@
#include "shared/source/os_interface/device_factory.h"
#include "shared/source/os_interface/linux/os_interface.h"
#include "shared/source/os_interface/linux/sys_calls.h"
#include "opencl/test/unit_test/os_interface/linux/drm_mock.h"
#include "test.h"
@ -19,6 +20,12 @@
using ::testing::_;
using ::testing::Return;
namespace NEO {
namespace SysCalls {
extern int fstatFuncRetVal;
} // namespace SysCalls
} // namespace NEO
namespace L0 {
namespace ult {
@ -328,11 +335,25 @@ TEST_F(MetricEnumerationTestLinux, givenIcorrectOpenMetricDeviceOnAdapterWhenGet
EXPECT_NE(mockMetricEnumeration->openMetricsDiscovery(), ZE_RESULT_SUCCESS);
}
TEST_F(MetricEnumerationTestLinux, givenIcorrectDrmFileForFstaWhenGetMetricsAdapterThenReturnFail) {
TEST_F(MetricEnumerationTestLinux, givenCorrectDrmFileForFstatWhenGetMetricsAdapterThenReturnSuccess) {
uint32_t drmMajor = 0;
uint32_t drmMinor = 0;
VariableBackup<int> fstatBackup(&NEO::SysCalls::fstatFuncRetVal);
NEO::SysCalls::fstatFuncRetVal = 0;
EXPECT_EQ(mockMetricEnumeration->baseGetAdapterId(drmMajor, drmMinor), true);
}
TEST_F(MetricEnumerationTestLinux, givenIncorrectDrmFileForFstatWhenGetMetricsAdapterThenReturnFail) {
uint32_t drmMajor = 0;
uint32_t drmMinor = 0;
VariableBackup<int> fstatBackup(&NEO::SysCalls::fstatFuncRetVal);
NEO::SysCalls::fstatFuncRetVal = -1;
EXPECT_EQ(mockMetricEnumeration->baseGetAdapterId(drmMajor, drmMinor), false);
}

View File

@ -544,6 +544,12 @@ TEST(SysCalls, WhenSysCallsPollCalledThenCallIsRedirectedToOs) {
EXPECT_EQ(0, result);
}
TEST(SysCalls, WhenSysCallsFstatCalledThenCallIsRedirectedToOs) {
struct stat st = {};
auto result = NEO::SysCalls::fstat(0, &st);
EXPECT_EQ(0, result);
}
int main(int argc, char **argv) {
bool useDefaultListener = false;

View File

@ -37,6 +37,7 @@ int ioctlVmCreateReturned = 0u;
uint64_t ioctlVmCreateExtensionArg = 0ull;
constexpr unsigned long int invalidIoctl = static_cast<unsigned long int>(-1);
int setErrno = 0;
int fstatFuncRetVal = 0;
int close(int fileDescriptor) {
closeFuncCalled++;
@ -124,5 +125,8 @@ int poll(struct pollfd *pollFd, unsigned long int numberOfFds, int timeout) {
return 0;
}
int fstat(int fd, struct stat *buf) {
return fstatFuncRetVal;
}
} // namespace SysCalls
} // namespace NEO

View File

@ -8,6 +8,7 @@
#pragma once
#include <iostream>
#include <poll.h>
#include <sys/stat.h>
namespace NEO {
namespace SysCalls {
@ -19,5 +20,6 @@ int getDevicePath(int deviceFd, char *buf, size_t &bufSize);
int access(const char *pathname, int mode);
int readlink(const char *path, char *buf, size_t bufsize);
int poll(struct pollfd *pollFd, unsigned long int numberOfFds, int timeout);
int fstat(int fd, struct stat *buf);
} // namespace SysCalls
} // namespace NEO

View File

@ -43,7 +43,7 @@ int readlink(const char *path, char *buf, size_t bufsize) {
int getDevicePath(int deviceFd, char *buf, size_t &bufSize) {
struct stat st;
if (fstat(deviceFd, &st)) {
if (::fstat(deviceFd, &st)) {
return -1;
}
@ -56,5 +56,9 @@ int getDevicePath(int deviceFd, char *buf, size_t &bufSize) {
int poll(struct pollfd *pollFd, unsigned long int numberOfFds, int timeout) {
return ::poll(pollFd, numberOfFds, timeout);
}
int fstat(int fd, struct stat *buf) {
return ::fstat(fd, buf);
}
} // namespace SysCalls
} // namespace NEO