blob: 97177c0edf1dd367093d15686cdd851195dacf7e [file] [log] [blame]
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +05301#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
10TEST(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);
crgeddes2550cee2020-05-05 17:51:28 +000017 ASSERT_EQ(requestPtr->hdr.instance_id, 0u);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053018 ASSERT_EQ(requestPtr->hdr.type, PLDM_FRU);
19 ASSERT_EQ(requestPtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE_METADATA);
20}
21
22TEST(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
28TEST(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 YU7cfeb8e2020-02-27 18:24:18 +080045 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 Thomas8e92c6c2019-08-06 12:22:34 +053050
51 uint8_t completion_code = 0xFF;
52 uint8_t fru_data_major_version = 0x00;
53 uint8_t fru_data_minor_version = 0x00;
Lei YU7cfeb8e2020-02-27 18:24:18 +080054 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 Thomas8e92c6c2019-08-06 12:22:34 +053059
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);
crgeddes2550cee2020-05-05 17:51:28 +000066 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 Thomas8e92c6c2019-08-06 12:22:34 +053073
74 response->fru_data_major_version = 0x00;
75 response->fru_data_minor_version = 0x00;
Lei YU7cfeb8e2020-02-27 18:24:18 +080076 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 Thomas8e92c6c2019-08-06 12:22:34 +053081 fru_data_major_version = 0x00;
82 fru_data_minor_version = 0x00;
Lei YU7cfeb8e2020-02-27 18:24:18 +080083 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 Thomas8e92c6c2019-08-06 12:22:34 +053088 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);
crgeddes2550cee2020-05-05 17:51:28 +000095 ASSERT_EQ(responsePtr->hdr.instance_id, 0u);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053096 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);
crgeddes2550cee2020-05-05 17:51:28 +000099 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 Thomas8e92c6c2019-08-06 12:22:34 +0530106}
107
108TEST(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 YU7cfeb8e2020-02-27 18:24:18 +0800120 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 Thomas8e92c6c2019-08-06 12:22:34 +0530125
126 uint8_t completion_code = 0xFF;
127 uint8_t fru_data_major_version = 0x00;
128 uint8_t fru_data_minor_version = 0x00;
Lei YU7cfeb8e2020-02-27 18:24:18 +0800129 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 Thomas8e92c6c2019-08-06 12:22:34 +0530134
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
185TEST(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 YU7cfeb8e2020-02-27 18:24:18 +0800201 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 Thomas8e92c6c2019-08-06 12:22:34 +0530206
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);
crgeddes2550cee2020-05-05 17:51:28 +0000217 ASSERT_EQ(responsePtr->hdr.instance_id, 0u);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530218 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);
crgeddes2550cee2020-05-05 17:51:28 +0000221 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 Thomas8e92c6c2019-08-06 12:22:34 +0530228
229 response->fru_data_major_version = 0;
230 response->fru_data_major_version = 0x00;
231 response->fru_data_minor_version = 0x00;
Lei YU7cfeb8e2020-02-27 18:24:18 +0800232 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 Thomas8e92c6c2019-08-06 12:22:34 +0530237 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);
crgeddes2550cee2020-05-05 17:51:28 +0000245 ASSERT_EQ(responsePtr->hdr.instance_id, 0u);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530246 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);
crgeddes2550cee2020-05-05 17:51:28 +0000249 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 Thomas8e92c6c2019-08-06 12:22:34 +0530256}
257
258TEST(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 YU7cfeb8e2020-02-27 18:24:18 +0800268 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 Thomas8e92c6c2019-08-06 12:22:34 +0530273
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);
crgeddes2550cee2020-05-05 17:51:28 +0000284 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 Thomas8e92c6c2019-08-06 12:22:34 +0530291}
PriyangaRamasamy497665a2019-07-30 12:48:25 +0530292
293TEST(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 YU90ff3ed2020-03-02 11:16:51 +0800305 request->data_transfer_handle = htole32(data_transfer_handle);
PriyangaRamasamy497665a2019-07-30 12:48:25 +0530306 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
321TEST(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
342TEST(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);
crgeddes2550cee2020-05-05 17:51:28 +0000362 ASSERT_EQ(responsePtr->hdr.instance_id, 0u);
PriyangaRamasamy497665a2019-07-30 12:48:25 +0530363 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 YU90ff3ed2020-03-02 11:16:51 +0800366 ASSERT_EQ(le32toh(response->next_data_transfer_handle),
367 next_data_transfer_handle);
PriyangaRamasamy497665a2019-07-30 12:48:25 +0530368 ASSERT_EQ(response->transfer_flag, transfer_flag);
369}
370
371TEST(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);
crgeddes2550cee2020-05-05 17:51:28 +0000385 ASSERT_EQ(responsePtr->hdr.instance_id, 0u);
PriyangaRamasamy497665a2019-07-30 12:48:25 +0530386 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}
PriyangaRamasamyf3295be2019-07-23 12:18:40 +0530395
396TEST(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);
crgeddes2550cee2020-05-05 17:51:28 +0000418 ASSERT_EQ(requestPtr->hdr.instance_id, 0u);
PriyangaRamasamyf3295be2019-07-23 12:18:40 +0530419 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
425TEST(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
441TEST(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
484TEST(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}