blob: cf6567db426489500323eadb12dbb3592f01b1cd [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"
5
6#include <sdeventplus/event.hpp>
7
8#include <bitset>
9
10#include <gtest/gtest.h>
11
12class PlatformManagerTest : public testing::Test
13{
14 protected:
15 PlatformManagerTest() :
16 bus(pldm::utils::DBusHandler::getBus()),
17 event(sdeventplus::Event::get_default()), instanceIdDb(),
18 reqHandler(pldmTransport, event, instanceIdDb, false,
19 std::chrono::seconds(1), 2, std::chrono::milliseconds(100)),
20 mockTerminusManager(event, reqHandler, instanceIdDb, termini, nullptr),
21 platformManager(mockTerminusManager, termini)
22 {}
23
24 PldmTransport* pldmTransport = nullptr;
25 sdbusplus::bus_t& bus;
26 sdeventplus::Event event;
27 TestInstanceIdDb instanceIdDb;
28 pldm::requester::Handler<pldm::requester::Request> reqHandler;
29 pldm::platform_mc::MockTerminusManager mockTerminusManager;
30 pldm::platform_mc::PlatformManager platformManager;
31 std::map<pldm_tid_t, std::shared_ptr<pldm::platform_mc::Terminus>> termini;
32};
33
34TEST_F(PlatformManagerTest, initTerminusTest)
35{
36 // Add terminus
37 auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1));
38 auto tid = mappedTid.value();
39 termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
40 tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
41 auto terminus = termini[tid];
42
43 /* Set supported command by terminus */
44 auto size = PLDM_MAX_TYPES * (PLDM_MAX_CMDS_PER_TYPE / 8);
45 std::vector<uint8_t> pldmCmds(size);
46 uint8_t type = PLDM_PLATFORM;
47 uint8_t cmd = PLDM_GET_PDR;
48 auto idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
49 pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
50 cmd = PLDM_GET_PDR_REPOSITORY_INFO;
51 idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
52 pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
53 termini[tid]->setSupportedCommands(pldmCmds);
54
55 // queue getPDRRepositoryInfo response
56 const size_t getPDRRepositoryInfoLen =
57 PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES;
58 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen>
59 getPDRRepositoryInfoResp{
60 0x0, 0x02, 0x50, PLDM_SUCCESS,
61 0x0, // repositoryState
62 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
63 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // updateTime
64 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
65 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // OEMUpdateTime
Gilbert Cheneac61a42022-02-23 20:56:19 +000066 2, 0x0, 0x0, 0x0, // recordCount
Gilbert Chende2a1322022-05-24 15:35:21 +010067 0x0, 0x1, 0x0, 0x0, // repositorySize
68 59, 0x0, 0x0, 0x0, // largestRecordSize
69 0x0 // dataTransferHandleTimeout
70 };
71 auto rc = mockTerminusManager.enqueueResponse(
Thu Nguyen98831af2024-07-30 09:51:00 +000072 reinterpret_cast<pldm_msg*>(getPDRRepositoryInfoResp.data()),
Gilbert Chende2a1322022-05-24 15:35:21 +010073 sizeof(getPDRRepositoryInfoResp));
74 EXPECT_EQ(rc, PLDM_SUCCESS);
75
76 // queue getPDR responses
77 const size_t getPdrRespLen = 81;
78 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{
Gilbert Cheneac61a42022-02-23 20:56:19 +000079 0x0, 0x02, 0x51, PLDM_SUCCESS, 0x1, 0x0, 0x0, 0x0, // nextRecordHandle
Gilbert Chende2a1322022-05-24 15:35:21 +010080 0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
81 0x5, // transferFlag
82 69, 0x0, // responseCount
83 // numeric Sensor PDR
Gilbert Cheneac61a42022-02-23 20:56:19 +000084 0x0, 0x0, 0x0,
Gilbert Chende2a1322022-05-24 15:35:21 +010085 0x0, // record handle
86 0x1, // PDRHeaderVersion
87 PLDM_NUMERIC_SENSOR_PDR, // PDRType
88 0x0,
89 0x0, // recordChangeNumber
90 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
91 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH +
92 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH,
93 0, // dataLength
94 0,
95 0, // PLDMTerminusHandle
96 0x1,
97 0x0, // sensorID=1
98 120,
99 0, // entityType=Power Supply(120)
100 1,
101 0, // entityInstanceNumber
102 0x1,
103 0x0, // containerID=1
104 PLDM_NO_INIT, // sensorInit
105 false, // sensorAuxiliaryNamesPDR
106 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
107 1, // unitModifier = 1
108 0, // rateUnit
109 0, // baseOEMUnitHandle
110 0, // auxUnit
111 0, // auxUnitModifier
112 0, // auxRateUnit
113 0, // rel
114 0, // auxOEMUnitHandle
115 true, // isLinear
116 PLDM_SENSOR_DATA_SIZE_UINT8, // sensorDataSize
117 0, 0, 0xc0,
118 0x3f, // resolution=1.5
119 0, 0, 0x80,
120 0x3f, // offset=1.0
121 0,
122 0, // accuracy
123 0, // plusTolerance
124 0, // minusTolerance
125 2, // hysteresis
126 0, // supportedThresholds
127 0, // thresholdAndHysteresisVolatility
128 0, 0, 0x80,
129 0x3f, // stateTransistionInterval=1.0
130 0, 0, 0x80,
131 0x3f, // updateInverval=1.0
132 255, // maxReadable
133 0, // minReadable
134 PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat
135 0, // rangeFieldsupport
136 0, // nominalValue
137 0, // normalMax
138 0, // normalMin
139 0, // warningHigh
140 0, // warningLow
141 0, // criticalHigh
142 0, // criticalLow
143 0, // fatalHigh
144 0 // fatalLow
145 };
Thu Nguyen98831af2024-07-30 09:51:00 +0000146 rc = mockTerminusManager.enqueueResponse(
147 reinterpret_cast<pldm_msg*>(getPdrResp.data()), sizeof(getPdrResp));
Gilbert Chende2a1322022-05-24 15:35:21 +0100148 EXPECT_EQ(rc, PLDM_SUCCESS);
149
Gilbert Cheneac61a42022-02-23 20:56:19 +0000150 const size_t getPdrAuxNameRespLen = 39;
151 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrAuxNameRespLen>
152 getPdrAuxNameResp{
153 0x0, 0x02, 0x51, PLDM_SUCCESS, 0x0, 0x0, 0x0,
154 0x0, // nextRecordHandle
155 0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
156 0x5, // transferFlag
157 0x1b, 0x0, // responseCount
158 // Common PDR Header
159 0x1, 0x0, 0x0,
160 0x0, // record handle
161 0x1, // PDRHeaderVersion
162 PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
163 0x1,
164 0x0, // recordChangeNumber
165 0x11,
166 0, // dataLength
167 /* Entity Auxiliary Names PDR Data*/
168 3,
169 0x80, // entityType system software
170 0x1,
171 0x0, // Entity instance number =1
172 0,
Manojkiran Eda04ac9972024-09-06 10:57:12 +0530173 0, // Overall system
Gilbert Cheneac61a42022-02-23 20:56:19 +0000174 0, // shared Name Count one name only
175 01, // nameStringCount
176 0x65, 0x6e, 0x00,
177 0x00, // Language Tag "en"
178 0x53, 0x00, 0x30, 0x00,
179 0x00 // Entity Name "S0"
180 };
181 rc = mockTerminusManager.enqueueResponse(
182 reinterpret_cast<pldm_msg*>(getPdrAuxNameResp.data()),
183 sizeof(getPdrAuxNameResp));
184 EXPECT_EQ(rc, PLDM_SUCCESS);
185
Chau Ly75e00422024-03-19 12:33:08 +0000186 mockTerminusManager.updateMctpEndpointAvailability(
187 pldm::MctpInfo(10, "", "", 1), true);
188
Gilbert Chende2a1322022-05-24 15:35:21 +0100189 stdexec::sync_wait(platformManager.initTerminus());
190 EXPECT_EQ(true, terminus->initialized);
Chau Ly75e00422024-03-19 12:33:08 +0000191 EXPECT_EQ(true, terminus->doesSupportCommand(PLDM_PLATFORM, PLDM_GET_PDR));
Gilbert Cheneac61a42022-02-23 20:56:19 +0000192 EXPECT_EQ(2, terminus->pdrs.size());
193 EXPECT_EQ(1, terminus->numericSensors.size());
Thu Nguyen9fc79122024-09-10 10:15:01 +0000194 EXPECT_EQ("S0", terminus->getTerminusName().value());
Gilbert Chende2a1322022-05-24 15:35:21 +0100195}
196
Thu Nguyenb8cf46b2024-06-15 02:44:35 +0000197TEST_F(PlatformManagerTest, parseTerminusNameTest)
198{
199 // Add terminus
200 auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1));
201 auto tid = mappedTid.value();
202 termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
203 tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
204 auto terminus = termini[tid];
205
206 /* Set supported command by terminus */
207 auto size = PLDM_MAX_TYPES * (PLDM_MAX_CMDS_PER_TYPE / 8);
208 std::vector<uint8_t> pldmCmds(size);
209 uint8_t type = PLDM_PLATFORM;
210 uint8_t cmd = PLDM_GET_PDR;
211 auto idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
212 pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
213 cmd = PLDM_GET_PDR_REPOSITORY_INFO;
214 idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
215 pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
216 termini[tid]->setSupportedCommands(pldmCmds);
217
218 // queue getPDRRepositoryInfo response
219 const size_t getPDRRepositoryInfoLen =
220 PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES;
221 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen>
222 getPDRRepositoryInfoResp{
223 0x0, 0x02, 0x50, PLDM_SUCCESS,
224 0x0, // repositoryState
225 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
226 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // updateTime
227 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
228 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // OEMUpdateTime
229 2, 0x0, 0x0, 0x0, // recordCount
230 0x0, 0x1, 0x0, 0x0, // repositorySize
231 59, 0x0, 0x0, 0x0, // largestRecordSize
232 0x0 // dataTransferHandleTimeout
233 };
234 auto rc = mockTerminusManager.enqueueResponse(
235 reinterpret_cast<pldm_msg*>(getPDRRepositoryInfoResp.data()),
236 sizeof(getPDRRepositoryInfoResp));
237 EXPECT_EQ(rc, PLDM_SUCCESS);
238
239 // queue getPDR responses
240 const size_t getPdrRespLen = 81;
241 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{
242 0x0, 0x02, 0x51, PLDM_SUCCESS, 0x1, 0x0, 0x0, 0x0, // nextRecordHandle
243 0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
244 0x5, // transferFlag
245 69, 0x0, // responseCount
246 // numeric Sensor PDR
247 0x0, 0x0, 0x0,
248 0x0, // record handle
249 0x1, // PDRHeaderVersion
250 PLDM_NUMERIC_SENSOR_PDR, // PDRType
251 0x0,
252 0x0, // recordChangeNumber
253 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
254 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH +
255 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH,
256 0, // dataLength
257 0,
258 0, // PLDMTerminusHandle
259 0x1,
260 0x0, // sensorID=1
261 120,
262 0, // entityType=Power Supply(120)
263 1,
264 0, // entityInstanceNumber
265 0x1,
266 0x0, // containerID=1
267 PLDM_NO_INIT, // sensorInit
268 false, // sensorAuxiliaryNamesPDR
269 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
270 1, // unitModifier = 1
271 0, // rateUnit
272 0, // baseOEMUnitHandle
273 0, // auxUnit
274 0, // auxUnitModifier
275 0, // auxRateUnit
276 0, // rel
277 0, // auxOEMUnitHandle
278 true, // isLinear
279 PLDM_SENSOR_DATA_SIZE_UINT8, // sensorDataSize
280 0, 0, 0xc0,
281 0x3f, // resolution=1.5
282 0, 0, 0x80,
283 0x3f, // offset=1.0
284 0,
285 0, // accuracy
286 0, // plusTolerance
287 0, // minusTolerance
288 2, // hysteresis
289 0, // supportedThresholds
290 0, // thresholdAndHysteresisVolatility
291 0, 0, 0x80,
292 0x3f, // stateTransistionInterval=1.0
293 0, 0, 0x80,
294 0x3f, // updateInverval=1.0
295 255, // maxReadable
296 0, // minReadable
297 PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat
298 0, // rangeFieldsupport
299 0, // nominalValue
300 0, // normalMax
301 0, // normalMin
302 0, // warningHigh
303 0, // warningLow
304 0, // criticalHigh
305 0, // criticalLow
306 0, // fatalHigh
307 0 // fatalLow
308 };
309 rc = mockTerminusManager.enqueueResponse(
310 reinterpret_cast<pldm_msg*>(getPdrResp.data()), sizeof(getPdrResp));
311 EXPECT_EQ(rc, PLDM_SUCCESS);
312
313 const size_t getPdrAuxNameRespLen = 39;
314 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrAuxNameRespLen>
315 getPdrAuxNameResp{
316 0x0, 0x02, 0x51, PLDM_SUCCESS, 0x0, 0x0, 0x0,
317 0x0, // nextRecordHandle
318 0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
319 0x5, // transferFlag
320 0x1b, 0x0, // responseCount
321 // Common PDR Header
322 0x1, 0x0, 0x0,
323 0x0, // record handle
324 0x1, // PDRHeaderVersion
325 PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
326 0x1,
327 0x0, // recordChangeNumber
328 0x11,
329 0, // dataLength
330 /* Entity Auxiliary Names PDR Data*/
331 3,
332 0x80, // entityType system software
333 0x1,
334 0x0, // Entity instance number =1
335 0,
Manojkiran Eda04ac9972024-09-06 10:57:12 +0530336 0, // Overall system
Thu Nguyenb8cf46b2024-06-15 02:44:35 +0000337 0, // shared Name Count one name only
338 01, // nameStringCount
339 0x65, 0x6e, 0x00,
340 0x00, // Language Tag "en"
341 0x53, 0x00, 0x30, 0x00,
342 0x00 // Entity Name "S0"
343 };
344 rc = mockTerminusManager.enqueueResponse(
345 reinterpret_cast<pldm_msg*>(getPdrAuxNameResp.data()),
346 sizeof(getPdrAuxNameResp));
347 EXPECT_EQ(rc, PLDM_SUCCESS);
348
Chau Ly75e00422024-03-19 12:33:08 +0000349 mockTerminusManager.updateMctpEndpointAvailability(
350 pldm::MctpInfo(10, "", "", 1), true);
351
Thu Nguyenb8cf46b2024-06-15 02:44:35 +0000352 stdexec::sync_wait(platformManager.initTerminus());
353 EXPECT_EQ(true, terminus->initialized);
354 EXPECT_EQ(2, terminus->pdrs.size());
Thu Nguyen9fc79122024-09-10 10:15:01 +0000355 EXPECT_EQ("S0", terminus->getTerminusName().value());
Thu Nguyenb8cf46b2024-06-15 02:44:35 +0000356}
357
Gilbert Chende2a1322022-05-24 15:35:21 +0100358TEST_F(PlatformManagerTest, initTerminusDontSupportGetPDRTest)
359{
360 // Add terminus
361 auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1));
362 auto tid = mappedTid.value();
363 termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
364 tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
365 auto terminus = termini[tid];
366
367 /* Set supported command by terminus */
368 auto size = PLDM_MAX_TYPES * (PLDM_MAX_CMDS_PER_TYPE / 8);
369 std::vector<uint8_t> pldmCmds(size);
370 uint8_t type = PLDM_PLATFORM;
371 uint8_t cmd = PLDM_GET_PDR_REPOSITORY_INFO;
372 auto idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
373 pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
374 termini[tid]->setSupportedCommands(pldmCmds);
375
376 // queue getPDRRepositoryInfo response
377 const size_t getPDRRepositoryInfoLen =
378 PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES;
379 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen>
380 getPDRRepositoryInfoResp{
381 0x0, 0x02, 0x50, PLDM_SUCCESS,
382 0x0, // repositoryState
383 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
384 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // updateTime
385 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
386 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // OEMUpdateTime
387 1, 0x0, 0x0, 0x0, // recordCount
388 0x0, 0x1, 0x0, 0x0, // repositorySize
389 59, 0x0, 0x0, 0x0, // largestRecordSize
390 0x0 // dataTransferHandleTimeout
391 };
392 auto rc = mockTerminusManager.enqueueResponse(
Thu Nguyen98831af2024-07-30 09:51:00 +0000393 reinterpret_cast<pldm_msg*>(getPDRRepositoryInfoResp.data()),
Gilbert Chende2a1322022-05-24 15:35:21 +0100394 sizeof(getPDRRepositoryInfoResp));
395 EXPECT_EQ(rc, PLDM_SUCCESS);
396
397 // queue getPDR responses
398 const size_t getPdrRespLen = 81;
399 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{
400 0x0, 0x02, 0x51, PLDM_SUCCESS, 0x0, 0x0, 0x0, 0x0, // nextRecordHandle
401 0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
402 0x5, // transferFlag
403 69, 0x0, // responseCount
404 // numeric Sensor PDR
405 0x1, 0x0, 0x0,
406 0x0, // record handle
407 0x1, // PDRHeaderVersion
408 PLDM_NUMERIC_SENSOR_PDR, // PDRType
409 0x0,
410 0x0, // recordChangeNumber
411 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
412 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH +
413 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH,
414 0, // dataLength
415 0,
416 0, // PLDMTerminusHandle
417 0x1,
418 0x0, // sensorID=1
419 120,
420 0, // entityType=Power Supply(120)
421 1,
422 0, // entityInstanceNumber
423 0x1,
424 0x0, // containerID=1
425 PLDM_NO_INIT, // sensorInit
426 false, // sensorAuxiliaryNamesPDR
427 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
428 1, // unitModifier = 1
429 0, // rateUnit
430 0, // baseOEMUnitHandle
431 0, // auxUnit
432 0, // auxUnitModifier
433 0, // auxRateUnit
434 0, // rel
435 0, // auxOEMUnitHandle
436 true, // isLinear
437 PLDM_SENSOR_DATA_SIZE_UINT8, // sensorDataSize
438 0, 0, 0xc0,
439 0x3f, // resolution=1.5
440 0, 0, 0x80,
441 0x3f, // offset=1.0
442 0,
443 0, // accuracy
444 0, // plusTolerance
445 0, // minusTolerance
446 2, // hysteresis
447 0, // supportedThresholds
448 0, // thresholdAndHysteresisVolatility
449 0, 0, 0x80,
450 0x3f, // stateTransistionInterval=1.0
451 0, 0, 0x80,
452 0x3f, // updateInverval=1.0
453 255, // maxReadable
454 0, // minReadable
455 PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat
456 0, // rangeFieldsupport
457 0, // nominalValue
458 0, // normalMax
459 0, // normalMin
460 0, // warningHigh
461 0, // warningLow
462 0, // criticalHigh
463 0, // criticalLow
464 0, // fatalHigh
465 0 // fatalLow
466 };
Thu Nguyen98831af2024-07-30 09:51:00 +0000467 rc = mockTerminusManager.enqueueResponse(
468 reinterpret_cast<pldm_msg*>(getPdrResp.data()), sizeof(getPdrResp));
Gilbert Chende2a1322022-05-24 15:35:21 +0100469 EXPECT_EQ(rc, PLDM_SUCCESS);
470
471 stdexec::sync_wait(platformManager.initTerminus());
472 EXPECT_EQ(true, terminus->initialized);
473 EXPECT_EQ(0, terminus->pdrs.size());
474}
475
476TEST_F(PlatformManagerTest, negativeInitTerminusTest1)
477{
478 // terminus doesn't Type2 support
479 auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1));
480 auto tid = mappedTid.value();
481 termini[tid] =
482 std::make_shared<pldm::platform_mc::Terminus>(tid, 1 << PLDM_BASE);
483 auto terminus = termini[tid];
484
485 stdexec::sync_wait(platformManager.initTerminus());
486 EXPECT_EQ(true, terminus->initialized);
487 EXPECT_EQ(0, terminus->pdrs.size());
Gilbert Cheneac61a42022-02-23 20:56:19 +0000488 EXPECT_EQ(0, terminus->numericSensors.size());
Gilbert Chende2a1322022-05-24 15:35:21 +0100489}
490
491TEST_F(PlatformManagerTest, negativeInitTerminusTest2)
492{
493 // terminus responses error
494 auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1));
495 auto tid = mappedTid.value();
496 termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
497 tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
498 auto terminus = termini[tid];
499
500 // queue getPDRRepositoryInfo response cc=PLDM_ERROR
501 const size_t getPDRRepositoryInfoLen = 1;
502 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen>
503 getPDRRepositoryInfoResp{0x0, 0x02, 0x50, PLDM_ERROR};
504 auto rc = mockTerminusManager.enqueueResponse(
Thu Nguyen98831af2024-07-30 09:51:00 +0000505 reinterpret_cast<pldm_msg*>(getPDRRepositoryInfoResp.data()),
Gilbert Chende2a1322022-05-24 15:35:21 +0100506 sizeof(getPDRRepositoryInfoResp));
507 EXPECT_EQ(rc, PLDM_SUCCESS);
508
509 // queue getPDR responses cc=PLDM_ERROR
510 const size_t getPdrRespLen = 1;
511 std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{
512 0x0, 0x02, 0x51, PLDM_ERROR};
Thu Nguyen98831af2024-07-30 09:51:00 +0000513 rc = mockTerminusManager.enqueueResponse(
514 reinterpret_cast<pldm_msg*>(getPdrResp.data()), sizeof(getPdrResp));
Gilbert Chende2a1322022-05-24 15:35:21 +0100515 EXPECT_EQ(rc, PLDM_SUCCESS);
516
517 stdexec::sync_wait(platformManager.initTerminus());
518 EXPECT_EQ(true, terminus->initialized);
519 EXPECT_EQ(0, terminus->pdrs.size());
Gilbert Cheneac61a42022-02-23 20:56:19 +0000520 EXPECT_EQ(0, terminus->numericSensors.size());
Gilbert Chende2a1322022-05-24 15:35:21 +0100521}