1 #include "libpldm/entity.h"
2
3 #include "platform-mc/numeric_sensor.hpp"
4 #include "platform-mc/terminus.hpp"
5
6 #include <gtest/gtest.h>
7
TEST(TerminusTest,supportedTypeTest)8 TEST(TerminusTest, supportedTypeTest)
9 {
10 auto t1 = pldm::platform_mc::Terminus(1, 1 << PLDM_BASE);
11 auto t2 =
12 pldm::platform_mc::Terminus(2, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
13
14 EXPECT_EQ(true, t1.doesSupportType(PLDM_BASE));
15 EXPECT_EQ(false, t1.doesSupportType(PLDM_PLATFORM));
16 EXPECT_EQ(true, t2.doesSupportType(PLDM_BASE));
17 EXPECT_EQ(true, t2.doesSupportType(PLDM_PLATFORM));
18 }
19
TEST(TerminusTest,getTidTest)20 TEST(TerminusTest, getTidTest)
21 {
22 const pldm_tid_t tid = 1;
23 auto t1 = pldm::platform_mc::Terminus(tid, 1 << PLDM_BASE);
24
25 EXPECT_EQ(tid, t1.getTid());
26 }
27
TEST(TerminusTest,parseSensorAuxiliaryNamesPDRTest)28 TEST(TerminusTest, parseSensorAuxiliaryNamesPDRTest)
29 {
30 auto t1 =
31 pldm::platform_mc::Terminus(1, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
32 std::vector<uint8_t> pdr1{
33 0x0,
34 0x0,
35 0x0,
36 0x1, // record handle
37 0x1, // PDRHeaderVersion
38 PLDM_SENSOR_AUXILIARY_NAMES_PDR, // PDRType
39 0x0,
40 0x0, // recordChangeNumber
41 0x0,
42 21, // dataLength
43 0,
44 0x0, // PLDMTerminusHandle
45 0x1,
46 0x0, // sensorID
47 0x1, // sensorCount
48 0x1, // nameStringCount
49 'e',
50 'n',
51 0x0, // nameLanguageTag
52 0x0,
53 'T',
54 0x0,
55 'E',
56 0x0,
57 'M',
58 0x0,
59 'P',
60 0x0,
61 '1',
62 0x0,
63 0x0 // sensorName
64 };
65
66 std::vector<uint8_t> pdr2{
67 0x1, 0x0, 0x0,
68 0x0, // record handle
69 0x1, // PDRHeaderVersion
70 PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
71 0x1,
72 0x0, // recordChangeNumber
73 0x11,
74 0, // dataLength
75 /* Entity Auxiliary Names PDR Data*/
76 3,
77 0x80, // entityType system software
78 0x1,
79 0x0, // Entity instance number =1
80 0,
81 0, // Overall system
82 0, // shared Name Count one name only
83 01, // nameStringCount
84 0x65, 0x6e, 0x00,
85 0x00, // Language Tag "en"
86 0x53, 0x00, 0x30, 0x00,
87 0x00 // Entity Name "S0"
88 };
89
90 t1.pdrs.emplace_back(pdr1);
91 t1.pdrs.emplace_back(pdr2);
92 t1.parseTerminusPDRs();
93
94 auto sensorAuxNames = t1.getSensorAuxiliaryNames(0);
95 EXPECT_EQ(nullptr, sensorAuxNames);
96
97 sensorAuxNames = t1.getSensorAuxiliaryNames(1);
98 EXPECT_NE(nullptr, sensorAuxNames);
99
100 const auto& [sensorId, sensorCnt, names] = *sensorAuxNames;
101 EXPECT_EQ(1, sensorId);
102 EXPECT_EQ(1, sensorCnt);
103 EXPECT_EQ(1, names.size());
104 EXPECT_EQ(1, names[0].size());
105 EXPECT_EQ("en", names[0][0].first);
106 EXPECT_EQ("TEMP1", names[0][0].second);
107 EXPECT_EQ(2, t1.pdrs.size());
108 EXPECT_EQ("S0", t1.getTerminusName().value());
109 }
110
TEST(TerminusTest,parseSensorAuxiliaryMultiNamesPDRTest)111 TEST(TerminusTest, parseSensorAuxiliaryMultiNamesPDRTest)
112 {
113 auto t1 =
114 pldm::platform_mc::Terminus(1, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
115 std::vector<uint8_t> pdr1{
116 0x0,
117 0x0,
118 0x0,
119 0x1, // record handle
120 0x1, // PDRHeaderVersion
121 PLDM_SENSOR_AUXILIARY_NAMES_PDR, // PDRType
122 0x0,
123 0x0, // recordChangeNumber
124 0x0,
125 53, // dataLength
126 0,
127 0x0, // PLDMTerminusHandle
128 0x1,
129 0x0, // sensorID
130 0x1, // sensorCount
131 0x3, // nameStringCount
132 'e',
133 'n',
134 0x0, // nameLanguageTag
135 0x0,
136 'T',
137 0x0,
138 'E',
139 0x0,
140 'M',
141 0x0,
142 'P',
143 0x0,
144 '1',
145 0x0,
146 0x0, // sensorName Temp1
147 'f',
148 'r',
149 0x0, // nameLanguageTag
150 0x0,
151 'T',
152 0x0,
153 'E',
154 0x0,
155 'M',
156 0x0,
157 'P',
158 0x0,
159 '2',
160 0x0,
161 0x0, // sensorName Temp2
162 'f',
163 'r',
164 0x0, // nameLanguageTag
165 0x0,
166 'T',
167 0x0,
168 'E',
169 0x0,
170 'M',
171 0x0,
172 'P',
173 0x0,
174 '1',
175 0x0,
176 '2',
177 0x0,
178 0x0 // sensorName Temp12
179 };
180
181 std::vector<uint8_t> pdr2{
182 0x1, 0x0, 0x0,
183 0x0, // record handle
184 0x1, // PDRHeaderVersion
185 PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
186 0x1,
187 0x0, // recordChangeNumber
188 0x11,
189 0, // dataLength
190 /* Entity Auxiliary Names PDR Data*/
191 3,
192 0x80, // entityType system software
193 0x1,
194 0x0, // Entity instance number =1
195 0,
196 0, // Overall system
197 0, // shared Name Count one name only
198 01, // nameStringCount
199 0x65, 0x6e, 0x00,
200 0x00, // Language Tag "en"
201 0x53, 0x00, 0x30, 0x00,
202 0x00 // Entity Name "S0"
203 };
204
205 t1.pdrs.emplace_back(pdr1);
206 t1.pdrs.emplace_back(pdr2);
207 t1.parseTerminusPDRs();
208
209 auto sensorAuxNames = t1.getSensorAuxiliaryNames(0);
210 EXPECT_EQ(nullptr, sensorAuxNames);
211
212 sensorAuxNames = t1.getSensorAuxiliaryNames(1);
213 EXPECT_NE(nullptr, sensorAuxNames);
214
215 const auto& [sensorId, sensorCnt, names] = *sensorAuxNames;
216 EXPECT_EQ(1, sensorId);
217 EXPECT_EQ(1, sensorCnt);
218 EXPECT_EQ(1, names.size());
219 EXPECT_EQ(3, names[0].size());
220 EXPECT_EQ("en", names[0][0].first);
221 EXPECT_EQ("TEMP1", names[0][0].second);
222 EXPECT_EQ("fr", names[0][1].first);
223 EXPECT_EQ("TEMP2", names[0][1].second);
224 EXPECT_EQ("fr", names[0][2].first);
225 EXPECT_EQ("TEMP12", names[0][2].second);
226 EXPECT_EQ(2, t1.pdrs.size());
227 EXPECT_EQ("S0", t1.getTerminusName().value());
228 }
229
TEST(TerminusTest,parseSensorAuxiliaryNamesMultiSensorsPDRTest)230 TEST(TerminusTest, parseSensorAuxiliaryNamesMultiSensorsPDRTest)
231 {
232 auto t1 =
233 pldm::platform_mc::Terminus(1, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
234 std::vector<uint8_t> pdr1{
235 0x0,
236 0x0,
237 0x0,
238 0x1, // record handle
239 0x1, // PDRHeaderVersion
240 PLDM_SENSOR_AUXILIARY_NAMES_PDR, // PDRType
241 0x0,
242 0x0, // recordChangeNumber
243 0x0,
244 54, // dataLength
245 0,
246 0x0, // PLDMTerminusHandle
247 0x1,
248 0x0, // sensorID
249 0x2, // sensorCount
250 0x1, // nameStringCount
251 'e',
252 'n',
253 0x0, // nameLanguageTag
254 0x0,
255 'T',
256 0x0,
257 'E',
258 0x0,
259 'M',
260 0x0,
261 'P',
262 0x0,
263 '1',
264 0x0,
265 0x0, // sensorName Temp1
266 0x2, // nameStringCount
267 'f',
268 'r',
269 0x0, // nameLanguageTag
270 0x0,
271 'T',
272 0x0,
273 'E',
274 0x0,
275 'M',
276 0x0,
277 'P',
278 0x0,
279 '2',
280 0x0,
281 0x0, // sensorName Temp2
282 'f',
283 'r',
284 0x0, // nameLanguageTag
285 0x0,
286 'T',
287 0x0,
288 'E',
289 0x0,
290 'M',
291 0x0,
292 'P',
293 0x0,
294 '1',
295 0x0,
296 '2',
297 0x0,
298 0x0 // sensorName Temp12
299 };
300
301 std::vector<uint8_t> pdr2{
302 0x1, 0x0, 0x0,
303 0x0, // record handle
304 0x1, // PDRHeaderVersion
305 PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
306 0x1,
307 0x0, // recordChangeNumber
308 0x11,
309 0, // dataLength
310 /* Entity Auxiliary Names PDR Data*/
311 3,
312 0x80, // entityType system software
313 0x1,
314 0x0, // Entity instance number =1
315 0,
316 0, // Overall system
317 0, // shared Name Count one name only
318 01, // nameStringCount
319 0x65, 0x6e, 0x00,
320 0x00, // Language Tag "en"
321 0x53, 0x00, 0x30, 0x00,
322 0x00 // Entity Name "S0"
323 };
324
325 t1.pdrs.emplace_back(pdr1);
326 t1.pdrs.emplace_back(pdr2);
327 t1.parseTerminusPDRs();
328
329 auto sensorAuxNames = t1.getSensorAuxiliaryNames(0);
330 EXPECT_EQ(nullptr, sensorAuxNames);
331
332 sensorAuxNames = t1.getSensorAuxiliaryNames(1);
333 EXPECT_NE(nullptr, sensorAuxNames);
334
335 const auto& [sensorId, sensorCnt, names] = *sensorAuxNames;
336 EXPECT_EQ(1, sensorId);
337 EXPECT_EQ(2, sensorCnt);
338 EXPECT_EQ(2, names.size());
339 EXPECT_EQ(1, names[0].size());
340 EXPECT_EQ("en", names[0][0].first);
341 EXPECT_EQ("TEMP1", names[0][0].second);
342 EXPECT_EQ(2, names[1].size());
343 EXPECT_EQ("fr", names[1][0].first);
344 EXPECT_EQ("TEMP2", names[1][0].second);
345 EXPECT_EQ("fr", names[1][1].first);
346 EXPECT_EQ("TEMP12", names[1][1].second);
347 EXPECT_EQ(2, t1.pdrs.size());
348 EXPECT_EQ("S0", t1.getTerminusName().value());
349 }
350
TEST(TerminusTest,parsePDRTestNoSensorPDR)351 TEST(TerminusTest, parsePDRTestNoSensorPDR)
352 {
353 auto t1 =
354 pldm::platform_mc::Terminus(1, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
355 std::vector<uint8_t> pdr1{
356 0x1, 0x0, 0x0,
357 0x0, // record handle
358 0x1, // PDRHeaderVersion
359 PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
360 0x1,
361 0x0, // recordChangeNumber
362 0x11,
363 0, // dataLength
364 /* Entity Auxiliary Names PDR Data*/
365 3,
366 0x80, // entityType system software
367 0x1,
368 0x0, // Entity instance number =1
369 0,
370 0, // Overall system
371 0, // shared Name Count one name only
372 01, // nameStringCount
373 0x65, 0x6e, 0x00,
374 0x00, // Language Tag "en"
375 0x53, 0x00, 0x30, 0x00,
376 0x00 // Entity Name "S0"
377 };
378
379 t1.pdrs.emplace_back(pdr1);
380 t1.parseTerminusPDRs();
381
382 auto sensorAuxNames = t1.getSensorAuxiliaryNames(1);
383 EXPECT_EQ(nullptr, sensorAuxNames);
384 }
385