Debian Codegraph @

level_zero/sysman/test/unit_tests/sources/engine/windows/test_zes_engine.cpp

raw
1 /*
2 * Copyright (C) 2023-2024 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "level_zero/sysman/source/api/engine/windows/sysman_os_engine_imp.h"
9 #include "level_zero/sysman/test/unit_tests/sources/engine/windows/mock_engine.h"
10 #include "level_zero/sysman/test/unit_tests/sources/windows/mock_sysman_fixture.h"
11
12 namespace L0 {
13 namespace Sysman {
14 namespace ult {
15
16 class SysmanDeviceEngineFixture : public SysmanDeviceFixture {
17 protected:
18 std::unique_ptr<MockEngineKmdSysManager> pKmdSysManager = nullptr;
19 L0::Sysman::KmdSysManager *pOriginalKmdSysManager = nullptr;
20 void SetUp() override {
21 SysmanDeviceFixture::SetUp();
22
23 pKmdSysManager.reset(new MockEngineKmdSysManager);
24
25 pOriginalKmdSysManager = pWddmSysmanImp->pKmdSysManager;
26 pWddmSysmanImp->pKmdSysManager = pKmdSysManager.get();
27
28 pSysmanDeviceImp->pEngineHandleContext->handleList.clear();
29 }
30
31 void TearDown() override {
32 pWddmSysmanImp->pKmdSysManager = pOriginalKmdSysManager;
33 SysmanDeviceFixture::TearDown();
34 }
35
36 std::vector<zes_engine_handle_t> getEngineHandles(uint32_t count) {
37 std::vector<zes_engine_handle_t> handles(count, nullptr);
38 EXPECT_EQ(zesDeviceEnumEngineGroups(pSysmanDevice->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS);
39 return handles;
40 }
41 };
42
43 TEST_F(SysmanDeviceEngineFixture, GivenComponentCountZeroWhenEnumeratingEngineGroupsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
44 uint32_t count = 0;
45 EXPECT_EQ(zesDeviceEnumEngineGroups(pSysmanDevice->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
46 EXPECT_EQ(count, MockEngineKmdSysManager::mockEngineHandleComponentCount);
47 }
48
49 TEST_F(SysmanDeviceEngineFixture, GivenInvalidComponentCountWhenEnumeratingEngineGroupsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
50 uint32_t count = 0;
51 EXPECT_EQ(zesDeviceEnumEngineGroups(pSysmanDevice->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
52 EXPECT_EQ(count, MockEngineKmdSysManager::mockEngineHandleComponentCount);
53
54 count = count + 1;
55 EXPECT_EQ(zesDeviceEnumEngineGroups(pSysmanDevice->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
56 EXPECT_EQ(count, MockEngineKmdSysManager::mockEngineHandleComponentCount);
57 }
58
59 TEST_F(SysmanDeviceEngineFixture, GivenComponentCountZeroWhenEnumeratingEngineGroupsThenValidPowerHandlesIsReturned) {
60 uint32_t count = 0;
61 EXPECT_EQ(zesDeviceEnumEngineGroups(pSysmanDevice->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
62 EXPECT_EQ(count, MockEngineKmdSysManager::mockEngineHandleComponentCount);
63
64 std::vector<zes_engine_handle_t> handles(count, nullptr);
65 EXPECT_EQ(zesDeviceEnumEngineGroups(pSysmanDevice->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS);
66 for (auto handle : handles) {
67 EXPECT_NE(handle, nullptr);
68 }
69 }
70
71 TEST_F(SysmanDeviceEngineFixture, GivenComponentCountZeroWhenEnumeratingEngineGroupsAndRequestMultipleFailsThenErrorAndZeroHandlesAreReturned) {
72 pKmdSysManager->mockRequestMultiple = true;
73 pKmdSysManager->mockRequestMultipleResult = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
74 uint32_t count = 0;
75 EXPECT_EQ(zesDeviceEnumEngineGroups(pSysmanDevice->toHandle(), &count, nullptr), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
76 EXPECT_EQ(count, 0u);
77 }
78
79 TEST_F(SysmanDeviceEngineFixture, GivenComponentCountZeroWhenEnumeratingEngineGroupsIfEngineSupportIsAbsentThenZeroHandlesAreReturned) {
80 pKmdSysManager->mockNumSupportedEngineGroups = 0;
81 uint32_t count = 0;
82 EXPECT_EQ(zesDeviceEnumEngineGroups(pSysmanDevice->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
83 EXPECT_EQ(count, 0u);
84 }
85
86 TEST_F(SysmanDeviceEngineFixture, GivenUnsupportedEngineHandleWhenGettingEngineActivityThenFailureIsReturned) {
87 std::unique_ptr<L0::Sysman::WddmEngineImp> pEngineImp = std::make_unique<L0::Sysman::WddmEngineImp>(pOsSysman, ZES_ENGINE_GROUP_FORCE_UINT32, 0, 0);
88 zes_engine_stats_t pStats = {};
89 EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pEngineImp->getActivity(&pStats));
90 }
91
92 TEST_F(SysmanDeviceEngineFixture, GivenValidHandleGetPropertiesThenCorrectEngineGroupIsReturned) {
93 auto handles = getEngineHandles(MockEngineKmdSysManager::mockEngineHandleComponentCount);
94
95 for (auto &handle : handles) {
96 zes_engine_properties_t properties = {};
97
98 ze_result_t result = zesEngineGetProperties(handle, &properties);
99
100 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
101 EXPECT_FALSE(properties.onSubdevice);
102 EXPECT_EQ(properties.subdeviceId, 0u);
103 }
104 }
105
106 TEST_F(SysmanDeviceEngineFixture, GivenValidHandleGetAvtivityThenCorrectValuesAreReturned) {
107 auto handles = getEngineHandles(MockEngineKmdSysManager::mockEngineHandleComponentCount);
108 uint32_t engineGroupIndex = 0;
109 for (auto &handle : handles) {
110 zes_engine_stats_t stats;
111
112 ze_result_t result = zesEngineGetActivity(handle, &stats);
113
114 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
115 EXPECT_EQ(stats.activeTime, pKmdSysManager->mockActivityCounters[engineGroupIndex]);
116 EXPECT_EQ(stats.timestamp, pKmdSysManager->mockActivityTimeStamps[engineGroupIndex]);
117 engineGroupIndex++;
118 }
119 }
120
121 TEST_F(SysmanDeviceEngineFixture, GivenValidHandleWhenGettingEngineActivityAndRequestSingleFailsThenFailureIsReturned) {
122 auto handles = getEngineHandles(MockEngineKmdSysManager::mockEngineHandleComponentCount);
123 for (auto &handle : handles) {
124 pKmdSysManager->mockRequestSingle = true;
125 pKmdSysManager->mockRequestSingleResult = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
126 zes_engine_stats_t stats;
127 EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesEngineGetActivity(handle, &stats));
128 }
129 }
130
131 TEST_F(SysmanDeviceEngineFixture, GivenValidHandleWhenCallingZesEngineGetActivityExtThenUnsupportedFeatureErrorIsReturned) {
132 auto handles = getEngineHandles(MockEngineKmdSysManager::mockEngineHandleComponentCount);
133 for (auto &handle : handles) {
134 zes_engine_stats_t stats;
135 EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesEngineGetActivityExt(handle, nullptr, &stats));
136 }
137 }
138
139 TEST_F(SysmanDeviceEngineFixture, GivenZeroResponseSizeFromKmdWhenEnumeratingEngineGroupsThenZeroHandlesAreReturned) {
140 pKmdSysManager->useZeroResponseSizeForEngineInstancesPerGroup = true;
141 uint32_t count = 0;
142 EXPECT_EQ(zesDeviceEnumEngineGroups(pSysmanDevice->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
143 EXPECT_EQ(count, 0u);
144 }
145
146 } // namespace ult
147 } // namespace Sysman
148 } // namespace L0