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 | |
| 155 | TEST(GetBIOSTable, testGoodDecodeRequest) |
| 156 | { |
| 157 | const auto hdr_size = sizeof(pldm_msg_hdr); |
| 158 | std::array<uint8_t, hdr_size + PLDM_GET_BIOS_TABLE_REQ_BYTES> requestMsg{}; |
| 159 | uint32_t transferHandle = 31; |
| 160 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 161 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 162 | uint32_t retTransferHandle = 0; |
| 163 | uint8_t retTransferOpFlag = 0; |
| 164 | uint8_t retTableType = 0; |
| 165 | |
| 166 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 167 | struct pldm_get_bios_table_req* request = |
| 168 | reinterpret_cast<struct pldm_get_bios_table_req*>(req->payload); |
| 169 | |
| 170 | request->transfer_handle = transferHandle; |
| 171 | request->transfer_op_flag = transferOpFlag; |
| 172 | request->table_type = tableType; |
| 173 | |
| 174 | auto rc = decode_get_bios_table_req(req, requestMsg.size() - hdr_size, |
| 175 | &retTransferHandle, &retTransferOpFlag, |
| 176 | &retTableType); |
| 177 | |
| 178 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 179 | ASSERT_EQ(transferHandle, retTransferHandle); |
| 180 | ASSERT_EQ(transferOpFlag, retTransferOpFlag); |
| 181 | ASSERT_EQ(tableType, retTableType); |
| 182 | } |
| 183 | |
| 184 | TEST(GetBIOSTable, testBadDecodeRequest) |
| 185 | { |
| 186 | const auto hdr_size = sizeof(pldm_msg_hdr); |
| 187 | std::array<uint8_t, hdr_size + PLDM_GET_BIOS_TABLE_REQ_BYTES> requestMsg{}; |
| 188 | uint32_t transferHandle = 31; |
| 189 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 190 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 191 | uint32_t retTransferHandle = 0; |
| 192 | uint8_t retTransferOpFlag = 0; |
| 193 | uint8_t retTableType = 0; |
| 194 | |
| 195 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 196 | struct pldm_get_bios_table_req* request = |
| 197 | reinterpret_cast<struct pldm_get_bios_table_req*>(req->payload); |
| 198 | |
| 199 | request->transfer_handle = transferHandle; |
| 200 | request->transfer_op_flag = transferOpFlag; |
| 201 | request->table_type = tableType; |
| 202 | |
| 203 | auto rc = decode_get_bios_table_req(req, requestMsg.size() - hdr_size - 3, |
| 204 | &retTransferHandle, &retTransferOpFlag, |
| 205 | &retTableType); |
| 206 | |
| 207 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 208 | } |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 209 | |
| 210 | TEST(GetBIOSAttributeCurrentValueByHandle, testGoodDecodeRequest) |
| 211 | { |
| 212 | uint32_t transferHandle = 45; |
| 213 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 214 | uint16_t attributehandle = 10; |
| 215 | uint32_t retTransferHandle = 0; |
| 216 | uint8_t retTransferOpFlag = 0; |
| 217 | uint16_t retattributehandle = 0; |
| 218 | std::array<uint8_t, hdrSize + sizeof(transferHandle) + |
| 219 | sizeof(transferOpFlag) + sizeof(attributehandle)> |
| 220 | requestMsg{}; |
| 221 | |
| 222 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 223 | struct pldm_get_bios_attribute_current_value_by_handle_req* request = |
| 224 | reinterpret_cast< |
| 225 | struct pldm_get_bios_attribute_current_value_by_handle_req*>( |
| 226 | req->payload); |
| 227 | |
| 228 | request->transfer_handle = transferHandle; |
| 229 | request->transfer_op_flag = transferOpFlag; |
| 230 | request->attribute_handle = attributehandle; |
| 231 | |
| 232 | auto rc = decode_get_bios_attribute_current_value_by_handle_req( |
| 233 | req, requestMsg.size() - hdrSize, &retTransferHandle, |
| 234 | &retTransferOpFlag, &retattributehandle); |
| 235 | |
| 236 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 237 | ASSERT_EQ(transferHandle, retTransferHandle); |
| 238 | ASSERT_EQ(transferOpFlag, retTransferOpFlag); |
| 239 | ASSERT_EQ(attributehandle, retattributehandle); |
| 240 | } |
| 241 | |
| 242 | TEST(GetBIOSAttributeCurrentValueByHandle, testBadDecodeRequest) |
| 243 | { |
| 244 | |
| 245 | uint32_t transferHandle = 0; |
| 246 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 247 | uint16_t attribute_handle = 0; |
| 248 | uint32_t retTransferHandle = 0; |
| 249 | uint8_t retTransferOpFlag = 0; |
| 250 | uint16_t retattribute_handle = 0; |
| 251 | std::array<uint8_t, hdrSize + sizeof(transferHandle) + |
| 252 | sizeof(transferOpFlag) + sizeof(attribute_handle)> |
| 253 | requestMsg{}; |
| 254 | |
| 255 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 256 | struct pldm_get_bios_attribute_current_value_by_handle_req* request = |
| 257 | reinterpret_cast< |
| 258 | struct pldm_get_bios_attribute_current_value_by_handle_req*>( |
| 259 | req->payload); |
| 260 | |
| 261 | request->transfer_handle = transferHandle; |
| 262 | request->transfer_op_flag = transferOpFlag; |
| 263 | request->attribute_handle = attribute_handle; |
| 264 | |
| 265 | auto rc = decode_get_bios_attribute_current_value_by_handle_req( |
| 266 | NULL, requestMsg.size() - hdrSize, &retTransferHandle, |
| 267 | &retTransferOpFlag, &retattribute_handle); |
| 268 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 269 | |
| 270 | transferHandle = 31; |
| 271 | request->transfer_handle = transferHandle; |
| 272 | |
| 273 | rc = decode_get_bios_attribute_current_value_by_handle_req( |
| 274 | req, 0, &retTransferHandle, &retTransferOpFlag, &retattribute_handle); |
| 275 | |
| 276 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 277 | } |
| 278 | |
| 279 | TEST(GetBIOSAttributeCurrentValueByHandle, testGoodEncodeResponse) |
| 280 | { |
| 281 | |
| 282 | uint8_t instanceId = 10; |
| 283 | uint8_t completionCode = PLDM_SUCCESS; |
| 284 | uint32_t nextTransferHandle = 32; |
| 285 | uint8_t transferFlag = PLDM_START_AND_END; |
| 286 | uint8_t attributeData = 44; |
| 287 | std::array<uint8_t, |
| 288 | hdrSize + |
| 289 | sizeof(pldm_get_bios_attribute_current_value_by_handle_resp)> |
| 290 | responseMsg{}; |
| 291 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 292 | |
| 293 | auto rc = encode_get_bios_current_value_by_handle_resp( |
| 294 | instanceId, completionCode, nextTransferHandle, transferFlag, |
| 295 | &attributeData, sizeof(attributeData), response); |
| 296 | |
| 297 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 298 | |
| 299 | struct pldm_get_bios_attribute_current_value_by_handle_resp* resp = |
| 300 | reinterpret_cast< |
| 301 | struct pldm_get_bios_attribute_current_value_by_handle_resp*>( |
| 302 | response->payload); |
| 303 | |
| 304 | ASSERT_EQ(completionCode, resp->completion_code); |
| 305 | ASSERT_EQ(nextTransferHandle, resp->next_transfer_handle); |
| 306 | ASSERT_EQ(transferFlag, resp->transfer_flag); |
| 307 | ASSERT_EQ( |
| 308 | 0, memcmp(&attributeData, resp->attribute_data, sizeof(attributeData))); |
| 309 | } |
| 310 | |
| 311 | TEST(GetBIOSAttributeCurrentValueByHandle, testBadEncodeResponse) |
| 312 | { |
| 313 | uint32_t nextTransferHandle = 32; |
| 314 | uint8_t transferFlag = PLDM_START_AND_END; |
| 315 | uint8_t attributeData = 44; |
| 316 | |
| 317 | auto rc = encode_get_bios_current_value_by_handle_resp( |
| 318 | 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, &attributeData, |
| 319 | sizeof(attributeData), nullptr); |
| 320 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 321 | |
| 322 | std::array<uint8_t, |
| 323 | hdrSize + |
| 324 | sizeof(pldm_get_bios_attribute_current_value_by_handle_resp)> |
| 325 | responseMsg{}; |
| 326 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 327 | rc = encode_get_bios_current_value_by_handle_resp( |
| 328 | 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, nullptr, |
| 329 | sizeof(attributeData), response); |
| 330 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 331 | } |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 332 | |
| 333 | TEST(SetBiosAttributeCurrentValue, testGoodEncodeRequest) |
| 334 | { |
| 335 | uint8_t instanceId = 10; |
| 336 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 337 | uint8_t transferFlag = PLDM_START_AND_END; |
| 338 | uint32_t attributeData = 44; |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 339 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + |
| 340 | sizeof(attributeData)> |
| 341 | requestMsg{}; |
| 342 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 343 | auto rc = encode_set_bios_attribute_current_value_req( |
| 344 | instanceId, transferHandle, transferFlag, |
| 345 | reinterpret_cast<uint8_t*>(&attributeData), sizeof(attributeData), |
| 346 | request, requestMsg.size() - hdrSize); |
| 347 | |
| 348 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 349 | |
| 350 | struct pldm_set_bios_attribute_current_value_req* req = |
| 351 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_req*>( |
| 352 | request->payload); |
| 353 | ASSERT_EQ(htole32(transferHandle), req->transfer_handle); |
| 354 | ASSERT_EQ(transferFlag, req->transfer_flag); |
| 355 | ASSERT_EQ( |
| 356 | 0, memcmp(&attributeData, req->attribute_data, sizeof(attributeData))); |
| 357 | } |
| 358 | |
| 359 | TEST(SetBiosAttributeCurrentValue, testBadEncodeRequest) |
| 360 | { |
| 361 | uint8_t instanceId = 10; |
| 362 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 363 | uint8_t transferFlag = PLDM_START_AND_END; |
| 364 | uint32_t attributeData = 44; |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 365 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES> |
| 366 | requestMsg{}; |
| 367 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 368 | |
| 369 | auto rc = encode_set_bios_attribute_current_value_req( |
| 370 | instanceId, transferHandle, transferFlag, nullptr, 0, nullptr, 0); |
| 371 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 372 | rc = encode_set_bios_attribute_current_value_req( |
| 373 | instanceId, transferHandle, transferFlag, |
| 374 | reinterpret_cast<uint8_t*>(&attributeData), sizeof(attributeData), |
| 375 | request, requestMsg.size() - hdrSize); |
| 376 | |
| 377 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 378 | } |
| 379 | |
| 380 | TEST(SetBiosAttributeCurrentValue, testGoodDecodeRequest) |
| 381 | { |
| 382 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 383 | uint8_t transferFlag = PLDM_START_AND_END; |
| 384 | uint32_t attributeData = 44; |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 385 | |
| 386 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + |
| 387 | sizeof(attributeData)> |
| 388 | requestMsg{}; |
| 389 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 390 | struct pldm_set_bios_attribute_current_value_req* req = |
| 391 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_req*>( |
| 392 | request->payload); |
| 393 | req->transfer_handle = htole32(transferHandle); |
| 394 | req->transfer_flag = transferFlag; |
| 395 | memcpy(req->attribute_data, &attributeData, sizeof(attributeData)); |
| 396 | |
| 397 | uint32_t retTransferHandle; |
| 398 | uint8_t retTransferFlag; |
| 399 | uint32_t retAttributeData; |
| 400 | size_t retAttributeDataLength; |
| 401 | auto rc = decode_set_bios_attribute_current_value_req( |
| 402 | request, requestMsg.size() - hdrSize, &retTransferHandle, |
| 403 | &retTransferFlag, reinterpret_cast<uint8_t*>(&retAttributeData), |
| 404 | &retAttributeDataLength); |
| 405 | |
| 406 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 407 | ASSERT_EQ(retTransferHandle, transferHandle); |
| 408 | ASSERT_EQ(retTransferFlag, transferFlag); |
| 409 | ASSERT_EQ(retAttributeDataLength, sizeof(attributeData)); |
| 410 | ASSERT_EQ(0, |
| 411 | memcmp(&retAttributeData, &attributeData, sizeof(attributeData))); |
| 412 | } |
| 413 | |
| 414 | TEST(SetBiosAttributeCurrentValue, testBadDecodeRequest) |
| 415 | { |
| 416 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 417 | uint8_t transferFlag = PLDM_START_AND_END; |
| 418 | uint32_t attributeData = 44; |
| 419 | size_t attributeDataLength = sizeof(attributeData); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 420 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES - 1> |
| 421 | requestMsg{}; |
| 422 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 423 | |
| 424 | auto rc = decode_set_bios_attribute_current_value_req( |
| 425 | nullptr, 0, &transferHandle, &transferFlag, |
| 426 | reinterpret_cast<uint8_t*>(&attributeData), &attributeDataLength); |
| 427 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 428 | rc = decode_set_bios_attribute_current_value_req( |
| 429 | request, requestMsg.size() - hdrSize, &transferHandle, &transferFlag, |
| 430 | reinterpret_cast<uint8_t*>(&attributeData), &attributeDataLength); |
| 431 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 432 | } |
| 433 | |
| 434 | TEST(SetBiosAttributeCurrentValue, testGoodEncodeResponse) |
| 435 | { |
| 436 | uint8_t instanceId = 10; |
| 437 | uint32_t nextTransferHandle = 32; |
| 438 | uint8_t completionCode = PLDM_SUCCESS; |
| 439 | |
| 440 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES> |
| 441 | responseMsg{}; |
| 442 | struct pldm_msg* response = |
| 443 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 444 | auto rc = encode_set_bios_attribute_current_value_resp( |
| 445 | instanceId, completionCode, nextTransferHandle, response); |
| 446 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 447 | |
| 448 | struct pldm_set_bios_attribute_current_value_resp* resp = |
| 449 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>( |
| 450 | response->payload); |
| 451 | ASSERT_EQ(completionCode, resp->completion_code); |
| 452 | ASSERT_EQ(htole32(nextTransferHandle), resp->next_transfer_handle); |
| 453 | } |
| 454 | |
| 455 | TEST(SetBiosAttributeCurrentValue, testBadEncodeResponse) |
| 456 | { |
| 457 | uint8_t instanceId = 10; |
| 458 | uint32_t nextTransferHandle = 32; |
| 459 | uint8_t completionCode = PLDM_SUCCESS; |
| 460 | auto rc = encode_set_bios_attribute_current_value_resp( |
| 461 | instanceId, completionCode, nextTransferHandle, nullptr); |
| 462 | |
| 463 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 464 | } |
| 465 | TEST(SetBiosAttributeCurrentValue, testGoodDecodeResponse) |
| 466 | { |
| 467 | uint32_t nextTransferHandle = 32; |
| 468 | uint8_t completionCode = PLDM_SUCCESS; |
| 469 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES> |
| 470 | responseMsg{}; |
| 471 | struct pldm_msg* response = |
| 472 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 473 | struct pldm_set_bios_attribute_current_value_resp* resp = |
| 474 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>( |
| 475 | response->payload); |
| 476 | |
| 477 | resp->completion_code = completionCode; |
| 478 | resp->next_transfer_handle = htole32(nextTransferHandle); |
| 479 | |
| 480 | uint8_t retCompletionCode; |
| 481 | uint32_t retNextTransferHandle; |
| 482 | auto rc = decode_set_bios_attribute_current_value_resp( |
| 483 | response, responseMsg.size() - hdrSize, &retCompletionCode, |
| 484 | &retNextTransferHandle); |
| 485 | |
| 486 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 487 | ASSERT_EQ(completionCode, retCompletionCode); |
| 488 | ASSERT_EQ(nextTransferHandle, retNextTransferHandle); |
| 489 | } |
| 490 | |
| 491 | TEST(SetBiosAttributeCurrentValue, testBadDecodeResponse) |
| 492 | { |
| 493 | uint32_t nextTransferHandle = 32; |
| 494 | uint8_t completionCode = PLDM_SUCCESS; |
| 495 | |
| 496 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES - 1> |
| 497 | responseMsg{}; |
| 498 | struct pldm_msg* response = |
| 499 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 500 | auto rc = decode_set_bios_attribute_current_value_resp( |
| 501 | nullptr, 0, &completionCode, &nextTransferHandle); |
| 502 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 503 | |
| 504 | rc = decode_set_bios_attribute_current_value_resp( |
| 505 | response, responseMsg.size() - hdrSize, &completionCode, |
| 506 | &nextTransferHandle); |
| 507 | |
| 508 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 509 | } |