xref: /openbmc/pldm/platform-mc/test/platform_manager_test.cpp (revision 5ea723773b102e5820fb638b27175b23705c1a05)
1 #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 #include "utils_test.hpp"
6 
7 #include <sdeventplus/event.hpp>
8 
9 #include <bitset>
10 
11 #include <gtest/gtest.h>
12 
13 class PlatformManagerTest : public testing::Test
14 {
15   protected:
PlatformManagerTest()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),
22         platformManager(mockTerminusManager, termini, nullptr)
23     {}
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 
TEST_F(PlatformManagerTest,initTerminusTest)35 TEST_F(PlatformManagerTest, initTerminusTest)
36 {
37     // Add terminus
38     auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1));
39     auto tid = mappedTid.value();
40     termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
41         tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM, event);
42     auto terminus = termini[tid];
43 
44     /* Set supported command by terminus */
45     auto size = PLDM_MAX_TYPES * (PLDM_MAX_CMDS_PER_TYPE / 8);
46     std::vector<uint8_t> pldmCmds(size);
47     uint8_t type = PLDM_PLATFORM;
48     uint8_t cmd = PLDM_GET_PDR;
49     auto idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
50     pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
51     cmd = PLDM_GET_PDR_REPOSITORY_INFO;
52     idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
53     pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
54     termini[tid]->setSupportedCommands(pldmCmds);
55 
56     // queue getPDRRepositoryInfo response
57     const size_t getPDRRepositoryInfoLen =
58         PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES;
59     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen>
60         getPDRRepositoryInfoResp{
61             0x0, 0x02, 0x50, PLDM_SUCCESS,
62             0x0,                                     // repositoryState
63             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, 0x0,
64             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, // updateTime
65             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, 0x0,
66             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, // OEMUpdateTime
67             2,   0x0,  0x0,  0x0,                    // recordCount
68             0x0, 0x1,  0x0,  0x0,                    // repositorySize
69             59,  0x0,  0x0,  0x0,                    // largestRecordSize
70             0x0 // dataTransferHandleTimeout
71         };
72     auto rc = mockTerminusManager.enqueueResponse(
73         new (getPDRRepositoryInfoResp.data()) pldm_msg,
74         sizeof(getPDRRepositoryInfoResp));
75     EXPECT_EQ(rc, PLDM_SUCCESS);
76 
77     // queue getPDR responses
78     const size_t getPdrRespLen = 81;
79     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{
80         0x0, 0x02, 0x51, PLDM_SUCCESS, 0x1, 0x0, 0x0, 0x0, // nextRecordHandle
81         0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
82         0x5,                // transferFlag
83         69, 0x0,            // responseCount
84         // numeric Sensor PDR
85         0x0, 0x0, 0x0,
86         0x0,                     // record handle
87         0x1,                     // PDRHeaderVersion
88         PLDM_NUMERIC_SENSOR_PDR, // PDRType
89         0x0,
90         0x0,                     // recordChangeNumber
91         PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
92             PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH +
93             PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH,
94         0,                             // dataLength
95         0,
96         0,                             // PLDMTerminusHandle
97         0x1,
98         0x0,                           // sensorID=1
99         120,
100         0,                             // entityType=Power Supply(120)
101         1,
102         0,                             // entityInstanceNumber
103         0x1,
104         0x0,                           // containerID=1
105         PLDM_NO_INIT,                  // sensorInit
106         false,                         // sensorAuxiliaryNamesPDR
107         PLDM_SENSOR_UNIT_DEGRESS_C,    // baseUint(2)=degrees C
108         1,                             // unitModifier = 1
109         0,                             // rateUnit
110         0,                             // baseOEMUnitHandle
111         0,                             // auxUnit
112         0,                             // auxUnitModifier
113         0,                             // auxRateUnit
114         0,                             // rel
115         0,                             // auxOEMUnitHandle
116         true,                          // isLinear
117         PLDM_SENSOR_DATA_SIZE_UINT8,   // sensorDataSize
118         0, 0, 0xc0,
119         0x3f,                          // resolution=1.5
120         0, 0, 0x80,
121         0x3f,                          // offset=1.0
122         0,
123         0,                             // accuracy
124         0,                             // plusTolerance
125         0,                             // minusTolerance
126         2,                             // hysteresis
127         0,                             // supportedThresholds
128         0,                             // thresholdAndHysteresisVolatility
129         0, 0, 0x80,
130         0x3f,                          // stateTransistionInterval=1.0
131         0, 0, 0x80,
132         0x3f,                          // updateInverval=1.0
133         255,                           // maxReadable
134         0,                             // minReadable
135         PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat
136         0,                             // rangeFieldsupport
137         0,                             // nominalValue
138         0,                             // normalMax
139         0,                             // normalMin
140         0,                             // warningHigh
141         0,                             // warningLow
142         0,                             // criticalHigh
143         0,                             // criticalLow
144         0,                             // fatalHigh
145         0                              // fatalLow
146     };
147     rc = mockTerminusManager.enqueueResponse(new (getPdrResp.data()) pldm_msg,
148                                              sizeof(getPdrResp));
149     EXPECT_EQ(rc, PLDM_SUCCESS);
150 
151     const size_t getPdrAuxNameRespLen = 39;
152     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrAuxNameRespLen>
153         getPdrAuxNameResp{
154             0x0, 0x02, 0x51, PLDM_SUCCESS, 0x0, 0x0, 0x0,
155             0x0,                // nextRecordHandle
156             0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
157             0x5,                // transferFlag
158             0x1b, 0x0,          // responseCount
159             // Common PDR Header
160             0x1, 0x0, 0x0,
161             0x0,                             // record handle
162             0x1,                             // PDRHeaderVersion
163             PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
164             0x1,
165             0x0,                             // recordChangeNumber
166             0x11,
167             0,                               // dataLength
168             /* Entity Auxiliary Names PDR Data*/
169             3,
170             0x80, // entityType system software
171             0x1,
172             0x0,  // Entity instance number =1
173             0,
174             0,    // Overall system
175             0,    // shared Name Count one name only
176             01,   // nameStringCount
177             0x65, 0x6e, 0x00,
178             0x00, // Language Tag "en"
179             0x53, 0x00, 0x30, 0x00,
180             0x00  // Entity Name "S0"
181         };
182     rc = mockTerminusManager.enqueueResponse(
183         new (getPdrAuxNameResp.data()) pldm_msg, sizeof(getPdrAuxNameResp));
184     EXPECT_EQ(rc, PLDM_SUCCESS);
185 
186     mockTerminusManager.updateMctpEndpointAvailability(
187         pldm::MctpInfo(10, "", "", 1), true);
188 
189     stdexec::sync_wait(platformManager.initTerminus());
190     EXPECT_EQ(true, terminus->initialized);
191     EXPECT_EQ(true, terminus->doesSupportCommand(PLDM_PLATFORM, PLDM_GET_PDR));
192     EXPECT_EQ(2, terminus->pdrs.size());
193     // Run event loop for a few seconds to let sensor creation
194     // defer tasks be run. May increase time when sensor num is large
195     utils::runEventLoopForSeconds(event, 1);
196     EXPECT_EQ(1, terminus->numericSensors.size());
197     EXPECT_EQ("S0", terminus->getTerminusName().value());
198 }
199 
TEST_F(PlatformManagerTest,parseTerminusNameTest)200 TEST_F(PlatformManagerTest, parseTerminusNameTest)
201 {
202     // Add terminus
203     auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1));
204     auto tid = mappedTid.value();
205     termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
206         tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM, event);
207     auto terminus = termini[tid];
208 
209     /* Set supported command by terminus */
210     auto size = PLDM_MAX_TYPES * (PLDM_MAX_CMDS_PER_TYPE / 8);
211     std::vector<uint8_t> pldmCmds(size);
212     uint8_t type = PLDM_PLATFORM;
213     uint8_t cmd = PLDM_GET_PDR;
214     auto idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
215     pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
216     cmd = PLDM_GET_PDR_REPOSITORY_INFO;
217     idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
218     pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
219     termini[tid]->setSupportedCommands(pldmCmds);
220 
221     // queue getPDRRepositoryInfo response
222     const size_t getPDRRepositoryInfoLen =
223         PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES;
224     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen>
225         getPDRRepositoryInfoResp{
226             0x0, 0x02, 0x50, PLDM_SUCCESS,
227             0x0,                                     // repositoryState
228             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, 0x0,
229             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, // updateTime
230             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, 0x0,
231             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, // OEMUpdateTime
232             2,   0x0,  0x0,  0x0,                    // recordCount
233             0x0, 0x1,  0x0,  0x0,                    // repositorySize
234             59,  0x0,  0x0,  0x0,                    // largestRecordSize
235             0x0 // dataTransferHandleTimeout
236         };
237     auto rc = mockTerminusManager.enqueueResponse(
238         new (getPDRRepositoryInfoResp.data()) pldm_msg,
239         sizeof(getPDRRepositoryInfoResp));
240     EXPECT_EQ(rc, PLDM_SUCCESS);
241 
242     // queue getPDR responses
243     const size_t getPdrRespLen = 81;
244     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{
245         0x0, 0x02, 0x51, PLDM_SUCCESS, 0x1, 0x0, 0x0, 0x0, // nextRecordHandle
246         0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
247         0x5,                // transferFlag
248         69, 0x0,            // responseCount
249         // numeric Sensor PDR
250         0x0, 0x0, 0x0,
251         0x0,                     // record handle
252         0x1,                     // PDRHeaderVersion
253         PLDM_NUMERIC_SENSOR_PDR, // PDRType
254         0x0,
255         0x0,                     // recordChangeNumber
256         PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
257             PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH +
258             PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH,
259         0,                             // dataLength
260         0,
261         0,                             // PLDMTerminusHandle
262         0x1,
263         0x0,                           // sensorID=1
264         120,
265         0,                             // entityType=Power Supply(120)
266         1,
267         0,                             // entityInstanceNumber
268         0x1,
269         0x0,                           // containerID=1
270         PLDM_NO_INIT,                  // sensorInit
271         false,                         // sensorAuxiliaryNamesPDR
272         PLDM_SENSOR_UNIT_DEGRESS_C,    // baseUint(2)=degrees C
273         1,                             // unitModifier = 1
274         0,                             // rateUnit
275         0,                             // baseOEMUnitHandle
276         0,                             // auxUnit
277         0,                             // auxUnitModifier
278         0,                             // auxRateUnit
279         0,                             // rel
280         0,                             // auxOEMUnitHandle
281         true,                          // isLinear
282         PLDM_SENSOR_DATA_SIZE_UINT8,   // sensorDataSize
283         0, 0, 0xc0,
284         0x3f,                          // resolution=1.5
285         0, 0, 0x80,
286         0x3f,                          // offset=1.0
287         0,
288         0,                             // accuracy
289         0,                             // plusTolerance
290         0,                             // minusTolerance
291         2,                             // hysteresis
292         0,                             // supportedThresholds
293         0,                             // thresholdAndHysteresisVolatility
294         0, 0, 0x80,
295         0x3f,                          // stateTransistionInterval=1.0
296         0, 0, 0x80,
297         0x3f,                          // updateInverval=1.0
298         255,                           // maxReadable
299         0,                             // minReadable
300         PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat
301         0,                             // rangeFieldsupport
302         0,                             // nominalValue
303         0,                             // normalMax
304         0,                             // normalMin
305         0,                             // warningHigh
306         0,                             // warningLow
307         0,                             // criticalHigh
308         0,                             // criticalLow
309         0,                             // fatalHigh
310         0                              // fatalLow
311     };
312     rc = mockTerminusManager.enqueueResponse(new (getPdrResp.data()) pldm_msg,
313                                              sizeof(getPdrResp));
314     EXPECT_EQ(rc, PLDM_SUCCESS);
315 
316     const size_t getPdrAuxNameRespLen = 39;
317     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrAuxNameRespLen>
318         getPdrAuxNameResp{
319             0x0, 0x02, 0x51, PLDM_SUCCESS, 0x0, 0x0, 0x0,
320             0x0,                // nextRecordHandle
321             0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
322             0x5,                // transferFlag
323             0x1b, 0x0,          // responseCount
324             // Common PDR Header
325             0x1, 0x0, 0x0,
326             0x0,                             // record handle
327             0x1,                             // PDRHeaderVersion
328             PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
329             0x1,
330             0x0,                             // recordChangeNumber
331             0x11,
332             0,                               // dataLength
333             /* Entity Auxiliary Names PDR Data*/
334             3,
335             0x80, // entityType system software
336             0x1,
337             0x0,  // Entity instance number =1
338             0,
339             0,    // Overall system
340             0,    // shared Name Count one name only
341             01,   // nameStringCount
342             0x65, 0x6e, 0x00,
343             0x00, // Language Tag "en"
344             0x53, 0x00, 0x30, 0x00,
345             0x00  // Entity Name "S0"
346         };
347     rc = mockTerminusManager.enqueueResponse(
348         new (getPdrAuxNameResp.data()) pldm_msg, sizeof(getPdrAuxNameResp));
349     EXPECT_EQ(rc, PLDM_SUCCESS);
350 
351     mockTerminusManager.updateMctpEndpointAvailability(
352         pldm::MctpInfo(10, "", "", 1), true);
353 
354     stdexec::sync_wait(platformManager.initTerminus());
355     EXPECT_EQ(true, terminus->initialized);
356     EXPECT_EQ(2, terminus->pdrs.size());
357     EXPECT_EQ("S0", terminus->getTerminusName().value());
358 }
359 
TEST_F(PlatformManagerTest,initTerminusDontSupportGetPDRTest)360 TEST_F(PlatformManagerTest, initTerminusDontSupportGetPDRTest)
361 {
362     // Add terminus
363     auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1));
364     auto tid = mappedTid.value();
365     termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
366         tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM, event);
367     auto terminus = termini[tid];
368 
369     /* Set supported command by terminus */
370     auto size = PLDM_MAX_TYPES * (PLDM_MAX_CMDS_PER_TYPE / 8);
371     std::vector<uint8_t> pldmCmds(size);
372     uint8_t type = PLDM_PLATFORM;
373     uint8_t cmd = PLDM_GET_PDR_REPOSITORY_INFO;
374     auto idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
375     pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
376     termini[tid]->setSupportedCommands(pldmCmds);
377 
378     // queue getPDRRepositoryInfo response
379     const size_t getPDRRepositoryInfoLen =
380         PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES;
381     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen>
382         getPDRRepositoryInfoResp{
383             0x0, 0x02, 0x50, PLDM_SUCCESS,
384             0x0,                                     // repositoryState
385             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, 0x0,
386             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, // updateTime
387             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, 0x0,
388             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, // OEMUpdateTime
389             1,   0x0,  0x0,  0x0,                    // recordCount
390             0x0, 0x1,  0x0,  0x0,                    // repositorySize
391             59,  0x0,  0x0,  0x0,                    // largestRecordSize
392             0x0 // dataTransferHandleTimeout
393         };
394     auto rc = mockTerminusManager.enqueueResponse(
395         new (getPDRRepositoryInfoResp.data()) pldm_msg,
396         sizeof(getPDRRepositoryInfoResp));
397     EXPECT_EQ(rc, PLDM_SUCCESS);
398 
399     // queue getPDR responses
400     const size_t getPdrRespLen = 81;
401     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{
402         0x0, 0x02, 0x51, PLDM_SUCCESS, 0x0, 0x0, 0x0, 0x0, // nextRecordHandle
403         0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
404         0x5,                // transferFlag
405         69, 0x0,            // responseCount
406         // numeric Sensor PDR
407         0x1, 0x0, 0x0,
408         0x0,                     // record handle
409         0x1,                     // PDRHeaderVersion
410         PLDM_NUMERIC_SENSOR_PDR, // PDRType
411         0x0,
412         0x0,                     // recordChangeNumber
413         PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
414             PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH +
415             PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH,
416         0,                             // dataLength
417         0,
418         0,                             // PLDMTerminusHandle
419         0x1,
420         0x0,                           // sensorID=1
421         120,
422         0,                             // entityType=Power Supply(120)
423         1,
424         0,                             // entityInstanceNumber
425         0x1,
426         0x0,                           // containerID=1
427         PLDM_NO_INIT,                  // sensorInit
428         false,                         // sensorAuxiliaryNamesPDR
429         PLDM_SENSOR_UNIT_DEGRESS_C,    // baseUint(2)=degrees C
430         1,                             // unitModifier = 1
431         0,                             // rateUnit
432         0,                             // baseOEMUnitHandle
433         0,                             // auxUnit
434         0,                             // auxUnitModifier
435         0,                             // auxRateUnit
436         0,                             // rel
437         0,                             // auxOEMUnitHandle
438         true,                          // isLinear
439         PLDM_SENSOR_DATA_SIZE_UINT8,   // sensorDataSize
440         0, 0, 0xc0,
441         0x3f,                          // resolution=1.5
442         0, 0, 0x80,
443         0x3f,                          // offset=1.0
444         0,
445         0,                             // accuracy
446         0,                             // plusTolerance
447         0,                             // minusTolerance
448         2,                             // hysteresis
449         0,                             // supportedThresholds
450         0,                             // thresholdAndHysteresisVolatility
451         0, 0, 0x80,
452         0x3f,                          // stateTransistionInterval=1.0
453         0, 0, 0x80,
454         0x3f,                          // updateInverval=1.0
455         255,                           // maxReadable
456         0,                             // minReadable
457         PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat
458         0,                             // rangeFieldsupport
459         0,                             // nominalValue
460         0,                             // normalMax
461         0,                             // normalMin
462         0,                             // warningHigh
463         0,                             // warningLow
464         0,                             // criticalHigh
465         0,                             // criticalLow
466         0,                             // fatalHigh
467         0                              // fatalLow
468     };
469     rc = mockTerminusManager.enqueueResponse(new (getPdrResp.data()) pldm_msg,
470                                              sizeof(getPdrResp));
471     EXPECT_EQ(rc, PLDM_SUCCESS);
472 
473     stdexec::sync_wait(platformManager.initTerminus());
474     EXPECT_EQ(true, terminus->initialized);
475     EXPECT_EQ(0, terminus->pdrs.size());
476 }
477 
TEST_F(PlatformManagerTest,negativeInitTerminusTest1)478 TEST_F(PlatformManagerTest, negativeInitTerminusTest1)
479 {
480     // terminus doesn't Type2 support
481     auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1));
482     auto tid = mappedTid.value();
483     termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
484         tid, 1 << PLDM_BASE, event);
485     auto terminus = termini[tid];
486 
487     stdexec::sync_wait(platformManager.initTerminus());
488     // Run event loop for a few seconds to let sensor creation
489     // defer tasks be run. May increase time when sensor num is large
490     utils::runEventLoopForSeconds(event, 1);
491     EXPECT_EQ(true, terminus->initialized);
492     EXPECT_EQ(0, terminus->pdrs.size());
493     EXPECT_EQ(0, terminus->numericSensors.size());
494 }
495 
TEST_F(PlatformManagerTest,negativeInitTerminusTest2)496 TEST_F(PlatformManagerTest, negativeInitTerminusTest2)
497 {
498     // terminus responses error
499     auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1));
500     auto tid = mappedTid.value();
501     termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
502         tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM, event);
503     auto terminus = termini[tid];
504 
505     // queue getPDRRepositoryInfo response cc=PLDM_ERROR
506     const size_t getPDRRepositoryInfoLen = 1;
507     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen>
508         getPDRRepositoryInfoResp{0x0, 0x02, 0x50, PLDM_ERROR};
509     auto rc = mockTerminusManager.enqueueResponse(
510         new (getPDRRepositoryInfoResp.data()) pldm_msg,
511         sizeof(getPDRRepositoryInfoResp));
512     EXPECT_EQ(rc, PLDM_SUCCESS);
513 
514     // queue getPDR responses cc=PLDM_ERROR
515     const size_t getPdrRespLen = 1;
516     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{
517         0x0, 0x02, 0x51, PLDM_ERROR};
518     rc = mockTerminusManager.enqueueResponse(new (getPdrResp.data()) pldm_msg,
519                                              sizeof(getPdrResp));
520     EXPECT_EQ(rc, PLDM_SUCCESS);
521 
522     stdexec::sync_wait(platformManager.initTerminus());
523     // Run event loop for a few seconds to let sensor creation
524     // defer tasks be run. May increase time when sensor num is large
525     utils::runEventLoopForSeconds(event, 1);
526     EXPECT_EQ(true, terminus->initialized);
527     EXPECT_EQ(0, terminus->pdrs.size());
528     EXPECT_EQ(0, terminus->numericSensors.size());
529 }
530