blob: 24eea413fd41969835dbb63102d9e0d87603725d [file] [log] [blame]
Deepak Kodihallid0782962019-05-07 16:36:47 +05301#include "libpldmresponder/effecters.hpp"
Deepak Kodihallic6e8fb52019-05-02 08:35:31 -05002#include "libpldmresponder/pdr.hpp"
3
4#include "libpldm/platform.h"
5
6#include <gtest/gtest.h>
7
8using namespace pldm::responder;
9
10TEST(GeneratePDR, testGoodJson)
11{
12 using namespace pdr;
Deepak Kodihallid0782962019-05-07 16:36:47 +053013 using namespace effecter::dbus_mapping;
Deepak Kodihallic6e8fb52019-05-02 08:35:31 -050014 Repo& pdrRepo = get("./pdr_jsons/good");
15
16 // 2 entries
17 ASSERT_EQ(pdrRepo.numEntries(), 2);
18
19 // Check first PDR
20 pdr::Entry e = pdrRepo.at(1);
21 pldm_state_effecter_pdr* pdr =
22 reinterpret_cast<pldm_state_effecter_pdr*>(e.data());
23
24 ASSERT_EQ(pdr->hdr.record_handle, 1);
25 ASSERT_EQ(pdr->hdr.version, 1);
26 ASSERT_EQ(pdr->hdr.type, PLDM_STATE_EFFECTER_PDR);
27 ASSERT_EQ(pdr->hdr.record_change_num, 0);
28 ASSERT_EQ(pdr->hdr.length, 19);
29
30 ASSERT_EQ(pdr->terminus_handle, 0);
31 ASSERT_EQ(pdr->effecter_id, 1);
32 ASSERT_EQ(pdr->entity_type, 33);
33 ASSERT_EQ(pdr->entity_instance, 0);
34 ASSERT_EQ(pdr->container_id, 0);
35 ASSERT_EQ(pdr->effecter_semantic_id, 0);
36 ASSERT_EQ(pdr->effecter_init, PLDM_NO_INIT);
37 ASSERT_EQ(pdr->has_description_pdr, false);
38 ASSERT_EQ(pdr->composite_effecter_count, 1);
39 state_effecter_possible_states* states =
40 reinterpret_cast<state_effecter_possible_states*>(pdr->possible_states);
41 ASSERT_EQ(states->state_set_id, 196);
42 ASSERT_EQ(states->possible_states_size, 1);
43 bitfield8_t bf1{};
44 bf1.byte = 2;
45 ASSERT_EQ(states->states[0].byte, bf1.byte);
46
Deepak Kodihallid0782962019-05-07 16:36:47 +053047 auto paths = get(pdr->effecter_id);
48 ASSERT_EQ(paths[0], "/foo/bar");
49
Deepak Kodihallic6e8fb52019-05-02 08:35:31 -050050 // Check second PDR
51 e = pdrRepo.at(2);
52 pdr = reinterpret_cast<pldm_state_effecter_pdr*>(e.data());
53
54 ASSERT_EQ(pdr->hdr.record_handle, 2);
55 ASSERT_EQ(pdr->hdr.version, 1);
56 ASSERT_EQ(pdr->hdr.type, PLDM_STATE_EFFECTER_PDR);
57 ASSERT_EQ(pdr->hdr.record_change_num, 0);
58 ASSERT_EQ(pdr->hdr.length, 24);
59
60 ASSERT_EQ(pdr->terminus_handle, 0);
61 ASSERT_EQ(pdr->effecter_id, 2);
62 ASSERT_EQ(pdr->entity_type, 100);
63 ASSERT_EQ(pdr->entity_instance, 0);
64 ASSERT_EQ(pdr->container_id, 0);
65 ASSERT_EQ(pdr->effecter_semantic_id, 0);
66 ASSERT_EQ(pdr->effecter_init, PLDM_NO_INIT);
67 ASSERT_EQ(pdr->has_description_pdr, false);
68 ASSERT_EQ(pdr->composite_effecter_count, 2);
69 states =
70 reinterpret_cast<state_effecter_possible_states*>(pdr->possible_states);
71 ASSERT_EQ(states->state_set_id, 197);
72 ASSERT_EQ(states->possible_states_size, 1);
73 bf1.byte = 2;
74 ASSERT_EQ(states->states[0].byte, bf1.byte);
75 states = reinterpret_cast<state_effecter_possible_states*>(
76 pdr->possible_states + sizeof(state_effecter_possible_states));
77 ASSERT_EQ(states->state_set_id, 198);
78 ASSERT_EQ(states->possible_states_size, 2);
79 bitfield8_t bf2[2];
80 bf2[0].byte = 38;
81 bf2[1].byte = 128;
82 ASSERT_EQ(states->states[0].byte, bf2[0].byte);
83 ASSERT_EQ(states->states[1].byte, bf2[1].byte);
Deepak Kodihallid0782962019-05-07 16:36:47 +053084
85 paths = get(pdr->effecter_id);
86 ASSERT_EQ(paths[0], "/foo/bar");
87 ASSERT_EQ(paths[1], "/foo/bar/baz");
88
89 ASSERT_THROW(get(0xDEAD), std::exception);
Deepak Kodihallic6e8fb52019-05-02 08:35:31 -050090}
91
92TEST(GeneratePDR, testNoJson)
93{
94 using namespace pdr;
95 Repo& pdrRepo = get("./pdr_jsons/not_there");
96
97 ASSERT_EQ(pdrRepo.numEntries(), 2);
98}
99
100TEST(GeneratePDR, testMalformedJson)
101{
102 using namespace pdr;
103 Repo& pdrRepo = get("./pdr_jsons/good");
104 ASSERT_EQ(pdrRepo.numEntries(), 2);
105 pdrRepo.makeEmpty();
106 ASSERT_THROW(get("./pdr_jsons/malformed"), std::exception);
107}