Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 1 | #include <string.h> |
| 2 | |
| 3 | #include <array> |
| 4 | |
| 5 | #include "libpldm/base.h" |
| 6 | #include "libpldm/fru.h" |
| 7 | |
| 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | TEST(GetFruRecordTableMetadata, testGoodEncodeRequest) |
| 11 | { |
| 12 | std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{}; |
| 13 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 14 | auto rc = encode_get_fru_record_table_metadata_req(0, requestPtr); |
| 15 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 16 | ASSERT_EQ(requestPtr->hdr.request, PLDM_REQUEST); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 17 | ASSERT_EQ(requestPtr->hdr.instance_id, 0u); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 18 | ASSERT_EQ(requestPtr->hdr.type, PLDM_FRU); |
| 19 | ASSERT_EQ(requestPtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE_METADATA); |
| 20 | } |
| 21 | |
| 22 | TEST(GetFruRecordTableMetadata, testBadEncodeRequest) |
| 23 | { |
| 24 | auto rc = encode_get_fru_record_table_metadata_req(0, NULL); |
| 25 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 26 | } |
| 27 | |
| 28 | TEST(GetFruRecordTableMetadata, testGoodDecodeResponse) |
| 29 | { |
| 30 | |
| 31 | std::vector<uint8_t> responseMsg( |
| 32 | sizeof(pldm_msg_hdr) + PLDM_GET_FRU_RECORD_TABLE_METADATA_RESP_BYTES); |
| 33 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 34 | size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr); |
| 35 | auto response = reinterpret_cast<pldm_get_fru_record_table_metadata_resp*>( |
| 36 | responsePtr->payload); |
| 37 | |
| 38 | responsePtr->hdr.request = PLDM_RESPONSE; |
| 39 | responsePtr->hdr.instance_id = 0; |
| 40 | responsePtr->hdr.type = PLDM_FRU; |
| 41 | responsePtr->hdr.command = PLDM_GET_FRU_RECORD_TABLE_METADATA; |
| 42 | response->completion_code = PLDM_SUCCESS; |
| 43 | response->fru_data_major_version = 0x12; |
| 44 | response->fru_data_minor_version = 0x21; |
Lei YU | 7cfeb8e | 2020-02-27 18:24:18 +0800 | [diff] [blame] | 45 | response->fru_table_maximum_size = htole32(0x1234ABCD); |
| 46 | response->fru_table_length = htole32(0x56781234); |
| 47 | response->total_record_set_identifiers = htole16(0x34EF); |
| 48 | response->total_table_records = htole16(0xEEEF); |
| 49 | response->checksum = htole32(0x6543FA71); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 50 | |
| 51 | uint8_t completion_code = 0xFF; |
| 52 | uint8_t fru_data_major_version = 0x00; |
| 53 | uint8_t fru_data_minor_version = 0x00; |
Lei YU | 7cfeb8e | 2020-02-27 18:24:18 +0800 | [diff] [blame] | 54 | uint32_t fru_table_maximum_size = htole32(0x00000000); |
| 55 | uint32_t fru_table_length = htole32(0x00000000); |
| 56 | uint16_t total_record_set_identifiers = htole16(0x0000); |
| 57 | uint16_t total_table_records = htole16(0x0000); |
| 58 | uint32_t checksum = htole32(0x00000000); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 59 | |
| 60 | auto rc = decode_get_fru_record_table_metadata_resp( |
| 61 | responsePtr, payload_length, &completion_code, &fru_data_major_version, |
| 62 | &fru_data_minor_version, &fru_table_maximum_size, &fru_table_length, |
| 63 | &total_record_set_identifiers, &total_table_records, &checksum); |
| 64 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 65 | ASSERT_EQ(completion_code, PLDM_SUCCESS); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 66 | ASSERT_EQ(fru_data_major_version, 0x12u); |
| 67 | ASSERT_EQ(fru_data_minor_version, 0x21u); |
| 68 | ASSERT_EQ(fru_table_maximum_size, 0x1234ABCDu); |
| 69 | ASSERT_EQ(fru_table_length, 0x56781234u); |
| 70 | ASSERT_EQ(total_record_set_identifiers, 0x34EFu); |
| 71 | ASSERT_EQ(total_table_records, 0xEEEFu); |
| 72 | ASSERT_EQ(checksum, 0x6543FA71u); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 73 | |
| 74 | response->fru_data_major_version = 0x00; |
| 75 | response->fru_data_minor_version = 0x00; |
Lei YU | 7cfeb8e | 2020-02-27 18:24:18 +0800 | [diff] [blame] | 76 | response->fru_table_maximum_size = htole32(0x00000000); |
| 77 | response->fru_table_length = htole32(0x00000000); |
| 78 | response->total_record_set_identifiers = htole16(0x0000); |
| 79 | response->total_table_records = htole16(0x0000); |
| 80 | response->checksum = htole32(0x00000000); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 81 | fru_data_major_version = 0x00; |
| 82 | fru_data_minor_version = 0x00; |
Lei YU | 7cfeb8e | 2020-02-27 18:24:18 +0800 | [diff] [blame] | 83 | fru_table_maximum_size = htole32(0x00000000); |
| 84 | fru_table_length = htole32(0x00000000); |
| 85 | total_record_set_identifiers = htole16(0x0000); |
| 86 | total_table_records = htole16(0x0000); |
| 87 | checksum = htole32(0x00000000); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 88 | response->completion_code = PLDM_ERROR_INVALID_LENGTH; |
| 89 | rc = decode_get_fru_record_table_metadata_resp( |
| 90 | responsePtr, payload_length, &completion_code, &fru_data_major_version, |
| 91 | &fru_data_minor_version, &fru_table_maximum_size, &fru_table_length, |
| 92 | &total_record_set_identifiers, &total_table_records, &checksum); |
| 93 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 94 | ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 95 | ASSERT_EQ(responsePtr->hdr.instance_id, 0u); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 96 | ASSERT_EQ(responsePtr->hdr.type, PLDM_FRU); |
| 97 | ASSERT_EQ(responsePtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE_METADATA); |
| 98 | ASSERT_EQ(completion_code, PLDM_ERROR_INVALID_LENGTH); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 99 | ASSERT_EQ(fru_data_major_version, 0x00u); |
| 100 | ASSERT_EQ(fru_data_minor_version, 0x00u); |
| 101 | ASSERT_EQ(fru_table_maximum_size, 0x00000000u); |
| 102 | ASSERT_EQ(fru_table_length, 0x00000000u); |
| 103 | ASSERT_EQ(total_record_set_identifiers, 0x0000u); |
| 104 | ASSERT_EQ(total_table_records, 0x0000u); |
| 105 | ASSERT_EQ(checksum, 0x00000000u); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | TEST(GetFruRecordTableMetadata, testBadDecodeResponse) |
| 109 | { |
| 110 | std::vector<uint8_t> responseMsg( |
| 111 | sizeof(pldm_msg_hdr) + PLDM_GET_FRU_RECORD_TABLE_METADATA_RESP_BYTES); |
| 112 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 113 | size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr); |
| 114 | auto response = reinterpret_cast<pldm_get_fru_record_table_metadata_resp*>( |
| 115 | responsePtr->payload); |
| 116 | |
| 117 | response->completion_code = PLDM_SUCCESS; |
| 118 | response->fru_data_major_version = 0x12; |
| 119 | response->fru_data_minor_version = 0x21; |
Lei YU | 7cfeb8e | 2020-02-27 18:24:18 +0800 | [diff] [blame] | 120 | response->fru_table_maximum_size = htole32(0x1234ABCD); |
| 121 | response->fru_table_length = htole32(0x56781234); |
| 122 | response->total_record_set_identifiers = htole16(0x34EF); |
| 123 | response->total_table_records = htole16(0xEEEF); |
| 124 | response->checksum = htole32(0x6543FA71); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 125 | |
| 126 | uint8_t completion_code = 0xFF; |
| 127 | uint8_t fru_data_major_version = 0x00; |
| 128 | uint8_t fru_data_minor_version = 0x00; |
Lei YU | 7cfeb8e | 2020-02-27 18:24:18 +0800 | [diff] [blame] | 129 | uint32_t fru_table_maximum_size = htole32(0x00000000); |
| 130 | uint32_t fru_table_length = htole32(0x00000000); |
| 131 | uint16_t total_record_set_identifiers = htole16(0x0000); |
| 132 | uint16_t total_table_records = htole16(0x0000); |
| 133 | uint32_t checksum = htole32(0x00000000); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 134 | |
| 135 | auto rc = decode_get_fru_record_table_metadata_resp( |
| 136 | responsePtr, PLDM_GET_FRU_RECORD_TABLE_METADATA_RESP_BYTES + 2, |
| 137 | &completion_code, &fru_data_major_version, &fru_data_minor_version, |
| 138 | &fru_table_maximum_size, &fru_table_length, |
| 139 | &total_record_set_identifiers, &total_table_records, &checksum); |
| 140 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 141 | |
| 142 | rc = decode_get_fru_record_table_metadata_resp( |
| 143 | responsePtr, payload_length, &completion_code, NULL, |
| 144 | &fru_data_minor_version, &fru_table_maximum_size, &fru_table_length, |
| 145 | &total_record_set_identifiers, &total_table_records, &checksum); |
| 146 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 147 | |
| 148 | rc = decode_get_fru_record_table_metadata_resp( |
| 149 | responsePtr, payload_length, &completion_code, &fru_data_major_version, |
| 150 | NULL, &fru_table_maximum_size, &fru_table_length, |
| 151 | &total_record_set_identifiers, &total_table_records, &checksum); |
| 152 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 153 | |
| 154 | rc = decode_get_fru_record_table_metadata_resp( |
| 155 | responsePtr, payload_length, &completion_code, &fru_data_major_version, |
| 156 | &fru_data_minor_version, NULL, &fru_table_length, |
| 157 | &total_record_set_identifiers, &total_table_records, &checksum); |
| 158 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 159 | |
| 160 | rc = decode_get_fru_record_table_metadata_resp( |
| 161 | responsePtr, payload_length, &completion_code, &fru_data_major_version, |
| 162 | &fru_data_minor_version, &fru_table_maximum_size, NULL, |
| 163 | &total_record_set_identifiers, &total_table_records, &checksum); |
| 164 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 165 | |
| 166 | rc = decode_get_fru_record_table_metadata_resp( |
| 167 | responsePtr, payload_length, &completion_code, &fru_data_major_version, |
| 168 | &fru_data_minor_version, &fru_table_maximum_size, &fru_table_length, |
| 169 | NULL, &total_table_records, &checksum); |
| 170 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 171 | |
| 172 | rc = decode_get_fru_record_table_metadata_resp( |
| 173 | responsePtr, payload_length, &completion_code, &fru_data_major_version, |
| 174 | &fru_data_minor_version, &fru_table_maximum_size, &fru_table_length, |
| 175 | &total_record_set_identifiers, NULL, &checksum); |
| 176 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 177 | |
| 178 | rc = decode_get_fru_record_table_metadata_resp( |
| 179 | responsePtr, payload_length, &completion_code, &fru_data_major_version, |
| 180 | &fru_data_minor_version, &fru_table_maximum_size, &fru_table_length, |
| 181 | &total_record_set_identifiers, &total_table_records, NULL); |
| 182 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 183 | } |
| 184 | |
| 185 | TEST(GetFruRecordTableMetadata, testGoodEncodeResponse) |
| 186 | { |
| 187 | |
| 188 | std::array<uint8_t, sizeof(pldm_msg_hdr) + |
| 189 | PLDM_GET_FRU_RECORD_TABLE_METADATA_RESP_BYTES> |
| 190 | responseMsg{}; |
| 191 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 192 | |
| 193 | responsePtr->hdr.request = PLDM_RESPONSE; |
| 194 | responsePtr->hdr.instance_id = 0; |
| 195 | responsePtr->hdr.type = PLDM_FRU; |
| 196 | responsePtr->hdr.command = PLDM_GET_FRU_RECORD_TABLE_METADATA; |
| 197 | |
| 198 | uint8_t completion_code = PLDM_SUCCESS; |
| 199 | uint8_t fru_data_major_version = 0x12; |
| 200 | uint8_t fru_data_minor_version = 0x21; |
Lei YU | 7cfeb8e | 2020-02-27 18:24:18 +0800 | [diff] [blame] | 201 | uint32_t fru_table_maximum_size = htole32(0x1234ABCD); |
| 202 | uint32_t fru_table_length = htole32(0x56781234); |
| 203 | uint16_t total_record_set_identifiers = htole16(0x34EF); |
| 204 | uint16_t total_table_records = htole16(0xEEEF); |
| 205 | uint32_t checksum = htole32(0x6543FA71); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 206 | |
| 207 | auto rc = encode_get_fru_record_table_metadata_resp( |
| 208 | 0, completion_code, fru_data_major_version, fru_data_minor_version, |
| 209 | fru_table_maximum_size, fru_table_length, total_record_set_identifiers, |
| 210 | total_table_records, checksum, responsePtr); |
| 211 | |
| 212 | auto response = reinterpret_cast<pldm_get_fru_record_table_metadata_resp*>( |
| 213 | responsePtr->payload); |
| 214 | |
| 215 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 216 | ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 217 | ASSERT_EQ(responsePtr->hdr.instance_id, 0u); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 218 | ASSERT_EQ(responsePtr->hdr.type, PLDM_FRU); |
| 219 | ASSERT_EQ(responsePtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE_METADATA); |
| 220 | ASSERT_EQ(response->completion_code, PLDM_SUCCESS); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 221 | ASSERT_EQ(response->fru_data_major_version, 0x12u); |
| 222 | ASSERT_EQ(response->fru_data_minor_version, 0x21u); |
| 223 | ASSERT_EQ(response->fru_table_maximum_size, 0x1234ABCDu); |
| 224 | ASSERT_EQ(response->fru_table_length, 0x56781234u); |
| 225 | ASSERT_EQ(response->total_record_set_identifiers, 0x34EFu); |
| 226 | ASSERT_EQ(response->total_table_records, 0xEEEFu); |
| 227 | ASSERT_EQ(response->checksum, 0x6543FA71u); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 228 | |
| 229 | response->fru_data_major_version = 0; |
| 230 | response->fru_data_major_version = 0x00; |
| 231 | response->fru_data_minor_version = 0x00; |
Lei YU | 7cfeb8e | 2020-02-27 18:24:18 +0800 | [diff] [blame] | 232 | response->fru_table_maximum_size = htole32(0x00000000); |
| 233 | response->fru_table_length = htole32(0x00000000); |
| 234 | response->total_record_set_identifiers = htole16(0x0000); |
| 235 | response->total_table_records = htole16(0x0000); |
| 236 | response->checksum = htole32(0x00000000); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 237 | completion_code = PLDM_ERROR_INVALID_DATA; |
| 238 | rc = encode_get_fru_record_table_metadata_resp( |
| 239 | 0, completion_code, fru_data_major_version, fru_data_minor_version, |
| 240 | fru_table_maximum_size, fru_table_length, total_record_set_identifiers, |
| 241 | total_table_records, checksum, responsePtr); |
| 242 | |
| 243 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 244 | ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 245 | ASSERT_EQ(responsePtr->hdr.instance_id, 0u); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 246 | ASSERT_EQ(responsePtr->hdr.type, PLDM_FRU); |
| 247 | ASSERT_EQ(responsePtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE_METADATA); |
| 248 | ASSERT_EQ(completion_code, PLDM_ERROR_INVALID_DATA); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 249 | ASSERT_EQ(response->fru_data_major_version, 0x00u); |
| 250 | ASSERT_EQ(response->fru_data_minor_version, 0x00u); |
| 251 | ASSERT_EQ(response->fru_table_maximum_size, 0x00000000u); |
| 252 | ASSERT_EQ(response->fru_table_length, 0x00000000u); |
| 253 | ASSERT_EQ(response->total_record_set_identifiers, 0x0000u); |
| 254 | ASSERT_EQ(response->total_table_records, 0x0000u); |
| 255 | ASSERT_EQ(response->checksum, 0x00000000u); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | TEST(GetFruRecordTableMetadata, testBadEncodeResponse) |
| 259 | { |
| 260 | std::array<uint8_t, sizeof(pldm_msg_hdr) + |
| 261 | PLDM_GET_FRU_RECORD_TABLE_METADATA_RESP_BYTES> |
| 262 | responseMsg{}; |
| 263 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 264 | |
| 265 | uint8_t completion_code = PLDM_SUCCESS; |
| 266 | uint8_t fru_data_major_version = 0x12; |
| 267 | uint8_t fru_data_minor_version = 0x21; |
Lei YU | 7cfeb8e | 2020-02-27 18:24:18 +0800 | [diff] [blame] | 268 | uint32_t fru_table_maximum_size = htole32(0x1234ABCD); |
| 269 | uint32_t fru_table_length = htole32(0x56781234); |
| 270 | uint16_t total_record_set_identifiers = htole16(0x34EF); |
| 271 | uint16_t total_table_records = htole16(0xEEEF); |
| 272 | uint32_t checksum = htole32(0x6543FA71); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 273 | |
| 274 | auto rc = encode_get_fru_record_table_metadata_resp( |
| 275 | 0, completion_code, fru_data_major_version, fru_data_minor_version, |
| 276 | fru_table_maximum_size, fru_table_length, total_record_set_identifiers, |
| 277 | total_table_records, checksum, NULL); |
| 278 | |
| 279 | auto response = reinterpret_cast<pldm_get_fru_record_table_metadata_resp*>( |
| 280 | responsePtr->payload); |
| 281 | |
| 282 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 283 | ASSERT_EQ(completion_code, PLDM_SUCCESS); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 284 | ASSERT_EQ(response->fru_data_major_version, 0x00u); |
| 285 | ASSERT_EQ(response->fru_data_minor_version, 0x00u); |
| 286 | ASSERT_EQ(response->fru_table_maximum_size, 0x00000000u); |
| 287 | ASSERT_EQ(response->fru_table_length, 0x00000000u); |
| 288 | ASSERT_EQ(response->total_record_set_identifiers, 0x0000u); |
| 289 | ASSERT_EQ(response->total_table_records, 0x0000u); |
| 290 | ASSERT_EQ(response->checksum, 0x00000000u); |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 291 | } |
PriyangaRamasamy | 497665a | 2019-07-30 12:48:25 +0530 | [diff] [blame] | 292 | |
| 293 | TEST(GetFruRecordTable, testGoodDecodeRequest) |
| 294 | { |
| 295 | uint32_t data_transfer_handle = 31; |
| 296 | uint8_t transfer_operation_flag = PLDM_GET_FIRSTPART; |
| 297 | std::array<uint8_t, |
| 298 | PLDM_GET_FRU_RECORD_TABLE_REQ_BYTES + sizeof(pldm_msg_hdr)> |
| 299 | requestMsg{}; |
| 300 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 301 | size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr); |
| 302 | auto request = |
| 303 | reinterpret_cast<pldm_get_fru_record_table_req*>(requestPtr->payload); |
| 304 | |
Lei YU | 90ff3ed | 2020-03-02 11:16:51 +0800 | [diff] [blame] | 305 | request->data_transfer_handle = htole32(data_transfer_handle); |
PriyangaRamasamy | 497665a | 2019-07-30 12:48:25 +0530 | [diff] [blame] | 306 | request->transfer_operation_flag = transfer_operation_flag; |
| 307 | |
| 308 | uint32_t ret_data_transfer_handle = 0; |
| 309 | uint8_t ret_transfer_operation_flag = 0; |
| 310 | |
| 311 | // Invoke decode get FRU record table request api |
| 312 | auto rc = decode_get_fru_record_table_req(requestPtr, payload_length, |
| 313 | &ret_data_transfer_handle, |
| 314 | &ret_transfer_operation_flag); |
| 315 | |
| 316 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 317 | ASSERT_EQ(data_transfer_handle, ret_data_transfer_handle); |
| 318 | ASSERT_EQ(transfer_operation_flag, ret_transfer_operation_flag); |
| 319 | } |
| 320 | |
| 321 | TEST(GetFruRecordTable, testBadDecodeRequest) |
| 322 | { |
| 323 | uint32_t data_transfer_handle = 0x0; |
| 324 | uint8_t transfer_operation_flag = PLDM_GET_FIRSTPART; |
| 325 | |
| 326 | std::array<uint8_t, |
| 327 | sizeof(pldm_msg_hdr) + PLDM_GET_FRU_RECORD_TABLE_REQ_BYTES> |
| 328 | requestMsg{}; |
| 329 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 330 | |
| 331 | // Payload message is missing |
| 332 | auto rc = decode_get_fru_record_table_req(NULL, 0, &data_transfer_handle, |
| 333 | &transfer_operation_flag); |
| 334 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 335 | |
| 336 | // Payload length is invalid |
| 337 | rc = decode_get_fru_record_table_req(requestPtr, 0, &data_transfer_handle, |
| 338 | &transfer_operation_flag); |
| 339 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 340 | } |
| 341 | |
| 342 | TEST(GetFruRecordTable, testGoodEncodeResponse) |
| 343 | { |
| 344 | uint8_t completion_code = 0; |
| 345 | uint32_t next_data_transfer_handle = 32; |
| 346 | uint8_t transfer_flag = PLDM_START_AND_END; |
| 347 | |
| 348 | std::vector<uint8_t> responseMsg(sizeof(pldm_msg_hdr) + |
| 349 | PLDM_GET_FRU_RECORD_TABLE_MIN_RESP_BYTES); |
| 350 | |
| 351 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 352 | auto response = |
| 353 | reinterpret_cast<pldm_get_fru_record_table_resp*>(responsePtr->payload); |
| 354 | |
| 355 | // Invoke encode get FRU record table response api |
| 356 | auto rc = encode_get_fru_record_table_resp(0, completion_code, |
| 357 | next_data_transfer_handle, |
| 358 | transfer_flag, responsePtr); |
| 359 | |
| 360 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 361 | ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 362 | ASSERT_EQ(responsePtr->hdr.instance_id, 0u); |
PriyangaRamasamy | 497665a | 2019-07-30 12:48:25 +0530 | [diff] [blame] | 363 | ASSERT_EQ(responsePtr->hdr.type, PLDM_FRU); |
| 364 | ASSERT_EQ(responsePtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE); |
| 365 | ASSERT_EQ(response->completion_code, PLDM_SUCCESS); |
Lei YU | 90ff3ed | 2020-03-02 11:16:51 +0800 | [diff] [blame] | 366 | ASSERT_EQ(le32toh(response->next_data_transfer_handle), |
| 367 | next_data_transfer_handle); |
PriyangaRamasamy | 497665a | 2019-07-30 12:48:25 +0530 | [diff] [blame] | 368 | ASSERT_EQ(response->transfer_flag, transfer_flag); |
| 369 | } |
| 370 | |
| 371 | TEST(GetFruRecordTable, testBadEncodeResponse) |
| 372 | { |
| 373 | uint32_t next_data_transfer_handle = 32; |
| 374 | uint8_t transfer_flag = PLDM_START_AND_END; |
| 375 | |
| 376 | std::vector<uint8_t> responseMsg(sizeof(pldm_msg_hdr) + |
| 377 | PLDM_GET_FRU_RECORD_TABLE_MIN_RESP_BYTES); |
| 378 | |
| 379 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 380 | auto rc = encode_get_fru_record_table_resp( |
| 381 | 0, PLDM_ERROR, next_data_transfer_handle, transfer_flag, responsePtr); |
| 382 | |
| 383 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 384 | ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 385 | ASSERT_EQ(responsePtr->hdr.instance_id, 0u); |
PriyangaRamasamy | 497665a | 2019-07-30 12:48:25 +0530 | [diff] [blame] | 386 | ASSERT_EQ(responsePtr->hdr.type, PLDM_FRU); |
| 387 | ASSERT_EQ(responsePtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE); |
| 388 | ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR); |
| 389 | |
| 390 | rc = encode_get_fru_record_table_resp( |
| 391 | 0, PLDM_SUCCESS, next_data_transfer_handle, transfer_flag, nullptr); |
| 392 | |
| 393 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 394 | } |
PriyangaRamasamy | f3295be | 2019-07-23 12:18:40 +0530 | [diff] [blame] | 395 | |
| 396 | TEST(GetFruRecordTable, testGoodEncodeRequest) |
| 397 | |
| 398 | { |
| 399 | std::array<uint8_t, |
| 400 | sizeof(pldm_msg_hdr) + PLDM_GET_FRU_RECORD_TABLE_REQ_BYTES> |
| 401 | requestMsg{}; |
| 402 | |
| 403 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 404 | auto request = |
| 405 | reinterpret_cast<pldm_get_fru_record_table_req*>(requestPtr->payload); |
| 406 | |
| 407 | // Random value for data transfer handle and transfer operation flag |
| 408 | uint32_t data_transfer_handle = 32; |
| 409 | uint8_t transfer_operation_flag = PLDM_GET_FIRSTPART; |
| 410 | |
| 411 | // Invoke encode get FRU record table request api |
| 412 | auto rc = encode_get_fru_record_table_req( |
| 413 | 0, data_transfer_handle, transfer_operation_flag, requestPtr, |
| 414 | requestMsg.size() - sizeof(pldm_msg_hdr)); |
| 415 | |
| 416 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 417 | ASSERT_EQ(requestPtr->hdr.request, PLDM_REQUEST); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 418 | ASSERT_EQ(requestPtr->hdr.instance_id, 0u); |
PriyangaRamasamy | f3295be | 2019-07-23 12:18:40 +0530 | [diff] [blame] | 419 | ASSERT_EQ(requestPtr->hdr.type, PLDM_FRU); |
| 420 | ASSERT_EQ(requestPtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE); |
| 421 | ASSERT_EQ(le32toh(data_transfer_handle), request->data_transfer_handle); |
| 422 | ASSERT_EQ(transfer_operation_flag, request->transfer_operation_flag); |
| 423 | } |
| 424 | |
| 425 | TEST(GetFruRecordTable, testBadEncodeRequest) |
| 426 | |
| 427 | { |
| 428 | uint32_t data_transfer_handle = 0x0; |
| 429 | uint8_t transfer_operation_flag = PLDM_GET_FIRSTPART; |
| 430 | |
| 431 | std::array<uint8_t, |
| 432 | sizeof(pldm_msg_hdr) + PLDM_GET_FRU_RECORD_TABLE_REQ_BYTES> |
| 433 | requestMsg{}; |
| 434 | auto rc = encode_get_fru_record_table_req( |
| 435 | 0, data_transfer_handle, transfer_operation_flag, NULL, |
| 436 | requestMsg.size() - sizeof(pldm_msg_hdr)); |
| 437 | |
| 438 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 439 | } |
| 440 | |
| 441 | TEST(GetFruRecordTable, testGoodDecodeResponse) |
| 442 | { |
| 443 | uint8_t completion_code = PLDM_SUCCESS; |
| 444 | uint32_t next_data_transfer_handle = 0x16; |
| 445 | uint8_t transfer_flag = PLDM_START_AND_END; |
| 446 | std::vector<uint8_t> fru_record_table_data = {1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 447 | |
| 448 | std::vector<uint8_t> responseMsg(sizeof(pldm_msg_hdr) + |
| 449 | PLDM_GET_FRU_RECORD_TABLE_MIN_RESP_BYTES + |
| 450 | fru_record_table_data.size()); |
| 451 | |
| 452 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 453 | size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr); |
| 454 | auto response = |
| 455 | reinterpret_cast<pldm_get_fru_record_table_resp*>(responsePtr->payload); |
| 456 | |
| 457 | response->completion_code = completion_code; |
| 458 | response->next_data_transfer_handle = htole32(next_data_transfer_handle); |
| 459 | response->transfer_flag = transfer_flag; |
| 460 | memcpy(response->fru_record_table_data, fru_record_table_data.data(), |
| 461 | fru_record_table_data.size()); |
| 462 | |
| 463 | uint8_t ret_completion_code = 0; |
| 464 | uint32_t ret_next_data_transfer_handle = 0; |
| 465 | uint8_t ret_transfer_flag = 0; |
| 466 | std::vector<uint8_t> ret_fru_record_table_data(9, 0); |
| 467 | size_t ret_fru_record_table_length = 0; |
| 468 | |
| 469 | // Invoke decode get FRU record table response api |
| 470 | auto rc = decode_get_fru_record_table_resp( |
| 471 | responsePtr, payload_length, &ret_completion_code, |
| 472 | &ret_next_data_transfer_handle, &ret_transfer_flag, |
| 473 | ret_fru_record_table_data.data(), &ret_fru_record_table_length); |
| 474 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 475 | ASSERT_EQ(completion_code, ret_completion_code); |
| 476 | ASSERT_EQ(next_data_transfer_handle, ret_next_data_transfer_handle); |
| 477 | ASSERT_EQ(transfer_flag, ret_transfer_flag); |
| 478 | ASSERT_EQ(0, memcmp(fru_record_table_data.data(), |
| 479 | ret_fru_record_table_data.data(), |
| 480 | ret_fru_record_table_length)); |
| 481 | ASSERT_EQ(fru_record_table_data.size(), ret_fru_record_table_length); |
| 482 | } |
| 483 | |
| 484 | TEST(GetFruRecordTable, testBadDecodeResponse) |
| 485 | { |
| 486 | uint8_t completion_code = 0; |
| 487 | uint32_t next_data_transfer_handle = 0; |
| 488 | uint8_t transfer_flag = PLDM_START_AND_END; |
| 489 | std::vector<uint8_t> fru_record_table_data(9, 0); |
| 490 | size_t fru_record_table_length = 0; |
| 491 | |
| 492 | std::vector<uint8_t> responseMsg(sizeof(pldm_msg_hdr) + |
| 493 | PLDM_GET_FRU_RECORD_TABLE_MIN_RESP_BYTES + |
| 494 | fru_record_table_data.size()); |
| 495 | |
| 496 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 497 | |
| 498 | // Payload message is missing |
| 499 | auto rc = decode_get_fru_record_table_resp( |
| 500 | NULL, 0, &completion_code, &next_data_transfer_handle, &transfer_flag, |
| 501 | fru_record_table_data.data(), &fru_record_table_length); |
| 502 | |
| 503 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 504 | |
| 505 | // Payload length is invalid |
| 506 | rc = decode_get_fru_record_table_resp( |
| 507 | responsePtr, 0, &completion_code, &next_data_transfer_handle, |
| 508 | &transfer_flag, fru_record_table_data.data(), &fru_record_table_length); |
| 509 | |
| 510 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 511 | } |