blob: 4af91d18f5476f510da6486037a48d240314f783 [file] [log] [blame]
George Liu83409572019-12-24 18:42:54 +08001#include "utils.hpp"
2
Pavithra Barithaya0f74c982020-04-27 02:17:10 -05003#include "libpldm/platform.h"
4
George Liu83409572019-12-24 18:42:54 +08005#include <gtest/gtest.h>
6
7using namespace pldm::utils;
8
9TEST(decodeDate, testGooduintToDate)
10{
11 uint64_t data = 20191212115959;
12 uint16_t year = 2019;
13 uint8_t month = 12;
14 uint8_t day = 12;
15 uint8_t hours = 11;
16 uint8_t minutes = 59;
17 uint8_t seconds = 59;
18
19 uint16_t retyear = 0;
20 uint8_t retmonth = 0;
21 uint8_t retday = 0;
22 uint8_t rethours = 0;
23 uint8_t retminutes = 0;
24 uint8_t retseconds = 0;
25
26 auto ret = uintToDate(data, &retyear, &retmonth, &retday, &rethours,
27 &retminutes, &retseconds);
28
29 EXPECT_EQ(ret, true);
30 EXPECT_EQ(year, retyear);
31 EXPECT_EQ(month, retmonth);
32 EXPECT_EQ(day, retday);
33 EXPECT_EQ(hours, rethours);
34 EXPECT_EQ(minutes, retminutes);
35 EXPECT_EQ(seconds, retseconds);
36}
37
38TEST(decodeDate, testBaduintToDate)
39{
40 uint64_t data = 10191212115959;
41
42 uint16_t retyear = 0;
43 uint8_t retmonth = 0;
44 uint8_t retday = 0;
45 uint8_t rethours = 0;
46 uint8_t retminutes = 0;
47 uint8_t retseconds = 0;
48
49 auto ret = uintToDate(data, &retyear, &retmonth, &retday, &rethours,
50 &retminutes, &retseconds);
51
52 EXPECT_EQ(ret, false);
53}
54
George Liuba4c1fb2020-02-05 14:13:30 +080055TEST(parseEffecterData, testGoodDecodeEffecterData)
George Liu83409572019-12-24 18:42:54 +080056{
George Liuba4c1fb2020-02-05 14:13:30 +080057 std::vector<uint8_t> effecterData = {1, 1, 0, 1};
58 uint8_t effecterCount = 2;
George Liu83409572019-12-24 18:42:54 +080059 set_effecter_state_field stateField0 = {1, 1};
George Liuba4c1fb2020-02-05 14:13:30 +080060 set_effecter_state_field stateField1 = {0, 1};
George Liu83409572019-12-24 18:42:54 +080061
George Liuba4c1fb2020-02-05 14:13:30 +080062 auto effecterField = parseEffecterData(effecterData, effecterCount);
63 EXPECT_NE(effecterField, std::nullopt);
64 EXPECT_EQ(effecterCount, effecterField->size());
George Liu83409572019-12-24 18:42:54 +080065
George Liuba4c1fb2020-02-05 14:13:30 +080066 std::vector<set_effecter_state_field> stateField = effecterField.value();
George Liu83409572019-12-24 18:42:54 +080067 EXPECT_EQ(stateField[0].set_request, stateField0.set_request);
68 EXPECT_EQ(stateField[0].effecter_state, stateField0.effecter_state);
69 EXPECT_EQ(stateField[1].set_request, stateField1.set_request);
70 EXPECT_EQ(stateField[1].effecter_state, stateField1.effecter_state);
George Liu83409572019-12-24 18:42:54 +080071}
72
George Liuba4c1fb2020-02-05 14:13:30 +080073TEST(parseEffecterData, testBadDecodeEffecterData)
George Liu83409572019-12-24 18:42:54 +080074{
George Liuba4c1fb2020-02-05 14:13:30 +080075 std::vector<uint8_t> effecterData = {0, 1, 0, 1, 0, 1};
76 uint8_t effecterCount = 2;
George Liu83409572019-12-24 18:42:54 +080077
George Liuba4c1fb2020-02-05 14:13:30 +080078 auto effecterField = parseEffecterData(effecterData, effecterCount);
George Liu83409572019-12-24 18:42:54 +080079
George Liuba4c1fb2020-02-05 14:13:30 +080080 EXPECT_EQ(effecterField, std::nullopt);
George Liu83409572019-12-24 18:42:54 +080081}
Pavithra Barithaya0f74c982020-04-27 02:17:10 -050082
83TEST(FindStateEffecterPDR, testOneMatch)
84{
85
86 auto repo = pldm_pdr_init();
87 uint8_t tid = 1;
88 uint16_t entityID = 33;
89 uint16_t stateSetId = 196;
90
91 std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) -
92 sizeof(uint8_t) +
93 sizeof(struct state_effecter_possible_states));
94
95 auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data());
96
97 auto state =
98 reinterpret_cast<state_effecter_possible_states*>(rec->possible_states);
99
100 rec->hdr.type = 11;
101 rec->hdr.record_handle = 1;
102 rec->entity_type = 33;
103 rec->container_id = 0;
104 rec->composite_effecter_count = 1;
105 state->state_set_id = 196;
106 state->possible_states_size = 1;
107
108 pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false);
109
110 auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
111
112 EXPECT_EQ(pdr, record[0]);
113
114 pldm_pdr_destroy(repo);
115}
116
117TEST(FindStateEffecterPDR, testNoMatch)
118{
119
120 auto repo = pldm_pdr_init();
121 uint8_t tid = 1;
122 uint16_t entityID = 44;
123 uint16_t stateSetId = 196;
124
125 std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) -
126 sizeof(uint8_t) +
127 sizeof(struct state_effecter_possible_states));
128
129 auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data());
130
131 auto state =
132 reinterpret_cast<state_effecter_possible_states*>(rec->possible_states);
133
134 rec->hdr.type = 11;
135 rec->hdr.record_handle = 1;
136 rec->entity_type = 33;
137 rec->container_id = 0;
138 rec->composite_effecter_count = 1;
139 state->state_set_id = 196;
140 state->possible_states_size = 1;
141
142 pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false);
143
144 auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
145
146 EXPECT_EQ(record.empty(), true);
147
148 pldm_pdr_destroy(repo);
149}
150
151TEST(FindStateEffecterPDR, testEmptyRepo)
152{
153
154 auto repo = pldm_pdr_init();
155 uint8_t tid = 1;
156 uint16_t entityID = 33;
157 uint16_t stateSetId = 196;
158
159 std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) -
160 sizeof(uint8_t) +
161 sizeof(struct state_effecter_possible_states));
162
163 auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
164
165 EXPECT_EQ(record.empty(), true);
166
167 pldm_pdr_destroy(repo);
168}
169
170TEST(FindStateEffecterPDR, testMoreMatch)
171{
172
173 auto repo = pldm_pdr_init();
174 uint8_t tid = 1;
175
176 std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) -
177 sizeof(uint8_t) +
178 sizeof(struct state_effecter_possible_states));
179
180 auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data());
181
182 auto state =
183 reinterpret_cast<state_effecter_possible_states*>(rec->possible_states);
184
185 rec->hdr.type = 11;
186 rec->hdr.record_handle = 1;
187 rec->entity_type = 31;
188 rec->container_id = 0;
189 rec->composite_effecter_count = 1;
190 state->state_set_id = 129;
191 state->possible_states_size = 1;
192
193 pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false);
194
195 std::vector<uint8_t> pdr_second(
196 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
197 sizeof(struct state_effecter_possible_states));
198
199 auto rec_second =
200 reinterpret_cast<pldm_state_effecter_pdr*>(pdr_second.data());
201
202 auto state_second = reinterpret_cast<state_effecter_possible_states*>(
203 rec_second->possible_states);
204
205 rec_second->hdr.type = 11;
206 rec_second->hdr.record_handle = 2;
207 rec_second->entity_type = 31;
208 rec_second->container_id = 0;
209 rec_second->composite_effecter_count = 1;
210 state_second->state_set_id = 129;
211 state_second->possible_states_size = 1;
212
213 pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), 0, false);
214
215 uint16_t entityID_ = 31;
216 uint16_t stateSetId_ = 129;
217
218 auto record = findStateEffecterPDR(tid, entityID_, stateSetId_, repo);
219
220 EXPECT_EQ(pdr, record[0]);
221 EXPECT_EQ(pdr_second, record[1]);
222
223 pldm_pdr_destroy(repo);
224}
225
226TEST(FindStateEffecterPDR, testManyNoMatch)
227{
228
229 auto repo = pldm_pdr_init();
230 uint8_t tid = 1;
231 uint16_t entityID = 33;
232 uint16_t stateSetId = 196;
233
234 std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) -
235 sizeof(uint8_t) +
236 sizeof(struct state_effecter_possible_states));
237
238 auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data());
239
240 auto state =
241 reinterpret_cast<state_effecter_possible_states*>(rec->possible_states);
242
243 rec->hdr.type = 11;
244 rec->hdr.record_handle = 1;
245 rec->entity_type = 34;
246 rec->container_id = 0;
247 rec->composite_effecter_count = 1;
248 state->state_set_id = 198;
249 state->possible_states_size = 1;
250
251 pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false);
252
253 std::vector<uint8_t> pdr_second(
254 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
255 sizeof(struct state_effecter_possible_states));
256
257 auto rec_second =
258 reinterpret_cast<pldm_state_effecter_pdr*>(pdr_second.data());
259
260 auto state_second = reinterpret_cast<state_effecter_possible_states*>(
261 rec_second->possible_states);
262
263 rec_second->hdr.type = 11;
264 rec_second->hdr.record_handle = 2;
265 rec_second->entity_type = 39;
266 rec_second->container_id = 0;
267 rec_second->composite_effecter_count = 1;
268 state_second->state_set_id = 169;
269 state_second->possible_states_size = 1;
270
271 pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), 0, false);
272
273 auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
274
275 EXPECT_EQ(record.empty(), true);
276
277 pldm_pdr_destroy(repo);
278}
279
280TEST(FindStateEffecterPDR, testOneMatchOneNoMatch)
281{
282 auto repo = pldm_pdr_init();
283 uint8_t tid = 1;
284 uint16_t entityID = 67;
285 uint16_t stateSetId = 192;
286
287 std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) -
288 sizeof(uint8_t) +
289 sizeof(struct state_effecter_possible_states));
290
291 auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data());
292
293 auto state =
294 reinterpret_cast<state_effecter_possible_states*>(rec->possible_states);
295
296 rec->hdr.type = 11;
297 rec->hdr.record_handle = 1;
298 rec->entity_type = 32;
299 rec->container_id = 0;
300 rec->composite_effecter_count = 1;
301 state->state_set_id = 198;
302 state->possible_states_size = 1;
303
304 pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false);
305
306 std::vector<uint8_t> pdr_second(
307 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
308 sizeof(struct state_effecter_possible_states));
309
310 auto rec_second =
311 reinterpret_cast<pldm_state_effecter_pdr*>(pdr_second.data());
312
313 auto state_second = reinterpret_cast<state_effecter_possible_states*>(
314 rec_second->possible_states);
315
316 rec_second->hdr.type = 11;
317 rec_second->hdr.record_handle = 2;
318 rec_second->entity_type = 67;
319 rec_second->container_id = 0;
320 rec_second->composite_effecter_count = 1;
321 state_second->state_set_id = 192;
322 state_second->possible_states_size = 1;
323
324 pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), 0, false);
325
326 auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
327
328 EXPECT_EQ(pdr_second, record[0]);
329 EXPECT_EQ(record.size(), 1);
330
331 pldm_pdr_destroy(repo);
332}
333
334TEST(FindStateEffecterPDR, testOneMatchManyNoMatch)
335{
336 auto repo = pldm_pdr_init();
337 uint8_t tid = 1;
338 uint16_t entityID = 67;
339 uint16_t stateSetId = 192;
340
341 std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) -
342 sizeof(uint8_t) +
343 sizeof(struct state_effecter_possible_states));
344
345 auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data());
346
347 auto state =
348 reinterpret_cast<state_effecter_possible_states*>(rec->possible_states);
349
350 rec->hdr.type = 11;
351 rec->hdr.record_handle = 1;
352 rec->entity_type = 32;
353 rec->container_id = 0;
354 rec->composite_effecter_count = 1;
355 state->state_set_id = 198;
356 state->possible_states_size = 1;
357
358 pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false);
359
360 std::vector<uint8_t> pdr_second(
361 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
362 sizeof(struct state_effecter_possible_states));
363
364 auto rec_second =
365 reinterpret_cast<pldm_state_effecter_pdr*>(pdr_second.data());
366
367 auto state_second = reinterpret_cast<state_effecter_possible_states*>(
368 rec_second->possible_states);
369
370 rec_second->hdr.type = 11;
371 rec_second->hdr.record_handle = 2;
372 rec_second->entity_type = 67;
373 rec_second->container_id = 0;
374 rec_second->composite_effecter_count = 1;
375 state_second->state_set_id = 192;
376 state_second->possible_states_size = 1;
377
378 pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), 0, false);
379
380 std::vector<uint8_t> pdr_third(
381 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
382 sizeof(struct state_effecter_possible_states));
383
384 auto rec_third =
385 reinterpret_cast<pldm_state_effecter_pdr*>(pdr_third.data());
386
387 auto state_third = reinterpret_cast<state_effecter_possible_states*>(
388 rec_third->possible_states);
389
390 rec_third->hdr.type = 11;
391 rec_third->hdr.record_handle = 3;
392 rec_third->entity_type = 69;
393 rec_third->container_id = 0;
394 rec_third->composite_effecter_count = 1;
395 state_third->state_set_id = 199;
396 state_third->possible_states_size = 1;
397
398 auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
399
400 EXPECT_EQ(pdr_second, record[0]);
401 EXPECT_EQ(record.size(), 1);
402
403 pldm_pdr_destroy(repo);
404}
405
406TEST(FindStateEffecterPDR, testCompositeEffecter)
407{
408 auto repo = pldm_pdr_init();
409 uint8_t tid = 1;
410 uint16_t entityID = 67;
411 uint16_t stateSetId = 192;
412
413 std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) -
414 sizeof(uint8_t) +
415 sizeof(struct state_effecter_possible_states));
416
417 auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data());
418
419 auto state =
420 reinterpret_cast<state_effecter_possible_states*>(rec->possible_states);
421
422 rec->hdr.type = 11;
423 rec->hdr.record_handle = 1;
424 rec->entity_type = 67;
425 rec->container_id = 0;
426 rec->composite_effecter_count = 3;
427 state->state_set_id = 198;
428 state->possible_states_size = 1;
429
430 state->state_set_id = 193;
431 state->possible_states_size = 1;
432
433 state->state_set_id = 192;
434 state->possible_states_size = 1;
435
436 pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false);
437
438 auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
439
440 EXPECT_EQ(pdr, record[0]);
441
442 pldm_pdr_destroy(repo);
443}
444
445TEST(FindStateEffecterPDR, testNoMatchCompositeEffecter)
446{
447 auto repo = pldm_pdr_init();
448 uint8_t tid = 1;
449 uint16_t entityID = 67;
450 uint16_t stateSetId = 192;
451
452 std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) -
453 sizeof(uint8_t) +
454 sizeof(struct state_effecter_possible_states));
455
456 auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data());
457
458 auto state =
459 reinterpret_cast<state_effecter_possible_states*>(rec->possible_states);
460
461 rec->hdr.type = 11;
462 rec->hdr.record_handle = 1;
463 rec->entity_type = 34;
464 rec->container_id = 0;
465 rec->composite_effecter_count = 3;
466 state->state_set_id = 198;
467 state->possible_states_size = 1;
468
469 state->state_set_id = 193;
470 state->possible_states_size = 1;
471
472 state->state_set_id = 123;
473 state->possible_states_size = 1;
474
475 pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false);
476
477 auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
478
479 EXPECT_EQ(record.empty(), true);
480
481 pldm_pdr_destroy(repo);
482}