refactor: move i915 specific logic to ioctl helper i915

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2024-12-17 14:41:33 +00:00
committed by Compute-Runtime-Automation
parent 46a0c87168
commit 270570c5d3
11 changed files with 69 additions and 145 deletions

View File

@@ -292,16 +292,33 @@ TEST(DrmTest, WhenGettingRevisionIdThenCorrectIdIsReturned) {
auto hwInfo = pDrm->getRootDeviceEnvironment().getMutableHardwareInfo();
pDrm->storedDeviceID = 0x1234;
pDrm->storedDeviceRevID = 0xB;
static constexpr uint16_t mockDeviceId = 0x1234;
static constexpr uint16_t mockRevisionId = 0xB;
hwInfo->platform.usDeviceID = 0;
hwInfo->platform.usRevId = 0;
VariableBackup<decltype(SysCalls::sysCallsIoctl)> mockIoctl(&SysCalls::sysCallsIoctl);
SysCalls::sysCallsIoctl = [](int fileDescriptor, unsigned long int request, void *arg) -> int {
if (request == DRM_IOCTL_I915_GETPARAM) {
auto getParam = reinterpret_cast<GetParam *>(arg);
if (getParam->param == I915_PARAM_CHIPSET_ID) {
*getParam->value = mockDeviceId;
} else if (getParam->param == I915_PARAM_REVISION) {
*getParam->value = mockRevisionId;
} else {
return -1;
}
return 0;
}
return 1;
};
EXPECT_TRUE(pDrm->queryDeviceIdAndRevision());
EXPECT_EQ(pDrm->storedDeviceID, hwInfo->platform.usDeviceID);
EXPECT_EQ(pDrm->storedDeviceRevID, hwInfo->platform.usRevId);
EXPECT_EQ(mockDeviceId, hwInfo->platform.usDeviceID);
EXPECT_EQ(mockRevisionId, hwInfo->platform.usRevId);
}
TEST(DrmTest, GivenDrmWhenAskedForGttSizeThenReturnCorrectValue) {
@@ -1745,42 +1762,16 @@ TEST(DrmTest, GivenDrmWhenDiscoveringDevicesThenCloseOnExecFlagIsPassedToFdOpen)
EXPECT_NE(0u, SysCalls::openFuncCalled);
}
TEST(DrmWrapperTest, WhenGettingDrmIoctlGetparamValueThenIoctlHelperIsNotNeeded) {
EXPECT_EQ(getIoctlRequestValue(DrmIoctl::getparam, nullptr), static_cast<unsigned int>(DRM_IOCTL_I915_GETPARAM));
EXPECT_THROW(getIoctlRequestValue(DrmIoctl::dg1GemCreateExt, nullptr), std::runtime_error);
}
TEST(DrmWrapperTest, WhenGettingDrmIoctlVersionValueThenIoctlHelperIsNotNeeded) {
EXPECT_EQ(getIoctlRequestValue(DrmIoctl::version, nullptr), static_cast<unsigned int>(DRM_IOCTL_VERSION));
}
TEST(DrmWrapperTest, WhenGettingChipsetIdParamValueThenIoctlHelperIsNotNeeded) {
EXPECT_EQ(getDrmParamValue(DrmParam::paramChipsetId, nullptr), static_cast<int>(I915_PARAM_CHIPSET_ID));
}
TEST(DrmWrapperTest, WhenGettingRevisionParamValueThenIoctlHelperIsNotNeeded) {
EXPECT_EQ(getDrmParamValue(DrmParam::paramRevision, nullptr), static_cast<int>(I915_PARAM_REVISION));
}
TEST(DrmWrapperTest, whenGettingDrmParamOrIoctlRequestValueThenUseIoctlHelperWhenAvailable) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
MockIoctlHelper ioctlHelper{drm};
EXPECT_EQ(getIoctlRequestValue(DrmIoctl::getparam, &ioctlHelper), ioctlHelper.getIoctlRequestValueResult);
EXPECT_NE(getIoctlRequestValue(DrmIoctl::getparam, nullptr), getIoctlRequestValue(DrmIoctl::getparam, &ioctlHelper));
EXPECT_EQ(getDrmParamValue(DrmParam::paramChipsetId, &ioctlHelper), ioctlHelper.getDrmParamValueResult);
EXPECT_NE(getDrmParamValue(DrmParam::paramChipsetId, nullptr), getDrmParamValue(DrmParam::paramChipsetId, &ioctlHelper));
}
TEST(DrmWrapperTest, WhenGettingIoctlStringValueThenProperStringIsReturned) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
MockIoctlHelper ioctlHelper{drm};
EXPECT_STREQ(getIoctlString(DrmIoctl::getparam, &ioctlHelper).c_str(), "DRM_IOCTL_I915_GETPARAM");
EXPECT_STREQ(getIoctlString(DrmIoctl::getparam, nullptr).c_str(), "DRM_IOCTL_I915_GETPARAM");
EXPECT_STREQ(ioctlHelper.getIoctlString(DrmIoctl::getparam).c_str(), "DRM_IOCTL_I915_GETPARAM");
}
TEST(DrmWrapperTest, WhenGettingDrmParamValueStringThenProperStringIsReturned) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
@@ -1794,16 +1785,8 @@ TEST(DrmWrapperTest, WhenGettingDrmParamValueStringThenProperStringIsReturned) {
{DrmParam::paramMinEuInPool, "I915_PARAM_MIN_EU_IN_POOL"},
{DrmParam::paramCsTimestampFrequency, "I915_PARAM_CS_TIMESTAMP_FREQUENCY"}};
for (auto &ioctlCodeString : ioctlCodeStringMap) {
EXPECT_STREQ(getDrmParamString(ioctlCodeString.first, &ioctlHelper).c_str(), ioctlCodeString.second);
EXPECT_THROW(getDrmParamString(ioctlCodeString.first, nullptr), std::runtime_error);
EXPECT_STREQ(ioctlHelper.getDrmParamString(ioctlCodeString.first).c_str(), ioctlCodeString.second);
}
EXPECT_STREQ(getDrmParamString(DrmParam::paramChipsetId, &ioctlHelper).c_str(), "I915_PARAM_CHIPSET_ID");
EXPECT_STREQ(getDrmParamString(DrmParam::paramChipsetId, nullptr).c_str(), "I915_PARAM_CHIPSET_ID");
EXPECT_STREQ(getDrmParamString(DrmParam::paramRevision, &ioctlHelper).c_str(), "I915_PARAM_REVISION");
EXPECT_STREQ(getDrmParamString(DrmParam::paramRevision, nullptr).c_str(), "I915_PARAM_REVISION");
EXPECT_THROW(getDrmParamString(DrmParam::engineClassRender, &ioctlHelper), std::runtime_error);
}
TEST(DrmHwInfoTest, givenTopologyDataWithoutSystemInfoWhenSettingHwInfoThenCorrectValuesAreSet) {

View File

@@ -161,8 +161,6 @@ DG1TEST_F(IoctlHelperTestsDg1, whenGettingDrmParamStringThenProperStringIsReturn
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto drm = std::make_unique<DrmMockProdDg1>(*executionEnvironment->rootDeviceEnvironments[0]);
auto &ioctlHelper = *drm->getIoctlHelper();
EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::paramChipsetId).c_str(), "I915_PARAM_CHIPSET_ID");
EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::paramRevision).c_str(), "I915_PARAM_REVISION");
EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::paramHasPooledEu).c_str(), "I915_PARAM_HAS_POOLED_EU");
EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::paramEuTotal).c_str(), "I915_PARAM_EU_TOTAL");
EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::paramSubsliceTotal).c_str(), "I915_PARAM_SUBSLICE_TOTAL");

