1 /*
2 * Copyright (C) 2020-2021 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "shared/source/helpers/file_io.h"
9 #include "shared/source/helpers/hw_info.h"
10 #include "shared/source/os_interface/hw_info_config.h"
11 #include "shared/source/os_interface/os_interface.h"
12 #include "shared/test/common/helpers/default_hw_info.h"
13 #include "shared/test/common/libult/linux/drm_mock.h"
14 #include "shared/test/common/mocks/linux/mock_drm_allocation.h"
15 #include "shared/test/common/test_macros/test.h"
16
17 #include "gtest/gtest.h"
18
19 using namespace NEO;
20
TEST(DrmQueryTest,WhenCallingIsDebugAttachAvailableThenReturnValueIsFalse)21 TEST(DrmQueryTest, WhenCallingIsDebugAttachAvailableThenReturnValueIsFalse) {
22 auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
23 executionEnvironment->prepareRootDeviceEnvironments(1);
24 DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
25 drm.allowDebugAttachCallBase = true;
26
27 EXPECT_FALSE(drm.isDebugAttachAvailable());
28 }
29
TEST(DrmQueryTest,GivenDrmWhenQueryingTopologyInfoCorrectMaxValuesAreSet)30 TEST(DrmQueryTest, GivenDrmWhenQueryingTopologyInfoCorrectMaxValuesAreSet) {
31 auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
32 executionEnvironment->prepareRootDeviceEnvironments(1);
33
34 *executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo() = *NEO::defaultHwInfo.get();
35 DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
36
37 Drm::QueryTopologyData topologyData = {};
38
39 EXPECT_TRUE(drm.queryTopology(*executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo(), topologyData));
40
41 EXPECT_EQ(drm.storedSVal, topologyData.sliceCount);
42 EXPECT_EQ(drm.storedSSVal, topologyData.subSliceCount);
43 EXPECT_EQ(drm.storedEUVal, topologyData.euCount);
44
45 EXPECT_EQ(drm.storedSVal, topologyData.maxSliceCount);
46 EXPECT_EQ(drm.storedSSVal / drm.storedSVal, topologyData.maxSubSliceCount);
47 EXPECT_EQ(drm.storedEUVal / drm.storedSSVal, topologyData.maxEuCount);
48 }
49
TEST(DrmQueryTest,givenDrmWhenGettingSliceMappingsThenCorrectMappingReturned)50 TEST(DrmQueryTest, givenDrmWhenGettingSliceMappingsThenCorrectMappingReturned) {
51 auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
52 executionEnvironment->prepareRootDeviceEnvironments(1);
53
54 *executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo() = *NEO::defaultHwInfo.get();
55 DrmMock drmMock{*executionEnvironment->rootDeviceEnvironments[0]};
56
57 Drm::QueryTopologyData topologyData = {};
58
59 EXPECT_TRUE(drmMock.queryTopology(*executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo(), topologyData));
60
61 auto device0SliceMapping = drmMock.getSliceMappings(0);
62 auto device1SliceMapping = drmMock.getSliceMappings(1);
63
64 ASSERT_EQ(static_cast<size_t>(topologyData.maxSliceCount), device0SliceMapping.size());
65 EXPECT_EQ(0u, device1SliceMapping.size());
66
67 for (int i = 0; i < topologyData.maxSliceCount; i++) {
68 EXPECT_EQ(i, device0SliceMapping[i]);
69 }
70 }
71
72 using HwConfigTopologyQuery = ::testing::Test;
73
HWTEST2_F(HwConfigTopologyQuery,WhenGettingTopologyFailsThenSetMaxValuesBasedOnSubsliceIoctlQuery,MatchAny)74 HWTEST2_F(HwConfigTopologyQuery, WhenGettingTopologyFailsThenSetMaxValuesBasedOnSubsliceIoctlQuery, MatchAny) {
75 auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
76 executionEnvironment->prepareRootDeviceEnvironments(1);
77
78 *executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo() = *NEO::defaultHwInfo.get();
79 auto drm = new DrmMock(*executionEnvironment->rootDeviceEnvironments[0]);
80
81 drm->setGtType(GTTYPE_GT1);
82
83 auto osInterface = std::make_unique<OSInterface>();
84 osInterface->setDriverModel(std::unique_ptr<Drm>(drm));
85
86 drm->failRetTopology = true;
87
88 auto hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo();
89 HardwareInfo outHwInfo;
90
91 hwInfo.gtSystemInfo.MaxSlicesSupported = 0;
92 hwInfo.gtSystemInfo.MaxSubSlicesSupported = 0;
93 hwInfo.gtSystemInfo.MaxEuPerSubSlice = 6;
94
95 auto hwConfig = HwInfoConfigHw<productFamily>::get();
96 int ret = hwConfig->configureHwInfoDrm(&hwInfo, &outHwInfo, osInterface.get());
97 EXPECT_NE(-1, ret);
98
99 EXPECT_EQ(6u, outHwInfo.gtSystemInfo.MaxEuPerSubSlice);
100 EXPECT_EQ(outHwInfo.gtSystemInfo.SubSliceCount, outHwInfo.gtSystemInfo.MaxSubSlicesSupported);
101 EXPECT_EQ(hwInfo.gtSystemInfo.SliceCount, outHwInfo.gtSystemInfo.MaxSlicesSupported);
102
103 EXPECT_EQ(static_cast<uint32_t>(drm->storedEUVal), outHwInfo.gtSystemInfo.EUCount);
104 EXPECT_EQ(static_cast<uint32_t>(drm->storedSSVal), outHwInfo.gtSystemInfo.SubSliceCount);
105 }
106
TEST(DrmQueryTest,givenIoctlWhenParseToStringThenProperStringIsReturned)107 TEST(DrmQueryTest, givenIoctlWhenParseToStringThenProperStringIsReturned) {
108 for (auto ioctlCodeString : ioctlCodeStringMap) {
109 EXPECT_STREQ(IoctlToStringHelper::getIoctlString(ioctlCodeString.first).c_str(), ioctlCodeString.second);
110 }
111 }
112
TEST(DrmQueryTest,givenIoctlParamWhenParseToStringThenProperStringIsReturned)113 TEST(DrmQueryTest, givenIoctlParamWhenParseToStringThenProperStringIsReturned) {
114 for (auto ioctlParamCodeString : ioctlParamCodeStringMap) {
115 EXPECT_STREQ(IoctlToStringHelper::getIoctlParamString(ioctlParamCodeString.first).c_str(), ioctlParamCodeString.second);
116 }
117 }
118
TEST(DrmQueryTest,WhenCallingQueryPageFaultSupportThenReturnFalse)119 TEST(DrmQueryTest, WhenCallingQueryPageFaultSupportThenReturnFalse) {
120 auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
121 executionEnvironment->prepareRootDeviceEnvironments(1);
122 DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
123
124 drm.queryPageFaultSupport();
125
126 EXPECT_FALSE(drm.hasPageFaultSupport());
127 }
128
TEST(DrmQueryTest,givenDrmAllocationWhenShouldAllocationFaultIsCalledThenReturnFalse)129 TEST(DrmQueryTest, givenDrmAllocationWhenShouldAllocationFaultIsCalledThenReturnFalse) {
130 auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
131 executionEnvironment->prepareRootDeviceEnvironments(1);
132 DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
133
134 MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::MemoryNull);
135 EXPECT_FALSE(allocation.shouldAllocationPageFault(&drm));
136 }
137
TEST(DrmQueryTest,givenDrmWhenGettingMemoryRegionsThenReturnNull)138 TEST(DrmQueryTest, givenDrmWhenGettingMemoryRegionsThenReturnNull) {
139 auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
140 executionEnvironment->prepareRootDeviceEnvironments(1);
141 DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
142
143 EXPECT_EQ(drm.getMemoryRegions(), nullptr);
144 }