Tom Joseph | 3fd3eb8 | 2021-06-18 04:13:29 -0700 | [diff] [blame] | 1 | #include <bitset>
|
Tom Joseph | 763b51e | 2021-06-05 04:50:47 -0700 | [diff] [blame] | 2 | #include <cstring>
|
| 3 |
|
gokulsanker | 138ceba | 2021-04-05 13:25:25 +0530 | [diff] [blame] | 4 | #include "libpldm/base.h"
|
| 5 | #include "libpldm/firmware_update.h"
|
| 6 |
|
| 7 | #include <gtest/gtest.h>
|
| 8 |
|
| 9 | constexpr auto hdrSize = sizeof(pldm_msg_hdr);
|
| 10 |
|
Tom Joseph | 763b51e | 2021-06-05 04:50:47 -0700 | [diff] [blame] | 11 | TEST(DecodeDescriptors, goodPath3Descriptors)
|
| 12 | {
|
| 13 | // In the descriptor data there are 3 descriptor entries
|
| 14 | // 1) IANA enterprise ID
|
| 15 | constexpr std::array<uint8_t, PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH> iana{
|
| 16 | 0x0a, 0x0b, 0x0c, 0xd};
|
| 17 | // 2) UUID
|
| 18 | constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
|
| 19 | 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
|
| 20 | 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
|
| 21 | // 3) Vendor Defined
|
| 22 | constexpr std::string_view vendorTitle{"OpenBMC"};
|
| 23 | constexpr size_t vendorDescriptorLen = 2;
|
| 24 | constexpr std::array<uint8_t, vendorDescriptorLen> vendorDescriptorData{
|
| 25 | 0x01, 0x02};
|
| 26 |
|
| 27 | constexpr size_t vendorDefinedDescriptorLen =
|
| 28 | sizeof(pldm_vendor_defined_descriptor_title_data()
|
| 29 | .vendor_defined_descriptor_title_str_type) +
|
| 30 | sizeof(pldm_vendor_defined_descriptor_title_data()
|
| 31 | .vendor_defined_descriptor_title_str_len) +
|
| 32 | vendorTitle.size() + vendorDescriptorData.size();
|
| 33 |
|
| 34 | constexpr size_t descriptorsLength =
|
| 35 | 3 * (sizeof(pldm_descriptor_tlv().descriptor_type) +
|
| 36 | sizeof(pldm_descriptor_tlv().descriptor_length)) +
|
| 37 | iana.size() + uuid.size() + vendorDefinedDescriptorLen;
|
| 38 |
|
| 39 | constexpr std::array<uint8_t, descriptorsLength> descriptors{
|
| 40 | 0x01, 0x00, 0x04, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x02, 0x00, 0x10,
|
| 41 | 0x00, 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18, 0xa0, 0x30,
|
| 42 | 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b, 0xFF, 0xFF, 0x0B, 0x00, 0x01,
|
| 43 | 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43, 0x01, 0x02};
|
| 44 |
|
| 45 | size_t descriptorCount = 1;
|
| 46 | size_t descriptorsRemainingLength = descriptorsLength;
|
| 47 | int rc = 0;
|
| 48 |
|
| 49 | while (descriptorsRemainingLength && (descriptorCount <= 3))
|
| 50 | {
|
| 51 | uint16_t descriptorType = 0;
|
| 52 | uint16_t descriptorLen = 0;
|
| 53 | variable_field descriptorData{};
|
| 54 |
|
| 55 | rc = decode_descriptor_type_length_value(
|
| 56 | descriptors.data() + descriptorsLength - descriptorsRemainingLength,
|
| 57 | descriptorsRemainingLength, &descriptorType, &descriptorData);
|
| 58 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 59 |
|
| 60 | if (descriptorCount == 1)
|
| 61 | {
|
| 62 | EXPECT_EQ(descriptorType, PLDM_FWUP_IANA_ENTERPRISE_ID);
|
| 63 | EXPECT_EQ(descriptorData.length,
|
| 64 | PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH);
|
| 65 | EXPECT_EQ(true,
|
| 66 | std::equal(descriptorData.ptr,
|
| 67 | descriptorData.ptr + descriptorData.length,
|
| 68 | iana.begin(), iana.end()));
|
| 69 | }
|
| 70 | else if (descriptorCount == 2)
|
| 71 | {
|
| 72 | EXPECT_EQ(descriptorType, PLDM_FWUP_UUID);
|
| 73 | EXPECT_EQ(descriptorData.length, PLDM_FWUP_UUID_LENGTH);
|
| 74 | EXPECT_EQ(true,
|
| 75 | std::equal(descriptorData.ptr,
|
| 76 | descriptorData.ptr + descriptorData.length,
|
| 77 | uuid.begin(), uuid.end()));
|
| 78 | }
|
| 79 | else if (descriptorCount == 3)
|
| 80 | {
|
| 81 | EXPECT_EQ(descriptorType, PLDM_FWUP_VENDOR_DEFINED);
|
| 82 | EXPECT_EQ(descriptorData.length, vendorDefinedDescriptorLen);
|
| 83 |
|
| 84 | uint8_t descriptorTitleStrType = 0;
|
| 85 | variable_field descriptorTitleStr{};
|
| 86 | variable_field vendorDefinedDescriptorData{};
|
| 87 |
|
| 88 | rc = decode_vendor_defined_descriptor_value(
|
| 89 | descriptorData.ptr, descriptorData.length,
|
| 90 | &descriptorTitleStrType, &descriptorTitleStr,
|
| 91 | &vendorDefinedDescriptorData);
|
| 92 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 93 |
|
| 94 | EXPECT_EQ(descriptorTitleStrType, PLDM_STR_TYPE_ASCII);
|
| 95 | EXPECT_EQ(descriptorTitleStr.length, vendorTitle.size());
|
| 96 | std::string vendorTitleStr(
|
| 97 | reinterpret_cast<const char*>(descriptorTitleStr.ptr),
|
| 98 | descriptorTitleStr.length);
|
| 99 | EXPECT_EQ(vendorTitleStr, vendorTitle);
|
| 100 |
|
| 101 | EXPECT_EQ(vendorDefinedDescriptorData.length,
|
| 102 | vendorDescriptorData.size());
|
| 103 | EXPECT_EQ(true, std::equal(vendorDefinedDescriptorData.ptr,
|
| 104 | vendorDefinedDescriptorData.ptr +
|
| 105 | vendorDefinedDescriptorData.length,
|
| 106 | vendorDescriptorData.begin(),
|
| 107 | vendorDescriptorData.end()));
|
| 108 | }
|
| 109 |
|
| 110 | descriptorsRemainingLength -= sizeof(descriptorType) +
|
| 111 | sizeof(descriptorLen) +
|
| 112 | descriptorData.length;
|
| 113 | descriptorCount++;
|
| 114 | }
|
| 115 | }
|
| 116 |
|
| 117 | TEST(DecodeDescriptors, errorPathDecodeDescriptorTLV)
|
| 118 | {
|
| 119 | int rc = 0;
|
| 120 | // IANA Enterprise ID descriptor length incorrect
|
| 121 | constexpr std::array<uint8_t, 7> invalidIANADescriptor1{
|
| 122 | 0x01, 0x00, 0x03, 0x00, 0x0a, 0x0b, 0x0c};
|
| 123 | uint16_t descriptorType = 0;
|
| 124 | variable_field descriptorData{};
|
| 125 |
|
| 126 | rc = decode_descriptor_type_length_value(nullptr,
|
| 127 | invalidIANADescriptor1.size(),
|
| 128 | &descriptorType, &descriptorData);
|
| 129 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 130 |
|
| 131 | rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
|
| 132 | invalidIANADescriptor1.size(),
|
| 133 | nullptr, &descriptorData);
|
| 134 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 135 |
|
| 136 | rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
|
| 137 | invalidIANADescriptor1.size(),
|
| 138 | &descriptorType, nullptr);
|
| 139 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 140 |
|
| 141 | rc = decode_descriptor_type_length_value(
|
| 142 | invalidIANADescriptor1.data(), PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN - 1,
|
| 143 | &descriptorType, &descriptorData);
|
| 144 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
|
| 145 |
|
| 146 | rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
|
| 147 | invalidIANADescriptor1.size(),
|
| 148 | &descriptorType, &descriptorData);
|
| 149 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
|
| 150 |
|
| 151 | // IANA Enterprise ID descriptor data less than length
|
| 152 | std::array<uint8_t, 7> invalidIANADescriptor2{0x01, 0x00, 0x04, 0x00,
|
| 153 | 0x0a, 0x0b, 0x0c};
|
| 154 | rc = decode_descriptor_type_length_value(invalidIANADescriptor2.data(),
|
| 155 | invalidIANADescriptor2.size(),
|
| 156 | &descriptorType, &descriptorData);
|
| 157 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
|
| 158 | }
|
| 159 |
|
| 160 | TEST(DecodeDescriptors, errorPathVendorDefinedDescriptor)
|
| 161 | {
|
| 162 | int rc = 0;
|
| 163 | // VendorDefinedDescriptorTitleStringType is invalid
|
| 164 | constexpr std::array<uint8_t, 9> invalidVendorDescriptor1{
|
| 165 | 0x06, 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
|
| 166 | uint8_t descriptorStringType = 0;
|
| 167 | variable_field descriptorTitleStr{};
|
| 168 | variable_field vendorDefinedDescriptorData{};
|
| 169 |
|
| 170 | rc = decode_vendor_defined_descriptor_value(
|
| 171 | nullptr, invalidVendorDescriptor1.size(), &descriptorStringType,
|
| 172 | &descriptorTitleStr, &vendorDefinedDescriptorData);
|
| 173 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 174 |
|
| 175 | rc = decode_vendor_defined_descriptor_value(
|
| 176 | invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
|
| 177 | &descriptorStringType, &descriptorTitleStr,
|
| 178 | &vendorDefinedDescriptorData);
|
| 179 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 180 |
|
| 181 | rc = decode_vendor_defined_descriptor_value(
|
| 182 | invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
|
| 183 | nullptr, &descriptorTitleStr, &vendorDefinedDescriptorData);
|
| 184 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 185 |
|
| 186 | rc = decode_vendor_defined_descriptor_value(
|
| 187 | invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
|
| 188 | &descriptorStringType, nullptr, &vendorDefinedDescriptorData);
|
| 189 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 190 |
|
| 191 | rc = decode_vendor_defined_descriptor_value(
|
| 192 | invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
|
| 193 | &descriptorStringType, &descriptorTitleStr, nullptr);
|
| 194 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 195 |
|
| 196 | rc = decode_vendor_defined_descriptor_value(
|
| 197 | invalidVendorDescriptor1.data(),
|
| 198 | sizeof(pldm_vendor_defined_descriptor_title_data) - 1,
|
| 199 | &descriptorStringType, &descriptorTitleStr,
|
| 200 | &vendorDefinedDescriptorData);
|
| 201 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
|
| 202 |
|
| 203 | rc = decode_vendor_defined_descriptor_value(
|
| 204 | invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
|
| 205 | &descriptorStringType, &descriptorTitleStr,
|
| 206 | &vendorDefinedDescriptorData);
|
| 207 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 208 |
|
| 209 | // VendorDefinedDescriptorTitleStringLength is 0
|
| 210 | std::array<uint8_t, 9> invalidVendorDescriptor2{
|
| 211 | 0x01, 0x00, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
|
| 212 | rc = decode_vendor_defined_descriptor_value(
|
| 213 | invalidVendorDescriptor2.data(), invalidVendorDescriptor2.size(),
|
| 214 | &descriptorStringType, &descriptorTitleStr,
|
| 215 | &vendorDefinedDescriptorData);
|
| 216 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 217 |
|
| 218 | // VendorDefinedDescriptorData not present in the data
|
| 219 | std::array<uint8_t, 9> invalidVendorDescriptor3{
|
| 220 | 0x01, 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
|
| 221 | rc = decode_vendor_defined_descriptor_value(
|
| 222 | invalidVendorDescriptor3.data(), invalidVendorDescriptor3.size(),
|
| 223 | &descriptorStringType, &descriptorTitleStr,
|
| 224 | &vendorDefinedDescriptorData);
|
| 225 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
|
| 226 | }
|
| 227 |
|
gokulsanker | 138ceba | 2021-04-05 13:25:25 +0530 | [diff] [blame] | 228 | TEST(QueryDeviceIdentifiers, goodPathEncodeRequest)
|
| 229 | {
|
| 230 | std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
|
| 231 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
|
| 232 |
|
| 233 | uint8_t instanceId = 0x01;
|
| 234 |
|
| 235 | auto rc = encode_query_device_identifiers_req(
|
| 236 | instanceId, PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES, requestPtr);
|
| 237 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 238 | EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
|
| 239 | EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
|
| 240 | EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
|
| 241 | EXPECT_EQ(requestPtr->hdr.command, PLDM_QUERY_DEVICE_IDENTIFIERS);
|
| 242 | }
|
gokulsanker | eca3e19 | 2021-04-05 14:57:41 +0530 | [diff] [blame] | 243 |
|
| 244 | TEST(QueryDeviceIdentifiers, goodPathDecodeResponse)
|
| 245 | {
|
| 246 | // descriptorDataLen is not fixed here taking it as 6
|
| 247 | constexpr uint8_t descriptorDataLen = 6;
|
| 248 | std::array<uint8_t, hdrSize +
|
| 249 | sizeof(struct pldm_query_device_identifiers_resp) +
|
| 250 | descriptorDataLen>
|
| 251 | responseMsg{};
|
| 252 | auto inResp = reinterpret_cast<struct pldm_query_device_identifiers_resp*>(
|
| 253 | responseMsg.data() + hdrSize);
|
| 254 |
|
| 255 | inResp->completion_code = PLDM_SUCCESS;
|
| 256 | inResp->device_identifiers_len = htole32(descriptorDataLen);
|
| 257 | inResp->descriptor_count = 1;
|
| 258 |
|
| 259 | // filling descriptor data
|
| 260 | std::fill_n(responseMsg.data() + hdrSize +
|
| 261 | sizeof(struct pldm_query_device_identifiers_resp),
|
| 262 | descriptorDataLen, 0xFF);
|
| 263 |
|
| 264 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
|
| 265 | uint8_t completionCode = PLDM_SUCCESS;
|
| 266 | uint32_t deviceIdentifiersLen = 0;
|
| 267 | uint8_t descriptorCount = 0;
|
| 268 | uint8_t* outDescriptorData = nullptr;
|
| 269 |
|
| 270 | auto rc = decode_query_device_identifiers_resp(
|
| 271 | response, responseMsg.size() - hdrSize, &completionCode,
|
| 272 | &deviceIdentifiersLen, &descriptorCount, &outDescriptorData);
|
| 273 |
|
| 274 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 275 | EXPECT_EQ(completionCode, PLDM_SUCCESS);
|
| 276 | EXPECT_EQ(deviceIdentifiersLen, inResp->device_identifiers_len);
|
| 277 | EXPECT_EQ(descriptorCount, inResp->descriptor_count);
|
| 278 | EXPECT_EQ(true,
|
| 279 | std::equal(outDescriptorData,
|
| 280 | outDescriptorData + deviceIdentifiersLen,
|
| 281 | responseMsg.begin() + hdrSize +
|
| 282 | sizeof(struct pldm_query_device_identifiers_resp),
|
| 283 | responseMsg.end()));
|
| 284 | }
|
gokulsanker | 981fbfb | 2021-04-05 15:17:25 +0530 | [diff] [blame] | 285 |
|
| 286 | TEST(GetFirmwareParameters, goodPathEncodeRequest)
|
| 287 | {
|
| 288 | std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
|
| 289 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
|
| 290 | uint8_t instanceId = 0x01;
|
| 291 |
|
| 292 | auto rc = encode_get_firmware_parameters_req(
|
| 293 | instanceId, PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES, requestPtr);
|
| 294 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 295 | EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
|
| 296 | EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
|
| 297 | EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
|
| 298 | EXPECT_EQ(requestPtr->hdr.command, PLDM_GET_FIRMWARE_PARAMETERS);
|
| 299 | }
|
gokulsanker | 22fbb34 | 2021-04-05 15:55:06 +0530 | [diff] [blame] | 300 |
|
Tom Joseph | 3fd3eb8 | 2021-06-18 04:13:29 -0700 | [diff] [blame] | 301 | TEST(GetFirmwareParameters, decodeResponse)
|
gokulsanker | 22fbb34 | 2021-04-05 15:55:06 +0530 | [diff] [blame] | 302 | {
|
Tom Joseph | 3fd3eb8 | 2021-06-18 04:13:29 -0700 | [diff] [blame] | 303 | // CapabilitiesDuringUpdate of the firmware device
|
| 304 | // Firmware device downgrade restrictions [Bit position 8] &
|
| 305 | // Firmware Device Partial Updates [Bit position 3]
|
| 306 | constexpr std::bitset<32> fdCapabilities{0x00000104};
|
| 307 | constexpr uint16_t compCount = 1;
|
| 308 | constexpr std::string_view activeCompImageSetVersion{"VersionString1"};
|
| 309 | constexpr std::string_view pendingCompImageSetVersion{"VersionString2"};
|
gokulsanker | 22fbb34 | 2021-04-05 15:55:06 +0530 | [diff] [blame] | 310 |
|
Tom Joseph | 3fd3eb8 | 2021-06-18 04:13:29 -0700 | [diff] [blame] | 311 | // constexpr uint16_t compClassification = 16;
|
| 312 | // constexpr uint16_t compIdentifier = 300;
|
| 313 | // constexpr uint8_t compClassificationIndex = 20;
|
| 314 | // constexpr uint32_t activeCompComparisonStamp = 0xABCDEFAB;
|
| 315 | // constexpr std::array<uint8_t, 8> activeComponentReleaseData = {
|
| 316 | // 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
| 317 | // constexpr uint32_t pendingCompComparisonStamp = 0x12345678;
|
| 318 | // constexpr std::array<uint8_t, 8> pendingComponentReleaseData = {
|
| 319 | // 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01};
|
| 320 | constexpr std::string_view activeCompVersion{"VersionString3"};
|
| 321 | constexpr std::string_view pendingCompVersion{"VersionString4"};
|
| 322 | // ComponentActivationMethods
|
| 323 | // DC Power cycle [Bit position 4] & Self-Contained[Bit position 2]
|
| 324 | constexpr std::bitset<16> compActivationMethod{0x12};
|
| 325 | // CapabilitiesDuringUpdate of the firmware component
|
| 326 | // Component downgrade capability [Bit position 2]
|
| 327 | constexpr std::bitset<32> compCapabilities{0x02};
|
gokulsanker | 22fbb34 | 2021-04-05 15:55:06 +0530 | [diff] [blame] | 328 |
|
Tom Joseph | 3fd3eb8 | 2021-06-18 04:13:29 -0700 | [diff] [blame] | 329 | constexpr size_t compParamTableSize =
|
| 330 | sizeof(pldm_component_parameter_entry) + activeCompVersion.size() +
|
| 331 | pendingCompVersion.size();
|
gokulsanker | 22fbb34 | 2021-04-05 15:55:06 +0530 | [diff] [blame] | 332 |
|
Tom Joseph | 3fd3eb8 | 2021-06-18 04:13:29 -0700 | [diff] [blame] | 333 | constexpr std::array<uint8_t, compParamTableSize> compParamTable{
|
| 334 | 0x10, 0x00, 0x2c, 0x01, 0x14, 0xAB, 0xEF, 0xCD, 0xAB, 0x01, 0x0e, 0x01,
|
| 335 | 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x78, 0x56, 0x34, 0x12, 0x01,
|
| 336 | 0x0e, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x12, 0x00, 0x02,
|
| 337 | 0x00, 0x00, 0x00, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53, 0x74,
|
| 338 | 0x72, 0x69, 0x6e, 0x67, 0x33, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
|
| 339 | 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x34};
|
gokulsanker | 22fbb34 | 2021-04-05 15:55:06 +0530 | [diff] [blame] | 340 |
|
Tom Joseph | 3fd3eb8 | 2021-06-18 04:13:29 -0700 | [diff] [blame] | 341 | constexpr size_t getFwParamsPayloadLen =
|
| 342 | sizeof(pldm_get_firmware_parameters_resp) +
|
| 343 | activeCompImageSetVersion.size() + pendingCompImageSetVersion.size() +
|
| 344 | compParamTableSize;
|
| 345 |
|
| 346 | constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
|
| 347 | getFwParamsResponse{
|
| 348 | 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01,
|
| 349 | 0x0e, 0x01, 0x0e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53,
|
| 350 | 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x56, 0x65, 0x72, 0x73, 0x69,
|
| 351 | 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32, 0x10, 0x00,
|
| 352 | 0x2c, 0x01, 0x14, 0xAB, 0xEF, 0xCD, 0xAB, 0x01, 0x0e, 0x01, 0x02,
|
| 353 | 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x78, 0x56, 0x34, 0x12, 0x01,
|
| 354 | 0x0e, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x12, 0x00,
|
| 355 | 0x02, 0x00, 0x00, 0x00, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
|
| 356 | 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x33, 0x56, 0x65, 0x72, 0x73,
|
| 357 | 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x34};
|
| 358 |
|
| 359 | auto responseMsg =
|
| 360 | reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
|
| 361 | pldm_get_firmware_parameters_resp outResp{};
|
| 362 | variable_field outActiveCompImageSetVersion{};
|
| 363 | variable_field outPendingCompImageSetVersion{};
|
| 364 | variable_field outCompParameterTable{};
|
| 365 |
|
| 366 | auto rc = decode_get_firmware_parameters_resp(
|
| 367 | responseMsg, getFwParamsPayloadLen, &outResp,
|
| 368 | &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
|
| 369 | &outCompParameterTable);
|
gokulsanker | 22fbb34 | 2021-04-05 15:55:06 +0530 | [diff] [blame] | 370 |
|
| 371 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 372 | EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
|
Tom Joseph | 3fd3eb8 | 2021-06-18 04:13:29 -0700 | [diff] [blame] | 373 | EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
|
| 374 | EXPECT_EQ(outResp.comp_count, compCount);
|
| 375 | EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
|
| 376 | EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
|
| 377 | activeCompImageSetVersion.size());
|
| 378 | EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
|
| 379 | EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len,
|
| 380 | pendingCompImageSetVersion.size());
|
| 381 | std::string activeCompImageSetVersionStr(
|
| 382 | reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
|
| 383 | outActiveCompImageSetVersion.length);
|
| 384 | EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
|
| 385 | std::string pendingCompImageSetVersionStr(
|
| 386 | reinterpret_cast<const char*>(outPendingCompImageSetVersion.ptr),
|
| 387 | outPendingCompImageSetVersion.length);
|
| 388 | EXPECT_EQ(pendingCompImageSetVersionStr, pendingCompImageSetVersion);
|
| 389 | EXPECT_EQ(outCompParameterTable.length, compParamTableSize);
|
| 390 | EXPECT_EQ(true, std::equal(outCompParameterTable.ptr,
|
| 391 | outCompParameterTable.ptr +
|
| 392 | outCompParameterTable.length,
|
| 393 | compParamTable.begin(), compParamTable.end()));
|
| 394 | }
|
gokulsanker | 22fbb34 | 2021-04-05 15:55:06 +0530 | [diff] [blame] | 395 |
|
Tom Joseph | 3fd3eb8 | 2021-06-18 04:13:29 -0700 | [diff] [blame] | 396 | TEST(GetFirmwareParameters, decodeResponseZeroCompCount)
|
| 397 | {
|
| 398 | // CapabilitiesDuringUpdate of the firmware device
|
| 399 | // FD Host Functionality during Firmware Update [Bit position 2] &
|
| 400 | // Component Update Failure Retry Capability [Bit position 1]
|
| 401 | constexpr std::bitset<32> fdCapabilities{0x06};
|
| 402 | constexpr uint16_t compCount = 0;
|
| 403 | constexpr std::string_view activeCompImageSetVersion{"VersionString1"};
|
| 404 | constexpr std::string_view pendingCompImageSetVersion{"VersionString2"};
|
| 405 |
|
| 406 | constexpr size_t getFwParamsPayloadLen =
|
| 407 | sizeof(pldm_get_firmware_parameters_resp) +
|
| 408 | activeCompImageSetVersion.size() + pendingCompImageSetVersion.size();
|
| 409 |
|
| 410 | constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
|
| 411 | getFwParamsResponse{
|
| 412 | 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
| 413 | 0x0e, 0x01, 0x0e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x53,
|
| 414 | 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x56, 0x65, 0x72, 0x73, 0x69,
|
| 415 | 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32};
|
| 416 |
|
| 417 | auto responseMsg =
|
| 418 | reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
|
| 419 | pldm_get_firmware_parameters_resp outResp{};
|
| 420 | variable_field outActiveCompImageSetVersion{};
|
| 421 | variable_field outPendingCompImageSetVersion{};
|
| 422 | variable_field outCompParameterTable{};
|
| 423 |
|
| 424 | auto rc = decode_get_firmware_parameters_resp(
|
| 425 | responseMsg, getFwParamsPayloadLen, &outResp,
|
| 426 | &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
|
| 427 | &outCompParameterTable);
|
| 428 |
|
| 429 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 430 | EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
|
| 431 | EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
|
| 432 | EXPECT_EQ(outResp.comp_count, compCount);
|
| 433 | EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
|
| 434 | EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
|
| 435 | activeCompImageSetVersion.size());
|
| 436 | EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
|
| 437 | EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len,
|
| 438 | pendingCompImageSetVersion.size());
|
| 439 | std::string activeCompImageSetVersionStr(
|
| 440 | reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
|
| 441 | outActiveCompImageSetVersion.length);
|
| 442 | EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
|
| 443 | std::string pendingCompImageSetVersionStr(
|
| 444 | reinterpret_cast<const char*>(outPendingCompImageSetVersion.ptr),
|
| 445 | outPendingCompImageSetVersion.length);
|
| 446 | EXPECT_EQ(pendingCompImageSetVersionStr, pendingCompImageSetVersion);
|
| 447 | EXPECT_EQ(outCompParameterTable.ptr, nullptr);
|
| 448 | EXPECT_EQ(outCompParameterTable.length, 0);
|
| 449 | }
|
| 450 |
|
| 451 | TEST(GetFirmwareParameters,
|
| 452 | decodeResponseNoPendingCompImageVersionStrZeroCompCount)
|
| 453 | {
|
| 454 | // CapabilitiesDuringUpdate of the firmware device
|
| 455 | // FD Host Functionality during Firmware Update [Bit position 2] &
|
| 456 | // Component Update Failure Retry Capability [Bit position 1]
|
| 457 | constexpr std::bitset<32> fdCapabilities{0x06};
|
| 458 | constexpr uint16_t compCount = 0;
|
| 459 | constexpr std::string_view activeCompImageSetVersion{"VersionString"};
|
| 460 |
|
| 461 | constexpr size_t getFwParamsPayloadLen =
|
| 462 | sizeof(pldm_get_firmware_parameters_resp) +
|
| 463 | activeCompImageSetVersion.size();
|
| 464 |
|
| 465 | constexpr std::array<uint8_t, hdrSize + getFwParamsPayloadLen>
|
| 466 | getFwParamsResponse{0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
|
| 467 | 0x00, 0x00, 0x00, 0x01, 0x0d, 0x00, 0x00,
|
| 468 | 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
|
| 469 | 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67};
|
| 470 |
|
| 471 | auto responseMsg =
|
| 472 | reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
|
| 473 | pldm_get_firmware_parameters_resp outResp{};
|
| 474 | variable_field outActiveCompImageSetVersion{};
|
| 475 | variable_field outPendingCompImageSetVersion{};
|
| 476 | variable_field outCompParameterTable{};
|
| 477 |
|
| 478 | auto rc = decode_get_firmware_parameters_resp(
|
| 479 | responseMsg, getFwParamsPayloadLen, &outResp,
|
| 480 | &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
|
| 481 | &outCompParameterTable);
|
| 482 |
|
| 483 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 484 | EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
|
| 485 | EXPECT_EQ(outResp.capabilities_during_update.value, fdCapabilities);
|
| 486 | EXPECT_EQ(outResp.comp_count, compCount);
|
| 487 | EXPECT_EQ(outResp.active_comp_image_set_ver_str_type, PLDM_STR_TYPE_ASCII);
|
| 488 | EXPECT_EQ(outResp.active_comp_image_set_ver_str_len,
|
| 489 | activeCompImageSetVersion.size());
|
| 490 | EXPECT_EQ(outResp.pending_comp_image_set_ver_str_type,
|
| 491 | PLDM_STR_TYPE_UNKNOWN);
|
| 492 | EXPECT_EQ(outResp.pending_comp_image_set_ver_str_len, 0);
|
| 493 | std::string activeCompImageSetVersionStr(
|
| 494 | reinterpret_cast<const char*>(outActiveCompImageSetVersion.ptr),
|
| 495 | outActiveCompImageSetVersion.length);
|
| 496 | EXPECT_EQ(activeCompImageSetVersionStr, activeCompImageSetVersion);
|
| 497 | EXPECT_EQ(outPendingCompImageSetVersion.ptr, nullptr);
|
| 498 | EXPECT_EQ(outPendingCompImageSetVersion.length, 0);
|
| 499 | EXPECT_EQ(outCompParameterTable.ptr, nullptr);
|
| 500 | EXPECT_EQ(outCompParameterTable.length, 0);
|
| 501 | }
|
| 502 |
|
| 503 | TEST(GetFirmwareParameters, decodeResponseErrorCompletionCode)
|
| 504 | {
|
| 505 | constexpr std::array<uint8_t,
|
| 506 | hdrSize + sizeof(pldm_get_firmware_parameters_resp)>
|
| 507 | getFwParamsResponse{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
| 508 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
| 509 |
|
| 510 | auto responseMsg =
|
| 511 | reinterpret_cast<const pldm_msg*>(getFwParamsResponse.data());
|
| 512 | pldm_get_firmware_parameters_resp outResp{};
|
| 513 | variable_field outActiveCompImageSetVersion{};
|
| 514 | variable_field outPendingCompImageSetVersion{};
|
| 515 | variable_field outCompParameterTable{};
|
| 516 |
|
| 517 | auto rc = decode_get_firmware_parameters_resp(
|
| 518 | responseMsg, getFwParamsResponse.size(), &outResp,
|
| 519 | &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
|
| 520 | &outCompParameterTable);
|
| 521 |
|
| 522 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 523 | EXPECT_EQ(outResp.completion_code, PLDM_ERROR);
|
| 524 | }
|
| 525 |
|
| 526 | TEST(GetFirmwareParameters, errorPathdecodeResponse)
|
| 527 | {
|
| 528 | int rc = 0;
|
| 529 | // Invalid ActiveComponentImageSetVersionStringType
|
| 530 | constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse1{
|
| 531 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
| 532 | 0x00, 0x00, 0x00, 0x06, 0x0e, 0x00, 0x00};
|
| 533 |
|
| 534 | auto responseMsg =
|
| 535 | reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse1.data());
|
| 536 | pldm_get_firmware_parameters_resp outResp{};
|
| 537 | variable_field outActiveCompImageSetVersion{};
|
| 538 | variable_field outPendingCompImageSetVersion{};
|
| 539 | variable_field outCompParameterTable{};
|
| 540 |
|
| 541 | rc = decode_get_firmware_parameters_resp(
|
| 542 | nullptr, invalidGetFwParamsResponse1.size(), &outResp,
|
| 543 | &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
|
| 544 | &outCompParameterTable);
|
| 545 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 546 |
|
| 547 | rc = decode_get_firmware_parameters_resp(
|
| 548 | responseMsg, invalidGetFwParamsResponse1.size(), nullptr,
|
| 549 | &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
|
| 550 | &outCompParameterTable);
|
| 551 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 552 |
|
| 553 | rc = decode_get_firmware_parameters_resp(
|
| 554 | responseMsg, invalidGetFwParamsResponse1.size(), &outResp, nullptr,
|
| 555 | &outPendingCompImageSetVersion, &outCompParameterTable);
|
| 556 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 557 |
|
| 558 | rc = decode_get_firmware_parameters_resp(
|
| 559 | responseMsg, invalidGetFwParamsResponse1.size(), &outResp,
|
| 560 | &outActiveCompImageSetVersion, nullptr, &outCompParameterTable);
|
| 561 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 562 |
|
| 563 | rc = decode_get_firmware_parameters_resp(
|
| 564 | responseMsg, invalidGetFwParamsResponse1.size(), &outResp,
|
| 565 | &outActiveCompImageSetVersion, &outPendingCompImageSetVersion, nullptr);
|
| 566 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 567 |
|
| 568 | rc = decode_get_firmware_parameters_resp(
|
| 569 | responseMsg, 0, &outResp, &outActiveCompImageSetVersion,
|
| 570 | &outPendingCompImageSetVersion, &outCompParameterTable);
|
| 571 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
|
| 572 |
|
| 573 | rc = decode_get_firmware_parameters_resp(
|
| 574 | responseMsg, invalidGetFwParamsResponse1.size(), &outResp,
|
| 575 | &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
|
| 576 | &outCompParameterTable);
|
| 577 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 578 |
|
| 579 | // Invalid ActiveComponentImageSetVersionStringLength
|
| 580 | constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse2{
|
| 581 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
| 582 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
|
| 583 | responseMsg =
|
| 584 | reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse2.data());
|
| 585 | rc = decode_get_firmware_parameters_resp(
|
| 586 | responseMsg, invalidGetFwParamsResponse2.size(), &outResp,
|
| 587 | &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
|
| 588 | &outCompParameterTable);
|
| 589 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 590 |
|
| 591 | // Invalid PendingComponentImageSetVersionStringType &
|
| 592 | // PendingComponentImageSetVersionStringLength
|
| 593 | constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse3{
|
| 594 | 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
|
| 595 | 0x00, 0x00, 0x00, 0x01, 0x0e, 0x01, 0x00};
|
| 596 | responseMsg =
|
| 597 | reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse3.data());
|
| 598 | rc = decode_get_firmware_parameters_resp(
|
| 599 | responseMsg, invalidGetFwParamsResponse3.size(), &outResp,
|
| 600 | &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
|
| 601 | &outCompParameterTable);
|
| 602 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 603 |
|
| 604 | // Invalid PendingComponentImageSetVersionStringType &
|
| 605 | // PendingComponentImageSetVersionStringLength
|
| 606 | constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse4{
|
| 607 | 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
|
| 608 | 0x00, 0x00, 0x00, 0x01, 0x0e, 0x06, 0x0e};
|
| 609 | responseMsg =
|
| 610 | reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse4.data());
|
| 611 | rc = decode_get_firmware_parameters_resp(
|
| 612 | responseMsg, invalidGetFwParamsResponse4.size(), &outResp,
|
| 613 | &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
|
| 614 | &outCompParameterTable);
|
| 615 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 616 |
|
| 617 | // Total payload length less than expected
|
| 618 | constexpr std::array<uint8_t, 14> invalidGetFwParamsResponse5{
|
| 619 | 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
|
| 620 | 0x00, 0x00, 0x00, 0x01, 0x0e, 0x01, 0x0e};
|
| 621 | responseMsg =
|
| 622 | reinterpret_cast<const pldm_msg*>(invalidGetFwParamsResponse5.data());
|
| 623 | rc = decode_get_firmware_parameters_resp(
|
| 624 | responseMsg, invalidGetFwParamsResponse5.size(), &outResp,
|
| 625 | &outActiveCompImageSetVersion, &outPendingCompImageSetVersion,
|
| 626 | &outCompParameterTable);
|
| 627 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
|
gokulsanker | 22fbb34 | 2021-04-05 15:55:06 +0530 | [diff] [blame] | 628 | }
|
gokulsanker | e1fb7a8 | 2021-04-05 16:09:29 +0530 | [diff] [blame] | 629 |
|
| 630 | TEST(GetFirmwareParameters, goodPathDecodeComponentParameterEntry)
|
| 631 | {
|
| 632 | // Random value for component classification
|
| 633 | constexpr uint16_t compClassification = 0x0A0B;
|
| 634 | // Random value for component classification
|
| 635 | constexpr uint16_t compIdentifier = 0x0C0D;
|
| 636 | // Random value for component classification
|
| 637 | constexpr uint32_t timestamp = 0X12345678;
|
| 638 | // Random value for component activation methods
|
| 639 | constexpr uint16_t compActivationMethods = 0xBBDD;
|
| 640 | // Random value for capabilities during update
|
| 641 | constexpr uint32_t capabilitiesDuringUpdate = 0xBADBEEFE;
|
| 642 |
|
| 643 | // ActiveCompImageSetVerStrLen is not fixed here taking it as 8
|
| 644 | constexpr uint8_t activeCompVerStrLen = 8;
|
| 645 | // PendingCompImageSetVerStrLen is not fixed here taking it as 8
|
| 646 | constexpr uint8_t pendingCompVerStrLen = 8;
|
| 647 | constexpr size_t entryLength =
|
| 648 | sizeof(struct pldm_component_parameter_entry) + activeCompVerStrLen +
|
| 649 | pendingCompVerStrLen;
|
| 650 | std::array<uint8_t, entryLength> entry{};
|
| 651 |
|
| 652 | auto inEntry =
|
| 653 | reinterpret_cast<struct pldm_component_parameter_entry*>(entry.data());
|
| 654 |
|
| 655 | inEntry->comp_classification = htole16(compClassification);
|
| 656 | inEntry->comp_identifier = htole16(compIdentifier);
|
| 657 | inEntry->comp_classification_index = 0x0F;
|
| 658 | inEntry->active_comp_comparison_stamp = htole32(timestamp);
|
| 659 | inEntry->active_comp_ver_str_type = 1;
|
| 660 | inEntry->active_comp_ver_str_len = activeCompVerStrLen;
|
| 661 | std::fill_n(inEntry->active_comp_release_date,
|
| 662 | sizeof(inEntry->active_comp_release_date), 0xFF);
|
| 663 | inEntry->pending_comp_comparison_stamp = htole32(timestamp);
|
| 664 | inEntry->pending_comp_ver_str_type = 1;
|
| 665 | inEntry->pending_comp_ver_str_len = pendingCompVerStrLen;
|
| 666 | std::fill_n(inEntry->pending_comp_release_date,
|
| 667 | sizeof(inEntry->pending_comp_release_date), 0xFF);
|
| 668 | inEntry->comp_activation_methods.value = htole16(compActivationMethods);
|
| 669 | inEntry->capabilities_during_update.value =
|
| 670 | htole32(capabilitiesDuringUpdate);
|
| 671 | constexpr auto activeCompVerStrPos =
|
| 672 | sizeof(struct pldm_component_parameter_entry);
|
| 673 | std::fill_n(entry.data() + activeCompVerStrPos, activeCompVerStrLen, 0xAA);
|
| 674 | constexpr auto pendingCompVerStrPos =
|
| 675 | activeCompVerStrPos + activeCompVerStrLen;
|
| 676 | std::fill_n(entry.data() + pendingCompVerStrPos, pendingCompVerStrLen,
|
| 677 | 0xBB);
|
| 678 |
|
| 679 | struct pldm_component_parameter_entry outEntry;
|
| 680 | struct variable_field outActiveCompVerStr;
|
| 681 | struct variable_field outPendingCompVerStr;
|
| 682 |
|
| 683 | auto rc = decode_get_firmware_parameters_resp_comp_entry(
|
| 684 | entry.data(), entryLength, &outEntry, &outActiveCompVerStr,
|
| 685 | &outPendingCompVerStr);
|
| 686 |
|
| 687 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 688 |
|
| 689 | EXPECT_EQ(outEntry.comp_classification, compClassification);
|
| 690 | EXPECT_EQ(outEntry.comp_identifier, compIdentifier);
|
| 691 | EXPECT_EQ(inEntry->comp_classification_index,
|
| 692 | outEntry.comp_classification_index);
|
| 693 | EXPECT_EQ(outEntry.active_comp_comparison_stamp, timestamp);
|
| 694 | EXPECT_EQ(inEntry->active_comp_ver_str_type,
|
| 695 | outEntry.active_comp_ver_str_type);
|
| 696 | EXPECT_EQ(inEntry->active_comp_ver_str_len,
|
| 697 | outEntry.active_comp_ver_str_len);
|
| 698 | EXPECT_EQ(0, memcmp(inEntry->active_comp_release_date,
|
| 699 | outEntry.active_comp_release_date,
|
| 700 | sizeof(inEntry->active_comp_release_date)));
|
| 701 | EXPECT_EQ(outEntry.pending_comp_comparison_stamp, timestamp);
|
| 702 | EXPECT_EQ(inEntry->pending_comp_ver_str_type,
|
| 703 | outEntry.pending_comp_ver_str_type);
|
| 704 | EXPECT_EQ(inEntry->pending_comp_ver_str_len,
|
| 705 | outEntry.pending_comp_ver_str_len);
|
| 706 | EXPECT_EQ(0, memcmp(inEntry->pending_comp_release_date,
|
| 707 | outEntry.pending_comp_release_date,
|
| 708 | sizeof(inEntry->pending_comp_release_date)));
|
| 709 | EXPECT_EQ(outEntry.comp_activation_methods.value, compActivationMethods);
|
| 710 | EXPECT_EQ(outEntry.capabilities_during_update.value,
|
| 711 | capabilitiesDuringUpdate);
|
| 712 |
|
| 713 | EXPECT_EQ(0, memcmp(outActiveCompVerStr.ptr,
|
| 714 | entry.data() + activeCompVerStrPos,
|
| 715 | outActiveCompVerStr.length));
|
| 716 | EXPECT_EQ(0, memcmp(outPendingCompVerStr.ptr,
|
| 717 | entry.data() + pendingCompVerStrPos,
|
| 718 | outPendingCompVerStr.length));
|
| 719 | }
|