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