Debian Codegraph @

level_zero/tools/test/unit_tests/sources/sysman/fan/windows/mock_fan.h

raw
1 /*
2 * Copyright (C) 2020-2025 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #pragma once
9 #include "level_zero/core/test/unit_tests/mock.h"
10 #include "level_zero/tools/source/sysman/fan/fan_imp.h"
11 #include "level_zero/tools/test/unit_tests/sources/sysman/windows/mock_kmd_sys_manager.h"
12
13 namespace L0 {
14 namespace ult {
15
16 class FanKmdSysManager : public Mock<MockKmdSysManager> {};
17
18 template <>
19 struct Mock<FanKmdSysManager> : public FanKmdSysManager {
20 union {
21 struct
22 {
23 uint32_t TemperatureDegreesCelsius : 16;
24 uint32_t FanSpeedPercent : 16;
25 };
26 uint32_t Data;
27 } mockFanTempSpeed[10], mockStockFanTable[10];
28 uint32_t mockFanMaxPoints = 10;
29 uint32_t mockFanCurrentPulses = 523436;
30 uint32_t mockFanCurrentFanPoints = 0;
31 uint32_t mockCurrentReadIndex = 0;
32 uint32_t mockCurrentWriteIndex = 0;
33 bool isFanTableSet = false;
34 bool isStockFanTableAvailable = false;
35 bool failMaxPointsGet = false;
36 bool retZeroMaxPoints = false;
37 bool smallStockTable = false;
38
39 void getFanProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) override {
40 uint8_t *pBuffer = reinterpret_cast<uint8_t *>(pResponse);
41 pBuffer += sizeof(KmdSysman::GfxSysmanReqHeaderOut);
42
43 switch (pRequest->inRequestId) {
44 case KmdSysman::Requests::Fans::MaxFanControlPointsSupported: {
45 uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
46 *pValue = mockFanMaxPoints;
47 if (retZeroMaxPoints) {
48 *pValue = 0;
49 }
50 if (!failMaxPointsGet) {
51 pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
52 pResponse->outDataSize = sizeof(uint32_t);
53 } else {
54 pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
55 pResponse->outDataSize = 0;
56 }
57
58 } break;
59 case KmdSysman::Requests::Fans::CurrentFanSpeed: {
60 if (fanSupported) {
61 uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
62 *pValue = mockFanCurrentPulses;
63 pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
64 pResponse->outDataSize = sizeof(uint32_t);
65 } else {
66 pResponse->outDataSize = 0;
67 pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
68 }
69 } break;
70 case KmdSysman::Requests::Fans::CurrentNumOfControlPoints: {
71 uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
72 *pValue = mockFanCurrentFanPoints;
73 mockCurrentReadIndex = 0;
74 pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
75 pResponse->outDataSize = sizeof(uint32_t);
76 } break;
77 case KmdSysman::Requests::Fans::CurrentFanPoint: {
78 uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
79 if (isFanTableSet) {
80 mockFanTempSpeed[mockCurrentReadIndex].FanSpeedPercent = mockCurrentReadIndex * 10;
81 mockFanTempSpeed[mockCurrentReadIndex].TemperatureDegreesCelsius = mockCurrentReadIndex * 10 + 20;
82 *pValue = mockFanTempSpeed[mockCurrentReadIndex].Data;
83 mockCurrentReadIndex++;
84 pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
85 pResponse->outDataSize = sizeof(uint32_t);
86 } else if (isStockFanTableAvailable) {
87 mockStockFanTable[mockCurrentReadIndex].FanSpeedPercent = mockCurrentReadIndex * 10 - 5;
88 mockStockFanTable[mockCurrentReadIndex].TemperatureDegreesCelsius = mockCurrentReadIndex * 10 + 15;
89 *pValue = mockStockFanTable[mockCurrentReadIndex].Data;
90 mockCurrentReadIndex++;
91 if (smallStockTable && mockCurrentReadIndex == 6) {
92 // only return 5 points for smallStockTable
93 *pValue = 0;
94 pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
95 pResponse->outDataSize = 0;
96 } else {
97 pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
98 pResponse->outDataSize = sizeof(uint32_t);
99 }
100 } else {
101 pResponse->outDataSize = 0;
102 pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
103 }
104 } break;
105 default: {
106 pResponse->outDataSize = 0;
107 pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
108 } break;
109 }
110 }
111
112 void setFanProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) override {
113 uint8_t *pBuffer = reinterpret_cast<uint8_t *>(pRequest);
114 pBuffer += sizeof(KmdSysman::GfxSysmanReqHeaderIn);
115
116 switch (pRequest->inRequestId) {
117 case KmdSysman::Requests::Fans::CurrentNumOfControlPoints: {
118 uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
119 mockFanCurrentFanPoints = *pValue;
120 pResponse->outDataSize = 0;
121 if ((mockFanCurrentFanPoints % 2 == 0) && (mockFanCurrentFanPoints > 0) && (mockFanCurrentFanPoints <= mockFanMaxPoints)) {
122 mockCurrentWriteIndex = 0;
123 pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
124 } else if (mockFanCurrentFanPoints == 0) {
125 isFanTableSet = false;
126 mockCurrentReadIndex = 0;
127 mockCurrentWriteIndex = 0;
128 pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
129 } else {
130 pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
131 }
132 } break;
133 case KmdSysman::Requests::Fans::CurrentFanPoint: {
134 uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
135 mockFanTempSpeed[mockCurrentWriteIndex++].Data = *pValue;
136 isFanTableSet = true;
137 pResponse->outDataSize = 0;
138 pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
139 } break;
140 default: {
141 pResponse->outDataSize = 0;
142 pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
143 } break;
144 }
145 }
146
147 Mock() = default;
148 ~Mock() = default;
149 };
150
151 } // namespace ult
152 } // namespace L0