View File

@@ -96,8 +96,6 @@ TEST_F(IoctlPrelimHelperTests, whenGettingIoctlRequestValueThenPropertValueIsRet
}
TEST_F(IoctlPrelimHelperTests, whenGettingDrmParamStringThenProperStringIsReturned) {
EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::paramChipsetId).c_str(), "I915_PARAM_CHIPSET_ID");
EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::paramRevision).c_str(), "I915_PARAM_REVISION");
EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::paramHasPooledEu).c_str(), "I915_PARAM_HAS_POOLED_EU");
EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::paramEuTotal).c_str(), "I915_PARAM_EU_TOTAL");
EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::paramSubsliceTotal).c_str(), "I915_PARAM_SUBSLICE_TOTAL");
@@ -175,8 +173,6 @@ TEST_F(IoctlPrelimHelperTests, whenGettingDrmParamValueThenPropertValueIsReturne
EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::memoryClassSystem), static_cast<int>(drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM));
EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::mmapOffsetWb), static_cast<int>(I915_MMAP_OFFSET_WB));
EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::mmapOffsetWc), static_cast<int>(I915_MMAP_OFFSET_WC));
EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::paramChipsetId), static_cast<int>(I915_PARAM_CHIPSET_ID));
EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::paramRevision), static_cast<int>(I915_PARAM_REVISION));
EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::paramHasPooledEu), static_cast<int>(I915_PARAM_HAS_POOLED_EU));
EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::paramEuTotal), static_cast<int>(I915_PARAM_EU_TOTAL));
EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::paramSubsliceTotal), static_cast<int>(I915_PARAM_SUBSLICE_TOTAL));

