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); |
| 17 | ASSERT_EQ(requestPtr->hdr.instance_id, 0); |
| 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; |
| 45 | response->fru_table_maximum_size = 0x1234ABCD; |
| 46 | response->fru_table_length = 0x56781234; |
| 47 | response->total_record_set_identifiers = 0x34EF; |
| 48 | response->total_table_records = 0xEEEF; |
| 49 | response->checksum = 0x6543FA71; |
| 50 | |
| 51 | uint8_t completion_code = 0xFF; |
| 52 | uint8_t fru_data_major_version = 0x00; |
| 53 | uint8_t fru_data_minor_version = 0x00; |
| 54 | uint32_t fru_table_maximum_size = 0x00000000; |
| 55 | uint32_t fru_table_length = 0x00000000; |
| 56 | uint16_t total_record_set_identifiers = 0x0000; |
| 57 | uint16_t total_table_records = 0x0000; |
| 58 | uint32_t checksum = 0x00000000; |
| 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); |
| 66 | ASSERT_EQ(fru_data_major_version, 0x12); |
| 67 | ASSERT_EQ(fru_data_minor_version, 0x21); |
| 68 | ASSERT_EQ(fru_table_maximum_size, 0x1234ABCD); |
| 69 | ASSERT_EQ(fru_table_length, 0x56781234); |
| 70 | ASSERT_EQ(total_record_set_identifiers, 0x34EF); |
| 71 | ASSERT_EQ(total_table_records, 0xEEEF); |
| 72 | ASSERT_EQ(checksum, 0x6543FA71); |
| 73 | |
| 74 | response->fru_data_major_version = 0x00; |
| 75 | response->fru_data_minor_version = 0x00; |
| 76 | response->fru_table_maximum_size = 0x00000000; |
| 77 | response->fru_table_length = 0x00000000; |
| 78 | response->total_record_set_identifiers = 0x0000; |
| 79 | response->total_table_records = 0x0000; |
| 80 | response->checksum = 0x00000000; |
| 81 | fru_data_major_version = 0x00; |
| 82 | fru_data_minor_version = 0x00; |
| 83 | fru_table_maximum_size = 0x00000000; |
| 84 | fru_table_length = 0x00000000; |
| 85 | total_record_set_identifiers = 0x0000; |
| 86 | total_table_records = 0x0000; |
| 87 | checksum = 0x00000000; |
| 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); |
| 95 | ASSERT_EQ(responsePtr->hdr.instance_id, 0); |
| 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); |
| 99 | ASSERT_EQ(fru_data_major_version, 0x00); |
| 100 | ASSERT_EQ(fru_data_minor_version, 0x00); |
| 101 | ASSERT_EQ(fru_table_maximum_size, 0x00000000); |
| 102 | ASSERT_EQ(fru_table_length, 0x00000000); |
| 103 | ASSERT_EQ(total_record_set_identifiers, 0x0000); |
| 104 | ASSERT_EQ(total_table_records, 0x0000); |
| 105 | ASSERT_EQ(checksum, 0x00000000); |
| 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; |
| 120 | response->fru_table_maximum_size = 0x1234ABCD; |
| 121 | response->fru_table_length = 0x56781234; |
| 122 | response->total_record_set_identifiers = 0x34EF; |
| 123 | response->total_table_records = 0xEEEF; |
| 124 | response->checksum = 0x6543FA71; |
| 125 | |
| 126 | uint8_t completion_code = 0xFF; |
| 127 | uint8_t fru_data_major_version = 0x00; |
| 128 | uint8_t fru_data_minor_version = 0x00; |
| 129 | uint32_t fru_table_maximum_size = 0x00000000; |
| 130 | uint32_t fru_table_length = 0x00000000; |
| 131 | uint16_t total_record_set_identifiers = 0x0000; |
| 132 | uint16_t total_table_records = 0x0000; |
| 133 | uint32_t checksum = 0x00000000; |
| 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; |
| 201 | uint32_t fru_table_maximum_size = 0x1234ABCD; |
| 202 | uint32_t fru_table_length = 0x56781234; |
| 203 | uint16_t total_record_set_identifiers = 0x34EF; |
| 204 | uint16_t total_table_records = 0xEEEF; |
| 205 | uint32_t checksum = 0x6543FA71; |
| 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); |
| 217 | ASSERT_EQ(responsePtr->hdr.instance_id, 0); |
| 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); |
| 221 | ASSERT_EQ(response->fru_data_major_version, 0x12); |
| 222 | ASSERT_EQ(response->fru_data_minor_version, 0x21); |
| 223 | ASSERT_EQ(response->fru_table_maximum_size, 0x1234ABCD); |
| 224 | ASSERT_EQ(response->fru_table_length, 0x56781234); |
| 225 | ASSERT_EQ(response->total_record_set_identifiers, 0x34EF); |
| 226 | ASSERT_EQ(response->total_table_records, 0xEEEF); |
| 227 | ASSERT_EQ(response->checksum, 0x6543FA71); |
| 228 | |
| 229 | response->fru_data_major_version = 0; |
| 230 | response->fru_data_major_version = 0x00; |
| 231 | response->fru_data_minor_version = 0x00; |
| 232 | response->fru_table_maximum_size = 0x00000000; |
| 233 | response->fru_table_length = 0x00000000; |
| 234 | response->total_record_set_identifiers = 0x0000; |
| 235 | response->total_table_records = 0x0000; |
| 236 | response->checksum = 0x00000000; |
| 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); |
| 245 | ASSERT_EQ(responsePtr->hdr.instance_id, 0); |
| 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); |
| 249 | ASSERT_EQ(response->fru_data_major_version, 0x00); |
| 250 | ASSERT_EQ(response->fru_data_minor_version, 0x00); |
| 251 | ASSERT_EQ(response->fru_table_maximum_size, 0x00000000); |
| 252 | ASSERT_EQ(response->fru_table_length, 0x00000000); |
| 253 | ASSERT_EQ(response->total_record_set_identifiers, 0x0000); |
| 254 | ASSERT_EQ(response->total_table_records, 0x0000); |
| 255 | ASSERT_EQ(response->checksum, 0x00000000); |
| 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; |
| 268 | uint32_t fru_table_maximum_size = 0x1234ABCD; |
| 269 | uint32_t fru_table_length = 0x56781234; |
| 270 | uint16_t total_record_set_identifiers = 0x34EF; |
| 271 | uint16_t total_table_records = 0xEEEF; |
| 272 | uint32_t checksum = 0x6543FA71; |
| 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); |
| 284 | ASSERT_EQ(response->fru_data_major_version, 0x00); |
| 285 | ASSERT_EQ(response->fru_data_minor_version, 0x00); |
| 286 | ASSERT_EQ(response->fru_table_maximum_size, 0x00000000); |
| 287 | ASSERT_EQ(response->fru_table_length, 0x00000000); |
| 288 | ASSERT_EQ(response->total_record_set_identifiers, 0x0000); |
| 289 | ASSERT_EQ(response->total_table_records, 0x0000); |
| 290 | ASSERT_EQ(response->checksum, 0x00000000); |
| 291 | } |