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