Skip to content

Commit d9886f6

Browse files
Make IoctlHelper member of Drm
Related-To: NEO-6575 This is needed to fix accessing IoctlHelper after driver detach. This way we are also reducing accessing sysfs file in Drm::getPrelimVersion Signed-off-by: Szymon Morek <szymon.morek@intel.com>
1 parent 63a8908 commit d9886f6

26 files changed

+181
-194
lines changed

level_zero/tools/test/unit_tests/sources/sysman/engine/linux/mock_engine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct MockMemoryManagerInEngineSysman : public MemoryManagerMock {
3232
class EngineNeoDrm : public Drm {
3333
public:
3434
using Drm::getEngineInfo;
35+
using Drm::setupIoctlHelper;
3536
const int mockFd = 0;
3637
EngineNeoDrm(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceIdDrm>(mockFd, ""), rootDeviceEnvironment) {}
3738
};

level_zero/tools/test/unit_tests/sources/sysman/engine/linux/test_zes_engine.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class ZesEngineFixture : public SysmanDeviceFixture {
5050

5151
EngineHandleContext *pEngineHandleContext = pSysmanDeviceImp->pEngineHandleContext;
5252
pDrm = std::make_unique<NiceMock<Mock<EngineNeoDrm>>>(const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment()));
53+
pDrm->setupIoctlHelper();
5354
pPmuInterface = std::make_unique<NiceMock<Mock<MockPmuInterfaceImp>>>(pLinuxSysmanImp);
5455
pOriginalDrm = pLinuxSysmanImp->pDrm;
5556
pOriginalPmuInterface = pLinuxSysmanImp->pPmuInterface;

level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -31,7 +31,9 @@ namespace ult {
3131
constexpr int mockFd = 0;
3232
class SysmanMockDrm : public Drm {
3333
public:
34-
SysmanMockDrm(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceIdDrm>(mockFd, ""), rootDeviceEnvironment) {}
34+
SysmanMockDrm(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceIdDrm>(mockFd, ""), rootDeviceEnvironment) {
35+
setupIoctlHelper();
36+
}
3537
};
3638

3739
class PublicLinuxSysmanImp : public L0::LinuxSysmanImp {

opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class DrmCommandStreamTest : public ::testing::Test {
4040

4141
auto hwInfo = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo();
4242
mock->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(hwInfo));
43+
mock->setupIoctlHelper();
4344
osContext = std::make_unique<OsContextLinux>(*mock, 0u,
4445
EngineDescriptorHelper::getDefaultDescriptor(HwHelper::get(hwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0],
4546
PreemptionHelper::getDefaultPreemptionMode(*hwInfo)));

opencl/test/unit_test/os_interface/linux/drm_engine_info_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ TEST(EngineInfoTest, whenCreateEngineInfoWithCcsThenCorrectHwInfoSet) {
7979

8080
auto hwInfo = *defaultHwInfo.get();
8181
std::vector<EngineCapabilities> engines(2);
82-
uint16_t ccsClass = IoctlHelper::get(drm.get())->getComputeEngineClass();
82+
uint16_t ccsClass = drm->getIoctlHelper()->getComputeEngineClass();
8383
engines[0].engine = {ccsClass, 0};
8484
engines[0].capabilities = 0;
8585
engines[1].engine = {I915_ENGINE_CLASS_COPY, 0};

opencl/test/unit_test/os_interface/linux/drm_mock_impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -20,6 +20,7 @@ class DrmTipMock : public DrmMock {
2020
DrmTipMock(RootDeviceEnvironment &rootDeviceEnvironment) : DrmTipMock(rootDeviceEnvironment, defaultHwInfo.get()) {}
2121
DrmTipMock(RootDeviceEnvironment &rootDeviceEnvironment, const HardwareInfo *inputHwInfo) : DrmMock(rootDeviceEnvironment) {
2222
rootDeviceEnvironment.setHwInfo(inputHwInfo);
23+
setupIoctlHelper();
2324
}
2425

2526
uint32_t i915QuerySuccessCount = std::numeric_limits<uint32_t>::max();

opencl/test/unit_test/os_interface/linux/drm_tests.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ TEST(DrmTest, whenImmediateVmBindExtIsEnabledThenUseVmBindImmediate) {
719719
}
720720
}
721721

722-
TEST(DrmQueryTest, GivenDrmWhenSetupHardwareInfoCalledThenCorrectMaxValuesInGtSystemInfoArePreserved) {
722+
TEST(DrmQueryTest, GivenDrmWhenSetupHardwareInfoCalledThenCorrectMaxValuesInGtSystemInfoArePreservedAndIoctlHelperSet) {
723723
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
724724
executionEnvironment->prepareRootDeviceEnvironments(1);
725725

@@ -737,7 +737,7 @@ TEST(DrmQueryTest, GivenDrmWhenSetupHardwareInfoCalledThenCorrectMaxValuesInGtSy
737737
DeviceDescriptor device = {0, hwInfo, setupHardwareInfo};
738738

739739
drm.setupHardwareInfo(&device, false);
740-
740+
EXPECT_NE(nullptr, drm.getIoctlHelper());
741741
EXPECT_EQ(NEO::defaultHwInfo->gtSystemInfo.MaxSlicesSupported, hwInfo->gtSystemInfo.MaxSlicesSupported);
742742
EXPECT_EQ(NEO::defaultHwInfo->gtSystemInfo.MaxSubSlicesSupported, hwInfo->gtSystemInfo.MaxSubSlicesSupported);
743743
EXPECT_EQ(NEO::defaultHwInfo->gtSystemInfo.MaxEuPerSubSlice, hwInfo->gtSystemInfo.MaxEuPerSubSlice);
@@ -941,6 +941,11 @@ TEST(DrmQueryTest, givenUapiPrelimVersionWithInvalidPathThenReturnEmptyString) {
941941
EXPECT_TRUE(prelimVersion.empty());
942942
}
943943

944+
TEST(DrmTest, givenInvalidUapiPrelimVersionThenFallbackToBasePrelim) {
945+
std::unique_ptr<IoctlHelper> ioctlHelper(IoctlHelper::get(defaultHwInfo.get(), "-1"));
946+
EXPECT_NE(nullptr, ioctlHelper.get());
947+
}
948+
944949
TEST(DrmTest, GivenCompletionFenceDebugFlagWhenCreatingDrmObjectThenExpectCorrectSetting) {
945950
DebugManagerStateRestore restore;
946951
DebugManager.flags.UseVmBind.set(1);
@@ -1116,4 +1121,15 @@ TEST(DrmTest, GivenBatchPendingGreaterThanZeroResetStatsWhenIsGpuHangIsCalledThe
11161121
EXPECT_TRUE(isGpuHangDetected);
11171122

11181123
memoryManagerRaw->registeredEngines.clear();
1119-
}
1124+
}
1125+
1126+
TEST(DrmTest, givenSetupIoctlHelperThenIoctlHelperNotNull) {
1127+
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
1128+
executionEnvironment->prepareRootDeviceEnvironments(1);
1129+
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
1130+
1131+
drm.ioctlHelper.reset(nullptr);
1132+
drm.setupIoctlHelper();
1133+
1134+
EXPECT_NE(nullptr, drm.ioctlHelper.get());
1135+
}

opencl/test/unit_test/os_interface/linux/ioctl_helper_tests_dg1.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2021 Intel Corporation
2+
* Copyright (C) 2021-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -23,7 +23,7 @@ DG1TEST_F(IoctlHelperTestsDg1, givenDg1WhenCreateGemExtThenReturnCorrectValue) {
2323
executionEnvironment->prepareRootDeviceEnvironments(1);
2424
auto drm = std::make_unique<DrmTipMock>(*executionEnvironment->rootDeviceEnvironments[0]);
2525

26-
auto ioctlHelper = IoctlHelper::get(drm.get());
26+
auto ioctlHelper = drm->getIoctlHelper();
2727
uint32_t handle = 0;
2828
std::vector<MemoryClassInstance> memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
2929
auto ret = ioctlHelper->createGemExt(drm.get(), memClassInstance, 1024, handle);
@@ -44,7 +44,7 @@ DG1TEST_F(IoctlHelperTestsDg1, givenDg1WithDrmTipWhenCreateGemExtWithDebugFlagTh
4444
auto drm = std::make_unique<DrmTipMock>(*executionEnvironment->rootDeviceEnvironments[0]);
4545

4646
testing::internal::CaptureStdout();
47-
auto ioctlHelper = IoctlHelper::get(drm.get());
47+
auto ioctlHelper = drm->getIoctlHelper();
4848
uint32_t handle = 0;
4949
std::vector<MemoryClassInstance> memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
5050
auto ret = ioctlHelper->createGemExt(drm.get(), memClassInstance, 1024, handle);
@@ -65,7 +65,7 @@ DG1TEST_F(IoctlHelperTestsDg1, givenDg1WhenCreateGemExtWithDebugFlagThenPrintDeb
6565
auto drm = std::make_unique<DrmMockProdDg1>(*executionEnvironment->rootDeviceEnvironments[0]);
6666

6767
testing::internal::CaptureStdout();
68-
auto ioctlHelper = IoctlHelper::get(drm.get());
68+
auto ioctlHelper = drm->getIoctlHelper();
6969
uint32_t handle = 0;
7070
std::vector<MemoryClassInstance> memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
7171
auto ret = ioctlHelper->createGemExt(drm.get(), memClassInstance, 1024, handle);

0 commit comments

Comments
 (0)