Added Engine ULTs

Related-To: LOCI-3544

Signed-off-by: Bari, Pratik <pratik.bari@intel.com>
This commit is contained in:
Bari, Pratik
2022-12-13 08:02:09 +00:00
committed by Compute-Runtime-Automation
parent 072963d0f7
commit 0b3c5a6ad2
5 changed files with 790 additions and 92 deletions

View File

@@ -6,12 +6,16 @@
set(L0_TESTS_TOOLS_SYSMAN_ENGINE_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}test_zes_engine.cpp
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}mock_engine.h
)
if((NEO_ENABLE_i915_PRELIM_DETECTION) AND ("${BRANCH_TYPE}" STREQUAL ""))
list(REMOVE_ITEM L0_TESTS_TOOLS_SYSMAN_ENGINE_LINUX
if(NEO_ENABLE_i915_PRELIM_DETECTION)
list(APPEND L0_TESTS_TOOLS_SYSMAN_ENGINE_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/test_zes_engine_prelim.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_engine_prelim.h
)
else()
list(APPEND L0_TESTS_TOOLS_SYSMAN_ENGINE_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/test_zes_engine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_engine.h
)

View File

@@ -36,11 +36,16 @@ class EngineNeoDrm : public Drm {
const int mockFd = 0;
EngineNeoDrm(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceIdDrm>(mockFd, ""), rootDeviceEnvironment) {}
};
template <>
struct Mock<EngineNeoDrm> : public EngineNeoDrm {
Mock<EngineNeoDrm>(RootDeviceEnvironment &rootDeviceEnvironment) : EngineNeoDrm(rootDeviceEnvironment) {}
bool queryEngineInfoMockPositiveTest() {
struct MockEngineNeoDrm : public EngineNeoDrm {
MockEngineNeoDrm(RootDeviceEnvironment &rootDeviceEnvironment) : EngineNeoDrm(rootDeviceEnvironment) {}
bool mockSysmanQueryEngineInfoReturnFalse = true;
bool sysmanQueryEngineInfo() override {
if (mockSysmanQueryEngineInfoReturnFalse != true) {
return mockSysmanQueryEngineInfoReturnFalse;
}
std::vector<NEO::EngineCapabilities> i915engineInfo(6);
i915engineInfo[0].engine.engineClass = drm_i915_gem_engine_class::I915_ENGINE_CLASS_RENDER;
i915engineInfo[0].engine.engineInstance = 0;
@@ -55,16 +60,9 @@ struct Mock<EngineNeoDrm> : public EngineNeoDrm {
i915engineInfo[5].engine.engineClass = I915_INVALID_ENGINE_CLASS;
i915engineInfo[5].engine.engineInstance = 0;
NEO::HardwareInfo hwInfo = *rootDeviceEnvironment.getHardwareInfo();
this->engineInfo.reset(new EngineInfo(this, &hwInfo, i915engineInfo));
this->engineInfo.reset(new EngineInfo(this, i915engineInfo));
return true;
}
bool queryEngineInfoMockReturnFalse() {
return false;
}
MOCK_METHOD(bool, sysmanQueryEngineInfo, (), (override));
};
class MockPmuInterfaceImp : public PmuInterfaceImp {
@@ -72,59 +70,65 @@ class MockPmuInterfaceImp : public PmuInterfaceImp {
using PmuInterfaceImp::perfEventOpen;
MockPmuInterfaceImp(LinuxSysmanImp *pLinuxSysmanImp) : PmuInterfaceImp(pLinuxSysmanImp) {}
};
template <>
struct Mock<MockPmuInterfaceImp> : public MockPmuInterfaceImp {
Mock<MockPmuInterfaceImp>(LinuxSysmanImp *pLinuxSysmanImp) : MockPmuInterfaceImp(pLinuxSysmanImp) {}
int64_t mockedPerfEventOpenAndSuccessReturn(perf_event_attr *attr, pid_t pid, int cpu, int groupFd, uint64_t flags) {
struct MockEnginePmuInterfaceImp : public MockPmuInterfaceImp {
MockEnginePmuInterfaceImp(LinuxSysmanImp *pLinuxSysmanImp) : MockPmuInterfaceImp(pLinuxSysmanImp) {}
int64_t mockPerfEventFailureReturnValue = 0;
int64_t perfEventOpen(perf_event_attr *attr, pid_t pid, int cpu, int groupFd, uint64_t flags) override {
if (mockPerfEventFailureReturnValue == -1) {
return mockPerfEventFailureReturnValue;
}
return mockPmuFd;
}
int64_t mockedPerfEventOpenAndFailureReturn(perf_event_attr *attr, pid_t pid, int cpu, int groupFd, uint64_t flags) {
return -1;
}
int mockedPmuReadAndSuccessReturn(int fd, uint64_t *data, ssize_t sizeOfdata) {
int mockPmuReadFailureReturnValue = 0;
int pmuRead(int fd, uint64_t *data, ssize_t sizeOfdata) override {
if (mockPmuReadFailureReturnValue == -1) {
return mockPmuReadFailureReturnValue;
}
data[0] = mockActiveTime;
data[1] = mockTimestamp;
return 0;
}
int mockedPmuReadAndFailureReturn(int fd, uint64_t *data, ssize_t sizeOfdata) {
return -1;
}
MOCK_METHOD(int64_t, perfEventOpen, (perf_event_attr * attr, pid_t pid, int cpu, int groupFd, uint64_t flags), (override));
MOCK_METHOD(int, pmuRead, (int fd, uint64_t *data, ssize_t sizeOfdata), (override));
};
class EngineSysfsAccess : public SysfsAccess {};
class EngineFsAccess : public FsAccess {};
template <>
struct Mock<EngineFsAccess> : public EngineFsAccess {
MOCK_METHOD(ze_result_t, read, (const std::string file, uint32_t &val), (override));
ze_result_t readValSuccess(const std::string file, uint32_t &val) {
val = 23;
return ZE_RESULT_SUCCESS;
}
ze_result_t readValFailure(const std::string file, uint32_t &val) {
val = 0;
return ZE_RESULT_ERROR_NOT_AVAILABLE;
struct MockEngineFsAccess : public EngineFsAccess {
uint32_t mockReadVal = 23;
ze_result_t mockReadErrorVal = ZE_RESULT_SUCCESS;
ze_result_t readResult = ZE_RESULT_SUCCESS;
ze_result_t read(const std::string file, uint32_t &val) override {
val = mockReadVal;
if (mockReadErrorVal != ZE_RESULT_SUCCESS) {
readResult = mockReadErrorVal;
}
return readResult;
}
};
template <>
struct Mock<EngineSysfsAccess> : public EngineSysfsAccess {
MOCK_METHOD(ze_result_t, readSymLink, (const std::string file, std::string &buf), (override));
ze_result_t getValStringSymLinkSuccess(const std::string file, std::string &val) {
struct MockEngineSysfsAccess : public EngineSysfsAccess {
ze_result_t mockReadSymLinkError = ZE_RESULT_SUCCESS;
ze_result_t readSymLinkResult = ZE_RESULT_SUCCESS;
uint32_t readSymLinkCalled = 0u;
ze_result_t readSymLink(const std::string file, std::string &val) override {
readSymLinkCalled++;
if ((mockReadSymLinkError != ZE_RESULT_SUCCESS) && (readSymLinkCalled == 1)) {
return mockReadSymLinkError;
}
if (file.compare(deviceDir) == 0) {
val = "/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/0000:02:01.0/0000:03:00.0";
return ZE_RESULT_SUCCESS;
}
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
ze_result_t getValStringSymLinkFailure(const std::string file, std::string &val) {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
return readSymLinkResult;
}
Mock<EngineSysfsAccess>() = default;
MockEngineSysfsAccess() = default;
};
using DrmMockEngineInfoFailing = DrmMock;

View File

@@ -0,0 +1,206 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/os_interface/linux/engine_info.h"
#include "shared/source/os_interface/linux/i915_prelim.h"
#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h"
#include "level_zero/tools/source/sysman/engine/linux/os_engine_imp.h"
#include "level_zero/tools/source/sysman/linux/pmu/pmu_imp.h"
#include "sysman/engine/engine_imp.h"
#include "sysman/linux/os_sysman_imp.h"
using namespace NEO;
namespace L0 {
namespace ult {
constexpr int64_t mockPmuFd = 10;
constexpr uint64_t mockTimestamp = 87654321;
constexpr uint64_t mockActiveTime = 987654321;
const uint32_t microSecondsToNanoSeconds = 1000u;
constexpr uint16_t I915_INVALID_ENGINE_CLASS = UINT16_MAX;
const std::string deviceDir("device");
constexpr uint32_t numberOfMockedEnginesForSingleTileDevice = 7u;
constexpr uint32_t numberOfTiles = 2u;
constexpr uint32_t numberOfMockedEnginesForMultiTileDevice = 2u;
struct MockMemoryManagerInEngineSysman : public MemoryManagerMock {
MockMemoryManagerInEngineSysman(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerMock(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {}
};
class EngineNeoDrm : public Drm {
public:
using Drm::engineInfo;
using Drm::setupIoctlHelper;
const int mockFd = 0;
EngineNeoDrm(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceIdDrm>(mockFd, ""), rootDeviceEnvironment) {}
};
struct MockEngineNeoDrm : public EngineNeoDrm {
MockEngineNeoDrm(RootDeviceEnvironment &rootDeviceEnvironment) : EngineNeoDrm(rootDeviceEnvironment) {}
bool mockReadSysmanQueryEngineInfo = false;
bool mockReadSysmanQueryEngineInfoMultiDevice = false;
bool sysmanQueryEngineInfo() override {
if (mockReadSysmanQueryEngineInfo == true) {
return queryEngineInfoMockReturnFalse();
}
if (mockReadSysmanQueryEngineInfoMultiDevice == true) {
return queryEngineInfoForMultiDeviceFixtureMockPositiveTest();
}
std::vector<NEO::EngineCapabilities> i915QueryEngineInfo(numberOfMockedEnginesForSingleTileDevice);
i915QueryEngineInfo[0].engine.engineClass = drm_i915_gem_engine_class::I915_ENGINE_CLASS_RENDER;
i915QueryEngineInfo[0].engine.engineInstance = 0;
i915QueryEngineInfo[1].engine.engineClass = drm_i915_gem_engine_class::I915_ENGINE_CLASS_VIDEO;
i915QueryEngineInfo[1].engine.engineInstance = 0;
i915QueryEngineInfo[2].engine.engineClass = drm_i915_gem_engine_class::I915_ENGINE_CLASS_VIDEO;
i915QueryEngineInfo[2].engine.engineInstance = 1;
i915QueryEngineInfo[3].engine.engineClass = drm_i915_gem_engine_class::I915_ENGINE_CLASS_COPY;
i915QueryEngineInfo[3].engine.engineInstance = 0;
i915QueryEngineInfo[4].engine.engineClass = drm_i915_gem_engine_class::I915_ENGINE_CLASS_VIDEO_ENHANCE;
i915QueryEngineInfo[4].engine.engineInstance = 0;
i915QueryEngineInfo[5].engine.engineClass = PrelimI915::prelim_drm_i915_gem_engine_class::PRELIM_I915_ENGINE_CLASS_COMPUTE;
i915QueryEngineInfo[5].engine.engineInstance = 0;
i915QueryEngineInfo[6].engine.engineClass = I915_INVALID_ENGINE_CLASS;
i915QueryEngineInfo[6].engine.engineInstance = 0;
this->engineInfo.reset(new EngineInfo(this, i915QueryEngineInfo));
return true;
}
bool queryEngineInfoMockReturnFalse() {
return false;
}
bool queryEngineInfoForMultiDeviceFixtureMockPositiveTest() {
// Fill distanceInfos vector with dummy values
std::vector<NEO::DistanceInfo> distanceInfos = {
{{1, 0}, {drm_i915_gem_engine_class::I915_ENGINE_CLASS_RENDER, 0}, 0},
{{1, 1}, {drm_i915_gem_engine_class::I915_ENGINE_CLASS_VIDEO, 0}, 0}};
std::vector<QueryItem> queryItems{distanceInfos.size()};
for (auto i = 0u; i < distanceInfos.size(); i++) {
queryItems[i].queryId = PRELIM_DRM_I915_QUERY_DISTANCE_INFO;
queryItems[i].length = sizeof(PrelimI915::prelim_drm_i915_query_distance_info);
queryItems[i].flags = 0u;
queryItems[i].dataPtr = reinterpret_cast<uint64_t>(&distanceInfos[i]);
}
// Fill i915QueryEngineInfo with dummy values
std::vector<NEO::EngineCapabilities> i915QueryEngineInfo(numberOfMockedEnginesForMultiTileDevice);
i915QueryEngineInfo[0].engine.engineClass = drm_i915_gem_engine_class::I915_ENGINE_CLASS_RENDER;
i915QueryEngineInfo[0].engine.engineInstance = 0;
i915QueryEngineInfo[1].engine.engineClass = drm_i915_gem_engine_class::I915_ENGINE_CLASS_VIDEO;
i915QueryEngineInfo[1].engine.engineInstance = 0;
this->engineInfo.reset(new EngineInfo(this, numberOfTiles, distanceInfos, queryItems, i915QueryEngineInfo));
return true;
}
};
class MockPmuInterfaceImp : public PmuInterfaceImp {
public:
using PmuInterfaceImp::perfEventOpen;
MockPmuInterfaceImp(LinuxSysmanImp *pLinuxSysmanImp) : PmuInterfaceImp(pLinuxSysmanImp) {}
};
struct MockEnginePmuInterfaceImp : public MockPmuInterfaceImp {
MockEnginePmuInterfaceImp(LinuxSysmanImp *pLinuxSysmanImp) : MockPmuInterfaceImp(pLinuxSysmanImp) {}
bool mockPmuRead = false;
bool mockPerfEventOpenRead = false;
int64_t perfEventOpen(perf_event_attr *attr, pid_t pid, int cpu, int groupFd, uint64_t flags) override {
if (mockPerfEventOpenRead == true) {
return mockedPerfEventOpenAndFailureReturn(attr, pid, cpu, groupFd, flags);
}
return mockPmuFd;
}
int64_t mockedPerfEventOpenAndFailureReturn(perf_event_attr *attr, pid_t pid, int cpu, int groupFd, uint64_t flags) {
return -1;
}
int pmuRead(int fd, uint64_t *data, ssize_t sizeOfdata) override {
if (mockPmuRead == true) {
return mockedPmuReadAndFailureReturn(fd, data, sizeOfdata);
}
data[0] = mockActiveTime;
data[1] = mockTimestamp;
return 0;
}
int mockedPmuReadAndFailureReturn(int fd, uint64_t *data, ssize_t sizeOfdata) {
return -1;
}
};
class EngineSysfsAccess : public SysfsAccess {};
class EngineFsAccess : public FsAccess {};
struct MockEngineFsAccess : public EngineFsAccess {
bool mockReadVal = false;
ze_result_t read(const std::string file, uint32_t &val) override {
if (mockReadVal == true) {
return readValFailure(file, val);
}
val = 23;
return ZE_RESULT_SUCCESS;
}
ze_result_t readValFailure(const std::string file, uint32_t &val) {
val = 0;
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
};
struct MockEngineSysfsAccess : public EngineSysfsAccess {
bool mockReadSymLinkFailure = false;
bool mockReadSymLinkSuccess = false;
ze_result_t readSymLink(const std::string file, std::string &val) override {
if (mockReadSymLinkFailure == true) {
return getValStringSymLinkFailure(file, val);
}
if (mockReadSymLinkSuccess == true) {
return getValStringSymLinkSuccess(file, val);
}
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
ze_result_t getValStringSymLinkSuccess(const std::string file, std::string &val) {
if (file.compare(deviceDir) == 0) {
val = "/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/0000:02:01.0/0000:03:00.0";
return ZE_RESULT_SUCCESS;
}
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
ze_result_t getValStringSymLinkFailure(const std::string file, std::string &val) {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
MockEngineSysfsAccess() = default;
};
} // namespace ult
} // namespace L0

View File

@@ -20,15 +20,15 @@ constexpr uint32_t handleComponentCount = 6u;
class ZesEngineFixture : public SysmanDeviceFixture {
protected:
std::vector<ze_device_handle_t> deviceHandles;
std::unique_ptr<Mock<EngineNeoDrm>> pDrm;
std::unique_ptr<Mock<MockPmuInterfaceImp>> pPmuInterface;
std::unique_ptr<MockEngineNeoDrm> pDrm;
std::unique_ptr<MockEnginePmuInterfaceImp> pPmuInterface;
Drm *pOriginalDrm = nullptr;
PmuInterface *pOriginalPmuInterface = nullptr;
MemoryManager *pMemoryManagerOriginal = nullptr;
std::unique_ptr<MockMemoryManagerInEngineSysman> pMemoryManager;
std::unique_ptr<Mock<EngineSysfsAccess>> pSysfsAccess;
std::unique_ptr<MockEngineSysfsAccess> pSysfsAccess;
SysfsAccess *pSysfsAccessOriginal = nullptr;
std::unique_ptr<Mock<EngineFsAccess>> pFsAccess;
std::unique_ptr<MockEngineFsAccess> pFsAccess;
FsAccess *pFsAccessOriginal = nullptr;
void SetUp() override {
@@ -37,37 +37,26 @@ class ZesEngineFixture : public SysmanDeviceFixture {
}
SysmanDeviceFixture::SetUp();
pMemoryManagerOriginal = device->getDriverHandle()->getMemoryManager();
pMemoryManager = std::make_unique<::testing::NiceMock<MockMemoryManagerInEngineSysman>>(*neoDevice->getExecutionEnvironment());
pMemoryManager = std::make_unique<MockMemoryManagerInEngineSysman>(*neoDevice->getExecutionEnvironment());
pMemoryManager->localMemorySupported[0] = false;
device->getDriverHandle()->setMemoryManager(pMemoryManager.get());
pSysfsAccessOriginal = pLinuxSysmanImp->pSysfsAccess;
pSysfsAccess = std::make_unique<NiceMock<Mock<EngineSysfsAccess>>>();
pSysfsAccess = std::make_unique<MockEngineSysfsAccess>();
pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get();
pFsAccessOriginal = pLinuxSysmanImp->pFsAccess;
pFsAccess = std::make_unique<NiceMock<Mock<EngineFsAccess>>>();
pFsAccess = std::make_unique<MockEngineFsAccess>();
pLinuxSysmanImp->pFsAccess = pFsAccess.get();
pDrm = std::make_unique<NiceMock<Mock<EngineNeoDrm>>>(const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment()));
pDrm = std::make_unique<MockEngineNeoDrm>(const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment()));
pDrm->setupIoctlHelper(neoDevice->getRootDeviceEnvironment().getHardwareInfo()->platform.eProductFamily);
pPmuInterface = std::make_unique<NiceMock<Mock<MockPmuInterfaceImp>>>(pLinuxSysmanImp);
pPmuInterface = std::make_unique<MockEnginePmuInterfaceImp>(pLinuxSysmanImp);
pOriginalDrm = pLinuxSysmanImp->pDrm;
pOriginalPmuInterface = pLinuxSysmanImp->pPmuInterface;
pLinuxSysmanImp->pDrm = pDrm.get();
pLinuxSysmanImp->pPmuInterface = pPmuInterface.get();
ON_CALL(*pDrm.get(), sysmanQueryEngineInfo())
.WillByDefault(::testing::Invoke(pDrm.get(), &Mock<EngineNeoDrm>::queryEngineInfoMockPositiveTest));
ON_CALL(*pPmuInterface.get(), perfEventOpen(_, _, _, _, _))
.WillByDefault(::testing::Invoke(pPmuInterface.get(), &Mock<MockPmuInterfaceImp>::mockedPerfEventOpenAndSuccessReturn));
ON_CALL(*pPmuInterface.get(), pmuRead(_, _, _))
.WillByDefault(::testing::Invoke(pPmuInterface.get(), &Mock<MockPmuInterfaceImp>::mockedPmuReadAndSuccessReturn));
ON_CALL(*pSysfsAccess.get(), readSymLink(_, _))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<EngineSysfsAccess>::getValStringSymLinkSuccess));
ON_CALL(*pFsAccess.get(), read(_, _))
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EngineFsAccess>::readValSuccess));
pFsAccess->mockReadVal = 23;
for (auto handle : pSysmanDeviceImp->pEngineHandleContext->handleList) {
delete handle;
@@ -83,6 +72,7 @@ class ZesEngineFixture : public SysmanDeviceFixture {
deviceHandles.resize(subDeviceCount, nullptr);
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
}
getEngineHandles(0);
}
@@ -163,7 +153,7 @@ TEST_F(ZesEngineFixture, GivenValidEngineHandleAndIntegratedDeviceWhenCallingZes
}
TEST_F(ZesEngineFixture, GivenValidEngineHandleAndDiscreteDeviceWhenCallingZesEngineGetActivityThenVerifyCallReturnsSuccess) {
auto pMemoryManagerTest = std::make_unique<::testing::NiceMock<MockMemoryManagerInEngineSysman>>(*neoDevice->getExecutionEnvironment());
auto pMemoryManagerTest = std::make_unique<MockMemoryManagerInEngineSysman>(*neoDevice->getExecutionEnvironment());
pMemoryManagerTest->localMemorySupported[0] = true;
device->getDriverHandle()->setMemoryManager(pMemoryManagerTest.get());
zes_engine_stats_t stats = {};
@@ -178,21 +168,16 @@ TEST_F(ZesEngineFixture, GivenValidEngineHandleAndDiscreteDeviceWhenCallingZesEn
}
TEST_F(ZesEngineFixture, GivenTestDiscreteDevicesAndValidEngineHandleWhenCallingZesEngineGetActivityAndPMUGetEventTypeFailsThenVerifyEngineGetActivityReturnsFailure) {
auto pMemoryManagerTest = std::make_unique<::testing::NiceMock<MockMemoryManagerInEngineSysman>>(*neoDevice->getExecutionEnvironment());
auto pMemoryManagerTest = std::make_unique<MockMemoryManagerInEngineSysman>(*neoDevice->getExecutionEnvironment());
pMemoryManagerTest->localMemorySupported[0] = true;
device->getDriverHandle()->setMemoryManager(pMemoryManagerTest.get());
ON_CALL(*pSysfsAccess.get(), readSymLink(_, _))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<EngineSysfsAccess>::getValStringSymLinkFailure));
pSysfsAccess->mockReadSymLinkError = ZE_RESULT_ERROR_NOT_AVAILABLE;
auto pOsEngineTest1 = OsEngine::create(pOsSysman, ZES_ENGINE_GROUP_RENDER_SINGLE, 0u, 0u, false);
zes_engine_stats_t stats = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pOsEngineTest1->getActivity(&stats));
ON_CALL(*pSysfsAccess.get(), readSymLink(_, _))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<EngineSysfsAccess>::getValStringSymLinkSuccess));
ON_CALL(*pFsAccess.get(), read(_, _))
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EngineFsAccess>::readValFailure));
pFsAccess->mockReadVal = 0;
pFsAccess->mockReadErrorVal = ZE_RESULT_ERROR_NOT_AVAILABLE;
auto pOsEngineTest2 = OsEngine::create(pOsSysman, ZES_ENGINE_GROUP_RENDER_SINGLE, 0u, 0u, false);
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pOsEngineTest2->getActivity(&stats));
@@ -202,9 +187,8 @@ TEST_F(ZesEngineFixture, GivenTestDiscreteDevicesAndValidEngineHandleWhenCalling
TEST_F(ZesEngineFixture, GivenTestIntegratedDevicesAndValidEngineHandleWhenCallingZesEngineGetActivityAndPMUGetEventTypeFailsThenVerifyEngineGetActivityReturnsFailure) {
zes_engine_stats_t stats = {};
ON_CALL(*pFsAccess.get(), read(_, _))
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EngineFsAccess>::readValFailure));
pFsAccess->mockReadVal = 0;
pFsAccess->mockReadErrorVal = ZE_RESULT_ERROR_NOT_AVAILABLE;
auto pOsEngineTest1 = OsEngine::create(pOsSysman, ZES_ENGINE_GROUP_RENDER_SINGLE, 0u, 0u, false);
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pOsEngineTest1->getActivity(&stats));
@@ -212,8 +196,7 @@ TEST_F(ZesEngineFixture, GivenTestIntegratedDevicesAndValidEngineHandleWhenCalli
}
TEST_F(ZesEngineFixture, GivenValidEngineHandleWhenCallingZesEngineGetActivityAndPmuReadFailsThenVerifyEngineGetActivityReturnsFailure) {
ON_CALL(*pPmuInterface.get(), pmuRead(_, _, _))
.WillByDefault(::testing::Invoke(pPmuInterface.get(), &Mock<MockPmuInterfaceImp>::mockedPmuReadAndFailureReturn));
pPmuInterface->mockPmuReadFailureReturnValue = -1;
zes_engine_stats_t stats = {};
auto handles = getEngineHandles(handleComponentCount);
EXPECT_EQ(handleComponentCount, handles.size());
@@ -224,18 +207,14 @@ TEST_F(ZesEngineFixture, GivenValidEngineHandleWhenCallingZesEngineGetActivityAn
}
TEST_F(ZesEngineFixture, GivenValidEngineHandleWhenCallingZesEngineGetActivityAndperfEventOpenFailsThenVerifyEngineGetActivityReturnsFailure) {
ON_CALL(*pPmuInterface.get(), perfEventOpen(_, _, _, _, _))
.WillByDefault(::testing::Invoke(pPmuInterface.get(), &Mock<MockPmuInterfaceImp>::mockedPerfEventOpenAndFailureReturn));
pPmuInterface->mockPerfEventFailureReturnValue = -1;
MockPmuInterfaceImp pPmuInterfaceImp(pLinuxSysmanImp);
EXPECT_EQ(-1, pPmuInterface->pmuInterfaceOpen(0, -1, 0));
}
TEST_F(ZesEngineFixture, GivenValidOsSysmanPointerWhenRetrievingEngineTypeAndInstancesAndIfEngineInfoQueryFailsThenErrorIsReturned) {
std::set<std::pair<zes_engine_group_t, EngineInstanceSubDeviceId>> engineGroupInstance;
ON_CALL(*pDrm.get(), sysmanQueryEngineInfo())
.WillByDefault(::testing::Invoke(pDrm.get(), &Mock<EngineNeoDrm>::queryEngineInfoMockReturnFalse));
pDrm->mockSysmanQueryEngineInfoReturnFalse = false;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, OsEngine::getNumEngineTypeAndInstances(engineGroupInstance, pOsSysman));
}

View File

@@ -0,0 +1,505 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/test/common/libult/linux/drm_mock.h"
#include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h"
#include "mock_engine_prelim.h"
extern bool sysmanUltsEnable;
using ::testing::Matcher;
using ::testing::Return;
class OsEngine;
namespace L0 {
namespace ult {
constexpr uint32_t handleComponentCount = 13u;
constexpr uint32_t handleCountForMultiDeviceFixture = 7u;
class ZesEngineFixture : public SysmanDeviceFixture {
protected:
std::vector<ze_device_handle_t> deviceHandles;
std::unique_ptr<MockEngineNeoDrm> pDrm;
std::unique_ptr<MockEnginePmuInterfaceImp> pPmuInterface;
Drm *pOriginalDrm = nullptr;
PmuInterface *pOriginalPmuInterface = nullptr;
MemoryManager *pMemoryManagerOriginal = nullptr;
std::unique_ptr<MockMemoryManagerInEngineSysman> pMemoryManager;
std::unique_ptr<MockEngineSysfsAccess> pSysfsAccess;
SysfsAccess *pSysfsAccessOriginal = nullptr;
std::unique_ptr<MockEngineFsAccess> pFsAccess;
FsAccess *pFsAccessOriginal = nullptr;
void SetUp() override {
if (!sysmanUltsEnable) {
GTEST_SKIP();
}
SysmanDeviceFixture::SetUp();
pMemoryManagerOriginal = device->getDriverHandle()->getMemoryManager();
pMemoryManager = std::make_unique<MockMemoryManagerInEngineSysman>(*neoDevice->getExecutionEnvironment());
pMemoryManager->localMemorySupported[0] = false;
device->getDriverHandle()->setMemoryManager(pMemoryManager.get());
pSysfsAccessOriginal = pLinuxSysmanImp->pSysfsAccess;
pSysfsAccess = std::make_unique<MockEngineSysfsAccess>();
pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get();
pFsAccessOriginal = pLinuxSysmanImp->pFsAccess;
pFsAccess = std::make_unique<MockEngineFsAccess>();
pLinuxSysmanImp->pFsAccess = pFsAccess.get();
pDrm = std::make_unique<MockEngineNeoDrm>(const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment()));
pDrm->setupIoctlHelper(neoDevice->getRootDeviceEnvironment().getHardwareInfo()->platform.eProductFamily);
pPmuInterface = std::make_unique<MockEnginePmuInterfaceImp>(pLinuxSysmanImp);
pOriginalDrm = pLinuxSysmanImp->pDrm;
pOriginalPmuInterface = pLinuxSysmanImp->pPmuInterface;
pLinuxSysmanImp->pDrm = pDrm.get();
pLinuxSysmanImp->pPmuInterface = pPmuInterface.get();
for (auto handle : pSysmanDeviceImp->pEngineHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pEngineHandleContext->handleList.clear();
uint32_t subDeviceCount = 0;
// We received a device handle. Check for subdevices in this device
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, nullptr);
if (subDeviceCount == 0) {
deviceHandles.resize(1, device->toHandle());
} else {
deviceHandles.resize(subDeviceCount, nullptr);
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
}
getEngineHandles(0);
}
void TearDown() override {
if (!sysmanUltsEnable) {
GTEST_SKIP();
}
device->getDriverHandle()->setMemoryManager(pMemoryManagerOriginal);
pLinuxSysmanImp->pDrm = pOriginalDrm;
pLinuxSysmanImp->pPmuInterface = pOriginalPmuInterface;
pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOriginal;
pLinuxSysmanImp->pFsAccess = pFsAccessOriginal;
SysmanDeviceFixture::TearDown();
}
std::vector<zes_engine_handle_t> getEngineHandles(uint32_t count) {
std::vector<zes_engine_handle_t> handles(count, nullptr);
EXPECT_EQ(zesDeviceEnumEngineGroups(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS);
return handles;
}
};
TEST_F(ZesEngineFixture, GivenComponentCountZeroWhenCallingzesDeviceEnumEngineGroupsThenNonZeroCountIsReturnedAndVerifyCallSucceeds) {
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEnumEngineGroups(device->toHandle(), &count, NULL));
EXPECT_EQ(count, handleComponentCount);
uint32_t testcount = count + 1;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEnumEngineGroups(device->toHandle(), &testcount, NULL));
EXPECT_EQ(testcount, count);
count = 0;
std::vector<zes_engine_handle_t> handles(count, nullptr);
EXPECT_EQ(zesDeviceEnumEngineGroups(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS);
EXPECT_EQ(count, handleComponentCount);
}
TEST_F(ZesEngineFixture, GivenValidEngineHandlesWhenCallingZesEngineGetPropertiesThenVerifyCallSucceeds) {
zes_engine_properties_t properties;
auto handle = getEngineHandles(handleComponentCount);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[0], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_ALL, properties.type);
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[1], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_COMPUTE_ALL, properties.type);
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[2], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_MEDIA_ALL, properties.type);
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[3], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_COPY_ALL, properties.type);
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[4], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_COMPUTE_SINGLE, properties.type);
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[5], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_RENDER_SINGLE, properties.type);
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[6], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_MEDIA_DECODE_SINGLE, properties.type);
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[7], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_MEDIA_DECODE_SINGLE, properties.type);
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[8], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_MEDIA_ENCODE_SINGLE, properties.type);
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[9], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_MEDIA_ENCODE_SINGLE, properties.type);
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[10], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_COPY_SINGLE, properties.type);
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[11], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_MEDIA_ENHANCEMENT_SINGLE, properties.type);
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[12], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_RENDER_ALL, properties.type);
EXPECT_FALSE(properties.onSubdevice);
}
TEST_F(ZesEngineFixture, GivenValidEngineHandleAndIntegratedDeviceWhenCallingZesEngineGetActivityThenVerifyCallReturnsSuccess) {
zes_engine_stats_t stats = {};
auto handles = getEngineHandles(handleComponentCount);
EXPECT_EQ(handleComponentCount, handles.size());
for (auto handle : handles) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetActivity(handle, &stats));
EXPECT_EQ(mockActiveTime / microSecondsToNanoSeconds, stats.activeTime);
EXPECT_EQ(mockTimestamp / microSecondsToNanoSeconds, stats.timestamp);
}
}
TEST_F(ZesEngineFixture, GivenValidEngineHandleAndDiscreteDeviceWhenCallingZesEngineGetActivityThenVerifyCallReturnsSuccess) {
auto pMemoryManagerTest = std::make_unique<MockMemoryManagerInEngineSysman>(*neoDevice->getExecutionEnvironment());
pMemoryManagerTest->localMemorySupported[0] = true;
device->getDriverHandle()->setMemoryManager(pMemoryManagerTest.get());
zes_engine_stats_t stats = {};
auto handles = getEngineHandles(handleComponentCount);
EXPECT_EQ(handleComponentCount, handles.size());
for (auto handle : handles) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetActivity(handle, &stats));
EXPECT_EQ(mockActiveTime / microSecondsToNanoSeconds, stats.activeTime);
EXPECT_EQ(mockTimestamp / microSecondsToNanoSeconds, stats.timestamp);
}
}
TEST_F(ZesEngineFixture, GivenTestDiscreteDevicesAndValidEngineHandleWhenCallingZesEngineGetActivityAndPMUGetEventTypeFailsThenVerifyEngineGetActivityReturnsFailure) {
auto pMemoryManagerTest = std::make_unique<MockMemoryManagerInEngineSysman>(*neoDevice->getExecutionEnvironment());
pMemoryManagerTest->localMemorySupported[0] = true;
device->getDriverHandle()->setMemoryManager(pMemoryManagerTest.get());
pSysfsAccess->mockReadSymLinkFailure = true;
auto pOsEngineTest1 = OsEngine::create(pOsSysman, ZES_ENGINE_GROUP_RENDER_SINGLE, 0u, 0u, false);
zes_engine_stats_t stats = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pOsEngineTest1->getActivity(&stats));
pSysfsAccess->mockReadSymLinkSuccess = true;
pFsAccess->mockReadVal = true;
auto pOsEngineTest2 = OsEngine::create(pOsSysman, ZES_ENGINE_GROUP_RENDER_SINGLE, 0u, 0u, false);
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pOsEngineTest2->getActivity(&stats));
delete pOsEngineTest1;
delete pOsEngineTest2;
}
TEST_F(ZesEngineFixture, GivenUnknownEngineTypeThengetEngineGroupFromTypeReturnsGroupAllEngineGroup) {
auto group = LinuxEngineImp::getGroupFromEngineType(ZES_ENGINE_GROUP_3D_SINGLE);
EXPECT_EQ(group, ZES_ENGINE_GROUP_ALL);
}
TEST_F(ZesEngineFixture, GivenTestIntegratedDevicesAndValidEngineHandleWhenCallingZesEngineGetActivityAndPMUGetEventTypeFailsThenVerifyEngineGetActivityReturnsFailure) {
zes_engine_stats_t stats = {};
pFsAccess->mockReadVal = true;
auto pOsEngineTest1 = OsEngine::create(pOsSysman, ZES_ENGINE_GROUP_RENDER_SINGLE, 0u, 0u, false);
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pOsEngineTest1->getActivity(&stats));
delete pOsEngineTest1;
}
TEST_F(ZesEngineFixture, GivenValidEngineHandleWhenCallingZesEngineGetActivityAndPmuReadFailsThenVerifyEngineGetActivityReturnsFailure) {
pPmuInterface->mockPmuRead = true;
zes_engine_stats_t stats = {};
auto handles = getEngineHandles(handleComponentCount);
EXPECT_EQ(handleComponentCount, handles.size());
for (auto handle : handles) {
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesEngineGetActivity(handle, &stats));
}
}
TEST_F(ZesEngineFixture, GivenValidEngineHandleWhenCallingZesEngineGetActivityAndperfEventOpenFailsThenVerifyEngineGetActivityReturnsFailure) {
pPmuInterface->mockPerfEventOpenRead = true;
MockPmuInterfaceImp pPmuInterfaceImp(pLinuxSysmanImp);
EXPECT_EQ(-1, pPmuInterface->pmuInterfaceOpen(0, -1, 0));
}
TEST_F(ZesEngineFixture, GivenValidOsSysmanPointerWhenRetrievingEngineTypeAndInstancesAndIfEngineInfoQueryFailsThenErrorIsReturned) {
std::set<std::pair<zes_engine_group_t, std::pair<uint32_t, uint32_t>>> engineGroupInstance;
pDrm->mockReadSysmanQueryEngineInfo = true;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, OsEngine::getNumEngineTypeAndInstances(engineGroupInstance, pOsSysman));
}
TEST_F(ZesEngineFixture, GivenHandleQueryItemCalledWithInvalidEngineTypeThenzesDeviceEnumEngineGroupsSucceeds) {
auto drm = std::make_unique<DrmMockEngine>(const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment()));
pLinuxSysmanImp->pDrm = drm.get();
for (auto handle : pSysmanDeviceImp->pEngineHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pEngineHandleContext->handleList.clear();
pSysmanDeviceImp->pEngineHandleContext->init(deviceHandles);
uint32_t count = 0;
uint32_t mockHandleCount = 5u;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEnumEngineGroups(device->toHandle(), &count, NULL));
EXPECT_EQ(count, mockHandleCount);
}
TEST_F(ZesEngineFixture, GivenHandleQueryItemCalledWhenPmuInterfaceOpenFailsThenzesDeviceEnumEngineGroupsSucceedsAndHandleCountIsZero) {
pFsAccess->mockReadVal = true;
for (auto handle : pSysmanDeviceImp->pEngineHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pEngineHandleContext->handleList.clear();
pSysmanDeviceImp->pEngineHandleContext->init(deviceHandles);
uint32_t count = 0;
uint32_t mockHandleCount = 0u;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEnumEngineGroups(device->toHandle(), &count, NULL));
EXPECT_EQ(count, mockHandleCount);
}
TEST_F(ZesEngineFixture, GivenValidDrmObjectWhenCallingsysmanQueryEngineInfoMethodThenSuccessIsReturned) {
auto drm = std::make_unique<DrmMockEngine>(const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment()));
pLinuxSysmanImp->pDrm = drm.get();
ASSERT_NE(nullptr, drm);
EXPECT_TRUE(drm->sysmanQueryEngineInfo());
auto engineInfo = drm->getEngineInfo();
ASSERT_NE(nullptr, engineInfo);
}
TEST_F(ZesEngineFixture, GivenValidEngineHandleAndHandleCountZeroWhenCallingReInitThenValidCountIsReturnedAndVerifyzesDeviceEnumEngineGroupsSucceeds) {
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEnumEngineGroups(device->toHandle(), &count, NULL));
EXPECT_EQ(count, handleComponentCount);
for (auto handle : pSysmanDeviceImp->pEngineHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pEngineHandleContext->handleList.clear();
pLinuxSysmanImp->reInitSysmanDeviceResources();
count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEnumEngineGroups(device->toHandle(), &count, NULL));
EXPECT_EQ(count, handleComponentCount);
}
class ZesEngineMultiFixture : public SysmanMultiDeviceFixture {
protected:
std::vector<ze_device_handle_t> deviceHandles;
std::unique_ptr<MockEnginePmuInterfaceImp> pPmuInterface;
PmuInterface *pOriginalPmuInterface = nullptr;
std::unique_ptr<MockEngineNeoDrm> pDrm;
Drm *pOriginalDrm = nullptr;
std::unique_ptr<MockEngineSysfsAccess> pSysfsAccess;
SysfsAccess *pSysfsAccessOriginal = nullptr;
std::unique_ptr<MockEngineFsAccess> pFsAccess;
FsAccess *pFsAccessOriginal = nullptr;
void SetUp() override {
if (!sysmanUltsEnable) {
GTEST_SKIP();
}
SysmanMultiDeviceFixture::SetUp();
pSysfsAccessOriginal = pLinuxSysmanImp->pSysfsAccess;
pSysfsAccess = std::make_unique<MockEngineSysfsAccess>();
pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get();
pFsAccessOriginal = pLinuxSysmanImp->pFsAccess;
pFsAccess = std::make_unique<MockEngineFsAccess>();
pLinuxSysmanImp->pFsAccess = pFsAccess.get();
pDrm = std::make_unique<MockEngineNeoDrm>(const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment()));
pDrm->setupIoctlHelper(neoDevice->getRootDeviceEnvironment().getHardwareInfo()->platform.eProductFamily);
pPmuInterface = std::make_unique<MockEnginePmuInterfaceImp>(pLinuxSysmanImp);
pOriginalDrm = pLinuxSysmanImp->pDrm;
pOriginalPmuInterface = pLinuxSysmanImp->pPmuInterface;
pLinuxSysmanImp->pDrm = pDrm.get();
pLinuxSysmanImp->pPmuInterface = pPmuInterface.get();
pDrm->mockReadSysmanQueryEngineInfoMultiDevice = true;
pSysfsAccess->mockReadSymLinkSuccess = true;
for (auto handle : pSysmanDeviceImp->pEngineHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pEngineHandleContext->handleList.clear();
uint32_t subDeviceCount = 0;
// We received a device handle. Check for subdevices in this device
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, nullptr);
if (subDeviceCount == 0) {
deviceHandles.resize(1, device->toHandle());
} else {
deviceHandles.resize(subDeviceCount, nullptr);
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
}
getEngineHandles(0);
}
void TearDown() override {
if (!sysmanUltsEnable) {
GTEST_SKIP();
}
SysmanMultiDeviceFixture::TearDown();
pLinuxSysmanImp->pDrm = pOriginalDrm;
pLinuxSysmanImp->pPmuInterface = pOriginalPmuInterface;
pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOriginal;
pLinuxSysmanImp->pFsAccess = pFsAccessOriginal;
}
std::vector<zes_engine_handle_t> getEngineHandles(uint32_t count) {
std::vector<zes_engine_handle_t> handles(count, nullptr);
EXPECT_EQ(zesDeviceEnumEngineGroups(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS);
return handles;
}
};
TEST_F(ZesEngineMultiFixture, GivenComponentCountZeroWhenCallingzesDeviceEnumEngineGroupsThenNonZeroCountIsReturnedAndVerifyCallSucceeds) {
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEnumEngineGroups(device->toHandle(), &count, NULL));
EXPECT_EQ(count, handleCountForMultiDeviceFixture);
uint32_t testcount = count + 1;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEnumEngineGroups(device->toHandle(), &testcount, NULL));
EXPECT_EQ(testcount, count);
count = 0;
std::vector<zes_engine_handle_t> handles(count, nullptr);
EXPECT_EQ(zesDeviceEnumEngineGroups(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS);
EXPECT_EQ(count, handleCountForMultiDeviceFixture);
}
TEST_F(ZesEngineMultiFixture, GivenValidEngineHandlesWhenCallingZesEngineGetPropertiesThenVerifyCallSucceeds) {
zes_engine_properties_t properties;
auto handle = getEngineHandles(handleCountForMultiDeviceFixture);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[0], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_ALL, properties.type);
EXPECT_TRUE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 0u);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[1], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_ALL, properties.type);
EXPECT_TRUE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 1u);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[2], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_MEDIA_ALL, properties.type);
EXPECT_TRUE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 1u);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[3], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_RENDER_SINGLE, properties.type);
EXPECT_TRUE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 0u);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[4], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_MEDIA_DECODE_SINGLE, properties.type);
EXPECT_TRUE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 1u);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[5], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_MEDIA_ENCODE_SINGLE, properties.type);
EXPECT_TRUE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 1u);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[6], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_RENDER_ALL, properties.type);
EXPECT_TRUE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 0u);
}
TEST_F(ZesEngineMultiFixture, GivenHandleQueryItemCalledWhenPmuInterfaceOpenFailsThenzesDeviceEnumEngineGroupsSucceedsAndHandleCountIsZero) {
pFsAccess->mockReadVal = true;
for (auto handle : pSysmanDeviceImp->pEngineHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pEngineHandleContext->handleList.clear();
pSysmanDeviceImp->pEngineHandleContext->init(deviceHandles);
uint32_t count = 0;
uint32_t mockHandleCount = 0u;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEnumEngineGroups(device->toHandle(), &count, NULL));
EXPECT_EQ(count, mockHandleCount);
}
class ZesEngineAffinityMaskFixture : public ZesEngineMultiFixture {
void SetUp() override {
if (!sysmanUltsEnable) {
GTEST_SKIP();
}
NEO::DebugManager.flags.ZE_AFFINITY_MASK.set("0.1");
ZesEngineMultiFixture::SetUp();
}
void TearDown() override {
if (!sysmanUltsEnable) {
GTEST_SKIP();
}
ZesEngineMultiFixture::TearDown();
}
DebugManagerStateRestore restorer;
};
TEST_F(ZesEngineAffinityMaskFixture, GivenValidEngineHandlesWhenCallingZesEngineGetPropertiesWhenAffinityMaskIsSetThenVerifyCallSucceeds) {
zes_engine_properties_t properties;
uint32_t handleCountForEngineAffinityMaskFixture = 4u;
auto handle = getEngineHandles(handleCountForEngineAffinityMaskFixture);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[0], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_ALL, properties.type);
EXPECT_TRUE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 1u);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[1], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_MEDIA_ALL, properties.type);
EXPECT_TRUE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 1u);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[2], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_MEDIA_DECODE_SINGLE, properties.type);
EXPECT_TRUE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 1u);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesEngineGetProperties(handle[3], &properties));
EXPECT_EQ(ZES_ENGINE_GROUP_MEDIA_ENCODE_SINGLE, properties.type);
EXPECT_TRUE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 1u);
}
} // namespace ult
} // namespace L0