blob: 091f8bb05b73ec58998d2567b4914565b8bb18c6 [file] [log] [blame]
Tom Joseph3fd3eb82021-06-18 04:13:29 -07001#include <bitset>
Tom Joseph763b51e2021-06-05 04:50:47 -07002#include <cstring>
3
gokulsanker138ceba2021-04-05 13:25:25 +05304#include "libpldm/base.h"
5#include "libpldm/firmware_update.h"
6
7#include <gtest/gtest.h>
8
9constexpr auto hdrSize = sizeof(pldm_msg_hdr);
10
Tom Joseph568e4702021-06-07 22:15:49 -070011TEST(DecodePackageHeaderInfo, goodPath)
12{
13 // Package header identifier for Version 1.0.x
14 constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
15 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43,
16 0x98, 0x00, 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02};
17 // Package header version for DSP0267 version 1.0.x
18 constexpr uint8_t pkgHeaderFormatRevision = 0x01;
19 // Random PackageHeaderSize
20 constexpr uint16_t pkgHeaderSize = 303;
21 // PackageReleaseDateTime - "25/12/2021 00:00:00"
22 std::array<uint8_t, PLDM_TIMESTAMP104_SIZE> timestamp104{
23 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
24 0x00, 0x19, 0x0c, 0xe5, 0x07, 0x00};
25 constexpr uint16_t componentBitmapBitLength = 8;
26 // PackageVersionString
27 constexpr std::string_view packageVersionStr{"OpenBMCv1.0"};
28 constexpr size_t packagerHeaderSize =
29 sizeof(pldm_package_header_information) + packageVersionStr.size();
30
31 constexpr std::array<uint8_t, packagerHeaderSize> packagerHeaderInfo{
32 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00, 0xa0, 0x2F,
33 0x05, 0x9a, 0xca, 0x02, 0x01, 0x2f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
34 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5, 0x07, 0x00, 0x08, 0x00, 0x01, 0x0b,
35 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
36 pldm_package_header_information pkgHeader{};
37 variable_field packageVersion{};
38
39 auto rc = decode_pldm_package_header_info(packagerHeaderInfo.data(),
40 packagerHeaderInfo.size(),
41 &pkgHeader, &packageVersion);
42
43 EXPECT_EQ(rc, PLDM_SUCCESS);
44 EXPECT_EQ(true,
45 std::equal(pkgHeader.uuid, pkgHeader.uuid + PLDM_FWUP_UUID_LENGTH,
46 uuid.begin(), uuid.end()));
47 EXPECT_EQ(pkgHeader.package_header_format_version, pkgHeaderFormatRevision);
48 EXPECT_EQ(pkgHeader.package_header_size, pkgHeaderSize);
49 EXPECT_EQ(true, std::equal(pkgHeader.timestamp104,
50 pkgHeader.timestamp104 + PLDM_TIMESTAMP104_SIZE,
51 timestamp104.begin(), timestamp104.end()));
52 EXPECT_EQ(pkgHeader.component_bitmap_bit_length, componentBitmapBitLength);
53 EXPECT_EQ(pkgHeader.package_version_string_type, PLDM_STR_TYPE_ASCII);
54 EXPECT_EQ(pkgHeader.package_version_string_length,
55 packageVersionStr.size());
56 std::string packageVersionString(
57 reinterpret_cast<const char*>(packageVersion.ptr),
58 packageVersion.length);
59 EXPECT_EQ(packageVersionString, packageVersionStr);
60}
61
62TEST(DecodePackageHeaderInfo, errorPaths)
63{
64 int rc = 0;
65 constexpr std::string_view packageVersionStr{"OpenBMCv1.0"};
66 constexpr size_t packagerHeaderSize =
67 sizeof(pldm_package_header_information) + packageVersionStr.size();
68
69 // Invalid Package Version String Type - 0x06
70 constexpr std::array<uint8_t, packagerHeaderSize>
71 invalidPackagerHeaderInfo1{
72 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
73 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
74 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
75 0x07, 0x00, 0x08, 0x00, 0x06, 0x0b, 0x4f, 0x70, 0x65, 0x6e,
76 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
77
78 pldm_package_header_information packageHeader{};
79 variable_field packageVersion{};
80
81 rc = decode_pldm_package_header_info(nullptr,
82 invalidPackagerHeaderInfo1.size(),
83 &packageHeader, &packageVersion);
84 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
85
86 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo1.data(),
87 invalidPackagerHeaderInfo1.size(),
88 nullptr, &packageVersion);
89 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
90
91 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo1.data(),
92 invalidPackagerHeaderInfo1.size(),
93 &packageHeader, nullptr);
94 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
95
96 rc = decode_pldm_package_header_info(
97 invalidPackagerHeaderInfo1.data(),
98 sizeof(pldm_package_header_information) - 1, &packageHeader,
99 &packageVersion);
100 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
101
102 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo1.data(),
103 invalidPackagerHeaderInfo1.size(),
104 &packageHeader, &packageVersion);
105 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
106
107 // Invalid Package Version String Length - 0x00
108 constexpr std::array<uint8_t, packagerHeaderSize>
109 invalidPackagerHeaderInfo2{
110 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
111 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
112 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
113 0x07, 0x00, 0x08, 0x00, 0x01, 0x00, 0x4f, 0x70, 0x65, 0x6e,
114 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
115 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo2.data(),
116 invalidPackagerHeaderInfo2.size(),
117 &packageHeader, &packageVersion);
118 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
119
120 // Package version string length less than in the header information
121 constexpr std::array<uint8_t, packagerHeaderSize - 1>
122 invalidPackagerHeaderInfo3{
123 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
124 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
126 0x07, 0x00, 0x08, 0x00, 0x01, 0x0b, 0x4f, 0x70, 0x65, 0x6e,
127 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e};
128 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo3.data(),
129 invalidPackagerHeaderInfo3.size(),
130 &packageHeader, &packageVersion);
131 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
132
133 // ComponentBitmapBitLength not a multiple of 8
134 constexpr std::array<uint8_t, packagerHeaderSize>
135 invalidPackagerHeaderInfo4{
136 0xf0, 0x18, 0x87, 0x8c, 0xcb, 0x7d, 0x49, 0x43, 0x98, 0x00,
137 0xa0, 0x2F, 0x05, 0x9a, 0xca, 0x02, 0x02, 0x2f, 0x01, 0x00,
138 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x0c, 0xe5,
139 0x07, 0x00, 0x09, 0x00, 0x01, 0x0b, 0x4f, 0x70, 0x65, 0x6e,
140 0x42, 0x4d, 0x43, 0x76, 0x31, 0x2e, 0x30};
141 rc = decode_pldm_package_header_info(invalidPackagerHeaderInfo4.data(),
142 invalidPackagerHeaderInfo4.size(),
143 &packageHeader, &packageVersion);
144 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
145}
146
Tom Joseph64af3452021-06-08 04:05:28 -0700147TEST(DecodeFirmwareDeviceIdRecord, goodPath)
148{
149 constexpr uint8_t descriptorCount = 1;
150 // Continue component updates after failure
151 constexpr std::bitset<32> deviceUpdateFlag{1};
152 constexpr uint16_t componentBitmapBitLength = 16;
153 // Applicable Components - 1,2,5,8,9
154 std::vector<std::bitset<8>> applicableComponentsBitfield{0x93, 0x01};
155 // ComponentImageSetVersionString
156 constexpr std::string_view imageSetVersionStr{"VersionString1"};
157 // Initial descriptor - UUID
158 constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
159 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
160 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
161 constexpr uint16_t fwDevicePkgDataLen = 2;
162 // FirmwareDevicePackageData
163 constexpr std::array<uint8_t, fwDevicePkgDataLen> fwDevicePkgData{0xab,
164 0xcd};
165 // Size of the firmware device ID record
166 constexpr uint16_t recordLen =
167 sizeof(pldm_firmware_device_id_record) +
168 (componentBitmapBitLength / PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE) +
169 imageSetVersionStr.size() + sizeof(pldm_descriptor_tlv) - 1 +
170 uuid.size() + fwDevicePkgData.size();
171 // Firmware device ID record
172 constexpr std::array<uint8_t, recordLen> record{
173 0x31, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x02,
174 0x00, 0x93, 0x01, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
175 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x02, 0x00, 0x10,
176 0x00, 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18, 0xa0,
177 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b, 0xab, 0xcd};
178
179 pldm_firmware_device_id_record deviceIdRecHeader{};
180 variable_field applicableComponents{};
181 variable_field outCompImageSetVersionStr{};
182 variable_field recordDescriptors{};
183 variable_field outFwDevicePkgData{};
184
185 auto rc = decode_firmware_device_id_record(
186 record.data(), record.size(), componentBitmapBitLength,
187 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
188 &recordDescriptors, &outFwDevicePkgData);
189
190 EXPECT_EQ(rc, PLDM_SUCCESS);
191 EXPECT_EQ(deviceIdRecHeader.record_length, recordLen);
192 EXPECT_EQ(deviceIdRecHeader.descriptor_count, descriptorCount);
193 EXPECT_EQ(deviceIdRecHeader.device_update_option_flags.value,
194 deviceUpdateFlag);
195 EXPECT_EQ(deviceIdRecHeader.comp_image_set_version_string_type,
196 PLDM_STR_TYPE_ASCII);
197 EXPECT_EQ(deviceIdRecHeader.comp_image_set_version_string_length,
198 imageSetVersionStr.size());
199 EXPECT_EQ(deviceIdRecHeader.fw_device_pkg_data_length, fwDevicePkgDataLen);
200
201 EXPECT_EQ(applicableComponents.length, applicableComponentsBitfield.size());
202 EXPECT_EQ(true,
203 std::equal(applicableComponents.ptr,
204 applicableComponents.ptr + applicableComponents.length,
205 applicableComponentsBitfield.begin(),
206 applicableComponentsBitfield.end()));
207
208 EXPECT_EQ(outCompImageSetVersionStr.length, imageSetVersionStr.size());
209 std::string compImageSetVersionStr(
210 reinterpret_cast<const char*>(outCompImageSetVersionStr.ptr),
211 outCompImageSetVersionStr.length);
212 EXPECT_EQ(compImageSetVersionStr, imageSetVersionStr);
213
214 uint16_t descriptorType = 0;
215 uint16_t descriptorLen = 0;
216 variable_field descriptorData{};
217 // DescriptorCount is 1, so decode_descriptor_type_length_value called once
218 rc = decode_descriptor_type_length_value(recordDescriptors.ptr,
219 recordDescriptors.length,
220 &descriptorType, &descriptorData);
221 EXPECT_EQ(rc, PLDM_SUCCESS);
222 EXPECT_EQ(recordDescriptors.length, sizeof(descriptorType) +
223 sizeof(descriptorLen) +
224 descriptorData.length);
225 EXPECT_EQ(descriptorType, PLDM_FWUP_UUID);
226 EXPECT_EQ(descriptorData.length, PLDM_FWUP_UUID_LENGTH);
227 EXPECT_EQ(true, std::equal(descriptorData.ptr,
228 descriptorData.ptr + descriptorData.length,
229 uuid.begin(), uuid.end()));
230
231 EXPECT_EQ(outFwDevicePkgData.length, fwDevicePkgData.size());
232 EXPECT_EQ(true,
233 std::equal(outFwDevicePkgData.ptr,
234 outFwDevicePkgData.ptr + outFwDevicePkgData.length,
235 fwDevicePkgData.begin(), fwDevicePkgData.end()));
236}
237
238TEST(DecodeFirmwareDeviceIdRecord, goodPathNofwDevicePkgData)
239{
240 constexpr uint8_t descriptorCount = 1;
241 // Continue component updates after failure
242 constexpr std::bitset<32> deviceUpdateFlag{1};
243 constexpr uint16_t componentBitmapBitLength = 8;
244 // Applicable Components - 1,2
245 std::vector<std::bitset<8>> applicableComponentsBitfield{0x03};
246 // ComponentImageSetVersionString
247 constexpr std::string_view imageSetVersionStr{"VersionString1"};
248 // Initial descriptor - UUID
249 constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
250 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
251 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
252 constexpr uint16_t fwDevicePkgDataLen = 0;
253
254 // Size of the firmware device ID record
255 constexpr uint16_t recordLen =
256 sizeof(pldm_firmware_device_id_record) +
257 (componentBitmapBitLength / PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE) +
258 imageSetVersionStr.size() +
259 sizeof(pldm_descriptor_tlv().descriptor_type) +
260 sizeof(pldm_descriptor_tlv().descriptor_length) + uuid.size() +
261 fwDevicePkgDataLen;
262 // Firmware device ID record
263 constexpr std::array<uint8_t, recordLen> record{
264 0x2e, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x00, 0x00, 0x03,
265 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e,
266 0x67, 0x31, 0x02, 0x00, 0x10, 0x00, 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d,
267 0x47, 0x18, 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
268
269 pldm_firmware_device_id_record deviceIdRecHeader{};
270 variable_field applicableComponents{};
271 variable_field outCompImageSetVersionStr{};
272 variable_field recordDescriptors{};
273 variable_field outFwDevicePkgData{};
274
275 auto rc = decode_firmware_device_id_record(
276 record.data(), record.size(), componentBitmapBitLength,
277 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
278 &recordDescriptors, &outFwDevicePkgData);
279
280 EXPECT_EQ(rc, PLDM_SUCCESS);
281 EXPECT_EQ(deviceIdRecHeader.record_length, recordLen);
282 EXPECT_EQ(deviceIdRecHeader.descriptor_count, descriptorCount);
283 EXPECT_EQ(deviceIdRecHeader.device_update_option_flags.value,
284 deviceUpdateFlag);
285 EXPECT_EQ(deviceIdRecHeader.comp_image_set_version_string_type,
286 PLDM_STR_TYPE_ASCII);
287 EXPECT_EQ(deviceIdRecHeader.comp_image_set_version_string_length,
288 imageSetVersionStr.size());
289 EXPECT_EQ(deviceIdRecHeader.fw_device_pkg_data_length, 0);
290
291 EXPECT_EQ(applicableComponents.length, applicableComponentsBitfield.size());
292 EXPECT_EQ(true,
293 std::equal(applicableComponents.ptr,
294 applicableComponents.ptr + applicableComponents.length,
295 applicableComponentsBitfield.begin(),
296 applicableComponentsBitfield.end()));
297
298 EXPECT_EQ(outCompImageSetVersionStr.length, imageSetVersionStr.size());
299 std::string compImageSetVersionStr(
300 reinterpret_cast<const char*>(outCompImageSetVersionStr.ptr),
301 outCompImageSetVersionStr.length);
302 EXPECT_EQ(compImageSetVersionStr, imageSetVersionStr);
303
304 uint16_t descriptorType = 0;
305 uint16_t descriptorLen = 0;
306 variable_field descriptorData{};
307 // DescriptorCount is 1, so decode_descriptor_type_length_value called once
308 rc = decode_descriptor_type_length_value(recordDescriptors.ptr,
309 recordDescriptors.length,
310 &descriptorType, &descriptorData);
311 EXPECT_EQ(rc, PLDM_SUCCESS);
312 EXPECT_EQ(recordDescriptors.length, sizeof(descriptorType) +
313 sizeof(descriptorLen) +
314 descriptorData.length);
315 EXPECT_EQ(descriptorType, PLDM_FWUP_UUID);
316 EXPECT_EQ(descriptorData.length, PLDM_FWUP_UUID_LENGTH);
317 EXPECT_EQ(true, std::equal(descriptorData.ptr,
318 descriptorData.ptr + descriptorData.length,
319 uuid.begin(), uuid.end()));
320
321 EXPECT_EQ(outFwDevicePkgData.ptr, nullptr);
322 EXPECT_EQ(outFwDevicePkgData.length, 0);
323}
324
325TEST(DecodeFirmwareDeviceIdRecord, ErrorPaths)
326{
327 constexpr uint16_t componentBitmapBitLength = 8;
328 // Invalid ComponentImageSetVersionStringType
329 constexpr std::array<uint8_t, 11> invalidRecord1{
330 0x0b, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x06, 0x0e, 0x00, 0x00};
331
332 int rc = 0;
333 pldm_firmware_device_id_record deviceIdRecHeader{};
334 variable_field applicableComponents{};
335 variable_field outCompImageSetVersionStr{};
336 variable_field recordDescriptors{};
337 variable_field outFwDevicePkgData{};
338
339 rc = decode_firmware_device_id_record(
340 nullptr, invalidRecord1.size(), componentBitmapBitLength,
341 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
342 &recordDescriptors, &outFwDevicePkgData);
343 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
344
345 rc = decode_firmware_device_id_record(
346 invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
347 nullptr, &applicableComponents, &outCompImageSetVersionStr,
348 &recordDescriptors, &outFwDevicePkgData);
349 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
350
351 rc = decode_firmware_device_id_record(
352 invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
353 &deviceIdRecHeader, nullptr, &outCompImageSetVersionStr,
354 &recordDescriptors, &outFwDevicePkgData);
355 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
356
357 rc = decode_firmware_device_id_record(
358 invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
359 &deviceIdRecHeader, &applicableComponents, nullptr, &recordDescriptors,
360 &outFwDevicePkgData);
361 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
362
363 rc = decode_firmware_device_id_record(
364 invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
365 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
366 nullptr, &outFwDevicePkgData);
367 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
368
369 rc = decode_firmware_device_id_record(
370 invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
371 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
372 &recordDescriptors, nullptr);
373 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
374
375 rc = decode_firmware_device_id_record(
376 invalidRecord1.data(), invalidRecord1.size() - 1,
377 componentBitmapBitLength, &deviceIdRecHeader, &applicableComponents,
378 &outCompImageSetVersionStr, &recordDescriptors, &outFwDevicePkgData);
379 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
380
381 rc = decode_firmware_device_id_record(
382 invalidRecord1.data(), invalidRecord1.size(),
383 componentBitmapBitLength + 1, &deviceIdRecHeader, &applicableComponents,
384 &outCompImageSetVersionStr, &recordDescriptors, &outFwDevicePkgData);
385 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
386
387 rc = decode_firmware_device_id_record(
388 invalidRecord1.data(), invalidRecord1.size(), componentBitmapBitLength,
389 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
390 &recordDescriptors, &outFwDevicePkgData);
391 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
392
393 // Invalid ComponentImageSetVersionStringLength
394 constexpr std::array<uint8_t, 11> invalidRecord2{
395 0x0b, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
396 rc = decode_firmware_device_id_record(
397 invalidRecord2.data(), invalidRecord2.size(), componentBitmapBitLength,
398 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
399 &recordDescriptors, &outFwDevicePkgData);
400 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
401
402 // invalidRecord3 size is less than RecordLength
403 constexpr std::array<uint8_t, 11> invalidRecord3{
404 0x2e, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x00, 0x00};
405 rc = decode_firmware_device_id_record(
406 invalidRecord3.data(), invalidRecord3.size(), componentBitmapBitLength,
407 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
408 &recordDescriptors, &outFwDevicePkgData);
409 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
410
411 // RecordLength is less than the calculated RecordLength
412 constexpr std::array<uint8_t, 11> invalidRecord4{
413 0x15, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x02, 0x00};
414 rc = decode_firmware_device_id_record(
415 invalidRecord4.data(), invalidRecord4.size(), componentBitmapBitLength,
416 &deviceIdRecHeader, &applicableComponents, &outCompImageSetVersionStr,
417 &recordDescriptors, &outFwDevicePkgData);
418 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
419}
420
Tom Joseph763b51e2021-06-05 04:50:47 -0700421TEST(DecodeDescriptors, goodPath3Descriptors)
422{
423 // In the descriptor data there are 3 descriptor entries
424 // 1) IANA enterprise ID
425 constexpr std::array<uint8_t, PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH> iana{
426 0x0a, 0x0b, 0x0c, 0xd};
427 // 2) UUID
428 constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
429 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
430 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
431 // 3) Vendor Defined
432 constexpr std::string_view vendorTitle{"OpenBMC"};
433 constexpr size_t vendorDescriptorLen = 2;
434 constexpr std::array<uint8_t, vendorDescriptorLen> vendorDescriptorData{
435 0x01, 0x02};
436
437 constexpr size_t vendorDefinedDescriptorLen =
438 sizeof(pldm_vendor_defined_descriptor_title_data()
439 .vendor_defined_descriptor_title_str_type) +
440 sizeof(pldm_vendor_defined_descriptor_title_data()
441 .vendor_defined_descriptor_title_str_len) +
442 vendorTitle.size() + vendorDescriptorData.size();
443
444 constexpr size_t descriptorsLength =
445 3 * (sizeof(pldm_descriptor_tlv().descriptor_type) +
446 sizeof(pldm_descriptor_tlv().descriptor_length)) +
447 iana.size() + uuid.size() + vendorDefinedDescriptorLen;
448
449 constexpr std::array<uint8_t, descriptorsLength> descriptors{
450 0x01, 0x00, 0x04, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x02, 0x00, 0x10,
451 0x00, 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18, 0xa0, 0x30,
452 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b, 0xFF, 0xFF, 0x0B, 0x00, 0x01,
453 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43, 0x01, 0x02};
454
455 size_t descriptorCount = 1;
456 size_t descriptorsRemainingLength = descriptorsLength;
457 int rc = 0;
458
459 while (descriptorsRemainingLength && (descriptorCount <= 3))
460 {
461 uint16_t descriptorType = 0;
462 uint16_t descriptorLen = 0;
463 variable_field descriptorData{};
464
465 rc = decode_descriptor_type_length_value(
466 descriptors.data() + descriptorsLength - descriptorsRemainingLength,
467 descriptorsRemainingLength, &descriptorType, &descriptorData);
468 EXPECT_EQ(rc, PLDM_SUCCESS);
469
470 if (descriptorCount == 1)
471 {
472 EXPECT_EQ(descriptorType, PLDM_FWUP_IANA_ENTERPRISE_ID);
473 EXPECT_EQ(descriptorData.length,
474 PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH);
475 EXPECT_EQ(true,
476 std::equal(descriptorData.ptr,
477 descriptorData.ptr + descriptorData.length,
478 iana.begin(), iana.end()));
479 }
480 else if (descriptorCount == 2)
481 {
482 EXPECT_EQ(descriptorType, PLDM_FWUP_UUID);
483 EXPECT_EQ(descriptorData.length, PLDM_FWUP_UUID_LENGTH);
484 EXPECT_EQ(true,
485 std::equal(descriptorData.ptr,
486 descriptorData.ptr + descriptorData.length,
487 uuid.begin(), uuid.end()));
488 }
489 else if (descriptorCount == 3)
490 {
491 EXPECT_EQ(descriptorType, PLDM_FWUP_VENDOR_DEFINED);
492 EXPECT_EQ(descriptorData.length, vendorDefinedDescriptorLen);
493
494 uint8_t descriptorTitleStrType = 0;
495 variable_field descriptorTitleStr{};
496 variable_field vendorDefinedDescriptorData{};
497
498 rc = decode_vendor_defined_descriptor_value(
499 descriptorData.ptr, descriptorData.length,
500 &descriptorTitleStrType, &descriptorTitleStr,
501 &vendorDefinedDescriptorData);
502 EXPECT_EQ(rc, PLDM_SUCCESS);
503
504 EXPECT_EQ(descriptorTitleStrType, PLDM_STR_TYPE_ASCII);
505 EXPECT_EQ(descriptorTitleStr.length, vendorTitle.size());
506 std::string vendorTitleStr(
507 reinterpret_cast<const char*>(descriptorTitleStr.ptr),
508 descriptorTitleStr.length);
509 EXPECT_EQ(vendorTitleStr, vendorTitle);
510
511 EXPECT_EQ(vendorDefinedDescriptorData.length,
512 vendorDescriptorData.size());
513 EXPECT_EQ(true, std::equal(vendorDefinedDescriptorData.ptr,
514 vendorDefinedDescriptorData.ptr +
515 vendorDefinedDescriptorData.length,
516 vendorDescriptorData.begin(),
517 vendorDescriptorData.end()));
518 }
519
520 descriptorsRemainingLength -= sizeof(descriptorType) +
521 sizeof(descriptorLen) +
522 descriptorData.length;
523 descriptorCount++;
524 }
525}
526
527TEST(DecodeDescriptors, errorPathDecodeDescriptorTLV)
528{
529 int rc = 0;
530 // IANA Enterprise ID descriptor length incorrect
531 constexpr std::array<uint8_t, 7> invalidIANADescriptor1{
532 0x01, 0x00, 0x03, 0x00, 0x0a, 0x0b, 0x0c};
533 uint16_t descriptorType = 0;
534 variable_field descriptorData{};
535
536 rc = decode_descriptor_type_length_value(nullptr,
537 invalidIANADescriptor1.size(),
538 &descriptorType, &descriptorData);
539 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
540
541 rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
542 invalidIANADescriptor1.size(),
543 nullptr, &descriptorData);
544 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
545
546 rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
547 invalidIANADescriptor1.size(),
548 &descriptorType, nullptr);
549 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
550
551 rc = decode_descriptor_type_length_value(
552 invalidIANADescriptor1.data(), PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN - 1,
553 &descriptorType, &descriptorData);
554 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
555
556 rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
557 invalidIANADescriptor1.size(),
558 &descriptorType, &descriptorData);
559 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
560
561 // IANA Enterprise ID descriptor data less than length
562 std::array<uint8_t, 7> invalidIANADescriptor2{0x01, 0x00, 0x04, 0x00,
563 0x0a, 0x0b, 0x0c};
564 rc = decode_descriptor_type_length_value(invalidIANADescriptor2.data(),
565 invalidIANADescriptor2.size(),
566 &descriptorType, &descriptorData);
567 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
568}
569
570TEST(DecodeDescriptors, errorPathVendorDefinedDescriptor)
571{
572 int rc = 0;
573 // VendorDefinedDescriptorTitleStringType is invalid
574 constexpr std::array<uint8_t, 9> invalidVendorDescriptor1{
575 0x06, 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
576 uint8_t descriptorStringType = 0;
577 variable_field descriptorTitleStr{};
578 variable_field vendorDefinedDescriptorData{};
579
580 rc = decode_vendor_defined_descriptor_value(
581 nullptr, invalidVendorDescriptor1.size(), &descriptorStringType,
582 &descriptorTitleStr, &vendorDefinedDescriptorData);
583 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
584
585 rc = decode_vendor_defined_descriptor_value(
586 invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
587 &descriptorStringType, &descriptorTitleStr,
588 &vendorDefinedDescriptorData);
589 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
590
591 rc = decode_vendor_defined_descriptor_value(
592 invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
593 nullptr, &descriptorTitleStr, &vendorDefinedDescriptorData);
594 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
595
596 rc = decode_vendor_defined_descriptor_value(
597 invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
598 &descriptorStringType, nullptr, &vendorDefinedDescriptorData);
599 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
600
601 rc = decode_vendor_defined_descriptor_value(
602 invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
603 &descriptorStringType, &descriptorTitleStr, nullptr);
604 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
605
606 rc = decode_vendor_defined_descriptor_value(
607 invalidVendorDescriptor1.data(),
608 sizeof(pldm_vendor_defined_descriptor_title_data) - 1,
609 &descriptorStringType, &descriptorTitleStr,
610 &vendorDefinedDescriptorData);
611 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
612
613 rc = decode_vendor_defined_descriptor_value(
614 invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
615 &descriptorStringType, &descriptorTitleStr,
616 &vendorDefinedDescriptorData);
617 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
618
619 // VendorDefinedDescriptorTitleStringLength is 0
620 std::array<uint8_t, 9> invalidVendorDescriptor2{
621 0x01, 0x00, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
622 rc = decode_vendor_defined_descriptor_value(
623 invalidVendorDescriptor2.data(), invalidVendorDescriptor2.size(),
624 &descriptorStringType, &descriptorTitleStr,
625 &vendorDefinedDescriptorData);
626 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
627
628 // VendorDefinedDescriptorData not present in the data
629 std::array<uint8_t, 9> invalidVendorDescriptor3{
630 0x01, 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
631 rc = decode_vendor_defined_descriptor_value(
632 invalidVendorDescriptor3.data(), invalidVendorDescriptor3.size(),
633 &descriptorStringType, &descriptorTitleStr,
634 &vendorDefinedDescriptorData);
635 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
636}
637
Tom Joseph58cc1722021-06-09 07:15:49 -0700638TEST(DecodeComponentImageInfo, goodPath)
639{
640 // Firmware
641 constexpr uint16_t compClassification = 16;
642 constexpr uint16_t compIdentifier = 300;
643 constexpr uint32_t compComparisonStamp = 0xFFFFFFFF;
644 // Force update
645 constexpr std::bitset<16> compOptions{1};
646 // System reboot[Bit position 3] & Medium-specific reset[Bit position 2]
647 constexpr std::bitset<16> reqCompActivationMethod{0x0c};
648 // Random ComponentLocationOffset
649 constexpr uint32_t compLocOffset = 357;
650 // Random ComponentSize
651 constexpr uint32_t compSize = 27;
652 // ComponentVersionString
653 constexpr std::string_view compVersionStr{"VersionString1"};
654 constexpr size_t compImageInfoSize =
655 sizeof(pldm_component_image_information) + compVersionStr.size();
656
657 constexpr std::array<uint8_t, compImageInfoSize> compImageInfo{
658 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
659 0x65, 0x01, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x56, 0x65,
660 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
661 pldm_component_image_information outCompImageInfo{};
662 variable_field outCompVersionStr{};
663
664 auto rc =
665 decode_pldm_comp_image_info(compImageInfo.data(), compImageInfo.size(),
666 &outCompImageInfo, &outCompVersionStr);
667
668 EXPECT_EQ(rc, PLDM_SUCCESS);
669 EXPECT_EQ(outCompImageInfo.comp_classification, compClassification);
670 EXPECT_EQ(outCompImageInfo.comp_identifier, compIdentifier);
671 EXPECT_EQ(outCompImageInfo.comp_comparison_stamp, compComparisonStamp);
672 EXPECT_EQ(outCompImageInfo.comp_options.value, compOptions);
673 EXPECT_EQ(outCompImageInfo.requested_comp_activation_method.value,
674 reqCompActivationMethod);
675 EXPECT_EQ(outCompImageInfo.comp_location_offset, compLocOffset);
676 EXPECT_EQ(outCompImageInfo.comp_size, compSize);
677 EXPECT_EQ(outCompImageInfo.comp_version_string_type, PLDM_STR_TYPE_ASCII);
678 EXPECT_EQ(outCompImageInfo.comp_version_string_length,
679 compVersionStr.size());
680
681 EXPECT_EQ(outCompVersionStr.length,
682 outCompImageInfo.comp_version_string_length);
683 std::string componentVersionString(
684 reinterpret_cast<const char*>(outCompVersionStr.ptr),
685 outCompVersionStr.length);
686 EXPECT_EQ(componentVersionString, compVersionStr);
687}
688
689TEST(DecodeComponentImageInfo, errorPaths)
690{
691 int rc = 0;
692 // ComponentVersionString
693 constexpr std::string_view compVersionStr{"VersionString1"};
694 constexpr size_t compImageInfoSize =
695 sizeof(pldm_component_image_information) + compVersionStr.size();
696 // Invalid ComponentVersionStringType - 0x06
697 constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo1{
698 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
699 0x65, 0x01, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x06, 0x0e, 0x56, 0x65,
700 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
701 pldm_component_image_information outCompImageInfo{};
702 variable_field outCompVersionStr{};
703
704 rc = decode_pldm_comp_image_info(nullptr, invalidCompImageInfo1.size(),
705 &outCompImageInfo, &outCompVersionStr);
706 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
707
708 rc = decode_pldm_comp_image_info(invalidCompImageInfo1.data(),
709 invalidCompImageInfo1.size(), nullptr,
710 &outCompVersionStr);
711 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
712
713 rc = decode_pldm_comp_image_info(invalidCompImageInfo1.data(),
714 invalidCompImageInfo1.size(),
715 &outCompImageInfo, nullptr);
716 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
717
718 rc = decode_pldm_comp_image_info(invalidCompImageInfo1.data(),
719 sizeof(pldm_component_image_information) -
720 1,
721 &outCompImageInfo, &outCompVersionStr);
722 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
723
724 rc = decode_pldm_comp_image_info(invalidCompImageInfo1.data(),
725 invalidCompImageInfo1.size(),
726 &outCompImageInfo, &outCompVersionStr);
727 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
728
729 // Invalid ComponentVersionStringLength - 0x00
730 constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo2{
731 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
732 0x65, 0x01, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x56, 0x65,
733 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
734 rc = decode_pldm_comp_image_info(invalidCompImageInfo2.data(),
735 invalidCompImageInfo2.size(),
736 &outCompImageInfo, &outCompVersionStr);
737 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
738
739 // Use Component Comparison Stamp is not set, but ComponentComparisonStamp
740 // is not 0xFFFFFFFF
741 constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo3{
742 0x10, 0x00, 0x2c, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0c, 0x00,
743 0x65, 0x01, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x56, 0x65,
744 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
745
746 rc = decode_pldm_comp_image_info(invalidCompImageInfo3.data(),
747 invalidCompImageInfo3.size() - 1,
748 &outCompImageInfo, &outCompVersionStr);
749 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
750
751 rc = decode_pldm_comp_image_info(invalidCompImageInfo3.data(),
752 invalidCompImageInfo3.size(),
753 &outCompImageInfo, &outCompVersionStr);
754 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
755
756 // Invalid ComponentLocationOffset - 0
757 constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo4{
758 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
759 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x56, 0x65,
760 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
761 rc = decode_pldm_comp_image_info(invalidCompImageInfo4.data(),
762 invalidCompImageInfo4.size(),
763 &outCompImageInfo, &outCompVersionStr);
764 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
765
766 // Invalid ComponentSize - 0
767 constexpr std::array<uint8_t, compImageInfoSize> invalidCompImageInfo5{
768 0x10, 0x00, 0x2c, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x0c, 0x00,
769 0x65, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x56, 0x65,
770 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31};
771 rc = decode_pldm_comp_image_info(invalidCompImageInfo5.data(),
772 invalidCompImageInfo5.size(),
773 &outCompImageInfo, &outCompVersionStr);
774 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
775}
776
gokulsanker138ceba2021-04-05 13:25:25 +0530777TEST(QueryDeviceIdentifiers, goodPathEncodeRequest)
778{
779 std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
780 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
781
782 uint8_t instanceId = 0x01;
783
784 auto rc = encode_query_device_identifiers_req(
785 instanceId, PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES, requestPtr);
786 EXPECT_EQ(rc, PLDM_SUCCESS);
787 EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
788 EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
789 EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
790 EXPECT_EQ(requestPtr->hdr.command, PLDM_QUERY_DEVICE_IDENTIFIERS);
791}
gokulsankereca3e192021-04-05 14:57:41 +0530792
793TEST(QueryDeviceIdentifiers, goodPathDecodeResponse)
794{
795 // descriptorDataLen is not fixed here taking it as 6
796 constexpr uint8_t descriptorDataLen = 6;
797 std::array<uint8_t, hdrSize +
798 sizeof(struct pldm_query_device_identifiers_resp) +
799 descriptorDataLen>
800 responseMsg{};
801 auto inResp = reinterpret_cast<struct pldm_query_device_identifiers_resp*>(
802 responseMsg.data() + hdrSize);
803
804 inResp->completion_code = PLDM_SUCCESS;
805 inResp->device_identifiers_len = htole32(descriptorDataLen);
806 inResp->descriptor_count = 1;
807
808 // filling descriptor data
809 std::fill_n(responseMsg.data() + hdrSize +
810 sizeof(struct pldm_query_device_identifiers_resp),
811 descriptorDataLen, 0xFF);
812
813 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
814 uint8_t completionCode = PLDM_SUCCESS;
815 uint32_t deviceIdentifiersLen = 0;
816 uint8_t descriptorCount = 0;
817 uint8_t* outDescriptorData = nullptr;
818
819 auto rc = decode_query_device_identifiers_resp(
820 response, responseMsg.size() - hdrSize, &completionCode,
821 &deviceIdentifiersLen, &descriptorCount, &outDescriptorData);
822
823 EXPECT_EQ(rc, PLDM_SUCCESS);
824 EXPECT_EQ(completionCode, PLDM_SUCCESS);
825 EXPECT_EQ(deviceIdentifiersLen, inResp->device_identifiers_len);
826 EXPECT_EQ(descriptorCount, inResp->descriptor_count);
827 EXPECT_EQ(true,
828 std::equal(outDescriptorData,
829 outDescriptorData + deviceIdentifiersLen,
830 responseMsg.begin() + hdrSize +
831 sizeof(struct pldm_query_device_identifiers_resp),
832 responseMsg.end()));
833}
gokulsanker981fbfb2021-04-05 15:17:25 +0530834
835TEST(GetFirmwareParameters, goodPathEncodeRequest)
836{
837 std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
838 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
839 uint8_t instanceId = 0x01;
840
841 auto rc = encode_get_firmware_parameters_req(
842 instanceId, PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES, requestPtr);
843 EXPECT_EQ(rc, PLDM_SUCCESS);
844 EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
845 EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
846 EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
847 EXPECT_EQ(requestPtr->hdr.command, PLDM_GET_FIRMWARE_PARAMETERS);
848}
gokulsanker22fbb342021-04-05 15:55:06 +0530849
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700850TEST(GetFirmwareParameters, decodeResponse)
gokulsanker22fbb342021-04-05 15:55:06 +0530851{
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700852 // CapabilitiesDuringUpdate of the firmware device
853 // Firmware device downgrade restrictions [Bit position 8] &
854 // Firmware Device Partial Updates [Bit position 3]
855 constexpr std::bitset<32> fdCapabilities{0x00000104};
856 constexpr uint16_t compCount = 1;
857 constexpr std::string_view activeCompImageSetVersion{"VersionString1"};
858 constexpr std::string_view pendingCompImageSetVersion{"VersionString2"};
gokulsanker22fbb342021-04-05 15:55:06 +0530859
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700860 // constexpr uint16_t compClassification = 16;
861 // constexpr uint16_t compIdentifier = 300;
862 // constexpr uint8_t compClassificationIndex = 20;
863 // constexpr uint32_t activeCompComparisonStamp = 0xABCDEFAB;
864 // constexpr std::array<uint8_t, 8> activeComponentReleaseData = {
865 // 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
866 // constexpr uint32_t pendingCompComparisonStamp = 0x12345678;
867 // constexpr std::array<uint8_t, 8> pendingComponentReleaseData = {
868 // 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01};
869 constexpr std::string_view activeCompVersion{"VersionString3"};
870 constexpr std::string_view pendingCompVersion{"VersionString4"};
871 // ComponentActivationMethods
872 // DC Power cycle [Bit position 4] & Self-Contained[Bit position 2]
873 constexpr std::bitset<16> compActivationMethod{0x12};
874 // CapabilitiesDuringUpdate of the firmware component
875 // Component downgrade capability [Bit position 2]
876 constexpr std::bitset<32> compCapabilities{0x02};
gokulsanker22fbb342021-04-05 15:55:06 +0530877
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700878 constexpr size_t compParamTableSize =
879 sizeof(pldm_component_parameter_entry) + activeCompVersion.size() +
880 pendingCompVersion.size();
gokulsanker22fbb342021-04-05 15:55:06 +0530881
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700882 constexpr std::array<uint8_t, compParamTableSize> compParamTable{
883 0x10, 0x00, 0x2c, 0x01, 0x14, 0xAB, 0xEF, 0xCD, 0xAB, 0x01, 0x0e, 0x01,
884 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x78, 0x56, 0x34, 0x12, 0x01,
885 0x0e, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x12, 0x00, 0x02,
886 0x00, 0x00, 0x00, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74,
887 0x72, 0x69, 0x6e, 0x67, 0x33, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
888 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x34};
gokulsanker22fbb342021-04-05 15:55:06 +0530889
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700890 constexpr size_t getFwParamsPayloadLen =
891 sizeof(pldm_get_firmware_parameters_resp) +
892 activeCompImageSetVersion.size() + pendingCompImageSetVersion.size() +
893 compParamTableSize;
894
895 constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
896 getFwParamsResponse{
897 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01,
898 0x0e, 0x01, 0x0e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53,
899 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x56, 0x65, 0x72, 0x73, 0x69,
900 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32, 0x10, 0x00,
901 0x2c, 0x01, 0x14, 0xAB, 0xEF, 0xCD, 0xAB, 0x01, 0x0e, 0x01, 0x02,
902 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x78, 0x56, 0x34, 0x12, 0x01,
903 0x0e, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x12, 0x00,
904 0x02, 0x00, 0x00, 0x00, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
905 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x33, 0x56, 0x65, 0x72, 0x73,
906 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x34};
907
908 auto responseMsg =
909 reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
910 pldm_get_firmware_parameters_resp outResp{};
911 variable_field outActiveCompImageSetVersion{};
912 variable_field outPendingCompImageSetVersion{};
913 variable_field outCompParameterTable{};
914
915 auto rc = decode_get_firmware_parameters_resp(
916 responseMsg, getFwParamsPayloadLen, &outResp,
917 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
918 &outCompParameterTable);
gokulsanker22fbb342021-04-05 15:55:06 +0530919
920 EXPECT_EQ(rc, PLDM_SUCCESS);
921 EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700922 EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
923 EXPECT_EQ(outResp.comp_count, compCount);
924 EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
925 EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
926 activeCompImageSetVersion.size());
927 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
928 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len,
929 pendingCompImageSetVersion.size());
930 std::string activeCompImageSetVersionStr(
931 reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
932 outActiveCompImageSetVersion.length);
933 EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
934 std::string pendingCompImageSetVersionStr(
935 reinterpret_cast<const char*>(outPendingCompImageSetVersion.ptr),
936 outPendingCompImageSetVersion.length);
937 EXPECT_EQ(pendingCompImageSetVersionStr, pendingCompImageSetVersion);
938 EXPECT_EQ(outCompParameterTable.length, compParamTableSize);
939 EXPECT_EQ(true, std::equal(outCompParameterTable.ptr,
940 outCompParameterTable.ptr +
941 outCompParameterTable.length,
942 compParamTable.begin(), compParamTable.end()));
943}
gokulsanker22fbb342021-04-05 15:55:06 +0530944
Tom Joseph3fd3eb82021-06-18 04:13:29 -0700945TEST(GetFirmwareParameters, decodeResponseZeroCompCount)
946{
947 // CapabilitiesDuringUpdate of the firmware device
948 // FD Host Functionality during Firmware Update [Bit position 2] &
949 // Component Update Failure Retry Capability [Bit position 1]
950 constexpr std::bitset<32> fdCapabilities{0x06};
951 constexpr uint16_t compCount = 0;
952 constexpr std::string_view activeCompImageSetVersion{"VersionString1"};
953 constexpr std::string_view pendingCompImageSetVersion{"VersionString2"};
954
955 constexpr size_t getFwParamsPayloadLen =
956 sizeof(pldm_get_firmware_parameters_resp) +
957 activeCompImageSetVersion.size() + pendingCompImageSetVersion.size();
958
959 constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
960 getFwParamsResponse{
961 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
962 0x0e, 0x01, 0x0e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53,
963 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x56, 0x65, 0x72, 0x73, 0x69,
964 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32};
965
966 auto responseMsg =
967 reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
968 pldm_get_firmware_parameters_resp outResp{};
969 variable_field outActiveCompImageSetVersion{};
970 variable_field outPendingCompImageSetVersion{};
971 variable_field outCompParameterTable{};
972
973 auto rc = decode_get_firmware_parameters_resp(
974 responseMsg, getFwParamsPayloadLen, &outResp,
975 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
976 &outCompParameterTable);
977
978 EXPECT_EQ(rc, PLDM_SUCCESS);
979 EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
980 EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
981 EXPECT_EQ(outResp.comp_count, compCount);
982 EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
983 EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
984 activeCompImageSetVersion.size());
985 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
986 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len,
987 pendingCompImageSetVersion.size());
988 std::string activeCompImageSetVersionStr(
989 reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
990 outActiveCompImageSetVersion.length);
991 EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
992 std::string pendingCompImageSetVersionStr(
993 reinterpret_cast<const char*>(outPendingCompImageSetVersion.ptr),
994 outPendingCompImageSetVersion.length);
995 EXPECT_EQ(pendingCompImageSetVersionStr, pendingCompImageSetVersion);
996 EXPECT_EQ(outCompParameterTable.ptr, nullptr);
997 EXPECT_EQ(outCompParameterTable.length, 0);
998}
999
1000TEST(GetFirmwareParameters,
1001 decodeResponseNoPendingCompImageVersionStrZeroCompCount)
1002{
1003 // CapabilitiesDuringUpdate of the firmware device
1004 // FD Host Functionality during Firmware Update [Bit position 2] &
1005 // Component Update Failure Retry Capability [Bit position 1]
1006 constexpr std::bitset<32> fdCapabilities{0x06};
1007 constexpr uint16_t compCount = 0;
1008 constexpr std::string_view activeCompImageSetVersion{"VersionString"};
1009
1010 constexpr size_t getFwParamsPayloadLen =
1011 sizeof(pldm_get_firmware_parameters_resp) +
1012 activeCompImageSetVersion.size();
1013
1014 constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
1015 getFwParamsResponse{0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
1016 0x00, 0x00, 0x00, 0x01, 0x0d, 0x00, 0x00,
1017 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
1018 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67};
1019
1020 auto responseMsg =
1021 reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
1022 pldm_get_firmware_parameters_resp outResp{};
1023 variable_field outActiveCompImageSetVersion{};
1024 variable_field outPendingCompImageSetVersion{};
1025 variable_field outCompParameterTable{};
1026
1027 auto rc = decode_get_firmware_parameters_resp(
1028 responseMsg, getFwParamsPayloadLen, &outResp,
1029 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1030 &outCompParameterTable);
1031
1032 EXPECT_EQ(rc, PLDM_SUCCESS);
1033 EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
1034 EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
1035 EXPECT_EQ(outResp.comp_count, compCount);
1036 EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
1037 EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
1038 activeCompImageSetVersion.size());
1039 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type,
1040 PLDM_STR_TYPE_UNKNOWN);
1041 EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len, 0);
1042 std::string activeCompImageSetVersionStr(
1043 reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
1044 outActiveCompImageSetVersion.length);
1045 EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
1046 EXPECT_EQ(outPendingCompImageSetVersion.ptr, nullptr);
1047 EXPECT_EQ(outPendingCompImageSetVersion.length, 0);
1048 EXPECT_EQ(outCompParameterTable.ptr, nullptr);
1049 EXPECT_EQ(outCompParameterTable.length, 0);
1050}
1051
1052TEST(GetFirmwareParameters, decodeResponseErrorCompletionCode)
1053{
Tom Joseph83a644c2021-06-22 22:25:25 -07001054 constexpr std::array<uint8_t, hdrSize + sizeof(uint8_t)>
1055 getFwParamsResponse{0x00, 0x00, 0x00, 0x01};
Tom Joseph3fd3eb82021-06-18 04:13:29 -07001056
1057 auto responseMsg =
1058 reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
1059 pldm_get_firmware_parameters_resp outResp{};
1060 variable_field outActiveCompImageSetVersion{};
1061 variable_field outPendingCompImageSetVersion{};
1062 variable_field outCompParameterTable{};
1063
1064 auto rc = decode_get_firmware_parameters_resp(
1065 responseMsg, getFwParamsResponse.size(), &outResp,
1066 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1067 &outCompParameterTable);
1068
1069 EXPECT_EQ(rc, PLDM_SUCCESS);
1070 EXPECT_EQ(outResp.completion_code, PLDM_ERROR);
1071}
1072
1073TEST(GetFirmwareParameters, errorPathdecodeResponse)
1074{
1075 int rc = 0;
1076 // Invalid ActiveComponentImageSetVersionStringType
1077 constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse1{
1078 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1079 0x00, 0x00, 0x00, 0x06, 0x0e, 0x00, 0x00};
1080
1081 auto responseMsg =
1082 reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse1.data());
1083 pldm_get_firmware_parameters_resp outResp{};
1084 variable_field outActiveCompImageSetVersion{};
1085 variable_field outPendingCompImageSetVersion{};
1086 variable_field outCompParameterTable{};
1087
1088 rc = decode_get_firmware_parameters_resp(
Tom Joseph83a644c2021-06-22 22:25:25 -07001089 nullptr, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
Tom Joseph3fd3eb82021-06-18 04:13:29 -07001090 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1091 &outCompParameterTable);
1092 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1093
1094 rc = decode_get_firmware_parameters_resp(
Tom Joseph83a644c2021-06-22 22:25:25 -07001095 responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, nullptr,
Tom Joseph3fd3eb82021-06-18 04:13:29 -07001096 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1097 &outCompParameterTable);
1098 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1099
1100 rc = decode_get_firmware_parameters_resp(
Tom Joseph83a644c2021-06-22 22:25:25 -07001101 responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
1102 nullptr, &outPendingCompImageSetVersion, &outCompParameterTable);
Tom Joseph3fd3eb82021-06-18 04:13:29 -07001103 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1104
1105 rc = decode_get_firmware_parameters_resp(
Tom Joseph83a644c2021-06-22 22:25:25 -07001106 responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
Tom Joseph3fd3eb82021-06-18 04:13:29 -07001107 &outActiveCompImageSetVersion, nullptr, &outCompParameterTable);
1108 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1109
1110 rc = decode_get_firmware_parameters_resp(
Tom Joseph83a644c2021-06-22 22:25:25 -07001111 responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
Tom Joseph3fd3eb82021-06-18 04:13:29 -07001112 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion, nullptr);
1113 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1114
1115 rc = decode_get_firmware_parameters_resp(
1116 responseMsg, 0, &outResp, &outActiveCompImageSetVersion,
1117 &outPendingCompImageSetVersion, &outCompParameterTable);
Tom Joseph83a644c2021-06-22 22:25:25 -07001118 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1119
1120 rc = decode_get_firmware_parameters_resp(
1121 responseMsg, invalidGetFwParamsResponse1.size() - 1 - hdrSize, &outResp,
1122 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1123 &outCompParameterTable);
Tom Joseph3fd3eb82021-06-18 04:13:29 -07001124 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1125
1126 rc = decode_get_firmware_parameters_resp(
Tom Joseph83a644c2021-06-22 22:25:25 -07001127 responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp,
Tom Joseph3fd3eb82021-06-18 04:13:29 -07001128 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1129 &outCompParameterTable);
1130 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1131
1132 // Invalid ActiveComponentImageSetVersionStringLength
1133 constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse2{
1134 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1135 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
1136 responseMsg =
1137 reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse2.data());
1138 rc = decode_get_firmware_parameters_resp(
Tom Joseph83a644c2021-06-22 22:25:25 -07001139 responseMsg, invalidGetFwParamsResponse2.size() - hdrSize, &outResp,
Tom Joseph3fd3eb82021-06-18 04:13:29 -07001140 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1141 &outCompParameterTable);
1142 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1143
1144 // Invalid PendingComponentImageSetVersionStringType &
1145 // PendingComponentImageSetVersionStringLength
1146 constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse3{
1147 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
1148 0x00, 0x00, 0x00, 0x01, 0x0e, 0x01, 0x00};
1149 responseMsg =
1150 reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse3.data());
1151 rc = decode_get_firmware_parameters_resp(
Tom Joseph83a644c2021-06-22 22:25:25 -07001152 responseMsg, invalidGetFwParamsResponse3.size() - hdrSize, &outResp,
Tom Joseph3fd3eb82021-06-18 04:13:29 -07001153 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1154 &outCompParameterTable);
1155 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1156
1157 // Invalid PendingComponentImageSetVersionStringType &
1158 // PendingComponentImageSetVersionStringLength
1159 constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse4{
1160 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
1161 0x00, 0x00, 0x00, 0x01, 0x0e, 0x06, 0x0e};
1162 responseMsg =
1163 reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse4.data());
1164 rc = decode_get_firmware_parameters_resp(
Tom Joseph83a644c2021-06-22 22:25:25 -07001165 responseMsg, invalidGetFwParamsResponse4.size() - hdrSize, &outResp,
Tom Joseph3fd3eb82021-06-18 04:13:29 -07001166 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1167 &outCompParameterTable);
1168 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1169
1170 // Total payload length less than expected
1171 constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse5{
1172 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
1173 0x00, 0x00, 0x00, 0x01, 0x0e, 0x01, 0x0e};
1174 responseMsg =
1175 reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse5.data());
1176 rc = decode_get_firmware_parameters_resp(
Tom Joseph83a644c2021-06-22 22:25:25 -07001177 responseMsg, invalidGetFwParamsResponse5.size() - hdrSize, &outResp,
Tom Joseph3fd3eb82021-06-18 04:13:29 -07001178 &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
1179 &outCompParameterTable);
1180 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
gokulsanker22fbb342021-04-05 15:55:06 +05301181}
gokulsankere1fb7a82021-04-05 16:09:29 +05301182
1183TEST(GetFirmwareParameters, goodPathDecodeComponentParameterEntry)
1184{
1185 // Random value for component classification
1186 constexpr uint16_t compClassification = 0x0A0B;
1187 // Random value for component classification
1188 constexpr uint16_t compIdentifier = 0x0C0D;
1189 // Random value for component classification
1190 constexpr uint32_t timestamp = 0X12345678;
1191 // Random value for component activation methods
1192 constexpr uint16_t compActivationMethods = 0xBBDD;
1193 // Random value for capabilities during update
1194 constexpr uint32_t capabilitiesDuringUpdate = 0xBADBEEFE;
1195
1196 // ActiveCompImageSetVerStrLen is not fixed here taking it as 8
1197 constexpr uint8_t activeCompVerStrLen = 8;
1198 // PendingCompImageSetVerStrLen is not fixed here taking it as 8
1199 constexpr uint8_t pendingCompVerStrLen = 8;
1200 constexpr size_t entryLength =
1201 sizeof(struct pldm_component_parameter_entry) + activeCompVerStrLen +
1202 pendingCompVerStrLen;
1203 std::array<uint8_t, entryLength> entry{};
1204
1205 auto inEntry =
1206 reinterpret_cast<struct pldm_component_parameter_entry*>(entry.data());
1207
1208 inEntry->comp_classification = htole16(compClassification);
1209 inEntry->comp_identifier = htole16(compIdentifier);
1210 inEntry->comp_classification_index = 0x0F;
1211 inEntry->active_comp_comparison_stamp = htole32(timestamp);
1212 inEntry->active_comp_ver_str_type = 1;
1213 inEntry->active_comp_ver_str_len = activeCompVerStrLen;
1214 std::fill_n(inEntry->active_comp_release_date,
1215 sizeof(inEntry->active_comp_release_date), 0xFF);
1216 inEntry->pending_comp_comparison_stamp = htole32(timestamp);
1217 inEntry->pending_comp_ver_str_type = 1;
1218 inEntry->pending_comp_ver_str_len = pendingCompVerStrLen;
1219 std::fill_n(inEntry->pending_comp_release_date,
1220 sizeof(inEntry->pending_comp_release_date), 0xFF);
1221 inEntry->comp_activation_methods.value = htole16(compActivationMethods);
1222 inEntry->capabilities_during_update.value =
1223 htole32(capabilitiesDuringUpdate);
1224 constexpr auto activeCompVerStrPos =
1225 sizeof(struct pldm_component_parameter_entry);
1226 std::fill_n(entry.data() + activeCompVerStrPos, activeCompVerStrLen, 0xAA);
1227 constexpr auto pendingCompVerStrPos =
1228 activeCompVerStrPos + activeCompVerStrLen;
1229 std::fill_n(entry.data() + pendingCompVerStrPos, pendingCompVerStrLen,
1230 0xBB);
1231
1232 struct pldm_component_parameter_entry outEntry;
1233 struct variable_field outActiveCompVerStr;
1234 struct variable_field outPendingCompVerStr;
1235
1236 auto rc = decode_get_firmware_parameters_resp_comp_entry(
1237 entry.data(), entryLength, &outEntry, &outActiveCompVerStr,
1238 &outPendingCompVerStr);
1239
1240 EXPECT_EQ(rc, PLDM_SUCCESS);
1241
1242 EXPECT_EQ(outEntry.comp_classification, compClassification);
1243 EXPECT_EQ(outEntry.comp_identifier, compIdentifier);
1244 EXPECT_EQ(inEntry->comp_classification_index,
1245 outEntry.comp_classification_index);
1246 EXPECT_EQ(outEntry.active_comp_comparison_stamp, timestamp);
1247 EXPECT_EQ(inEntry->active_comp_ver_str_type,
1248 outEntry.active_comp_ver_str_type);
1249 EXPECT_EQ(inEntry->active_comp_ver_str_len,
1250 outEntry.active_comp_ver_str_len);
1251 EXPECT_EQ(0, memcmp(inEntry->active_comp_release_date,
1252 outEntry.active_comp_release_date,
1253 sizeof(inEntry->active_comp_release_date)));
1254 EXPECT_EQ(outEntry.pending_comp_comparison_stamp, timestamp);
1255 EXPECT_EQ(inEntry->pending_comp_ver_str_type,
1256 outEntry.pending_comp_ver_str_type);
1257 EXPECT_EQ(inEntry->pending_comp_ver_str_len,
1258 outEntry.pending_comp_ver_str_len);
1259 EXPECT_EQ(0, memcmp(inEntry->pending_comp_release_date,
1260 outEntry.pending_comp_release_date,
1261 sizeof(inEntry->pending_comp_release_date)));
1262 EXPECT_EQ(outEntry.comp_activation_methods.value, compActivationMethods);
1263 EXPECT_EQ(outEntry.capabilities_during_update.value,
1264 capabilitiesDuringUpdate);
1265
1266 EXPECT_EQ(0, memcmp(outActiveCompVerStr.ptr,
1267 entry.data() + activeCompVerStrPos,
1268 outActiveCompVerStr.length));
1269 EXPECT_EQ(0, memcmp(outPendingCompVerStr.ptr,
1270 entry.data() + pendingCompVerStrPos,
1271 outPendingCompVerStr.length));
1272}
gokulsankerd434edc2021-04-05 16:36:04 +05301273
1274TEST(RequestUpdate, goodPathEncodeRequest)
1275{
1276 constexpr uint8_t instanceId = 1;
1277 constexpr uint32_t maxTransferSize = 512;
1278 constexpr uint16_t numOfComp = 3;
1279 constexpr uint8_t maxOutstandingTransferReq = 2;
1280 constexpr uint16_t pkgDataLen = 0x1234;
1281 constexpr std::string_view compImgSetVerStr = "0penBmcv1.0";
1282 constexpr uint8_t compImgSetVerStrLen =
1283 static_cast<uint8_t>(compImgSetVerStr.size());
1284 variable_field compImgSetVerStrInfo{};
1285 compImgSetVerStrInfo.ptr =
1286 reinterpret_cast<const uint8_t*>(compImgSetVerStr.data());
1287 compImgSetVerStrInfo.length = compImgSetVerStrLen;
1288
1289 std::array<uint8_t, hdrSize + sizeof(struct pldm_request_update_req) +
1290 compImgSetVerStrLen>
1291 request{};
1292 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
1293
1294 auto rc = encode_request_update_req(
1295 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1296 pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
1297 &compImgSetVerStrInfo, requestMsg,
1298 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1299 EXPECT_EQ(rc, PLDM_SUCCESS);
1300
1301 std::array<uint8_t, hdrSize + sizeof(struct pldm_request_update_req) +
1302 compImgSetVerStrLen>
1303 outRequest{0x81, 0x05, 0x10, 0x00, 0x02, 0x00, 0x00, 0x03, 0x00,
1304 0x02, 0x34, 0x12, 0x01, 0x0b, 0x30, 0x70, 0x65, 0x6e,
1305 0x42, 0x6d, 0x63, 0x76, 0x31, 0x2e, 0x30};
1306 EXPECT_EQ(request, outRequest);
1307}
1308
1309TEST(RequestUpdate, errorPathEncodeRequest)
1310{
1311 constexpr uint8_t instanceId = 1;
1312 uint32_t maxTransferSize = 512;
1313 constexpr uint16_t numOfComp = 3;
1314 uint8_t maxOutstandingTransferReq = 2;
1315 constexpr uint16_t pkgDataLen = 0x1234;
1316 constexpr std::string_view compImgSetVerStr = "0penBmcv1.0";
1317 uint8_t compImgSetVerStrLen = static_cast<uint8_t>(compImgSetVerStr.size());
1318 variable_field compImgSetVerStrInfo{};
1319 compImgSetVerStrInfo.ptr =
1320 reinterpret_cast<const uint8_t*>(compImgSetVerStr.data());
1321 compImgSetVerStrInfo.length = compImgSetVerStrLen;
1322
1323 std::array<uint8_t, hdrSize + sizeof(struct pldm_request_update_req) +
1324 compImgSetVerStr.size()>
1325 request{};
1326 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
1327
1328 auto rc = encode_request_update_req(
1329 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1330 pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen, nullptr,
1331 requestMsg,
1332 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1333 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1334
1335 compImgSetVerStrInfo.ptr = nullptr;
1336 rc = encode_request_update_req(
1337 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1338 pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
1339 &compImgSetVerStrInfo, requestMsg,
1340 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1341 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1342 compImgSetVerStrInfo.ptr =
1343 reinterpret_cast<const uint8_t*>(compImgSetVerStr.data());
1344
1345 rc = encode_request_update_req(
1346 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1347 pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
1348 &compImgSetVerStrInfo, nullptr,
1349 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1350 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1351
1352 rc = encode_request_update_req(instanceId, maxTransferSize, numOfComp,
1353 maxOutstandingTransferReq, pkgDataLen,
1354 PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
1355 &compImgSetVerStrInfo, requestMsg, 0);
1356 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1357
1358 compImgSetVerStrLen = 0;
1359 rc = encode_request_update_req(
1360 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1361 pkgDataLen, PLDM_STR_TYPE_ASCII, 0, &compImgSetVerStrInfo, nullptr,
1362 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1363 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1364 compImgSetVerStrLen = static_cast<uint8_t>(compImgSetVerStr.size());
1365
1366 compImgSetVerStrInfo.length = 0xFFFF;
1367 rc = encode_request_update_req(
1368 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1369 pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
1370 &compImgSetVerStrInfo, nullptr,
1371 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1372 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1373 compImgSetVerStrInfo.length = compImgSetVerStrLen;
1374
1375 maxTransferSize = PLDM_FWUP_BASELINE_TRANSFER_SIZE - 1;
1376 rc = encode_request_update_req(
1377 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1378 pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
1379 &compImgSetVerStrInfo, nullptr,
1380 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1381 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1382 maxTransferSize = PLDM_FWUP_BASELINE_TRANSFER_SIZE;
1383
1384 maxOutstandingTransferReq = PLDM_FWUP_MIN_OUTSTANDING_REQ - 1;
1385 rc = encode_request_update_req(
1386 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1387 pkgDataLen, PLDM_STR_TYPE_ASCII, compImgSetVerStrLen,
1388 &compImgSetVerStrInfo, nullptr,
1389 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1390 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1391 maxOutstandingTransferReq = PLDM_FWUP_MIN_OUTSTANDING_REQ;
1392
1393 rc = encode_request_update_req(
1394 instanceId, maxTransferSize, numOfComp, maxOutstandingTransferReq,
1395 pkgDataLen, PLDM_STR_TYPE_UNKNOWN, compImgSetVerStrLen,
1396 &compImgSetVerStrInfo, nullptr,
1397 sizeof(struct pldm_request_update_req) + compImgSetVerStrLen);
1398 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1399}
gokulsanker611238c2021-04-05 16:50:44 +05301400
1401TEST(RequestUpdate, goodPathDecodeResponse)
1402{
1403 constexpr uint16_t fdMetaDataLen = 1024;
1404 constexpr uint8_t fdWillSendPkgData = 1;
1405 constexpr std::array<uint8_t, hdrSize + sizeof(pldm_request_update_resp)>
1406 requestUpdateResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01};
1407
1408 auto responseMsg1 =
1409 reinterpret_cast<const pldm_msg*>(requestUpdateResponse1.data());
1410 uint8_t outCompletionCode = 0;
1411 uint16_t outFdMetaDataLen = 0;
1412 uint8_t outFdWillSendPkgData = 0;
1413
1414 auto rc = decode_request_update_resp(
1415 responseMsg1, requestUpdateResponse1.size() - hdrSize,
1416 &outCompletionCode, &outFdMetaDataLen, &outFdWillSendPkgData);
1417 EXPECT_EQ(rc, PLDM_SUCCESS);
1418 EXPECT_EQ(outCompletionCode, PLDM_SUCCESS);
1419 EXPECT_EQ(outFdMetaDataLen, fdMetaDataLen);
1420 EXPECT_EQ(outFdWillSendPkgData, fdWillSendPkgData);
1421
1422 outCompletionCode = 0;
1423 outFdMetaDataLen = 0;
1424 outFdWillSendPkgData = 0;
1425
1426 constexpr std::array<uint8_t, hdrSize + sizeof(outCompletionCode)>
1427 requestUpdateResponse2{0x00, 0x00, 0x00, 0x81};
1428 auto responseMsg2 =
1429 reinterpret_cast<const pldm_msg*>(requestUpdateResponse2.data());
1430 rc = decode_request_update_resp(
1431 responseMsg2, requestUpdateResponse2.size() - hdrSize,
1432 &outCompletionCode, &outFdMetaDataLen, &outFdWillSendPkgData);
1433 EXPECT_EQ(rc, PLDM_SUCCESS);
1434 EXPECT_EQ(outCompletionCode, PLDM_FWUP_ALREADY_IN_UPDATE_MODE);
1435}
1436
1437TEST(RequestUpdate, errorPathDecodeResponse)
1438{
1439 constexpr std::array<uint8_t,
1440 hdrSize + sizeof(pldm_request_update_resp) - 1>
1441 requestUpdateResponse{0x00, 0x00, 0x00, 0x00, 0x00, 0x04};
1442
1443 auto responseMsg =
1444 reinterpret_cast<const pldm_msg*>(requestUpdateResponse.data());
1445 uint8_t outCompletionCode = 0;
1446 uint16_t outFdMetaDataLen = 0;
1447 uint8_t outFdWillSendPkgData = 0;
1448
1449 auto rc = decode_request_update_resp(
1450 nullptr, requestUpdateResponse.size() - hdrSize, &outCompletionCode,
1451 &outFdMetaDataLen, &outFdWillSendPkgData);
1452 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1453
1454 rc = decode_request_update_resp(
1455 responseMsg, requestUpdateResponse.size() - hdrSize, nullptr,
1456 &outFdMetaDataLen, &outFdWillSendPkgData);
1457 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1458
1459 rc = decode_request_update_resp(
1460 responseMsg, requestUpdateResponse.size() - hdrSize, &outCompletionCode,
1461 nullptr, &outFdWillSendPkgData);
1462 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1463
1464 rc = decode_request_update_resp(
1465 responseMsg, requestUpdateResponse.size() - hdrSize, &outCompletionCode,
1466 &outFdMetaDataLen, nullptr);
1467 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1468
1469 rc = decode_request_update_resp(responseMsg, 0, &outCompletionCode,
1470 &outFdMetaDataLen, &outFdWillSendPkgData);
1471 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1472
1473 rc = decode_request_update_resp(
1474 responseMsg, requestUpdateResponse.size() - hdrSize, &outCompletionCode,
1475 &outFdMetaDataLen, &outFdWillSendPkgData);
1476 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1477}
gokulsanker1b909d82021-04-05 17:26:02 +05301478
1479TEST(PassComponentTable, goodPathEncodeRequest)
1480{
1481 constexpr uint8_t instanceId = 1;
1482 constexpr uint16_t compIdentifier = 400;
1483 constexpr uint8_t compClassificationIndex = 40;
1484 constexpr uint32_t compComparisonStamp = 0x12345678;
1485 constexpr std::string_view compVerStr = "0penBmcv1.1";
1486 constexpr uint8_t compVerStrLen = static_cast<uint8_t>(compVerStr.size());
1487 variable_field compVerStrInfo{};
1488 compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
1489 compVerStrInfo.length = compVerStrLen;
1490
1491 std::array<uint8_t,
1492 hdrSize + sizeof(pldm_pass_component_table_req) + compVerStrLen>
1493 request{};
1494 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
1495
1496 auto rc = encode_pass_component_table_req(
1497 instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
1498 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
1499 compVerStrLen, &compVerStrInfo, requestMsg,
1500 sizeof(pldm_pass_component_table_req) + compVerStrLen);
1501 EXPECT_EQ(rc, PLDM_SUCCESS);
1502
1503 std::array<uint8_t,
1504 hdrSize + sizeof(pldm_pass_component_table_req) + compVerStrLen>
1505 outRequest{0x81, 0x05, 0x13, 0x05, 0x0A, 0x00, 0x90, 0x01, 0x28,
1506 0x78, 0x56, 0x34, 0x12, 0x01, 0x0B, 0x30, 0x70, 0x65,
1507 0x6E, 0x42, 0x6D, 0x63, 0x76, 0x31, 0x2E, 0x31};
1508 EXPECT_EQ(request, outRequest);
1509}
1510
1511TEST(PassComponentTable, errorPathEncodeRequest)
1512{
1513 constexpr uint8_t instanceId = 1;
1514 constexpr uint16_t compIdentifier = 400;
1515 constexpr uint8_t compClassificationIndex = 40;
1516 constexpr uint32_t compComparisonStamp = 0x12345678;
1517 constexpr std::string_view compVerStr = "0penBmcv1.1";
1518 constexpr uint8_t compVerStrLen = static_cast<uint8_t>(compVerStr.size());
1519 variable_field compVerStrInfo{};
1520 compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
1521 compVerStrInfo.length = compVerStrLen;
1522
1523 std::array<uint8_t,
1524 hdrSize + sizeof(pldm_pass_component_table_req) + compVerStrLen>
1525 request{};
1526 auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
1527
1528 auto rc = encode_pass_component_table_req(
1529 instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
1530 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
1531 compVerStrLen, nullptr, requestMsg,
1532 sizeof(pldm_pass_component_table_req) + compVerStrLen);
1533 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1534
1535 compVerStrInfo.ptr = nullptr;
1536 rc = encode_pass_component_table_req(
1537 instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
1538 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
1539 compVerStrLen, &compVerStrInfo, requestMsg,
1540 sizeof(pldm_pass_component_table_req) + compVerStrLen);
1541 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1542 compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data());
1543
1544 rc = encode_pass_component_table_req(
1545 instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
1546 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
1547 compVerStrLen, &compVerStrInfo, nullptr,
1548 sizeof(pldm_pass_component_table_req) + compVerStrLen);
1549 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1550
1551 rc = encode_pass_component_table_req(
1552 instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
1553 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
1554 compVerStrLen, &compVerStrInfo, requestMsg,
1555 sizeof(pldm_pass_component_table_req));
1556 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1557
1558 rc = encode_pass_component_table_req(
1559 instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
1560 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII, 0,
1561 &compVerStrInfo, requestMsg,
1562 sizeof(pldm_pass_component_table_req) + compVerStrLen);
1563 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1564
1565 rc = encode_pass_component_table_req(
1566 instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
1567 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
1568 compVerStrLen - 1, &compVerStrInfo, requestMsg,
1569 sizeof(pldm_pass_component_table_req) + compVerStrLen);
1570 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1571
1572 rc = encode_pass_component_table_req(
1573 instanceId, PLDM_START_AND_END + 1, PLDM_COMP_FIRMWARE, compIdentifier,
1574 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_ASCII,
1575 compVerStrLen, &compVerStrInfo, requestMsg,
1576 sizeof(pldm_pass_component_table_req) + compVerStrLen);
1577 EXPECT_EQ(rc, PLDM_INVALID_TRANSFER_OPERATION_FLAG);
1578
1579 rc = encode_pass_component_table_req(
1580 instanceId, PLDM_START_AND_END, PLDM_COMP_FIRMWARE, compIdentifier,
1581 compClassificationIndex, compComparisonStamp, PLDM_STR_TYPE_UNKNOWN,
1582 compVerStrLen, &compVerStrInfo, requestMsg,
1583 sizeof(pldm_pass_component_table_req) + compVerStrLen);
1584 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1585}
gokulsanker566784b2021-04-05 17:47:04 +05301586
1587TEST(PassComponentTable, goodPathDecodeResponse)
1588{
1589 constexpr std::array<uint8_t,
1590 hdrSize + sizeof(pldm_pass_component_table_resp)>
1591 passCompTableResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
1592 auto responseMsg1 =
1593 reinterpret_cast<const pldm_msg*>(passCompTableResponse1.data());
1594
1595 uint8_t completionCode = 0;
1596 uint8_t compResp = 0;
1597 uint8_t compRespCode = 0;
1598
1599 auto rc = decode_pass_component_table_resp(
1600 responseMsg1, sizeof(pldm_pass_component_table_resp), &completionCode,
1601 &compResp, &compRespCode);
1602
1603 EXPECT_EQ(rc, PLDM_SUCCESS);
1604 EXPECT_EQ(completionCode, PLDM_SUCCESS);
1605 EXPECT_EQ(compResp, PLDM_CR_COMP_CAN_BE_UPDATED);
1606 EXPECT_EQ(compRespCode, PLDM_CRC_COMP_COMPARISON_STAMP_IDENTICAL);
1607
1608 constexpr std::array<uint8_t,
1609 hdrSize + sizeof(pldm_pass_component_table_resp)>
1610 passCompTableResponse2{0x00, 0x00, 0x00, 0x00, 0x00, 0xD0};
1611 auto responseMsg2 =
1612 reinterpret_cast<const pldm_msg*>(passCompTableResponse2.data());
1613 rc = decode_pass_component_table_resp(
1614 responseMsg2, sizeof(pldm_pass_component_table_resp), &completionCode,
1615 &compResp, &compRespCode);
1616
1617 EXPECT_EQ(rc, PLDM_SUCCESS);
1618 EXPECT_EQ(completionCode, PLDM_SUCCESS);
1619 EXPECT_EQ(compResp, PLDM_CR_COMP_CAN_BE_UPDATED);
1620 EXPECT_EQ(compRespCode, PLDM_CRC_VENDOR_COMP_RESP_CODE_RANGE_MIN);
1621
1622 constexpr std::array<uint8_t,
1623 hdrSize + sizeof(pldm_pass_component_table_resp)>
1624 passCompTableResponse3{0x00, 0x00, 0x00, 0x80};
1625 auto responseMsg3 =
1626 reinterpret_cast<const pldm_msg*>(passCompTableResponse3.data());
1627
1628 rc = decode_pass_component_table_resp(
1629 responseMsg3, sizeof(pldm_pass_component_table_resp), &completionCode,
1630 &compResp, &compRespCode);
1631
1632 EXPECT_EQ(rc, PLDM_SUCCESS);
1633 EXPECT_EQ(completionCode, PLDM_FWUP_NOT_IN_UPDATE_MODE);
1634}
1635
1636TEST(PassComponentTable, errorPathDecodeResponse)
1637{
1638 constexpr std::array<uint8_t,
1639 hdrSize + sizeof(pldm_pass_component_table_resp) - 1>
1640 passCompTableResponse1{0x00, 0x00, 0x00, 0x00, 0x00};
1641 auto responseMsg1 =
1642 reinterpret_cast<const pldm_msg*>(passCompTableResponse1.data());
1643
1644 uint8_t completionCode = 0;
1645 uint8_t compResp = 0;
1646 uint8_t compRespCode = 0;
1647
1648 auto rc = decode_pass_component_table_resp(
1649 nullptr, sizeof(pldm_pass_component_table_resp) - 1, &completionCode,
1650 &compResp, &compRespCode);
1651 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1652
1653 rc = decode_pass_component_table_resp(
1654 responseMsg1, sizeof(pldm_pass_component_table_resp) - 1, nullptr,
1655 &compResp, &compRespCode);
1656 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1657
1658 rc = decode_pass_component_table_resp(
1659 responseMsg1, sizeof(pldm_pass_component_table_resp) - 1,
1660 &completionCode, nullptr, &compRespCode);
1661 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1662
1663 rc = decode_pass_component_table_resp(
1664 responseMsg1, sizeof(pldm_pass_component_table_resp) - 1,
1665 &completionCode, &compResp, nullptr);
1666 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1667
1668 rc = decode_pass_component_table_resp(responseMsg1, 0, &completionCode,
1669 &compResp, &compRespCode);
1670 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1671
1672 rc = decode_pass_component_table_resp(
1673 responseMsg1, sizeof(pldm_pass_component_table_resp) - 1,
1674 &completionCode, &compResp, &compRespCode);
1675 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1676
1677 constexpr std::array<uint8_t,
1678 hdrSize + sizeof(pldm_pass_component_table_resp)>
1679 passCompTableResponse2{0x00, 0x00, 0x00, 0x00, 0x02, 0x00};
1680 auto responseMsg2 =
1681 reinterpret_cast<const pldm_msg*>(passCompTableResponse2.data());
1682 rc = decode_pass_component_table_resp(
1683 responseMsg2, sizeof(pldm_pass_component_table_resp), &completionCode,
1684 &compResp, &compRespCode);
1685 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1686
1687 constexpr std::array<uint8_t,
1688 hdrSize + sizeof(pldm_pass_component_table_resp)>
1689 passCompTableResponse3{0x00, 0x00, 0x00, 0x00, 0x00, 0x0C};
1690 auto responseMsg3 =
1691 reinterpret_cast<const pldm_msg*>(passCompTableResponse3.data());
1692 rc = decode_pass_component_table_resp(
1693 responseMsg3, sizeof(pldm_pass_component_table_resp), &completionCode,
1694 &compResp, &compRespCode);
1695 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1696
1697 constexpr std::array<uint8_t,
1698 hdrSize + sizeof(pldm_pass_component_table_resp)>
1699 passCompTableResponse4{0x00, 0x00, 0x00, 0x00, 0x00, 0xF0};
1700 auto responseMsg4 =
1701 reinterpret_cast<const pldm_msg*>(passCompTableResponse4.data());
1702 rc = decode_pass_component_table_resp(
1703 responseMsg4, sizeof(pldm_pass_component_table_resp), &completionCode,
1704 &compResp, &compRespCode);
1705 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1706}