Tom Joseph | 763b51e | 2021-06-05 04:50:47 -0700 | [diff] [blame^] | 1 | #include <cstring>
|
| 2 |
|
gokulsanker | 138ceba | 2021-04-05 13:25:25 +0530 | [diff] [blame] | 3 | #include "libpldm/base.h"
|
| 4 | #include "libpldm/firmware_update.h"
|
| 5 |
|
| 6 | #include <gtest/gtest.h>
|
| 7 |
|
| 8 | constexpr auto hdrSize = sizeof(pldm_msg_hdr);
|
| 9 |
|
Tom Joseph | 763b51e | 2021-06-05 04:50:47 -0700 | [diff] [blame^] | 10 | TEST(DecodeDescriptors, goodPath3Descriptors)
|
| 11 | {
|
| 12 | // In the descriptor data there are 3 descriptor entries
|
| 13 | // 1) IANA enterprise ID
|
| 14 | constexpr std::array<uint8_t, PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH> iana{
|
| 15 | 0x0a, 0x0b, 0x0c, 0xd};
|
| 16 | // 2) UUID
|
| 17 | constexpr std::array<uint8_t, PLDM_FWUP_UUID_LENGTH> uuid{
|
| 18 | 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18,
|
| 19 | 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b};
|
| 20 | // 3) Vendor Defined
|
| 21 | constexpr std::string_view vendorTitle{"OpenBMC"};
|
| 22 | constexpr size_t vendorDescriptorLen = 2;
|
| 23 | constexpr std::array<uint8_t, vendorDescriptorLen> vendorDescriptorData{
|
| 24 | 0x01, 0x02};
|
| 25 |
|
| 26 | constexpr size_t vendorDefinedDescriptorLen =
|
| 27 | sizeof(pldm_vendor_defined_descriptor_title_data()
|
| 28 | .vendor_defined_descriptor_title_str_type) +
|
| 29 | sizeof(pldm_vendor_defined_descriptor_title_data()
|
| 30 | .vendor_defined_descriptor_title_str_len) +
|
| 31 | vendorTitle.size() + vendorDescriptorData.size();
|
| 32 |
|
| 33 | constexpr size_t descriptorsLength =
|
| 34 | 3 * (sizeof(pldm_descriptor_tlv().descriptor_type) +
|
| 35 | sizeof(pldm_descriptor_tlv().descriptor_length)) +
|
| 36 | iana.size() + uuid.size() + vendorDefinedDescriptorLen;
|
| 37 |
|
| 38 | constexpr std::array<uint8_t, descriptorsLength> descriptors{
|
| 39 | 0x01, 0x00, 0x04, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x02, 0x00, 0x10,
|
| 40 | 0x00, 0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18, 0xa0, 0x30,
|
| 41 | 0xfc, 0x8a, 0x56, 0x58, 0x7d, 0x5b, 0xFF, 0xFF, 0x0B, 0x00, 0x01,
|
| 42 | 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43, 0x01, 0x02};
|
| 43 |
|
| 44 | size_t descriptorCount = 1;
|
| 45 | size_t descriptorsRemainingLength = descriptorsLength;
|
| 46 | int rc = 0;
|
| 47 |
|
| 48 | while (descriptorsRemainingLength && (descriptorCount <= 3))
|
| 49 | {
|
| 50 | uint16_t descriptorType = 0;
|
| 51 | uint16_t descriptorLen = 0;
|
| 52 | variable_field descriptorData{};
|
| 53 |
|
| 54 | rc = decode_descriptor_type_length_value(
|
| 55 | descriptors.data() + descriptorsLength - descriptorsRemainingLength,
|
| 56 | descriptorsRemainingLength, &descriptorType, &descriptorData);
|
| 57 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 58 |
|
| 59 | if (descriptorCount == 1)
|
| 60 | {
|
| 61 | EXPECT_EQ(descriptorType, PLDM_FWUP_IANA_ENTERPRISE_ID);
|
| 62 | EXPECT_EQ(descriptorData.length,
|
| 63 | PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH);
|
| 64 | EXPECT_EQ(true,
|
| 65 | std::equal(descriptorData.ptr,
|
| 66 | descriptorData.ptr + descriptorData.length,
|
| 67 | iana.begin(), iana.end()));
|
| 68 | }
|
| 69 | else if (descriptorCount == 2)
|
| 70 | {
|
| 71 | EXPECT_EQ(descriptorType, PLDM_FWUP_UUID);
|
| 72 | EXPECT_EQ(descriptorData.length, PLDM_FWUP_UUID_LENGTH);
|
| 73 | EXPECT_EQ(true,
|
| 74 | std::equal(descriptorData.ptr,
|
| 75 | descriptorData.ptr + descriptorData.length,
|
| 76 | uuid.begin(), uuid.end()));
|
| 77 | }
|
| 78 | else if (descriptorCount == 3)
|
| 79 | {
|
| 80 | EXPECT_EQ(descriptorType, PLDM_FWUP_VENDOR_DEFINED);
|
| 81 | EXPECT_EQ(descriptorData.length, vendorDefinedDescriptorLen);
|
| 82 |
|
| 83 | uint8_t descriptorTitleStrType = 0;
|
| 84 | variable_field descriptorTitleStr{};
|
| 85 | variable_field vendorDefinedDescriptorData{};
|
| 86 |
|
| 87 | rc = decode_vendor_defined_descriptor_value(
|
| 88 | descriptorData.ptr, descriptorData.length,
|
| 89 | &descriptorTitleStrType, &descriptorTitleStr,
|
| 90 | &vendorDefinedDescriptorData);
|
| 91 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 92 |
|
| 93 | EXPECT_EQ(descriptorTitleStrType, PLDM_STR_TYPE_ASCII);
|
| 94 | EXPECT_EQ(descriptorTitleStr.length, vendorTitle.size());
|
| 95 | std::string vendorTitleStr(
|
| 96 | reinterpret_cast<const char*>(descriptorTitleStr.ptr),
|
| 97 | descriptorTitleStr.length);
|
| 98 | EXPECT_EQ(vendorTitleStr, vendorTitle);
|
| 99 |
|
| 100 | EXPECT_EQ(vendorDefinedDescriptorData.length,
|
| 101 | vendorDescriptorData.size());
|
| 102 | EXPECT_EQ(true, std::equal(vendorDefinedDescriptorData.ptr,
|
| 103 | vendorDefinedDescriptorData.ptr +
|
| 104 | vendorDefinedDescriptorData.length,
|
| 105 | vendorDescriptorData.begin(),
|
| 106 | vendorDescriptorData.end()));
|
| 107 | }
|
| 108 |
|
| 109 | descriptorsRemainingLength -= sizeof(descriptorType) +
|
| 110 | sizeof(descriptorLen) +
|
| 111 | descriptorData.length;
|
| 112 | descriptorCount++;
|
| 113 | }
|
| 114 | }
|
| 115 |
|
| 116 | TEST(DecodeDescriptors, errorPathDecodeDescriptorTLV)
|
| 117 | {
|
| 118 | int rc = 0;
|
| 119 | // IANA Enterprise ID descriptor length incorrect
|
| 120 | constexpr std::array<uint8_t, 7> invalidIANADescriptor1{
|
| 121 | 0x01, 0x00, 0x03, 0x00, 0x0a, 0x0b, 0x0c};
|
| 122 | uint16_t descriptorType = 0;
|
| 123 | variable_field descriptorData{};
|
| 124 |
|
| 125 | rc = decode_descriptor_type_length_value(nullptr,
|
| 126 | invalidIANADescriptor1.size(),
|
| 127 | &descriptorType, &descriptorData);
|
| 128 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 129 |
|
| 130 | rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
|
| 131 | invalidIANADescriptor1.size(),
|
| 132 | nullptr, &descriptorData);
|
| 133 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 134 |
|
| 135 | rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
|
| 136 | invalidIANADescriptor1.size(),
|
| 137 | &descriptorType, nullptr);
|
| 138 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 139 |
|
| 140 | rc = decode_descriptor_type_length_value(
|
| 141 | invalidIANADescriptor1.data(), PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN - 1,
|
| 142 | &descriptorType, &descriptorData);
|
| 143 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
|
| 144 |
|
| 145 | rc = decode_descriptor_type_length_value(invalidIANADescriptor1.data(),
|
| 146 | invalidIANADescriptor1.size(),
|
| 147 | &descriptorType, &descriptorData);
|
| 148 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
|
| 149 |
|
| 150 | // IANA Enterprise ID descriptor data less than length
|
| 151 | std::array<uint8_t, 7> invalidIANADescriptor2{0x01, 0x00, 0x04, 0x00,
|
| 152 | 0x0a, 0x0b, 0x0c};
|
| 153 | rc = decode_descriptor_type_length_value(invalidIANADescriptor2.data(),
|
| 154 | invalidIANADescriptor2.size(),
|
| 155 | &descriptorType, &descriptorData);
|
| 156 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
|
| 157 | }
|
| 158 |
|
| 159 | TEST(DecodeDescriptors, errorPathVendorDefinedDescriptor)
|
| 160 | {
|
| 161 | int rc = 0;
|
| 162 | // VendorDefinedDescriptorTitleStringType is invalid
|
| 163 | constexpr std::array<uint8_t, 9> invalidVendorDescriptor1{
|
| 164 | 0x06, 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
|
| 165 | uint8_t descriptorStringType = 0;
|
| 166 | variable_field descriptorTitleStr{};
|
| 167 | variable_field vendorDefinedDescriptorData{};
|
| 168 |
|
| 169 | rc = decode_vendor_defined_descriptor_value(
|
| 170 | nullptr, invalidVendorDescriptor1.size(), &descriptorStringType,
|
| 171 | &descriptorTitleStr, &vendorDefinedDescriptorData);
|
| 172 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 173 |
|
| 174 | rc = decode_vendor_defined_descriptor_value(
|
| 175 | invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
|
| 176 | &descriptorStringType, &descriptorTitleStr,
|
| 177 | &vendorDefinedDescriptorData);
|
| 178 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 179 |
|
| 180 | rc = decode_vendor_defined_descriptor_value(
|
| 181 | invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
|
| 182 | nullptr, &descriptorTitleStr, &vendorDefinedDescriptorData);
|
| 183 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 184 |
|
| 185 | rc = decode_vendor_defined_descriptor_value(
|
| 186 | invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
|
| 187 | &descriptorStringType, nullptr, &vendorDefinedDescriptorData);
|
| 188 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 189 |
|
| 190 | rc = decode_vendor_defined_descriptor_value(
|
| 191 | invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
|
| 192 | &descriptorStringType, &descriptorTitleStr, nullptr);
|
| 193 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 194 |
|
| 195 | rc = decode_vendor_defined_descriptor_value(
|
| 196 | invalidVendorDescriptor1.data(),
|
| 197 | sizeof(pldm_vendor_defined_descriptor_title_data) - 1,
|
| 198 | &descriptorStringType, &descriptorTitleStr,
|
| 199 | &vendorDefinedDescriptorData);
|
| 200 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
|
| 201 |
|
| 202 | rc = decode_vendor_defined_descriptor_value(
|
| 203 | invalidVendorDescriptor1.data(), invalidVendorDescriptor1.size(),
|
| 204 | &descriptorStringType, &descriptorTitleStr,
|
| 205 | &vendorDefinedDescriptorData);
|
| 206 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 207 |
|
| 208 | // VendorDefinedDescriptorTitleStringLength is 0
|
| 209 | std::array<uint8_t, 9> invalidVendorDescriptor2{
|
| 210 | 0x01, 0x00, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
|
| 211 | rc = decode_vendor_defined_descriptor_value(
|
| 212 | invalidVendorDescriptor2.data(), invalidVendorDescriptor2.size(),
|
| 213 | &descriptorStringType, &descriptorTitleStr,
|
| 214 | &vendorDefinedDescriptorData);
|
| 215 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
|
| 216 |
|
| 217 | // VendorDefinedDescriptorData not present in the data
|
| 218 | std::array<uint8_t, 9> invalidVendorDescriptor3{
|
| 219 | 0x01, 0x07, 0x4f, 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43};
|
| 220 | rc = decode_vendor_defined_descriptor_value(
|
| 221 | invalidVendorDescriptor3.data(), invalidVendorDescriptor3.size(),
|
| 222 | &descriptorStringType, &descriptorTitleStr,
|
| 223 | &vendorDefinedDescriptorData);
|
| 224 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
|
| 225 | }
|
| 226 |
|
gokulsanker | 138ceba | 2021-04-05 13:25:25 +0530 | [diff] [blame] | 227 | TEST(QueryDeviceIdentifiers, goodPathEncodeRequest)
|
| 228 | {
|
| 229 | std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
|
| 230 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
|
| 231 |
|
| 232 | uint8_t instanceId = 0x01;
|
| 233 |
|
| 234 | auto rc = encode_query_device_identifiers_req(
|
| 235 | instanceId, PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES, requestPtr);
|
| 236 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 237 | EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
|
| 238 | EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
|
| 239 | EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
|
| 240 | EXPECT_EQ(requestPtr->hdr.command, PLDM_QUERY_DEVICE_IDENTIFIERS);
|
| 241 | }
|
gokulsanker | eca3e19 | 2021-04-05 14:57:41 +0530 | [diff] [blame] | 242 |
|
| 243 | TEST(QueryDeviceIdentifiers, goodPathDecodeResponse)
|
| 244 | {
|
| 245 | // descriptorDataLen is not fixed here taking it as 6
|
| 246 | constexpr uint8_t descriptorDataLen = 6;
|
| 247 | std::array<uint8_t, hdrSize +
|
| 248 | sizeof(struct pldm_query_device_identifiers_resp) +
|
| 249 | descriptorDataLen>
|
| 250 | responseMsg{};
|
| 251 | auto inResp = reinterpret_cast<struct pldm_query_device_identifiers_resp*>(
|
| 252 | responseMsg.data() + hdrSize);
|
| 253 |
|
| 254 | inResp->completion_code = PLDM_SUCCESS;
|
| 255 | inResp->device_identifiers_len = htole32(descriptorDataLen);
|
| 256 | inResp->descriptor_count = 1;
|
| 257 |
|
| 258 | // filling descriptor data
|
| 259 | std::fill_n(responseMsg.data() + hdrSize +
|
| 260 | sizeof(struct pldm_query_device_identifiers_resp),
|
| 261 | descriptorDataLen, 0xFF);
|
| 262 |
|
| 263 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
|
| 264 | uint8_t completionCode = PLDM_SUCCESS;
|
| 265 | uint32_t deviceIdentifiersLen = 0;
|
| 266 | uint8_t descriptorCount = 0;
|
| 267 | uint8_t* outDescriptorData = nullptr;
|
| 268 |
|
| 269 | auto rc = decode_query_device_identifiers_resp(
|
| 270 | response, responseMsg.size() - hdrSize, &completionCode,
|
| 271 | &deviceIdentifiersLen, &descriptorCount, &outDescriptorData);
|
| 272 |
|
| 273 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 274 | EXPECT_EQ(completionCode, PLDM_SUCCESS);
|
| 275 | EXPECT_EQ(deviceIdentifiersLen, inResp->device_identifiers_len);
|
| 276 | EXPECT_EQ(descriptorCount, inResp->descriptor_count);
|
| 277 | EXPECT_EQ(true,
|
| 278 | std::equal(outDescriptorData,
|
| 279 | outDescriptorData + deviceIdentifiersLen,
|
| 280 | responseMsg.begin() + hdrSize +
|
| 281 | sizeof(struct pldm_query_device_identifiers_resp),
|
| 282 | responseMsg.end()));
|
| 283 | }
|
gokulsanker | 981fbfb | 2021-04-05 15:17:25 +0530 | [diff] [blame] | 284 |
|
| 285 | TEST(GetFirmwareParameters, goodPathEncodeRequest)
|
| 286 | {
|
| 287 | std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
|
| 288 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
|
| 289 | uint8_t instanceId = 0x01;
|
| 290 |
|
| 291 | auto rc = encode_get_firmware_parameters_req(
|
| 292 | instanceId, PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES, requestPtr);
|
| 293 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 294 | EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
|
| 295 | EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
|
| 296 | EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
|
| 297 | EXPECT_EQ(requestPtr->hdr.command, PLDM_GET_FIRMWARE_PARAMETERS);
|
| 298 | }
|
gokulsanker | 22fbb34 | 2021-04-05 15:55:06 +0530 | [diff] [blame] | 299 |
|
| 300 | TEST(GetFirmwareParameters, goodPathDecodeResponseComponentSetInfo)
|
| 301 | {
|
| 302 | // Random value for capabilities during update
|
| 303 | constexpr uint32_t capabilitiesDuringUpdate = 0xBADBEEFE;
|
| 304 | // Random value for component count
|
| 305 | constexpr uint16_t componentCount = 0xAABB;
|
| 306 | // ActiveCompImageSetVerStrLen is not fixed here taking it as 8
|
| 307 | constexpr uint8_t activeCompImageSetVerStrLen = 8;
|
| 308 | // PendingCompImageSetVerStrLen is not fixed here taking it as 8
|
| 309 | constexpr uint8_t pendingCompImageSetVerStrLen = 8;
|
| 310 | constexpr size_t payloadLen =
|
| 311 | sizeof(struct pldm_get_firmware_parameters_resp) +
|
| 312 | activeCompImageSetVerStrLen + pendingCompImageSetVerStrLen;
|
| 313 |
|
| 314 | std::array<uint8_t, hdrSize + payloadLen> response{};
|
| 315 | auto inResp = reinterpret_cast<struct pldm_get_firmware_parameters_resp*>(
|
| 316 | response.data() + hdrSize);
|
| 317 | inResp->completion_code = PLDM_SUCCESS;
|
| 318 | inResp->capabilities_during_update.value =
|
| 319 | htole32(capabilitiesDuringUpdate);
|
| 320 | inResp->comp_count = htole16(componentCount);
|
| 321 | inResp->active_comp_image_set_ver_str_type = 1;
|
| 322 | inResp->active_comp_image_set_ver_str_len = activeCompImageSetVerStrLen;
|
| 323 | inResp->pending_comp_image_set_ver_str_type = 1;
|
| 324 | inResp->pending_comp_image_set_ver_str_len = pendingCompImageSetVerStrLen;
|
| 325 |
|
| 326 | constexpr size_t activeCompImageSetVerStrPos =
|
| 327 | hdrSize + sizeof(struct pldm_get_firmware_parameters_resp);
|
| 328 | // filling default values for ActiveComponentImageSetVersionString
|
| 329 | std::fill_n(response.data() + activeCompImageSetVerStrPos,
|
| 330 | activeCompImageSetVerStrLen, 0xFF);
|
| 331 | constexpr size_t pendingCompImageSetVerStrPos =
|
| 332 | hdrSize + sizeof(struct pldm_get_firmware_parameters_resp) +
|
| 333 | activeCompImageSetVerStrLen;
|
| 334 | // filling default values for ActiveComponentImageSetVersionString
|
| 335 | std::fill_n(response.data() + pendingCompImageSetVerStrPos,
|
| 336 | pendingCompImageSetVerStrLen, 0xFF);
|
| 337 |
|
| 338 | auto responseMsg = reinterpret_cast<pldm_msg*>(response.data());
|
| 339 | struct pldm_get_firmware_parameters_resp outResp;
|
| 340 | struct variable_field outActiveCompImageSetVerStr;
|
| 341 | struct variable_field outPendingCompImageSetVerStr;
|
| 342 |
|
| 343 | auto rc = decode_get_firmware_parameters_resp_comp_set_info(
|
| 344 | responseMsg, payloadLen, &outResp, &outActiveCompImageSetVerStr,
|
| 345 | &outPendingCompImageSetVerStr);
|
| 346 |
|
| 347 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 348 | EXPECT_EQ(outResp.completion_code, PLDM_SUCCESS);
|
| 349 | EXPECT_EQ(outResp.capabilities_during_update.value,
|
| 350 | capabilitiesDuringUpdate);
|
| 351 | EXPECT_EQ(outResp.comp_count, componentCount);
|
| 352 | EXPECT_EQ(inResp->active_comp_image_set_ver_str_type,
|
| 353 | outResp.active_comp_image_set_ver_str_type);
|
| 354 | EXPECT_EQ(inResp->active_comp_image_set_ver_str_len,
|
| 355 | outResp.active_comp_image_set_ver_str_len);
|
| 356 | EXPECT_EQ(0, memcmp(outActiveCompImageSetVerStr.ptr,
|
| 357 | response.data() + activeCompImageSetVerStrPos,
|
| 358 | outActiveCompImageSetVerStr.length));
|
| 359 |
|
| 360 | EXPECT_EQ(inResp->pending_comp_image_set_ver_str_type,
|
| 361 | outResp.pending_comp_image_set_ver_str_type);
|
| 362 | EXPECT_EQ(inResp->pending_comp_image_set_ver_str_len,
|
| 363 | outResp.pending_comp_image_set_ver_str_len);
|
| 364 | EXPECT_EQ(0, memcmp(outPendingCompImageSetVerStr.ptr,
|
| 365 | response.data() + pendingCompImageSetVerStrPos,
|
| 366 | outPendingCompImageSetVerStr.length));
|
| 367 | }
|
gokulsanker | e1fb7a8 | 2021-04-05 16:09:29 +0530 | [diff] [blame] | 368 |
|
| 369 | TEST(GetFirmwareParameters, goodPathDecodeComponentParameterEntry)
|
| 370 | {
|
| 371 | // Random value for component classification
|
| 372 | constexpr uint16_t compClassification = 0x0A0B;
|
| 373 | // Random value for component classification
|
| 374 | constexpr uint16_t compIdentifier = 0x0C0D;
|
| 375 | // Random value for component classification
|
| 376 | constexpr uint32_t timestamp = 0X12345678;
|
| 377 | // Random value for component activation methods
|
| 378 | constexpr uint16_t compActivationMethods = 0xBBDD;
|
| 379 | // Random value for capabilities during update
|
| 380 | constexpr uint32_t capabilitiesDuringUpdate = 0xBADBEEFE;
|
| 381 |
|
| 382 | // ActiveCompImageSetVerStrLen is not fixed here taking it as 8
|
| 383 | constexpr uint8_t activeCompVerStrLen = 8;
|
| 384 | // PendingCompImageSetVerStrLen is not fixed here taking it as 8
|
| 385 | constexpr uint8_t pendingCompVerStrLen = 8;
|
| 386 | constexpr size_t entryLength =
|
| 387 | sizeof(struct pldm_component_parameter_entry) + activeCompVerStrLen +
|
| 388 | pendingCompVerStrLen;
|
| 389 | std::array<uint8_t, entryLength> entry{};
|
| 390 |
|
| 391 | auto inEntry =
|
| 392 | reinterpret_cast<struct pldm_component_parameter_entry*>(entry.data());
|
| 393 |
|
| 394 | inEntry->comp_classification = htole16(compClassification);
|
| 395 | inEntry->comp_identifier = htole16(compIdentifier);
|
| 396 | inEntry->comp_classification_index = 0x0F;
|
| 397 | inEntry->active_comp_comparison_stamp = htole32(timestamp);
|
| 398 | inEntry->active_comp_ver_str_type = 1;
|
| 399 | inEntry->active_comp_ver_str_len = activeCompVerStrLen;
|
| 400 | std::fill_n(inEntry->active_comp_release_date,
|
| 401 | sizeof(inEntry->active_comp_release_date), 0xFF);
|
| 402 | inEntry->pending_comp_comparison_stamp = htole32(timestamp);
|
| 403 | inEntry->pending_comp_ver_str_type = 1;
|
| 404 | inEntry->pending_comp_ver_str_len = pendingCompVerStrLen;
|
| 405 | std::fill_n(inEntry->pending_comp_release_date,
|
| 406 | sizeof(inEntry->pending_comp_release_date), 0xFF);
|
| 407 | inEntry->comp_activation_methods.value = htole16(compActivationMethods);
|
| 408 | inEntry->capabilities_during_update.value =
|
| 409 | htole32(capabilitiesDuringUpdate);
|
| 410 | constexpr auto activeCompVerStrPos =
|
| 411 | sizeof(struct pldm_component_parameter_entry);
|
| 412 | std::fill_n(entry.data() + activeCompVerStrPos, activeCompVerStrLen, 0xAA);
|
| 413 | constexpr auto pendingCompVerStrPos =
|
| 414 | activeCompVerStrPos + activeCompVerStrLen;
|
| 415 | std::fill_n(entry.data() + pendingCompVerStrPos, pendingCompVerStrLen,
|
| 416 | 0xBB);
|
| 417 |
|
| 418 | struct pldm_component_parameter_entry outEntry;
|
| 419 | struct variable_field outActiveCompVerStr;
|
| 420 | struct variable_field outPendingCompVerStr;
|
| 421 |
|
| 422 | auto rc = decode_get_firmware_parameters_resp_comp_entry(
|
| 423 | entry.data(), entryLength, &outEntry, &outActiveCompVerStr,
|
| 424 | &outPendingCompVerStr);
|
| 425 |
|
| 426 | EXPECT_EQ(rc, PLDM_SUCCESS);
|
| 427 |
|
| 428 | EXPECT_EQ(outEntry.comp_classification, compClassification);
|
| 429 | EXPECT_EQ(outEntry.comp_identifier, compIdentifier);
|
| 430 | EXPECT_EQ(inEntry->comp_classification_index,
|
| 431 | outEntry.comp_classification_index);
|
| 432 | EXPECT_EQ(outEntry.active_comp_comparison_stamp, timestamp);
|
| 433 | EXPECT_EQ(inEntry->active_comp_ver_str_type,
|
| 434 | outEntry.active_comp_ver_str_type);
|
| 435 | EXPECT_EQ(inEntry->active_comp_ver_str_len,
|
| 436 | outEntry.active_comp_ver_str_len);
|
| 437 | EXPECT_EQ(0, memcmp(inEntry->active_comp_release_date,
|
| 438 | outEntry.active_comp_release_date,
|
| 439 | sizeof(inEntry->active_comp_release_date)));
|
| 440 | EXPECT_EQ(outEntry.pending_comp_comparison_stamp, timestamp);
|
| 441 | EXPECT_EQ(inEntry->pending_comp_ver_str_type,
|
| 442 | outEntry.pending_comp_ver_str_type);
|
| 443 | EXPECT_EQ(inEntry->pending_comp_ver_str_len,
|
| 444 | outEntry.pending_comp_ver_str_len);
|
| 445 | EXPECT_EQ(0, memcmp(inEntry->pending_comp_release_date,
|
| 446 | outEntry.pending_comp_release_date,
|
| 447 | sizeof(inEntry->pending_comp_release_date)));
|
| 448 | EXPECT_EQ(outEntry.comp_activation_methods.value, compActivationMethods);
|
| 449 | EXPECT_EQ(outEntry.capabilities_during_update.value,
|
| 450 | capabilitiesDuringUpdate);
|
| 451 |
|
| 452 | EXPECT_EQ(0, memcmp(outActiveCompVerStr.ptr,
|
| 453 | entry.data() + activeCompVerStrPos,
|
| 454 | outActiveCompVerStr.length));
|
| 455 | EXPECT_EQ(0, memcmp(outPendingCompVerStr.ptr,
|
| 456 | entry.data() + pendingCompVerStrPos,
|
| 457 | outPendingCompVerStr.length));
|
| 458 | }
|