blob: 8f8775c1401387ab38f2b97e4fdaa6841e689eda [file] [log] [blame]
Tom Joseph3fd3eb82021-06-18 04:13:29 -07001#include <bitset>
Tom Joseph763b51e2021-06-05 04:50:47 -07002#include <cstring>
3
gokulsanker138ceba2021-04-05 13:25:25 +05304#include "libpldm/base.h"
5#include "libpldm/firmware_update.h"
6
7#include <gtest/gtest.h>
8
9constexpr auto hdrSize = sizeof(pldm_msg_hdr);
10
Tom Joseph568e4702021-06-07 22:15:49 -070011TEST(DecodePackageHeaderInfo, goodPath)
12{
13 // Package header identifier for Version 1.0.x
14 constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
15 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43,
16 0x98, 0x00, 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02};
17 // Package header version for DSP0267 version 1.0.x
18 constexpr uint8_t pkgHeaderFormatRevision = 0x01;
19 // Random PackageHeaderSize
20 constexpr uint16_t pkgHeaderSize = 303;
21 // PackageReleaseDateTime - "25/12/2021 00:00:00"
22 std::array<uint8_t, PLDM_TIMESTAMP104_SIZE> timestamp104{
23 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
24 0x00, 0x19, 0x0c, 0xe5, 0x07, 0x00};
25 constexpr uint16_t componentBitmapBitLength = 8;
26 // PackageVersionString
27 constexpr std::string_view packageVersionStr{"OpenBMCv1.0"};
28 constexpr size_t packagerHeaderSize =
29 sizeof(pldm_package_header_information) + packageVersionStr.size();
30
31 constexpr std::array<uint8_t, packagerHeaderSize> packagerHeaderInfo{
32 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00, 0xa0, 0x2F,
33 0x05, 0x9a, 0xca, 0x02, 0x01, 0x2f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
34 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5, 0x07, 0x00, 0x08, 0x00, 0x01, 0x0b,
35 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
36 pldm_package_header_information pkgHeader{};
37 variable_field packageVersion{};
38
39 auto rc = decode_pldm_package_header_info(packagerHeaderInfo.data(),
40 packagerHeaderInfo.size(),
41 &pkgHeader, &packageVersion);
42
43 EXPECT_EQ(rc, PLDM_SUCCESS);
44 EXPECT_EQ(true,
45 std::equal(pkgHeader.uuid, pkgHeader.uuid + PLDM_FWUP_UUID_LENGTH,
46 uuid.begin(), uuid.end()));
47 EXPECT_EQ(pkgHeader.package_header_format_version, pkgHeaderFormatRevision);
48 EXPECT_EQ(pkgHeader.package_header_size, pkgHeaderSize);
49 EXPECT_EQ(true, std::equal(pkgHeader.timestamp104,
50 pkgHeader.timestamp104 + PLDM_TIMESTAMP104_SIZE,
51 timestamp104.begin(), timestamp104.end()));
52 EXPECT_EQ(pkgHeader.component_bitmap_bit_length, componentBitmapBitLength);
53 EXPECT_EQ(pkgHeader.package_version_string_type, PLDM_STR_TYPE_ASCII);
54 EXPECT_EQ(pkgHeader.package_version_string_length,
55 packageVersionStr.size());
56 std::string packageVersionString(
57 reinterpret_cast<const char*>(packageVersion.ptr),
58 packageVersion.length);
59 EXPECT_EQ(packageVersionString, packageVersionStr);
60}
61
62TEST(DecodePackageHeaderInfo, errorPaths)
63{
64 int rc = 0;
65 constexpr std::string_view packageVersionStr{"OpenBMCv1.0"};
66 constexpr size_t packagerHeaderSize =
67 sizeof(pldm_package_header_information) + packageVersionStr.size();
68
69 // Invalid Package Version String Type - 0x06
70 constexpr std::array<uint8_t, packagerHeaderSize>
71 invalidPackagerHeaderInfo1{
72 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
73 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
74 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
75 0x07, 0x00, 0x08, 0x00, 0x06, 0x0b, 0x4f, 0x70, 0x65, 0x6e,
76 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
77
78 pldm_package_header_information packageHeader{};
79 variable_field packageVersion{};
80
81 rc = decode_pldm_package_header_info(nullptr,
82 invalidPackagerHeaderInfo1.size(),
83 &packageHeader, &packageVersion);
84 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
85
86 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo1.data(),
87 invalidPackagerHeaderInfo1.size(),
88 nullptr, &packageVersion);
89 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
90
91 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo1.data(),
92 invalidPackagerHeaderInfo1.size(),
93 &packageHeader, nullptr);
94 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
95
96 rc = decode_pldm_package_header_info(
97 invalidPackagerHeaderInfo1.data(),
98 sizeof(pldm_package_header_information) - 1, &packageHeader,
99 &packageVersion);
100 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
101
102 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo1.data(),
103 invalidPackagerHeaderInfo1.size(),
104 &packageHeader, &packageVersion);
105 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
106
107 // Invalid Package Version String Length - 0x00
108 constexpr std::array<uint8_t, packagerHeaderSize>
109 invalidPackagerHeaderInfo2{
110 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
111 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
112 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
113 0x07, 0x00, 0x08, 0x00, 0x01, 0x00, 0x4f, 0x70, 0x65, 0x6e,
114 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
115 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo2.data(),
116 invalidPackagerHeaderInfo2.size(),
117 &packageHeader, &packageVersion);
118 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
119
120 // Package version string length less than in the header information
121 constexpr std::array<uint8_t, packagerHeaderSize - 1>
122 invalidPackagerHeaderInfo3{
123 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
124 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
126 0x07, 0x00, 0x08, 0x00, 0x01, 0x0b, 0x4f, 0x70, 0x65, 0x6e,
127 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e};
128 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo3.data(),
129 invalidPackagerHeaderInfo3.size(),
130 &packageHeader, &packageVersion);
131 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
132
133 // ComponentBitmapBitLength not a multiple of 8
134 constexpr std::array<uint8_t, packagerHeaderSize>
135 invalidPackagerHeaderInfo4{
136 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
137 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
138 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
139 0x07, 0x00, 0x09, 0x00, 0x01, 0x0b, 0x4f, 0x70, 0x65, 0x6e,
140 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
141 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo4.data(),
142 invalidPackagerHeaderInfo4.size(),
143 &packageHeader, &packageVersion);
144 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
145}
146
Tom Joseph763b51e2021-06-05 04:50:47 -0700147TEST(DecodeDescriptors, goodPath3Descriptors)
148{
149 // In the descriptor data there are 3 descriptor entries
150 // 1) IANA enterprise ID
151 constexpr std::array<uint8_t, PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH> iana{
152 0x0a, 0x0b, 0x0c, 0xd};
153 // 2) UUID
154 constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
155 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
156 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
157 // 3) Vendor Defined
158 constexpr std::string_view vendorTitle{"OpenBMC"};
159 constexpr size_t vendorDescriptorLen = 2;
160 constexpr std::array<uint8_t, vendorDescriptorLen> vendorDescriptorData{
161 0x01, 0x02};
162
163 constexpr size_t vendorDefinedDescriptorLen =
164 sizeof(pldm_vendor_defined_descriptor_title_data()
165 .vendor_defined_descriptor_title_str_type) +
166 sizeof(pldm_vendor_defined_descriptor_title_data()
167 .vendor_defined_descriptor_title_str_len) +
168 vendorTitle.size() + vendorDescriptorData.size();
169
170 constexpr size_t descriptorsLength =
171 3 * (sizeof(pldm_descriptor_tlv().descriptor_type) +
172 sizeof(pldm_descriptor_tlv().descriptor_length)) +
173 iana.size() + uuid.size() + vendorDefinedDescriptorLen;
174
175 constexpr std::array<uint8_t, descriptorsLength> descriptors{
176 0x01, 0x00, 0x04, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x02, 0x00, 0x10,
177 0x00, 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18, 0xa0, 0x30,
178 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b, 0xFF, 0xFF, 0x0B, 0x00, 0x01,
179 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43, 0x01, 0x02};
180
181 size_t descriptorCount = 1;
182 size_t descriptorsRemainingLength = descriptorsLength;
183 int rc = 0;
184
185 while (descriptorsRemainingLength && (descriptorCount <= 3))
186 {
187 uint16_t descriptorType = 0;
188 uint16_t descriptorLen = 0;
189 variable_field descriptorData{};
190
191 rc = decode_descriptor_type_length_value(
192 descriptors.data() + descriptorsLength - descriptorsRemainingLength,
193 descriptorsRemainingLength, &descriptorType, &descriptorData);
194 EXPECT_EQ(rc, PLDM_SUCCESS);
195
196 if (descriptorCount == 1)
197 {
198 EXPECT_EQ(descriptorType, PLDM_FWUP_IANA_ENTERPRISE_ID);
199 EXPECT_EQ(descriptorData.length,
200 PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH);
201 EXPECT_EQ(true,
202 std::equal(descriptorData.ptr,
203 descriptorData.ptr + descriptorData.length,
204 iana.begin(), iana.end()));
205 }
206 else if (descriptorCount == 2)
207 {
208 EXPECT_EQ(descriptorType, PLDM_FWUP_UUID);
209 EXPECT_EQ(descriptorData.length, PLDM_FWUP_UUID_LENGTH);
210 EXPECT_EQ(true,
211 std::equal(descriptorData.ptr,
212 descriptorData.ptr + descriptorData.length,
213 uuid.begin(), uuid.end()));
214 }
215 else if (descriptorCount == 3)
216 {
217 EXPECT_EQ(descriptorType, PLDM_FWUP_VENDOR_DEFINED);
218 EXPECT_EQ(descriptorData.length, vendorDefinedDescriptorLen);
219
220 uint8_t descriptorTitleStrType = 0;
221 variable_field descriptorTitleStr{};
222 variable_field vendorDefinedDescriptorData{};
223
224 rc = decode_vendor_defined_descriptor_value(
225 descriptorData.ptr, descriptorData.length,
226 &descriptorTitleStrType, &descriptorTitleStr,
227 &vendorDefinedDescriptorData);
228 EXPECT_EQ(rc, PLDM_SUCCESS);
229
230 EXPECT_EQ(descriptorTitleStrType, PLDM_STR_TYPE_ASCII);
231 EXPECT_EQ(descriptorTitleStr.length, vendorTitle.size());
232 std::string vendorTitleStr(
233 reinterpret_cast<const char*>(descriptorTitleStr.ptr),
234 descriptorTitleStr.length);
235 EXPECT_EQ(vendorTitleStr, vendorTitle);
236
237 EXPECT_EQ(vendorDefinedDescriptorData.length,
238 vendorDescriptorData.size());
239 EXPECT_EQ(true, std::equal(vendorDefinedDescriptorData.ptr,
240 vendorDefinedDescriptorData.ptr +
241 vendorDefinedDescriptorData.length,
242 vendorDescriptorData.begin(),
243 vendorDescriptorData.end()));
244 }
245
246 descriptorsRemainingLength -= sizeof(descriptorType) +
247 sizeof(descriptorLen) +
248 descriptorData.length;
249 descriptorCount++;
250 }
251}
252
253TEST(DecodeDescriptors, errorPathDecodeDescriptorTLV)
254{
255 int rc = 0;
256 // IANA Enterprise ID descriptor length incorrect
257 constexpr std::array<uint8_t, 7> invalidIANADescriptor1{
258 0x01, 0x00, 0x03, 0x00, 0x0a, 0x0b, 0x0c};
259 uint16_t descriptorType = 0;
260 variable_field descriptorData{};
261
262 rc = decode_descriptor_type_length_value(nullptr,
263 invalidIANADescriptor1.size(),
264 &descriptorType, &descriptorData);
265 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
266
267 rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
268 invalidIANADescriptor1.size(),
269 nullptr, &descriptorData);
270 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
271
272 rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
273 invalidIANADescriptor1.size(),
274 &descriptorType, nullptr);
275 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
276
277 rc = decode_descriptor_type_length_value(
278 invalidIANADescriptor1.data(), PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN - 1,
279 &descriptorType, &descriptorData);
280 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
281
282 rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
283 invalidIANADescriptor1.size(),
284 &descriptorType, &descriptorData);
285 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
286
287 // IANA Enterprise ID descriptor data less than length
288 std::array<uint8_t, 7> invalidIANADescriptor2{0x01, 0x00, 0x04, 0x00,
289 0x0a, 0x0b, 0x0c};
290 rc = decode_descriptor_type_length_value(invalidIANADescriptor2.data(),
291 invalidIANADescriptor2.size(),
292 &descriptorType, &descriptorData);
293 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
294}
295
296TEST(DecodeDescriptors, errorPathVendorDefinedDescriptor)
297{
298 int rc = 0;
299 // VendorDefinedDescriptorTitleStringType is invalid
300 constexpr std::array<uint8_t, 9> invalidVendorDescriptor1{
301 0x06, 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
302 uint8_t descriptorStringType = 0;
303 variable_field descriptorTitleStr{};
304 variable_field vendorDefinedDescriptorData{};
305
306 rc = decode_vendor_defined_descriptor_value(
307 nullptr, invalidVendorDescriptor1.size(), &descriptorStringType,
308 &descriptorTitleStr, &vendorDefinedDescriptorData);
309 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
310
311 rc = decode_vendor_defined_descriptor_value(
312 invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
313 &descriptorStringType, &descriptorTitleStr,
314 &vendorDefinedDescriptorData);
315 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
316
317 rc = decode_vendor_defined_descriptor_value(
318 invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
319 nullptr, &descriptorTitleStr, &vendorDefinedDescriptorData);
320 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
321
322 rc = decode_vendor_defined_descriptor_value(
323 invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
324 &descriptorStringType, nullptr, &vendorDefinedDescriptorData);
325 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
326
327 rc = decode_vendor_defined_descriptor_value(
328 invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
329 &descriptorStringType, &descriptorTitleStr, nullptr);
330 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
331
332 rc = decode_vendor_defined_descriptor_value(
333 invalidVendorDescriptor1.data(),
334 sizeof(pldm_vendor_defined_descriptor_title_data) - 1,
335 &descriptorStringType, &descriptorTitleStr,
336 &vendorDefinedDescriptorData);
337 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
338
339 rc = decode_vendor_defined_descriptor_value(
340 invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
341 &descriptorStringType, &descriptorTitleStr,
342 &vendorDefinedDescriptorData);
343 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
344
345 // VendorDefinedDescriptorTitleStringLength is 0
346 std::array<uint8_t, 9> invalidVendorDescriptor2{
347 0x01, 0x00, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
348 rc = decode_vendor_defined_descriptor_value(
349 invalidVendorDescriptor2.data(), invalidVendorDescriptor2.size(),
350 &descriptorStringType, &descriptorTitleStr,
351 &vendorDefinedDescriptorData);
352 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
353
354 // VendorDefinedDescriptorData not present in the data
355 std::array<uint8_t, 9> invalidVendorDescriptor3{
356 0x01, 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
357 rc = decode_vendor_defined_descriptor_value(
358 invalidVendorDescriptor3.data(), invalidVendorDescriptor3.size(),
359 &descriptorStringType, &descriptorTitleStr,
360 &vendorDefinedDescriptorData);
361 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
362}
363
gokulsanker138ceba2021-04-05 13:25:25 +0530364TEST(QueryDeviceIdentifiers, goodPathEncodeRequest)
365{
366 std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
367 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
368
369 uint8_t instanceId = 0x01;
370
371 auto rc = encode_query_device_identifiers_req(
372 instanceId, PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES, requestPtr);
373 EXPECT_EQ(rc, PLDM_SUCCESS);
374 EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
375 EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
376 EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
377 EXPECT_EQ(requestPtr->hdr.command, PLDM_QUERY_DEVICE_IDENTIFIERS);
378}
gokulsankereca3e192021-04-05 14:57:41 +0530379
380TEST(QueryDeviceIdentifiers, goodPathDecodeResponse)
381{
382 // descriptorDataLen is not fixed here taking it as 6
383 constexpr uint8_t descriptorDataLen = 6;
384 std::array<uint8_t, hdrSize +
385 sizeof(struct pldm_query_device_identifiers_resp) +
386 descriptorDataLen>
387 responseMsg{};
388 auto inResp = reinterpret_cast<struct pldm_query_device_identifiers_resp*>(
389 responseMsg.data() + hdrSize);
390
391 inResp->completion_code = PLDM_SUCCESS;
392 inResp->device_identifiers_len = htole32(descriptorDataLen);
393 inResp->descriptor_count = 1;
394
395 // filling descriptor data
396 std::fill_n(responseMsg.data() + hdrSize +
397 sizeof(struct pldm_query_device_identifiers_resp),
398 descriptorDataLen, 0xFF);
399
400 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
401 uint8_t completionCode = PLDM_SUCCESS;
402 uint32_t deviceIdentifiersLen = 0;
403 uint8_t descriptorCount = 0;
404 uint8_t* outDescriptorData = nullptr;
405
406 auto rc = decode_query_device_identifiers_resp(
407 response, responseMsg.size() - hdrSize, &completionCode,
408 &deviceIdentifiersLen, &descriptorCount, &outDescriptorData);
409
410 EXPECT_EQ(rc, PLDM_SUCCESS);
411 EXPECT_EQ(completionCode, PLDM_SUCCESS);
412 EXPECT_EQ(deviceIdentifiersLen, inResp->device_identifiers_len);
413 EXPECT_EQ(descriptorCount, inResp->descriptor_count);
414 EXPECT_EQ(true,
415 std::equal(outDescriptorData,
416 outDescriptorData + deviceIdentifiersLen,
417 responseMsg.begin() + hdrSize +
418 sizeof(struct pldm_query_device_identifiers_resp),
419 responseMsg.end()));
420}
gokulsanker981fbfb2021-04-05 15:17:25 +0530421
422TEST(GetFirmwareParameters, goodPathEncodeRequest)
423{
424 std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
425 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
426 uint8_t instanceId = 0x01;
427
428 auto rc = encode_get_firmware_parameters_req(
429 instanceId, PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES, requestPtr);
430 EXPECT_EQ(rc, PLDM_SUCCESS);
431 EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
432 EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
433 EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
434 EXPECT_EQ(requestPtr->hdr.command, PLDM_GET_FIRMWARE_PARAMETERS);
435}
gokulsanker22fbb342021-04-05 15:55:06 +0530436
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700437TEST(GetFirmwareParameters, decodeResponse)
gokulsanker22fbb342021-04-05 15:55:06 +0530438{
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700439 // CapabilitiesDuringUpdate of the firmware device
440 // Firmware device downgrade restrictions [Bit position 8] &
441 // Firmware Device Partial Updates [Bit position 3]
442 constexpr std::bitset<32> fdCapabilities{0x00000104};
443 constexpr uint16_t compCount = 1;
444 constexpr std::string_view activeCompImageSetVersion{"VersionString1"};
445 constexpr std::string_view pendingCompImageSetVersion{"VersionString2"};
gokulsanker22fbb342021-04-05 15:55:06 +0530446
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700447 // constexpr uint16_t compClassification = 16;
448 // constexpr uint16_t compIdentifier = 300;
449 // constexpr uint8_t compClassificationIndex = 20;
450 // constexpr uint32_t activeCompComparisonStamp = 0xABCDEFAB;
451 // constexpr std::array<uint8_t, 8> activeComponentReleaseData = {
452 // 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
453 // constexpr uint32_t pendingCompComparisonStamp = 0x12345678;
454 // constexpr std::array<uint8_t, 8> pendingComponentReleaseData = {
455 // 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01};
456 constexpr std::string_view activeCompVersion{"VersionString3"};
457 constexpr std::string_view pendingCompVersion{"VersionString4"};
458 // ComponentActivationMethods
459 // DC Power cycle [Bit position 4] & Self-Contained[Bit position 2]
460 constexpr std::bitset<16> compActivationMethod{0x12};
461 // CapabilitiesDuringUpdate of the firmware component
462 // Component downgrade capability [Bit position 2]
463 constexpr std::bitset<32> compCapabilities{0x02};
gokulsanker22fbb342021-04-05 15:55:06 +0530464
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700465 constexpr size_t compParamTableSize =
466 sizeof(pldm_component_parameter_entry) + activeCompVersion.size() +
467 pendingCompVersion.size();
gokulsanker22fbb342021-04-05 15:55:06 +0530468
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700469 constexpr std::array<uint8_t, compParamTableSize> compParamTable{
470 0x10, 0x00, 0x2c, 0x01, 0x14, 0xAB, 0xEF, 0xCD, 0xAB, 0x01, 0x0e, 0x01,
471 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x78, 0x56, 0x34, 0x12, 0x01,
472 0x0e, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x12, 0x00, 0x02,
473 0x00, 0x00, 0x00, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74,
474 0x72, 0x69, 0x6e, 0x67, 0x33, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
475 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x34};
gokulsanker22fbb342021-04-05 15:55:06 +0530476
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700477 constexpr size_t getFwParamsPayloadLen =
478 sizeof(pldm_get_firmware_parameters_resp) +
479 activeCompImageSetVersion.size() + pendingCompImageSetVersion.size() +
480 compParamTableSize;
481
482 constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
483 getFwParamsResponse{
484 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01,
485 0x0e, 0x01, 0x0e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53,
486 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x56, 0x65, 0x72, 0x73, 0x69,
487 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32, 0x10, 0x00,
488 0x2c, 0x01, 0x14, 0xAB, 0xEF, 0xCD, 0xAB, 0x01, 0x0e, 0x01, 0x02,
489 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x78, 0x56, 0x34, 0x12, 0x01,
490 0x0e, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x12, 0x00,
491 0x02, 0x00, 0x00, 0x00, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
492 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x33, 0x56, 0x65, 0x72, 0x73,
493 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x34};
494
495 auto responseMsg =
496 reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
497 pldm_get_firmware_parameters_resp outResp{};
498 variable_field outActiveCompImageSetVersion{};
499 variable_field outPendingCompImageSetVersion{};
500 variable_field outCompParameterTable{};
501
502 auto rc = decode_get_firmware_parameters_resp(
503 responseMsg, getFwParamsPayloadLen, &outResp,
504 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
505 &outCompParameterTable);
gokulsanker22fbb342021-04-05 15:55:06 +0530506
507 EXPECT_EQ(rc, PLDM_SUCCESS);
508 EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700509 EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
510 EXPECT_EQ(outResp.comp_count, compCount);
511 EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
512 EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
513 activeCompImageSetVersion.size());
514 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
515 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len,
516 pendingCompImageSetVersion.size());
517 std::string activeCompImageSetVersionStr(
518 reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
519 outActiveCompImageSetVersion.length);
520 EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
521 std::string pendingCompImageSetVersionStr(
522 reinterpret_cast<const char*>(outPendingCompImageSetVersion.ptr),
523 outPendingCompImageSetVersion.length);
524 EXPECT_EQ(pendingCompImageSetVersionStr, pendingCompImageSetVersion);
525 EXPECT_EQ(outCompParameterTable.length, compParamTableSize);
526 EXPECT_EQ(true, std::equal(outCompParameterTable.ptr,
527 outCompParameterTable.ptr +
528 outCompParameterTable.length,
529 compParamTable.begin(), compParamTable.end()));
530}
gokulsanker22fbb342021-04-05 15:55:06 +0530531
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700532TEST(GetFirmwareParameters, decodeResponseZeroCompCount)
533{
534 // CapabilitiesDuringUpdate of the firmware device
535 // FD Host Functionality during Firmware Update [Bit position 2] &
536 // Component Update Failure Retry Capability [Bit position 1]
537 constexpr std::bitset<32> fdCapabilities{0x06};
538 constexpr uint16_t compCount = 0;
539 constexpr std::string_view activeCompImageSetVersion{"VersionString1"};
540 constexpr std::string_view pendingCompImageSetVersion{"VersionString2"};
541
542 constexpr size_t getFwParamsPayloadLen =
543 sizeof(pldm_get_firmware_parameters_resp) +
544 activeCompImageSetVersion.size() + pendingCompImageSetVersion.size();
545
546 constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
547 getFwParamsResponse{
548 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
549 0x0e, 0x01, 0x0e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53,
550 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x56, 0x65, 0x72, 0x73, 0x69,
551 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32};
552
553 auto responseMsg =
554 reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
555 pldm_get_firmware_parameters_resp outResp{};
556 variable_field outActiveCompImageSetVersion{};
557 variable_field outPendingCompImageSetVersion{};
558 variable_field outCompParameterTable{};
559
560 auto rc = decode_get_firmware_parameters_resp(
561 responseMsg, getFwParamsPayloadLen, &outResp,
562 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
563 &outCompParameterTable);
564
565 EXPECT_EQ(rc, PLDM_SUCCESS);
566 EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
567 EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
568 EXPECT_EQ(outResp.comp_count, compCount);
569 EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
570 EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
571 activeCompImageSetVersion.size());
572 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
573 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len,
574 pendingCompImageSetVersion.size());
575 std::string activeCompImageSetVersionStr(
576 reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
577 outActiveCompImageSetVersion.length);
578 EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
579 std::string pendingCompImageSetVersionStr(
580 reinterpret_cast<const char*>(outPendingCompImageSetVersion.ptr),
581 outPendingCompImageSetVersion.length);
582 EXPECT_EQ(pendingCompImageSetVersionStr, pendingCompImageSetVersion);
583 EXPECT_EQ(outCompParameterTable.ptr, nullptr);
584 EXPECT_EQ(outCompParameterTable.length, 0);
585}
586
587TEST(GetFirmwareParameters,
588 decodeResponseNoPendingCompImageVersionStrZeroCompCount)
589{
590 // CapabilitiesDuringUpdate of the firmware device
591 // FD Host Functionality during Firmware Update [Bit position 2] &
592 // Component Update Failure Retry Capability [Bit position 1]
593 constexpr std::bitset<32> fdCapabilities{0x06};
594 constexpr uint16_t compCount = 0;
595 constexpr std::string_view activeCompImageSetVersion{"VersionString"};
596
597 constexpr size_t getFwParamsPayloadLen =
598 sizeof(pldm_get_firmware_parameters_resp) +
599 activeCompImageSetVersion.size();
600
601 constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
602 getFwParamsResponse{0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
603 0x00, 0x00, 0x00, 0x01, 0x0d, 0x00, 0x00,
604 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
605 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67};
606
607 auto responseMsg =
608 reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
609 pldm_get_firmware_parameters_resp outResp{};
610 variable_field outActiveCompImageSetVersion{};
611 variable_field outPendingCompImageSetVersion{};
612 variable_field outCompParameterTable{};
613
614 auto rc = decode_get_firmware_parameters_resp(
615 responseMsg, getFwParamsPayloadLen, &outResp,
616 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
617 &outCompParameterTable);
618
619 EXPECT_EQ(rc, PLDM_SUCCESS);
620 EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
621 EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
622 EXPECT_EQ(outResp.comp_count, compCount);
623 EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
624 EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
625 activeCompImageSetVersion.size());
626 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type,
627 PLDM_STR_TYPE_UNKNOWN);
628 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len, 0);
629 std::string activeCompImageSetVersionStr(
630 reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
631 outActiveCompImageSetVersion.length);
632 EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
633 EXPECT_EQ(outPendingCompImageSetVersion.ptr, nullptr);
634 EXPECT_EQ(outPendingCompImageSetVersion.length, 0);
635 EXPECT_EQ(outCompParameterTable.ptr, nullptr);
636 EXPECT_EQ(outCompParameterTable.length, 0);
637}
638
639TEST(GetFirmwareParameters, decodeResponseErrorCompletionCode)
640{
641 constexpr std::array<uint8_t,
642 hdrSize + sizeof(pldm_get_firmware_parameters_resp)>
643 getFwParamsResponse{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
644 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
645
646 auto responseMsg =
647 reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
648 pldm_get_firmware_parameters_resp outResp{};
649 variable_field outActiveCompImageSetVersion{};
650 variable_field outPendingCompImageSetVersion{};
651 variable_field outCompParameterTable{};
652
653 auto rc = decode_get_firmware_parameters_resp(
654 responseMsg, getFwParamsResponse.size(), &outResp,
655 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
656 &outCompParameterTable);
657
658 EXPECT_EQ(rc, PLDM_SUCCESS);
659 EXPECT_EQ(outResp.completion_code, PLDM_ERROR);
660}
661
662TEST(GetFirmwareParameters, errorPathdecodeResponse)
663{
664 int rc = 0;
665 // Invalid ActiveComponentImageSetVersionStringType
666 constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse1{
667 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
668 0x00, 0x00, 0x00, 0x06, 0x0e, 0x00, 0x00};
669
670 auto responseMsg =
671 reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse1.data());
672 pldm_get_firmware_parameters_resp outResp{};
673 variable_field outActiveCompImageSetVersion{};
674 variable_field outPendingCompImageSetVersion{};
675 variable_field outCompParameterTable{};
676
677 rc = decode_get_firmware_parameters_resp(
678 nullptr, invalidGetFwParamsResponse1.size(), &outResp,
679 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
680 &outCompParameterTable);
681 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
682
683 rc = decode_get_firmware_parameters_resp(
684 responseMsg, invalidGetFwParamsResponse1.size(), nullptr,
685 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
686 &outCompParameterTable);
687 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
688
689 rc = decode_get_firmware_parameters_resp(
690 responseMsg, invalidGetFwParamsResponse1.size(), &outResp, nullptr,
691 &outPendingCompImageSetVersion, &outCompParameterTable);
692 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
693
694 rc = decode_get_firmware_parameters_resp(
695 responseMsg, invalidGetFwParamsResponse1.size(), &outResp,
696 &outActiveCompImageSetVersion, nullptr, &outCompParameterTable);
697 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
698
699 rc = decode_get_firmware_parameters_resp(
700 responseMsg, invalidGetFwParamsResponse1.size(), &outResp,
701 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion, nullptr);
702 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
703
704 rc = decode_get_firmware_parameters_resp(
705 responseMsg, 0, &outResp, &outActiveCompImageSetVersion,
706 &outPendingCompImageSetVersion, &outCompParameterTable);
707 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
708
709 rc = decode_get_firmware_parameters_resp(
710 responseMsg, invalidGetFwParamsResponse1.size(), &outResp,
711 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
712 &outCompParameterTable);
713 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
714
715 // Invalid ActiveComponentImageSetVersionStringLength
716 constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse2{
717 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
718 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
719 responseMsg =
720 reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse2.data());
721 rc = decode_get_firmware_parameters_resp(
722 responseMsg, invalidGetFwParamsResponse2.size(), &outResp,
723 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
724 &outCompParameterTable);
725 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
726
727 // Invalid PendingComponentImageSetVersionStringType &
728 // PendingComponentImageSetVersionStringLength
729 constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse3{
730 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
731 0x00, 0x00, 0x00, 0x01, 0x0e, 0x01, 0x00};
732 responseMsg =
733 reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse3.data());
734 rc = decode_get_firmware_parameters_resp(
735 responseMsg, invalidGetFwParamsResponse3.size(), &outResp,
736 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
737 &outCompParameterTable);
738 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
739
740 // Invalid PendingComponentImageSetVersionStringType &
741 // PendingComponentImageSetVersionStringLength
742 constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse4{
743 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
744 0x00, 0x00, 0x00, 0x01, 0x0e, 0x06, 0x0e};
745 responseMsg =
746 reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse4.data());
747 rc = decode_get_firmware_parameters_resp(
748 responseMsg, invalidGetFwParamsResponse4.size(), &outResp,
749 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
750 &outCompParameterTable);
751 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
752
753 // Total payload length less than expected
754 constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse5{
755 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
756 0x00, 0x00, 0x00, 0x01, 0x0e, 0x01, 0x0e};
757 responseMsg =
758 reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse5.data());
759 rc = decode_get_firmware_parameters_resp(
760 responseMsg, invalidGetFwParamsResponse5.size(), &outResp,
761 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
762 &outCompParameterTable);
763 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
gokulsanker22fbb342021-04-05 15:55:06 +0530764}
gokulsankere1fb7a82021-04-05 16:09:29 +0530765
766TEST(GetFirmwareParameters, goodPathDecodeComponentParameterEntry)
767{
768 // Random value for component classification
769 constexpr uint16_t compClassification = 0x0A0B;
770 // Random value for component classification
771 constexpr uint16_t compIdentifier = 0x0C0D;
772 // Random value for component classification
773 constexpr uint32_t timestamp = 0X12345678;
774 // Random value for component activation methods
775 constexpr uint16_t compActivationMethods = 0xBBDD;
776 // Random value for capabilities during update
777 constexpr uint32_t capabilitiesDuringUpdate = 0xBADBEEFE;
778
779 // ActiveCompImageSetVerStrLen is not fixed here taking it as 8
780 constexpr uint8_t activeCompVerStrLen = 8;
781 // PendingCompImageSetVerStrLen is not fixed here taking it as 8
782 constexpr uint8_t pendingCompVerStrLen = 8;
783 constexpr size_t entryLength =
784 sizeof(struct pldm_component_parameter_entry) + activeCompVerStrLen +
785 pendingCompVerStrLen;
786 std::array<uint8_t, entryLength> entry{};
787
788 auto inEntry =
789 reinterpret_cast<struct pldm_component_parameter_entry*>(entry.data());
790
791 inEntry->comp_classification = htole16(compClassification);
792 inEntry->comp_identifier = htole16(compIdentifier);
793 inEntry->comp_classification_index = 0x0F;
794 inEntry->active_comp_comparison_stamp = htole32(timestamp);
795 inEntry->active_comp_ver_str_type = 1;
796 inEntry->active_comp_ver_str_len = activeCompVerStrLen;
797 std::fill_n(inEntry->active_comp_release_date,
798 sizeof(inEntry->active_comp_release_date), 0xFF);
799 inEntry->pending_comp_comparison_stamp = htole32(timestamp);
800 inEntry->pending_comp_ver_str_type = 1;
801 inEntry->pending_comp_ver_str_len = pendingCompVerStrLen;
802 std::fill_n(inEntry->pending_comp_release_date,
803 sizeof(inEntry->pending_comp_release_date), 0xFF);
804 inEntry->comp_activation_methods.value = htole16(compActivationMethods);
805 inEntry->capabilities_during_update.value =
806 htole32(capabilitiesDuringUpdate);
807 constexpr auto activeCompVerStrPos =
808 sizeof(struct pldm_component_parameter_entry);
809 std::fill_n(entry.data() + activeCompVerStrPos, activeCompVerStrLen, 0xAA);
810 constexpr auto pendingCompVerStrPos =
811 activeCompVerStrPos + activeCompVerStrLen;
812 std::fill_n(entry.data() + pendingCompVerStrPos, pendingCompVerStrLen,
813 0xBB);
814
815 struct pldm_component_parameter_entry outEntry;
816 struct variable_field outActiveCompVerStr;
817 struct variable_field outPendingCompVerStr;
818
819 auto rc = decode_get_firmware_parameters_resp_comp_entry(
820 entry.data(), entryLength, &outEntry, &outActiveCompVerStr,
821 &outPendingCompVerStr);
822
823 EXPECT_EQ(rc, PLDM_SUCCESS);
824
825 EXPECT_EQ(outEntry.comp_classification, compClassification);
826 EXPECT_EQ(outEntry.comp_identifier, compIdentifier);
827 EXPECT_EQ(inEntry->comp_classification_index,
828 outEntry.comp_classification_index);
829 EXPECT_EQ(outEntry.active_comp_comparison_stamp, timestamp);
830 EXPECT_EQ(inEntry->active_comp_ver_str_type,
831 outEntry.active_comp_ver_str_type);
832 EXPECT_EQ(inEntry->active_comp_ver_str_len,
833 outEntry.active_comp_ver_str_len);
834 EXPECT_EQ(0, memcmp(inEntry->active_comp_release_date,
835 outEntry.active_comp_release_date,
836 sizeof(inEntry->active_comp_release_date)));
837 EXPECT_EQ(outEntry.pending_comp_comparison_stamp, timestamp);
838 EXPECT_EQ(inEntry->pending_comp_ver_str_type,
839 outEntry.pending_comp_ver_str_type);
840 EXPECT_EQ(inEntry->pending_comp_ver_str_len,
841 outEntry.pending_comp_ver_str_len);
842 EXPECT_EQ(0, memcmp(inEntry->pending_comp_release_date,
843 outEntry.pending_comp_release_date,
844 sizeof(inEntry->pending_comp_release_date)));
845 EXPECT_EQ(outEntry.comp_activation_methods.value, compActivationMethods);
846 EXPECT_EQ(outEntry.capabilities_during_update.value,
847 capabilitiesDuringUpdate);
848
849 EXPECT_EQ(0, memcmp(outActiveCompVerStr.ptr,
850 entry.data() + activeCompVerStrPos,
851 outActiveCompVerStr.length));
852 EXPECT_EQ(0, memcmp(outPendingCompVerStr.ptr,
853 entry.data() + pendingCompVerStrPos,
854 outPendingCompVerStr.length));
855}