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