View File

@@ -226,8 +226,6 @@ TEST(IoctlHelperUpstreamTest, whenGettingDrmParamStringThenProperStringIsReturne
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto drm = std::make_unique<DrmTipMock>(*executionEnvironment->rootDeviceEnvironments[0]);
IoctlHelperUpstream ioctlHelper{*drm};
EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::paramChipsetId).c_str(), "I915_PARAM_CHIPSET_ID");
EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::paramRevision).c_str(), "I915_PARAM_REVISION");
EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::paramHasPooledEu).c_str(), "I915_PARAM_HAS_POOLED_EU");
EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::paramEuTotal).c_str(), "I915_PARAM_EU_TOTAL");
EXPECT_STREQ(ioctlHelper.getDrmParamString(DrmParam::paramSubsliceTotal).c_str(), "I915_PARAM_SUBSLICE_TOTAL");
@@ -264,8 +262,6 @@ TEST(IoctlHelperUpstreamTest, whenGettingDrmParamValueThenPropertValueIsReturned
EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::memoryClassSystem), static_cast<int>(drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM));
EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::mmapOffsetWb), static_cast<int>(I915_MMAP_OFFSET_WB));
EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::mmapOffsetWc), static_cast<int>(I915_MMAP_OFFSET_WC));
EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::paramChipsetId), static_cast<int>(I915_PARAM_CHIPSET_ID));
EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::paramRevision), static_cast<int>(I915_PARAM_REVISION));
EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::paramHasPooledEu), static_cast<int>(I915_PARAM_HAS_POOLED_EU));
EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::paramEuTotal), static_cast<int>(I915_PARAM_EU_TOTAL));
EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::paramSubsliceTotal), static_cast<int>(I915_PARAM_SUBSLICE_TOTAL));
@@ -888,4 +884,4 @@ TEST(IoctlHelperTestsUpstream, givenUpstreamWhenQueryDeviceParamsIsCalledThenFal
uint32_t moduleId = 0;
uint16_t serverType = 0;
EXPECT_FALSE(ioctlHelper.queryDeviceParams(&moduleId, &serverType));
}
}

View File

@@ -720,12 +720,6 @@ TEST(IoctlHelperXeTest, whenCallingIoctlThenProperValueIsReturned) {
test.value = &dstvalue;
ret = mockXeIoctlHelper->ioctl(DrmIoctl::getparam, &test);
EXPECT_EQ(-1, ret);
test.param = static_cast<int>(DrmParam::paramChipsetId);
ret = mockXeIoctlHelper->ioctl(DrmIoctl::getparam, &test);
EXPECT_EQ(-1, ret);
test.param = static_cast<int>(DrmParam::paramRevision);
ret = mockXeIoctlHelper->ioctl(DrmIoctl::getparam, &test);
EXPECT_EQ(-1, ret);
test.param = static_cast<int>(DrmParam::paramHasPageFault);
ret = mockXeIoctlHelper->ioctl(DrmIoctl::getparam, &test);
EXPECT_EQ(-1, ret);