Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 1 | #include "libpldmresponder/base.hpp" |
| 2 | |
| 3 | #include <string.h> |
| 4 | |
| 5 | #include <array> |
| 6 | |
| 7 | #include "libpldm/base.h" |
| 8 | |
| 9 | #include <gtest/gtest.h> |
| 10 | |
| 11 | using namespace pldm::responder; |
| 12 | |
| 13 | TEST(GetPLDMTypes, testGoodRequest) |
| 14 | { |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 15 | std::array<uint8_t, sizeof(pldm_msg_hdr)> requestPayload{}; |
| 16 | auto request = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
| 17 | // payload length will be 0 in this case |
| 18 | size_t requestPayloadLength = 0; |
| 19 | auto response = getPLDMTypes(request, requestPayloadLength); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 20 | // Only base type supported at the moment |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 21 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 22 | uint8_t* payload_ptr = responsePtr->payload; |
| 23 | ASSERT_EQ(payload_ptr[0], 0); |
Zahed Hossain | 5e4e383 | 2019-07-05 03:43:18 -0500 | [diff] [blame] | 24 | ASSERT_EQ(payload_ptr[1], 13); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 25 | ASSERT_EQ(payload_ptr[2], 0); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | TEST(GetPLDMCommands, testGoodRequest) |
| 29 | { |
| 30 | // Only base type supported at the moment, and commands - |
| 31 | // GetPLDMTypes, GetPLDMCommands |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 32 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_COMMANDS_REQ_BYTES> |
| 33 | requestPayload{}; |
| 34 | auto request = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
| 35 | size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
| 36 | auto response = getPLDMCommands(request, requestPayloadLength); |
| 37 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 38 | uint8_t* payload_ptr = responsePtr->payload; |
| 39 | ASSERT_EQ(payload_ptr[0], 0); |
John Wang | 5c4f80d | 2019-07-29 11:12:18 +0800 | [diff] [blame] | 40 | ASSERT_EQ(payload_ptr[1], 60); // 60 = 0b111100 |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 41 | ASSERT_EQ(payload_ptr[2], 0); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | TEST(GetPLDMCommands, testBadRequest) |
| 45 | { |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 46 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_COMMANDS_REQ_BYTES> |
| 47 | requestPayload{}; |
| 48 | auto request = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 49 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 50 | request->payload[0] = 0xFF; |
| 51 | size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
| 52 | auto response = getPLDMCommands(request, requestPayloadLength); |
| 53 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 54 | uint8_t* payload_ptr = responsePtr->payload; |
| 55 | ASSERT_EQ(payload_ptr[0], PLDM_ERROR_INVALID_PLDM_TYPE); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 56 | } |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 57 | TEST(GetPLDMVersion, testGoodRequest) |
| 58 | { |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 59 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_VERSION_REQ_BYTES> |
| 60 | requestPayload{}; |
| 61 | auto request = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
| 62 | size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 63 | |
| 64 | uint8_t pldmType = PLDM_BASE; |
| 65 | uint32_t transferHandle = 0x0; |
| 66 | uint8_t flag = PLDM_GET_FIRSTPART; |
| 67 | uint8_t retFlag = PLDM_START_AND_END; |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 68 | ver32_t version = {0xF1, 0xF0, 0xF0, 0x00}; |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 69 | |
| 70 | auto rc = |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 71 | encode_get_version_req(0, transferHandle, flag, pldmType, request); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 72 | |
| 73 | ASSERT_EQ(0, rc); |
| 74 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 75 | auto response = getPLDMVersion(request, requestPayloadLength); |
| 76 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 77 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 78 | ASSERT_EQ(responsePtr->payload[0], 0); |
| 79 | ASSERT_EQ(0, memcmp(responsePtr->payload + sizeof(responsePtr->payload[0]), |
| 80 | &transferHandle, sizeof(transferHandle))); |
| 81 | ASSERT_EQ(0, memcmp(responsePtr->payload + sizeof(responsePtr->payload[0]) + |
| 82 | sizeof(transferHandle), |
| 83 | &retFlag, sizeof(flag))); |
| 84 | ASSERT_EQ(0, memcmp(responsePtr->payload + sizeof(responsePtr->payload[0]) + |
| 85 | sizeof(transferHandle) + sizeof(flag), |
| 86 | &version, sizeof(version))); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 87 | } |
Sampa Misra | 94d704b | 2019-02-22 03:36:02 -0600 | [diff] [blame] | 88 | TEST(GetPLDMVersion, testBadRequest) |
| 89 | { |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 90 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_VERSION_REQ_BYTES> |
| 91 | requestPayload{}; |
| 92 | auto request = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
| 93 | size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
Sampa Misra | 94d704b | 2019-02-22 03:36:02 -0600 | [diff] [blame] | 94 | |
| 95 | uint8_t pldmType = 7; |
| 96 | uint32_t transferHandle = 0x0; |
| 97 | uint8_t flag = PLDM_GET_FIRSTPART; |
| 98 | |
| 99 | auto rc = |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 100 | encode_get_version_req(0, transferHandle, flag, pldmType, request); |
Sampa Misra | 94d704b | 2019-02-22 03:36:02 -0600 | [diff] [blame] | 101 | |
| 102 | ASSERT_EQ(0, rc); |
| 103 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 104 | auto response = getPLDMVersion(request, requestPayloadLength - 1); |
| 105 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
Sampa Misra | 94d704b | 2019-02-22 03:36:02 -0600 | [diff] [blame] | 106 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 107 | ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR_INVALID_LENGTH); |
Sampa Misra | 94d704b | 2019-02-22 03:36:02 -0600 | [diff] [blame] | 108 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 109 | request = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
| 110 | requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
Sampa Misra | 94d704b | 2019-02-22 03:36:02 -0600 | [diff] [blame] | 111 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 112 | rc = encode_get_version_req(0, transferHandle, flag, pldmType, request); |
Sampa Misra | 94d704b | 2019-02-22 03:36:02 -0600 | [diff] [blame] | 113 | |
| 114 | ASSERT_EQ(0, rc); |
| 115 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 116 | response = getPLDMVersion(request, requestPayloadLength); |
| 117 | responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
Sampa Misra | 94d704b | 2019-02-22 03:36:02 -0600 | [diff] [blame] | 118 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 119 | ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR_INVALID_PLDM_TYPE); |
Sampa Misra | 94d704b | 2019-02-22 03:36:02 -0600 | [diff] [blame] | 120 | } |
John Wang | 5c4f80d | 2019-07-29 11:12:18 +0800 | [diff] [blame] | 121 | |
| 122 | TEST(GetTID, testGoodRequest) |
| 123 | { |
| 124 | std::array<uint8_t, sizeof(pldm_msg_hdr)> requestPayload{}; |
| 125 | auto request = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
| 126 | size_t requestPayloadLength = 0; |
| 127 | |
| 128 | auto response = getTID(request, requestPayloadLength); |
| 129 | |
| 130 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 131 | uint8_t* payload = responsePtr->payload; |
| 132 | |
| 133 | ASSERT_EQ(payload[0], 0); |
| 134 | ASSERT_EQ(payload[1], 1); |
| 135 | } |