Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame^] | 1 | #include <bitset> |
| 2 | #include <cstring> |
| 3 | |
| 4 | #include "libpldm/base.h" |
| 5 | #include "libpldm/firmware_update.h" |
| 6 | |
| 7 | #include <gtest/gtest.h> |
| 8 | |
| 9 | constexpr auto hdrSize = sizeof(pldm_msg_hdr); |
| 10 | |
| 11 | TEST(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 | |
| 62 | TEST(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 | |
| 147 | TEST(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 | |
| 238 | TEST(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 | |
| 325 | TEST(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 | |
| 421 | TEST(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 | |
| 527 | TEST(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 | |
| 570 | TEST(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 | |
| 638 | TEST(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 | |
| 689 | TEST(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 | |
| 777 | TEST(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 | } |
| 792 | |
| 793 | TEST(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 | } |
| 834 | |
| 835 | TEST(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 | } |
| 849 | |
| 850 | TEST(GetFirmwareParameters, decodeResponse) |
| 851 | { |
| 852 | // 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"}; |
| 859 | |
| 860 | // 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}; |
| 877 | |
| 878 | constexpr size_t compParamTableSize = |
| 879 | sizeof(pldm_component_parameter_entry) + activeCompVersion.size() + |
| 880 | pendingCompVersion.size(); |
| 881 | |
| 882 | 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}; |
| 889 | |
| 890 | 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); |
| 919 | |
| 920 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 921 | EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS); |
| 922 | 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 | } |
| 944 | |
| 945 | TEST(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 | |
| 1000 | TEST(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 | |
| 1052 | TEST(GetFirmwareParameters, decodeResponseErrorCompletionCode) |
| 1053 | { |
| 1054 | constexpr std::array<uint8_t, hdrSize + sizeof(uint8_t)> |
| 1055 | getFwParamsResponse{0x00, 0x00, 0x00, 0x01}; |
| 1056 | |
| 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 | |
| 1073 | TEST(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( |
| 1089 | nullptr, invalidGetFwParamsResponse1.size() - hdrSize, &outResp, |
| 1090 | &outActiveCompImageSetVersion, &outPendingCompImageSetVersion, |
| 1091 | &outCompParameterTable); |
| 1092 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1093 | |
| 1094 | rc = decode_get_firmware_parameters_resp( |
| 1095 | responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, nullptr, |
| 1096 | &outActiveCompImageSetVersion, &outPendingCompImageSetVersion, |
| 1097 | &outCompParameterTable); |
| 1098 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1099 | |
| 1100 | rc = decode_get_firmware_parameters_resp( |
| 1101 | responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp, |
| 1102 | nullptr, &outPendingCompImageSetVersion, &outCompParameterTable); |
| 1103 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1104 | |
| 1105 | rc = decode_get_firmware_parameters_resp( |
| 1106 | responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp, |
| 1107 | &outActiveCompImageSetVersion, nullptr, &outCompParameterTable); |
| 1108 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1109 | |
| 1110 | rc = decode_get_firmware_parameters_resp( |
| 1111 | responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp, |
| 1112 | &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); |
| 1118 | 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); |
| 1124 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1125 | |
| 1126 | rc = decode_get_firmware_parameters_resp( |
| 1127 | responseMsg, invalidGetFwParamsResponse1.size() - hdrSize, &outResp, |
| 1128 | &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( |
| 1139 | responseMsg, invalidGetFwParamsResponse2.size() - hdrSize, &outResp, |
| 1140 | &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( |
| 1152 | responseMsg, invalidGetFwParamsResponse3.size() - hdrSize, &outResp, |
| 1153 | &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( |
| 1165 | responseMsg, invalidGetFwParamsResponse4.size() - hdrSize, &outResp, |
| 1166 | &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( |
| 1177 | responseMsg, invalidGetFwParamsResponse5.size() - hdrSize, &outResp, |
| 1178 | &outActiveCompImageSetVersion, &outPendingCompImageSetVersion, |
| 1179 | &outCompParameterTable); |
| 1180 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1181 | } |
| 1182 | |
| 1183 | TEST(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 | } |
| 1273 | |
| 1274 | TEST(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 | |
| 1309 | TEST(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 | } |
| 1400 | |
| 1401 | TEST(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 | |
| 1437 | TEST(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 | } |
| 1478 | |
| 1479 | TEST(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 | |
| 1511 | TEST(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 | } |
| 1586 | |
| 1587 | TEST(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 | |
| 1636 | TEST(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 | } |
| 1707 | |
| 1708 | TEST(UpdateComponent, goodPathEncodeRequest) |
| 1709 | { |
| 1710 | constexpr uint8_t instanceId = 2; |
| 1711 | constexpr uint16_t compIdentifier = 500; |
| 1712 | constexpr uint8_t compClassificationIndex = 50; |
| 1713 | constexpr uint32_t compComparisonStamp = 0x89ABCDEF; |
| 1714 | constexpr uint32_t compImageSize = 4096; |
| 1715 | constexpr bitfield32_t updateOptionFlags{1}; |
| 1716 | constexpr std::string_view compVerStr = "OpenBmcv2.2"; |
| 1717 | constexpr uint8_t compVerStrLen = static_cast<uint8_t>(compVerStr.size()); |
| 1718 | variable_field compVerStrInfo{}; |
| 1719 | compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data()); |
| 1720 | compVerStrInfo.length = compVerStrLen; |
| 1721 | |
| 1722 | std::array<uint8_t, |
| 1723 | hdrSize + sizeof(pldm_update_component_req) + compVerStrLen> |
| 1724 | request{}; |
| 1725 | auto requestMsg = reinterpret_cast<pldm_msg*>(request.data()); |
| 1726 | |
| 1727 | auto rc = encode_update_component_req( |
| 1728 | instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex, |
| 1729 | compComparisonStamp, compImageSize, updateOptionFlags, |
| 1730 | PLDM_STR_TYPE_ASCII, compVerStrLen, &compVerStrInfo, requestMsg, |
| 1731 | sizeof(pldm_update_component_req) + compVerStrLen); |
| 1732 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1733 | |
| 1734 | std::array<uint8_t, |
| 1735 | hdrSize + sizeof(pldm_update_component_req) + compVerStrLen> |
| 1736 | outRequest{0x82, 0x05, 0x14, 0x0A, 0x00, 0xF4, 0x01, 0x32, 0xEF, |
| 1737 | 0xCD, 0xAB, 0x89, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00, |
| 1738 | 0x00, 0x00, 0x01, 0x0B, 0x4f, 0x70, 0x65, 0x6E, 0x42, |
| 1739 | 0x6D, 0x63, 0x76, 0x32, 0x2E, 0x32}; |
| 1740 | EXPECT_EQ(request, outRequest); |
| 1741 | } |
| 1742 | |
| 1743 | TEST(UpdateComponent, errorPathEncodeRequest) |
| 1744 | { |
| 1745 | constexpr uint8_t instanceId = 2; |
| 1746 | constexpr uint16_t compIdentifier = 500; |
| 1747 | constexpr uint8_t compClassificationIndex = 50; |
| 1748 | constexpr uint32_t compComparisonStamp = 0x89ABCDEF; |
| 1749 | constexpr uint32_t compImageSize = 4096; |
| 1750 | constexpr bitfield32_t updateOptionFlags{1}; |
| 1751 | constexpr std::string_view compVerStr = "OpenBmcv2.2"; |
| 1752 | constexpr uint8_t compVerStrLen = static_cast<uint8_t>(compVerStr.size()); |
| 1753 | variable_field compVerStrInfo{}; |
| 1754 | compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data()); |
| 1755 | compVerStrInfo.length = compVerStrLen; |
| 1756 | |
| 1757 | std::array<uint8_t, |
| 1758 | hdrSize + sizeof(pldm_update_component_req) + compVerStrLen> |
| 1759 | request{}; |
| 1760 | auto requestMsg = reinterpret_cast<pldm_msg*>(request.data()); |
| 1761 | |
| 1762 | auto rc = encode_update_component_req( |
| 1763 | instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex, |
| 1764 | compComparisonStamp, compImageSize, updateOptionFlags, |
| 1765 | PLDM_STR_TYPE_ASCII, compVerStrLen, nullptr, requestMsg, |
| 1766 | sizeof(pldm_update_component_req) + compVerStrLen); |
| 1767 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1768 | |
| 1769 | compVerStrInfo.ptr = nullptr; |
| 1770 | rc = encode_update_component_req( |
| 1771 | instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex, |
| 1772 | compComparisonStamp, compImageSize, updateOptionFlags, |
| 1773 | PLDM_STR_TYPE_ASCII, compVerStrLen, &compVerStrInfo, requestMsg, |
| 1774 | sizeof(pldm_update_component_req) + compVerStrLen); |
| 1775 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1776 | compVerStrInfo.ptr = reinterpret_cast<const uint8_t*>(compVerStr.data()); |
| 1777 | |
| 1778 | rc = encode_update_component_req( |
| 1779 | instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex, |
| 1780 | compComparisonStamp, compImageSize, updateOptionFlags, |
| 1781 | PLDM_STR_TYPE_ASCII, compVerStrLen, &compVerStrInfo, nullptr, |
| 1782 | sizeof(pldm_update_component_req) + compVerStrLen); |
| 1783 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1784 | |
| 1785 | rc = encode_update_component_req( |
| 1786 | instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex, |
| 1787 | compComparisonStamp, compImageSize, updateOptionFlags, |
| 1788 | PLDM_STR_TYPE_ASCII, compVerStrLen, &compVerStrInfo, requestMsg, |
| 1789 | sizeof(pldm_update_component_req)); |
| 1790 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1791 | |
| 1792 | rc = encode_update_component_req( |
| 1793 | instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex, |
| 1794 | compComparisonStamp, 0, updateOptionFlags, PLDM_STR_TYPE_ASCII, |
| 1795 | compVerStrLen, &compVerStrInfo, requestMsg, |
| 1796 | sizeof(pldm_update_component_req) + compVerStrLen); |
| 1797 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1798 | |
| 1799 | rc = encode_update_component_req( |
| 1800 | instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex, |
| 1801 | compComparisonStamp, compImageSize, updateOptionFlags, |
| 1802 | PLDM_STR_TYPE_ASCII, 0, &compVerStrInfo, requestMsg, |
| 1803 | sizeof(pldm_update_component_req) + compVerStrLen); |
| 1804 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1805 | |
| 1806 | rc = encode_update_component_req( |
| 1807 | instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex, |
| 1808 | compComparisonStamp, compImageSize, updateOptionFlags, |
| 1809 | PLDM_STR_TYPE_ASCII, compVerStrLen - 1, &compVerStrInfo, requestMsg, |
| 1810 | sizeof(pldm_update_component_req) + compVerStrLen); |
| 1811 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1812 | |
| 1813 | rc = encode_update_component_req( |
| 1814 | instanceId, PLDM_COMP_FIRMWARE, compIdentifier, compClassificationIndex, |
| 1815 | compComparisonStamp, compImageSize, updateOptionFlags, |
| 1816 | PLDM_STR_TYPE_UNKNOWN, compVerStrLen, &compVerStrInfo, requestMsg, |
| 1817 | sizeof(pldm_update_component_req) + compVerStrLen); |
| 1818 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1819 | } |
| 1820 | |
| 1821 | TEST(UpdateComponent, goodPathDecodeResponse) |
| 1822 | { |
| 1823 | constexpr std::bitset<32> forceUpdateComp{1}; |
| 1824 | constexpr uint16_t timeBeforeSendingReqFwData100s = 100; |
| 1825 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)> |
| 1826 | updateComponentResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1827 | 0x01, 0x00, 0x00, 0x00, 0x64, 0x00}; |
| 1828 | auto responseMsg1 = |
| 1829 | reinterpret_cast<const pldm_msg*>(updateComponentResponse1.data()); |
| 1830 | |
| 1831 | uint8_t completionCode = 0; |
| 1832 | uint8_t compCompatibilityResp = 0; |
| 1833 | uint8_t compCompatibilityRespCode = 0; |
| 1834 | bitfield32_t updateOptionFlagsEnabled{}; |
| 1835 | uint16_t timeBeforeReqFWData = 0; |
| 1836 | |
| 1837 | auto rc = decode_update_component_resp( |
| 1838 | responseMsg1, sizeof(pldm_update_component_resp), &completionCode, |
| 1839 | &compCompatibilityResp, &compCompatibilityRespCode, |
| 1840 | &updateOptionFlagsEnabled, &timeBeforeReqFWData); |
| 1841 | |
| 1842 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1843 | EXPECT_EQ(completionCode, PLDM_SUCCESS); |
| 1844 | EXPECT_EQ(compCompatibilityResp, PLDM_CCR_COMP_CAN_BE_UPDATED); |
| 1845 | EXPECT_EQ(compCompatibilityRespCode, PLDM_CCRC_NO_RESPONSE_CODE); |
| 1846 | EXPECT_EQ(updateOptionFlagsEnabled.value, forceUpdateComp); |
| 1847 | EXPECT_EQ(timeBeforeReqFWData, timeBeforeSendingReqFwData100s); |
| 1848 | |
| 1849 | constexpr std::bitset<32> noFlags{}; |
| 1850 | constexpr uint16_t timeBeforeSendingReqFwData0s = 0; |
| 1851 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)> |
| 1852 | updateComponentResponse2{0x00, 0x00, 0x00, 0x00, 0x01, 0x09, |
| 1853 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 1854 | auto responseMsg2 = |
| 1855 | reinterpret_cast<const pldm_msg*>(updateComponentResponse2.data()); |
| 1856 | rc = decode_update_component_resp( |
| 1857 | responseMsg2, sizeof(pldm_update_component_resp), &completionCode, |
| 1858 | &compCompatibilityResp, &compCompatibilityRespCode, |
| 1859 | &updateOptionFlagsEnabled, &timeBeforeReqFWData); |
| 1860 | |
| 1861 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1862 | EXPECT_EQ(completionCode, PLDM_SUCCESS); |
| 1863 | EXPECT_EQ(compCompatibilityResp, PLDM_CCR_COMP_CANNOT_BE_UPDATED); |
| 1864 | EXPECT_EQ(compCompatibilityRespCode, PLDM_CCRC_COMP_INFO_NO_MATCH); |
| 1865 | EXPECT_EQ(updateOptionFlagsEnabled.value, noFlags); |
| 1866 | EXPECT_EQ(timeBeforeReqFWData, timeBeforeSendingReqFwData0s); |
| 1867 | |
| 1868 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)> |
| 1869 | updateComponentResponse3{0x00, 0x00, 0x00, 0x80}; |
| 1870 | auto responseMsg3 = |
| 1871 | reinterpret_cast<const pldm_msg*>(updateComponentResponse3.data()); |
| 1872 | |
| 1873 | rc = decode_update_component_resp( |
| 1874 | responseMsg3, sizeof(pldm_update_component_resp), &completionCode, |
| 1875 | &compCompatibilityResp, &compCompatibilityRespCode, |
| 1876 | &updateOptionFlagsEnabled, &timeBeforeReqFWData); |
| 1877 | |
| 1878 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1879 | EXPECT_EQ(completionCode, PLDM_FWUP_NOT_IN_UPDATE_MODE); |
| 1880 | } |
| 1881 | |
| 1882 | TEST(UpdateComponent, errorPathDecodeResponse) |
| 1883 | { |
| 1884 | constexpr std::array<uint8_t, |
| 1885 | hdrSize + sizeof(pldm_update_component_resp) - 1> |
| 1886 | updateComponentResponse1{0x00, 0x00, 0x00, 0x00, 0x01, 0x09, |
| 1887 | 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 1888 | auto responseMsg1 = |
| 1889 | reinterpret_cast<const pldm_msg*>(updateComponentResponse1.data()); |
| 1890 | |
| 1891 | uint8_t completionCode = 0; |
| 1892 | uint8_t compCompatibilityResp = 0; |
| 1893 | uint8_t compCompatibilityRespCode = 0; |
| 1894 | bitfield32_t updateOptionFlagsEnabled{}; |
| 1895 | uint16_t timeBeforeReqFWData = 0; |
| 1896 | |
| 1897 | auto rc = decode_update_component_resp( |
| 1898 | nullptr, sizeof(pldm_update_component_resp) - 1, &completionCode, |
| 1899 | &compCompatibilityResp, &compCompatibilityRespCode, |
| 1900 | &updateOptionFlagsEnabled, &timeBeforeReqFWData); |
| 1901 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1902 | |
| 1903 | rc = decode_update_component_resp( |
| 1904 | responseMsg1, sizeof(pldm_update_component_resp) - 1, nullptr, |
| 1905 | &compCompatibilityResp, &compCompatibilityRespCode, |
| 1906 | &updateOptionFlagsEnabled, &timeBeforeReqFWData); |
| 1907 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1908 | |
| 1909 | rc = decode_update_component_resp( |
| 1910 | responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode, |
| 1911 | nullptr, &compCompatibilityRespCode, &updateOptionFlagsEnabled, |
| 1912 | &timeBeforeReqFWData); |
| 1913 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1914 | |
| 1915 | rc = decode_update_component_resp( |
| 1916 | responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode, |
| 1917 | &compCompatibilityResp, nullptr, &updateOptionFlagsEnabled, |
| 1918 | &timeBeforeReqFWData); |
| 1919 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1920 | |
| 1921 | rc = decode_update_component_resp( |
| 1922 | responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode, |
| 1923 | &compCompatibilityResp, &compCompatibilityRespCode, nullptr, |
| 1924 | &timeBeforeReqFWData); |
| 1925 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1926 | |
| 1927 | rc = decode_update_component_resp( |
| 1928 | responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode, |
| 1929 | &compCompatibilityResp, &compCompatibilityRespCode, |
| 1930 | &updateOptionFlagsEnabled, nullptr); |
| 1931 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1932 | |
| 1933 | rc = decode_update_component_resp( |
| 1934 | responseMsg1, 0, &completionCode, &compCompatibilityResp, |
| 1935 | &compCompatibilityRespCode, &updateOptionFlagsEnabled, |
| 1936 | &timeBeforeReqFWData); |
| 1937 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1938 | |
| 1939 | rc = decode_update_component_resp( |
| 1940 | responseMsg1, sizeof(pldm_update_component_resp) - 1, &completionCode, |
| 1941 | &compCompatibilityResp, &compCompatibilityRespCode, |
| 1942 | &updateOptionFlagsEnabled, &timeBeforeReqFWData); |
| 1943 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1944 | |
| 1945 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)> |
| 1946 | updateComponentResponse2{0x00, 0x00, 0x00, 0x00, 0x02, 0x00, |
| 1947 | 0x01, 0x00, 0x00, 0x00, 0x64, 0x00}; |
| 1948 | auto responseMsg2 = |
| 1949 | reinterpret_cast<const pldm_msg*>(updateComponentResponse2.data()); |
| 1950 | rc = decode_update_component_resp( |
| 1951 | responseMsg2, sizeof(pldm_update_component_resp), &completionCode, |
| 1952 | &compCompatibilityResp, &compCompatibilityRespCode, |
| 1953 | &updateOptionFlagsEnabled, &timeBeforeReqFWData); |
| 1954 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1955 | |
| 1956 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)> |
| 1957 | updateComponentResponse3{0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, |
| 1958 | 0x01, 0x00, 0x00, 0x00, 0x64, 0x00}; |
| 1959 | auto responseMsg3 = |
| 1960 | reinterpret_cast<const pldm_msg*>(updateComponentResponse3.data()); |
| 1961 | rc = decode_update_component_resp( |
| 1962 | responseMsg3, sizeof(pldm_update_component_resp), &completionCode, |
| 1963 | &compCompatibilityResp, &compCompatibilityRespCode, |
| 1964 | &updateOptionFlagsEnabled, &timeBeforeReqFWData); |
| 1965 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1966 | |
| 1967 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_update_component_resp)> |
| 1968 | updateComponentResponse4{0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, |
| 1969 | 0x01, 0x00, 0x00, 0x00, 0x64, 0x00}; |
| 1970 | auto responseMsg4 = |
| 1971 | reinterpret_cast<const pldm_msg*>(updateComponentResponse4.data()); |
| 1972 | rc = decode_update_component_resp( |
| 1973 | responseMsg4, sizeof(pldm_update_component_resp), &completionCode, |
| 1974 | &compCompatibilityResp, &compCompatibilityRespCode, |
| 1975 | &updateOptionFlagsEnabled, &timeBeforeReqFWData); |
| 1976 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1977 | } |
| 1978 | |
| 1979 | TEST(RequestFirmwareData, goodPathDecodeRequest) |
| 1980 | { |
| 1981 | constexpr uint32_t offset = 300; |
| 1982 | constexpr uint32_t length = 255; |
| 1983 | constexpr std::array<uint8_t, |
| 1984 | hdrSize + sizeof(pldm_request_firmware_data_req)> |
| 1985 | reqFWDataReq{0x00, 0x00, 0x00, 0x2C, 0x01, 0x00, |
| 1986 | 0x00, 0xFF, 0x00, 0x00, 0x00}; |
| 1987 | auto requestMsg = reinterpret_cast<const pldm_msg*>(reqFWDataReq.data()); |
| 1988 | |
| 1989 | uint32_t outOffset = 0; |
| 1990 | uint32_t outLength = 0; |
| 1991 | auto rc = decode_request_firmware_data_req( |
| 1992 | requestMsg, sizeof(pldm_request_firmware_data_req), &outOffset, |
| 1993 | &outLength); |
| 1994 | |
| 1995 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1996 | EXPECT_EQ(outOffset, offset); |
| 1997 | EXPECT_EQ(outLength, length); |
| 1998 | } |
| 1999 | |
| 2000 | TEST(RequestFirmwareData, errorPathDecodeRequest) |
| 2001 | { |
| 2002 | constexpr std::array<uint8_t, |
| 2003 | hdrSize + sizeof(pldm_request_firmware_data_req)> |
| 2004 | reqFWDataReq{0x00, 0x00, 0x00, 0x2C, 0x01, 0x00, |
| 2005 | 0x00, 0x1F, 0x00, 0x00, 0x00}; |
| 2006 | auto requestMsg = reinterpret_cast<const pldm_msg*>(reqFWDataReq.data()); |
| 2007 | |
| 2008 | uint32_t outOffset = 0; |
| 2009 | uint32_t outLength = 0; |
| 2010 | auto rc = decode_request_firmware_data_req( |
| 2011 | nullptr, sizeof(pldm_request_firmware_data_req), &outOffset, |
| 2012 | &outLength); |
| 2013 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2014 | |
| 2015 | rc = decode_request_firmware_data_req( |
| 2016 | requestMsg, sizeof(pldm_request_firmware_data_req), nullptr, |
| 2017 | &outLength); |
| 2018 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2019 | |
| 2020 | rc = decode_request_firmware_data_req( |
| 2021 | requestMsg, sizeof(pldm_request_firmware_data_req), &outOffset, |
| 2022 | nullptr); |
| 2023 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2024 | |
| 2025 | rc = decode_request_firmware_data_req( |
| 2026 | requestMsg, sizeof(pldm_request_firmware_data_req) - 1, &outOffset, |
| 2027 | &outLength); |
| 2028 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2029 | |
| 2030 | rc = decode_request_firmware_data_req( |
| 2031 | requestMsg, sizeof(pldm_request_firmware_data_req), &outOffset, |
| 2032 | &outLength); |
| 2033 | EXPECT_EQ(rc, PLDM_FWUP_INVALID_TRANSFER_LENGTH); |
| 2034 | } |
| 2035 | |
| 2036 | TEST(RequestFirmwareData, goodPathEncodeResponse) |
| 2037 | { |
| 2038 | constexpr uint8_t instanceId = 3; |
| 2039 | constexpr uint8_t completionCode = PLDM_SUCCESS; |
| 2040 | constexpr std::array<uint8_t, hdrSize + sizeof(completionCode) + |
| 2041 | PLDM_FWUP_BASELINE_TRANSFER_SIZE> |
| 2042 | outReqFwDataResponse1{0x03, 0x05, 0x15, 0x00, 0x01, 0x02, 0x03, 0x04, |
| 2043 | 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, |
| 2044 | 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, |
| 2045 | 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, |
| 2046 | 0x1D, 0x1E, 0x1F, 0x20}; |
| 2047 | std::array<uint8_t, hdrSize + sizeof(completionCode) + |
| 2048 | PLDM_FWUP_BASELINE_TRANSFER_SIZE> |
| 2049 | reqFwDataResponse1{0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, |
| 2050 | 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, |
| 2051 | 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, |
| 2052 | 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, |
| 2053 | 0x1D, 0x1E, 0x1F, 0x20}; |
| 2054 | auto responseMsg1 = reinterpret_cast<pldm_msg*>(reqFwDataResponse1.data()); |
| 2055 | auto rc = encode_request_firmware_data_resp( |
| 2056 | instanceId, completionCode, responseMsg1, |
| 2057 | sizeof(completionCode) + PLDM_FWUP_BASELINE_TRANSFER_SIZE); |
| 2058 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2059 | EXPECT_EQ(reqFwDataResponse1, outReqFwDataResponse1); |
| 2060 | |
| 2061 | constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2062 | outReqFwDataResponse2{0x03, 0x05, 0x15, 0x82}; |
| 2063 | std::array<uint8_t, hdrSize + sizeof(completionCode)> reqFwDataResponse2{ |
| 2064 | 0x00, 0x00, 0x00, 0x00}; |
| 2065 | auto responseMsg2 = reinterpret_cast<pldm_msg*>(reqFwDataResponse2.data()); |
| 2066 | rc = encode_request_firmware_data_resp( |
| 2067 | instanceId, PLDM_FWUP_DATA_OUT_OF_RANGE, responseMsg2, |
| 2068 | sizeof(completionCode)); |
| 2069 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2070 | EXPECT_EQ(reqFwDataResponse2, outReqFwDataResponse2); |
| 2071 | } |
| 2072 | |
| 2073 | TEST(RequestFirmwareData, errorPathEncodeResponse) |
| 2074 | { |
| 2075 | std::array<uint8_t, hdrSize> reqFwDataResponse{0x00, 0x00, 0x00}; |
| 2076 | auto responseMsg = reinterpret_cast<pldm_msg*>(reqFwDataResponse.data()); |
| 2077 | auto rc = encode_request_firmware_data_resp(0, PLDM_SUCCESS, nullptr, 0); |
| 2078 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2079 | |
| 2080 | rc = encode_request_firmware_data_resp(0, PLDM_SUCCESS, responseMsg, 0); |
| 2081 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2082 | } |
| 2083 | |
| 2084 | TEST(TransferComplete, goodPathDecodeRequest) |
| 2085 | { |
| 2086 | constexpr uint8_t transferResult = PLDM_FWUP_TRANSFER_SUCCESS; |
| 2087 | constexpr std::array<uint8_t, hdrSize + sizeof(transferResult)> |
| 2088 | transferCompleteReq1{0x00, 0x00, 0x00, 0x00}; |
| 2089 | auto requestMsg1 = |
| 2090 | reinterpret_cast<const pldm_msg*>(transferCompleteReq1.data()); |
| 2091 | uint8_t outTransferResult = 0; |
| 2092 | |
| 2093 | auto rc = decode_transfer_complete_req(requestMsg1, sizeof(transferResult), |
| 2094 | &outTransferResult); |
| 2095 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2096 | EXPECT_EQ(outTransferResult, transferResult); |
| 2097 | |
| 2098 | constexpr std::array<uint8_t, hdrSize + sizeof(transferResult)> |
| 2099 | transferCompleteReq2{0x00, 0x00, 0x00, 0x02}; |
| 2100 | auto requestMsg2 = |
| 2101 | reinterpret_cast<const pldm_msg*>(transferCompleteReq2.data()); |
| 2102 | rc = decode_transfer_complete_req(requestMsg2, sizeof(transferResult), |
| 2103 | &outTransferResult); |
| 2104 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2105 | EXPECT_EQ(outTransferResult, PLDM_FWUP_TRANSFER_ERROR_IMAGE_CORRUPT); |
| 2106 | } |
| 2107 | |
| 2108 | TEST(TransferComplete, errorPathDecodeRequest) |
| 2109 | { |
| 2110 | constexpr std::array<uint8_t, hdrSize> transferCompleteReq{0x00, 0x00, |
| 2111 | 0x00}; |
| 2112 | auto requestMsg = |
| 2113 | reinterpret_cast<const pldm_msg*>(transferCompleteReq.data()); |
| 2114 | uint8_t outTransferResult = 0; |
| 2115 | |
| 2116 | auto rc = decode_transfer_complete_req(nullptr, 0, &outTransferResult); |
| 2117 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2118 | |
| 2119 | rc = decode_transfer_complete_req(requestMsg, 0, nullptr); |
| 2120 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2121 | |
| 2122 | rc = decode_transfer_complete_req(requestMsg, 0, &outTransferResult); |
| 2123 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2124 | } |
| 2125 | |
| 2126 | TEST(TransferComplete, goodPathEncodeResponse) |
| 2127 | { |
| 2128 | constexpr uint8_t instanceId = 4; |
| 2129 | constexpr uint8_t completionCode = PLDM_SUCCESS; |
| 2130 | constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2131 | outTransferCompleteResponse1{0x04, 0x05, 0x16, 0x00}; |
| 2132 | std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2133 | transferCompleteResponse1{0x00, 0x00, 0x00, 0x00}; |
| 2134 | auto responseMsg1 = |
| 2135 | reinterpret_cast<pldm_msg*>(transferCompleteResponse1.data()); |
| 2136 | auto rc = encode_transfer_complete_resp( |
| 2137 | instanceId, completionCode, responseMsg1, sizeof(completionCode)); |
| 2138 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2139 | EXPECT_EQ(transferCompleteResponse1, outTransferCompleteResponse1); |
| 2140 | |
| 2141 | constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2142 | outTransferCompleteResponse2{0x04, 0x05, 0x16, 0x87}; |
| 2143 | std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2144 | transferCompleteResponse2{0x00, 0x00, 0x00, 0x00}; |
| 2145 | auto responseMsg2 = |
| 2146 | reinterpret_cast<pldm_msg*>(transferCompleteResponse2.data()); |
| 2147 | rc = encode_transfer_complete_resp(instanceId, |
| 2148 | PLDM_FWUP_COMMAND_NOT_EXPECTED, |
| 2149 | responseMsg2, sizeof(completionCode)); |
| 2150 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2151 | EXPECT_EQ(transferCompleteResponse2, outTransferCompleteResponse2); |
| 2152 | } |
| 2153 | |
| 2154 | TEST(TransferComplete, errorPathEncodeResponse) |
| 2155 | { |
| 2156 | std::array<uint8_t, hdrSize> transferCompleteResponse{0x00, 0x00, 0x00}; |
| 2157 | auto responseMsg = |
| 2158 | reinterpret_cast<pldm_msg*>(transferCompleteResponse.data()); |
| 2159 | auto rc = encode_transfer_complete_resp(0, PLDM_SUCCESS, nullptr, 0); |
| 2160 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2161 | |
| 2162 | rc = encode_transfer_complete_resp(0, PLDM_SUCCESS, responseMsg, 0); |
| 2163 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2164 | } |
| 2165 | |
| 2166 | TEST(VerifyComplete, goodPathDecodeRequest) |
| 2167 | { |
| 2168 | constexpr uint8_t verifyResult = PLDM_FWUP_VERIFY_SUCCESS; |
| 2169 | constexpr std::array<uint8_t, hdrSize + sizeof(verifyResult)> |
| 2170 | verifyCompleteReq1{0x00, 0x00, 0x00, 0x00}; |
| 2171 | auto requestMsg1 = |
| 2172 | reinterpret_cast<const pldm_msg*>(verifyCompleteReq1.data()); |
| 2173 | uint8_t outVerifyResult = 0; |
| 2174 | |
| 2175 | auto rc = decode_verify_complete_req(requestMsg1, sizeof(verifyResult), |
| 2176 | &outVerifyResult); |
| 2177 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2178 | EXPECT_EQ(outVerifyResult, verifyResult); |
| 2179 | |
| 2180 | constexpr std::array<uint8_t, hdrSize + sizeof(verifyResult)> |
| 2181 | verifyCompleteReq2{0x00, 0x00, 0x00, 0x03}; |
| 2182 | auto requestMsg2 = |
| 2183 | reinterpret_cast<const pldm_msg*>(verifyCompleteReq2.data()); |
| 2184 | rc = decode_verify_complete_req(requestMsg2, sizeof(verifyResult), |
| 2185 | &outVerifyResult); |
| 2186 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2187 | EXPECT_EQ(outVerifyResult, PLDM_FWUP_VERIFY_FAILED_FD_SECURITY_CHECKS); |
| 2188 | } |
| 2189 | |
| 2190 | TEST(VerifyComplete, errorPathDecodeRequest) |
| 2191 | { |
| 2192 | constexpr std::array<uint8_t, hdrSize> verifyCompleteReq{0x00, 0x00, 0x00}; |
| 2193 | auto requestMsg = |
| 2194 | reinterpret_cast<const pldm_msg*>(verifyCompleteReq.data()); |
| 2195 | uint8_t outVerifyResult = 0; |
| 2196 | |
| 2197 | auto rc = decode_verify_complete_req(nullptr, 0, &outVerifyResult); |
| 2198 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2199 | |
| 2200 | rc = decode_verify_complete_req(requestMsg, 0, nullptr); |
| 2201 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2202 | |
| 2203 | rc = decode_verify_complete_req(requestMsg, 0, &outVerifyResult); |
| 2204 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2205 | } |
| 2206 | |
| 2207 | TEST(VerifyComplete, goodPathEncodeResponse) |
| 2208 | { |
| 2209 | constexpr uint8_t instanceId = 5; |
| 2210 | constexpr uint8_t completionCode = PLDM_SUCCESS; |
| 2211 | constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2212 | outVerifyCompleteResponse1{0x05, 0x05, 0x17, 0x00}; |
| 2213 | std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2214 | verifyCompleteResponse1{0x00, 0x00, 0x00, 0x00}; |
| 2215 | auto responseMsg1 = |
| 2216 | reinterpret_cast<pldm_msg*>(verifyCompleteResponse1.data()); |
| 2217 | auto rc = encode_verify_complete_resp(instanceId, completionCode, |
| 2218 | responseMsg1, sizeof(completionCode)); |
| 2219 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2220 | EXPECT_EQ(verifyCompleteResponse1, outVerifyCompleteResponse1); |
| 2221 | |
| 2222 | constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2223 | outVerifyCompleteResponse2{0x05, 0x05, 0x17, 0x87}; |
| 2224 | std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2225 | verifyCompleteResponse2{0x00, 0x00, 0x00, 0x00}; |
| 2226 | auto responseMsg2 = |
| 2227 | reinterpret_cast<pldm_msg*>(verifyCompleteResponse2.data()); |
| 2228 | rc = encode_verify_complete_resp(instanceId, PLDM_FWUP_COMMAND_NOT_EXPECTED, |
| 2229 | responseMsg2, sizeof(completionCode)); |
| 2230 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2231 | EXPECT_EQ(verifyCompleteResponse2, outVerifyCompleteResponse2); |
| 2232 | } |
| 2233 | |
| 2234 | TEST(VerifyComplete, errorPathEncodeResponse) |
| 2235 | { |
| 2236 | std::array<uint8_t, hdrSize> verifyCompleteResponse{0x00, 0x00, 0x00}; |
| 2237 | auto responseMsg = |
| 2238 | reinterpret_cast<pldm_msg*>(verifyCompleteResponse.data()); |
| 2239 | auto rc = encode_verify_complete_resp(0, PLDM_SUCCESS, nullptr, 0); |
| 2240 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2241 | |
| 2242 | rc = encode_verify_complete_resp(0, PLDM_SUCCESS, responseMsg, 0); |
| 2243 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2244 | } |
| 2245 | |
| 2246 | TEST(ApplyComplete, goodPathDecodeRequest) |
| 2247 | { |
| 2248 | constexpr uint8_t applyResult1 = |
| 2249 | PLDM_FWUP_APPLY_SUCCESS_WITH_ACTIVATION_METHOD; |
| 2250 | // DC power cycle [Bit position 4] & AC power cycle [Bit position 5] |
| 2251 | constexpr std::bitset<16> compActivationModification1{0x30}; |
| 2252 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_apply_complete_req)> |
| 2253 | applyCompleteReq1{0x00, 0x00, 0x00, 0x01, 0x30, 0x00}; |
| 2254 | auto requestMsg1 = |
| 2255 | reinterpret_cast<const pldm_msg*>(applyCompleteReq1.data()); |
| 2256 | uint8_t outApplyResult = 0; |
| 2257 | bitfield16_t outCompActivationModification{}; |
| 2258 | auto rc = decode_apply_complete_req( |
| 2259 | requestMsg1, sizeof(pldm_apply_complete_req), &outApplyResult, |
| 2260 | &outCompActivationModification); |
| 2261 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2262 | EXPECT_EQ(outApplyResult, applyResult1); |
| 2263 | EXPECT_EQ(outCompActivationModification.value, compActivationModification1); |
| 2264 | |
| 2265 | constexpr uint8_t applyResult2 = PLDM_FWUP_APPLY_SUCCESS; |
| 2266 | constexpr std::bitset<16> compActivationModification2{}; |
| 2267 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_apply_complete_req)> |
| 2268 | applyCompleteReq2{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 2269 | auto requestMsg2 = |
| 2270 | reinterpret_cast<const pldm_msg*>(applyCompleteReq2.data()); |
| 2271 | rc = decode_apply_complete_req(requestMsg2, sizeof(pldm_apply_complete_req), |
| 2272 | &outApplyResult, |
| 2273 | &outCompActivationModification); |
| 2274 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2275 | EXPECT_EQ(outApplyResult, applyResult2); |
| 2276 | EXPECT_EQ(outCompActivationModification.value, compActivationModification2); |
| 2277 | } |
| 2278 | |
| 2279 | TEST(ApplyComplete, errorPathDecodeRequest) |
| 2280 | { |
| 2281 | constexpr std::array<uint8_t, hdrSize> applyCompleteReq1{0x00, 0x00, 0x00}; |
| 2282 | auto requestMsg1 = |
| 2283 | reinterpret_cast<const pldm_msg*>(applyCompleteReq1.data()); |
| 2284 | uint8_t outApplyResult = 0; |
| 2285 | bitfield16_t outCompActivationModification{}; |
| 2286 | |
| 2287 | auto rc = decode_apply_complete_req( |
| 2288 | nullptr, sizeof(pldm_apply_complete_req), &outApplyResult, |
| 2289 | &outCompActivationModification); |
| 2290 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2291 | |
| 2292 | rc = decode_apply_complete_req(requestMsg1, sizeof(pldm_apply_complete_req), |
| 2293 | nullptr, &outCompActivationModification); |
| 2294 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2295 | |
| 2296 | rc = decode_apply_complete_req(requestMsg1, sizeof(pldm_apply_complete_req), |
| 2297 | &outApplyResult, nullptr); |
| 2298 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2299 | |
| 2300 | rc = decode_apply_complete_req(requestMsg1, 0, &outApplyResult, |
| 2301 | &outCompActivationModification); |
| 2302 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2303 | |
| 2304 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_apply_complete_req)> |
| 2305 | applyCompleteReq2{0x00, 0x00, 0x00, 0x00, 0x01, 0x00}; |
| 2306 | auto requestMsg2 = |
| 2307 | reinterpret_cast<const pldm_msg*>(applyCompleteReq2.data()); |
| 2308 | rc = decode_apply_complete_req(requestMsg2, sizeof(pldm_apply_complete_req), |
| 2309 | &outApplyResult, |
| 2310 | &outCompActivationModification); |
| 2311 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2312 | } |
| 2313 | |
| 2314 | TEST(ApplyComplete, goodPathEncodeResponse) |
| 2315 | { |
| 2316 | constexpr uint8_t instanceId = 6; |
| 2317 | constexpr uint8_t completionCode = PLDM_SUCCESS; |
| 2318 | constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2319 | outApplyCompleteResponse1{0x06, 0x05, 0x18, 0x00}; |
| 2320 | std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2321 | applyCompleteResponse1{0x00, 0x00, 0x00, 0x00}; |
| 2322 | auto responseMsg1 = |
| 2323 | reinterpret_cast<pldm_msg*>(applyCompleteResponse1.data()); |
| 2324 | auto rc = encode_apply_complete_resp(instanceId, completionCode, |
| 2325 | responseMsg1, sizeof(completionCode)); |
| 2326 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2327 | EXPECT_EQ(applyCompleteResponse1, outApplyCompleteResponse1); |
| 2328 | |
| 2329 | constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2330 | outApplyCompleteResponse2{0x06, 0x05, 0x18, 0x87}; |
| 2331 | std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2332 | applyCompleteResponse2{0x00, 0x00, 0x00, 0x00}; |
| 2333 | auto responseMsg2 = |
| 2334 | reinterpret_cast<pldm_msg*>(applyCompleteResponse2.data()); |
| 2335 | rc = encode_apply_complete_resp(instanceId, PLDM_FWUP_COMMAND_NOT_EXPECTED, |
| 2336 | responseMsg2, sizeof(completionCode)); |
| 2337 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2338 | EXPECT_EQ(applyCompleteResponse2, outApplyCompleteResponse2); |
| 2339 | } |
| 2340 | |
| 2341 | TEST(ApplyComplete, errorPathEncodeResponse) |
| 2342 | { |
| 2343 | std::array<uint8_t, hdrSize> applyCompleteResponse{0x00, 0x00, 0x00}; |
| 2344 | auto responseMsg = |
| 2345 | reinterpret_cast<pldm_msg*>(applyCompleteResponse.data()); |
| 2346 | auto rc = encode_apply_complete_resp(0, PLDM_SUCCESS, nullptr, 0); |
| 2347 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2348 | |
| 2349 | rc = encode_apply_complete_resp(0, PLDM_SUCCESS, responseMsg, 0); |
| 2350 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2351 | } |
| 2352 | |
| 2353 | TEST(ActivateFirmware, goodPathEncodeRequest) |
| 2354 | { |
| 2355 | constexpr uint8_t instanceId = 7; |
| 2356 | |
| 2357 | std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_req)> request{}; |
| 2358 | auto requestMsg = reinterpret_cast<pldm_msg*>(request.data()); |
| 2359 | |
| 2360 | auto rc = encode_activate_firmware_req( |
| 2361 | instanceId, PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS, requestMsg, |
| 2362 | sizeof(pldm_activate_firmware_req)); |
| 2363 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2364 | |
| 2365 | std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_req)> |
| 2366 | outRequest{0x87, 0x05, 0x1A, 0x01}; |
| 2367 | EXPECT_EQ(request, outRequest); |
| 2368 | } |
| 2369 | |
| 2370 | TEST(ActivateFirmware, errorPathEncodeRequest) |
| 2371 | { |
| 2372 | std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_req)> request{}; |
| 2373 | auto requestMsg = reinterpret_cast<pldm_msg*>(request.data()); |
| 2374 | |
| 2375 | auto rc = encode_activate_firmware_req( |
| 2376 | 0, PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS, nullptr, |
| 2377 | sizeof(pldm_activate_firmware_req)); |
| 2378 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2379 | |
| 2380 | rc = encode_activate_firmware_req( |
| 2381 | 0, PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS, requestMsg, 0); |
| 2382 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2383 | |
| 2384 | rc = encode_activate_firmware_req(0, 2, requestMsg, |
| 2385 | sizeof(pldm_activate_firmware_req)); |
| 2386 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2387 | } |
| 2388 | |
| 2389 | TEST(ActivateFirmware, goodPathDecodeResponse) |
| 2390 | { |
| 2391 | constexpr uint16_t estimatedTimeForActivation100s = 100; |
| 2392 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_resp)> |
| 2393 | activateFirmwareResponse1{0x00, 0x00, 0x00, 0x00, 0x64, 0x00}; |
| 2394 | auto responseMsg1 = |
| 2395 | reinterpret_cast<const pldm_msg*>(activateFirmwareResponse1.data()); |
| 2396 | |
| 2397 | uint8_t completionCode = 0; |
| 2398 | uint16_t estimatedTimeForActivation = 0; |
| 2399 | |
| 2400 | auto rc = decode_activate_firmware_resp( |
| 2401 | responseMsg1, sizeof(pldm_activate_firmware_resp), &completionCode, |
| 2402 | &estimatedTimeForActivation); |
| 2403 | |
| 2404 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2405 | EXPECT_EQ(completionCode, PLDM_SUCCESS); |
| 2406 | EXPECT_EQ(estimatedTimeForActivation, estimatedTimeForActivation100s); |
| 2407 | |
| 2408 | constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2409 | activateFirmwareResponse2{0x00, 0x00, 0x00, 0x85}; |
| 2410 | auto responseMsg2 = |
| 2411 | reinterpret_cast<const pldm_msg*>(activateFirmwareResponse2.data()); |
| 2412 | |
| 2413 | rc = decode_activate_firmware_resp(responseMsg2, sizeof(completionCode), |
| 2414 | &completionCode, |
| 2415 | &estimatedTimeForActivation); |
| 2416 | |
| 2417 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2418 | EXPECT_EQ(completionCode, PLDM_FWUP_INCOMPLETE_UPDATE); |
| 2419 | } |
| 2420 | |
| 2421 | TEST(ActivateFirmware, errorPathDecodeResponse) |
| 2422 | { |
| 2423 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_activate_firmware_resp)> |
| 2424 | activateFirmwareResponse{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 2425 | auto responseMsg = |
| 2426 | reinterpret_cast<const pldm_msg*>(activateFirmwareResponse.data()); |
| 2427 | |
| 2428 | uint8_t completionCode = 0; |
| 2429 | uint16_t estimatedTimeForActivation = 0; |
| 2430 | |
| 2431 | auto rc = decode_activate_firmware_resp( |
| 2432 | nullptr, sizeof(pldm_activate_firmware_resp), &completionCode, |
| 2433 | &estimatedTimeForActivation); |
| 2434 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2435 | |
| 2436 | rc = decode_activate_firmware_resp(responseMsg, |
| 2437 | sizeof(pldm_activate_firmware_resp), |
| 2438 | nullptr, &estimatedTimeForActivation); |
| 2439 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2440 | |
| 2441 | rc = decode_activate_firmware_resp(responseMsg, |
| 2442 | sizeof(pldm_activate_firmware_resp), |
| 2443 | &completionCode, nullptr); |
| 2444 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2445 | |
| 2446 | rc = decode_activate_firmware_resp(responseMsg, 0, &completionCode, |
| 2447 | &estimatedTimeForActivation); |
| 2448 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2449 | |
| 2450 | rc = decode_activate_firmware_resp( |
| 2451 | responseMsg, sizeof(pldm_activate_firmware_resp) - 1, &completionCode, |
| 2452 | &estimatedTimeForActivation); |
| 2453 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2454 | } |
| 2455 | |
| 2456 | TEST(GetStatus, goodPathEncodeRequest) |
| 2457 | { |
| 2458 | constexpr uint8_t instanceId = 8; |
| 2459 | std::array<uint8_t, hdrSize> request{}; |
| 2460 | auto requestMsg = reinterpret_cast<pldm_msg*>(request.data()); |
| 2461 | |
| 2462 | auto rc = encode_get_status_req(instanceId, requestMsg, |
| 2463 | PLDM_GET_STATUS_REQ_BYTES); |
| 2464 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2465 | |
| 2466 | constexpr std::array<uint8_t, hdrSize> outRequest{0x88, 0x05, 0x1B}; |
| 2467 | EXPECT_EQ(request, outRequest); |
| 2468 | } |
| 2469 | |
| 2470 | TEST(GetStatus, errorPathEncodeRequest) |
| 2471 | { |
| 2472 | std::array<uint8_t, hdrSize + sizeof(uint8_t)> request{}; |
| 2473 | auto requestMsg = reinterpret_cast<pldm_msg*>(request.data()); |
| 2474 | |
| 2475 | auto rc = encode_get_status_req(0, nullptr, PLDM_GET_STATUS_REQ_BYTES); |
| 2476 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2477 | |
| 2478 | rc = encode_get_status_req(0, requestMsg, PLDM_GET_STATUS_REQ_BYTES + 1); |
| 2479 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2480 | } |
| 2481 | |
| 2482 | TEST(GetStatus, goodPathDecodeResponse) |
| 2483 | { |
| 2484 | constexpr std::bitset<32> updateOptionFlagsEnabled1{0}; |
| 2485 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)> |
| 2486 | getStatusResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, |
| 2487 | 0x09, 0x65, 0x05, 0x00, 0x00, 0x00, 0x00}; |
| 2488 | auto responseMsg1 = |
| 2489 | reinterpret_cast<const pldm_msg*>(getStatusResponse1.data()); |
| 2490 | |
| 2491 | uint8_t completionCode = 0; |
| 2492 | uint8_t currentState = 0; |
| 2493 | uint8_t previousState = 0; |
| 2494 | uint8_t auxState = 0; |
| 2495 | uint8_t auxStateStatus = 0; |
| 2496 | uint8_t progressPercent = 0; |
| 2497 | uint8_t reasonCode = 0; |
| 2498 | bitfield32_t updateOptionFlagsEnabled{0}; |
| 2499 | |
| 2500 | auto rc = decode_get_status_resp( |
| 2501 | responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode, |
| 2502 | ¤tState, &previousState, &auxState, &auxStateStatus, |
| 2503 | &progressPercent, &reasonCode, &updateOptionFlagsEnabled); |
| 2504 | |
| 2505 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2506 | EXPECT_EQ(completionCode, PLDM_SUCCESS); |
| 2507 | EXPECT_EQ(currentState, PLDM_FD_STATE_IDLE); |
| 2508 | EXPECT_EQ(previousState, PLDM_FD_STATE_DOWNLOAD); |
| 2509 | EXPECT_EQ(auxState, PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER); |
| 2510 | EXPECT_EQ(auxStateStatus, PLDM_FD_TIMEOUT); |
| 2511 | EXPECT_EQ(progressPercent, PLDM_FWUP_MAX_PROGRESS_PERCENT); |
| 2512 | EXPECT_EQ(reasonCode, PLDM_FD_TIMEOUT_DOWNLOAD); |
| 2513 | EXPECT_EQ(updateOptionFlagsEnabled.value, updateOptionFlagsEnabled1); |
| 2514 | |
| 2515 | // Bit position 0 - Force update of component – FD will perform a force |
| 2516 | // update of the component. |
| 2517 | constexpr std::bitset<32> updateOptionFlagsEnabled2{1}; |
| 2518 | constexpr uint8_t progressPercent2 = 50; |
| 2519 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)> |
| 2520 | getStatusResponse2{0x00, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, |
| 2521 | 0x70, 0x32, 0x05, 0x01, 0x00, 0x00, 0x00}; |
| 2522 | auto responseMsg2 = |
| 2523 | reinterpret_cast<const pldm_msg*>(getStatusResponse2.data()); |
| 2524 | |
| 2525 | rc = decode_get_status_resp( |
| 2526 | responseMsg2, getStatusResponse2.size() - hdrSize, &completionCode, |
| 2527 | ¤tState, &previousState, &auxState, &auxStateStatus, |
| 2528 | &progressPercent, &reasonCode, &updateOptionFlagsEnabled); |
| 2529 | |
| 2530 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2531 | EXPECT_EQ(completionCode, PLDM_SUCCESS); |
| 2532 | EXPECT_EQ(currentState, PLDM_FD_STATE_VERIFY); |
| 2533 | EXPECT_EQ(previousState, PLDM_FD_STATE_DOWNLOAD); |
| 2534 | EXPECT_EQ(auxState, PLDM_FD_OPERATION_IN_PROGRESS); |
| 2535 | EXPECT_EQ(auxStateStatus, PLDM_FD_VENDOR_DEFINED_STATUS_CODE_START); |
| 2536 | EXPECT_EQ(progressPercent, progressPercent2); |
| 2537 | EXPECT_EQ(reasonCode, PLDM_FD_TIMEOUT_DOWNLOAD); |
| 2538 | EXPECT_EQ(updateOptionFlagsEnabled.value, updateOptionFlagsEnabled2); |
| 2539 | |
| 2540 | constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2541 | getStatusResponse3{0x00, 0x00, 0x00, 0x04}; |
| 2542 | auto responseMsg3 = |
| 2543 | reinterpret_cast<const pldm_msg*>(getStatusResponse3.data()); |
| 2544 | rc = decode_get_status_resp( |
| 2545 | responseMsg3, getStatusResponse3.size() - hdrSize, &completionCode, |
| 2546 | ¤tState, &previousState, &auxState, &auxStateStatus, |
| 2547 | &progressPercent, &reasonCode, &updateOptionFlagsEnabled); |
| 2548 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2549 | EXPECT_EQ(completionCode, PLDM_ERROR_NOT_READY); |
| 2550 | } |
| 2551 | |
| 2552 | TEST(GetStatus, errorPathDecodeResponse) |
| 2553 | { |
| 2554 | uint8_t completionCode = 0; |
| 2555 | uint8_t currentState = 0; |
| 2556 | uint8_t previousState = 0; |
| 2557 | uint8_t auxState = 0; |
| 2558 | uint8_t auxStateStatus = 0; |
| 2559 | uint8_t progressPercent = 0; |
| 2560 | uint8_t reasonCode = 0; |
| 2561 | bitfield32_t updateOptionFlagsEnabled{0}; |
| 2562 | |
| 2563 | constexpr std::array<uint8_t, hdrSize> getStatusResponse1{0x00, 0x00, 0x00}; |
| 2564 | auto responseMsg1 = |
| 2565 | reinterpret_cast<const pldm_msg*>(getStatusResponse1.data()); |
| 2566 | |
| 2567 | auto rc = decode_get_status_resp( |
| 2568 | nullptr, getStatusResponse1.size() - hdrSize, &completionCode, |
| 2569 | ¤tState, &previousState, &auxState, &auxStateStatus, |
| 2570 | &progressPercent, &reasonCode, &updateOptionFlagsEnabled); |
| 2571 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2572 | |
| 2573 | rc = decode_get_status_resp( |
| 2574 | responseMsg1, getStatusResponse1.size() - hdrSize, nullptr, |
| 2575 | ¤tState, &previousState, &auxState, &auxStateStatus, |
| 2576 | &progressPercent, &reasonCode, &updateOptionFlagsEnabled); |
| 2577 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2578 | |
| 2579 | rc = decode_get_status_resp( |
| 2580 | responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode, |
| 2581 | nullptr, &previousState, &auxState, &auxStateStatus, &progressPercent, |
| 2582 | &reasonCode, &updateOptionFlagsEnabled); |
| 2583 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2584 | |
| 2585 | rc = decode_get_status_resp( |
| 2586 | responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode, |
| 2587 | ¤tState, nullptr, &auxState, &auxStateStatus, &progressPercent, |
| 2588 | &reasonCode, &updateOptionFlagsEnabled); |
| 2589 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2590 | |
| 2591 | rc = decode_get_status_resp( |
| 2592 | responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode, |
| 2593 | ¤tState, &previousState, nullptr, &auxStateStatus, |
| 2594 | &progressPercent, &reasonCode, &updateOptionFlagsEnabled); |
| 2595 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2596 | |
| 2597 | rc = decode_get_status_resp( |
| 2598 | responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode, |
| 2599 | ¤tState, &previousState, &auxState, nullptr, &progressPercent, |
| 2600 | &reasonCode, &updateOptionFlagsEnabled); |
| 2601 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2602 | |
| 2603 | rc = decode_get_status_resp( |
| 2604 | responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode, |
| 2605 | ¤tState, &previousState, &auxState, &auxStateStatus, nullptr, |
| 2606 | &reasonCode, &updateOptionFlagsEnabled); |
| 2607 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2608 | |
| 2609 | rc = decode_get_status_resp( |
| 2610 | responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode, |
| 2611 | ¤tState, &previousState, &auxState, &auxStateStatus, |
| 2612 | &progressPercent, nullptr, &updateOptionFlagsEnabled); |
| 2613 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2614 | |
| 2615 | rc = decode_get_status_resp( |
| 2616 | responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode, |
| 2617 | ¤tState, &previousState, &auxState, &auxStateStatus, |
| 2618 | &progressPercent, &reasonCode, nullptr); |
| 2619 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2620 | |
| 2621 | rc = decode_get_status_resp( |
| 2622 | responseMsg1, getStatusResponse1.size() - hdrSize, &completionCode, |
| 2623 | ¤tState, &previousState, &auxState, &auxStateStatus, |
| 2624 | &progressPercent, &reasonCode, &updateOptionFlagsEnabled); |
| 2625 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2626 | |
| 2627 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp) - 1> |
| 2628 | getStatusResponse2{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2629 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 2630 | auto responseMsg2 = |
| 2631 | reinterpret_cast<const pldm_msg*>(getStatusResponse2.data()); |
| 2632 | rc = decode_get_status_resp( |
| 2633 | responseMsg2, getStatusResponse2.size() - hdrSize, &completionCode, |
| 2634 | ¤tState, &previousState, &auxState, &auxStateStatus, |
| 2635 | &progressPercent, &reasonCode, &updateOptionFlagsEnabled); |
| 2636 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2637 | |
| 2638 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)> |
| 2639 | getStatusResponse3{0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, |
| 2640 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 2641 | auto responseMsg3 = |
| 2642 | reinterpret_cast<const pldm_msg*>(getStatusResponse3.data()); |
| 2643 | rc = decode_get_status_resp( |
| 2644 | responseMsg3, getStatusResponse3.size() - hdrSize, &completionCode, |
| 2645 | ¤tState, &previousState, &auxState, &auxStateStatus, |
| 2646 | &progressPercent, &reasonCode, &updateOptionFlagsEnabled); |
| 2647 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2648 | |
| 2649 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)> |
| 2650 | getStatusResponse4{0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, |
| 2651 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 2652 | auto responseMsg4 = |
| 2653 | reinterpret_cast<const pldm_msg*>(getStatusResponse4.data()); |
| 2654 | rc = decode_get_status_resp( |
| 2655 | responseMsg4, getStatusResponse4.size() - hdrSize, &completionCode, |
| 2656 | ¤tState, &previousState, &auxState, &auxStateStatus, |
| 2657 | &progressPercent, &reasonCode, &updateOptionFlagsEnabled); |
| 2658 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2659 | |
| 2660 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)> |
| 2661 | getStatusResponse5{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, |
| 2662 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 2663 | auto responseMsg5 = |
| 2664 | reinterpret_cast<const pldm_msg*>(getStatusResponse5.data()); |
| 2665 | rc = decode_get_status_resp( |
| 2666 | responseMsg5, getStatusResponse5.size() - hdrSize, &completionCode, |
| 2667 | ¤tState, &previousState, &auxState, &auxStateStatus, |
| 2668 | &progressPercent, &reasonCode, &updateOptionFlagsEnabled); |
| 2669 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2670 | |
| 2671 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)> |
| 2672 | getStatusResponse6{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2673 | 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 2674 | auto responseMsg6 = |
| 2675 | reinterpret_cast<const pldm_msg*>(getStatusResponse6.data()); |
| 2676 | rc = decode_get_status_resp( |
| 2677 | responseMsg6, getStatusResponse6.size() - hdrSize, &completionCode, |
| 2678 | ¤tState, &previousState, &auxState, &auxStateStatus, |
| 2679 | &progressPercent, &reasonCode, &updateOptionFlagsEnabled); |
| 2680 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2681 | |
| 2682 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)> |
| 2683 | getStatusResponse7{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2684 | 0x00, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 2685 | auto responseMsg7 = |
| 2686 | reinterpret_cast<const pldm_msg*>(getStatusResponse7.data()); |
| 2687 | rc = decode_get_status_resp( |
| 2688 | responseMsg7, getStatusResponse7.size() - hdrSize, &completionCode, |
| 2689 | ¤tState, &previousState, &auxState, &auxStateStatus, |
| 2690 | &progressPercent, &reasonCode, &updateOptionFlagsEnabled); |
| 2691 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2692 | |
| 2693 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)> |
| 2694 | getStatusResponse8{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2695 | 0x00, 0x00, 0xC7, 0x00, 0x00, 0x00, 0x00}; |
| 2696 | auto responseMsg8 = |
| 2697 | reinterpret_cast<const pldm_msg*>(getStatusResponse8.data()); |
| 2698 | rc = decode_get_status_resp( |
| 2699 | responseMsg8, getStatusResponse8.size() - hdrSize, &completionCode, |
| 2700 | ¤tState, &previousState, &auxState, &auxStateStatus, |
| 2701 | &progressPercent, &reasonCode, &updateOptionFlagsEnabled); |
| 2702 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2703 | |
| 2704 | // AuxState is not PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER when the state is |
| 2705 | // IDLE |
| 2706 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_get_status_resp)> |
| 2707 | getStatusResponse9{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
| 2708 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 2709 | auto responseMsg9 = |
| 2710 | reinterpret_cast<const pldm_msg*>(getStatusResponse9.data()); |
| 2711 | rc = decode_get_status_resp( |
| 2712 | responseMsg9, getStatusResponse9.size() - hdrSize, &completionCode, |
| 2713 | ¤tState, &previousState, &auxState, &auxStateStatus, |
| 2714 | &progressPercent, &reasonCode, &updateOptionFlagsEnabled); |
| 2715 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2716 | } |
| 2717 | |
| 2718 | TEST(CancelUpdateComponent, goodPathEncodeRequest) |
| 2719 | { |
| 2720 | constexpr uint8_t instanceId = 9; |
| 2721 | std::array<uint8_t, hdrSize> request{}; |
| 2722 | auto requestMsg = reinterpret_cast<pldm_msg*>(request.data()); |
| 2723 | |
| 2724 | auto rc = encode_cancel_update_component_req( |
| 2725 | instanceId, requestMsg, PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES); |
| 2726 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2727 | |
| 2728 | constexpr std::array<uint8_t, hdrSize> outRequest{0x89, 0x05, 0x1C}; |
| 2729 | EXPECT_EQ(request, outRequest); |
| 2730 | } |
| 2731 | |
| 2732 | TEST(CancelUpdateComponent, errorPathEncodeRequest) |
| 2733 | { |
| 2734 | std::array<uint8_t, hdrSize + sizeof(uint8_t)> request{}; |
| 2735 | auto requestMsg = reinterpret_cast<pldm_msg*>(request.data()); |
| 2736 | |
| 2737 | auto rc = encode_cancel_update_component_req( |
| 2738 | 0, nullptr, PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES); |
| 2739 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2740 | |
| 2741 | rc = encode_cancel_update_component_req( |
| 2742 | 0, requestMsg, PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES + 1); |
| 2743 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2744 | } |
| 2745 | |
| 2746 | TEST(CancelUpdateComponent, testGoodDecodeResponse) |
| 2747 | { |
| 2748 | uint8_t completionCode = 0; |
| 2749 | constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2750 | cancelUpdateComponentResponse1{0x00, 0x00, 0x00, 0x00}; |
| 2751 | auto responseMsg1 = reinterpret_cast<const pldm_msg*>( |
| 2752 | cancelUpdateComponentResponse1.data()); |
| 2753 | auto rc = decode_cancel_update_component_resp( |
| 2754 | responseMsg1, cancelUpdateComponentResponse1.size() - hdrSize, |
| 2755 | &completionCode); |
| 2756 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2757 | EXPECT_EQ(completionCode, PLDM_SUCCESS); |
| 2758 | |
| 2759 | constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2760 | cancelUpdateComponentResponse2{0x00, 0x00, 0x00, 0x86}; |
| 2761 | auto responseMsg2 = reinterpret_cast<const pldm_msg*>( |
| 2762 | cancelUpdateComponentResponse2.data()); |
| 2763 | rc = decode_cancel_update_component_resp( |
| 2764 | responseMsg2, cancelUpdateComponentResponse2.size() - hdrSize, |
| 2765 | &completionCode); |
| 2766 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2767 | EXPECT_EQ(completionCode, PLDM_FWUP_BUSY_IN_BACKGROUND); |
| 2768 | } |
| 2769 | |
| 2770 | TEST(CancelUpdateComponent, testBadDecodeResponse) |
| 2771 | { |
| 2772 | uint8_t completionCode = 0; |
| 2773 | constexpr std::array<uint8_t, hdrSize> cancelUpdateComponentResponse{ |
| 2774 | 0x00, 0x00, 0x00}; |
| 2775 | auto responseMsg = |
| 2776 | reinterpret_cast<const pldm_msg*>(cancelUpdateComponentResponse.data()); |
| 2777 | |
| 2778 | auto rc = decode_cancel_update_component_resp( |
| 2779 | nullptr, cancelUpdateComponentResponse.size() - hdrSize, |
| 2780 | &completionCode); |
| 2781 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2782 | |
| 2783 | rc = decode_cancel_update_component_resp( |
| 2784 | responseMsg, cancelUpdateComponentResponse.size() - hdrSize, nullptr); |
| 2785 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2786 | |
| 2787 | rc = decode_cancel_update_component_resp( |
| 2788 | responseMsg, cancelUpdateComponentResponse.size() - hdrSize, |
| 2789 | &completionCode); |
| 2790 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2791 | } |
| 2792 | |
| 2793 | TEST(CancelUpdate, goodPathEncodeRequest) |
| 2794 | { |
| 2795 | constexpr uint8_t instanceId = 10; |
| 2796 | std::array<uint8_t, hdrSize> request{}; |
| 2797 | auto requestMsg = reinterpret_cast<pldm_msg*>(request.data()); |
| 2798 | |
| 2799 | auto rc = encode_cancel_update_req(instanceId, requestMsg, |
| 2800 | PLDM_CANCEL_UPDATE_REQ_BYTES); |
| 2801 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2802 | |
| 2803 | constexpr std::array<uint8_t, hdrSize> outRequest{0x8A, 0x05, 0x1D}; |
| 2804 | EXPECT_EQ(request, outRequest); |
| 2805 | } |
| 2806 | |
| 2807 | TEST(CancelUpdate, errorPathEncodeRequest) |
| 2808 | { |
| 2809 | std::array<uint8_t, hdrSize + sizeof(uint8_t)> request{}; |
| 2810 | auto requestMsg = reinterpret_cast<pldm_msg*>(request.data()); |
| 2811 | |
| 2812 | auto rc = |
| 2813 | encode_cancel_update_req(0, nullptr, PLDM_CANCEL_UPDATE_REQ_BYTES); |
| 2814 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2815 | |
| 2816 | rc = encode_cancel_update_req(0, requestMsg, |
| 2817 | PLDM_CANCEL_UPDATE_REQ_BYTES + 1); |
| 2818 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2819 | } |
| 2820 | |
| 2821 | TEST(CancelUpdate, goodPathDecodeResponse) |
| 2822 | { |
| 2823 | constexpr std::bitset<64> nonFunctioningComponentBitmap1{0}; |
| 2824 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_cancel_update_resp)> |
| 2825 | cancelUpdateResponse1{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2826 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 2827 | auto responseMsg1 = |
| 2828 | reinterpret_cast<const pldm_msg*>(cancelUpdateResponse1.data()); |
| 2829 | uint8_t completionCode = 0; |
| 2830 | bool8_t nonFunctioningComponentIndication = 0; |
| 2831 | bitfield64_t nonFunctioningComponentBitmap{0}; |
| 2832 | auto rc = decode_cancel_update_resp( |
| 2833 | responseMsg1, cancelUpdateResponse1.size() - hdrSize, &completionCode, |
| 2834 | &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap); |
| 2835 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2836 | EXPECT_EQ(completionCode, PLDM_SUCCESS); |
| 2837 | EXPECT_EQ(nonFunctioningComponentIndication, |
| 2838 | PLDM_FWUP_COMPONENTS_FUNCTIONING); |
| 2839 | EXPECT_EQ(nonFunctioningComponentBitmap.value, |
| 2840 | nonFunctioningComponentBitmap1); |
| 2841 | |
| 2842 | constexpr std::bitset<64> nonFunctioningComponentBitmap2{0x0101}; |
| 2843 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_cancel_update_resp)> |
| 2844 | cancelUpdateResponse2{0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, |
| 2845 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 2846 | auto responseMsg2 = |
| 2847 | reinterpret_cast<const pldm_msg*>(cancelUpdateResponse2.data()); |
| 2848 | rc = decode_cancel_update_resp( |
| 2849 | responseMsg2, cancelUpdateResponse2.size() - hdrSize, &completionCode, |
| 2850 | &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap); |
| 2851 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2852 | EXPECT_EQ(completionCode, PLDM_SUCCESS); |
| 2853 | EXPECT_EQ(nonFunctioningComponentIndication, |
| 2854 | PLDM_FWUP_COMPONENTS_NOT_FUNCTIONING); |
| 2855 | EXPECT_EQ(nonFunctioningComponentBitmap.value, |
| 2856 | nonFunctioningComponentBitmap2); |
| 2857 | |
| 2858 | constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2859 | cancelUpdateResponse3{0x00, 0x00, 0x00, 0x86}; |
| 2860 | auto responseMsg3 = |
| 2861 | reinterpret_cast<const pldm_msg*>(cancelUpdateResponse3.data()); |
| 2862 | rc = decode_cancel_update_resp( |
| 2863 | responseMsg3, cancelUpdateResponse3.size() - hdrSize, &completionCode, |
| 2864 | &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap); |
| 2865 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2866 | EXPECT_EQ(completionCode, PLDM_FWUP_BUSY_IN_BACKGROUND); |
| 2867 | } |
| 2868 | |
| 2869 | TEST(CancelUpdate, errorPathDecodeResponse) |
| 2870 | { |
| 2871 | constexpr std::array<uint8_t, hdrSize> cancelUpdateResponse1{0x00, 0x00, |
| 2872 | 0x00}; |
| 2873 | auto responseMsg1 = |
| 2874 | reinterpret_cast<const pldm_msg*>(cancelUpdateResponse1.data()); |
| 2875 | uint8_t completionCode = 0; |
| 2876 | bool8_t nonFunctioningComponentIndication = 0; |
| 2877 | bitfield64_t nonFunctioningComponentBitmap{0}; |
| 2878 | |
| 2879 | auto rc = decode_cancel_update_resp( |
| 2880 | nullptr, cancelUpdateResponse1.size() - hdrSize, &completionCode, |
| 2881 | &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap); |
| 2882 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2883 | |
| 2884 | rc = decode_cancel_update_resp( |
| 2885 | responseMsg1, cancelUpdateResponse1.size() - hdrSize, nullptr, |
| 2886 | &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap); |
| 2887 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2888 | |
| 2889 | rc = decode_cancel_update_resp( |
| 2890 | responseMsg1, cancelUpdateResponse1.size() - hdrSize, &completionCode, |
| 2891 | nullptr, &nonFunctioningComponentBitmap); |
| 2892 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2893 | |
| 2894 | rc = decode_cancel_update_resp( |
| 2895 | responseMsg1, cancelUpdateResponse1.size() - hdrSize, &completionCode, |
| 2896 | &nonFunctioningComponentIndication, nullptr); |
| 2897 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2898 | |
| 2899 | rc = decode_cancel_update_resp( |
| 2900 | responseMsg1, cancelUpdateResponse1.size() - hdrSize, &completionCode, |
| 2901 | &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap); |
| 2902 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2903 | |
| 2904 | constexpr std::array<uint8_t, hdrSize + sizeof(completionCode)> |
| 2905 | cancelUpdateResponse2{0x00, 0x00, 0x00, 0x00}; |
| 2906 | auto responseMsg2 = |
| 2907 | reinterpret_cast<const pldm_msg*>(cancelUpdateResponse2.data()); |
| 2908 | rc = decode_cancel_update_resp( |
| 2909 | responseMsg2, cancelUpdateResponse2.size() - hdrSize, &completionCode, |
| 2910 | &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap); |
| 2911 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2912 | |
| 2913 | constexpr std::array<uint8_t, hdrSize + sizeof(pldm_cancel_update_resp)> |
| 2914 | cancelUpdateResponse3{0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 2915 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 2916 | auto responseMsg3 = |
| 2917 | reinterpret_cast<const pldm_msg*>(cancelUpdateResponse3.data()); |
| 2918 | rc = decode_cancel_update_resp( |
| 2919 | responseMsg3, cancelUpdateResponse3.size() - hdrSize, &completionCode, |
| 2920 | &nonFunctioningComponentIndication, &nonFunctioningComponentBitmap); |
| 2921 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2922 | } |