1 /*
2 * Copyright (C) 2021 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "shared/source/execution_environment/execution_environment.h"
9 #include "shared/source/os_interface/linux/ioctl_helper.h"
10 #include "shared/source/os_interface/linux/memory_info.h"
11 #include "shared/test/common/helpers/debug_manager_state_restore.h"
12 #include "shared/test/common/test_macros/test.h"
13
14 #include "opencl/test/unit_test/os_interface/linux/drm_mock_impl.h"
15 #include "opencl/test/unit_test/os_interface/linux/drm_mock_prod_dg1.h"
16
17 using namespace NEO;
18
19 using IoctlHelperTestsDg1 = ::testing::Test;
20
DG1TEST_F(IoctlHelperTestsDg1,givenDg1WhenCreateGemExtThenReturnCorrectValue)21 DG1TEST_F(IoctlHelperTestsDg1, givenDg1WhenCreateGemExtThenReturnCorrectValue) {
22 auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
23 executionEnvironment->prepareRootDeviceEnvironments(1);
24 auto drm = std::make_unique<DrmTipMock>(*executionEnvironment->rootDeviceEnvironments[0]);
25
26 drm_i915_memory_region_info regionInfo[2] = {};
27 regionInfo[0].region = {I915_MEMORY_CLASS_SYSTEM, 0};
28 regionInfo[0].probed_size = 8 * GB;
29 regionInfo[1].region = {I915_MEMORY_CLASS_DEVICE, 0};
30 regionInfo[1].probed_size = 16 * GB;
31
32 auto ioctlHelper = IoctlHelper::get(drm.get());
33 uint32_t handle = 0;
34 auto ret = ioctlHelper->createGemExt(drm.get(), ®ionInfo[1], 1, 1024, handle);
35
36 EXPECT_EQ(0u, ret);
37 EXPECT_EQ(1u, handle);
38 EXPECT_EQ(1u, drm->numRegions);
39 EXPECT_EQ(1024u, drm->createExt.size);
40 EXPECT_EQ(I915_MEMORY_CLASS_DEVICE, drm->memRegions.memory_class);
41 }
42
DG1TEST_F(IoctlHelperTestsDg1,givenDg1WithDrmTipWhenCreateGemExtWithDebugFlagThenPrintDebugInfo)43 DG1TEST_F(IoctlHelperTestsDg1, givenDg1WithDrmTipWhenCreateGemExtWithDebugFlagThenPrintDebugInfo) {
44 DebugManagerStateRestore stateRestore;
45 DebugManager.flags.PrintBOCreateDestroyResult.set(true);
46
47 auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
48 executionEnvironment->prepareRootDeviceEnvironments(1);
49 auto drm = std::make_unique<DrmTipMock>(*executionEnvironment->rootDeviceEnvironments[0]);
50 drm_i915_memory_region_info regionInfo[2] = {};
51 regionInfo[0].region = {I915_MEMORY_CLASS_SYSTEM, 0};
52 regionInfo[1].region = {I915_MEMORY_CLASS_DEVICE, 0};
53
54 testing::internal::CaptureStdout();
55 auto ioctlHelper = IoctlHelper::get(drm.get());
56 uint32_t handle = 0;
57
58 auto ret = ioctlHelper->createGemExt(drm.get(), ®ionInfo[1], 1, 1024, handle);
59
60 std::string output = testing::internal::GetCapturedStdout();
61 std::string expectedOutput("Performing GEM_CREATE_EXT with { size: 1024, memory class: 1, memory instance: 0 }\nGEM_CREATE_EXT with EXT_MEMORY_REGIONS has returned: 0 BO-1 with size: 1024\n");
62 EXPECT_EQ(expectedOutput, output);
63 EXPECT_EQ(1u, drm->ioctlCallsCount);
64 EXPECT_EQ(0u, ret);
65 }
66
DG1TEST_F(IoctlHelperTestsDg1,givenDg1WhenCreateGemExtWithDebugFlagThenPrintDebugInfo)67 DG1TEST_F(IoctlHelperTestsDg1, givenDg1WhenCreateGemExtWithDebugFlagThenPrintDebugInfo) {
68 DebugManagerStateRestore stateRestore;
69 DebugManager.flags.PrintBOCreateDestroyResult.set(true);
70
71 auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
72 executionEnvironment->prepareRootDeviceEnvironments(1);
73 auto drm = std::make_unique<DrmMockProdDg1>(*executionEnvironment->rootDeviceEnvironments[0]);
74 drm_i915_memory_region_info regionInfo[2] = {};
75 regionInfo[0].region = {I915_MEMORY_CLASS_SYSTEM, 0};
76 regionInfo[1].region = {I915_MEMORY_CLASS_DEVICE, 0};
77
78 testing::internal::CaptureStdout();
79 auto ioctlHelper = IoctlHelper::get(drm.get());
80 uint32_t handle = 0;
81
82 auto ret = ioctlHelper->createGemExt(drm.get(), ®ionInfo[1], 1, 1024, handle);
83
84 std::string output = testing::internal::GetCapturedStdout();
85 std::string expectedOutput("Performing GEM_CREATE_EXT with { size: 1024, memory class: 1, memory instance: 0 }\nGEM_CREATE_EXT with EXT_SETPARAM has returned: 0 BO-1 with size: 1024\n");
86 EXPECT_EQ(expectedOutput, output);
87 EXPECT_EQ(2u, drm->ioctlCallsCount);
88 EXPECT_EQ(0u, ret);
89 }
90
DG1TEST_F(IoctlHelperTestsDg1,givenDg1AndMemoryRegionQuerySupportedWhenQueryingMemoryInfoThenMemoryInfoIsCreatedWithRegions)91 DG1TEST_F(IoctlHelperTestsDg1, givenDg1AndMemoryRegionQuerySupportedWhenQueryingMemoryInfoThenMemoryInfoIsCreatedWithRegions) {
92 DebugManagerStateRestore restorer;
93 DebugManager.flags.EnableLocalMemory.set(1);
94 auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
95 executionEnvironment->prepareRootDeviceEnvironments(1);
96
97 auto drm = std::make_unique<DrmMockProdDg1>(*executionEnvironment->rootDeviceEnvironments[0]);
98 ASSERT_NE(nullptr, drm);
99
100 drm->queryMemoryInfo();
101 EXPECT_EQ(2u, drm->ioctlCallsCount);
102
103 auto memoryInfo = drm->getMemoryInfo();
104
105 ASSERT_NE(nullptr, memoryInfo);
106 EXPECT_EQ(2u, memoryInfo->getDrmRegionInfos().size());
107 }
108