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