libpldm: Add encode API for CancelUpdate request
Update agent send this command to FD/FDP to exit from update mode
even if activation is required to begin operating at the new firmware
level. FD/FDP will transition to IDLE state on CancelUpdate. This
implementation works with DSP0267_1.1.0, DSP0267_1.0.1 and
DSP0267_1.0.0.
Tested: Unit tests passed
Signed-off-by: gokulsanker <gokul.sanker.v.g@intel.com>
Change-Id: Iab9c2f078c216c20c2432ac5ec0438fdae8da27d
diff --git a/libpldm/tests/libpldm_firmware_update_test.cpp b/libpldm/tests/libpldm_firmware_update_test.cpp
index 1e6bdb5..9ef53f7 100644
--- a/libpldm/tests/libpldm_firmware_update_test.cpp
+++ b/libpldm/tests/libpldm_firmware_update_test.cpp
@@ -2788,4 +2788,32 @@
responseMsg, cancelUpdateComponentResponse.size() - hdrSize,
&completionCode);
EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
\ No newline at end of file
+}
+
+TEST(CancelUpdate, goodPathEncodeRequest)
+{
+ constexpr uint8_t instanceId = 10;
+ std::array<uint8_t, hdrSize> request{};
+ auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
+
+ auto rc = encode_cancel_update_req(instanceId, requestMsg,
+ PLDM_CANCEL_UPDATE_REQ_BYTES);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+
+ constexpr std::array<uint8_t, hdrSize> outRequest{0x8A, 0x05, 0x1D};
+ EXPECT_EQ(request, outRequest);
+}
+
+TEST(CancelUpdate, errorPathEncodeRequest)
+{
+ std::array<uint8_t, hdrSize + sizeof(uint8_t)> request{};
+ auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
+
+ auto rc =
+ encode_cancel_update_req(0, nullptr, PLDM_CANCEL_UPDATE_REQ_BYTES);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_cancel_update_req(0, requestMsg,
+ PLDM_CANCEL_UPDATE_REQ_BYTES + 1);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}