Skip to content

Commit 4d6169e

Browse files
Extract querying device id and revision to a dedicated method
Related-To: NEO-6999 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
1 parent 39c1c4d commit 4d6169e

File tree

9 files changed

+46
-59
lines changed

9 files changed

+46
-59
lines changed

opencl/test/unit_test/linux/drm_null_device_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class DrmNullDeviceTestsFixture {
3838
void TearDown() { // NOLINT(readability-identifier-naming)
3939
}
4040

41-
std::unique_ptr<Drm> drmNullDevice;
41+
std::unique_ptr<DrmWrap> drmNullDevice;
4242
ExecutionEnvironment executionEnvironment;
4343

4444
protected:
@@ -48,10 +48,10 @@ class DrmNullDeviceTestsFixture {
4848
typedef Test<DrmNullDeviceTestsFixture> DrmNullDeviceTests;
4949

5050
TEST_F(DrmNullDeviceTests, GIVENdrmNullDeviceWHENcallGetDeviceIdTHENreturnProperDeviceId) {
51-
int deviceIdQueried = 0;
52-
int ret = drmNullDevice->getDeviceID(deviceIdQueried);
53-
EXPECT_EQ(0, ret);
54-
EXPECT_EQ(deviceId, deviceIdQueried);
51+
int ret = drmNullDevice->queryDeviceIdAndRevision();
52+
EXPECT_TRUE(ret);
53+
EXPECT_EQ(deviceId, drmNullDevice->deviceId);
54+
EXPECT_EQ(revisionId, drmNullDevice->revisionId);
5555
}
5656

5757
TEST_F(DrmNullDeviceTests, GIVENdrmNullDeviceWHENcallIoctlTHENalwaysSuccess) {

opencl/test/unit_test/linux/drm_wrap.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@
1414

1515
class DrmWrap : public NEO::Drm {
1616
public:
17+
using Drm::deviceId;
18+
using Drm::ioctlStatistics;
19+
using Drm::queryDeviceIdAndRevision;
20+
using Drm::revisionId;
1721
using Drm::virtualMemoryIds;
18-
19-
static std::unique_ptr<NEO::Drm> createDrm(RootDeviceEnvironment &rootDeviceEnvironment) {
22+
static std::unique_ptr<DrmWrap> createDrm(RootDeviceEnvironment &rootDeviceEnvironment) {
2023
auto hwDeviceIds = OSInterface::discoverDevices(rootDeviceEnvironment.executionEnvironment);
2124
if (!hwDeviceIds.empty()) {
22-
return std::unique_ptr<Drm>{NEO::Drm::create(std::unique_ptr<HwDeviceIdDrm>(hwDeviceIds[0].release()->as<HwDeviceIdDrm>()), rootDeviceEnvironment)};
25+
return std::unique_ptr<DrmWrap>{static_cast<DrmWrap *>(NEO::Drm::create(std::unique_ptr<HwDeviceIdDrm>(hwDeviceIds[0].release()->as<HwDeviceIdDrm>()), rootDeviceEnvironment))};
2326
}
2427
return nullptr;
2528
}
2629
};
30+
31+
static_assert(sizeof(DrmWrap) == sizeof(NEO::Drm));

opencl/test/unit_test/linux/main_linux_dll.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,12 @@ TEST_F(DrmFailedIoctlTests, givenPrintIoctlEntriesWhenCallFailedIoctlThenExpecte
254254
}
255255

256256
TEST_F(DrmSimpleTests, givenPrintIoctlTimesWhenCallIoctlThenStatisticsAreGathered) {
257-
struct DrmMock : public Drm {
258-
using Drm::ioctlStatistics;
259-
};
260-
261257
constexpr long long initialMin = std::numeric_limits<long long>::max();
262258
constexpr long long initialMax = std::numeric_limits<long long>::min();
263259

264260
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
265261
executionEnvironment->prepareRootDeviceEnvironments(1);
266-
auto drm = static_cast<DrmMock *>(DrmWrap::createDrm(*executionEnvironment->rootDeviceEnvironments[0]).release());
262+
auto drm = DrmWrap::createDrm(*executionEnvironment->rootDeviceEnvironments[0]).release();
267263

268264
DebugManagerStateRestore restorer;
269265
DebugManager.flags.PrintIoctlTimes.set(true);

shared/source/dll/linux/drm_neo_create.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,11 @@ Drm *Drm::create(std::unique_ptr<HwDeviceIdDrm> &&hwDeviceId, RootDeviceEnvironm
3939
drmObject.reset(new Drm(std::move(hwDeviceId), rootDeviceEnvironment));
4040
}
4141

42-
// Get HW version (I915_drm.h)
43-
int ret = drmObject->getDeviceID(drmObject->deviceId);
44-
if (ret != 0) {
45-
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "FATAL: Cannot query device ID parameter!\n");
46-
return nullptr;
47-
}
48-
if (!DeviceFactory::isAllowedDeviceId(drmObject->deviceId, DebugManager.flags.FilterDeviceId.get())) {
42+
if (!drmObject->queryDeviceIdAndRevision()) {
4943
return nullptr;
5044
}
5145

52-
// Get HW Revision (I915_drm.h)
53-
ret = drmObject->getDeviceRevID(drmObject->revisionId);
54-
if (ret != 0) {
55-
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "FATAL: Cannot query device Rev ID parameter!\n");
46+
if (!DeviceFactory::isAllowedDeviceId(drmObject->deviceId, DebugManager.flags.FilterDeviceId.get())) {
5647
return nullptr;
5748
}
5849

@@ -65,6 +56,7 @@ Drm *Drm::create(std::unique_ptr<HwDeviceIdDrm> &&hwDeviceId, RootDeviceEnvironm
6556
break;
6657
}
6758
}
59+
int ret = 0;
6860
if (device) {
6961
ret = drmObject->setupHardwareInfo(device, true);
7062
if (ret != 0) {

shared/source/os_interface/linux/drm_neo.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,24 @@ int Drm::getParamIoctl(DrmParam param, int *dstValue) {
127127
return retVal;
128128
}
129129

130-
int Drm::getDeviceID(int &devId) {
131-
return getParamIoctl(DrmParam::ParamChipsetId, &devId);
132-
}
133-
134-
int Drm::getDeviceRevID(int &revId) {
135-
return getParamIoctl(DrmParam::ParamRevision, &revId);
136-
}
137-
138130
int Drm::getExecSoftPin(int &execSoftPin) {
139131
return getParamIoctl(DrmParam::ParamHasExecSoftpin, &execSoftPin);
140132
}
141133

134+
bool Drm::queryI915DeviceIdAndRevision() {
135+
auto ret = getParamIoctl(DrmParam::ParamChipsetId, &this->deviceId);
136+
if (ret != 0) {
137+
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "FATAL: Cannot query device ID parameter!\n");
138+
return false;
139+
}
140+
ret = getParamIoctl(DrmParam::ParamRevision, &this->revisionId);
141+
if (ret != 0) {
142+
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "FATAL: Cannot query device Rev ID parameter!\n");
143+
return false;
144+
}
145+
return true;
146+
}
147+
142148
int Drm::enableTurboBoost() {
143149
GemContextParam contextParam = {};
144150

shared/source/os_interface/linux/drm_neo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,10 @@ class Drm : public DriverModel {
8282

8383
virtual int ioctl(DrmIoctl request, void *arg);
8484

85-
int getDeviceID(int &devId);
8685
unsigned int getDeviceHandle() const override {
8786
return 0;
8887
}
8988
PhyicalDevicePciSpeedInfo getPciSpeedInfo() const override;
90-
int getDeviceRevID(int &revId);
9189
int getExecSoftPin(int &execSoftPin);
9290
int enableTurboBoost();
9391
int getEuTotal(int &euTotal);
@@ -266,6 +264,8 @@ class Drm : public DriverModel {
266264
void setupIoctlHelper(const PRODUCT_FAMILY productFamily);
267265
void queryAndSetVmBindPatIndexProgrammingSupport();
268266
static std::string getDrmVersion(int fileDescriptor);
267+
bool queryDeviceIdAndRevision();
268+
bool queryI915DeviceIdAndRevision();
269269

270270
#pragma pack(1)
271271
struct PCIConfig {

shared/source/os_interface/linux/drm_version.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ bool Drm::isDrmSupported(int fileDescriptor) {
1313
return "i915" == drmVersion;
1414
}
1515

16+
bool Drm::queryDeviceIdAndRevision() {
17+
return queryI915DeviceIdAndRevision();
18+
}
19+
1620
} // namespace NEO

shared/test/common/libult/linux/drm_mock.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
using namespace NEO;
2727

28-
// Mock DRM class that responds to DRM_IOCTL_I915_GETPARAMs
2928
class DrmMock : public Drm {
3029
public:
3130
using Drm::bindAvailable;
@@ -34,6 +33,7 @@ class DrmMock : public Drm {
3433
using Drm::classHandles;
3534
using Drm::completionFenceSupported;
3635
using Drm::contextDebugSupported;
36+
using Drm::deviceId;
3737
using Drm::engineInfo;
3838
using Drm::fenceVal;
3939
using Drm::generateElfUUID;
@@ -47,7 +47,9 @@ class DrmMock : public Drm {
4747
using Drm::preemptionSupported;
4848
using Drm::query;
4949
using Drm::queryAndSetVmBindPatIndexProgrammingSupport;
50+
using Drm::queryDeviceIdAndRevision;
5051
using Drm::requirePerContextVM;
52+
using Drm::revisionId;
5153
using Drm::setupIoctlHelper;
5254
using Drm::sliceCountChangeSupported;
5355
using Drm::systemInfo;
@@ -110,8 +112,6 @@ class DrmMock : public Drm {
110112
hwDeviceId = std::make_unique<HwDeviceIdDrm>(getFileDescriptor(), pciPath);
111113
}
112114

113-
void setDeviceID(int deviceId) { this->deviceId = deviceId; }
114-
void setDeviceRevID(int revisionId) { this->revisionId = revisionId; }
115115
void setBindAvailable() {
116116
this->bindAvailable = true;
117117
}

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

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,6 @@ std::string getLinuxDevicesPath(const char *file) {
3434
return resultString;
3535
}
3636

37-
TEST(DrmTest, WhenGettingDeviceIdThenCorrectIdReturned) {
38-
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
39-
executionEnvironment->prepareRootDeviceEnvironments(1);
40-
DrmMock *pDrm = new DrmMock(*executionEnvironment->rootDeviceEnvironments[0]);
41-
EXPECT_NE(nullptr, pDrm);
42-
43-
pDrm->storedDeviceID = 0x1234;
44-
int deviceID = 0;
45-
int ret = pDrm->getDeviceID(deviceID);
46-
EXPECT_EQ(0, ret);
47-
EXPECT_EQ(pDrm->storedDeviceID, deviceID);
48-
delete pDrm;
49-
}
50-
5137
TEST(DrmTest, GivenValidPciPathWhenGettingAdapterBdfThenCorrectValuesAreReturned) {
5238
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
5339
executionEnvironment->prepareRootDeviceEnvironments(1);
@@ -124,15 +110,13 @@ TEST(DrmTest, WhenGettingRevisionIdThenCorrectIdIsReturned) {
124110

125111
pDrm->storedDeviceID = 0x1234;
126112
pDrm->storedDeviceRevID = 0xB;
127-
int deviceID = 0;
128-
int ret = pDrm->getDeviceID(deviceID);
129-
EXPECT_EQ(0, ret);
130-
int revID = 0;
131-
ret = pDrm->getDeviceRevID(revID);
132-
EXPECT_EQ(0, ret);
113+
pDrm->deviceId = 0;
114+
pDrm->revisionId = 0;
115+
116+
EXPECT_TRUE(pDrm->queryDeviceIdAndRevision());
133117

134-
EXPECT_EQ(pDrm->storedDeviceID, deviceID);
135-
EXPECT_EQ(pDrm->storedDeviceRevID, revID);
118+
EXPECT_EQ(pDrm->storedDeviceID, pDrm->deviceId);
119+
EXPECT_EQ(pDrm->storedDeviceRevID, pDrm->revisionId);
136120

137121
delete pDrm;
138122
}

0 commit comments

Comments
 (0)