1de2a132aSGilbert Chen #include "libpldm/entity.h"
2de2a132aSGilbert Chen
33c5486d4SThu Nguyen #include "platform-mc/numeric_sensor.hpp"
46c7fed4cSGilbert Chen #include "platform-mc/terminus.hpp"
56c7fed4cSGilbert Chen
66c7fed4cSGilbert Chen #include <gtest/gtest.h>
76c7fed4cSGilbert Chen
TEST(TerminusTest,supportedTypeTest)86c7fed4cSGilbert Chen TEST(TerminusTest, supportedTypeTest)
96c7fed4cSGilbert Chen {
106c7fed4cSGilbert Chen auto t1 = pldm::platform_mc::Terminus(1, 1 << PLDM_BASE);
1116c2a0a0SPatrick Williams auto t2 =
1216c2a0a0SPatrick Williams pldm::platform_mc::Terminus(2, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
136c7fed4cSGilbert Chen
146c7fed4cSGilbert Chen EXPECT_EQ(true, t1.doesSupportType(PLDM_BASE));
156c7fed4cSGilbert Chen EXPECT_EQ(false, t1.doesSupportType(PLDM_PLATFORM));
166c7fed4cSGilbert Chen EXPECT_EQ(true, t2.doesSupportType(PLDM_BASE));
176c7fed4cSGilbert Chen EXPECT_EQ(true, t2.doesSupportType(PLDM_PLATFORM));
186c7fed4cSGilbert Chen }
196c7fed4cSGilbert Chen
TEST(TerminusTest,getTidTest)206c7fed4cSGilbert Chen TEST(TerminusTest, getTidTest)
216c7fed4cSGilbert Chen {
226c7fed4cSGilbert Chen const pldm_tid_t tid = 1;
236c7fed4cSGilbert Chen auto t1 = pldm::platform_mc::Terminus(tid, 1 << PLDM_BASE);
246c7fed4cSGilbert Chen
256c7fed4cSGilbert Chen EXPECT_EQ(tid, t1.getTid());
266c7fed4cSGilbert Chen }
27de2a132aSGilbert Chen
TEST(TerminusTest,parseSensorAuxiliaryNamesPDRTest)28de2a132aSGilbert Chen TEST(TerminusTest, parseSensorAuxiliaryNamesPDRTest)
29de2a132aSGilbert Chen {
3016c2a0a0SPatrick Williams auto t1 =
3116c2a0a0SPatrick Williams pldm::platform_mc::Terminus(1, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
32de2a132aSGilbert Chen std::vector<uint8_t> pdr1{
33de2a132aSGilbert Chen 0x0,
34de2a132aSGilbert Chen 0x0,
35de2a132aSGilbert Chen 0x0,
36de2a132aSGilbert Chen 0x1, // record handle
37de2a132aSGilbert Chen 0x1, // PDRHeaderVersion
38de2a132aSGilbert Chen PLDM_SENSOR_AUXILIARY_NAMES_PDR, // PDRType
39de2a132aSGilbert Chen 0x0,
40de2a132aSGilbert Chen 0x0, // recordChangeNumber
41de2a132aSGilbert Chen 0x0,
42de2a132aSGilbert Chen 21, // dataLength
43de2a132aSGilbert Chen 0,
44de2a132aSGilbert Chen 0x0, // PLDMTerminusHandle
45de2a132aSGilbert Chen 0x1,
46de2a132aSGilbert Chen 0x0, // sensorID
47de2a132aSGilbert Chen 0x1, // sensorCount
48de2a132aSGilbert Chen 0x1, // nameStringCount
49de2a132aSGilbert Chen 'e',
50de2a132aSGilbert Chen 'n',
51de2a132aSGilbert Chen 0x0, // nameLanguageTag
52de2a132aSGilbert Chen 0x0,
53de2a132aSGilbert Chen 'T',
54de2a132aSGilbert Chen 0x0,
55de2a132aSGilbert Chen 'E',
56de2a132aSGilbert Chen 0x0,
57de2a132aSGilbert Chen 'M',
58de2a132aSGilbert Chen 0x0,
59de2a132aSGilbert Chen 'P',
60de2a132aSGilbert Chen 0x0,
61de2a132aSGilbert Chen '1',
62de2a132aSGilbert Chen 0x0,
63de2a132aSGilbert Chen 0x0 // sensorName
64de2a132aSGilbert Chen };
65de2a132aSGilbert Chen
663c5486d4SThu Nguyen std::vector<uint8_t> pdr2{
673c5486d4SThu Nguyen 0x1, 0x0, 0x0,
683c5486d4SThu Nguyen 0x0, // record handle
693c5486d4SThu Nguyen 0x1, // PDRHeaderVersion
703c5486d4SThu Nguyen PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
713c5486d4SThu Nguyen 0x1,
723c5486d4SThu Nguyen 0x0, // recordChangeNumber
733c5486d4SThu Nguyen 0x11,
743c5486d4SThu Nguyen 0, // dataLength
753c5486d4SThu Nguyen /* Entity Auxiliary Names PDR Data*/
763c5486d4SThu Nguyen 3,
773c5486d4SThu Nguyen 0x80, // entityType system software
783c5486d4SThu Nguyen 0x1,
793c5486d4SThu Nguyen 0x0, // Entity instance number =1
803c5486d4SThu Nguyen 0,
8104ac9971SManojkiran Eda 0, // Overall system
823c5486d4SThu Nguyen 0, // shared Name Count one name only
833c5486d4SThu Nguyen 01, // nameStringCount
843c5486d4SThu Nguyen 0x65, 0x6e, 0x00,
853c5486d4SThu Nguyen 0x00, // Language Tag "en"
863c5486d4SThu Nguyen 0x53, 0x00, 0x30, 0x00,
873c5486d4SThu Nguyen 0x00 // Entity Name "S0"
883c5486d4SThu Nguyen };
893c5486d4SThu Nguyen
90de2a132aSGilbert Chen t1.pdrs.emplace_back(pdr1);
913c5486d4SThu Nguyen t1.pdrs.emplace_back(pdr2);
92de2a132aSGilbert Chen t1.parseTerminusPDRs();
93de2a132aSGilbert Chen
94de2a132aSGilbert Chen auto sensorAuxNames = t1.getSensorAuxiliaryNames(0);
95de2a132aSGilbert Chen EXPECT_EQ(nullptr, sensorAuxNames);
96de2a132aSGilbert Chen
97de2a132aSGilbert Chen sensorAuxNames = t1.getSensorAuxiliaryNames(1);
98de2a132aSGilbert Chen EXPECT_NE(nullptr, sensorAuxNames);
99de2a132aSGilbert Chen
100de2a132aSGilbert Chen const auto& [sensorId, sensorCnt, names] = *sensorAuxNames;
101de2a132aSGilbert Chen EXPECT_EQ(1, sensorId);
102de2a132aSGilbert Chen EXPECT_EQ(1, sensorCnt);
103de2a132aSGilbert Chen EXPECT_EQ(1, names.size());
104de2a132aSGilbert Chen EXPECT_EQ(1, names[0].size());
105de2a132aSGilbert Chen EXPECT_EQ("en", names[0][0].first);
106de2a132aSGilbert Chen EXPECT_EQ("TEMP1", names[0][0].second);
1073c5486d4SThu Nguyen EXPECT_EQ(2, t1.pdrs.size());
108*9fc79128SThu Nguyen EXPECT_EQ("S0", t1.getTerminusName().value());
1093c5486d4SThu Nguyen }
1103c5486d4SThu Nguyen
TEST(TerminusTest,parseSensorAuxiliaryMultiNamesPDRTest)111f1e32c17Stal-yac TEST(TerminusTest, parseSensorAuxiliaryMultiNamesPDRTest)
112f1e32c17Stal-yac {
11316c2a0a0SPatrick Williams auto t1 =
11416c2a0a0SPatrick Williams pldm::platform_mc::Terminus(1, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
115f1e32c17Stal-yac std::vector<uint8_t> pdr1{
116f1e32c17Stal-yac 0x0,
117f1e32c17Stal-yac 0x0,
118f1e32c17Stal-yac 0x0,
119f1e32c17Stal-yac 0x1, // record handle
120f1e32c17Stal-yac 0x1, // PDRHeaderVersion
121f1e32c17Stal-yac PLDM_SENSOR_AUXILIARY_NAMES_PDR, // PDRType
122f1e32c17Stal-yac 0x0,
123f1e32c17Stal-yac 0x0, // recordChangeNumber
124f1e32c17Stal-yac 0x0,
125f1e32c17Stal-yac 53, // dataLength
126f1e32c17Stal-yac 0,
127f1e32c17Stal-yac 0x0, // PLDMTerminusHandle
128f1e32c17Stal-yac 0x1,
129f1e32c17Stal-yac 0x0, // sensorID
130f1e32c17Stal-yac 0x1, // sensorCount
131f1e32c17Stal-yac 0x3, // nameStringCount
132f1e32c17Stal-yac 'e',
133f1e32c17Stal-yac 'n',
134f1e32c17Stal-yac 0x0, // nameLanguageTag
135f1e32c17Stal-yac 0x0,
136f1e32c17Stal-yac 'T',
137f1e32c17Stal-yac 0x0,
138f1e32c17Stal-yac 'E',
139f1e32c17Stal-yac 0x0,
140f1e32c17Stal-yac 'M',
141f1e32c17Stal-yac 0x0,
142f1e32c17Stal-yac 'P',
143f1e32c17Stal-yac 0x0,
144f1e32c17Stal-yac '1',
145f1e32c17Stal-yac 0x0,
146f1e32c17Stal-yac 0x0, // sensorName Temp1
147f1e32c17Stal-yac 'f',
148f1e32c17Stal-yac 'r',
149f1e32c17Stal-yac 0x0, // nameLanguageTag
150f1e32c17Stal-yac 0x0,
151f1e32c17Stal-yac 'T',
152f1e32c17Stal-yac 0x0,
153f1e32c17Stal-yac 'E',
154f1e32c17Stal-yac 0x0,
155f1e32c17Stal-yac 'M',
156f1e32c17Stal-yac 0x0,
157f1e32c17Stal-yac 'P',
158f1e32c17Stal-yac 0x0,
159f1e32c17Stal-yac '2',
160f1e32c17Stal-yac 0x0,
161f1e32c17Stal-yac 0x0, // sensorName Temp2
162f1e32c17Stal-yac 'f',
163f1e32c17Stal-yac 'r',
164f1e32c17Stal-yac 0x0, // nameLanguageTag
165f1e32c17Stal-yac 0x0,
166f1e32c17Stal-yac 'T',
167f1e32c17Stal-yac 0x0,
168f1e32c17Stal-yac 'E',
169f1e32c17Stal-yac 0x0,
170f1e32c17Stal-yac 'M',
171f1e32c17Stal-yac 0x0,
172f1e32c17Stal-yac 'P',
173f1e32c17Stal-yac 0x0,
174f1e32c17Stal-yac '1',
175f1e32c17Stal-yac 0x0,
176f1e32c17Stal-yac '2',
177f1e32c17Stal-yac 0x0,
178f1e32c17Stal-yac 0x0 // sensorName Temp12
179f1e32c17Stal-yac };
180f1e32c17Stal-yac
181f1e32c17Stal-yac std::vector<uint8_t> pdr2{
182f1e32c17Stal-yac 0x1, 0x0, 0x0,
183f1e32c17Stal-yac 0x0, // record handle
184f1e32c17Stal-yac 0x1, // PDRHeaderVersion
185f1e32c17Stal-yac PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
186f1e32c17Stal-yac 0x1,
187f1e32c17Stal-yac 0x0, // recordChangeNumber
188f1e32c17Stal-yac 0x11,
189f1e32c17Stal-yac 0, // dataLength
190f1e32c17Stal-yac /* Entity Auxiliary Names PDR Data*/
191f1e32c17Stal-yac 3,
192f1e32c17Stal-yac 0x80, // entityType system software
193f1e32c17Stal-yac 0x1,
194f1e32c17Stal-yac 0x0, // Entity instance number =1
195f1e32c17Stal-yac 0,
19604ac9971SManojkiran Eda 0, // Overall system
197f1e32c17Stal-yac 0, // shared Name Count one name only
198f1e32c17Stal-yac 01, // nameStringCount
199f1e32c17Stal-yac 0x65, 0x6e, 0x00,
200f1e32c17Stal-yac 0x00, // Language Tag "en"
201f1e32c17Stal-yac 0x53, 0x00, 0x30, 0x00,
202f1e32c17Stal-yac 0x00 // Entity Name "S0"
203f1e32c17Stal-yac };
204f1e32c17Stal-yac
205f1e32c17Stal-yac t1.pdrs.emplace_back(pdr1);
206f1e32c17Stal-yac t1.pdrs.emplace_back(pdr2);
207f1e32c17Stal-yac t1.parseTerminusPDRs();
208f1e32c17Stal-yac
209f1e32c17Stal-yac auto sensorAuxNames = t1.getSensorAuxiliaryNames(0);
210f1e32c17Stal-yac EXPECT_EQ(nullptr, sensorAuxNames);
211f1e32c17Stal-yac
212f1e32c17Stal-yac sensorAuxNames = t1.getSensorAuxiliaryNames(1);
213f1e32c17Stal-yac EXPECT_NE(nullptr, sensorAuxNames);
214f1e32c17Stal-yac
215f1e32c17Stal-yac const auto& [sensorId, sensorCnt, names] = *sensorAuxNames;
216f1e32c17Stal-yac EXPECT_EQ(1, sensorId);
217f1e32c17Stal-yac EXPECT_EQ(1, sensorCnt);
218f1e32c17Stal-yac EXPECT_EQ(1, names.size());
219f1e32c17Stal-yac EXPECT_EQ(3, names[0].size());
220f1e32c17Stal-yac EXPECT_EQ("en", names[0][0].first);
221f1e32c17Stal-yac EXPECT_EQ("TEMP1", names[0][0].second);
222f1e32c17Stal-yac EXPECT_EQ("fr", names[0][1].first);
223f1e32c17Stal-yac EXPECT_EQ("TEMP2", names[0][1].second);
224f1e32c17Stal-yac EXPECT_EQ("fr", names[0][2].first);
225f1e32c17Stal-yac EXPECT_EQ("TEMP12", names[0][2].second);
226f1e32c17Stal-yac EXPECT_EQ(2, t1.pdrs.size());
227*9fc79128SThu Nguyen EXPECT_EQ("S0", t1.getTerminusName().value());
228f1e32c17Stal-yac }
229f1e32c17Stal-yac
TEST(TerminusTest,parseSensorAuxiliaryNamesMultiSensorsPDRTest)230f1e32c17Stal-yac TEST(TerminusTest, parseSensorAuxiliaryNamesMultiSensorsPDRTest)
231f1e32c17Stal-yac {
23216c2a0a0SPatrick Williams auto t1 =
23316c2a0a0SPatrick Williams pldm::platform_mc::Terminus(1, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
234f1e32c17Stal-yac std::vector<uint8_t> pdr1{
235f1e32c17Stal-yac 0x0,
236f1e32c17Stal-yac 0x0,
237f1e32c17Stal-yac 0x0,
238f1e32c17Stal-yac 0x1, // record handle
239f1e32c17Stal-yac 0x1, // PDRHeaderVersion
240f1e32c17Stal-yac PLDM_SENSOR_AUXILIARY_NAMES_PDR, // PDRType
241f1e32c17Stal-yac 0x0,
242f1e32c17Stal-yac 0x0, // recordChangeNumber
243f1e32c17Stal-yac 0x0,
244f1e32c17Stal-yac 54, // dataLength
245f1e32c17Stal-yac 0,
246f1e32c17Stal-yac 0x0, // PLDMTerminusHandle
247f1e32c17Stal-yac 0x1,
248f1e32c17Stal-yac 0x0, // sensorID
249f1e32c17Stal-yac 0x2, // sensorCount
250f1e32c17Stal-yac 0x1, // nameStringCount
251f1e32c17Stal-yac 'e',
252f1e32c17Stal-yac 'n',
253f1e32c17Stal-yac 0x0, // nameLanguageTag
254f1e32c17Stal-yac 0x0,
255f1e32c17Stal-yac 'T',
256f1e32c17Stal-yac 0x0,
257f1e32c17Stal-yac 'E',
258f1e32c17Stal-yac 0x0,
259f1e32c17Stal-yac 'M',
260f1e32c17Stal-yac 0x0,
261f1e32c17Stal-yac 'P',
262f1e32c17Stal-yac 0x0,
263f1e32c17Stal-yac '1',
264f1e32c17Stal-yac 0x0,
265f1e32c17Stal-yac 0x0, // sensorName Temp1
266f1e32c17Stal-yac 0x2, // nameStringCount
267f1e32c17Stal-yac 'f',
268f1e32c17Stal-yac 'r',
269f1e32c17Stal-yac 0x0, // nameLanguageTag
270f1e32c17Stal-yac 0x0,
271f1e32c17Stal-yac 'T',
272f1e32c17Stal-yac 0x0,
273f1e32c17Stal-yac 'E',
274f1e32c17Stal-yac 0x0,
275f1e32c17Stal-yac 'M',
276f1e32c17Stal-yac 0x0,
277f1e32c17Stal-yac 'P',
278f1e32c17Stal-yac 0x0,
279f1e32c17Stal-yac '2',
280f1e32c17Stal-yac 0x0,
281f1e32c17Stal-yac 0x0, // sensorName Temp2
282f1e32c17Stal-yac 'f',
283f1e32c17Stal-yac 'r',
284f1e32c17Stal-yac 0x0, // nameLanguageTag
285f1e32c17Stal-yac 0x0,
286f1e32c17Stal-yac 'T',
287f1e32c17Stal-yac 0x0,
288f1e32c17Stal-yac 'E',
289f1e32c17Stal-yac 0x0,
290f1e32c17Stal-yac 'M',
291f1e32c17Stal-yac 0x0,
292f1e32c17Stal-yac 'P',
293f1e32c17Stal-yac 0x0,
294f1e32c17Stal-yac '1',
295f1e32c17Stal-yac 0x0,
296f1e32c17Stal-yac '2',
297f1e32c17Stal-yac 0x0,
298f1e32c17Stal-yac 0x0 // sensorName Temp12
299f1e32c17Stal-yac };
300f1e32c17Stal-yac
301f1e32c17Stal-yac std::vector<uint8_t> pdr2{
302f1e32c17Stal-yac 0x1, 0x0, 0x0,
303f1e32c17Stal-yac 0x0, // record handle
304f1e32c17Stal-yac 0x1, // PDRHeaderVersion
305f1e32c17Stal-yac PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
306f1e32c17Stal-yac 0x1,
307f1e32c17Stal-yac 0x0, // recordChangeNumber
308f1e32c17Stal-yac 0x11,
309f1e32c17Stal-yac 0, // dataLength
310f1e32c17Stal-yac /* Entity Auxiliary Names PDR Data*/
311f1e32c17Stal-yac 3,
312f1e32c17Stal-yac 0x80, // entityType system software
313f1e32c17Stal-yac 0x1,
314f1e32c17Stal-yac 0x0, // Entity instance number =1
315f1e32c17Stal-yac 0,
31604ac9971SManojkiran Eda 0, // Overall system
317f1e32c17Stal-yac 0, // shared Name Count one name only
318f1e32c17Stal-yac 01, // nameStringCount
319f1e32c17Stal-yac 0x65, 0x6e, 0x00,
320f1e32c17Stal-yac 0x00, // Language Tag "en"
321f1e32c17Stal-yac 0x53, 0x00, 0x30, 0x00,
322f1e32c17Stal-yac 0x00 // Entity Name "S0"
323f1e32c17Stal-yac };
324f1e32c17Stal-yac
325f1e32c17Stal-yac t1.pdrs.emplace_back(pdr1);
326f1e32c17Stal-yac t1.pdrs.emplace_back(pdr2);
327f1e32c17Stal-yac t1.parseTerminusPDRs();
328f1e32c17Stal-yac
329f1e32c17Stal-yac auto sensorAuxNames = t1.getSensorAuxiliaryNames(0);
330f1e32c17Stal-yac EXPECT_EQ(nullptr, sensorAuxNames);
331f1e32c17Stal-yac
332f1e32c17Stal-yac sensorAuxNames = t1.getSensorAuxiliaryNames(1);
333f1e32c17Stal-yac EXPECT_NE(nullptr, sensorAuxNames);
334f1e32c17Stal-yac
335f1e32c17Stal-yac const auto& [sensorId, sensorCnt, names] = *sensorAuxNames;
336f1e32c17Stal-yac EXPECT_EQ(1, sensorId);
337f1e32c17Stal-yac EXPECT_EQ(2, sensorCnt);
338f1e32c17Stal-yac EXPECT_EQ(2, names.size());
339f1e32c17Stal-yac EXPECT_EQ(1, names[0].size());
340f1e32c17Stal-yac EXPECT_EQ("en", names[0][0].first);
341f1e32c17Stal-yac EXPECT_EQ("TEMP1", names[0][0].second);
342f1e32c17Stal-yac EXPECT_EQ(2, names[1].size());
343f1e32c17Stal-yac EXPECT_EQ("fr", names[1][0].first);
344f1e32c17Stal-yac EXPECT_EQ("TEMP2", names[1][0].second);
345f1e32c17Stal-yac EXPECT_EQ("fr", names[1][1].first);
346f1e32c17Stal-yac EXPECT_EQ("TEMP12", names[1][1].second);
347f1e32c17Stal-yac EXPECT_EQ(2, t1.pdrs.size());
348*9fc79128SThu Nguyen EXPECT_EQ("S0", t1.getTerminusName().value());
349f1e32c17Stal-yac }
350f1e32c17Stal-yac
TEST(TerminusTest,parsePDRTestNoSensorPDR)3513c5486d4SThu Nguyen TEST(TerminusTest, parsePDRTestNoSensorPDR)
3523c5486d4SThu Nguyen {
35316c2a0a0SPatrick Williams auto t1 =
35416c2a0a0SPatrick Williams pldm::platform_mc::Terminus(1, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
3553c5486d4SThu Nguyen std::vector<uint8_t> pdr1{
3563c5486d4SThu Nguyen 0x1, 0x0, 0x0,
3573c5486d4SThu Nguyen 0x0, // record handle
3583c5486d4SThu Nguyen 0x1, // PDRHeaderVersion
3593c5486d4SThu Nguyen PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
3603c5486d4SThu Nguyen 0x1,
3613c5486d4SThu Nguyen 0x0, // recordChangeNumber
3623c5486d4SThu Nguyen 0x11,
3633c5486d4SThu Nguyen 0, // dataLength
3643c5486d4SThu Nguyen /* Entity Auxiliary Names PDR Data*/
3653c5486d4SThu Nguyen 3,
3663c5486d4SThu Nguyen 0x80, // entityType system software
3673c5486d4SThu Nguyen 0x1,
3683c5486d4SThu Nguyen 0x0, // Entity instance number =1
3693c5486d4SThu Nguyen 0,
37004ac9971SManojkiran Eda 0, // Overall system
3713c5486d4SThu Nguyen 0, // shared Name Count one name only
3723c5486d4SThu Nguyen 01, // nameStringCount
3733c5486d4SThu Nguyen 0x65, 0x6e, 0x00,
3743c5486d4SThu Nguyen 0x00, // Language Tag "en"
3753c5486d4SThu Nguyen 0x53, 0x00, 0x30, 0x00,
3763c5486d4SThu Nguyen 0x00 // Entity Name "S0"
3773c5486d4SThu Nguyen };
3783c5486d4SThu Nguyen
3793c5486d4SThu Nguyen t1.pdrs.emplace_back(pdr1);
3803c5486d4SThu Nguyen t1.parseTerminusPDRs();
3813c5486d4SThu Nguyen
3823c5486d4SThu Nguyen auto sensorAuxNames = t1.getSensorAuxiliaryNames(1);
3833c5486d4SThu Nguyen EXPECT_EQ(nullptr, sensorAuxNames);
384de2a132aSGilbert Chen }
385