blob: 756097fb1e563f254d9343c0328d47ac737d71aa [file] [log] [blame]
Andrew Jeffery9c766792022-08-10 23:12:49 +09301#include <bitset>
2#include <cstring>
3
4#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
11TEST(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> package_release_date_time{
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.package_release_date_time,
50 pkgHeader.package_release_date_time +
51 PLDM_TIMESTAMP104_SIZE,
52 package_release_date_time.begin(),
53 package_release_date_time.end()));
54 EXPECT_EQ(pkgHeader.component_bitmap_bit_length, componentBitmapBitLength);
55 EXPECT_EQ(pkgHeader.package_version_string_type, PLDM_STR_TYPE_ASCII);
56 EXPECT_EQ(pkgHeader.package_version_string_length,
57 packageVersionStr.size());
58 std::string packageVersionString(
59 reinterpret_cast<const char*>(packageVersion.ptr),
60 packageVersion.length);
61 EXPECT_EQ(packageVersionString, packageVersionStr);
62}
63
64TEST(DecodePackageHeaderInfo, errorPaths)
65{
66 int rc = 0;
67 constexpr std::string_view packageVersionStr{"OpenBMCv1.0"};
68 constexpr size_t packagerHeaderSize =
69 sizeof(pldm_package_header_information) + packageVersionStr.size();
70
71 // Invalid Package Version String Type - 0x06
72 constexpr std::array<uint8_t, packagerHeaderSize>
73 invalidPackagerHeaderInfo1{
74 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
75 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
76 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
77 0x07, 0x00, 0x08, 0x00, 0x06, 0x0b, 0x4f, 0x70, 0x65, 0x6e,
78 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
79
80 pldm_package_header_information packageHeader{};
81 variable_field packageVersion{};
82
83 rc = decode_pldm_package_header_info(nullptr,
84 invalidPackagerHeaderInfo1.size(),
85 &packageHeader, &packageVersion);
86 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
87
88 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo1.data(),
89 invalidPackagerHeaderInfo1.size(),
90 nullptr, &packageVersion);
91 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
92
93 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo1.data(),
94 invalidPackagerHeaderInfo1.size(),
95 &packageHeader, nullptr);
96 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
97
98 rc = decode_pldm_package_header_info(
99 invalidPackagerHeaderInfo1.data(),
100 sizeof(pldm_package_header_information) - 1, &packageHeader,
101 &packageVersion);
102 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
103
104 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo1.data(),
105 invalidPackagerHeaderInfo1.size(),
106 &packageHeader, &packageVersion);
107 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
108
109 // Invalid Package Version String Length - 0x00
110 constexpr std::array<uint8_t, packagerHeaderSize>
111 invalidPackagerHeaderInfo2{
112 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
113 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
114 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
115 0x07, 0x00, 0x08, 0x00, 0x01, 0x00, 0x4f, 0x70, 0x65, 0x6e,
116 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
117 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo2.data(),
118 invalidPackagerHeaderInfo2.size(),
119 &packageHeader, &packageVersion);
120 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
121
122 // Package version string length less than in the header information
123 constexpr std::array<uint8_t, packagerHeaderSize - 1>
124 invalidPackagerHeaderInfo3{
125 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
126 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
127 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
128 0x07, 0x00, 0x08, 0x00, 0x01, 0x0b, 0x4f, 0x70, 0x65, 0x6e,
129 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e};
130 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo3.data(),
131 invalidPackagerHeaderInfo3.size(),
132 &packageHeader, &packageVersion);
133 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
134
135 // ComponentBitmapBitLength not a multiple of 8
136 constexpr std::array<uint8_t, packagerHeaderSize>
137 invalidPackagerHeaderInfo4{
138 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
139 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
140 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
141 0x07, 0x00, 0x09, 0x00, 0x01, 0x0b, 0x4f, 0x70, 0x65, 0x6e,
142 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
143 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo4.data(),
144 invalidPackagerHeaderInfo4.size(),
145 &packageHeader, &packageVersion);
146 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
147}
148
149TEST(DecodeFirmwareDeviceIdRecord, goodPath)
150{
151 constexpr uint8_t descriptorCount = 1;
152 // Continue component updates after failure
153 constexpr std::bitset<32> deviceUpdateFlag{1};
154 constexpr uint16_t componentBitmapBitLength = 16;
155 // Applicable Components - 1,2,5,8,9
156 std::vector<std::bitset<8>> applicableComponentsBitfield{0x93, 0x01};
157 // ComponentImageSetVersionString
158 constexpr std::string_view imageSetVersionStr{"VersionString1"};
159 // Initial descriptor - UUID
160 constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
161 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
162 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
163 constexpr uint16_t fwDevicePkgDataLen = 2;
164 // FirmwareDevicePackageData
165 constexpr std::array<uint8_t, fwDevicePkgDataLen> fwDevicePkgData{0xab,
166 0xcd};
167 // Size of the firmware device ID record
168 constexpr uint16_t recordLen =
169 sizeof(pldm_firmware_device_id_record) +
170 (componentBitmapBitLength / PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE) +
171 imageSetVersionStr.size() + sizeof(pldm_descriptor_tlv) - 1 +
172 uuid.size() + fwDevicePkgData.size();
173 // Firmware device ID record
174 constexpr std::array<uint8_t, recordLen> record{
175 0x31, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x02,
176 0x00, 0x93, 0x01, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
177 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x02, 0x00, 0x10,
178 0x00, 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18, 0xa0,
179 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b, 0xab, 0xcd};
180
181 pldm_firmware_device_id_record deviceIdRecHeader{};
182 variable_field applicableComponents{};
183 variable_field outCompImageSetVersionStr{};
184 variable_field recordDescriptors{};
185 variable_field outFwDevicePkgData{};
186
187 auto rc = decode_firmware_device_id_record(
188 record.data(), record.size(), componentBitmapBitLength,
189 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
190 &recordDescriptors, &outFwDevicePkgData);
191
192 EXPECT_EQ(rc, PLDM_SUCCESS);
193 EXPECT_EQ(deviceIdRecHeader.record_length, recordLen);
194 EXPECT_EQ(deviceIdRecHeader.descriptor_count, descriptorCount);
195 EXPECT_EQ(deviceIdRecHeader.device_update_option_flags.value,
196 deviceUpdateFlag);
197 EXPECT_EQ(deviceIdRecHeader.comp_image_set_version_string_type,
198 PLDM_STR_TYPE_ASCII);
199 EXPECT_EQ(deviceIdRecHeader.comp_image_set_version_string_length,
200 imageSetVersionStr.size());
201 EXPECT_EQ(deviceIdRecHeader.fw_device_pkg_data_length, fwDevicePkgDataLen);
202
203 EXPECT_EQ(applicableComponents.length, applicableComponentsBitfield.size());
204 EXPECT_EQ(true,
205 std::equal(applicableComponents.ptr,
206 applicableComponents.ptr + applicableComponents.length,
207 applicableComponentsBitfield.begin(),
208 applicableComponentsBitfield.end()));
209
210 EXPECT_EQ(outCompImageSetVersionStr.length, imageSetVersionStr.size());
211 std::string compImageSetVersionStr(
212 reinterpret_cast<const char*>(outCompImageSetVersionStr.ptr),
213 outCompImageSetVersionStr.length);
214 EXPECT_EQ(compImageSetVersionStr, imageSetVersionStr);
215
216 uint16_t descriptorType = 0;
217 uint16_t descriptorLen = 0;
218 variable_field descriptorData{};
219 // DescriptorCount is 1, so decode_descriptor_type_length_value called once
220 rc = decode_descriptor_type_length_value(recordDescriptors.ptr,
221 recordDescriptors.length,
222 &descriptorType, &descriptorData);
223 EXPECT_EQ(rc, PLDM_SUCCESS);
224 EXPECT_EQ(recordDescriptors.length, sizeof(descriptorType) +
225 sizeof(descriptorLen) +
226 descriptorData.length);
227 EXPECT_EQ(descriptorType, PLDM_FWUP_UUID);
228 EXPECT_EQ(descriptorData.length, PLDM_FWUP_UUID_LENGTH);
229 EXPECT_EQ(true, std::equal(descriptorData.ptr,
230 descriptorData.ptr + descriptorData.length,
231 uuid.begin(), uuid.end()));
232
233 EXPECT_EQ(outFwDevicePkgData.length, fwDevicePkgData.size());
234 EXPECT_EQ(true,
235 std::equal(outFwDevicePkgData.ptr,
236 outFwDevicePkgData.ptr + outFwDevicePkgData.length,
237 fwDevicePkgData.begin(), fwDevicePkgData.end()));
238}
239
240TEST(DecodeFirmwareDeviceIdRecord, goodPathNofwDevicePkgData)
241{
242 constexpr uint8_t descriptorCount = 1;
243 // Continue component updates after failure
244 constexpr std::bitset<32> deviceUpdateFlag{1};
245 constexpr uint16_t componentBitmapBitLength = 8;
246 // Applicable Components - 1,2
247 std::vector<std::bitset<8>> applicableComponentsBitfield{0x03};
248 // ComponentImageSetVersionString
249 constexpr std::string_view imageSetVersionStr{"VersionString1"};
250 // Initial descriptor - UUID
251 constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
252 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
253 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
254 constexpr uint16_t fwDevicePkgDataLen = 0;
255
256 // Size of the firmware device ID record
257 constexpr uint16_t recordLen =
258 sizeof(pldm_firmware_device_id_record) +
259 (componentBitmapBitLength / PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE) +
260 imageSetVersionStr.size() +
261 sizeof(pldm_descriptor_tlv().descriptor_type) +
262 sizeof(pldm_descriptor_tlv().descriptor_length) + uuid.size() +
263 fwDevicePkgDataLen;
264 // Firmware device ID record
265 constexpr std::array<uint8_t, recordLen> record{
266 0x2e, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x00, 0x00, 0x03,
267 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e,
268 0x67, 0x31, 0x02, 0x00, 0x10, 0x00, 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d,
269 0x47, 0x18, 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
270
271 pldm_firmware_device_id_record deviceIdRecHeader{};
272 variable_field applicableComponents{};
273 variable_field outCompImageSetVersionStr{};
274 variable_field recordDescriptors{};
275 variable_field outFwDevicePkgData{};
276
277 auto rc = decode_firmware_device_id_record(
278 record.data(), record.size(), componentBitmapBitLength,
279 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
280 &recordDescriptors, &outFwDevicePkgData);
281
282 EXPECT_EQ(rc, PLDM_SUCCESS);
283 EXPECT_EQ(deviceIdRecHeader.record_length, recordLen);
284 EXPECT_EQ(deviceIdRecHeader.descriptor_count, descriptorCount);
285 EXPECT_EQ(deviceIdRecHeader.device_update_option_flags.value,
286 deviceUpdateFlag);
287 EXPECT_EQ(deviceIdRecHeader.comp_image_set_version_string_type,
288 PLDM_STR_TYPE_ASCII);
289 EXPECT_EQ(deviceIdRecHeader.comp_image_set_version_string_length,
290 imageSetVersionStr.size());
291 EXPECT_EQ(deviceIdRecHeader.fw_device_pkg_data_length, 0);
292
293 EXPECT_EQ(applicableComponents.length, applicableComponentsBitfield.size());
294 EXPECT_EQ(true,
295 std::equal(applicableComponents.ptr,
296 applicableComponents.ptr + applicableComponents.length,
297 applicableComponentsBitfield.begin(),
298 applicableComponentsBitfield.end()));
299
300 EXPECT_EQ(outCompImageSetVersionStr.length, imageSetVersionStr.size());
301 std::string compImageSetVersionStr(
302 reinterpret_cast<const char*>(outCompImageSetVersionStr.ptr),
303 outCompImageSetVersionStr.length);
304 EXPECT_EQ(compImageSetVersionStr, imageSetVersionStr);
305
306 uint16_t descriptorType = 0;
307 uint16_t descriptorLen = 0;
308 variable_field descriptorData{};
309 // DescriptorCount is 1, so decode_descriptor_type_length_value called once
310 rc = decode_descriptor_type_length_value(recordDescriptors.ptr,
311 recordDescriptors.length,
312 &descriptorType, &descriptorData);
313 EXPECT_EQ(rc, PLDM_SUCCESS);
314 EXPECT_EQ(recordDescriptors.length, sizeof(descriptorType) +
315 sizeof(descriptorLen) +
316 descriptorData.length);
317 EXPECT_EQ(descriptorType, PLDM_FWUP_UUID);
318 EXPECT_EQ(descriptorData.length, PLDM_FWUP_UUID_LENGTH);
319 EXPECT_EQ(true, std::equal(descriptorData.ptr,
320 descriptorData.ptr + descriptorData.length,
321 uuid.begin(), uuid.end()));
322
323 EXPECT_EQ(outFwDevicePkgData.ptr, nullptr);
324 EXPECT_EQ(outFwDevicePkgData.length, 0);
325}
326
327TEST(DecodeFirmwareDeviceIdRecord, ErrorPaths)
328{
329 constexpr uint16_t componentBitmapBitLength = 8;
330 // Invalid ComponentImageSetVersionStringType
331 constexpr std::array<uint8_t, 11> invalidRecord1{
332 0x0b, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x06, 0x0e, 0x00, 0x00};
333
334 int rc = 0;
335 pldm_firmware_device_id_record deviceIdRecHeader{};
336 variable_field applicableComponents{};
337 variable_field outCompImageSetVersionStr{};
338 variable_field recordDescriptors{};
339 variable_field outFwDevicePkgData{};
340
341 rc = decode_firmware_device_id_record(
342 nullptr, invalidRecord1.size(), componentBitmapBitLength,
343 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
344 &recordDescriptors, &outFwDevicePkgData);
345 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
346
347 rc = decode_firmware_device_id_record(
348 invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
349 nullptr, &applicableComponents, &outCompImageSetVersionStr,
350 &recordDescriptors, &outFwDevicePkgData);
351 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
352
353 rc = decode_firmware_device_id_record(
354 invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
355 &deviceIdRecHeader, nullptr, &outCompImageSetVersionStr,
356 &recordDescriptors, &outFwDevicePkgData);
357 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
358
359 rc = decode_firmware_device_id_record(
360 invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
361 &deviceIdRecHeader, &applicableComponents, nullptr, &recordDescriptors,
362 &outFwDevicePkgData);
363 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
364
365 rc = decode_firmware_device_id_record(
366 invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
367 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
368 nullptr, &outFwDevicePkgData);
369 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
370
371 rc = decode_firmware_device_id_record(
372 invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
373 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
374 &recordDescriptors, nullptr);
375 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
376
377 rc = decode_firmware_device_id_record(
378 invalidRecord1.data(), invalidRecord1.size() - 1,
379 componentBitmapBitLength, &deviceIdRecHeader, &applicableComponents,
380 &outCompImageSetVersionStr, &recordDescriptors, &outFwDevicePkgData);
381 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
382
383 rc = decode_firmware_device_id_record(
384 invalidRecord1.data(), invalidRecord1.size(),
385 componentBitmapBitLength + 1, &deviceIdRecHeader, &applicableComponents,
386 &outCompImageSetVersionStr, &recordDescriptors, &outFwDevicePkgData);
387 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
388
389 rc = decode_firmware_device_id_record(
390 invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
391 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
392 &recordDescriptors, &outFwDevicePkgData);
393 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
394
395 // Invalid ComponentImageSetVersionStringLength
396 constexpr std::array<uint8_t, 11> invalidRecord2{
397 0x0b, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
398 rc = decode_firmware_device_id_record(
399 invalidRecord2.data(), invalidRecord2.size(), componentBitmapBitLength,
400 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
401 &recordDescriptors, &outFwDevicePkgData);
402 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
403
404 // invalidRecord3 size is less than RecordLength
405 constexpr std::array<uint8_t, 11> invalidRecord3{
406 0x2e, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x00, 0x00};
407 rc = decode_firmware_device_id_record(
408 invalidRecord3.data(), invalidRecord3.size(), componentBitmapBitLength,
409 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
410 &recordDescriptors, &outFwDevicePkgData);
411 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
412
413 // RecordLength is less than the calculated RecordLength
414 constexpr std::array<uint8_t, 11> invalidRecord4{
415 0x15, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x02, 0x00};
416 rc = decode_firmware_device_id_record(
417 invalidRecord4.data(), invalidRecord4.size(), componentBitmapBitLength,
418 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
419 &recordDescriptors, &outFwDevicePkgData);
420 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
421}
422
423TEST(DecodeDescriptors, goodPath3Descriptors)
424{
425 // In the descriptor data there are 3 descriptor entries
426 // 1) IANA enterprise ID
427 constexpr std::array<uint8_t, PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH> iana{
428 0x0a, 0x0b, 0x0c, 0xd};
429 // 2) UUID
430 constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
431 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
432 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
433 // 3) Vendor Defined
434 constexpr std::string_view vendorTitle{"OpenBMC"};
435 constexpr size_t vendorDescriptorLen = 2;
436 constexpr std::array<uint8_t, vendorDescriptorLen> vendorDescriptorData{
437 0x01, 0x02};
438
439 constexpr size_t vendorDefinedDescriptorLen =
440 sizeof(pldm_vendor_defined_descriptor_title_data()
441 .vendor_defined_descriptor_title_str_type) +
442 sizeof(pldm_vendor_defined_descriptor_title_data()
443 .vendor_defined_descriptor_title_str_len) +
444 vendorTitle.size() + vendorDescriptorData.size();
445
446 constexpr size_t descriptorsLength =
447 3 * (sizeof(pldm_descriptor_tlv().descriptor_type) +
448 sizeof(pldm_descriptor_tlv().descriptor_length)) +
449 iana.size() + uuid.size() + vendorDefinedDescriptorLen;
450
451 constexpr std::array<uint8_t, descriptorsLength> descriptors{
452 0x01, 0x00, 0x04, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x02, 0x00, 0x10,
453 0x00, 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18, 0xa0, 0x30,
454 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b, 0xFF, 0xFF, 0x0B, 0x00, 0x01,
455 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43, 0x01, 0x02};
456
457 size_t descriptorCount = 1;
458 size_t descriptorsRemainingLength = descriptorsLength;
459 int rc = 0;
460
461 while (descriptorsRemainingLength && (descriptorCount <= 3))
462 {
463 uint16_t descriptorType = 0;
464 uint16_t descriptorLen = 0;
465 variable_field descriptorData{};
466
467 rc = decode_descriptor_type_length_value(
468 descriptors.data() + descriptorsLength - descriptorsRemainingLength,
469 descriptorsRemainingLength, &descriptorType, &descriptorData);
470 EXPECT_EQ(rc, PLDM_SUCCESS);
471
472 if (descriptorCount == 1)
473 {
474 EXPECT_EQ(descriptorType, PLDM_FWUP_IANA_ENTERPRISE_ID);
475 EXPECT_EQ(descriptorData.length,
476 PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH);
477 EXPECT_EQ(true,
478 std::equal(descriptorData.ptr,
479 descriptorData.ptr + descriptorData.length,
480 iana.begin(), iana.end()));
481 }
482 else if (descriptorCount == 2)
483 {
484 EXPECT_EQ(descriptorType, PLDM_FWUP_UUID);
485 EXPECT_EQ(descriptorData.length, PLDM_FWUP_UUID_LENGTH);
486 EXPECT_EQ(true,
487 std::equal(descriptorData.ptr,
488 descriptorData.ptr + descriptorData.length,
489 uuid.begin(), uuid.end()));
490 }
491 else if (descriptorCount == 3)
492 {
493 EXPECT_EQ(descriptorType, PLDM_FWUP_VENDOR_DEFINED);
494 EXPECT_EQ(descriptorData.length, vendorDefinedDescriptorLen);
495
496 uint8_t descriptorTitleStrType = 0;
497 variable_field descriptorTitleStr{};
498 variable_field vendorDefinedDescriptorData{};
499
500 rc = decode_vendor_defined_descriptor_value(
501 descriptorData.ptr, descriptorData.length,
502 &descriptorTitleStrType, &descriptorTitleStr,
503 &vendorDefinedDescriptorData);
504 EXPECT_EQ(rc, PLDM_SUCCESS);
505
506 EXPECT_EQ(descriptorTitleStrType, PLDM_STR_TYPE_ASCII);
507 EXPECT_EQ(descriptorTitleStr.length, vendorTitle.size());
508 std::string vendorTitleStr(
509 reinterpret_cast<const char*>(descriptorTitleStr.ptr),
510 descriptorTitleStr.length);
511 EXPECT_EQ(vendorTitleStr, vendorTitle);
512
513 EXPECT_EQ(vendorDefinedDescriptorData.length,
514 vendorDescriptorData.size());
515 EXPECT_EQ(true, std::equal(vendorDefinedDescriptorData.ptr,
516 vendorDefinedDescriptorData.ptr +
517 vendorDefinedDescriptorData.length,
518 vendorDescriptorData.begin(),
519 vendorDescriptorData.end()));
520 }
521
522 descriptorsRemainingLength -= sizeof(descriptorType) +
523 sizeof(descriptorLen) +
524 descriptorData.length;
525 descriptorCount++;
526 }
527}
528
529TEST(DecodeDescriptors, errorPathDecodeDescriptorTLV)
530{
531 int rc = 0;
532 // IANA Enterprise ID descriptor length incorrect
533 constexpr std::array<uint8_t, 7> invalidIANADescriptor1{
534 0x01, 0x00, 0x03, 0x00, 0x0a, 0x0b, 0x0c};
535 uint16_t descriptorType = 0;
536 variable_field descriptorData{};
537
538 rc = decode_descriptor_type_length_value(nullptr,
539 invalidIANADescriptor1.size(),
540 &descriptorType, &descriptorData);
541 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
542
543 rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
544 invalidIANADescriptor1.size(),
545 nullptr, &descriptorData);
546 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
547
548 rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
549 invalidIANADescriptor1.size(),
550 &descriptorType, nullptr);
551 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
552
553 rc = decode_descriptor_type_length_value(
554 invalidIANADescriptor1.data(), PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN - 1,
555 &descriptorType, &descriptorData);
556 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
557
558 rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
559 invalidIANADescriptor1.size(),
560 &descriptorType, &descriptorData);
561 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
562
563 // IANA Enterprise ID descriptor data less than length
564 std::array<uint8_t, 7> invalidIANADescriptor2{0x01, 0x00, 0x04, 0x00,
565 0x0a, 0x0b, 0x0c};
566 rc = decode_descriptor_type_length_value(invalidIANADescriptor2.data(),
567 invalidIANADescriptor2.size(),
568 &descriptorType, &descriptorData);
569 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
570}
571
572TEST(DecodeDescriptors, errorPathVendorDefinedDescriptor)
573{
574 int rc = 0;
575 // VendorDefinedDescriptorTitleStringType is invalid
576 constexpr std::array<uint8_t, 9> invalidVendorDescriptor1{
577 0x06, 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
578 uint8_t descriptorStringType = 0;
579 variable_field descriptorTitleStr{};
580 variable_field vendorDefinedDescriptorData{};
581
582 rc = decode_vendor_defined_descriptor_value(
583 nullptr, invalidVendorDescriptor1.size(), &descriptorStringType,
584 &descriptorTitleStr, &vendorDefinedDescriptorData);
585 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
586
587 rc = decode_vendor_defined_descriptor_value(
588 invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
589 &descriptorStringType, &descriptorTitleStr,
590 &vendorDefinedDescriptorData);
591 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
592
593 rc = decode_vendor_defined_descriptor_value(
594 invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
595 nullptr, &descriptorTitleStr, &vendorDefinedDescriptorData);
596 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
597
598 rc = decode_vendor_defined_descriptor_value(
599 invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
600 &descriptorStringType, nullptr, &vendorDefinedDescriptorData);
601 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
602
603 rc = decode_vendor_defined_descriptor_value(
604 invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
605 &descriptorStringType, &descriptorTitleStr, nullptr);
606 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
607
608 rc = decode_vendor_defined_descriptor_value(
609 invalidVendorDescriptor1.data(),
610 sizeof(pldm_vendor_defined_descriptor_title_data) - 1,
611 &descriptorStringType, &descriptorTitleStr,
612 &vendorDefinedDescriptorData);
613 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
614
615 rc = decode_vendor_defined_descriptor_value(
616 invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
617 &descriptorStringType, &descriptorTitleStr,
618 &vendorDefinedDescriptorData);
619 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
620
621 // VendorDefinedDescriptorTitleStringLength is 0
622 std::array<uint8_t, 9> invalidVendorDescriptor2{
623 0x01, 0x00, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
624 rc = decode_vendor_defined_descriptor_value(
625 invalidVendorDescriptor2.data(), invalidVendorDescriptor2.size(),
626 &descriptorStringType, &descriptorTitleStr,
627 &vendorDefinedDescriptorData);
628 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
629
630 // VendorDefinedDescriptorData not present in the data
631 std::array<uint8_t, 9> invalidVendorDescriptor3{
632 0x01, 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
633 rc = decode_vendor_defined_descriptor_value(
634 invalidVendorDescriptor3.data(), invalidVendorDescriptor3.size(),
635 &descriptorStringType, &descriptorTitleStr,
636 &vendorDefinedDescriptorData);
637 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
638}
639
640TEST(DecodeComponentImageInfo, goodPath)
641{
642 // Firmware
643 constexpr uint16_t compClassification = 16;
644 constexpr uint16_t compIdentifier = 300;
645 constexpr uint32_t compComparisonStamp = 0xFFFFFFFF;
646 // Force update
647 constexpr std::bitset<16> compOptions{1};
648 // System reboot[Bit position 3] & Medium-specific reset[Bit position 2]
649 constexpr std::bitset<16> reqCompActivationMethod{0x0c};
650 // Random ComponentLocationOffset
651 constexpr uint32_t compLocOffset = 357;
652 // Random ComponentSize
653 constexpr uint32_t compSize = 27;
654 // ComponentVersionString
655 constexpr std::string_view compVersionStr{"VersionString1"};
656 constexpr size_t compImageInfoSize =
657 sizeof(pldm_component_image_information) + compVersionStr.size();
658
659 constexpr std::array<uint8_t, compImageInfoSize> compImageInfo{
660 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
661 0x65, 0x01, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x56, 0x65,
662 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
663 pldm_component_image_information outCompImageInfo{};
664 variable_field outCompVersionStr{};
665
666 auto rc =
667 decode_pldm_comp_image_info(compImageInfo.data(), compImageInfo.size(),
668 &outCompImageInfo, &outCompVersionStr);
669
670 EXPECT_EQ(rc, PLDM_SUCCESS);
671 EXPECT_EQ(outCompImageInfo.comp_classification, compClassification);
672 EXPECT_EQ(outCompImageInfo.comp_identifier, compIdentifier);
673 EXPECT_EQ(outCompImageInfo.comp_comparison_stamp, compComparisonStamp);
674 EXPECT_EQ(outCompImageInfo.comp_options.value, compOptions);
675 EXPECT_EQ(outCompImageInfo.requested_comp_activation_method.value,
676 reqCompActivationMethod);
677 EXPECT_EQ(outCompImageInfo.comp_location_offset, compLocOffset);
678 EXPECT_EQ(outCompImageInfo.comp_size, compSize);
679 EXPECT_EQ(outCompImageInfo.comp_version_string_type, PLDM_STR_TYPE_ASCII);
680 EXPECT_EQ(outCompImageInfo.comp_version_string_length,
681 compVersionStr.size());
682
683 EXPECT_EQ(outCompVersionStr.length,
684 outCompImageInfo.comp_version_string_length);
685 std::string componentVersionString(
686 reinterpret_cast<const char*>(outCompVersionStr.ptr),
687 outCompVersionStr.length);
688 EXPECT_EQ(componentVersionString, compVersionStr);
689}
690
691TEST(DecodeComponentImageInfo, errorPaths)
692{
693 int rc = 0;
694 // ComponentVersionString
695 constexpr std::string_view compVersionStr{"VersionString1"};
696 constexpr size_t compImageInfoSize =
697 sizeof(pldm_component_image_information) + compVersionStr.size();
698 // Invalid ComponentVersionStringType - 0x06
699 constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo1{
700 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
701 0x65, 0x01, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x06, 0x0e, 0x56, 0x65,
702 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
703 pldm_component_image_information outCompImageInfo{};
704 variable_field outCompVersionStr{};
705
706 rc = decode_pldm_comp_image_info(nullptr, invalidCompImageInfo1.size(),
707 &outCompImageInfo, &outCompVersionStr);
708 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
709
710 rc = decode_pldm_comp_image_info(invalidCompImageInfo1.data(),
711 invalidCompImageInfo1.size(), nullptr,
712 &outCompVersionStr);
713 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
714
715 rc = decode_pldm_comp_image_info(invalidCompImageInfo1.data(),
716 invalidCompImageInfo1.size(),
717 &outCompImageInfo, nullptr);
718 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
719
720 rc = decode_pldm_comp_image_info(invalidCompImageInfo1.data(),
721 sizeof(pldm_component_image_information) -
722 1,
723 &outCompImageInfo, &outCompVersionStr);
724 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
725
726 rc = decode_pldm_comp_image_info(invalidCompImageInfo1.data(),
727 invalidCompImageInfo1.size(),
728 &outCompImageInfo, &outCompVersionStr);
729 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
730
731 // Invalid ComponentVersionStringLength - 0x00
732 constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo2{
733 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
734 0x65, 0x01, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x56, 0x65,
735 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
736 rc = decode_pldm_comp_image_info(invalidCompImageInfo2.data(),
737 invalidCompImageInfo2.size(),
738 &outCompImageInfo, &outCompVersionStr);
739 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
740
741 // Use Component Comparison Stamp is not set, but ComponentComparisonStamp
742 // is not 0xFFFFFFFF
743 constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo3{
744 0x10, 0x00, 0x2c, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0c, 0x00,
745 0x65, 0x01, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x56, 0x65,
746 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
747
748 rc = decode_pldm_comp_image_info(invalidCompImageInfo3.data(),
749 invalidCompImageInfo3.size() - 1,
750 &outCompImageInfo, &outCompVersionStr);
751 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
752
753 rc = decode_pldm_comp_image_info(invalidCompImageInfo3.data(),
754 invalidCompImageInfo3.size(),
755 &outCompImageInfo, &outCompVersionStr);
756 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
757
758 // Invalid ComponentLocationOffset - 0
759 constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo4{
760 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
761 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x56, 0x65,
762 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
763 rc = decode_pldm_comp_image_info(invalidCompImageInfo4.data(),
764 invalidCompImageInfo4.size(),
765 &outCompImageInfo, &outCompVersionStr);
766 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
767
768 // Invalid ComponentSize - 0
769 constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo5{
770 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
771 0x65, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x56, 0x65,
772 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
773 rc = decode_pldm_comp_image_info(invalidCompImageInfo5.data(),
774 invalidCompImageInfo5.size(),
775 &outCompImageInfo, &outCompVersionStr);
776 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
777}
778
779TEST(QueryDeviceIdentifiers, goodPathEncodeRequest)
780{
781 std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
782 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
783
784 uint8_t instanceId = 0x01;
785
786 auto rc = encode_query_device_identifiers_req(
787 instanceId, PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES, requestPtr);
788 EXPECT_EQ(rc, PLDM_SUCCESS);
789 EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
790 EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
791 EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
792 EXPECT_EQ(requestPtr->hdr.command, PLDM_QUERY_DEVICE_IDENTIFIERS);
793}
794
795TEST(QueryDeviceIdentifiers, goodPathDecodeResponse)
796{
797 // descriptorDataLen is not fixed here taking it as 6
798 constexpr uint8_t descriptorDataLen = 6;
799 std::array<uint8_t, hdrSize +
800 sizeof(struct pldm_query_device_identifiers_resp) +
801 descriptorDataLen>
802 responseMsg{};
803 auto inResp = reinterpret_cast<struct pldm_query_device_identifiers_resp*>(
804 responseMsg.data() + hdrSize);
805
806 inResp->completion_code = PLDM_SUCCESS;
807 inResp->device_identifiers_len = htole32(descriptorDataLen);
808 inResp->descriptor_count = 1;
809
810 // filling descriptor data
811 std::fill_n(responseMsg.data() + hdrSize +
812 sizeof(struct pldm_query_device_identifiers_resp),
813 descriptorDataLen, 0xFF);
814
815 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
816 uint8_t completionCode = PLDM_SUCCESS;
817 uint32_t deviceIdentifiersLen = 0;
818 uint8_t descriptorCount = 0;
819 uint8_t* outDescriptorData = nullptr;
820
821 auto rc = decode_query_device_identifiers_resp(
822 response, responseMsg.size() - hdrSize, &completionCode,
823 &deviceIdentifiersLen, &descriptorCount, &outDescriptorData);
824
825 EXPECT_EQ(rc, PLDM_SUCCESS);
826 EXPECT_EQ(completionCode, PLDM_SUCCESS);
827 EXPECT_EQ(deviceIdentifiersLen, inResp->device_identifiers_len);
828 EXPECT_EQ(descriptorCount, inResp->descriptor_count);
829 EXPECT_EQ(true,
830 std::equal(outDescriptorData,
831 outDescriptorData + deviceIdentifiersLen,
832 responseMsg.begin() + hdrSize +
833 sizeof(struct pldm_query_device_identifiers_resp),
834 responseMsg.end()));
835}
836
837TEST(GetFirmwareParameters, goodPathEncodeRequest)
838{
839 std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
840 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
841 uint8_t instanceId = 0x01;
842
843 auto rc = encode_get_firmware_parameters_req(
844 instanceId, PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES, requestPtr);
845 EXPECT_EQ(rc, PLDM_SUCCESS);
846 EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
847 EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
848 EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
849 EXPECT_EQ(requestPtr->hdr.command, PLDM_GET_FIRMWARE_PARAMETERS);
850}
851
852TEST(GetFirmwareParameters, decodeResponse)
853{
854 // CapabilitiesDuringUpdate of the firmware device
855 // Firmware device downgrade restrictions [Bit position 8] &
856 // Firmware Device Partial Updates [Bit position 3]
857 constexpr std::bitset<32> fdCapabilities{0x00000104};
858 constexpr uint16_t compCount = 1;
859 constexpr std::string_view activeCompImageSetVersion{"VersionString1"};
860 constexpr std::string_view pendingCompImageSetVersion{"VersionString2"};
861
862 // constexpr uint16_t compClassification = 16;
863 // constexpr uint16_t compIdentifier = 300;
864 // constexpr uint8_t compClassificationIndex = 20;
865 // constexpr uint32_t activeCompComparisonStamp = 0xABCDEFAB;
866 // constexpr std::array<uint8_t, 8> activeComponentReleaseData = {
867 // 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
868 // constexpr uint32_t pendingCompComparisonStamp = 0x12345678;
869 // constexpr std::array<uint8_t, 8> pendingComponentReleaseData = {
870 // 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01};
871 constexpr std::string_view activeCompVersion{"VersionString3"};
872 constexpr std::string_view pendingCompVersion{"VersionString4"};
873 // ComponentActivationMethods
874 // DC Power cycle [Bit position 4] & Self-Contained[Bit position 2]
875 constexpr std::bitset<16> compActivationMethod{0x12};
876 // CapabilitiesDuringUpdate of the firmware component
877 // Component downgrade capability [Bit position 2]
878 constexpr std::bitset<32> compCapabilities{0x02};
879
880 constexpr size_t compParamTableSize =
881 sizeof(pldm_component_parameter_entry) + activeCompVersion.size() +
882 pendingCompVersion.size();
883
884 constexpr std::array<uint8_t, compParamTableSize> compParamTable{
885 0x10, 0x00, 0x2c, 0x01, 0x14, 0xAB, 0xEF, 0xCD, 0xAB, 0x01, 0x0e, 0x01,
886 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x78, 0x56, 0x34, 0x12, 0x01,
887 0x0e, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x12, 0x00, 0x02,
888 0x00, 0x00, 0x00, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74,
889 0x72, 0x69, 0x6e, 0x67, 0x33, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
890 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x34};
891
892 constexpr size_t getFwParamsPayloadLen =
893 sizeof(pldm_get_firmware_parameters_resp) +
894 activeCompImageSetVersion.size() + pendingCompImageSetVersion.size() +
895 compParamTableSize;
896
897 constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
898 getFwParamsResponse{
899 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01,
900 0x0e, 0x01, 0x0e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53,
901 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x56, 0x65, 0x72, 0x73, 0x69,
902 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32, 0x10, 0x00,
903 0x2c, 0x01, 0x14, 0xAB, 0xEF, 0xCD, 0xAB, 0x01, 0x0e, 0x01, 0x02,
904 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x78, 0x56, 0x34, 0x12, 0x01,
905 0x0e, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x12, 0x00,
906 0x02, 0x00, 0x00, 0x00, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
907 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x33, 0x56, 0x65, 0x72, 0x73,
908 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x34};
909
910 auto responseMsg =
911 reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
912 pldm_get_firmware_parameters_resp outResp{};
913 variable_field outActiveCompImageSetVersion{};
914 variable_field outPendingCompImageSetVersion{};
915 variable_field outCompParameterTable{};
916
917 auto rc = decode_get_firmware_parameters_resp(
918 responseMsg, getFwParamsPayloadLen, &outResp,
919 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
920 &outCompParameterTable);
921
922 EXPECT_EQ(rc, PLDM_SUCCESS);
923 EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
924 EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
925 EXPECT_EQ(outResp.comp_count, compCount);
926 EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
927 EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
928 activeCompImageSetVersion.size());
929 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
930 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len,
931 pendingCompImageSetVersion.size());
932 std::string activeCompImageSetVersionStr(
933 reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
934 outActiveCompImageSetVersion.length);
935 EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
936 std::string pendingCompImageSetVersionStr(
937 reinterpret_cast<const char*>(outPendingCompImageSetVersion.ptr),
938 outPendingCompImageSetVersion.length);
939 EXPECT_EQ(pendingCompImageSetVersionStr, pendingCompImageSetVersion);
940 EXPECT_EQ(outCompParameterTable.length, compParamTableSize);
941 EXPECT_EQ(true, std::equal(outCompParameterTable.ptr,
942 outCompParameterTable.ptr +
943 outCompParameterTable.length,
944 compParamTable.begin(), compParamTable.end()));
945}
946
947TEST(GetFirmwareParameters, decodeResponseZeroCompCount)
948{
949 // CapabilitiesDuringUpdate of the firmware device
950 // FD Host Functionality during Firmware Update [Bit position 2] &
951 // Component Update Failure Retry Capability [Bit position 1]
952 constexpr std::bitset<32> fdCapabilities{0x06};
953 constexpr uint16_t compCount = 0;
954 constexpr std::string_view activeCompImageSetVersion{"VersionString1"};
955 constexpr std::string_view pendingCompImageSetVersion{"VersionString2"};
956
957 constexpr size_t getFwParamsPayloadLen =
958 sizeof(pldm_get_firmware_parameters_resp) +
959 activeCompImageSetVersion.size() + pendingCompImageSetVersion.size();
960
961 constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
962 getFwParamsResponse{
963 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
964 0x0e, 0x01, 0x0e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53,
965 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x56, 0x65, 0x72, 0x73, 0x69,
966 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32};
967
968 auto responseMsg =
969 reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
970 pldm_get_firmware_parameters_resp outResp{};
971 variable_field outActiveCompImageSetVersion{};
972 variable_field outPendingCompImageSetVersion{};
973 variable_field outCompParameterTable{};
974
975 auto rc = decode_get_firmware_parameters_resp(
976 responseMsg, getFwParamsPayloadLen, &outResp,
977 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
978 &outCompParameterTable);
979
980 EXPECT_EQ(rc, PLDM_SUCCESS);
981 EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
982 EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
983 EXPECT_EQ(outResp.comp_count, compCount);
984 EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
985 EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
986 activeCompImageSetVersion.size());
987 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
988 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len,
989 pendingCompImageSetVersion.size());
990 std::string activeCompImageSetVersionStr(
991 reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
992 outActiveCompImageSetVersion.length);
993 EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
994 std::string pendingCompImageSetVersionStr(
995 reinterpret_cast<const char*>(outPendingCompImageSetVersion.ptr),
996 outPendingCompImageSetVersion.length);
997 EXPECT_EQ(pendingCompImageSetVersionStr, pendingCompImageSetVersion);
998 EXPECT_EQ(outCompParameterTable.ptr, nullptr);
999 EXPECT_EQ(outCompParameterTable.length, 0);
1000}
1001
1002TEST(GetFirmwareParameters,
1003 decodeResponseNoPendingCompImageVersionStrZeroCompCount)
1004{
1005 // CapabilitiesDuringUpdate of the firmware device
1006 // FD Host Functionality during Firmware Update [Bit position 2] &
1007 // Component Update Failure Retry Capability [Bit position 1]
1008 constexpr std::bitset<32> fdCapabilities{0x06};
1009 constexpr uint16_t compCount = 0;
1010 constexpr std::string_view activeCompImageSetVersion{"VersionString"};
1011
1012 constexpr size_t getFwParamsPayloadLen =
1013 sizeof(pldm_get_firmware_parameters_resp) +
1014 activeCompImageSetVersion.size();
1015
1016 constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
1017 getFwParamsResponse{0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
1018 0x00, 0x00, 0x00, 0x01, 0x0d, 0x00, 0x00,
1019 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
1020 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67};
1021
1022 auto responseMsg =
1023 reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
1024 pldm_get_firmware_parameters_resp outResp{};
1025 variable_field outActiveCompImageSetVersion{};
1026 variable_field outPendingCompImageSetVersion{};
1027 variable_field outCompParameterTable{};
1028
1029 auto rc = decode_get_firmware_parameters_resp(
1030 responseMsg, getFwParamsPayloadLen, &outResp,
1031 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1032 &outCompParameterTable);
1033
1034 EXPECT_EQ(rc, PLDM_SUCCESS);
1035 EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
1036 EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
1037 EXPECT_EQ(outResp.comp_count, compCount);
1038 EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
1039 EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
1040 activeCompImageSetVersion.size());
1041 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type,
1042 PLDM_STR_TYPE_UNKNOWN);
1043 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len, 0);
1044 std::string activeCompImageSetVersionStr(
1045 reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
1046 outActiveCompImageSetVersion.length);
1047 EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
1048 EXPECT_EQ(outPendingCompImageSetVersion.ptr, nullptr);
1049 EXPECT_EQ(outPendingCompImageSetVersion.length, 0);
1050 EXPECT_EQ(outCompParameterTable.ptr, nullptr);
1051 EXPECT_EQ(outCompParameterTable.length, 0);
1052}
1053
1054TEST(GetFirmwareParameters, decodeResponseErrorCompletionCode)
1055{
1056 constexpr std::array<uint8_t, hdrSize + sizeof(uint8_t)>
1057 getFwParamsResponse{0x00, 0x00, 0x00, 0x01};
1058
1059 auto responseMsg =
1060 reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
1061 pldm_get_firmware_parameters_resp outResp{};
1062 variable_field outActiveCompImageSetVersion{};
1063 variable_field outPendingCompImageSetVersion{};
1064 variable_field outCompParameterTable{};
1065
1066 auto rc = decode_get_firmware_parameters_resp(
1067 responseMsg, getFwParamsResponse.size(), &outResp,
1068 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1069 &outCompParameterTable);
1070
1071 EXPECT_EQ(rc, PLDM_SUCCESS);
1072 EXPECT_EQ(outResp.completion_code, PLDM_ERROR);
1073}
1074
1075TEST(GetFirmwareParameters, errorPathdecodeResponse)
1076{
1077 int rc = 0;
1078 // Invalid ActiveComponentImageSetVersionStringType
1079 constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse1{
1080 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1081 0x00, 0x00, 0x00, 0x06, 0x0e, 0x00, 0x00};
1082
1083 auto responseMsg =
1084 reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse1.data());
1085 pldm_get_firmware_parameters_resp outResp{};
1086 variable_field outActiveCompImageSetVersion{};
1087 variable_field outPendingCompImageSetVersion{};
1088 variable_field outCompParameterTable{};
1089
1090 rc = decode_get_firmware_parameters_resp(
1091 nullptr, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
1092 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1093 &outCompParameterTable);
1094 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1095
1096 rc = decode_get_firmware_parameters_resp(
1097 responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, nullptr,
1098 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1099 &outCompParameterTable);
1100 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1101
1102 rc = decode_get_firmware_parameters_resp(
1103 responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
1104 nullptr, &outPendingCompImageSetVersion, &outCompParameterTable);
1105 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1106
1107 rc = decode_get_firmware_parameters_resp(
1108 responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
1109 &outActiveCompImageSetVersion, nullptr, &outCompParameterTable);
1110 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1111
1112 rc = decode_get_firmware_parameters_resp(
1113 responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
1114 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion, nullptr);
1115 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1116
1117 rc = decode_get_firmware_parameters_resp(
1118 responseMsg, 0, &outResp, &outActiveCompImageSetVersion,
1119 &outPendingCompImageSetVersion, &outCompParameterTable);
1120 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1121
1122 rc = decode_get_firmware_parameters_resp(
1123 responseMsg, invalidGetFwParamsResponse1.size() - 1 - hdrSize, &outResp,
1124 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1125 &outCompParameterTable);
1126 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1127
1128 rc = decode_get_firmware_parameters_resp(
1129 responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
1130 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1131 &outCompParameterTable);
1132 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1133
1134 // Invalid ActiveComponentImageSetVersionStringLength
1135 constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse2{
1136 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1137 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
1138 responseMsg =
1139 reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse2.data());
1140 rc = decode_get_firmware_parameters_resp(
1141 responseMsg, invalidGetFwParamsResponse2.size() - hdrSize, &outResp,
1142 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1143 &outCompParameterTable);
1144 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1145
1146 // Invalid PendingComponentImageSetVersionStringType &
1147 // PendingComponentImageSetVersionStringLength
1148 constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse3{
1149 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
1150 0x00, 0x00, 0x00, 0x01, 0x0e, 0x01, 0x00};
1151 responseMsg =
1152 reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse3.data());
1153 rc = decode_get_firmware_parameters_resp(
1154 responseMsg, invalidGetFwParamsResponse3.size() - hdrSize, &outResp,
1155 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1156 &outCompParameterTable);
1157 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1158
1159 // Invalid PendingComponentImageSetVersionStringType &
1160 // PendingComponentImageSetVersionStringLength
1161 constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse4{
1162 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
1163 0x00, 0x00, 0x00, 0x01, 0x0e, 0x06, 0x0e};
1164 responseMsg =
1165 reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse4.data());
1166 rc = decode_get_firmware_parameters_resp(
1167 responseMsg, invalidGetFwParamsResponse4.size() - hdrSize, &outResp,
1168 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1169 &outCompParameterTable);
1170 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1171
1172 // Total payload length less than expected
1173 constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse5{
1174 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
1175 0x00, 0x00, 0x00, 0x01, 0x0e, 0x01, 0x0e};
1176 responseMsg =
1177 reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse5.data());
1178 rc = decode_get_firmware_parameters_resp(
1179 responseMsg, invalidGetFwParamsResponse5.size() - hdrSize, &outResp,
1180 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1181 &outCompParameterTable);
1182 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1183}
1184
1185TEST(GetFirmwareParameters, goodPathDecodeComponentParameterEntry)
1186{
1187 // Random value for component classification
1188 constexpr uint16_t compClassification = 0x0A0B;
1189 // Random value for component classification
1190 constexpr uint16_t compIdentifier = 0x0C0D;
1191 // Random value for component classification
1192 constexpr uint32_t timestamp = 0X12345678;
1193 // Random value for component activation methods
1194 constexpr uint16_t compActivationMethods = 0xBBDD;
1195 // Random value for capabilities during update
1196 constexpr uint32_t capabilitiesDuringUpdate = 0xBADBEEFE;
1197
1198 // ActiveCompImageSetVerStrLen is not fixed here taking it as 8
1199 constexpr uint8_t activeCompVerStrLen = 8;
1200 // PendingCompImageSetVerStrLen is not fixed here taking it as 8
1201 constexpr uint8_t pendingCompVerStrLen = 8;
1202 constexpr size_t entryLength =
1203 sizeof(struct pldm_component_parameter_entry) + activeCompVerStrLen +
1204 pendingCompVerStrLen;
1205 std::array<uint8_t, entryLength> entry{};
1206
1207 auto inEntry =
1208 reinterpret_cast<struct pldm_component_parameter_entry*>(entry.data());
1209
1210 inEntry->comp_classification = htole16(compClassification);
1211 inEntry->comp_identifier = htole16(compIdentifier);
1212 inEntry->comp_classification_index = 0x0F;
1213 inEntry->active_comp_comparison_stamp = htole32(timestamp);
1214 inEntry->active_comp_ver_str_type = 1;
1215 inEntry->active_comp_ver_str_len = activeCompVerStrLen;
1216 std::fill_n(inEntry->active_comp_release_date,
1217 sizeof(inEntry->active_comp_release_date), 0xFF);
1218 inEntry->pending_comp_comparison_stamp = htole32(timestamp);
1219 inEntry->pending_comp_ver_str_type = 1;
1220 inEntry->pending_comp_ver_str_len = pendingCompVerStrLen;
1221 std::fill_n(inEntry->pending_comp_release_date,
1222 sizeof(inEntry->pending_comp_release_date), 0xFF);
1223 inEntry->comp_activation_methods.value = htole16(compActivationMethods);
1224 inEntry->capabilities_during_update.value =
1225 htole32(capabilitiesDuringUpdate);
1226 constexpr auto activeCompVerStrPos =
1227 sizeof(struct pldm_component_parameter_entry);
1228 std::fill_n(entry.data() + activeCompVerStrPos, activeCompVerStrLen, 0xAA);
1229 constexpr auto pendingCompVerStrPos =
1230 activeCompVerStrPos + activeCompVerStrLen;
1231 std::fill_n(entry.data() + pendingCompVerStrPos, pendingCompVerStrLen,
1232 0xBB);
1233
1234 struct pldm_component_parameter_entry outEntry;
1235 struct variable_field outActiveCompVerStr;
1236 struct variable_field outPendingCompVerStr;
1237
1238 auto rc = decode_get_firmware_parameters_resp_comp_entry(
1239 entry.data(), entryLength, &outEntry, &outActiveCompVerStr,
1240 &outPendingCompVerStr);
1241
1242 EXPECT_EQ(rc, PLDM_SUCCESS);
1243
1244 EXPECT_EQ(outEntry.comp_classification, compClassification);
1245 EXPECT_EQ(outEntry.comp_identifier, compIdentifier);
1246 EXPECT_EQ(inEntry->comp_classification_index,
1247 outEntry.comp_classification_index);
1248 EXPECT_EQ(outEntry.active_comp_comparison_stamp, timestamp);
1249 EXPECT_EQ(inEntry->active_comp_ver_str_type,
1250 outEntry.active_comp_ver_str_type);
1251 EXPECT_EQ(inEntry->active_comp_ver_str_len,
1252 outEntry.active_comp_ver_str_len);
1253 EXPECT_EQ(0, memcmp(inEntry->active_comp_release_date,
1254 outEntry.active_comp_release_date,
1255 sizeof(inEntry->active_comp_release_date)));
1256 EXPECT_EQ(outEntry.pending_comp_comparison_stamp, timestamp);
1257 EXPECT_EQ(inEntry->pending_comp_ver_str_type,
1258 outEntry.pending_comp_ver_str_type);
1259 EXPECT_EQ(inEntry->pending_comp_ver_str_len,
1260 outEntry.pending_comp_ver_str_len);
1261 EXPECT_EQ(0, memcmp(inEntry->pending_comp_release_date,
1262 outEntry.pending_comp_release_date,
1263 sizeof(inEntry->pending_comp_release_date)));
1264 EXPECT_EQ(outEntry.comp_activation_methods.value, compActivationMethods);
1265 EXPECT_EQ(outEntry.capabilities_during_update.value,
1266 capabilitiesDuringUpdate);
1267
1268 EXPECT_EQ(0, memcmp(outActiveCompVerStr.ptr,
1269 entry.data() + activeCompVerStrPos,
1270 outActiveCompVerStr.length));
1271 EXPECT_EQ(0, memcmp(outPendingCompVerStr.ptr,
1272 entry.data() + pendingCompVerStrPos,
1273 outPendingCompVerStr.length));
1274}
1275
1276TEST(RequestUpdate, goodPathEncodeRequest)
1277{
1278 constexpr uint8_t instanceId = 1;
1279 constexpr uint32_t maxTransferSize = 512;
1280 constexpr uint16_t numOfComp = 3;
1281 constexpr uint8_t maxOutstandingTransferReq = 2;
1282 constexpr uint16_t pkgDataLen = 0x1234;
1283 constexpr std::string_view compImgSetVerStr = "0penBmcv1.0";
1284 constexpr uint8_t compImgSetVerStrLen =
1285 static_cast<uint8_t>(compImgSetVerStr.size());
1286 variable_field compImgSetVerStrInfo{};
1287 compImgSetVerStrInfo.ptr =
1288 reinterpret_cast<const uint8_t*>(compImgSetVerStr.data());
1289 compImgSetVerStrInfo.length = compImgSetVerStrLen;
1290
1291 std::array<uint8_t, hdrSize + sizeof(struct pldm_request_update_req) +
1292 compImgSetVerStrLen>
1293 request{};
1294 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
1295
1296 auto rc = encode_request_update_req(
1297 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1298 pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
1299 &compImgSetVerStrInfo, requestMsg,
1300 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1301 EXPECT_EQ(rc, PLDM_SUCCESS);
1302
1303 std::array<uint8_t, hdrSize + sizeof(struct pldm_request_update_req) +
1304 compImgSetVerStrLen>
1305 outRequest{0x81, 0x05, 0x10, 0x00, 0x02, 0x00, 0x00, 0x03, 0x00,
1306 0x02, 0x34, 0x12, 0x01, 0x0b, 0x30, 0x70, 0x65, 0x6e,
1307 0x42, 0x6d, 0x63, 0x76, 0x31, 0x2e, 0x30};
1308 EXPECT_EQ(request, outRequest);
1309}
1310
1311TEST(RequestUpdate, errorPathEncodeRequest)
1312{
1313 constexpr uint8_t instanceId = 1;
1314 uint32_t maxTransferSize = 512;
1315 constexpr uint16_t numOfComp = 3;
1316 uint8_t maxOutstandingTransferReq = 2;
1317 constexpr uint16_t pkgDataLen = 0x1234;
1318 constexpr std::string_view compImgSetVerStr = "0penBmcv1.0";
1319 uint8_t compImgSetVerStrLen = static_cast<uint8_t>(compImgSetVerStr.size());
1320 variable_field compImgSetVerStrInfo{};
1321 compImgSetVerStrInfo.ptr =
1322 reinterpret_cast<const uint8_t*>(compImgSetVerStr.data());
1323 compImgSetVerStrInfo.length = compImgSetVerStrLen;
1324
1325 std::array<uint8_t, hdrSize + sizeof(struct pldm_request_update_req) +
1326 compImgSetVerStr.size()>
1327 request{};
1328 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
1329
1330 auto rc = encode_request_update_req(
1331 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1332 pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen, nullptr,
1333 requestMsg,
1334 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1335 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1336
1337 compImgSetVerStrInfo.ptr = nullptr;
1338 rc = encode_request_update_req(
1339 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1340 pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
1341 &compImgSetVerStrInfo, requestMsg,
1342 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1343 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1344 compImgSetVerStrInfo.ptr =
1345 reinterpret_cast<const uint8_t*>(compImgSetVerStr.data());
1346
1347 rc = encode_request_update_req(
1348 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1349 pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
1350 &compImgSetVerStrInfo, nullptr,
1351 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1352 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1353
1354 rc = encode_request_update_req(instanceId, maxTransferSize, numOfComp,
1355 maxOutstandingTransferReq, pkgDataLen,
1356 PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
1357 &compImgSetVerStrInfo, requestMsg, 0);
1358 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1359
1360 compImgSetVerStrLen = 0;
1361 rc = encode_request_update_req(
1362 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1363 pkgDataLen, PLDM_STR_TYPE_ASCII, 0, &compImgSetVerStrInfo, nullptr,
1364 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1365 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1366 compImgSetVerStrLen = static_cast<uint8_t>(compImgSetVerStr.size());
1367
1368 compImgSetVerStrInfo.length = 0xFFFF;
1369 rc = encode_request_update_req(
1370 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1371 pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
1372 &compImgSetVerStrInfo, nullptr,
1373 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1374 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1375 compImgSetVerStrInfo.length = compImgSetVerStrLen;
1376
1377 maxTransferSize = PLDM_FWUP_BASELINE_TRANSFER_SIZE - 1;
1378 rc = encode_request_update_req(
1379 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1380 pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
1381 &compImgSetVerStrInfo, nullptr,
1382 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1383 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1384 maxTransferSize = PLDM_FWUP_BASELINE_TRANSFER_SIZE;
1385
1386 maxOutstandingTransferReq = PLDM_FWUP_MIN_OUTSTANDING_REQ - 1;
1387 rc = encode_request_update_req(
1388 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1389 pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
1390 &compImgSetVerStrInfo, nullptr,
1391 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1392 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1393 maxOutstandingTransferReq = PLDM_FWUP_MIN_OUTSTANDING_REQ;
1394
1395 rc = encode_request_update_req(
1396 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1397 pkgDataLen, PLDM_STR_TYPE_UNKNOWN, compImgSetVerStrLen,
1398 &compImgSetVerStrInfo, nullptr,
1399 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1400 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1401}
1402
1403TEST(RequestUpdate, goodPathDecodeResponse)
1404{
1405 constexpr uint16_t fdMetaDataLen = 1024;
1406 constexpr uint8_t fdWillSendPkgData = 1;
1407 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_request_update_resp)>
1408 requestUpdateResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01};
1409
1410 auto responseMsg1 =
1411 reinterpret_cast<const pldm_msg*>(requestUpdateResponse1.data());
1412 uint8_t outCompletionCode = 0;
1413 uint16_t outFdMetaDataLen = 0;
1414 uint8_t outFdWillSendPkgData = 0;
1415
1416 auto rc = decode_request_update_resp(
1417 responseMsg1, requestUpdateResponse1.size() - hdrSize,
1418 &outCompletionCode, &outFdMetaDataLen, &outFdWillSendPkgData);
1419 EXPECT_EQ(rc, PLDM_SUCCESS);
1420 EXPECT_EQ(outCompletionCode, PLDM_SUCCESS);
1421 EXPECT_EQ(outFdMetaDataLen, fdMetaDataLen);
1422 EXPECT_EQ(outFdWillSendPkgData, fdWillSendPkgData);
1423
1424 outCompletionCode = 0;
1425 outFdMetaDataLen = 0;
1426 outFdWillSendPkgData = 0;
1427
1428 constexpr std::array<uint8_t, hdrSize + sizeof(outCompletionCode)>
1429 requestUpdateResponse2{0x00, 0x00, 0x00, 0x81};
1430 auto responseMsg2 =
1431 reinterpret_cast<const pldm_msg*>(requestUpdateResponse2.data());
1432 rc = decode_request_update_resp(
1433 responseMsg2, requestUpdateResponse2.size() - hdrSize,
1434 &outCompletionCode, &outFdMetaDataLen, &outFdWillSendPkgData);
1435 EXPECT_EQ(rc, PLDM_SUCCESS);
1436 EXPECT_EQ(outCompletionCode, PLDM_FWUP_ALREADY_IN_UPDATE_MODE);
1437}
1438
1439TEST(RequestUpdate, errorPathDecodeResponse)
1440{
1441 constexpr std::array<uint8_t,
1442 hdrSize + sizeof(pldm_request_update_resp) - 1>
1443 requestUpdateResponse{0x00, 0x00, 0x00, 0x00, 0x00, 0x04};
1444
1445 auto responseMsg =
1446 reinterpret_cast<const pldm_msg*>(requestUpdateResponse.data());
1447 uint8_t outCompletionCode = 0;
1448 uint16_t outFdMetaDataLen = 0;
1449 uint8_t outFdWillSendPkgData = 0;
1450
1451 auto rc = decode_request_update_resp(
1452 nullptr, requestUpdateResponse.size() - hdrSize, &outCompletionCode,
1453 &outFdMetaDataLen, &outFdWillSendPkgData);
1454 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1455
1456 rc = decode_request_update_resp(
1457 responseMsg, requestUpdateResponse.size() - hdrSize, nullptr,
1458 &outFdMetaDataLen, &outFdWillSendPkgData);
1459 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1460
1461 rc = decode_request_update_resp(
1462 responseMsg, requestUpdateResponse.size() - hdrSize, &outCompletionCode,
1463 nullptr, &outFdWillSendPkgData);
1464 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1465
1466 rc = decode_request_update_resp(
1467 responseMsg, requestUpdateResponse.size() - hdrSize, &outCompletionCode,
1468 &outFdMetaDataLen, nullptr);
1469 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1470
1471 rc = decode_request_update_resp(responseMsg, 0, &outCompletionCode,
1472 &outFdMetaDataLen, &outFdWillSendPkgData);
1473 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1474
1475 rc = decode_request_update_resp(
1476 responseMsg, requestUpdateResponse.size() - hdrSize, &outCompletionCode,
1477 &outFdMetaDataLen, &outFdWillSendPkgData);
1478 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1479}
1480
1481TEST(PassComponentTable, goodPathEncodeRequest)
1482{
1483 constexpr uint8_t instanceId = 1;
1484 constexpr uint16_t compIdentifier = 400;
1485 constexpr uint8_t compClassificationIndex = 40;
1486 constexpr uint32_t compComparisonStamp = 0x12345678;
1487 constexpr std::string_view compVerStr = "0penBmcv1.1";
1488 constexpr uint8_t compVerStrLen = static_cast<uint8_t>(compVerStr.size());
1489 variable_field compVerStrInfo{};
1490 compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
1491 compVerStrInfo.length = compVerStrLen;
1492
1493 std::array<uint8_t,
1494 hdrSize + sizeof(pldm_pass_component_table_req) + compVerStrLen>
1495 request{};
1496 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
1497
1498 auto rc = encode_pass_component_table_req(
1499 instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
1500 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
1501 compVerStrLen, &compVerStrInfo, requestMsg,
1502 sizeof(pldm_pass_component_table_req) + compVerStrLen);
1503 EXPECT_EQ(rc, PLDM_SUCCESS);
1504
1505 std::array<uint8_t,
1506 hdrSize + sizeof(pldm_pass_component_table_req) + compVerStrLen>
1507 outRequest{0x81, 0x05, 0x13, 0x05, 0x0A, 0x00, 0x90, 0x01, 0x28,
1508 0x78, 0x56, 0x34, 0x12, 0x01, 0x0B, 0x30, 0x70, 0x65,
1509 0x6E, 0x42, 0x6D, 0x63, 0x76, 0x31, 0x2E, 0x31};
1510 EXPECT_EQ(request, outRequest);
1511}
1512
1513TEST(PassComponentTable, errorPathEncodeRequest)
1514{
1515 constexpr uint8_t instanceId = 1;
1516 constexpr uint16_t compIdentifier = 400;
1517 constexpr uint8_t compClassificationIndex = 40;
1518 constexpr uint32_t compComparisonStamp = 0x12345678;
1519 constexpr std::string_view compVerStr = "0penBmcv1.1";
1520 constexpr uint8_t compVerStrLen = static_cast<uint8_t>(compVerStr.size());
1521 variable_field compVerStrInfo{};
1522 compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
1523 compVerStrInfo.length = compVerStrLen;
1524
1525 std::array<uint8_t,
1526 hdrSize + sizeof(pldm_pass_component_table_req) + compVerStrLen>
1527 request{};
1528 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
1529
1530 auto rc = encode_pass_component_table_req(
1531 instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
1532 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
1533 compVerStrLen, nullptr, requestMsg,
1534 sizeof(pldm_pass_component_table_req) + compVerStrLen);
1535 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1536
1537 compVerStrInfo.ptr = nullptr;
1538 rc = encode_pass_component_table_req(
1539 instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
1540 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
1541 compVerStrLen, &compVerStrInfo, requestMsg,
1542 sizeof(pldm_pass_component_table_req) + compVerStrLen);
1543 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1544 compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
1545
1546 rc = encode_pass_component_table_req(
1547 instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
1548 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
1549 compVerStrLen, &compVerStrInfo, nullptr,
1550 sizeof(pldm_pass_component_table_req) + compVerStrLen);
1551 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1552
1553 rc = encode_pass_component_table_req(
1554 instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
1555 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
1556 compVerStrLen, &compVerStrInfo, requestMsg,
1557 sizeof(pldm_pass_component_table_req));
1558 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1559
1560 rc = encode_pass_component_table_req(
1561 instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
1562 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII, 0,
1563 &compVerStrInfo, requestMsg,
1564 sizeof(pldm_pass_component_table_req) + compVerStrLen);
1565 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1566
1567 rc = encode_pass_component_table_req(
1568 instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
1569 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
1570 compVerStrLen - 1, &compVerStrInfo, requestMsg,
1571 sizeof(pldm_pass_component_table_req) + compVerStrLen);
1572 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1573
1574 rc = encode_pass_component_table_req(
1575 instanceId, PLDM_START_AND_END + 1, PLDM_COMP_FIRMWARE, compIdentifier,
1576 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
1577 compVerStrLen, &compVerStrInfo, requestMsg,
1578 sizeof(pldm_pass_component_table_req) + compVerStrLen);
1579 EXPECT_EQ(rc, PLDM_INVALID_TRANSFER_OPERATION_FLAG);
1580
1581 rc = encode_pass_component_table_req(
1582 instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
1583 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_UNKNOWN,
1584 compVerStrLen, &compVerStrInfo, requestMsg,
1585 sizeof(pldm_pass_component_table_req) + compVerStrLen);
1586 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1587}
1588
1589TEST(PassComponentTable, goodPathDecodeResponse)
1590{
1591 constexpr std::array<uint8_t,
1592 hdrSize + sizeof(pldm_pass_component_table_resp)>
1593 passCompTableResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
1594 auto responseMsg1 =
1595 reinterpret_cast<const pldm_msg*>(passCompTableResponse1.data());
1596
1597 uint8_t completionCode = 0;
1598 uint8_t compResp = 0;
1599 uint8_t compRespCode = 0;
1600
1601 auto rc = decode_pass_component_table_resp(
1602 responseMsg1, sizeof(pldm_pass_component_table_resp), &completionCode,
1603 &compResp, &compRespCode);
1604
1605 EXPECT_EQ(rc, PLDM_SUCCESS);
1606 EXPECT_EQ(completionCode, PLDM_SUCCESS);
1607 EXPECT_EQ(compResp, PLDM_CR_COMP_CAN_BE_UPDATED);
1608 EXPECT_EQ(compRespCode, PLDM_CRC_COMP_COMPARISON_STAMP_IDENTICAL);
1609
1610 constexpr std::array<uint8_t,
1611 hdrSize + sizeof(pldm_pass_component_table_resp)>
1612 passCompTableResponse2{0x00, 0x00, 0x00, 0x00, 0x00, 0xD0};
1613 auto responseMsg2 =
1614 reinterpret_cast<const pldm_msg*>(passCompTableResponse2.data());
1615 rc = decode_pass_component_table_resp(
1616 responseMsg2, sizeof(pldm_pass_component_table_resp), &completionCode,
1617 &compResp, &compRespCode);
1618
1619 EXPECT_EQ(rc, PLDM_SUCCESS);
1620 EXPECT_EQ(completionCode, PLDM_SUCCESS);
1621 EXPECT_EQ(compResp, PLDM_CR_COMP_CAN_BE_UPDATED);
1622 EXPECT_EQ(compRespCode, PLDM_CRC_VENDOR_COMP_RESP_CODE_RANGE_MIN);
1623
1624 constexpr std::array<uint8_t,
1625 hdrSize + sizeof(pldm_pass_component_table_resp)>
1626 passCompTableResponse3{0x00, 0x00, 0x00, 0x80};
1627 auto responseMsg3 =
1628 reinterpret_cast<const pldm_msg*>(passCompTableResponse3.data());
1629
1630 rc = decode_pass_component_table_resp(
1631 responseMsg3, sizeof(pldm_pass_component_table_resp), &completionCode,
1632 &compResp, &compRespCode);
1633
1634 EXPECT_EQ(rc, PLDM_SUCCESS);
1635 EXPECT_EQ(completionCode, PLDM_FWUP_NOT_IN_UPDATE_MODE);
1636}
1637
1638TEST(PassComponentTable, errorPathDecodeResponse)
1639{
1640 constexpr std::array<uint8_t,
1641 hdrSize + sizeof(pldm_pass_component_table_resp) - 1>
1642 passCompTableResponse1{0x00, 0x00, 0x00, 0x00, 0x00};
1643 auto responseMsg1 =
1644 reinterpret_cast<const pldm_msg*>(passCompTableResponse1.data());
1645
1646 uint8_t completionCode = 0;
1647 uint8_t compResp = 0;
1648 uint8_t compRespCode = 0;
1649
1650 auto rc = decode_pass_component_table_resp(
1651 nullptr, sizeof(pldm_pass_component_table_resp) - 1, &completionCode,
1652 &compResp, &compRespCode);
1653 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1654
1655 rc = decode_pass_component_table_resp(
1656 responseMsg1, sizeof(pldm_pass_component_table_resp) - 1, nullptr,
1657 &compResp, &compRespCode);
1658 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1659
1660 rc = decode_pass_component_table_resp(
1661 responseMsg1, sizeof(pldm_pass_component_table_resp) - 1,
1662 &completionCode, nullptr, &compRespCode);
1663 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1664
1665 rc = decode_pass_component_table_resp(
1666 responseMsg1, sizeof(pldm_pass_component_table_resp) - 1,
1667 &completionCode, &compResp, nullptr);
1668 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1669
1670 rc = decode_pass_component_table_resp(responseMsg1, 0, &completionCode,
1671 &compResp, &compRespCode);
1672 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1673
1674 rc = decode_pass_component_table_resp(
1675 responseMsg1, sizeof(pldm_pass_component_table_resp) - 1,
1676 &completionCode, &compResp, &compRespCode);
1677 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1678
1679 constexpr std::array<uint8_t,
1680 hdrSize + sizeof(pldm_pass_component_table_resp)>
1681 passCompTableResponse2{0x00, 0x00, 0x00, 0x00, 0x02, 0x00};
1682 auto responseMsg2 =
1683 reinterpret_cast<const pldm_msg*>(passCompTableResponse2.data());
1684 rc = decode_pass_component_table_resp(
1685 responseMsg2, sizeof(pldm_pass_component_table_resp), &completionCode,
1686 &compResp, &compRespCode);
1687 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1688
1689 constexpr std::array<uint8_t,
1690 hdrSize + sizeof(pldm_pass_component_table_resp)>
1691 passCompTableResponse3{0x00, 0x00, 0x00, 0x00, 0x00, 0x0C};
1692 auto responseMsg3 =
1693 reinterpret_cast<const pldm_msg*>(passCompTableResponse3.data());
1694 rc = decode_pass_component_table_resp(
1695 responseMsg3, sizeof(pldm_pass_component_table_resp), &completionCode,
1696 &compResp, &compRespCode);
1697 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1698
1699 constexpr std::array<uint8_t,
1700 hdrSize + sizeof(pldm_pass_component_table_resp)>
1701 passCompTableResponse4{0x00, 0x00, 0x00, 0x00, 0x00, 0xF0};
1702 auto responseMsg4 =
1703 reinterpret_cast<const pldm_msg*>(passCompTableResponse4.data());
1704 rc = decode_pass_component_table_resp(
1705 responseMsg4, sizeof(pldm_pass_component_table_resp), &completionCode,
1706 &compResp, &compRespCode);
1707 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1708}
1709
1710TEST(UpdateComponent, goodPathEncodeRequest)
1711{
1712 constexpr uint8_t instanceId = 2;
1713 constexpr uint16_t compIdentifier = 500;
1714 constexpr uint8_t compClassificationIndex = 50;
1715 constexpr uint32_t compComparisonStamp = 0x89ABCDEF;
1716 constexpr uint32_t compImageSize = 4096;
1717 constexpr bitfield32_t updateOptionFlags{1};
1718 constexpr std::string_view compVerStr = "OpenBmcv2.2";
1719 constexpr uint8_t compVerStrLen = static_cast<uint8_t>(compVerStr.size());
1720 variable_field compVerStrInfo{};
1721 compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
1722 compVerStrInfo.length = compVerStrLen;
1723
1724 std::array<uint8_t,
1725 hdrSize + sizeof(pldm_update_component_req) + compVerStrLen>
1726 request{};
1727 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
1728
1729 auto rc = encode_update_component_req(
1730 instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
1731 compComparisonStamp, compImageSize, updateOptionFlags,
1732 PLDM_STR_TYPE_ASCII, compVerStrLen, &compVerStrInfo, requestMsg,
1733 sizeof(pldm_update_component_req) + compVerStrLen);
1734 EXPECT_EQ(rc, PLDM_SUCCESS);
1735
1736 std::array<uint8_t,
1737 hdrSize + sizeof(pldm_update_component_req) + compVerStrLen>
1738 outRequest{0x82, 0x05, 0x14, 0x0A, 0x00, 0xF4, 0x01, 0x32, 0xEF,
1739 0xCD, 0xAB, 0x89, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00,
1740 0x00, 0x00, 0x01, 0x0B, 0x4f, 0x70, 0x65, 0x6E, 0x42,
1741 0x6D, 0x63, 0x76, 0x32, 0x2E, 0x32};
1742 EXPECT_EQ(request, outRequest);
1743}
1744
1745TEST(UpdateComponent, errorPathEncodeRequest)
1746{
1747 constexpr uint8_t instanceId = 2;
1748 constexpr uint16_t compIdentifier = 500;
1749 constexpr uint8_t compClassificationIndex = 50;
1750 constexpr uint32_t compComparisonStamp = 0x89ABCDEF;
1751 constexpr uint32_t compImageSize = 4096;
1752 constexpr bitfield32_t updateOptionFlags{1};
1753 constexpr std::string_view compVerStr = "OpenBmcv2.2";
1754 constexpr uint8_t compVerStrLen = static_cast<uint8_t>(compVerStr.size());
1755 variable_field compVerStrInfo{};
1756 compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
1757 compVerStrInfo.length = compVerStrLen;
1758
1759 std::array<uint8_t,
1760 hdrSize + sizeof(pldm_update_component_req) + compVerStrLen>
1761 request{};
1762 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
1763
1764 auto rc = encode_update_component_req(
1765 instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
1766 compComparisonStamp, compImageSize, updateOptionFlags,
1767 PLDM_STR_TYPE_ASCII, compVerStrLen, nullptr, requestMsg,
1768 sizeof(pldm_update_component_req) + compVerStrLen);
1769 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1770
1771 compVerStrInfo.ptr = nullptr;
1772 rc = encode_update_component_req(
1773 instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
1774 compComparisonStamp, compImageSize, updateOptionFlags,
1775 PLDM_STR_TYPE_ASCII, compVerStrLen, &compVerStrInfo, requestMsg,
1776 sizeof(pldm_update_component_req) + compVerStrLen);
1777 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1778 compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
1779
1780 rc = encode_update_component_req(
1781 instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
1782 compComparisonStamp, compImageSize, updateOptionFlags,
1783 PLDM_STR_TYPE_ASCII, compVerStrLen, &compVerStrInfo, nullptr,
1784 sizeof(pldm_update_component_req) + compVerStrLen);
1785 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1786
1787 rc = encode_update_component_req(
1788 instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
1789 compComparisonStamp, compImageSize, updateOptionFlags,
1790 PLDM_STR_TYPE_ASCII, compVerStrLen, &compVerStrInfo, requestMsg,
1791 sizeof(pldm_update_component_req));
1792 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1793
1794 rc = encode_update_component_req(
1795 instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
1796 compComparisonStamp, 0, updateOptionFlags, PLDM_STR_TYPE_ASCII,
1797 compVerStrLen, &compVerStrInfo, requestMsg,
1798 sizeof(pldm_update_component_req) + compVerStrLen);
1799 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1800
1801 rc = encode_update_component_req(
1802 instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
1803 compComparisonStamp, compImageSize, updateOptionFlags,
1804 PLDM_STR_TYPE_ASCII, 0, &compVerStrInfo, requestMsg,
1805 sizeof(pldm_update_component_req) + compVerStrLen);
1806 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1807
1808 rc = encode_update_component_req(
1809 instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
1810 compComparisonStamp, compImageSize, updateOptionFlags,
1811 PLDM_STR_TYPE_ASCII, compVerStrLen - 1, &compVerStrInfo, requestMsg,
1812 sizeof(pldm_update_component_req) + compVerStrLen);
1813 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1814
1815 rc = encode_update_component_req(
1816 instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex,
1817 compComparisonStamp, compImageSize, updateOptionFlags,
1818 PLDM_STR_TYPE_UNKNOWN, compVerStrLen, &compVerStrInfo, requestMsg,
1819 sizeof(pldm_update_component_req) + compVerStrLen);
1820 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1821}
1822
1823TEST(UpdateComponent, goodPathDecodeResponse)
1824{
1825 constexpr std::bitset<32> forceUpdateComp{1};
1826 constexpr uint16_t timeBeforeSendingReqFwData100s = 100;
1827 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
1828 updateComponentResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1829 0x01, 0x00, 0x00, 0x00, 0x64, 0x00};
1830 auto responseMsg1 =
1831 reinterpret_cast<const pldm_msg*>(updateComponentResponse1.data());
1832
1833 uint8_t completionCode = 0;
1834 uint8_t compCompatibilityResp = 0;
1835 uint8_t compCompatibilityRespCode = 0;
1836 bitfield32_t updateOptionFlagsEnabled{};
1837 uint16_t timeBeforeReqFWData = 0;
1838
1839 auto rc = decode_update_component_resp(
1840 responseMsg1, sizeof(pldm_update_component_resp), &completionCode,
1841 &compCompatibilityResp, &compCompatibilityRespCode,
1842 &updateOptionFlagsEnabled, &timeBeforeReqFWData);
1843
1844 EXPECT_EQ(rc, PLDM_SUCCESS);
1845 EXPECT_EQ(completionCode, PLDM_SUCCESS);
1846 EXPECT_EQ(compCompatibilityResp, PLDM_CCR_COMP_CAN_BE_UPDATED);
1847 EXPECT_EQ(compCompatibilityRespCode, PLDM_CCRC_NO_RESPONSE_CODE);
1848 EXPECT_EQ(updateOptionFlagsEnabled.value, forceUpdateComp);
1849 EXPECT_EQ(timeBeforeReqFWData, timeBeforeSendingReqFwData100s);
1850
1851 constexpr std::bitset<32> noFlags{};
1852 constexpr uint16_t timeBeforeSendingReqFwData0s = 0;
1853 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
1854 updateComponentResponse2{0x00, 0x00, 0x00, 0x00, 0x01, 0x09,
1855 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1856 auto responseMsg2 =
1857 reinterpret_cast<const pldm_msg*>(updateComponentResponse2.data());
1858 rc = decode_update_component_resp(
1859 responseMsg2, sizeof(pldm_update_component_resp), &completionCode,
1860 &compCompatibilityResp, &compCompatibilityRespCode,
1861 &updateOptionFlagsEnabled, &timeBeforeReqFWData);
1862
1863 EXPECT_EQ(rc, PLDM_SUCCESS);
1864 EXPECT_EQ(completionCode, PLDM_SUCCESS);
1865 EXPECT_EQ(compCompatibilityResp, PLDM_CCR_COMP_CANNOT_BE_UPDATED);
1866 EXPECT_EQ(compCompatibilityRespCode, PLDM_CCRC_COMP_INFO_NO_MATCH);
1867 EXPECT_EQ(updateOptionFlagsEnabled.value, noFlags);
1868 EXPECT_EQ(timeBeforeReqFWData, timeBeforeSendingReqFwData0s);
1869
1870 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
1871 updateComponentResponse3{0x00, 0x00, 0x00, 0x80};
1872 auto responseMsg3 =
1873 reinterpret_cast<const pldm_msg*>(updateComponentResponse3.data());
1874
1875 rc = decode_update_component_resp(
1876 responseMsg3, sizeof(pldm_update_component_resp), &completionCode,
1877 &compCompatibilityResp, &compCompatibilityRespCode,
1878 &updateOptionFlagsEnabled, &timeBeforeReqFWData);
1879
1880 EXPECT_EQ(rc, PLDM_SUCCESS);
1881 EXPECT_EQ(completionCode, PLDM_FWUP_NOT_IN_UPDATE_MODE);
1882}
1883
1884TEST(UpdateComponent, errorPathDecodeResponse)
1885{
1886 constexpr std::array<uint8_t,
1887 hdrSize + sizeof(pldm_update_component_resp) - 1>
1888 updateComponentResponse1{0x00, 0x00, 0x00, 0x00, 0x01, 0x09,
1889 0x00, 0x00, 0x00, 0x00, 0x00};
1890 auto responseMsg1 =
1891 reinterpret_cast<const pldm_msg*>(updateComponentResponse1.data());
1892
1893 uint8_t completionCode = 0;
1894 uint8_t compCompatibilityResp = 0;
1895 uint8_t compCompatibilityRespCode = 0;
1896 bitfield32_t updateOptionFlagsEnabled{};
1897 uint16_t timeBeforeReqFWData = 0;
1898
1899 auto rc = decode_update_component_resp(
1900 nullptr, sizeof(pldm_update_component_resp) - 1, &completionCode,
1901 &compCompatibilityResp, &compCompatibilityRespCode,
1902 &updateOptionFlagsEnabled, &timeBeforeReqFWData);
1903 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1904
1905 rc = decode_update_component_resp(
1906 responseMsg1, sizeof(pldm_update_component_resp) - 1, nullptr,
1907 &compCompatibilityResp, &compCompatibilityRespCode,
1908 &updateOptionFlagsEnabled, &timeBeforeReqFWData);
1909 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1910
1911 rc = decode_update_component_resp(
1912 responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode,
1913 nullptr, &compCompatibilityRespCode, &updateOptionFlagsEnabled,
1914 &timeBeforeReqFWData);
1915 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1916
1917 rc = decode_update_component_resp(
1918 responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode,
1919 &compCompatibilityResp, nullptr, &updateOptionFlagsEnabled,
1920 &timeBeforeReqFWData);
1921 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1922
1923 rc = decode_update_component_resp(
1924 responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode,
1925 &compCompatibilityResp, &compCompatibilityRespCode, nullptr,
1926 &timeBeforeReqFWData);
1927 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1928
1929 rc = decode_update_component_resp(
1930 responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode,
1931 &compCompatibilityResp, &compCompatibilityRespCode,
1932 &updateOptionFlagsEnabled, nullptr);
1933 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1934
1935 rc = decode_update_component_resp(
1936 responseMsg1, 0, &completionCode, &compCompatibilityResp,
1937 &compCompatibilityRespCode, &updateOptionFlagsEnabled,
1938 &timeBeforeReqFWData);
1939 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1940
1941 rc = decode_update_component_resp(
1942 responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode,
1943 &compCompatibilityResp, &compCompatibilityRespCode,
1944 &updateOptionFlagsEnabled, &timeBeforeReqFWData);
1945 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1946
1947 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
1948 updateComponentResponse2{0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
1949 0x01, 0x00, 0x00, 0x00, 0x64, 0x00};
1950 auto responseMsg2 =
1951 reinterpret_cast<const pldm_msg*>(updateComponentResponse2.data());
1952 rc = decode_update_component_resp(
1953 responseMsg2, sizeof(pldm_update_component_resp), &completionCode,
1954 &compCompatibilityResp, &compCompatibilityRespCode,
1955 &updateOptionFlagsEnabled, &timeBeforeReqFWData);
1956 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1957
1958 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
1959 updateComponentResponse3{0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
1960 0x01, 0x00, 0x00, 0x00, 0x64, 0x00};
1961 auto responseMsg3 =
1962 reinterpret_cast<const pldm_msg*>(updateComponentResponse3.data());
1963 rc = decode_update_component_resp(
1964 responseMsg3, sizeof(pldm_update_component_resp), &completionCode,
1965 &compCompatibilityResp, &compCompatibilityRespCode,
1966 &updateOptionFlagsEnabled, &timeBeforeReqFWData);
1967 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1968
1969 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)>
1970 updateComponentResponse4{0x00, 0x00, 0x00, 0x00, 0x00, 0xF0,
1971 0x01, 0x00, 0x00, 0x00, 0x64, 0x00};
1972 auto responseMsg4 =
1973 reinterpret_cast<const pldm_msg*>(updateComponentResponse4.data());
1974 rc = decode_update_component_resp(
1975 responseMsg4, sizeof(pldm_update_component_resp), &completionCode,
1976 &compCompatibilityResp, &compCompatibilityRespCode,
1977 &updateOptionFlagsEnabled, &timeBeforeReqFWData);
1978 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1979}
1980
1981TEST(RequestFirmwareData, goodPathDecodeRequest)
1982{
1983 constexpr uint32_t offset = 300;
1984 constexpr uint32_t length = 255;
1985 constexpr std::array<uint8_t,
1986 hdrSize + sizeof(pldm_request_firmware_data_req)>
1987 reqFWDataReq{0x00, 0x00, 0x00, 0x2C, 0x01, 0x00,
1988 0x00, 0xFF, 0x00, 0x00, 0x00};
1989 auto requestMsg = reinterpret_cast<const pldm_msg*>(reqFWDataReq.data());
1990
1991 uint32_t outOffset = 0;
1992 uint32_t outLength = 0;
1993 auto rc = decode_request_firmware_data_req(
1994 requestMsg, sizeof(pldm_request_firmware_data_req), &outOffset,
1995 &outLength);
1996
1997 EXPECT_EQ(rc, PLDM_SUCCESS);
1998 EXPECT_EQ(outOffset, offset);
1999 EXPECT_EQ(outLength, length);
2000}
2001
2002TEST(RequestFirmwareData, errorPathDecodeRequest)
2003{
2004 constexpr std::array<uint8_t,
2005 hdrSize + sizeof(pldm_request_firmware_data_req)>
2006 reqFWDataReq{0x00, 0x00, 0x00, 0x2C, 0x01, 0x00,
2007 0x00, 0x1F, 0x00, 0x00, 0x00};
2008 auto requestMsg = reinterpret_cast<const pldm_msg*>(reqFWDataReq.data());
2009
2010 uint32_t outOffset = 0;
2011 uint32_t outLength = 0;
2012 auto rc = decode_request_firmware_data_req(
2013 nullptr, sizeof(pldm_request_firmware_data_req), &outOffset,
2014 &outLength);
2015 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2016
2017 rc = decode_request_firmware_data_req(
2018 requestMsg, sizeof(pldm_request_firmware_data_req), nullptr,
2019 &outLength);
2020 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2021
2022 rc = decode_request_firmware_data_req(
2023 requestMsg, sizeof(pldm_request_firmware_data_req), &outOffset,
2024 nullptr);
2025 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2026
2027 rc = decode_request_firmware_data_req(
2028 requestMsg, sizeof(pldm_request_firmware_data_req) - 1, &outOffset,
2029 &outLength);
2030 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2031
2032 rc = decode_request_firmware_data_req(
2033 requestMsg, sizeof(pldm_request_firmware_data_req), &outOffset,
2034 &outLength);
2035 EXPECT_EQ(rc, PLDM_FWUP_INVALID_TRANSFER_LENGTH);
2036}
2037
2038TEST(RequestFirmwareData, goodPathEncodeResponse)
2039{
2040 constexpr uint8_t instanceId = 3;
2041 constexpr uint8_t completionCode = PLDM_SUCCESS;
2042 constexpr std::array<uint8_t, hdrSize + sizeof(completionCode) +
2043 PLDM_FWUP_BASELINE_TRANSFER_SIZE>
2044 outReqFwDataResponse1{0x03, 0x05, 0x15, 0x00, 0x01, 0x02, 0x03, 0x04,
2045 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
2046 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14,
2047 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C,
2048 0x1D, 0x1E, 0x1F, 0x20};
2049 std::array<uint8_t, hdrSize + sizeof(completionCode) +
2050 PLDM_FWUP_BASELINE_TRANSFER_SIZE>
2051 reqFwDataResponse1{0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04,
2052 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
2053 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14,
2054 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C,
2055 0x1D, 0x1E, 0x1F, 0x20};
2056 auto responseMsg1 = reinterpret_cast<pldm_msg*>(reqFwDataResponse1.data());
2057 auto rc = encode_request_firmware_data_resp(
2058 instanceId, completionCode, responseMsg1,
2059 sizeof(completionCode) + PLDM_FWUP_BASELINE_TRANSFER_SIZE);
2060 EXPECT_EQ(rc, PLDM_SUCCESS);
2061 EXPECT_EQ(reqFwDataResponse1, outReqFwDataResponse1);
2062
2063 constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
2064 outReqFwDataResponse2{0x03, 0x05, 0x15, 0x82};
2065 std::array<uint8_t, hdrSize + sizeof(completionCode)> reqFwDataResponse2{
2066 0x00, 0x00, 0x00, 0x00};
2067 auto responseMsg2 = reinterpret_cast<pldm_msg*>(reqFwDataResponse2.data());
2068 rc = encode_request_firmware_data_resp(
2069 instanceId, PLDM_FWUP_DATA_OUT_OF_RANGE, responseMsg2,
2070 sizeof(completionCode));
2071 EXPECT_EQ(rc, PLDM_SUCCESS);
2072 EXPECT_EQ(reqFwDataResponse2, outReqFwDataResponse2);
2073}
2074
2075TEST(RequestFirmwareData, errorPathEncodeResponse)
2076{
2077 std::array<uint8_t, hdrSize> reqFwDataResponse{0x00, 0x00, 0x00};
2078 auto responseMsg = reinterpret_cast<pldm_msg*>(reqFwDataResponse.data());
2079 auto rc = encode_request_firmware_data_resp(0, PLDM_SUCCESS, nullptr, 0);
2080 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2081
2082 rc = encode_request_firmware_data_resp(0, PLDM_SUCCESS, responseMsg, 0);
2083 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2084}
2085
2086TEST(TransferComplete, goodPathDecodeRequest)
2087{
2088 constexpr uint8_t transferResult = PLDM_FWUP_TRANSFER_SUCCESS;
2089 constexpr std::array<uint8_t, hdrSize + sizeof(transferResult)>
2090 transferCompleteReq1{0x00, 0x00, 0x00, 0x00};
2091 auto requestMsg1 =
2092 reinterpret_cast<const pldm_msg*>(transferCompleteReq1.data());
2093 uint8_t outTransferResult = 0;
2094
2095 auto rc = decode_transfer_complete_req(requestMsg1, sizeof(transferResult),
2096 &outTransferResult);
2097 EXPECT_EQ(rc, PLDM_SUCCESS);
2098 EXPECT_EQ(outTransferResult, transferResult);
2099
2100 constexpr std::array<uint8_t, hdrSize + sizeof(transferResult)>
2101 transferCompleteReq2{0x00, 0x00, 0x00, 0x02};
2102 auto requestMsg2 =
2103 reinterpret_cast<const pldm_msg*>(transferCompleteReq2.data());
2104 rc = decode_transfer_complete_req(requestMsg2, sizeof(transferResult),
2105 &outTransferResult);
2106 EXPECT_EQ(rc, PLDM_SUCCESS);
2107 EXPECT_EQ(outTransferResult, PLDM_FWUP_TRANSFER_ERROR_IMAGE_CORRUPT);
2108}
2109
2110TEST(TransferComplete, errorPathDecodeRequest)
2111{
2112 constexpr std::array<uint8_t, hdrSize> transferCompleteReq{0x00, 0x00,
2113 0x00};
2114 auto requestMsg =
2115 reinterpret_cast<const pldm_msg*>(transferCompleteReq.data());
2116 uint8_t outTransferResult = 0;
2117
2118 auto rc = decode_transfer_complete_req(nullptr, 0, &outTransferResult);
2119 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2120
2121 rc = decode_transfer_complete_req(requestMsg, 0, nullptr);
2122 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2123
2124 rc = decode_transfer_complete_req(requestMsg, 0, &outTransferResult);
2125 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2126}
2127
2128TEST(TransferComplete, goodPathEncodeResponse)
2129{
2130 constexpr uint8_t instanceId = 4;
2131 constexpr uint8_t completionCode = PLDM_SUCCESS;
2132 constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
2133 outTransferCompleteResponse1{0x04, 0x05, 0x16, 0x00};
2134 std::array<uint8_t, hdrSize + sizeof(completionCode)>
2135 transferCompleteResponse1{0x00, 0x00, 0x00, 0x00};
2136 auto responseMsg1 =
2137 reinterpret_cast<pldm_msg*>(transferCompleteResponse1.data());
2138 auto rc = encode_transfer_complete_resp(
2139 instanceId, completionCode, responseMsg1, sizeof(completionCode));
2140 EXPECT_EQ(rc, PLDM_SUCCESS);
2141 EXPECT_EQ(transferCompleteResponse1, outTransferCompleteResponse1);
2142
2143 constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
2144 outTransferCompleteResponse2{0x04, 0x05, 0x16, 0x88};
2145 std::array<uint8_t, hdrSize + sizeof(completionCode)>
2146 transferCompleteResponse2{0x00, 0x00, 0x00, 0x00};
2147 auto responseMsg2 =
2148 reinterpret_cast<pldm_msg*>(transferCompleteResponse2.data());
2149 rc = encode_transfer_complete_resp(instanceId,
2150 PLDM_FWUP_COMMAND_NOT_EXPECTED,
2151 responseMsg2, sizeof(completionCode));
2152 EXPECT_EQ(rc, PLDM_SUCCESS);
2153 EXPECT_EQ(transferCompleteResponse2, outTransferCompleteResponse2);
2154}
2155
2156TEST(TransferComplete, errorPathEncodeResponse)
2157{
2158 std::array<uint8_t, hdrSize> transferCompleteResponse{0x00, 0x00, 0x00};
2159 auto responseMsg =
2160 reinterpret_cast<pldm_msg*>(transferCompleteResponse.data());
2161 auto rc = encode_transfer_complete_resp(0, PLDM_SUCCESS, nullptr, 0);
2162 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2163
2164 rc = encode_transfer_complete_resp(0, PLDM_SUCCESS, responseMsg, 0);
2165 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2166}
2167
2168TEST(VerifyComplete, goodPathDecodeRequest)
2169{
2170 constexpr uint8_t verifyResult = PLDM_FWUP_VERIFY_SUCCESS;
2171 constexpr std::array<uint8_t, hdrSize + sizeof(verifyResult)>
2172 verifyCompleteReq1{0x00, 0x00, 0x00, 0x00};
2173 auto requestMsg1 =
2174 reinterpret_cast<const pldm_msg*>(verifyCompleteReq1.data());
2175 uint8_t outVerifyResult = 0;
2176
2177 auto rc = decode_verify_complete_req(requestMsg1, sizeof(verifyResult),
2178 &outVerifyResult);
2179 EXPECT_EQ(rc, PLDM_SUCCESS);
2180 EXPECT_EQ(outVerifyResult, verifyResult);
2181
2182 constexpr std::array<uint8_t, hdrSize + sizeof(verifyResult)>
2183 verifyCompleteReq2{0x00, 0x00, 0x00, 0x03};
2184 auto requestMsg2 =
2185 reinterpret_cast<const pldm_msg*>(verifyCompleteReq2.data());
2186 rc = decode_verify_complete_req(requestMsg2, sizeof(verifyResult),
2187 &outVerifyResult);
2188 EXPECT_EQ(rc, PLDM_SUCCESS);
2189 EXPECT_EQ(outVerifyResult, PLDM_FWUP_VERIFY_FAILED_FD_SECURITY_CHECKS);
2190}
2191
2192TEST(VerifyComplete, errorPathDecodeRequest)
2193{
2194 constexpr std::array<uint8_t, hdrSize> verifyCompleteReq{0x00, 0x00, 0x00};
2195 auto requestMsg =
2196 reinterpret_cast<const pldm_msg*>(verifyCompleteReq.data());
2197 uint8_t outVerifyResult = 0;
2198
2199 auto rc = decode_verify_complete_req(nullptr, 0, &outVerifyResult);
2200 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2201
2202 rc = decode_verify_complete_req(requestMsg, 0, nullptr);
2203 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2204
2205 rc = decode_verify_complete_req(requestMsg, 0, &outVerifyResult);
2206 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2207}
2208
2209TEST(VerifyComplete, goodPathEncodeResponse)
2210{
2211 constexpr uint8_t instanceId = 5;
2212 constexpr uint8_t completionCode = PLDM_SUCCESS;
2213 constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
2214 outVerifyCompleteResponse1{0x05, 0x05, 0x17, 0x00};
2215 std::array<uint8_t, hdrSize + sizeof(completionCode)>
2216 verifyCompleteResponse1{0x00, 0x00, 0x00, 0x00};
2217 auto responseMsg1 =
2218 reinterpret_cast<pldm_msg*>(verifyCompleteResponse1.data());
2219 auto rc = encode_verify_complete_resp(instanceId, completionCode,
2220 responseMsg1, sizeof(completionCode));
2221 EXPECT_EQ(rc, PLDM_SUCCESS);
2222 EXPECT_EQ(verifyCompleteResponse1, outVerifyCompleteResponse1);
2223
2224 constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
2225 outVerifyCompleteResponse2{0x05, 0x05, 0x17, 0x88};
2226 std::array<uint8_t, hdrSize + sizeof(completionCode)>
2227 verifyCompleteResponse2{0x00, 0x00, 0x00, 0x00};
2228 auto responseMsg2 =
2229 reinterpret_cast<pldm_msg*>(verifyCompleteResponse2.data());
2230 rc = encode_verify_complete_resp(instanceId, PLDM_FWUP_COMMAND_NOT_EXPECTED,
2231 responseMsg2, sizeof(completionCode));
2232 EXPECT_EQ(rc, PLDM_SUCCESS);
2233 EXPECT_EQ(verifyCompleteResponse2, outVerifyCompleteResponse2);
2234}
2235
2236TEST(VerifyComplete, errorPathEncodeResponse)
2237{
2238 std::array<uint8_t, hdrSize> verifyCompleteResponse{0x00, 0x00, 0x00};
2239 auto responseMsg =
2240 reinterpret_cast<pldm_msg*>(verifyCompleteResponse.data());
2241 auto rc = encode_verify_complete_resp(0, PLDM_SUCCESS, nullptr, 0);
2242 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2243
2244 rc = encode_verify_complete_resp(0, PLDM_SUCCESS, responseMsg, 0);
2245 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2246}
2247
2248TEST(ApplyComplete, goodPathDecodeRequest)
2249{
2250 constexpr uint8_t applyResult1 =
2251 PLDM_FWUP_APPLY_SUCCESS_WITH_ACTIVATION_METHOD;
2252 // DC power cycle [Bit position 4] & AC power cycle [Bit position 5]
2253 constexpr std::bitset<16> compActivationModification1{0x30};
2254 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_apply_complete_req)>
2255 applyCompleteReq1{0x00, 0x00, 0x00, 0x01, 0x30, 0x00};
2256 auto requestMsg1 =
2257 reinterpret_cast<const pldm_msg*>(applyCompleteReq1.data());
2258 uint8_t outApplyResult = 0;
2259 bitfield16_t outCompActivationModification{};
2260 auto rc = decode_apply_complete_req(
2261 requestMsg1, sizeof(pldm_apply_complete_req), &outApplyResult,
2262 &outCompActivationModification);
2263 EXPECT_EQ(rc, PLDM_SUCCESS);
2264 EXPECT_EQ(outApplyResult, applyResult1);
2265 EXPECT_EQ(outCompActivationModification.value, compActivationModification1);
2266
2267 constexpr uint8_t applyResult2 = PLDM_FWUP_APPLY_SUCCESS;
2268 constexpr std::bitset<16> compActivationModification2{};
2269 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_apply_complete_req)>
2270 applyCompleteReq2{0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
2271 auto requestMsg2 =
2272 reinterpret_cast<const pldm_msg*>(applyCompleteReq2.data());
2273 rc = decode_apply_complete_req(requestMsg2, sizeof(pldm_apply_complete_req),
2274 &outApplyResult,
2275 &outCompActivationModification);
2276 EXPECT_EQ(rc, PLDM_SUCCESS);
2277 EXPECT_EQ(outApplyResult, applyResult2);
2278 EXPECT_EQ(outCompActivationModification.value, compActivationModification2);
2279}
2280
2281TEST(ApplyComplete, errorPathDecodeRequest)
2282{
2283 constexpr std::array<uint8_t, hdrSize> applyCompleteReq1{0x00, 0x00, 0x00};
2284 auto requestMsg1 =
2285 reinterpret_cast<const pldm_msg*>(applyCompleteReq1.data());
2286 uint8_t outApplyResult = 0;
2287 bitfield16_t outCompActivationModification{};
2288
2289 auto rc = decode_apply_complete_req(
2290 nullptr, sizeof(pldm_apply_complete_req), &outApplyResult,
2291 &outCompActivationModification);
2292 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2293
2294 rc = decode_apply_complete_req(requestMsg1, sizeof(pldm_apply_complete_req),
2295 nullptr, &outCompActivationModification);
2296 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2297
2298 rc = decode_apply_complete_req(requestMsg1, sizeof(pldm_apply_complete_req),
2299 &outApplyResult, nullptr);
2300 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2301
2302 rc = decode_apply_complete_req(requestMsg1, 0, &outApplyResult,
2303 &outCompActivationModification);
2304 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2305
2306 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_apply_complete_req)>
2307 applyCompleteReq2{0x00, 0x00, 0x00, 0x00, 0x01, 0x00};
2308 auto requestMsg2 =
2309 reinterpret_cast<const pldm_msg*>(applyCompleteReq2.data());
2310 rc = decode_apply_complete_req(requestMsg2, sizeof(pldm_apply_complete_req),
2311 &outApplyResult,
2312 &outCompActivationModification);
2313 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2314}
2315
2316TEST(ApplyComplete, goodPathEncodeResponse)
2317{
2318 constexpr uint8_t instanceId = 6;
2319 constexpr uint8_t completionCode = PLDM_SUCCESS;
2320 constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
2321 outApplyCompleteResponse1{0x06, 0x05, 0x18, 0x00};
2322 std::array<uint8_t, hdrSize + sizeof(completionCode)>
2323 applyCompleteResponse1{0x00, 0x00, 0x00, 0x00};
2324 auto responseMsg1 =
2325 reinterpret_cast<pldm_msg*>(applyCompleteResponse1.data());
2326 auto rc = encode_apply_complete_resp(instanceId, completionCode,
2327 responseMsg1, sizeof(completionCode));
2328 EXPECT_EQ(rc, PLDM_SUCCESS);
2329 EXPECT_EQ(applyCompleteResponse1, outApplyCompleteResponse1);
2330
2331 constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
2332 outApplyCompleteResponse2{0x06, 0x05, 0x18, 0x88};
2333 std::array<uint8_t, hdrSize + sizeof(completionCode)>
2334 applyCompleteResponse2{0x00, 0x00, 0x00, 0x00};
2335 auto responseMsg2 =
2336 reinterpret_cast<pldm_msg*>(applyCompleteResponse2.data());
2337 rc = encode_apply_complete_resp(instanceId, PLDM_FWUP_COMMAND_NOT_EXPECTED,
2338 responseMsg2, sizeof(completionCode));
2339 EXPECT_EQ(rc, PLDM_SUCCESS);
2340 EXPECT_EQ(applyCompleteResponse2, outApplyCompleteResponse2);
2341}
2342
2343TEST(ApplyComplete, errorPathEncodeResponse)
2344{
2345 std::array<uint8_t, hdrSize> applyCompleteResponse{0x00, 0x00, 0x00};
2346 auto responseMsg =
2347 reinterpret_cast<pldm_msg*>(applyCompleteResponse.data());
2348 auto rc = encode_apply_complete_resp(0, PLDM_SUCCESS, nullptr, 0);
2349 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2350
2351 rc = encode_apply_complete_resp(0, PLDM_SUCCESS, responseMsg, 0);
2352 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2353}
2354
2355TEST(ActivateFirmware, goodPathEncodeRequest)
2356{
2357 constexpr uint8_t instanceId = 7;
2358
2359 std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_req)> request{};
2360 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
2361
2362 auto rc = encode_activate_firmware_req(
2363 instanceId, PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS, requestMsg,
2364 sizeof(pldm_activate_firmware_req));
2365 EXPECT_EQ(rc, PLDM_SUCCESS);
2366
2367 std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_req)>
2368 outRequest{0x87, 0x05, 0x1A, 0x01};
2369 EXPECT_EQ(request, outRequest);
2370}
2371
2372TEST(ActivateFirmware, errorPathEncodeRequest)
2373{
2374 std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_req)> request{};
2375 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
2376
2377 auto rc = encode_activate_firmware_req(
2378 0, PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS, nullptr,
2379 sizeof(pldm_activate_firmware_req));
2380 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2381
2382 rc = encode_activate_firmware_req(
2383 0, PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS, requestMsg, 0);
2384 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2385
2386 rc = encode_activate_firmware_req(0, 2, requestMsg,
2387 sizeof(pldm_activate_firmware_req));
2388 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2389}
2390
2391TEST(ActivateFirmware, goodPathDecodeResponse)
2392{
2393 constexpr uint16_t estimatedTimeForActivation100s = 100;
2394 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_resp)>
2395 activateFirmwareResponse1{0x00, 0x00, 0x00, 0x00, 0x64, 0x00};
2396 auto responseMsg1 =
2397 reinterpret_cast<const pldm_msg*>(activateFirmwareResponse1.data());
2398
2399 uint8_t completionCode = 0;
2400 uint16_t estimatedTimeForActivation = 0;
2401
2402 auto rc = decode_activate_firmware_resp(
2403 responseMsg1, sizeof(pldm_activate_firmware_resp), &completionCode,
2404 &estimatedTimeForActivation);
2405
2406 EXPECT_EQ(rc, PLDM_SUCCESS);
2407 EXPECT_EQ(completionCode, PLDM_SUCCESS);
2408 EXPECT_EQ(estimatedTimeForActivation, estimatedTimeForActivation100s);
2409
2410 constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
2411 activateFirmwareResponse2{0x00, 0x00, 0x00, 0x85};
2412 auto responseMsg2 =
2413 reinterpret_cast<const pldm_msg*>(activateFirmwareResponse2.data());
2414
2415 rc = decode_activate_firmware_resp(responseMsg2, sizeof(completionCode),
2416 &completionCode,
2417 &estimatedTimeForActivation);
2418
2419 EXPECT_EQ(rc, PLDM_SUCCESS);
2420 EXPECT_EQ(completionCode, PLDM_FWUP_INCOMPLETE_UPDATE);
2421}
2422
2423TEST(ActivateFirmware, errorPathDecodeResponse)
2424{
2425 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_resp)>
2426 activateFirmwareResponse{0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
2427 auto responseMsg =
2428 reinterpret_cast<const pldm_msg*>(activateFirmwareResponse.data());
2429
2430 uint8_t completionCode = 0;
2431 uint16_t estimatedTimeForActivation = 0;
2432
2433 auto rc = decode_activate_firmware_resp(
2434 nullptr, sizeof(pldm_activate_firmware_resp), &completionCode,
2435 &estimatedTimeForActivation);
2436 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2437
2438 rc = decode_activate_firmware_resp(responseMsg,
2439 sizeof(pldm_activate_firmware_resp),
2440 nullptr, &estimatedTimeForActivation);
2441 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2442
2443 rc = decode_activate_firmware_resp(responseMsg,
2444 sizeof(pldm_activate_firmware_resp),
2445 &completionCode, nullptr);
2446 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2447
2448 rc = decode_activate_firmware_resp(responseMsg, 0, &completionCode,
2449 &estimatedTimeForActivation);
2450 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2451
2452 rc = decode_activate_firmware_resp(
2453 responseMsg, sizeof(pldm_activate_firmware_resp) - 1, &completionCode,
2454 &estimatedTimeForActivation);
2455 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2456}
2457
2458TEST(GetStatus, goodPathEncodeRequest)
2459{
2460 constexpr uint8_t instanceId = 8;
2461 std::array<uint8_t, hdrSize> request{};
2462 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
2463
2464 auto rc = encode_get_status_req(instanceId, requestMsg,
2465 PLDM_GET_STATUS_REQ_BYTES);
2466 EXPECT_EQ(rc, PLDM_SUCCESS);
2467
2468 constexpr std::array<uint8_t, hdrSize> outRequest{0x88, 0x05, 0x1B};
2469 EXPECT_EQ(request, outRequest);
2470}
2471
2472TEST(GetStatus, errorPathEncodeRequest)
2473{
2474 std::array<uint8_t, hdrSize + sizeof(uint8_t)> request{};
2475 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
2476
2477 auto rc = encode_get_status_req(0, nullptr, PLDM_GET_STATUS_REQ_BYTES);
2478 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2479
2480 rc = encode_get_status_req(0, requestMsg, PLDM_GET_STATUS_REQ_BYTES + 1);
2481 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2482}
2483
2484TEST(GetStatus, goodPathDecodeResponse)
2485{
2486 constexpr std::bitset<32> updateOptionFlagsEnabled1{0};
2487 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
2488 getStatusResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03,
2489 0x09, 0x65, 0x05, 0x00, 0x00, 0x00, 0x00};
2490 auto responseMsg1 =
2491 reinterpret_cast<const pldm_msg*>(getStatusResponse1.data());
2492
2493 uint8_t completionCode = 0;
2494 uint8_t currentState = 0;
2495 uint8_t previousState = 0;
2496 uint8_t auxState = 0;
2497 uint8_t auxStateStatus = 0;
2498 uint8_t progressPercent = 0;
2499 uint8_t reasonCode = 0;
2500 bitfield32_t updateOptionFlagsEnabled{0};
2501
2502 auto rc = decode_get_status_resp(
2503 responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
2504 &currentState, &previousState, &auxState, &auxStateStatus,
2505 &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
2506
2507 EXPECT_EQ(rc, PLDM_SUCCESS);
2508 EXPECT_EQ(completionCode, PLDM_SUCCESS);
2509 EXPECT_EQ(currentState, PLDM_FD_STATE_IDLE);
2510 EXPECT_EQ(previousState, PLDM_FD_STATE_DOWNLOAD);
2511 EXPECT_EQ(auxState, PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER);
2512 EXPECT_EQ(auxStateStatus, PLDM_FD_TIMEOUT);
2513 EXPECT_EQ(progressPercent, PLDM_FWUP_MAX_PROGRESS_PERCENT);
2514 EXPECT_EQ(reasonCode, PLDM_FD_TIMEOUT_DOWNLOAD);
2515 EXPECT_EQ(updateOptionFlagsEnabled.value, updateOptionFlagsEnabled1);
2516
2517 // Bit position 0 - Force update of component – FD will perform a force
2518 // update of the component.
2519 constexpr std::bitset<32> updateOptionFlagsEnabled2{1};
2520 constexpr uint8_t progressPercent2 = 50;
2521 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
2522 getStatusResponse2{0x00, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00,
2523 0x70, 0x32, 0x05, 0x01, 0x00, 0x00, 0x00};
2524 auto responseMsg2 =
2525 reinterpret_cast<const pldm_msg*>(getStatusResponse2.data());
2526
2527 rc = decode_get_status_resp(
2528 responseMsg2, getStatusResponse2.size() - hdrSize, &completionCode,
2529 &currentState, &previousState, &auxState, &auxStateStatus,
2530 &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
2531
2532 EXPECT_EQ(rc, PLDM_SUCCESS);
2533 EXPECT_EQ(completionCode, PLDM_SUCCESS);
2534 EXPECT_EQ(currentState, PLDM_FD_STATE_VERIFY);
2535 EXPECT_EQ(previousState, PLDM_FD_STATE_DOWNLOAD);
2536 EXPECT_EQ(auxState, PLDM_FD_OPERATION_IN_PROGRESS);
2537 EXPECT_EQ(auxStateStatus, PLDM_FD_VENDOR_DEFINED_STATUS_CODE_START);
2538 EXPECT_EQ(progressPercent, progressPercent2);
2539 EXPECT_EQ(reasonCode, PLDM_FD_TIMEOUT_DOWNLOAD);
2540 EXPECT_EQ(updateOptionFlagsEnabled.value, updateOptionFlagsEnabled2);
2541
2542 constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
2543 getStatusResponse3{0x00, 0x00, 0x00, 0x04};
2544 auto responseMsg3 =
2545 reinterpret_cast<const pldm_msg*>(getStatusResponse3.data());
2546 rc = decode_get_status_resp(
2547 responseMsg3, getStatusResponse3.size() - hdrSize, &completionCode,
2548 &currentState, &previousState, &auxState, &auxStateStatus,
2549 &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
2550 EXPECT_EQ(rc, PLDM_SUCCESS);
2551 EXPECT_EQ(completionCode, PLDM_ERROR_NOT_READY);
2552}
2553
2554TEST(GetStatus, errorPathDecodeResponse)
2555{
2556 uint8_t completionCode = 0;
2557 uint8_t currentState = 0;
2558 uint8_t previousState = 0;
2559 uint8_t auxState = 0;
2560 uint8_t auxStateStatus = 0;
2561 uint8_t progressPercent = 0;
2562 uint8_t reasonCode = 0;
2563 bitfield32_t updateOptionFlagsEnabled{0};
2564
2565 constexpr std::array<uint8_t, hdrSize> getStatusResponse1{0x00, 0x00, 0x00};
2566 auto responseMsg1 =
2567 reinterpret_cast<const pldm_msg*>(getStatusResponse1.data());
2568
2569 auto rc = decode_get_status_resp(
2570 nullptr, getStatusResponse1.size() - hdrSize, &completionCode,
2571 &currentState, &previousState, &auxState, &auxStateStatus,
2572 &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
2573 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2574
2575 rc = decode_get_status_resp(
2576 responseMsg1, getStatusResponse1.size() - hdrSize, nullptr,
2577 &currentState, &previousState, &auxState, &auxStateStatus,
2578 &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
2579 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2580
2581 rc = decode_get_status_resp(
2582 responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
2583 nullptr, &previousState, &auxState, &auxStateStatus, &progressPercent,
2584 &reasonCode, &updateOptionFlagsEnabled);
2585 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2586
2587 rc = decode_get_status_resp(
2588 responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
2589 &currentState, nullptr, &auxState, &auxStateStatus, &progressPercent,
2590 &reasonCode, &updateOptionFlagsEnabled);
2591 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2592
2593 rc = decode_get_status_resp(
2594 responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
2595 &currentState, &previousState, nullptr, &auxStateStatus,
2596 &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
2597 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2598
2599 rc = decode_get_status_resp(
2600 responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
2601 &currentState, &previousState, &auxState, nullptr, &progressPercent,
2602 &reasonCode, &updateOptionFlagsEnabled);
2603 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2604
2605 rc = decode_get_status_resp(
2606 responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
2607 &currentState, &previousState, &auxState, &auxStateStatus, nullptr,
2608 &reasonCode, &updateOptionFlagsEnabled);
2609 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2610
2611 rc = decode_get_status_resp(
2612 responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
2613 &currentState, &previousState, &auxState, &auxStateStatus,
2614 &progressPercent, nullptr, &updateOptionFlagsEnabled);
2615 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2616
2617 rc = decode_get_status_resp(
2618 responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
2619 &currentState, &previousState, &auxState, &auxStateStatus,
2620 &progressPercent, &reasonCode, nullptr);
2621 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2622
2623 rc = decode_get_status_resp(
2624 responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode,
2625 &currentState, &previousState, &auxState, &auxStateStatus,
2626 &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
2627 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2628
2629 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp) - 1>
2630 getStatusResponse2{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2631 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
2632 auto responseMsg2 =
2633 reinterpret_cast<const pldm_msg*>(getStatusResponse2.data());
2634 rc = decode_get_status_resp(
2635 responseMsg2, getStatusResponse2.size() - hdrSize, &completionCode,
2636 &currentState, &previousState, &auxState, &auxStateStatus,
2637 &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
2638 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2639
2640 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
2641 getStatusResponse3{0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
2642 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
2643 auto responseMsg3 =
2644 reinterpret_cast<const pldm_msg*>(getStatusResponse3.data());
2645 rc = decode_get_status_resp(
2646 responseMsg3, getStatusResponse3.size() - hdrSize, &completionCode,
2647 &currentState, &previousState, &auxState, &auxStateStatus,
2648 &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
2649 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2650
2651 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
2652 getStatusResponse4{0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
2653 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
2654 auto responseMsg4 =
2655 reinterpret_cast<const pldm_msg*>(getStatusResponse4.data());
2656 rc = decode_get_status_resp(
2657 responseMsg4, getStatusResponse4.size() - hdrSize, &completionCode,
2658 &currentState, &previousState, &auxState, &auxStateStatus,
2659 &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
2660 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2661
2662 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
2663 getStatusResponse5{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
2664 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
2665 auto responseMsg5 =
2666 reinterpret_cast<const pldm_msg*>(getStatusResponse5.data());
2667 rc = decode_get_status_resp(
2668 responseMsg5, getStatusResponse5.size() - hdrSize, &completionCode,
2669 &currentState, &previousState, &auxState, &auxStateStatus,
2670 &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
2671 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2672
2673 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
2674 getStatusResponse6{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2675 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
2676 auto responseMsg6 =
2677 reinterpret_cast<const pldm_msg*>(getStatusResponse6.data());
2678 rc = decode_get_status_resp(
2679 responseMsg6, getStatusResponse6.size() - hdrSize, &completionCode,
2680 &currentState, &previousState, &auxState, &auxStateStatus,
2681 &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
2682 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2683
2684 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
2685 getStatusResponse7{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2686 0x00, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00};
2687 auto responseMsg7 =
2688 reinterpret_cast<const pldm_msg*>(getStatusResponse7.data());
2689 rc = decode_get_status_resp(
2690 responseMsg7, getStatusResponse7.size() - hdrSize, &completionCode,
2691 &currentState, &previousState, &auxState, &auxStateStatus,
2692 &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
2693 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2694
2695 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
2696 getStatusResponse8{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2697 0x00, 0x00, 0xC7, 0x00, 0x00, 0x00, 0x00};
2698 auto responseMsg8 =
2699 reinterpret_cast<const pldm_msg*>(getStatusResponse8.data());
2700 rc = decode_get_status_resp(
2701 responseMsg8, getStatusResponse8.size() - hdrSize, &completionCode,
2702 &currentState, &previousState, &auxState, &auxStateStatus,
2703 &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
2704 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2705
2706 // AuxState is not PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER when the state is
2707 // IDLE
2708 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)>
2709 getStatusResponse9{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
2710 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
2711 auto responseMsg9 =
2712 reinterpret_cast<const pldm_msg*>(getStatusResponse9.data());
2713 rc = decode_get_status_resp(
2714 responseMsg9, getStatusResponse9.size() - hdrSize, &completionCode,
2715 &currentState, &previousState, &auxState, &auxStateStatus,
2716 &progressPercent, &reasonCode, &updateOptionFlagsEnabled);
2717 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2718}
2719
2720TEST(CancelUpdateComponent, goodPathEncodeRequest)
2721{
2722 constexpr uint8_t instanceId = 9;
2723 std::array<uint8_t, hdrSize> request{};
2724 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
2725
2726 auto rc = encode_cancel_update_component_req(
2727 instanceId, requestMsg, PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES);
2728 EXPECT_EQ(rc, PLDM_SUCCESS);
2729
2730 constexpr std::array<uint8_t, hdrSize> outRequest{0x89, 0x05, 0x1C};
2731 EXPECT_EQ(request, outRequest);
2732}
2733
2734TEST(CancelUpdateComponent, errorPathEncodeRequest)
2735{
2736 std::array<uint8_t, hdrSize + sizeof(uint8_t)> request{};
2737 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
2738
2739 auto rc = encode_cancel_update_component_req(
2740 0, nullptr, PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES);
2741 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2742
2743 rc = encode_cancel_update_component_req(
2744 0, requestMsg, PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES + 1);
2745 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2746}
2747
2748TEST(CancelUpdateComponent, testGoodDecodeResponse)
2749{
2750 uint8_t completionCode = 0;
2751 constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
2752 cancelUpdateComponentResponse1{0x00, 0x00, 0x00, 0x00};
2753 auto responseMsg1 = reinterpret_cast<const pldm_msg*>(
2754 cancelUpdateComponentResponse1.data());
2755 auto rc = decode_cancel_update_component_resp(
2756 responseMsg1, cancelUpdateComponentResponse1.size() - hdrSize,
2757 &completionCode);
2758 EXPECT_EQ(rc, PLDM_SUCCESS);
2759 EXPECT_EQ(completionCode, PLDM_SUCCESS);
2760
2761 constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
2762 cancelUpdateComponentResponse2{0x00, 0x00, 0x00, 0x86};
2763 auto responseMsg2 = reinterpret_cast<const pldm_msg*>(
2764 cancelUpdateComponentResponse2.data());
2765 rc = decode_cancel_update_component_resp(
2766 responseMsg2, cancelUpdateComponentResponse2.size() - hdrSize,
2767 &completionCode);
2768 EXPECT_EQ(rc, PLDM_SUCCESS);
2769 EXPECT_EQ(completionCode, PLDM_FWUP_BUSY_IN_BACKGROUND);
2770}
2771
2772TEST(CancelUpdateComponent, testBadDecodeResponse)
2773{
2774 uint8_t completionCode = 0;
2775 constexpr std::array<uint8_t, hdrSize> cancelUpdateComponentResponse{
2776 0x00, 0x00, 0x00};
2777 auto responseMsg =
2778 reinterpret_cast<const pldm_msg*>(cancelUpdateComponentResponse.data());
2779
2780 auto rc = decode_cancel_update_component_resp(
2781 nullptr, cancelUpdateComponentResponse.size() - hdrSize,
2782 &completionCode);
2783 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2784
2785 rc = decode_cancel_update_component_resp(
2786 responseMsg, cancelUpdateComponentResponse.size() - hdrSize, nullptr);
2787 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2788
2789 rc = decode_cancel_update_component_resp(
2790 responseMsg, cancelUpdateComponentResponse.size() - hdrSize,
2791 &completionCode);
2792 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2793}
2794
2795TEST(CancelUpdate, goodPathEncodeRequest)
2796{
2797 constexpr uint8_t instanceId = 10;
2798 std::array<uint8_t, hdrSize> request{};
2799 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
2800
2801 auto rc = encode_cancel_update_req(instanceId, requestMsg,
2802 PLDM_CANCEL_UPDATE_REQ_BYTES);
2803 EXPECT_EQ(rc, PLDM_SUCCESS);
2804
2805 constexpr std::array<uint8_t, hdrSize> outRequest{0x8A, 0x05, 0x1D};
2806 EXPECT_EQ(request, outRequest);
2807}
2808
2809TEST(CancelUpdate, errorPathEncodeRequest)
2810{
2811 std::array<uint8_t, hdrSize + sizeof(uint8_t)> request{};
2812 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
2813
2814 auto rc =
2815 encode_cancel_update_req(0, nullptr, PLDM_CANCEL_UPDATE_REQ_BYTES);
2816 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2817
2818 rc = encode_cancel_update_req(0, requestMsg,
2819 PLDM_CANCEL_UPDATE_REQ_BYTES + 1);
2820 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2821}
2822
2823TEST(CancelUpdate, goodPathDecodeResponse)
2824{
2825 constexpr std::bitset<64> nonFunctioningComponentBitmap1{0};
2826 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_cancel_update_resp)>
2827 cancelUpdateResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2828 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
2829 auto responseMsg1 =
2830 reinterpret_cast<const pldm_msg*>(cancelUpdateResponse1.data());
2831 uint8_t completionCode = 0;
2832 bool8_t nonFunctioningComponentIndication = 0;
2833 bitfield64_t nonFunctioningComponentBitmap{0};
2834 auto rc = decode_cancel_update_resp(
2835 responseMsg1, cancelUpdateResponse1.size() - hdrSize, &completionCode,
2836 &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
2837 EXPECT_EQ(rc, PLDM_SUCCESS);
2838 EXPECT_EQ(completionCode, PLDM_SUCCESS);
2839 EXPECT_EQ(nonFunctioningComponentIndication,
2840 PLDM_FWUP_COMPONENTS_FUNCTIONING);
2841 EXPECT_EQ(nonFunctioningComponentBitmap.value,
2842 nonFunctioningComponentBitmap1);
2843
2844 constexpr std::bitset<64> nonFunctioningComponentBitmap2{0x0101};
2845 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_cancel_update_resp)>
2846 cancelUpdateResponse2{0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
2847 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
2848 auto responseMsg2 =
2849 reinterpret_cast<const pldm_msg*>(cancelUpdateResponse2.data());
2850 rc = decode_cancel_update_resp(
2851 responseMsg2, cancelUpdateResponse2.size() - hdrSize, &completionCode,
2852 &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
2853 EXPECT_EQ(rc, PLDM_SUCCESS);
2854 EXPECT_EQ(completionCode, PLDM_SUCCESS);
2855 EXPECT_EQ(nonFunctioningComponentIndication,
2856 PLDM_FWUP_COMPONENTS_NOT_FUNCTIONING);
2857 EXPECT_EQ(nonFunctioningComponentBitmap.value,
2858 nonFunctioningComponentBitmap2);
2859
2860 constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
2861 cancelUpdateResponse3{0x00, 0x00, 0x00, 0x86};
2862 auto responseMsg3 =
2863 reinterpret_cast<const pldm_msg*>(cancelUpdateResponse3.data());
2864 rc = decode_cancel_update_resp(
2865 responseMsg3, cancelUpdateResponse3.size() - hdrSize, &completionCode,
2866 &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
2867 EXPECT_EQ(rc, PLDM_SUCCESS);
2868 EXPECT_EQ(completionCode, PLDM_FWUP_BUSY_IN_BACKGROUND);
2869}
2870
2871TEST(CancelUpdate, errorPathDecodeResponse)
2872{
2873 constexpr std::array<uint8_t, hdrSize> cancelUpdateResponse1{0x00, 0x00,
2874 0x00};
2875 auto responseMsg1 =
2876 reinterpret_cast<const pldm_msg*>(cancelUpdateResponse1.data());
2877 uint8_t completionCode = 0;
2878 bool8_t nonFunctioningComponentIndication = 0;
2879 bitfield64_t nonFunctioningComponentBitmap{0};
2880
2881 auto rc = decode_cancel_update_resp(
2882 nullptr, cancelUpdateResponse1.size() - hdrSize, &completionCode,
2883 &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
2884 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2885
2886 rc = decode_cancel_update_resp(
2887 responseMsg1, cancelUpdateResponse1.size() - hdrSize, nullptr,
2888 &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
2889 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2890
2891 rc = decode_cancel_update_resp(
2892 responseMsg1, cancelUpdateResponse1.size() - hdrSize, &completionCode,
2893 nullptr, &nonFunctioningComponentBitmap);
2894 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2895
2896 rc = decode_cancel_update_resp(
2897 responseMsg1, cancelUpdateResponse1.size() - hdrSize, &completionCode,
2898 &nonFunctioningComponentIndication, nullptr);
2899 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2900
2901 rc = decode_cancel_update_resp(
2902 responseMsg1, cancelUpdateResponse1.size() - hdrSize, &completionCode,
2903 &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
2904 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2905
2906 constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)>
2907 cancelUpdateResponse2{0x00, 0x00, 0x00, 0x00};
2908 auto responseMsg2 =
2909 reinterpret_cast<const pldm_msg*>(cancelUpdateResponse2.data());
2910 rc = decode_cancel_update_resp(
2911 responseMsg2, cancelUpdateResponse2.size() - hdrSize, &completionCode,
2912 &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
2913 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2914
2915 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_cancel_update_resp)>
2916 cancelUpdateResponse3{0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
2917 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
2918 auto responseMsg3 =
2919 reinterpret_cast<const pldm_msg*>(cancelUpdateResponse3.data());
2920 rc = decode_cancel_update_resp(
2921 responseMsg3, cancelUpdateResponse3.size() - hdrSize, &completionCode,
2922 &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap);
2923 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2924}