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