blob: b1353e7105ca6ef98e937914519bafe578b5fa15 [file] [log] [blame]
Gilbert Chende2a1322022-05-24 15:35:21 +01001#include "common/instance_id.hpp"
2#include "mock_terminus_manager.hpp"
3#include "platform-mc/platform_manager.hpp"
4#include "test/test_instance_id.hpp"
Chaul Lyfdf61cc2025-01-22 07:55:45 +00005#include "utils_test.hpp"
Gilbert Chende2a1322022-05-24 15:35:21 +01006
7#include <sdeventplus/event.hpp>
8
9#include <bitset>
10
11#include <gtest/gtest.h>
12
13class PlatformManagerTest : public testing::Test
14{
15 protected:
16 PlatformManagerTest() :
17 bus(pldm::utils::DBusHandler::getBus()),
18 event(sdeventplus::Event::get_default()), instanceIdDb(),
19 reqHandler(pldmTransport, event, instanceIdDb, false,
20 std::chrono::seconds(1), 2, std::chrono::milliseconds(100)),
21 mockTerminusManager(event, reqHandler, instanceIdDb, termini, nullptr),
Eric Yang6baafe42025-01-20 17:13:33 +080022 platformManager(mockTerminusManager, termini, nullptr)
Gilbert Chende2a1322022-05-24 15:35:21 +010023 {}
24
25 PldmTransport* pldmTransport = nullptr;
26 sdbusplus::bus_t& bus;
27 sdeventplus::Event event;
28 TestInstanceIdDb instanceIdDb;
29 pldm::requester::Handler<pldm::requester::Request> reqHandler;
30 pldm::platform_mc::MockTerminusManager mockTerminusManager;
31 pldm::platform_mc::PlatformManager platformManager;
32 std::map<pldm_tid_t, std::shared_ptr<pldm::platform_mc::Terminus>> termini;
33};
34
35TEST_F(PlatformManagerTest, initTerminusTest)
36{
37 // Add terminus
Unive Tienc40d4a62025-03-12 11:36:07 +080038 auto mappedTid =
39 mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1, std::nullopt));
Gilbert Chende2a1322022-05-24 15:35:21 +010040 auto tid = mappedTid.value();
41 termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
Chaul Lyfdf61cc2025-01-22 07:55:45 +000042 tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM, event);
Gilbert Chende2a1322022-05-24 15:35:21 +010043 auto terminus = termini[tid];
44
45 /* Set supported command by terminus */
46 auto size = PLDM_MAX_TYPES * (PLDM_MAX_CMDS_PER_TYPE / 8);
47 std::vector<uint8_t> pldmCmds(size);
48 uint8_t type = PLDM_PLATFORM;
49 uint8_t cmd = PLDM_GET_PDR;
50 auto idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
51 pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
52 cmd = PLDM_GET_PDR_REPOSITORY_INFO;
53 idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
54 pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
55 termini[tid]->setSupportedCommands(pldmCmds);
56
57 // queue getPDRRepositoryInfo response
58 const size_t getPDRRepositoryInfoLen =
59 PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES;
60 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen>
61 getPDRRepositoryInfoResp{
62 0x0, 0x02, 0x50, PLDM_SUCCESS,
63 0x0, // repositoryState
64 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
65 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // updateTime
66 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
67 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // OEMUpdateTime
Gilbert Cheneac61a42022-02-23 20:56:19 +000068 2, 0x0, 0x0, 0x0, // recordCount
Gilbert Chende2a1322022-05-24 15:35:21 +010069 0x0, 0x1, 0x0, 0x0, // repositorySize
70 59, 0x0, 0x0, 0x0, // largestRecordSize
71 0x0 // dataTransferHandleTimeout
72 };
73 auto rc = mockTerminusManager.enqueueResponse(
Pavithra Barithaya5ea72372025-02-04 18:09:57 +053074 new (getPDRRepositoryInfoResp.data()) pldm_msg,
Gilbert Chende2a1322022-05-24 15:35:21 +010075 sizeof(getPDRRepositoryInfoResp));
76 EXPECT_EQ(rc, PLDM_SUCCESS);
77
78 // queue getPDR responses
79 const size_t getPdrRespLen = 81;
80 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{
Gilbert Cheneac61a42022-02-23 20:56:19 +000081 0x0, 0x02, 0x51, PLDM_SUCCESS, 0x1, 0x0, 0x0, 0x0, // nextRecordHandle
Gilbert Chende2a1322022-05-24 15:35:21 +010082 0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
83 0x5, // transferFlag
84 69, 0x0, // responseCount
85 // numeric Sensor PDR
Gilbert Cheneac61a42022-02-23 20:56:19 +000086 0x0, 0x0, 0x0,
Gilbert Chende2a1322022-05-24 15:35:21 +010087 0x0, // record handle
88 0x1, // PDRHeaderVersion
89 PLDM_NUMERIC_SENSOR_PDR, // PDRType
90 0x0,
91 0x0, // recordChangeNumber
92 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
93 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH +
94 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH,
95 0, // dataLength
96 0,
97 0, // PLDMTerminusHandle
98 0x1,
99 0x0, // sensorID=1
100 120,
101 0, // entityType=Power Supply(120)
102 1,
103 0, // entityInstanceNumber
104 0x1,
105 0x0, // containerID=1
106 PLDM_NO_INIT, // sensorInit
107 false, // sensorAuxiliaryNamesPDR
108 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
109 1, // unitModifier = 1
110 0, // rateUnit
111 0, // baseOEMUnitHandle
112 0, // auxUnit
113 0, // auxUnitModifier
114 0, // auxRateUnit
115 0, // rel
116 0, // auxOEMUnitHandle
117 true, // isLinear
118 PLDM_SENSOR_DATA_SIZE_UINT8, // sensorDataSize
119 0, 0, 0xc0,
120 0x3f, // resolution=1.5
121 0, 0, 0x80,
122 0x3f, // offset=1.0
123 0,
124 0, // accuracy
125 0, // plusTolerance
126 0, // minusTolerance
127 2, // hysteresis
128 0, // supportedThresholds
129 0, // thresholdAndHysteresisVolatility
130 0, 0, 0x80,
131 0x3f, // stateTransistionInterval=1.0
132 0, 0, 0x80,
133 0x3f, // updateInverval=1.0
134 255, // maxReadable
135 0, // minReadable
136 PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat
137 0, // rangeFieldsupport
138 0, // nominalValue
139 0, // normalMax
140 0, // normalMin
141 0, // warningHigh
142 0, // warningLow
143 0, // criticalHigh
144 0, // criticalLow
145 0, // fatalHigh
146 0 // fatalLow
147 };
Pavithra Barithaya5ea72372025-02-04 18:09:57 +0530148 rc = mockTerminusManager.enqueueResponse(new (getPdrResp.data()) pldm_msg,
149 sizeof(getPdrResp));
Gilbert Chende2a1322022-05-24 15:35:21 +0100150 EXPECT_EQ(rc, PLDM_SUCCESS);
151
Gilbert Cheneac61a42022-02-23 20:56:19 +0000152 const size_t getPdrAuxNameRespLen = 39;
153 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrAuxNameRespLen>
154 getPdrAuxNameResp{
155 0x0, 0x02, 0x51, PLDM_SUCCESS, 0x0, 0x0, 0x0,
156 0x0, // nextRecordHandle
157 0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
158 0x5, // transferFlag
159 0x1b, 0x0, // responseCount
160 // Common PDR Header
161 0x1, 0x0, 0x0,
162 0x0, // record handle
163 0x1, // PDRHeaderVersion
164 PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
165 0x1,
166 0x0, // recordChangeNumber
167 0x11,
168 0, // dataLength
169 /* Entity Auxiliary Names PDR Data*/
170 3,
171 0x80, // entityType system software
172 0x1,
173 0x0, // Entity instance number =1
174 0,
Manojkiran Eda04ac9972024-09-06 10:57:12 +0530175 0, // Overall system
Gilbert Cheneac61a42022-02-23 20:56:19 +0000176 0, // shared Name Count one name only
177 01, // nameStringCount
178 0x65, 0x6e, 0x00,
179 0x00, // Language Tag "en"
180 0x53, 0x00, 0x30, 0x00,
181 0x00 // Entity Name "S0"
182 };
183 rc = mockTerminusManager.enqueueResponse(
Pavithra Barithaya5ea72372025-02-04 18:09:57 +0530184 new (getPdrAuxNameResp.data()) pldm_msg, sizeof(getPdrAuxNameResp));
Gilbert Cheneac61a42022-02-23 20:56:19 +0000185 EXPECT_EQ(rc, PLDM_SUCCESS);
186
Chau Ly75e00422024-03-19 12:33:08 +0000187 mockTerminusManager.updateMctpEndpointAvailability(
Unive Tienc40d4a62025-03-12 11:36:07 +0800188 pldm::MctpInfo(10, "", "", 1, std::nullopt), true);
Chau Ly75e00422024-03-19 12:33:08 +0000189
Gilbert Chende2a1322022-05-24 15:35:21 +0100190 stdexec::sync_wait(platformManager.initTerminus());
191 EXPECT_EQ(true, terminus->initialized);
Chau Ly75e00422024-03-19 12:33:08 +0000192 EXPECT_EQ(true, terminus->doesSupportCommand(PLDM_PLATFORM, PLDM_GET_PDR));
Gilbert Cheneac61a42022-02-23 20:56:19 +0000193 EXPECT_EQ(2, terminus->pdrs.size());
Chaul Lyfdf61cc2025-01-22 07:55:45 +0000194 // Run event loop for a few seconds to let sensor creation
195 // defer tasks be run. May increase time when sensor num is large
196 utils::runEventLoopForSeconds(event, 1);
Gilbert Cheneac61a42022-02-23 20:56:19 +0000197 EXPECT_EQ(1, terminus->numericSensors.size());
Thu Nguyen9fc79122024-09-10 10:15:01 +0000198 EXPECT_EQ("S0", terminus->getTerminusName().value());
Gilbert Chende2a1322022-05-24 15:35:21 +0100199}
200
Thu Nguyenb8cf46b2024-06-15 02:44:35 +0000201TEST_F(PlatformManagerTest, parseTerminusNameTest)
202{
203 // Add terminus
Unive Tienc40d4a62025-03-12 11:36:07 +0800204 auto mappedTid =
205 mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1, std::nullopt));
Thu Nguyenb8cf46b2024-06-15 02:44:35 +0000206 auto tid = mappedTid.value();
207 termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
Chaul Lyfdf61cc2025-01-22 07:55:45 +0000208 tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM, event);
Thu Nguyenb8cf46b2024-06-15 02:44:35 +0000209 auto terminus = termini[tid];
210
211 /* Set supported command by terminus */
212 auto size = PLDM_MAX_TYPES * (PLDM_MAX_CMDS_PER_TYPE / 8);
213 std::vector<uint8_t> pldmCmds(size);
214 uint8_t type = PLDM_PLATFORM;
215 uint8_t cmd = PLDM_GET_PDR;
216 auto idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
217 pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
218 cmd = PLDM_GET_PDR_REPOSITORY_INFO;
219 idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
220 pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
221 termini[tid]->setSupportedCommands(pldmCmds);
222
223 // queue getPDRRepositoryInfo response
224 const size_t getPDRRepositoryInfoLen =
225 PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES;
226 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen>
227 getPDRRepositoryInfoResp{
228 0x0, 0x02, 0x50, PLDM_SUCCESS,
229 0x0, // repositoryState
230 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
231 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // updateTime
232 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
233 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // OEMUpdateTime
234 2, 0x0, 0x0, 0x0, // recordCount
235 0x0, 0x1, 0x0, 0x0, // repositorySize
236 59, 0x0, 0x0, 0x0, // largestRecordSize
237 0x0 // dataTransferHandleTimeout
238 };
239 auto rc = mockTerminusManager.enqueueResponse(
Pavithra Barithaya5ea72372025-02-04 18:09:57 +0530240 new (getPDRRepositoryInfoResp.data()) pldm_msg,
Thu Nguyenb8cf46b2024-06-15 02:44:35 +0000241 sizeof(getPDRRepositoryInfoResp));
242 EXPECT_EQ(rc, PLDM_SUCCESS);
243
244 // queue getPDR responses
245 const size_t getPdrRespLen = 81;
246 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{
247 0x0, 0x02, 0x51, PLDM_SUCCESS, 0x1, 0x0, 0x0, 0x0, // nextRecordHandle
248 0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
249 0x5, // transferFlag
250 69, 0x0, // responseCount
251 // numeric Sensor PDR
252 0x0, 0x0, 0x0,
253 0x0, // record handle
254 0x1, // PDRHeaderVersion
255 PLDM_NUMERIC_SENSOR_PDR, // PDRType
256 0x0,
257 0x0, // recordChangeNumber
258 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
259 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH +
260 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH,
261 0, // dataLength
262 0,
263 0, // PLDMTerminusHandle
264 0x1,
265 0x0, // sensorID=1
266 120,
267 0, // entityType=Power Supply(120)
268 1,
269 0, // entityInstanceNumber
270 0x1,
271 0x0, // containerID=1
272 PLDM_NO_INIT, // sensorInit
273 false, // sensorAuxiliaryNamesPDR
274 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
275 1, // unitModifier = 1
276 0, // rateUnit
277 0, // baseOEMUnitHandle
278 0, // auxUnit
279 0, // auxUnitModifier
280 0, // auxRateUnit
281 0, // rel
282 0, // auxOEMUnitHandle
283 true, // isLinear
284 PLDM_SENSOR_DATA_SIZE_UINT8, // sensorDataSize
285 0, 0, 0xc0,
286 0x3f, // resolution=1.5
287 0, 0, 0x80,
288 0x3f, // offset=1.0
289 0,
290 0, // accuracy
291 0, // plusTolerance
292 0, // minusTolerance
293 2, // hysteresis
294 0, // supportedThresholds
295 0, // thresholdAndHysteresisVolatility
296 0, 0, 0x80,
297 0x3f, // stateTransistionInterval=1.0
298 0, 0, 0x80,
299 0x3f, // updateInverval=1.0
300 255, // maxReadable
301 0, // minReadable
302 PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat
303 0, // rangeFieldsupport
304 0, // nominalValue
305 0, // normalMax
306 0, // normalMin
307 0, // warningHigh
308 0, // warningLow
309 0, // criticalHigh
310 0, // criticalLow
311 0, // fatalHigh
312 0 // fatalLow
313 };
Pavithra Barithaya5ea72372025-02-04 18:09:57 +0530314 rc = mockTerminusManager.enqueueResponse(new (getPdrResp.data()) pldm_msg,
315 sizeof(getPdrResp));
Thu Nguyenb8cf46b2024-06-15 02:44:35 +0000316 EXPECT_EQ(rc, PLDM_SUCCESS);
317
318 const size_t getPdrAuxNameRespLen = 39;
319 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrAuxNameRespLen>
320 getPdrAuxNameResp{
321 0x0, 0x02, 0x51, PLDM_SUCCESS, 0x0, 0x0, 0x0,
322 0x0, // nextRecordHandle
323 0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
324 0x5, // transferFlag
325 0x1b, 0x0, // responseCount
326 // Common PDR Header
327 0x1, 0x0, 0x0,
328 0x0, // record handle
329 0x1, // PDRHeaderVersion
330 PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
331 0x1,
332 0x0, // recordChangeNumber
333 0x11,
334 0, // dataLength
335 /* Entity Auxiliary Names PDR Data*/
336 3,
337 0x80, // entityType system software
338 0x1,
339 0x0, // Entity instance number =1
340 0,
Manojkiran Eda04ac9972024-09-06 10:57:12 +0530341 0, // Overall system
Thu Nguyenb8cf46b2024-06-15 02:44:35 +0000342 0, // shared Name Count one name only
343 01, // nameStringCount
344 0x65, 0x6e, 0x00,
345 0x00, // Language Tag "en"
346 0x53, 0x00, 0x30, 0x00,
347 0x00 // Entity Name "S0"
348 };
349 rc = mockTerminusManager.enqueueResponse(
Pavithra Barithaya5ea72372025-02-04 18:09:57 +0530350 new (getPdrAuxNameResp.data()) pldm_msg, sizeof(getPdrAuxNameResp));
Thu Nguyenb8cf46b2024-06-15 02:44:35 +0000351 EXPECT_EQ(rc, PLDM_SUCCESS);
352
Chau Ly75e00422024-03-19 12:33:08 +0000353 mockTerminusManager.updateMctpEndpointAvailability(
Unive Tienc40d4a62025-03-12 11:36:07 +0800354 pldm::MctpInfo(10, "", "", 1, std::nullopt), true);
Chau Ly75e00422024-03-19 12:33:08 +0000355
Thu Nguyenb8cf46b2024-06-15 02:44:35 +0000356 stdexec::sync_wait(platformManager.initTerminus());
357 EXPECT_EQ(true, terminus->initialized);
358 EXPECT_EQ(2, terminus->pdrs.size());
Thu Nguyen9fc79122024-09-10 10:15:01 +0000359 EXPECT_EQ("S0", terminus->getTerminusName().value());
Thu Nguyenb8cf46b2024-06-15 02:44:35 +0000360}
361
Gilbert Chende2a1322022-05-24 15:35:21 +0100362TEST_F(PlatformManagerTest, initTerminusDontSupportGetPDRTest)
363{
364 // Add terminus
Unive Tienc40d4a62025-03-12 11:36:07 +0800365 auto mappedTid =
366 mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1, std::nullopt));
Gilbert Chende2a1322022-05-24 15:35:21 +0100367 auto tid = mappedTid.value();
368 termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
Chaul Lyfdf61cc2025-01-22 07:55:45 +0000369 tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM, event);
Gilbert Chende2a1322022-05-24 15:35:21 +0100370 auto terminus = termini[tid];
371
372 /* Set supported command by terminus */
373 auto size = PLDM_MAX_TYPES * (PLDM_MAX_CMDS_PER_TYPE / 8);
374 std::vector<uint8_t> pldmCmds(size);
375 uint8_t type = PLDM_PLATFORM;
376 uint8_t cmd = PLDM_GET_PDR_REPOSITORY_INFO;
377 auto idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
378 pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
379 termini[tid]->setSupportedCommands(pldmCmds);
380
381 // queue getPDRRepositoryInfo response
382 const size_t getPDRRepositoryInfoLen =
383 PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES;
384 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen>
385 getPDRRepositoryInfoResp{
386 0x0, 0x02, 0x50, PLDM_SUCCESS,
387 0x0, // repositoryState
388 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
389 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // updateTime
390 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
391 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // OEMUpdateTime
392 1, 0x0, 0x0, 0x0, // recordCount
393 0x0, 0x1, 0x0, 0x0, // repositorySize
394 59, 0x0, 0x0, 0x0, // largestRecordSize
395 0x0 // dataTransferHandleTimeout
396 };
397 auto rc = mockTerminusManager.enqueueResponse(
Pavithra Barithaya5ea72372025-02-04 18:09:57 +0530398 new (getPDRRepositoryInfoResp.data()) pldm_msg,
Gilbert Chende2a1322022-05-24 15:35:21 +0100399 sizeof(getPDRRepositoryInfoResp));
400 EXPECT_EQ(rc, PLDM_SUCCESS);
401
402 // queue getPDR responses
403 const size_t getPdrRespLen = 81;
404 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{
405 0x0, 0x02, 0x51, PLDM_SUCCESS, 0x0, 0x0, 0x0, 0x0, // nextRecordHandle
406 0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
407 0x5, // transferFlag
408 69, 0x0, // responseCount
409 // numeric Sensor PDR
410 0x1, 0x0, 0x0,
411 0x0, // record handle
412 0x1, // PDRHeaderVersion
413 PLDM_NUMERIC_SENSOR_PDR, // PDRType
414 0x0,
415 0x0, // recordChangeNumber
416 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
417 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH +
418 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH,
419 0, // dataLength
420 0,
421 0, // PLDMTerminusHandle
422 0x1,
423 0x0, // sensorID=1
424 120,
425 0, // entityType=Power Supply(120)
426 1,
427 0, // entityInstanceNumber
428 0x1,
429 0x0, // containerID=1
430 PLDM_NO_INIT, // sensorInit
431 false, // sensorAuxiliaryNamesPDR
432 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
433 1, // unitModifier = 1
434 0, // rateUnit
435 0, // baseOEMUnitHandle
436 0, // auxUnit
437 0, // auxUnitModifier
438 0, // auxRateUnit
439 0, // rel
440 0, // auxOEMUnitHandle
441 true, // isLinear
442 PLDM_SENSOR_DATA_SIZE_UINT8, // sensorDataSize
443 0, 0, 0xc0,
444 0x3f, // resolution=1.5
445 0, 0, 0x80,
446 0x3f, // offset=1.0
447 0,
448 0, // accuracy
449 0, // plusTolerance
450 0, // minusTolerance
451 2, // hysteresis
452 0, // supportedThresholds
453 0, // thresholdAndHysteresisVolatility
454 0, 0, 0x80,
455 0x3f, // stateTransistionInterval=1.0
456 0, 0, 0x80,
457 0x3f, // updateInverval=1.0
458 255, // maxReadable
459 0, // minReadable
460 PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat
461 0, // rangeFieldsupport
462 0, // nominalValue
463 0, // normalMax
464 0, // normalMin
465 0, // warningHigh
466 0, // warningLow
467 0, // criticalHigh
468 0, // criticalLow
469 0, // fatalHigh
470 0 // fatalLow
471 };
Pavithra Barithaya5ea72372025-02-04 18:09:57 +0530472 rc = mockTerminusManager.enqueueResponse(new (getPdrResp.data()) pldm_msg,
473 sizeof(getPdrResp));
Gilbert Chende2a1322022-05-24 15:35:21 +0100474 EXPECT_EQ(rc, PLDM_SUCCESS);
475
476 stdexec::sync_wait(platformManager.initTerminus());
477 EXPECT_EQ(true, terminus->initialized);
478 EXPECT_EQ(0, terminus->pdrs.size());
479}
480
481TEST_F(PlatformManagerTest, negativeInitTerminusTest1)
482{
483 // terminus doesn't Type2 support
Unive Tienc40d4a62025-03-12 11:36:07 +0800484 auto mappedTid =
485 mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1, std::nullopt));
Gilbert Chende2a1322022-05-24 15:35:21 +0100486 auto tid = mappedTid.value();
Chaul Lyfdf61cc2025-01-22 07:55:45 +0000487 termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
488 tid, 1 << PLDM_BASE, event);
Gilbert Chende2a1322022-05-24 15:35:21 +0100489 auto terminus = termini[tid];
490
491 stdexec::sync_wait(platformManager.initTerminus());
Chaul Lyfdf61cc2025-01-22 07:55:45 +0000492 // Run event loop for a few seconds to let sensor creation
493 // defer tasks be run. May increase time when sensor num is large
494 utils::runEventLoopForSeconds(event, 1);
Gilbert Chende2a1322022-05-24 15:35:21 +0100495 EXPECT_EQ(true, terminus->initialized);
496 EXPECT_EQ(0, terminus->pdrs.size());
Gilbert Cheneac61a42022-02-23 20:56:19 +0000497 EXPECT_EQ(0, terminus->numericSensors.size());
Gilbert Chende2a1322022-05-24 15:35:21 +0100498}
499
500TEST_F(PlatformManagerTest, negativeInitTerminusTest2)
501{
502 // terminus responses error
Unive Tienc40d4a62025-03-12 11:36:07 +0800503 auto mappedTid =
504 mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1, std::nullopt));
Gilbert Chende2a1322022-05-24 15:35:21 +0100505 auto tid = mappedTid.value();
506 termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
Chaul Lyfdf61cc2025-01-22 07:55:45 +0000507 tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM, event);
Gilbert Chende2a1322022-05-24 15:35:21 +0100508 auto terminus = termini[tid];
509
510 // queue getPDRRepositoryInfo response cc=PLDM_ERROR
511 const size_t getPDRRepositoryInfoLen = 1;
512 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen>
513 getPDRRepositoryInfoResp{0x0, 0x02, 0x50, PLDM_ERROR};
514 auto rc = mockTerminusManager.enqueueResponse(
Pavithra Barithaya5ea72372025-02-04 18:09:57 +0530515 new (getPDRRepositoryInfoResp.data()) pldm_msg,
Gilbert Chende2a1322022-05-24 15:35:21 +0100516 sizeof(getPDRRepositoryInfoResp));
517 EXPECT_EQ(rc, PLDM_SUCCESS);
518
519 // queue getPDR responses cc=PLDM_ERROR
520 const size_t getPdrRespLen = 1;
521 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{
522 0x0, 0x02, 0x51, PLDM_ERROR};
Pavithra Barithaya5ea72372025-02-04 18:09:57 +0530523 rc = mockTerminusManager.enqueueResponse(new (getPdrResp.data()) pldm_msg,
524 sizeof(getPdrResp));
Gilbert Chende2a1322022-05-24 15:35:21 +0100525 EXPECT_EQ(rc, PLDM_SUCCESS);
526
527 stdexec::sync_wait(platformManager.initTerminus());
Chaul Lyfdf61cc2025-01-22 07:55:45 +0000528 // Run event loop for a few seconds to let sensor creation
529 // defer tasks be run. May increase time when sensor num is large
530 utils::runEventLoopForSeconds(event, 1);
Gilbert Chende2a1322022-05-24 15:35:21 +0100531 EXPECT_EQ(true, terminus->initialized);
532 EXPECT_EQ(0, terminus->pdrs.size());
Gilbert Cheneac61a42022-02-23 20:56:19 +0000533 EXPECT_EQ(0, terminus->numericSensors.size());
Gilbert Chende2a1322022-05-24 15:35:21 +0100534}