blob: 5e76b465fa153b2905d3499f23bbb3643035a508 [file] [log] [blame]
Tom Joseph75356c12021-06-20 03:52:40 -07001#include "common/utils.hpp"
Unive Tienee2bd8a2025-10-30 08:11:06 +00002#include "fw-update/aggregate_update_manager.hpp"
Tom Joseph75356c12021-06-20 03:52:40 -07003#include "fw-update/inventory_manager.hpp"
4#include "requester/test/mock_request.hpp"
Andrew Jeffery7c1dc7e2023-04-28 14:52:16 +09305#include "test/test_instance_id.hpp"
Tom Joseph75356c12021-06-20 03:52:40 -07006
George Liuc453e162022-12-21 17:16:23 +08007#include <libpldm/firmware_update.h>
8
Tom Joseph75356c12021-06-20 03:52:40 -07009#include <gtest/gtest.h>
10
11using namespace pldm;
12using namespace std::chrono;
13using namespace pldm::fw_update;
14
15class InventoryManagerTest : public testing::Test
16{
17 protected:
18 InventoryManagerTest() :
Andrew Jeffery7c1dc7e2023-04-28 14:52:16 +093019 event(sdeventplus::Event::get_default()), instanceIdDb(),
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +100020 reqHandler(nullptr, event, instanceIdDb, false, seconds(1), 2,
Tom Joseph75356c12021-06-20 03:52:40 -070021 milliseconds(100)),
Unive Tienee2bd8a2025-10-30 08:11:06 +000022 updateManager(event, reqHandler, instanceIdDb, outDescriptorMap,
23 outComponentInfoMap),
Unive Tien7ad45b42025-08-18 06:04:53 +000024 inventoryManager(&dBusHandler, reqHandler, instanceIdDb,
25 outDescriptorMap, outDownstreamDescriptorMap,
Unive Tienee2bd8a2025-10-30 08:11:06 +000026 outComponentInfoMap, configurations, updateManager)
Tom Joseph75356c12021-06-20 03:52:40 -070027 {}
28
29 int fd = -1;
Unive Tien7ad45b42025-08-18 06:04:53 +000030 const pldm::utils::DBusHandler dBusHandler;
Tom Joseph75356c12021-06-20 03:52:40 -070031 sdeventplus::Event event;
Andrew Jeffery7c1dc7e2023-04-28 14:52:16 +093032 TestInstanceIdDb instanceIdDb;
Tom Joseph75356c12021-06-20 03:52:40 -070033 requester::Handler<requester::Request> reqHandler;
Unive Tienee2bd8a2025-10-30 08:11:06 +000034 AggregateUpdateManager updateManager;
Tom Joseph75356c12021-06-20 03:52:40 -070035 InventoryManager inventoryManager;
36 DescriptorMap outDescriptorMap{};
Unive Tien8b169dc2024-11-25 09:34:39 +080037 DownstreamDescriptorMap outDownstreamDescriptorMap{};
Tom Joseph75356c12021-06-20 03:52:40 -070038 ComponentInfoMap outComponentInfoMap{};
Unive Tien7ad45b42025-08-18 06:04:53 +000039 Configurations configurations;
Tom Joseph75356c12021-06-20 03:52:40 -070040};
41
42TEST_F(InventoryManagerTest, handleQueryDeviceIdentifiersResponse)
43{
44 constexpr size_t respPayloadLength1 = 49;
45 constexpr std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength1>
46 queryDeviceIdentifiersResp1{
47 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00,
48 0x04, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x02, 0x00, 0x10, 0x00, 0x12,
49 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18, 0xa0, 0x30, 0xfc, 0x8a,
50 0x56, 0x58, 0x7d, 0x5b, 0xFF, 0xFF, 0x0B, 0x00, 0x01, 0x07, 0x4f,
51 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43, 0x01, 0x02};
52 auto responseMsg1 =
53 reinterpret_cast<const pldm_msg*>(queryDeviceIdentifiersResp1.data());
54 inventoryManager.queryDeviceIdentifiers(1, responseMsg1,
55 respPayloadLength1);
56
57 DescriptorMap descriptorMap1{
58 {0x01,
59 {{PLDM_FWUP_IANA_ENTERPRISE_ID,
60 std::vector<uint8_t>{0x0a, 0x0b, 0x0c, 0xd}},
61 {PLDM_FWUP_UUID,
62 std::vector<uint8_t>{0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
63 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d,
64 0x5b}},
65 {PLDM_FWUP_VENDOR_DEFINED,
66 std::make_tuple("OpenBMC", std::vector<uint8_t>{0x01, 0x02})}}}};
67
68 EXPECT_EQ(outDescriptorMap.size(), descriptorMap1.size());
69 EXPECT_EQ(outDescriptorMap, descriptorMap1);
70
71 constexpr size_t respPayloadLength2 = 26;
72 constexpr std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength2>
73 queryDeviceIdentifiersResp2{
74 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x02,
75 0x00, 0x10, 0x00, 0xF0, 0x18, 0x87, 0x8C, 0xCB, 0x7D, 0x49,
76 0x43, 0x98, 0x00, 0xA0, 0x2F, 0x59, 0x9A, 0xCA, 0x02};
77 auto responseMsg2 =
78 reinterpret_cast<const pldm_msg*>(queryDeviceIdentifiersResp2.data());
79 inventoryManager.queryDeviceIdentifiers(2, responseMsg2,
80 respPayloadLength2);
81 DescriptorMap descriptorMap2{
82 {0x01,
83 {{PLDM_FWUP_IANA_ENTERPRISE_ID,
84 std::vector<uint8_t>{0x0a, 0x0b, 0x0c, 0xd}},
85 {PLDM_FWUP_UUID,
86 std::vector<uint8_t>{0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
87 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d,
88 0x5b}},
89 {PLDM_FWUP_VENDOR_DEFINED,
90 std::make_tuple("OpenBMC", std::vector<uint8_t>{0x01, 0x02})}}},
91 {0x02,
92 {{PLDM_FWUP_UUID,
93 std::vector<uint8_t>{0xF0, 0x18, 0x87, 0x8C, 0xCB, 0x7D, 0x49, 0x43,
94 0x98, 0x00, 0xA0, 0x2F, 0x59, 0x9A, 0xCA,
95 0x02}}}}};
96 EXPECT_EQ(outDescriptorMap.size(), descriptorMap2.size());
97 EXPECT_EQ(outDescriptorMap, descriptorMap2);
98}
99
100TEST_F(InventoryManagerTest, handleQueryDeviceIdentifiersResponseErrorCC)
101{
102 constexpr size_t respPayloadLength = 1;
103 constexpr std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength>
104 queryDeviceIdentifiersResp{0x00, 0x00, 0x00, 0x01};
105 auto responseMsg =
106 reinterpret_cast<const pldm_msg*>(queryDeviceIdentifiersResp.data());
107 inventoryManager.queryDeviceIdentifiers(1, responseMsg, respPayloadLength);
108 EXPECT_EQ(outDescriptorMap.size(), 0);
109}
110
Unive Tien8b169dc2024-11-25 09:34:39 +0800111TEST_F(InventoryManagerTest, handleQueryDownstreamIdentifierResponse)
112{
113 constexpr uint8_t eid = 1;
114 constexpr uint8_t downstreamDeviceCount = 1;
115 constexpr uint32_t downstreamDeviceLen = 11;
116 constexpr size_t respPayloadLength =
117 PLDM_QUERY_DOWNSTREAM_IDENTIFIERS_RESP_MIN_LEN + downstreamDeviceLen;
118
119 std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength>
120 queryDownstreamIdentifiersResp{
121 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
122 0x0B, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
123 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa0, 0x15};
124 auto responseMsg = new (queryDownstreamIdentifiersResp.data()) pldm_msg;
125
126 inventoryManager.queryDownstreamIdentifiers(eid, responseMsg,
127 respPayloadLength);
128
129 DownstreamDeviceInfo downstreamDevices = {
130 {0,
131 {{PLDM_FWUP_IANA_ENTERPRISE_ID,
132 std::vector<uint8_t>{0x00, 0x00, 0xa0, 0x15}}}}};
133 DownstreamDescriptorMap refDownstreamDescriptorMap{
134 {eid, downstreamDevices}};
135
136 ASSERT_EQ(outDownstreamDescriptorMap.size(), downstreamDeviceCount);
137 ASSERT_EQ(outDownstreamDescriptorMap.size(),
138 refDownstreamDescriptorMap.size());
139 ASSERT_EQ(outDownstreamDescriptorMap, refDownstreamDescriptorMap);
140}
141
142TEST_F(InventoryManagerTest, handleQueryDownstreamIdentifierResponseErrorCC)
143{
144 constexpr size_t respPayloadLength = 1;
145 constexpr std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength>
146 queryDownstreamIdentifiersResp{0x00, 0x00, 0x00, 0x01};
147 const auto responseMsg =
148 new (const_cast<unsigned char*>(queryDownstreamIdentifiersResp.data()))
149 pldm_msg;
150 inventoryManager.queryDownstreamIdentifiers(1, responseMsg,
151 respPayloadLength);
152
153 ASSERT_EQ(outDownstreamDescriptorMap.size(), 0);
154}
155
Tom Joseph75356c12021-06-20 03:52:40 -0700156TEST_F(InventoryManagerTest, getFirmwareParametersResponse)
157{
158 // constexpr uint16_t compCount = 2;
159 // constexpr std::string_view activeCompImageSetVersion{"DeviceVer1.0"};
160 // constexpr std::string_view activeCompVersion1{"Comp1v2.0"};
161 // constexpr std::string_view activeCompVersion2{"Comp2v3.0"};
162 constexpr uint16_t compClassification1 = 10;
163 constexpr uint16_t compIdentifier1 = 300;
164 constexpr uint8_t compClassificationIndex1 = 20;
165 constexpr uint16_t compClassification2 = 16;
166 constexpr uint16_t compIdentifier2 = 301;
167 constexpr uint8_t compClassificationIndex2 = 30;
168
169 constexpr size_t respPayloadLength1 = 119;
170 constexpr std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength1>
171 getFirmwareParametersResp1{
172 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01,
173 0x0c, 0x00, 0x00, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x56, 0x65,
174 0x72, 0x31, 0x2e, 0x30, 0x0a, 0x00, 0x2c, 0x01, 0x14, 0x00, 0x00,
175 0x00, 0x00, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
177 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43,
178 0x6f, 0x6d, 0x70, 0x31, 0x76, 0x32, 0x2e, 0x30, 0x10, 0x00, 0x2d,
179 0x01, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x01, 0x09, 0x00, 0x00, 0x00,
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
181 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
182 0x00, 0x00, 0x00, 0x43, 0x6f, 0x6d, 0x70, 0x32, 0x76, 0x33, 0x2e,
183 0x30};
184 auto responseMsg1 =
185 reinterpret_cast<const pldm_msg*>(getFirmwareParametersResp1.data());
186 inventoryManager.getFirmwareParameters(1, responseMsg1, respPayloadLength1);
187
188 ComponentInfoMap componentInfoMap1{
189 {1,
190 {{std::make_pair(compClassification1, compIdentifier1),
191 compClassificationIndex1},
192 {std::make_pair(compClassification2, compIdentifier2),
193 compClassificationIndex2}}}};
194 EXPECT_EQ(outComponentInfoMap.size(), componentInfoMap1.size());
195 EXPECT_EQ(outComponentInfoMap, componentInfoMap1);
196
197 // constexpr uint16_t compCount = 1;
198 // constexpr std::string_view activeCompImageSetVersion{"DeviceVer2.0"};
199 // constexpr std::string_view activeCompVersion1{"Comp3v4.0"};
200 constexpr uint16_t compClassification3 = 2;
201 constexpr uint16_t compIdentifier3 = 302;
202 constexpr uint8_t compClassificationIndex3 = 40;
203
204 constexpr size_t respPayloadLength2 = 119;
205 constexpr std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength2>
206 getFirmwareParametersResp2{
207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
208 0x0c, 0x00, 0x00, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x56, 0x65,
209 0x72, 0x32, 0x2e, 0x30, 0x02, 0x00, 0x2e, 0x01, 0x28, 0x00, 0x00,
210 0x00, 0x00, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
212 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43,
213 0x6f, 0x6d, 0x70, 0x33, 0x76, 0x34, 0x2e, 0x30};
214 auto responseMsg2 =
215 reinterpret_cast<const pldm_msg*>(getFirmwareParametersResp2.data());
216 inventoryManager.getFirmwareParameters(2, responseMsg2, respPayloadLength2);
217
218 ComponentInfoMap componentInfoMap2{
219 {1,
220 {{std::make_pair(compClassification1, compIdentifier1),
221 compClassificationIndex1},
222 {std::make_pair(compClassification2, compIdentifier2),
223 compClassificationIndex2}}},
224 {2,
225 {{std::make_pair(compClassification3, compIdentifier3),
226 compClassificationIndex3}}}};
227 EXPECT_EQ(outComponentInfoMap.size(), componentInfoMap2.size());
228 EXPECT_EQ(outComponentInfoMap, componentInfoMap2);
229}
230
231TEST_F(InventoryManagerTest, getFirmwareParametersResponseErrorCC)
232{
233 constexpr size_t respPayloadLength = 1;
234 constexpr std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength>
235 getFirmwareParametersResp{0x00, 0x00, 0x00, 0x01};
236 auto responseMsg =
237 reinterpret_cast<const pldm_msg*>(getFirmwareParametersResp.data());
238 inventoryManager.getFirmwareParameters(1, responseMsg, respPayloadLength);
239 EXPECT_EQ(outComponentInfoMap.size(), 0);
240}