libpldm: Add decode API for ComponentParameterTable entry
ComponentParameterTable is present in the response of
GetFirmwareParameters command. ComponentParameterTable is a table that
contains component entries for all of the updateable components which
reside on the firmware device.
decode_get_firmware_parameters_resp_comp_entry decodes each entry in
the ComponentParameterTable.
Tested: Unit tests passed
Signed-off-by: gokulsanker <gokul.sanker.v.g@intel.com>
Change-Id: I3698b268cf42345d80d7d218919d42ffad0b011f
diff --git a/libpldm/tests/libpldm_firmware_update_test.cpp b/libpldm/tests/libpldm_firmware_update_test.cpp
index b02e8ca..3e35cf6 100644
--- a/libpldm/tests/libpldm_firmware_update_test.cpp
+++ b/libpldm/tests/libpldm_firmware_update_test.cpp
@@ -146,3 +146,94 @@
response.data() + pendingCompImageSetVerStrPos,
outPendingCompImageSetVerStr.length));
}
+
+TEST(GetFirmwareParameters, goodPathDecodeComponentParameterEntry)
+{
+ // Random value for component classification
+ constexpr uint16_t compClassification = 0x0A0B;
+ // Random value for component classification
+ constexpr uint16_t compIdentifier = 0x0C0D;
+ // Random value for component classification
+ constexpr uint32_t timestamp = 0X12345678;
+ // Random value for component activation methods
+ constexpr uint16_t compActivationMethods = 0xBBDD;
+ // Random value for capabilities during update
+ constexpr uint32_t capabilitiesDuringUpdate = 0xBADBEEFE;
+
+ // ActiveCompImageSetVerStrLen is not fixed here taking it as 8
+ constexpr uint8_t activeCompVerStrLen = 8;
+ // PendingCompImageSetVerStrLen is not fixed here taking it as 8
+ constexpr uint8_t pendingCompVerStrLen = 8;
+ constexpr size_t entryLength =
+ sizeof(struct pldm_component_parameter_entry) + activeCompVerStrLen +
+ pendingCompVerStrLen;
+ std::array<uint8_t, entryLength> entry{};
+
+ auto inEntry =
+ reinterpret_cast<struct pldm_component_parameter_entry*>(entry.data());
+
+ inEntry->comp_classification = htole16(compClassification);
+ inEntry->comp_identifier = htole16(compIdentifier);
+ inEntry->comp_classification_index = 0x0F;
+ inEntry->active_comp_comparison_stamp = htole32(timestamp);
+ inEntry->active_comp_ver_str_type = 1;
+ inEntry->active_comp_ver_str_len = activeCompVerStrLen;
+ std::fill_n(inEntry->active_comp_release_date,
+ sizeof(inEntry->active_comp_release_date), 0xFF);
+ inEntry->pending_comp_comparison_stamp = htole32(timestamp);
+ inEntry->pending_comp_ver_str_type = 1;
+ inEntry->pending_comp_ver_str_len = pendingCompVerStrLen;
+ std::fill_n(inEntry->pending_comp_release_date,
+ sizeof(inEntry->pending_comp_release_date), 0xFF);
+ inEntry->comp_activation_methods.value = htole16(compActivationMethods);
+ inEntry->capabilities_during_update.value =
+ htole32(capabilitiesDuringUpdate);
+ constexpr auto activeCompVerStrPos =
+ sizeof(struct pldm_component_parameter_entry);
+ std::fill_n(entry.data() + activeCompVerStrPos, activeCompVerStrLen, 0xAA);
+ constexpr auto pendingCompVerStrPos =
+ activeCompVerStrPos + activeCompVerStrLen;
+ std::fill_n(entry.data() + pendingCompVerStrPos, pendingCompVerStrLen,
+ 0xBB);
+
+ struct pldm_component_parameter_entry outEntry;
+ struct variable_field outActiveCompVerStr;
+ struct variable_field outPendingCompVerStr;
+
+ auto rc = decode_get_firmware_parameters_resp_comp_entry(
+ entry.data(), entryLength, &outEntry, &outActiveCompVerStr,
+ &outPendingCompVerStr);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+
+ EXPECT_EQ(outEntry.comp_classification, compClassification);
+ EXPECT_EQ(outEntry.comp_identifier, compIdentifier);
+ EXPECT_EQ(inEntry->comp_classification_index,
+ outEntry.comp_classification_index);
+ EXPECT_EQ(outEntry.active_comp_comparison_stamp, timestamp);
+ EXPECT_EQ(inEntry->active_comp_ver_str_type,
+ outEntry.active_comp_ver_str_type);
+ EXPECT_EQ(inEntry->active_comp_ver_str_len,
+ outEntry.active_comp_ver_str_len);
+ EXPECT_EQ(0, memcmp(inEntry->active_comp_release_date,
+ outEntry.active_comp_release_date,
+ sizeof(inEntry->active_comp_release_date)));
+ EXPECT_EQ(outEntry.pending_comp_comparison_stamp, timestamp);
+ EXPECT_EQ(inEntry->pending_comp_ver_str_type,
+ outEntry.pending_comp_ver_str_type);
+ EXPECT_EQ(inEntry->pending_comp_ver_str_len,
+ outEntry.pending_comp_ver_str_len);
+ EXPECT_EQ(0, memcmp(inEntry->pending_comp_release_date,
+ outEntry.pending_comp_release_date,
+ sizeof(inEntry->pending_comp_release_date)));
+ EXPECT_EQ(outEntry.comp_activation_methods.value, compActivationMethods);
+ EXPECT_EQ(outEntry.capabilities_during_update.value,
+ capabilitiesDuringUpdate);
+
+ EXPECT_EQ(0, memcmp(outActiveCompVerStr.ptr,
+ entry.data() + activeCompVerStrPos,
+ outActiveCompVerStr.length));
+ EXPECT_EQ(0, memcmp(outPendingCompVerStr.ptr,
+ entry.data() + pendingCompVerStrPos,
+ outPendingCompVerStr.length));
+}