Implement discovery commands
This commit does the following
- Implements the GetPLDMTypes and GetPLDMCommands commands. These are
commands that need to be handled by a PLDM device as part of the
initial PLDM discovery.
- Sets up the build infrastructure: separate libraries for PLDM
encode/decode libs and the PLDM responder.
Change-Id: I65fa222d2a681c473f579c8e30d84faaf94fe754
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/test/libpldmresponder_base_test.cpp b/test/libpldmresponder_base_test.cpp
new file mode 100644
index 0000000..2bd6ebd
--- /dev/null
+++ b/test/libpldmresponder_base_test.cpp
@@ -0,0 +1,59 @@
+#include "libpldmresponder/base.hpp"
+
+#include <string.h>
+
+#include <array>
+
+#include "libpldm/base.h"
+
+#include <gtest/gtest.h>
+
+using namespace pldm::responder;
+
+TEST(GetPLDMTypes, testGoodRequest)
+{
+ pldm_msg_payload request{};
+ pldm_msg response{};
+ std::array<uint8_t, PLDM_GET_TYPES_RESP_BYTES> responseMsg{};
+ response.body.payload = responseMsg.data();
+ response.body.payload_length = responseMsg.size();
+ getPLDMTypes(&request, &response);
+ // Only base type supported at the moment
+ ASSERT_EQ(response.body.payload[0], 0);
+ ASSERT_EQ(response.body.payload[1], 1);
+ ASSERT_EQ(response.body.payload[2], 0);
+}
+
+TEST(GetPLDMCommands, testGoodRequest)
+{
+ // Only base type supported at the moment, and commands -
+ // GetPLDMTypes, GetPLDMCommands
+ pldm_msg response{};
+ std::array<uint8_t, PLDM_GET_COMMANDS_RESP_BYTES> responseMsg{};
+ response.body.payload = responseMsg.data();
+ response.body.payload_length = responseMsg.size();
+ pldm_msg_payload request{};
+ std::array<uint8_t, 5> requestPayload{};
+ request.payload = requestPayload.data();
+ request.payload_length = requestPayload.size();
+ getPLDMCommands(&request, &response);
+ ASSERT_EQ(response.body.payload[0], 0);
+ ASSERT_EQ(response.body.payload[1], 48); // 48 = 0b110000
+ ASSERT_EQ(response.body.payload[2], 0);
+}
+
+TEST(GetPLDMCommands, testBadRequest)
+{
+ pldm_msg response{};
+ std::array<uint8_t, PLDM_GET_COMMANDS_RESP_BYTES> responseMsg{};
+ response.body.payload = responseMsg.data();
+ response.body.payload_length = responseMsg.size();
+ pldm_msg_payload request{};
+ std::array<uint8_t, 5> requestPayload{};
+
+ request.payload = requestPayload.data();
+ request.payload[0] = 0xFF;
+ request.payload_length = requestPayload.size();
+ getPLDMCommands(&request, &response);
+ ASSERT_EQ(response.body.payload[0], PLDM_ERROR_INVALID_PLDM_TYPE);
+}