xref: /openbmc/pldm/platform-mc/test/platform_manager_test.cpp (revision fdf61cc310dfe7bb56d007bf1026635081f44aca)
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         reinterpret_cast<pldm_msg*>(getPDRRepositoryInfoResp.data()),
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(
148         reinterpret_cast<pldm_msg*>(getPdrResp.data()), 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         reinterpret_cast<pldm_msg*>(getPdrAuxNameResp.data()),
184         sizeof(getPdrAuxNameResp));
185     EXPECT_EQ(rc, PLDM_SUCCESS);
186 
187     mockTerminusManager.updateMctpEndpointAvailability(
188         pldm::MctpInfo(10, "", "", 1), true);
189 
190     stdexec::sync_wait(platformManager.initTerminus());
191     EXPECT_EQ(true, terminus->initialized);
192     EXPECT_EQ(true, terminus->doesSupportCommand(PLDM_PLATFORM, PLDM_GET_PDR));
193     EXPECT_EQ(2, terminus->pdrs.size());
194     // 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);
197     EXPECT_EQ(1, terminus->numericSensors.size());
198     EXPECT_EQ("S0", terminus->getTerminusName().value());
199 }
200 
TEST_F(PlatformManagerTest,parseTerminusNameTest)201 TEST_F(PlatformManagerTest, parseTerminusNameTest)
202 {
203     // Add terminus
204     auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1));
205     auto tid = mappedTid.value();
206     termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
207         tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM, event);
208     auto terminus = termini[tid];
209 
210     /* Set supported command by terminus */
211     auto size = PLDM_MAX_TYPES * (PLDM_MAX_CMDS_PER_TYPE / 8);
212     std::vector<uint8_t> pldmCmds(size);
213     uint8_t type = PLDM_PLATFORM;
214     uint8_t cmd = PLDM_GET_PDR;
215     auto idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
216     pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
217     cmd = PLDM_GET_PDR_REPOSITORY_INFO;
218     idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
219     pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
220     termini[tid]->setSupportedCommands(pldmCmds);
221 
222     // queue getPDRRepositoryInfo response
223     const size_t getPDRRepositoryInfoLen =
224         PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES;
225     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen>
226         getPDRRepositoryInfoResp{
227             0x0, 0x02, 0x50, PLDM_SUCCESS,
228             0x0,                                     // repositoryState
229             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, 0x0,
230             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, // updateTime
231             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, 0x0,
232             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, // OEMUpdateTime
233             2,   0x0,  0x0,  0x0,                    // recordCount
234             0x0, 0x1,  0x0,  0x0,                    // repositorySize
235             59,  0x0,  0x0,  0x0,                    // largestRecordSize
236             0x0 // dataTransferHandleTimeout
237         };
238     auto rc = mockTerminusManager.enqueueResponse(
239         reinterpret_cast<pldm_msg*>(getPDRRepositoryInfoResp.data()),
240         sizeof(getPDRRepositoryInfoResp));
241     EXPECT_EQ(rc, PLDM_SUCCESS);
242 
243     // queue getPDR responses
244     const size_t getPdrRespLen = 81;
245     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{
246         0x0, 0x02, 0x51, PLDM_SUCCESS, 0x1, 0x0, 0x0, 0x0, // nextRecordHandle
247         0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
248         0x5,                // transferFlag
249         69, 0x0,            // responseCount
250         // numeric Sensor PDR
251         0x0, 0x0, 0x0,
252         0x0,                     // record handle
253         0x1,                     // PDRHeaderVersion
254         PLDM_NUMERIC_SENSOR_PDR, // PDRType
255         0x0,
256         0x0,                     // recordChangeNumber
257         PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
258             PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH +
259             PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH,
260         0,                             // dataLength
261         0,
262         0,                             // PLDMTerminusHandle
263         0x1,
264         0x0,                           // sensorID=1
265         120,
266         0,                             // entityType=Power Supply(120)
267         1,
268         0,                             // entityInstanceNumber
269         0x1,
270         0x0,                           // containerID=1
271         PLDM_NO_INIT,                  // sensorInit
272         false,                         // sensorAuxiliaryNamesPDR
273         PLDM_SENSOR_UNIT_DEGRESS_C,    // baseUint(2)=degrees C
274         1,                             // unitModifier = 1
275         0,                             // rateUnit
276         0,                             // baseOEMUnitHandle
277         0,                             // auxUnit
278         0,                             // auxUnitModifier
279         0,                             // auxRateUnit
280         0,                             // rel
281         0,                             // auxOEMUnitHandle
282         true,                          // isLinear
283         PLDM_SENSOR_DATA_SIZE_UINT8,   // sensorDataSize
284         0, 0, 0xc0,
285         0x3f,                          // resolution=1.5
286         0, 0, 0x80,
287         0x3f,                          // offset=1.0
288         0,
289         0,                             // accuracy
290         0,                             // plusTolerance
291         0,                             // minusTolerance
292         2,                             // hysteresis
293         0,                             // supportedThresholds
294         0,                             // thresholdAndHysteresisVolatility
295         0, 0, 0x80,
296         0x3f,                          // stateTransistionInterval=1.0
297         0, 0, 0x80,
298         0x3f,                          // updateInverval=1.0
299         255,                           // maxReadable
300         0,                             // minReadable
301         PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat
302         0,                             // rangeFieldsupport
303         0,                             // nominalValue
304         0,                             // normalMax
305         0,                             // normalMin
306         0,                             // warningHigh
307         0,                             // warningLow
308         0,                             // criticalHigh
309         0,                             // criticalLow
310         0,                             // fatalHigh
311         0                              // fatalLow
312     };
313     rc = mockTerminusManager.enqueueResponse(
314         reinterpret_cast<pldm_msg*>(getPdrResp.data()), sizeof(getPdrResp));
315     EXPECT_EQ(rc, PLDM_SUCCESS);
316 
317     const size_t getPdrAuxNameRespLen = 39;
318     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrAuxNameRespLen>
319         getPdrAuxNameResp{
320             0x0, 0x02, 0x51, PLDM_SUCCESS, 0x0, 0x0, 0x0,
321             0x0,                // nextRecordHandle
322             0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
323             0x5,                // transferFlag
324             0x1b, 0x0,          // responseCount
325             // Common PDR Header
326             0x1, 0x0, 0x0,
327             0x0,                             // record handle
328             0x1,                             // PDRHeaderVersion
329             PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
330             0x1,
331             0x0,                             // recordChangeNumber
332             0x11,
333             0,                               // dataLength
334             /* Entity Auxiliary Names PDR Data*/
335             3,
336             0x80, // entityType system software
337             0x1,
338             0x0,  // Entity instance number =1
339             0,
340             0,    // Overall system
341             0,    // shared Name Count one name only
342             01,   // nameStringCount
343             0x65, 0x6e, 0x00,
344             0x00, // Language Tag "en"
345             0x53, 0x00, 0x30, 0x00,
346             0x00  // Entity Name "S0"
347         };
348     rc = mockTerminusManager.enqueueResponse(
349         reinterpret_cast<pldm_msg*>(getPdrAuxNameResp.data()),
350         sizeof(getPdrAuxNameResp));
351     EXPECT_EQ(rc, PLDM_SUCCESS);
352 
353     mockTerminusManager.updateMctpEndpointAvailability(
354         pldm::MctpInfo(10, "", "", 1), true);
355 
356     stdexec::sync_wait(platformManager.initTerminus());
357     EXPECT_EQ(true, terminus->initialized);
358     EXPECT_EQ(2, terminus->pdrs.size());
359     EXPECT_EQ("S0", terminus->getTerminusName().value());
360 }
361 
TEST_F(PlatformManagerTest,initTerminusDontSupportGetPDRTest)362 TEST_F(PlatformManagerTest, initTerminusDontSupportGetPDRTest)
363 {
364     // Add terminus
365     auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1));
366     auto tid = mappedTid.value();
367     termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
368         tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM, event);
369     auto terminus = termini[tid];
370 
371     /* Set supported command by terminus */
372     auto size = PLDM_MAX_TYPES * (PLDM_MAX_CMDS_PER_TYPE / 8);
373     std::vector<uint8_t> pldmCmds(size);
374     uint8_t type = PLDM_PLATFORM;
375     uint8_t cmd = PLDM_GET_PDR_REPOSITORY_INFO;
376     auto idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8);
377     pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8));
378     termini[tid]->setSupportedCommands(pldmCmds);
379 
380     // queue getPDRRepositoryInfo response
381     const size_t getPDRRepositoryInfoLen =
382         PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES;
383     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen>
384         getPDRRepositoryInfoResp{
385             0x0, 0x02, 0x50, PLDM_SUCCESS,
386             0x0,                                     // repositoryState
387             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, 0x0,
388             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, // updateTime
389             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, 0x0,
390             0x0, 0x0,  0x0,  0x0,          0x0, 0x0, // OEMUpdateTime
391             1,   0x0,  0x0,  0x0,                    // recordCount
392             0x0, 0x1,  0x0,  0x0,                    // repositorySize
393             59,  0x0,  0x0,  0x0,                    // largestRecordSize
394             0x0 // dataTransferHandleTimeout
395         };
396     auto rc = mockTerminusManager.enqueueResponse(
397         reinterpret_cast<pldm_msg*>(getPDRRepositoryInfoResp.data()),
398         sizeof(getPDRRepositoryInfoResp));
399     EXPECT_EQ(rc, PLDM_SUCCESS);
400 
401     // queue getPDR responses
402     const size_t getPdrRespLen = 81;
403     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{
404         0x0, 0x02, 0x51, PLDM_SUCCESS, 0x0, 0x0, 0x0, 0x0, // nextRecordHandle
405         0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle
406         0x5,                // transferFlag
407         69, 0x0,            // responseCount
408         // numeric Sensor PDR
409         0x1, 0x0, 0x0,
410         0x0,                     // record handle
411         0x1,                     // PDRHeaderVersion
412         PLDM_NUMERIC_SENSOR_PDR, // PDRType
413         0x0,
414         0x0,                     // recordChangeNumber
415         PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
416             PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH +
417             PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH,
418         0,                             // dataLength
419         0,
420         0,                             // PLDMTerminusHandle
421         0x1,
422         0x0,                           // sensorID=1
423         120,
424         0,                             // entityType=Power Supply(120)
425         1,
426         0,                             // entityInstanceNumber
427         0x1,
428         0x0,                           // containerID=1
429         PLDM_NO_INIT,                  // sensorInit
430         false,                         // sensorAuxiliaryNamesPDR
431         PLDM_SENSOR_UNIT_DEGRESS_C,    // baseUint(2)=degrees C
432         1,                             // unitModifier = 1
433         0,                             // rateUnit
434         0,                             // baseOEMUnitHandle
435         0,                             // auxUnit
436         0,                             // auxUnitModifier
437         0,                             // auxRateUnit
438         0,                             // rel
439         0,                             // auxOEMUnitHandle
440         true,                          // isLinear
441         PLDM_SENSOR_DATA_SIZE_UINT8,   // sensorDataSize
442         0, 0, 0xc0,
443         0x3f,                          // resolution=1.5
444         0, 0, 0x80,
445         0x3f,                          // offset=1.0
446         0,
447         0,                             // accuracy
448         0,                             // plusTolerance
449         0,                             // minusTolerance
450         2,                             // hysteresis
451         0,                             // supportedThresholds
452         0,                             // thresholdAndHysteresisVolatility
453         0, 0, 0x80,
454         0x3f,                          // stateTransistionInterval=1.0
455         0, 0, 0x80,
456         0x3f,                          // updateInverval=1.0
457         255,                           // maxReadable
458         0,                             // minReadable
459         PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat
460         0,                             // rangeFieldsupport
461         0,                             // nominalValue
462         0,                             // normalMax
463         0,                             // normalMin
464         0,                             // warningHigh
465         0,                             // warningLow
466         0,                             // criticalHigh
467         0,                             // criticalLow
468         0,                             // fatalHigh
469         0                              // fatalLow
470     };
471     rc = mockTerminusManager.enqueueResponse(
472         reinterpret_cast<pldm_msg*>(getPdrResp.data()), sizeof(getPdrResp));
473     EXPECT_EQ(rc, PLDM_SUCCESS);
474 
475     stdexec::sync_wait(platformManager.initTerminus());
476     EXPECT_EQ(true, terminus->initialized);
477     EXPECT_EQ(0, terminus->pdrs.size());
478 }
479 
TEST_F(PlatformManagerTest,negativeInitTerminusTest1)480 TEST_F(PlatformManagerTest, negativeInitTerminusTest1)
481 {
482     // terminus doesn't Type2 support
483     auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1));
484     auto tid = mappedTid.value();
485     termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
486         tid, 1 << PLDM_BASE, event);
487     auto terminus = termini[tid];
488 
489     stdexec::sync_wait(platformManager.initTerminus());
490     // Run event loop for a few seconds to let sensor creation
491     // defer tasks be run. May increase time when sensor num is large
492     utils::runEventLoopForSeconds(event, 1);
493     EXPECT_EQ(true, terminus->initialized);
494     EXPECT_EQ(0, terminus->pdrs.size());
495     EXPECT_EQ(0, terminus->numericSensors.size());
496 }
497 
TEST_F(PlatformManagerTest,negativeInitTerminusTest2)498 TEST_F(PlatformManagerTest, negativeInitTerminusTest2)
499 {
500     // terminus responses error
501     auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1));
502     auto tid = mappedTid.value();
503     termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(
504         tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM, event);
505     auto terminus = termini[tid];
506 
507     // queue getPDRRepositoryInfo response cc=PLDM_ERROR
508     const size_t getPDRRepositoryInfoLen = 1;
509     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen>
510         getPDRRepositoryInfoResp{0x0, 0x02, 0x50, PLDM_ERROR};
511     auto rc = mockTerminusManager.enqueueResponse(
512         reinterpret_cast<pldm_msg*>(getPDRRepositoryInfoResp.data()),
513         sizeof(getPDRRepositoryInfoResp));
514     EXPECT_EQ(rc, PLDM_SUCCESS);
515 
516     // queue getPDR responses cc=PLDM_ERROR
517     const size_t getPdrRespLen = 1;
518     std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{
519         0x0, 0x02, 0x51, PLDM_ERROR};
520     rc = mockTerminusManager.enqueueResponse(
521         reinterpret_cast<pldm_msg*>(getPdrResp.data()), sizeof(getPdrResp));
522     EXPECT_EQ(rc, PLDM_SUCCESS);
523 
524     stdexec::sync_wait(platformManager.initTerminus());
525     // Run event loop for a few seconds to let sensor creation
526     // defer tasks be run. May increase time when sensor num is large
527     utils::runEventLoopForSeconds(event, 1);
528     EXPECT_EQ(true, terminus->initialized);
529     EXPECT_EQ(0, terminus->pdrs.size());
530     EXPECT_EQ(0, terminus->numericSensors.size());
531 }
532