PLDM: Implement encode response & decode request api for SetEventReceiver.
This commit implements the responder flow for SetEventReceiver.
PLDM SPEC: DSP248_1.2.0 TABLE 13
Signed-off-by: Sridevi Ramesh <sridevra@in.ibm.com>
Change-Id: I2e9fe2797ef2adb1f24f2a80bd19e7255ac80ce9
diff --git a/libpldm/tests/libpldm_platform_test.cpp b/libpldm/tests/libpldm_platform_test.cpp
index 11d6777..cab6a07 100644
--- a/libpldm/tests/libpldm_platform_test.cpp
+++ b/libpldm/tests/libpldm_platform_test.cpp
@@ -1942,3 +1942,95 @@
EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
}
+
+TEST(SetEventReceiver, testGoodEncodeResponse)
+{
+ std::array<uint8_t,
+ sizeof(pldm_msg_hdr) + PLDM_SET_EVENT_RECEIVER_RESP_BYTES>
+ responseMsg{};
+ auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+ uint8_t completionCode = 0;
+
+ auto rc = encode_set_event_receiver_resp(0, PLDM_SUCCESS, response);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(completionCode, response->payload[0]);
+}
+
+TEST(SetEventReceiver, testBadEncodeResponse)
+{
+ auto rc = encode_set_event_receiver_resp(0, PLDM_SUCCESS, NULL);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(SetEventReceiver, testGoodDecodeRequest)
+{
+
+ std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_REQ_BYTES>
+ requestMsg{};
+
+ uint8_t eventMessageGlobalEnable =
+ PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
+ uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
+ uint8_t eventReceiverAddressInfo = 0x08;
+ uint16_t heartbeatTimer = 0x78;
+
+ auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ struct pldm_set_event_receiver_req* req =
+ reinterpret_cast<struct pldm_set_event_receiver_req*>(request->payload);
+
+ req->event_message_global_enable = eventMessageGlobalEnable;
+ req->transport_protocol_type = transportProtocolType;
+ req->event_receiver_address_info = eventReceiverAddressInfo;
+ req->heartbeat_timer = htole16(heartbeatTimer);
+
+ uint8_t reteventMessageGlobalEnable;
+ uint8_t rettransportProtocolType;
+ uint8_t reteventReceiverAddressInfo;
+ uint16_t retheartbeatTimer;
+ auto rc = decode_set_event_receiver_req(
+ request, requestMsg.size() - hdrSize, &reteventMessageGlobalEnable,
+ &rettransportProtocolType, &reteventReceiverAddressInfo,
+ &retheartbeatTimer);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(eventMessageGlobalEnable, reteventMessageGlobalEnable);
+ EXPECT_EQ(transportProtocolType, rettransportProtocolType);
+ EXPECT_EQ(eventReceiverAddressInfo, reteventReceiverAddressInfo);
+ EXPECT_EQ(heartbeatTimer, retheartbeatTimer);
+}
+
+TEST(SetEventReceiver, testBadDecodeRequest)
+{
+ std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_REQ_BYTES>
+ requestMsg{};
+
+ auto rc = decode_set_event_receiver_req(NULL, requestMsg.size() - hdrSize,
+ NULL, NULL, NULL, NULL);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ uint8_t eventMessageGlobalEnable =
+ PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
+ uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
+ uint8_t eventReceiverAddressInfo = 0x08;
+ uint16_t heartbeatTimer = 0x78;
+
+ auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ struct pldm_set_event_receiver_req* req =
+ reinterpret_cast<struct pldm_set_event_receiver_req*>(request->payload);
+
+ req->event_message_global_enable = eventMessageGlobalEnable;
+ req->transport_protocol_type = transportProtocolType;
+ req->event_receiver_address_info = eventReceiverAddressInfo;
+ req->heartbeat_timer = htole16(heartbeatTimer);
+
+ uint8_t reteventMessageGlobalEnable;
+ uint8_t rettransportProtocolType;
+ uint8_t reteventReceiverAddressInfo;
+ uint16_t retheartbeatTimer;
+ rc = decode_set_event_receiver_req(
+ request, requestMsg.size() - hdrSize - 1, &reteventMessageGlobalEnable,
+ &rettransportProtocolType, &reteventReceiverAddressInfo,
+ &retheartbeatTimer);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}