GetPLDMVersion: add test cases
This commit adds additional bad path tests for the command
GetPLDMVersion.
Change-Id: I0c88bfbb2f40829cc84f4e29ce632dc1e5e53aec
Signed-off-by: Sampa Misra <sampmisr@in.ibm.com>
diff --git a/test/libpldm_base_test.cpp b/test/libpldm_base_test.cpp
index d6bdc47..f906f77 100644
--- a/test/libpldm_base_test.cpp
+++ b/test/libpldm_base_test.cpp
@@ -307,7 +307,7 @@
ASSERT_EQ(response.payload[3], outTypes[2].byte);
}
-TEST(GetPLDMVersion, testEncodeRequest)
+TEST(GetPLDMVersion, testGoodEncodeRequest)
{
std::array<uint8_t, PLDM_GET_VERSION_REQ_BYTES> requestMsg{};
pldm_msg request{};
@@ -329,6 +329,18 @@
&pldmType, sizeof(pldmType)));
}
+TEST(GetPLDMVersion, testBadEncodeRequest)
+{
+ uint8_t pldmType = 0x03;
+ uint32_t transferHandle = 0x0;
+ uint8_t opFlag = 0x01;
+
+ auto rc =
+ encode_get_version_req(0, transferHandle, opFlag, pldmType, nullptr);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
TEST(GetPLDMVersion, testEncodeResponse)
{
pldm_msg response{};
diff --git a/test/libpldmresponder_base_test.cpp b/test/libpldmresponder_base_test.cpp
index b9ef717..cdd22e6 100644
--- a/test/libpldmresponder_base_test.cpp
+++ b/test/libpldmresponder_base_test.cpp
@@ -95,3 +95,42 @@
sizeof(transferHandle) + sizeof(flag),
&version, sizeof(version)));
}
+
+TEST(GetPLDMVersion, testBadRequest)
+{
+ pldm_msg response{};
+ std::array<uint8_t, PLDM_GET_VERSION_RESP_BYTES> responseMsg{};
+ response.body.payload = responseMsg.data();
+ response.body.payload_length = responseMsg.size();
+ pldm_msg request{};
+
+ std::array<uint8_t, PLDM_GET_VERSION_REQ_BYTES> requestPayload{};
+
+ std::array<uint8_t, (PLDM_GET_VERSION_REQ_BYTES - 3)> requestPayloadSmall{};
+ request.body.payload = requestPayloadSmall.data();
+ request.body.payload_length = requestPayloadSmall.size();
+
+ uint8_t pldmType = 7;
+ uint32_t transferHandle = 0x0;
+ uint8_t flag = PLDM_GET_FIRSTPART;
+
+ auto rc =
+ encode_get_version_req(0, transferHandle, flag, pldmType, &request);
+
+ ASSERT_EQ(0, rc);
+
+ getPLDMVersion(&(request.body), &response);
+
+ ASSERT_EQ(response.body.payload[0], PLDM_ERROR_INVALID_LENGTH);
+
+ request.body.payload = requestPayload.data();
+ request.body.payload_length = requestPayload.size();
+
+ rc = encode_get_version_req(0, transferHandle, flag, pldmType, &request);
+
+ ASSERT_EQ(0, rc);
+
+ getPLDMVersion(&(request.body), &response);
+
+ ASSERT_EQ(response.body.payload[0], PLDM_ERROR_INVALID_PLDM_TYPE);
+}