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