Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 1 | #include <string.h> |
| 2 | |
| 3 | #include <array> |
| 4 | |
| 5 | #include "libpldm/base.h" |
| 6 | #include "libpldm/bios.h" |
| 7 | |
| 8 | #include <gtest/gtest.h> |
| 9 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 10 | constexpr auto hdrSize = sizeof(pldm_msg_hdr); |
| 11 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 12 | TEST(GetDateTime, testEncodeRequest) |
| 13 | { |
| 14 | pldm_msg request{}; |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 15 | |
| 16 | auto rc = encode_get_date_time_req(0, &request); |
| 17 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 18 | } |
| 19 | |
| 20 | TEST(GetDateTime, testEncodeResponse) |
| 21 | { |
| 22 | uint8_t completionCode = 0; |
| 23 | uint8_t seconds = 50; |
| 24 | uint8_t minutes = 20; |
| 25 | uint8_t hours = 5; |
| 26 | uint8_t day = 23; |
| 27 | uint8_t month = 11; |
| 28 | uint16_t year = 2019; |
| 29 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 30 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_DATE_TIME_RESP_BYTES> |
| 31 | responseMsg{}; |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 32 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 33 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 34 | |
| 35 | auto rc = encode_get_date_time_resp(0, PLDM_SUCCESS, seconds, minutes, |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 36 | hours, day, month, year, response); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 37 | |
| 38 | ASSERT_EQ(rc, PLDM_SUCCESS); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 39 | ASSERT_EQ(completionCode, response->payload[0]); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 40 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 41 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]), |
| 42 | &seconds, sizeof(seconds))); |
| 43 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 44 | sizeof(seconds), |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 45 | &minutes, sizeof(minutes))); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 46 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 47 | sizeof(seconds) + sizeof(minutes), |
| 48 | &hours, sizeof(hours))); |
| 49 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 50 | sizeof(seconds) + sizeof(minutes) + sizeof(hours), |
| 51 | &day, sizeof(day))); |
| 52 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 53 | sizeof(seconds) + sizeof(minutes) + sizeof(hours) + |
| 54 | sizeof(day), |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 55 | &month, sizeof(month))); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 56 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 57 | sizeof(seconds) + sizeof(minutes) + sizeof(hours) + |
| 58 | sizeof(day) + sizeof(month), |
| 59 | &year, sizeof(year))); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | TEST(GetDateTime, testDecodeResponse) |
| 63 | { |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 64 | std::array<uint8_t, hdrSize + PLDM_GET_DATE_TIME_RESP_BYTES> responseMsg{}; |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 65 | |
| 66 | uint8_t completionCode = 0; |
| 67 | |
| 68 | uint8_t seconds = 55; |
| 69 | uint8_t minutes = 2; |
| 70 | uint8_t hours = 8; |
| 71 | uint8_t day = 9; |
| 72 | uint8_t month = 7; |
| 73 | uint16_t year = 2020; |
| 74 | |
| 75 | uint8_t retSeconds = 0; |
| 76 | uint8_t retMinutes = 0; |
| 77 | uint8_t retHours = 0; |
| 78 | uint8_t retDay = 0; |
| 79 | uint8_t retMonth = 0; |
| 80 | uint16_t retYear = 0; |
| 81 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 82 | memcpy(responseMsg.data() + sizeof(completionCode) + hdrSize, &seconds, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 83 | sizeof(seconds)); |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 84 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
| 85 | hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 86 | &minutes, sizeof(minutes)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 87 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 88 | sizeof(minutes) + hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 89 | &hours, sizeof(hours)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 90 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 91 | sizeof(minutes) + sizeof(hours) + hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 92 | &day, sizeof(day)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 93 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 94 | sizeof(minutes) + sizeof(hours) + sizeof(day) + hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 95 | &month, sizeof(month)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 96 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 97 | sizeof(minutes) + sizeof(hours) + sizeof(day) + sizeof(month) + |
| 98 | hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 99 | &year, sizeof(year)); |
| 100 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 101 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 102 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 103 | auto rc = decode_get_date_time_resp( |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 104 | response, responseMsg.size() - hdrSize, &completionCode, &retSeconds, |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 105 | &retMinutes, &retHours, &retDay, &retMonth, &retYear); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 106 | |
| 107 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 108 | ASSERT_EQ(seconds, retSeconds); |
| 109 | ASSERT_EQ(minutes, retMinutes); |
| 110 | ASSERT_EQ(hours, retHours); |
| 111 | ASSERT_EQ(day, retDay); |
| 112 | ASSERT_EQ(month, retMonth); |
| 113 | ASSERT_EQ(year, retYear); |
| 114 | } |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 115 | |
| 116 | TEST(GetBIOSTable, testGoodEncodeResponse) |
| 117 | { |
| 118 | std::array<uint8_t, |
| 119 | sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + 4> |
| 120 | responseMsg{}; |
| 121 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 122 | |
| 123 | uint8_t completionCode = PLDM_SUCCESS; |
| 124 | uint32_t nextTransferHandle = 32; |
| 125 | uint8_t transferFlag = PLDM_START_AND_END; |
| 126 | std::array<uint8_t, 4> tableData{1, 2, 3, 4}; |
| 127 | |
| 128 | auto rc = encode_get_bios_table_resp( |
| 129 | 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, tableData.data(), |
| 130 | sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + 4, |
| 131 | response); |
| 132 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 133 | |
| 134 | struct pldm_get_bios_table_resp* resp = |
| 135 | reinterpret_cast<struct pldm_get_bios_table_resp*>(response->payload); |
| 136 | |
| 137 | ASSERT_EQ(completionCode, resp->completion_code); |
| 138 | ASSERT_EQ(nextTransferHandle, resp->next_transfer_handle); |
| 139 | ASSERT_EQ(transferFlag, resp->transfer_flag); |
| 140 | ASSERT_EQ(0, memcmp(tableData.data(), resp->table_data, tableData.size())); |
| 141 | } |
| 142 | |
| 143 | TEST(GetBIOSTable, testBadEncodeResponse) |
| 144 | { |
| 145 | uint32_t nextTransferHandle = 32; |
| 146 | uint8_t transferFlag = PLDM_START_AND_END; |
| 147 | std::array<uint8_t, 4> tableData{1, 2, 3, 4}; |
| 148 | |
| 149 | auto rc = encode_get_bios_table_resp( |
| 150 | 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, tableData.data(), |
| 151 | sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + 4, nullptr); |
| 152 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 153 | } |
| 154 | |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 155 | TEST(GetBIOSTable, testGoodEncodeRequest) |
| 156 | { |
| 157 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_REQ_BYTES> |
| 158 | requestMsg{}; |
| 159 | uint32_t transferHandle = 0x0; |
| 160 | uint8_t transferOpFlag = 0x01; |
| 161 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 162 | |
| 163 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 164 | auto rc = encode_get_bios_table_req(0, transferHandle, transferOpFlag, |
| 165 | tableType, request); |
| 166 | |
| 167 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 168 | |
| 169 | struct pldm_get_bios_table_req* req = |
| 170 | reinterpret_cast<struct pldm_get_bios_table_req*>(request->payload); |
| 171 | ASSERT_EQ(transferHandle, le32toh(req->transfer_handle)); |
| 172 | ASSERT_EQ(transferOpFlag, req->transfer_op_flag); |
| 173 | ASSERT_EQ(tableType, req->table_type); |
| 174 | } |
| 175 | |
| 176 | TEST(GetBIOSTable, testBadEncodeRequest) |
| 177 | { |
| 178 | uint32_t transferHandle = 0x0; |
| 179 | uint8_t transferOpFlag = 0x01; |
| 180 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 181 | |
| 182 | auto rc = encode_get_bios_table_req(0, transferHandle, transferOpFlag, |
| 183 | tableType, nullptr); |
| 184 | |
| 185 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 186 | } |
| 187 | |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 188 | TEST(GetBIOSTable, testGoodDecodeRequest) |
| 189 | { |
| 190 | const auto hdr_size = sizeof(pldm_msg_hdr); |
| 191 | std::array<uint8_t, hdr_size + PLDM_GET_BIOS_TABLE_REQ_BYTES> requestMsg{}; |
| 192 | uint32_t transferHandle = 31; |
| 193 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 194 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 195 | uint32_t retTransferHandle = 0; |
| 196 | uint8_t retTransferOpFlag = 0; |
| 197 | uint8_t retTableType = 0; |
| 198 | |
| 199 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 200 | struct pldm_get_bios_table_req* request = |
| 201 | reinterpret_cast<struct pldm_get_bios_table_req*>(req->payload); |
| 202 | |
| 203 | request->transfer_handle = transferHandle; |
| 204 | request->transfer_op_flag = transferOpFlag; |
| 205 | request->table_type = tableType; |
| 206 | |
| 207 | auto rc = decode_get_bios_table_req(req, requestMsg.size() - hdr_size, |
| 208 | &retTransferHandle, &retTransferOpFlag, |
| 209 | &retTableType); |
| 210 | |
| 211 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 212 | ASSERT_EQ(transferHandle, retTransferHandle); |
| 213 | ASSERT_EQ(transferOpFlag, retTransferOpFlag); |
| 214 | ASSERT_EQ(tableType, retTableType); |
| 215 | } |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 216 | TEST(GetBIOSTable, testBadDecodeRequest) |
| 217 | { |
| 218 | const auto hdr_size = sizeof(pldm_msg_hdr); |
| 219 | std::array<uint8_t, hdr_size + PLDM_GET_BIOS_TABLE_REQ_BYTES> requestMsg{}; |
| 220 | uint32_t transferHandle = 31; |
| 221 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 222 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 223 | uint32_t retTransferHandle = 0; |
| 224 | uint8_t retTransferOpFlag = 0; |
| 225 | uint8_t retTableType = 0; |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 226 | |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 227 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 228 | struct pldm_get_bios_table_req* request = |
| 229 | reinterpret_cast<struct pldm_get_bios_table_req*>(req->payload); |
| 230 | |
| 231 | request->transfer_handle = transferHandle; |
| 232 | request->transfer_op_flag = transferOpFlag; |
| 233 | request->table_type = tableType; |
| 234 | |
| 235 | auto rc = decode_get_bios_table_req(req, requestMsg.size() - hdr_size, |
| 236 | &retTransferHandle, &retTransferOpFlag, |
| 237 | &retTableType); |
| 238 | |
| 239 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 240 | ASSERT_EQ(transferHandle, retTransferHandle); |
| 241 | ASSERT_EQ(transferOpFlag, retTransferOpFlag); |
| 242 | ASSERT_EQ(tableType, retTableType); |
| 243 | } |
| 244 | /* |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 245 | TEST(GetBIOSTable, testBadDecodeRequest) |
| 246 | { |
| 247 | const auto hdr_size = sizeof(pldm_msg_hdr); |
| 248 | std::array<uint8_t, hdr_size + PLDM_GET_BIOS_TABLE_REQ_BYTES> requestMsg{}; |
| 249 | uint32_t transferHandle = 31; |
| 250 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 251 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 252 | uint32_t retTransferHandle = 0; |
| 253 | uint8_t retTransferOpFlag = 0; |
| 254 | uint8_t retTableType = 0; |
| 255 | |
| 256 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 257 | struct pldm_get_bios_table_req* request = |
| 258 | reinterpret_cast<struct pldm_get_bios_table_req*>(req->payload); |
| 259 | |
| 260 | request->transfer_handle = transferHandle; |
| 261 | request->transfer_op_flag = transferOpFlag; |
| 262 | request->table_type = tableType; |
| 263 | |
| 264 | auto rc = decode_get_bios_table_req(req, requestMsg.size() - hdr_size - 3, |
| 265 | &retTransferHandle, &retTransferOpFlag, |
| 266 | &retTableType); |
| 267 | |
| 268 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 269 | }*/ |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 270 | |
| 271 | TEST(GetBIOSAttributeCurrentValueByHandle, testGoodDecodeRequest) |
| 272 | { |
| 273 | uint32_t transferHandle = 45; |
| 274 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 275 | uint16_t attributehandle = 10; |
| 276 | uint32_t retTransferHandle = 0; |
| 277 | uint8_t retTransferOpFlag = 0; |
| 278 | uint16_t retattributehandle = 0; |
| 279 | std::array<uint8_t, hdrSize + sizeof(transferHandle) + |
| 280 | sizeof(transferOpFlag) + sizeof(attributehandle)> |
| 281 | requestMsg{}; |
| 282 | |
| 283 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 284 | struct pldm_get_bios_attribute_current_value_by_handle_req* request = |
| 285 | reinterpret_cast< |
| 286 | struct pldm_get_bios_attribute_current_value_by_handle_req*>( |
| 287 | req->payload); |
| 288 | |
| 289 | request->transfer_handle = transferHandle; |
| 290 | request->transfer_op_flag = transferOpFlag; |
| 291 | request->attribute_handle = attributehandle; |
| 292 | |
| 293 | auto rc = decode_get_bios_attribute_current_value_by_handle_req( |
| 294 | req, requestMsg.size() - hdrSize, &retTransferHandle, |
| 295 | &retTransferOpFlag, &retattributehandle); |
| 296 | |
| 297 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 298 | ASSERT_EQ(transferHandle, retTransferHandle); |
| 299 | ASSERT_EQ(transferOpFlag, retTransferOpFlag); |
| 300 | ASSERT_EQ(attributehandle, retattributehandle); |
| 301 | } |
| 302 | |
| 303 | TEST(GetBIOSAttributeCurrentValueByHandle, testBadDecodeRequest) |
| 304 | { |
| 305 | |
| 306 | uint32_t transferHandle = 0; |
| 307 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 308 | uint16_t attribute_handle = 0; |
| 309 | uint32_t retTransferHandle = 0; |
| 310 | uint8_t retTransferOpFlag = 0; |
| 311 | uint16_t retattribute_handle = 0; |
| 312 | std::array<uint8_t, hdrSize + sizeof(transferHandle) + |
| 313 | sizeof(transferOpFlag) + sizeof(attribute_handle)> |
| 314 | requestMsg{}; |
| 315 | |
| 316 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 317 | struct pldm_get_bios_attribute_current_value_by_handle_req* request = |
| 318 | reinterpret_cast< |
| 319 | struct pldm_get_bios_attribute_current_value_by_handle_req*>( |
| 320 | req->payload); |
| 321 | |
| 322 | request->transfer_handle = transferHandle; |
| 323 | request->transfer_op_flag = transferOpFlag; |
| 324 | request->attribute_handle = attribute_handle; |
| 325 | |
| 326 | auto rc = decode_get_bios_attribute_current_value_by_handle_req( |
| 327 | NULL, requestMsg.size() - hdrSize, &retTransferHandle, |
| 328 | &retTransferOpFlag, &retattribute_handle); |
| 329 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 330 | |
| 331 | transferHandle = 31; |
| 332 | request->transfer_handle = transferHandle; |
| 333 | |
| 334 | rc = decode_get_bios_attribute_current_value_by_handle_req( |
| 335 | req, 0, &retTransferHandle, &retTransferOpFlag, &retattribute_handle); |
| 336 | |
| 337 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 338 | } |
| 339 | |
| 340 | TEST(GetBIOSAttributeCurrentValueByHandle, testGoodEncodeResponse) |
| 341 | { |
| 342 | |
| 343 | uint8_t instanceId = 10; |
| 344 | uint8_t completionCode = PLDM_SUCCESS; |
| 345 | uint32_t nextTransferHandle = 32; |
| 346 | uint8_t transferFlag = PLDM_START_AND_END; |
| 347 | uint8_t attributeData = 44; |
| 348 | std::array<uint8_t, |
| 349 | hdrSize + |
| 350 | sizeof(pldm_get_bios_attribute_current_value_by_handle_resp)> |
| 351 | responseMsg{}; |
| 352 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 353 | |
| 354 | auto rc = encode_get_bios_current_value_by_handle_resp( |
| 355 | instanceId, completionCode, nextTransferHandle, transferFlag, |
| 356 | &attributeData, sizeof(attributeData), response); |
| 357 | |
| 358 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 359 | |
| 360 | struct pldm_get_bios_attribute_current_value_by_handle_resp* resp = |
| 361 | reinterpret_cast< |
| 362 | struct pldm_get_bios_attribute_current_value_by_handle_resp*>( |
| 363 | response->payload); |
| 364 | |
| 365 | ASSERT_EQ(completionCode, resp->completion_code); |
| 366 | ASSERT_EQ(nextTransferHandle, resp->next_transfer_handle); |
| 367 | ASSERT_EQ(transferFlag, resp->transfer_flag); |
| 368 | ASSERT_EQ( |
| 369 | 0, memcmp(&attributeData, resp->attribute_data, sizeof(attributeData))); |
| 370 | } |
| 371 | |
| 372 | TEST(GetBIOSAttributeCurrentValueByHandle, testBadEncodeResponse) |
| 373 | { |
| 374 | uint32_t nextTransferHandle = 32; |
| 375 | uint8_t transferFlag = PLDM_START_AND_END; |
| 376 | uint8_t attributeData = 44; |
| 377 | |
| 378 | auto rc = encode_get_bios_current_value_by_handle_resp( |
| 379 | 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, &attributeData, |
| 380 | sizeof(attributeData), nullptr); |
| 381 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 382 | |
| 383 | std::array<uint8_t, |
| 384 | hdrSize + |
| 385 | sizeof(pldm_get_bios_attribute_current_value_by_handle_resp)> |
| 386 | responseMsg{}; |
| 387 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 388 | rc = encode_get_bios_current_value_by_handle_resp( |
| 389 | 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, nullptr, |
| 390 | sizeof(attributeData), response); |
| 391 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 392 | } |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 393 | |
| 394 | TEST(SetBiosAttributeCurrentValue, testGoodEncodeRequest) |
| 395 | { |
| 396 | uint8_t instanceId = 10; |
| 397 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 398 | uint8_t transferFlag = PLDM_START_AND_END; |
| 399 | uint32_t attributeData = 44; |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 400 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + |
| 401 | sizeof(attributeData)> |
| 402 | requestMsg{}; |
| 403 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 404 | auto rc = encode_set_bios_attribute_current_value_req( |
| 405 | instanceId, transferHandle, transferFlag, |
| 406 | reinterpret_cast<uint8_t*>(&attributeData), sizeof(attributeData), |
| 407 | request, requestMsg.size() - hdrSize); |
| 408 | |
| 409 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 410 | |
| 411 | struct pldm_set_bios_attribute_current_value_req* req = |
| 412 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_req*>( |
| 413 | request->payload); |
| 414 | ASSERT_EQ(htole32(transferHandle), req->transfer_handle); |
| 415 | ASSERT_EQ(transferFlag, req->transfer_flag); |
| 416 | ASSERT_EQ( |
| 417 | 0, memcmp(&attributeData, req->attribute_data, sizeof(attributeData))); |
| 418 | } |
| 419 | |
| 420 | TEST(SetBiosAttributeCurrentValue, testBadEncodeRequest) |
| 421 | { |
| 422 | uint8_t instanceId = 10; |
| 423 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 424 | uint8_t transferFlag = PLDM_START_AND_END; |
| 425 | uint32_t attributeData = 44; |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 426 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES> |
| 427 | requestMsg{}; |
| 428 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 429 | |
| 430 | auto rc = encode_set_bios_attribute_current_value_req( |
| 431 | instanceId, transferHandle, transferFlag, nullptr, 0, nullptr, 0); |
| 432 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 433 | rc = encode_set_bios_attribute_current_value_req( |
| 434 | instanceId, transferHandle, transferFlag, |
| 435 | reinterpret_cast<uint8_t*>(&attributeData), sizeof(attributeData), |
| 436 | request, requestMsg.size() - hdrSize); |
| 437 | |
| 438 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 439 | } |
| 440 | |
| 441 | TEST(SetBiosAttributeCurrentValue, testGoodDecodeRequest) |
| 442 | { |
| 443 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 444 | uint8_t transferFlag = PLDM_START_AND_END; |
| 445 | uint32_t attributeData = 44; |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 446 | |
| 447 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + |
| 448 | sizeof(attributeData)> |
| 449 | requestMsg{}; |
| 450 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 451 | struct pldm_set_bios_attribute_current_value_req* req = |
| 452 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_req*>( |
| 453 | request->payload); |
| 454 | req->transfer_handle = htole32(transferHandle); |
| 455 | req->transfer_flag = transferFlag; |
| 456 | memcpy(req->attribute_data, &attributeData, sizeof(attributeData)); |
| 457 | |
| 458 | uint32_t retTransferHandle; |
| 459 | uint8_t retTransferFlag; |
| 460 | uint32_t retAttributeData; |
| 461 | size_t retAttributeDataLength; |
| 462 | auto rc = decode_set_bios_attribute_current_value_req( |
| 463 | request, requestMsg.size() - hdrSize, &retTransferHandle, |
| 464 | &retTransferFlag, reinterpret_cast<uint8_t*>(&retAttributeData), |
| 465 | &retAttributeDataLength); |
| 466 | |
| 467 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 468 | ASSERT_EQ(retTransferHandle, transferHandle); |
| 469 | ASSERT_EQ(retTransferFlag, transferFlag); |
| 470 | ASSERT_EQ(retAttributeDataLength, sizeof(attributeData)); |
| 471 | ASSERT_EQ(0, |
| 472 | memcmp(&retAttributeData, &attributeData, sizeof(attributeData))); |
| 473 | } |
| 474 | |
| 475 | TEST(SetBiosAttributeCurrentValue, testBadDecodeRequest) |
| 476 | { |
| 477 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 478 | uint8_t transferFlag = PLDM_START_AND_END; |
| 479 | uint32_t attributeData = 44; |
| 480 | size_t attributeDataLength = sizeof(attributeData); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 481 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES - 1> |
| 482 | requestMsg{}; |
| 483 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 484 | |
| 485 | auto rc = decode_set_bios_attribute_current_value_req( |
| 486 | nullptr, 0, &transferHandle, &transferFlag, |
| 487 | reinterpret_cast<uint8_t*>(&attributeData), &attributeDataLength); |
| 488 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 489 | rc = decode_set_bios_attribute_current_value_req( |
| 490 | request, requestMsg.size() - hdrSize, &transferHandle, &transferFlag, |
| 491 | reinterpret_cast<uint8_t*>(&attributeData), &attributeDataLength); |
| 492 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 493 | } |
| 494 | |
| 495 | TEST(SetBiosAttributeCurrentValue, testGoodEncodeResponse) |
| 496 | { |
| 497 | uint8_t instanceId = 10; |
| 498 | uint32_t nextTransferHandle = 32; |
| 499 | uint8_t completionCode = PLDM_SUCCESS; |
| 500 | |
| 501 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES> |
| 502 | responseMsg{}; |
| 503 | struct pldm_msg* response = |
| 504 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 505 | auto rc = encode_set_bios_attribute_current_value_resp( |
| 506 | instanceId, completionCode, nextTransferHandle, response); |
| 507 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 508 | |
| 509 | struct pldm_set_bios_attribute_current_value_resp* resp = |
| 510 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>( |
| 511 | response->payload); |
| 512 | ASSERT_EQ(completionCode, resp->completion_code); |
| 513 | ASSERT_EQ(htole32(nextTransferHandle), resp->next_transfer_handle); |
| 514 | } |
| 515 | |
| 516 | TEST(SetBiosAttributeCurrentValue, testBadEncodeResponse) |
| 517 | { |
| 518 | uint8_t instanceId = 10; |
| 519 | uint32_t nextTransferHandle = 32; |
| 520 | uint8_t completionCode = PLDM_SUCCESS; |
| 521 | auto rc = encode_set_bios_attribute_current_value_resp( |
| 522 | instanceId, completionCode, nextTransferHandle, nullptr); |
| 523 | |
| 524 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 525 | } |
| 526 | TEST(SetBiosAttributeCurrentValue, testGoodDecodeResponse) |
| 527 | { |
| 528 | uint32_t nextTransferHandle = 32; |
| 529 | uint8_t completionCode = PLDM_SUCCESS; |
| 530 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES> |
| 531 | responseMsg{}; |
| 532 | struct pldm_msg* response = |
| 533 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 534 | struct pldm_set_bios_attribute_current_value_resp* resp = |
| 535 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>( |
| 536 | response->payload); |
| 537 | |
| 538 | resp->completion_code = completionCode; |
| 539 | resp->next_transfer_handle = htole32(nextTransferHandle); |
| 540 | |
| 541 | uint8_t retCompletionCode; |
| 542 | uint32_t retNextTransferHandle; |
| 543 | auto rc = decode_set_bios_attribute_current_value_resp( |
| 544 | response, responseMsg.size() - hdrSize, &retCompletionCode, |
| 545 | &retNextTransferHandle); |
| 546 | |
| 547 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 548 | ASSERT_EQ(completionCode, retCompletionCode); |
| 549 | ASSERT_EQ(nextTransferHandle, retNextTransferHandle); |
| 550 | } |
| 551 | |
| 552 | TEST(SetBiosAttributeCurrentValue, testBadDecodeResponse) |
| 553 | { |
| 554 | uint32_t nextTransferHandle = 32; |
| 555 | uint8_t completionCode = PLDM_SUCCESS; |
| 556 | |
| 557 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES - 1> |
| 558 | responseMsg{}; |
| 559 | struct pldm_msg* response = |
| 560 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 561 | auto rc = decode_set_bios_attribute_current_value_resp( |
| 562 | nullptr, 0, &completionCode, &nextTransferHandle); |
| 563 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 564 | |
| 565 | rc = decode_set_bios_attribute_current_value_resp( |
| 566 | response, responseMsg.size() - hdrSize, &completionCode, |
| 567 | &nextTransferHandle); |
| 568 | |
| 569 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 570 | } |