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 | { |
| 15 | pldm_msg_payload request{}; |
| 16 | pldm_msg response{}; |
| 17 | std::array<uint8_t, PLDM_GET_TYPES_RESP_BYTES> responseMsg{}; |
| 18 | response.body.payload = responseMsg.data(); |
| 19 | response.body.payload_length = responseMsg.size(); |
| 20 | getPLDMTypes(&request, &response); |
| 21 | // Only base type supported at the moment |
| 22 | ASSERT_EQ(response.body.payload[0], 0); |
| 23 | ASSERT_EQ(response.body.payload[1], 1); |
| 24 | ASSERT_EQ(response.body.payload[2], 0); |
| 25 | } |
| 26 | |
| 27 | TEST(GetPLDMCommands, testGoodRequest) |
| 28 | { |
| 29 | // Only base type supported at the moment, and commands - |
| 30 | // GetPLDMTypes, GetPLDMCommands |
| 31 | pldm_msg response{}; |
| 32 | std::array<uint8_t, PLDM_GET_COMMANDS_RESP_BYTES> responseMsg{}; |
| 33 | response.body.payload = responseMsg.data(); |
| 34 | response.body.payload_length = responseMsg.size(); |
| 35 | pldm_msg_payload request{}; |
| 36 | std::array<uint8_t, 5> requestPayload{}; |
| 37 | request.payload = requestPayload.data(); |
| 38 | request.payload_length = requestPayload.size(); |
| 39 | getPLDMCommands(&request, &response); |
| 40 | ASSERT_EQ(response.body.payload[0], 0); |
| 41 | ASSERT_EQ(response.body.payload[1], 48); // 48 = 0b110000 |
| 42 | ASSERT_EQ(response.body.payload[2], 0); |
| 43 | } |
| 44 | |
| 45 | TEST(GetPLDMCommands, testBadRequest) |
| 46 | { |
| 47 | pldm_msg response{}; |
| 48 | std::array<uint8_t, PLDM_GET_COMMANDS_RESP_BYTES> responseMsg{}; |
| 49 | response.body.payload = responseMsg.data(); |
| 50 | response.body.payload_length = responseMsg.size(); |
| 51 | pldm_msg_payload request{}; |
| 52 | std::array<uint8_t, 5> requestPayload{}; |
| 53 | |
| 54 | request.payload = requestPayload.data(); |
| 55 | request.payload[0] = 0xFF; |
| 56 | request.payload_length = requestPayload.size(); |
| 57 | getPLDMCommands(&request, &response); |
| 58 | ASSERT_EQ(response.body.payload[0], PLDM_ERROR_INVALID_PLDM_TYPE); |
| 59 | } |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 60 | |
| 61 | TEST(GetPLDMVersion, testGoodRequest) |
| 62 | { |
| 63 | pldm_msg response{}; |
| 64 | std::array<uint8_t, PLDM_GET_VERSION_RESP_BYTES> responseMsg{}; |
| 65 | response.body.payload = responseMsg.data(); |
| 66 | response.body.payload_length = responseMsg.size(); |
| 67 | pldm_msg request{}; |
| 68 | std::array<uint8_t, PLDM_GET_VERSION_REQ_BYTES> requestPayload{}; |
| 69 | request.body.payload = requestPayload.data(); |
| 70 | request.body.payload_length = requestPayload.size(); |
| 71 | |
| 72 | uint8_t pldmType = PLDM_BASE; |
| 73 | uint32_t transferHandle = 0x0; |
| 74 | uint8_t flag = PLDM_GET_FIRSTPART; |
| 75 | uint8_t retFlag = PLDM_START_AND_END; |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 76 | ver32_t version = {0xF1, 0xF0, 0xF0, 0x00}; |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 77 | |
| 78 | auto rc = |
| 79 | encode_get_version_req(0, transferHandle, flag, pldmType, &request); |
| 80 | |
| 81 | ASSERT_EQ(0, rc); |
| 82 | |
| 83 | getPLDMVersion(&(request.body), &response); |
| 84 | |
| 85 | ASSERT_EQ(response.body.payload[0], 0); |
| 86 | ASSERT_EQ(0, |
| 87 | memcmp(response.body.payload + sizeof(response.body.payload[0]), |
| 88 | &transferHandle, sizeof(transferHandle))); |
| 89 | ASSERT_EQ(0, |
| 90 | memcmp(response.body.payload + sizeof(response.body.payload[0]) + |
| 91 | sizeof(transferHandle), |
| 92 | &retFlag, sizeof(flag))); |
| 93 | ASSERT_EQ(0, |
| 94 | memcmp(response.body.payload + sizeof(response.body.payload[0]) + |
| 95 | sizeof(transferHandle) + sizeof(flag), |
| 96 | &version, sizeof(version))); |
| 97 | } |
Sampa Misra | 94d704b | 2019-02-22 03:36:02 -0600 | [diff] [blame] | 98 | |
| 99 | TEST(GetPLDMVersion, testBadRequest) |
| 100 | { |
| 101 | pldm_msg response{}; |
| 102 | std::array<uint8_t, PLDM_GET_VERSION_RESP_BYTES> responseMsg{}; |
| 103 | response.body.payload = responseMsg.data(); |
| 104 | response.body.payload_length = responseMsg.size(); |
| 105 | pldm_msg request{}; |
| 106 | |
| 107 | std::array<uint8_t, PLDM_GET_VERSION_REQ_BYTES> requestPayload{}; |
| 108 | |
| 109 | std::array<uint8_t, (PLDM_GET_VERSION_REQ_BYTES - 3)> requestPayloadSmall{}; |
| 110 | request.body.payload = requestPayloadSmall.data(); |
| 111 | request.body.payload_length = requestPayloadSmall.size(); |
| 112 | |
| 113 | uint8_t pldmType = 7; |
| 114 | uint32_t transferHandle = 0x0; |
| 115 | uint8_t flag = PLDM_GET_FIRSTPART; |
| 116 | |
| 117 | auto rc = |
| 118 | encode_get_version_req(0, transferHandle, flag, pldmType, &request); |
| 119 | |
| 120 | ASSERT_EQ(0, rc); |
| 121 | |
| 122 | getPLDMVersion(&(request.body), &response); |
| 123 | |
| 124 | ASSERT_EQ(response.body.payload[0], PLDM_ERROR_INVALID_LENGTH); |
| 125 | |
| 126 | request.body.payload = requestPayload.data(); |
| 127 | request.body.payload_length = requestPayload.size(); |
| 128 | |
| 129 | rc = encode_get_version_req(0, transferHandle, flag, pldmType, &request); |
| 130 | |
| 131 | ASSERT_EQ(0, rc); |
| 132 | |
| 133 | getPLDMVersion(&(request.body), &response); |
| 134 | |
| 135 | ASSERT_EQ(response.body.payload[0], PLDM_ERROR_INVALID_PLDM_TYPE); |
| 136 | } |