blob: 8a3850cec5b31c6ca494fd30a02f379d9f3a1068 [file] [log] [blame]
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +05301#include <string.h>
2
3#include <array>
John Wang9fa87cf2020-06-10 17:53:40 +08004#include <cstring>
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +05305
6#include "libpldm/base.h"
7#include "libpldm/fru.h"
8
9#include <gtest/gtest.h>
10
11TEST(GetFruRecordTableMetadata, testGoodEncodeRequest)
12{
13 std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
14 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
Christian Geddes3bdb3c22020-05-01 14:55:39 -050015 auto rc = encode_get_fru_record_table_metadata_req(
16 0, requestPtr, PLDM_GET_FRU_RECORD_TABLE_METADATA_REQ_BYTES);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053017 ASSERT_EQ(rc, PLDM_SUCCESS);
18 ASSERT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
crgeddes2550cee2020-05-05 17:51:28 +000019 ASSERT_EQ(requestPtr->hdr.instance_id, 0u);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053020 ASSERT_EQ(requestPtr->hdr.type, PLDM_FRU);
21 ASSERT_EQ(requestPtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE_METADATA);
22}
23
24TEST(GetFruRecordTableMetadata, testBadEncodeRequest)
25{
Christian Geddes3bdb3c22020-05-01 14:55:39 -050026 auto rc = encode_get_fru_record_table_metadata_req(0, NULL, 0);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053027 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
Christian Geddes3bdb3c22020-05-01 14:55:39 -050028 std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
29 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
30 rc = encode_get_fru_record_table_metadata_req(0, requestPtr, 1);
31 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053032}
33
34TEST(GetFruRecordTableMetadata, testGoodDecodeResponse)
35{
36
37 std::vector<uint8_t> responseMsg(
38 sizeof(pldm_msg_hdr) + PLDM_GET_FRU_RECORD_TABLE_METADATA_RESP_BYTES);
39 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
40 size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
41 auto response = reinterpret_cast<pldm_get_fru_record_table_metadata_resp*>(
42 responsePtr->payload);
43
44 responsePtr->hdr.request = PLDM_RESPONSE;
45 responsePtr->hdr.instance_id = 0;
46 responsePtr->hdr.type = PLDM_FRU;
47 responsePtr->hdr.command = PLDM_GET_FRU_RECORD_TABLE_METADATA;
48 response->completion_code = PLDM_SUCCESS;
49 response->fru_data_major_version = 0x12;
50 response->fru_data_minor_version = 0x21;
Lei YU7cfeb8e2020-02-27 18:24:18 +080051 response->fru_table_maximum_size = htole32(0x1234ABCD);
52 response->fru_table_length = htole32(0x56781234);
53 response->total_record_set_identifiers = htole16(0x34EF);
54 response->total_table_records = htole16(0xEEEF);
55 response->checksum = htole32(0x6543FA71);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053056
57 uint8_t completion_code = 0xFF;
58 uint8_t fru_data_major_version = 0x00;
59 uint8_t fru_data_minor_version = 0x00;
Lei YU7cfeb8e2020-02-27 18:24:18 +080060 uint32_t fru_table_maximum_size = htole32(0x00000000);
61 uint32_t fru_table_length = htole32(0x00000000);
62 uint16_t total_record_set_identifiers = htole16(0x0000);
63 uint16_t total_table_records = htole16(0x0000);
64 uint32_t checksum = htole32(0x00000000);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053065
66 auto rc = decode_get_fru_record_table_metadata_resp(
67 responsePtr, payload_length, &completion_code, &fru_data_major_version,
68 &fru_data_minor_version, &fru_table_maximum_size, &fru_table_length,
69 &total_record_set_identifiers, &total_table_records, &checksum);
70 ASSERT_EQ(rc, PLDM_SUCCESS);
71 ASSERT_EQ(completion_code, PLDM_SUCCESS);
crgeddes2550cee2020-05-05 17:51:28 +000072 ASSERT_EQ(fru_data_major_version, 0x12u);
73 ASSERT_EQ(fru_data_minor_version, 0x21u);
74 ASSERT_EQ(fru_table_maximum_size, 0x1234ABCDu);
75 ASSERT_EQ(fru_table_length, 0x56781234u);
76 ASSERT_EQ(total_record_set_identifiers, 0x34EFu);
77 ASSERT_EQ(total_table_records, 0xEEEFu);
78 ASSERT_EQ(checksum, 0x6543FA71u);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053079
80 response->fru_data_major_version = 0x00;
81 response->fru_data_minor_version = 0x00;
Lei YU7cfeb8e2020-02-27 18:24:18 +080082 response->fru_table_maximum_size = htole32(0x00000000);
83 response->fru_table_length = htole32(0x00000000);
84 response->total_record_set_identifiers = htole16(0x0000);
85 response->total_table_records = htole16(0x0000);
86 response->checksum = htole32(0x00000000);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053087 fru_data_major_version = 0x00;
88 fru_data_minor_version = 0x00;
Lei YU7cfeb8e2020-02-27 18:24:18 +080089 fru_table_maximum_size = htole32(0x00000000);
90 fru_table_length = htole32(0x00000000);
91 total_record_set_identifiers = htole16(0x0000);
92 total_table_records = htole16(0x0000);
93 checksum = htole32(0x00000000);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053094 response->completion_code = PLDM_ERROR_INVALID_LENGTH;
95 rc = decode_get_fru_record_table_metadata_resp(
96 responsePtr, payload_length, &completion_code, &fru_data_major_version,
97 &fru_data_minor_version, &fru_table_maximum_size, &fru_table_length,
98 &total_record_set_identifiers, &total_table_records, &checksum);
99 ASSERT_EQ(rc, PLDM_SUCCESS);
100 ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE);
crgeddes2550cee2020-05-05 17:51:28 +0000101 ASSERT_EQ(responsePtr->hdr.instance_id, 0u);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530102 ASSERT_EQ(responsePtr->hdr.type, PLDM_FRU);
103 ASSERT_EQ(responsePtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE_METADATA);
104 ASSERT_EQ(completion_code, PLDM_ERROR_INVALID_LENGTH);
crgeddes2550cee2020-05-05 17:51:28 +0000105 ASSERT_EQ(fru_data_major_version, 0x00u);
106 ASSERT_EQ(fru_data_minor_version, 0x00u);
107 ASSERT_EQ(fru_table_maximum_size, 0x00000000u);
108 ASSERT_EQ(fru_table_length, 0x00000000u);
109 ASSERT_EQ(total_record_set_identifiers, 0x0000u);
110 ASSERT_EQ(total_table_records, 0x0000u);
111 ASSERT_EQ(checksum, 0x00000000u);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530112}
113
114TEST(GetFruRecordTableMetadata, testBadDecodeResponse)
115{
116 std::vector<uint8_t> responseMsg(
117 sizeof(pldm_msg_hdr) + PLDM_GET_FRU_RECORD_TABLE_METADATA_RESP_BYTES);
118 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
119 size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
120 auto response = reinterpret_cast<pldm_get_fru_record_table_metadata_resp*>(
121 responsePtr->payload);
122
123 response->completion_code = PLDM_SUCCESS;
124 response->fru_data_major_version = 0x12;
125 response->fru_data_minor_version = 0x21;
Lei YU7cfeb8e2020-02-27 18:24:18 +0800126 response->fru_table_maximum_size = htole32(0x1234ABCD);
127 response->fru_table_length = htole32(0x56781234);
128 response->total_record_set_identifiers = htole16(0x34EF);
129 response->total_table_records = htole16(0xEEEF);
130 response->checksum = htole32(0x6543FA71);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530131
132 uint8_t completion_code = 0xFF;
133 uint8_t fru_data_major_version = 0x00;
134 uint8_t fru_data_minor_version = 0x00;
Lei YU7cfeb8e2020-02-27 18:24:18 +0800135 uint32_t fru_table_maximum_size = htole32(0x00000000);
136 uint32_t fru_table_length = htole32(0x00000000);
137 uint16_t total_record_set_identifiers = htole16(0x0000);
138 uint16_t total_table_records = htole16(0x0000);
139 uint32_t checksum = htole32(0x00000000);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530140
141 auto rc = decode_get_fru_record_table_metadata_resp(
142 responsePtr, PLDM_GET_FRU_RECORD_TABLE_METADATA_RESP_BYTES + 2,
143 &completion_code, &fru_data_major_version, &fru_data_minor_version,
144 &fru_table_maximum_size, &fru_table_length,
145 &total_record_set_identifiers, &total_table_records, &checksum);
146 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
147
148 rc = decode_get_fru_record_table_metadata_resp(
149 responsePtr, payload_length, &completion_code, NULL,
150 &fru_data_minor_version, &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 NULL, &fru_table_maximum_size, &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, NULL, &fru_table_length,
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, NULL,
169 &total_record_set_identifiers, &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 NULL, &total_table_records, &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, NULL, &checksum);
182 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
183
184 rc = decode_get_fru_record_table_metadata_resp(
185 responsePtr, payload_length, &completion_code, &fru_data_major_version,
186 &fru_data_minor_version, &fru_table_maximum_size, &fru_table_length,
187 &total_record_set_identifiers, &total_table_records, NULL);
188 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
189}
190
191TEST(GetFruRecordTableMetadata, testGoodEncodeResponse)
192{
193
194 std::array<uint8_t, sizeof(pldm_msg_hdr) +
195 PLDM_GET_FRU_RECORD_TABLE_METADATA_RESP_BYTES>
196 responseMsg{};
197 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
198
199 responsePtr->hdr.request = PLDM_RESPONSE;
200 responsePtr->hdr.instance_id = 0;
201 responsePtr->hdr.type = PLDM_FRU;
202 responsePtr->hdr.command = PLDM_GET_FRU_RECORD_TABLE_METADATA;
203
204 uint8_t completion_code = PLDM_SUCCESS;
205 uint8_t fru_data_major_version = 0x12;
206 uint8_t fru_data_minor_version = 0x21;
Lei YU7cfeb8e2020-02-27 18:24:18 +0800207 uint32_t fru_table_maximum_size = htole32(0x1234ABCD);
208 uint32_t fru_table_length = htole32(0x56781234);
209 uint16_t total_record_set_identifiers = htole16(0x34EF);
210 uint16_t total_table_records = htole16(0xEEEF);
211 uint32_t checksum = htole32(0x6543FA71);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530212
213 auto rc = encode_get_fru_record_table_metadata_resp(
214 0, completion_code, fru_data_major_version, fru_data_minor_version,
215 fru_table_maximum_size, fru_table_length, total_record_set_identifiers,
216 total_table_records, checksum, responsePtr);
217
218 auto response = reinterpret_cast<pldm_get_fru_record_table_metadata_resp*>(
219 responsePtr->payload);
220
221 ASSERT_EQ(rc, PLDM_SUCCESS);
222 ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE);
crgeddes2550cee2020-05-05 17:51:28 +0000223 ASSERT_EQ(responsePtr->hdr.instance_id, 0u);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530224 ASSERT_EQ(responsePtr->hdr.type, PLDM_FRU);
225 ASSERT_EQ(responsePtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE_METADATA);
226 ASSERT_EQ(response->completion_code, PLDM_SUCCESS);
crgeddes2550cee2020-05-05 17:51:28 +0000227 ASSERT_EQ(response->fru_data_major_version, 0x12u);
228 ASSERT_EQ(response->fru_data_minor_version, 0x21u);
229 ASSERT_EQ(response->fru_table_maximum_size, 0x1234ABCDu);
230 ASSERT_EQ(response->fru_table_length, 0x56781234u);
231 ASSERT_EQ(response->total_record_set_identifiers, 0x34EFu);
232 ASSERT_EQ(response->total_table_records, 0xEEEFu);
233 ASSERT_EQ(response->checksum, 0x6543FA71u);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530234
235 response->fru_data_major_version = 0;
236 response->fru_data_major_version = 0x00;
237 response->fru_data_minor_version = 0x00;
Lei YU7cfeb8e2020-02-27 18:24:18 +0800238 response->fru_table_maximum_size = htole32(0x00000000);
239 response->fru_table_length = htole32(0x00000000);
240 response->total_record_set_identifiers = htole16(0x0000);
241 response->total_table_records = htole16(0x0000);
242 response->checksum = htole32(0x00000000);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530243 completion_code = PLDM_ERROR_INVALID_DATA;
244 rc = encode_get_fru_record_table_metadata_resp(
245 0, completion_code, fru_data_major_version, fru_data_minor_version,
246 fru_table_maximum_size, fru_table_length, total_record_set_identifiers,
247 total_table_records, checksum, responsePtr);
248
249 ASSERT_EQ(rc, PLDM_SUCCESS);
250 ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE);
crgeddes2550cee2020-05-05 17:51:28 +0000251 ASSERT_EQ(responsePtr->hdr.instance_id, 0u);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530252 ASSERT_EQ(responsePtr->hdr.type, PLDM_FRU);
253 ASSERT_EQ(responsePtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE_METADATA);
254 ASSERT_EQ(completion_code, PLDM_ERROR_INVALID_DATA);
crgeddes2550cee2020-05-05 17:51:28 +0000255 ASSERT_EQ(response->fru_data_major_version, 0x00u);
256 ASSERT_EQ(response->fru_data_minor_version, 0x00u);
257 ASSERT_EQ(response->fru_table_maximum_size, 0x00000000u);
258 ASSERT_EQ(response->fru_table_length, 0x00000000u);
259 ASSERT_EQ(response->total_record_set_identifiers, 0x0000u);
260 ASSERT_EQ(response->total_table_records, 0x0000u);
261 ASSERT_EQ(response->checksum, 0x00000000u);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530262}
263
264TEST(GetFruRecordTableMetadata, testBadEncodeResponse)
265{
266 std::array<uint8_t, sizeof(pldm_msg_hdr) +
267 PLDM_GET_FRU_RECORD_TABLE_METADATA_RESP_BYTES>
268 responseMsg{};
269 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
270
271 uint8_t completion_code = PLDM_SUCCESS;
272 uint8_t fru_data_major_version = 0x12;
273 uint8_t fru_data_minor_version = 0x21;
Lei YU7cfeb8e2020-02-27 18:24:18 +0800274 uint32_t fru_table_maximum_size = htole32(0x1234ABCD);
275 uint32_t fru_table_length = htole32(0x56781234);
276 uint16_t total_record_set_identifiers = htole16(0x34EF);
277 uint16_t total_table_records = htole16(0xEEEF);
278 uint32_t checksum = htole32(0x6543FA71);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530279
280 auto rc = encode_get_fru_record_table_metadata_resp(
281 0, completion_code, fru_data_major_version, fru_data_minor_version,
282 fru_table_maximum_size, fru_table_length, total_record_set_identifiers,
283 total_table_records, checksum, NULL);
284
285 auto response = reinterpret_cast<pldm_get_fru_record_table_metadata_resp*>(
286 responsePtr->payload);
287
288 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
289 ASSERT_EQ(completion_code, PLDM_SUCCESS);
crgeddes2550cee2020-05-05 17:51:28 +0000290 ASSERT_EQ(response->fru_data_major_version, 0x00u);
291 ASSERT_EQ(response->fru_data_minor_version, 0x00u);
292 ASSERT_EQ(response->fru_table_maximum_size, 0x00000000u);
293 ASSERT_EQ(response->fru_table_length, 0x00000000u);
294 ASSERT_EQ(response->total_record_set_identifiers, 0x0000u);
295 ASSERT_EQ(response->total_table_records, 0x0000u);
296 ASSERT_EQ(response->checksum, 0x00000000u);
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +0530297}
PriyangaRamasamy497665a2019-07-30 12:48:25 +0530298
299TEST(GetFruRecordTable, testGoodDecodeRequest)
300{
301 uint32_t data_transfer_handle = 31;
302 uint8_t transfer_operation_flag = PLDM_GET_FIRSTPART;
303 std::array<uint8_t,
304 PLDM_GET_FRU_RECORD_TABLE_REQ_BYTES + sizeof(pldm_msg_hdr)>
305 requestMsg{};
306 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
307 size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
308 auto request =
309 reinterpret_cast<pldm_get_fru_record_table_req*>(requestPtr->payload);
310
Lei YU90ff3ed2020-03-02 11:16:51 +0800311 request->data_transfer_handle = htole32(data_transfer_handle);
PriyangaRamasamy497665a2019-07-30 12:48:25 +0530312 request->transfer_operation_flag = transfer_operation_flag;
313
314 uint32_t ret_data_transfer_handle = 0;
315 uint8_t ret_transfer_operation_flag = 0;
316
317 // Invoke decode get FRU record table request api
318 auto rc = decode_get_fru_record_table_req(requestPtr, payload_length,
319 &ret_data_transfer_handle,
320 &ret_transfer_operation_flag);
321
322 ASSERT_EQ(rc, PLDM_SUCCESS);
323 ASSERT_EQ(data_transfer_handle, ret_data_transfer_handle);
324 ASSERT_EQ(transfer_operation_flag, ret_transfer_operation_flag);
325}
326
327TEST(GetFruRecordTable, testBadDecodeRequest)
328{
329 uint32_t data_transfer_handle = 0x0;
330 uint8_t transfer_operation_flag = PLDM_GET_FIRSTPART;
331
332 std::array<uint8_t,
333 sizeof(pldm_msg_hdr) + PLDM_GET_FRU_RECORD_TABLE_REQ_BYTES>
334 requestMsg{};
335 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
336
337 // Payload message is missing
338 auto rc = decode_get_fru_record_table_req(NULL, 0, &data_transfer_handle,
339 &transfer_operation_flag);
340 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
341
342 // Payload length is invalid
343 rc = decode_get_fru_record_table_req(requestPtr, 0, &data_transfer_handle,
344 &transfer_operation_flag);
345 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
346}
347
348TEST(GetFruRecordTable, testGoodEncodeResponse)
349{
350 uint8_t completion_code = 0;
351 uint32_t next_data_transfer_handle = 32;
352 uint8_t transfer_flag = PLDM_START_AND_END;
353
354 std::vector<uint8_t> responseMsg(sizeof(pldm_msg_hdr) +
355 PLDM_GET_FRU_RECORD_TABLE_MIN_RESP_BYTES);
356
357 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
358 auto response =
359 reinterpret_cast<pldm_get_fru_record_table_resp*>(responsePtr->payload);
360
361 // Invoke encode get FRU record table response api
362 auto rc = encode_get_fru_record_table_resp(0, completion_code,
363 next_data_transfer_handle,
364 transfer_flag, responsePtr);
365
366 ASSERT_EQ(rc, PLDM_SUCCESS);
367 ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE);
crgeddes2550cee2020-05-05 17:51:28 +0000368 ASSERT_EQ(responsePtr->hdr.instance_id, 0u);
PriyangaRamasamy497665a2019-07-30 12:48:25 +0530369 ASSERT_EQ(responsePtr->hdr.type, PLDM_FRU);
370 ASSERT_EQ(responsePtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE);
371 ASSERT_EQ(response->completion_code, PLDM_SUCCESS);
Lei YU90ff3ed2020-03-02 11:16:51 +0800372 ASSERT_EQ(le32toh(response->next_data_transfer_handle),
373 next_data_transfer_handle);
PriyangaRamasamy497665a2019-07-30 12:48:25 +0530374 ASSERT_EQ(response->transfer_flag, transfer_flag);
375}
376
377TEST(GetFruRecordTable, testBadEncodeResponse)
378{
379 uint32_t next_data_transfer_handle = 32;
380 uint8_t transfer_flag = PLDM_START_AND_END;
381
382 std::vector<uint8_t> responseMsg(sizeof(pldm_msg_hdr) +
383 PLDM_GET_FRU_RECORD_TABLE_MIN_RESP_BYTES);
384
385 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
386 auto rc = encode_get_fru_record_table_resp(
387 0, PLDM_ERROR, next_data_transfer_handle, transfer_flag, responsePtr);
388
389 ASSERT_EQ(rc, PLDM_SUCCESS);
390 ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE);
crgeddes2550cee2020-05-05 17:51:28 +0000391 ASSERT_EQ(responsePtr->hdr.instance_id, 0u);
PriyangaRamasamy497665a2019-07-30 12:48:25 +0530392 ASSERT_EQ(responsePtr->hdr.type, PLDM_FRU);
393 ASSERT_EQ(responsePtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE);
394 ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR);
395
396 rc = encode_get_fru_record_table_resp(
397 0, PLDM_SUCCESS, next_data_transfer_handle, transfer_flag, nullptr);
398
399 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
400}
PriyangaRamasamyf3295be2019-07-23 12:18:40 +0530401
402TEST(GetFruRecordTable, testGoodEncodeRequest)
403
404{
405 std::array<uint8_t,
406 sizeof(pldm_msg_hdr) + PLDM_GET_FRU_RECORD_TABLE_REQ_BYTES>
407 requestMsg{};
408
409 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
410 auto request =
411 reinterpret_cast<pldm_get_fru_record_table_req*>(requestPtr->payload);
412
413 // Random value for data transfer handle and transfer operation flag
414 uint32_t data_transfer_handle = 32;
415 uint8_t transfer_operation_flag = PLDM_GET_FIRSTPART;
416
417 // Invoke encode get FRU record table request api
418 auto rc = encode_get_fru_record_table_req(
419 0, data_transfer_handle, transfer_operation_flag, requestPtr,
420 requestMsg.size() - sizeof(pldm_msg_hdr));
421
422 ASSERT_EQ(rc, PLDM_SUCCESS);
423 ASSERT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
crgeddes2550cee2020-05-05 17:51:28 +0000424 ASSERT_EQ(requestPtr->hdr.instance_id, 0u);
PriyangaRamasamyf3295be2019-07-23 12:18:40 +0530425 ASSERT_EQ(requestPtr->hdr.type, PLDM_FRU);
426 ASSERT_EQ(requestPtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE);
427 ASSERT_EQ(le32toh(data_transfer_handle), request->data_transfer_handle);
428 ASSERT_EQ(transfer_operation_flag, request->transfer_operation_flag);
429}
430
431TEST(GetFruRecordTable, testBadEncodeRequest)
432
433{
434 uint32_t data_transfer_handle = 0x0;
435 uint8_t transfer_operation_flag = PLDM_GET_FIRSTPART;
436
437 std::array<uint8_t,
438 sizeof(pldm_msg_hdr) + PLDM_GET_FRU_RECORD_TABLE_REQ_BYTES>
439 requestMsg{};
440 auto rc = encode_get_fru_record_table_req(
441 0, data_transfer_handle, transfer_operation_flag, NULL,
442 requestMsg.size() - sizeof(pldm_msg_hdr));
443
444 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
445}
446
447TEST(GetFruRecordTable, testGoodDecodeResponse)
448{
449 uint8_t completion_code = PLDM_SUCCESS;
450 uint32_t next_data_transfer_handle = 0x16;
451 uint8_t transfer_flag = PLDM_START_AND_END;
452 std::vector<uint8_t> fru_record_table_data = {1, 2, 3, 4, 5, 6, 7, 8, 9};
453
454 std::vector<uint8_t> responseMsg(sizeof(pldm_msg_hdr) +
455 PLDM_GET_FRU_RECORD_TABLE_MIN_RESP_BYTES +
456 fru_record_table_data.size());
457
458 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
459 size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
460 auto response =
461 reinterpret_cast<pldm_get_fru_record_table_resp*>(responsePtr->payload);
462
463 response->completion_code = completion_code;
464 response->next_data_transfer_handle = htole32(next_data_transfer_handle);
465 response->transfer_flag = transfer_flag;
466 memcpy(response->fru_record_table_data, fru_record_table_data.data(),
467 fru_record_table_data.size());
468
469 uint8_t ret_completion_code = 0;
470 uint32_t ret_next_data_transfer_handle = 0;
471 uint8_t ret_transfer_flag = 0;
472 std::vector<uint8_t> ret_fru_record_table_data(9, 0);
473 size_t ret_fru_record_table_length = 0;
474
475 // Invoke decode get FRU record table response api
476 auto rc = decode_get_fru_record_table_resp(
477 responsePtr, payload_length, &ret_completion_code,
478 &ret_next_data_transfer_handle, &ret_transfer_flag,
479 ret_fru_record_table_data.data(), &ret_fru_record_table_length);
480 ASSERT_EQ(rc, PLDM_SUCCESS);
481 ASSERT_EQ(completion_code, ret_completion_code);
482 ASSERT_EQ(next_data_transfer_handle, ret_next_data_transfer_handle);
483 ASSERT_EQ(transfer_flag, ret_transfer_flag);
484 ASSERT_EQ(0, memcmp(fru_record_table_data.data(),
485 ret_fru_record_table_data.data(),
486 ret_fru_record_table_length));
487 ASSERT_EQ(fru_record_table_data.size(), ret_fru_record_table_length);
488}
489
490TEST(GetFruRecordTable, testBadDecodeResponse)
491{
492 uint8_t completion_code = 0;
493 uint32_t next_data_transfer_handle = 0;
494 uint8_t transfer_flag = PLDM_START_AND_END;
495 std::vector<uint8_t> fru_record_table_data(9, 0);
496 size_t fru_record_table_length = 0;
497
498 std::vector<uint8_t> responseMsg(sizeof(pldm_msg_hdr) +
499 PLDM_GET_FRU_RECORD_TABLE_MIN_RESP_BYTES +
500 fru_record_table_data.size());
501
502 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
503
504 // Payload message is missing
505 auto rc = decode_get_fru_record_table_resp(
506 NULL, 0, &completion_code, &next_data_transfer_handle, &transfer_flag,
507 fru_record_table_data.data(), &fru_record_table_length);
508
509 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
510
511 // Payload length is invalid
512 rc = decode_get_fru_record_table_resp(
513 responsePtr, 0, &completion_code, &next_data_transfer_handle,
514 &transfer_flag, fru_record_table_data.data(), &fru_record_table_length);
515
516 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
517}
John Wang9fa87cf2020-06-10 17:53:40 +0800518
519TEST(GetFRURecordByOption, testGoodEncodeRequest)
520{
521 uint8_t instanceId = 2;
522 uint32_t dataTransferHandle = 3;
523 uint16_t fruTableHandle = 4;
524 uint16_t recordSetIdentifier = 5;
525 uint8_t recordType = 6;
526 uint8_t fieldType = 7;
527 uint8_t transferOpFlag = 0;
528
529 constexpr auto payLoadLength = sizeof(pldm_get_fru_record_by_option_req);
530
531 std::array<uint8_t, sizeof(pldm_msg_hdr) + payLoadLength> request;
532 auto reqMsg = reinterpret_cast<pldm_msg*>(request.data());
533
534 auto rc = encode_get_fru_record_by_option_req(
535 instanceId, dataTransferHandle, fruTableHandle, recordSetIdentifier,
536 recordType, fieldType, transferOpFlag, reqMsg, payLoadLength);
537
538 EXPECT_EQ(rc, PLDM_SUCCESS);
539 EXPECT_EQ(instanceId, reqMsg->hdr.instance_id);
540
541 auto payLoadMsg =
542 reinterpret_cast<pldm_get_fru_record_by_option_req*>(reqMsg->payload);
543
544 EXPECT_EQ(le32toh(payLoadMsg->data_transfer_handle), dataTransferHandle);
545 EXPECT_EQ(le16toh(payLoadMsg->fru_table_handle), fruTableHandle);
546 EXPECT_EQ(le16toh(payLoadMsg->record_set_identifier), recordSetIdentifier);
547 EXPECT_EQ(payLoadMsg->record_type, recordType);
548 EXPECT_EQ(payLoadMsg->field_type, fieldType);
549 EXPECT_EQ(payLoadMsg->transfer_op_flag, transferOpFlag);
550}
551
552TEST(GetFRURecordByOption, testBadEncodeRequest)
553{
554
555 constexpr auto payLoadLength = sizeof(pldm_get_fru_record_by_option_req);
556
557 auto rc = encode_get_fru_record_by_option_req(1, 2, 3, 4, 5, 6, 0, nullptr,
558 payLoadLength);
559
560 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
561 std::array<uint8_t, sizeof(pldm_msg_hdr) + payLoadLength> request;
562 auto reqMsg = reinterpret_cast<pldm_msg*>(request.data());
563
564 rc = encode_get_fru_record_by_option_req(1, 2, 3, 4, 5, 6, 0, reqMsg,
565 payLoadLength - 1);
566
567 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
568}
569
570TEST(GetFRURecordByOption, testGoodDecodeRequest)
571{
572 uint8_t instanceId = 2;
573 uint32_t dataTransferHandle = 3;
574 uint16_t fruTableHandle = 4;
575 uint16_t recordSetIdentifier = 5;
576 uint8_t recordType = 6;
577 uint8_t fieldType = 7;
578 uint8_t transferOpFlag = 0;
579
580 constexpr auto payLoadLength = sizeof(pldm_get_fru_record_by_option_req);
581
582 std::array<uint8_t, sizeof(pldm_msg_hdr) + payLoadLength> request;
583 auto reqMsg = reinterpret_cast<pldm_msg*>(request.data());
584
585 auto rc = encode_get_fru_record_by_option_req(
586 instanceId, dataTransferHandle, fruTableHandle, recordSetIdentifier,
587 recordType, fieldType, transferOpFlag, reqMsg, payLoadLength);
588
589 EXPECT_EQ(rc, PLDM_SUCCESS);
590
591 uint32_t retDataTransferHandle{};
592 uint16_t retFruTableHandle{};
593 uint16_t retRecordSetIdentifier{};
594 uint8_t retRecordType{};
595 uint8_t retFieldType{};
596 uint8_t retTransferOpFlag{};
597
598 rc = decode_get_fru_record_by_option_req(
599 reqMsg, payLoadLength, &retDataTransferHandle, &retFruTableHandle,
600 &retRecordSetIdentifier, &retRecordType, &retFieldType,
601 &retTransferOpFlag);
602
603 EXPECT_EQ(rc, PLDM_SUCCESS);
604 EXPECT_EQ(retDataTransferHandle, dataTransferHandle);
605 EXPECT_EQ(retFruTableHandle, fruTableHandle);
606 EXPECT_EQ(retRecordSetIdentifier, recordSetIdentifier);
607 EXPECT_EQ(retRecordType, recordType);
608 EXPECT_EQ(retFieldType, fieldType);
609 EXPECT_EQ(retTransferOpFlag, transferOpFlag);
610}
611
612TEST(GetFRURecordByOption, testBadDecodeRequest)
613{
614 constexpr auto payLoadLength = sizeof(pldm_get_fru_record_by_option_req);
Tom Josephcb0982b2021-06-14 22:01:31 -0700615 std::array<uint8_t, sizeof(pldm_msg_hdr) + payLoadLength> request{};
John Wang9fa87cf2020-06-10 17:53:40 +0800616 auto reqMsg = reinterpret_cast<pldm_msg*>(request.data());
617
618 uint32_t retDataTransferHandle{};
619 uint16_t retFruTableHandle{};
620 uint16_t retRecordSetIdentifier{};
621 uint8_t retRecordType{};
622 uint8_t retFieldType{};
623 uint8_t retTransferOpFlag{};
624
625 auto rc = decode_get_fru_record_by_option_req(
626 reqMsg, payLoadLength - 1, &retDataTransferHandle, &retFruTableHandle,
627 &retRecordSetIdentifier, &retRecordType, &retFieldType,
628 &retTransferOpFlag);
629
630 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
631
632 rc = decode_get_fru_record_by_option_req(
633 reqMsg, payLoadLength - 1, nullptr, &retFruTableHandle,
634 &retRecordSetIdentifier, &retRecordType, &retFieldType,
635 &retTransferOpFlag);
636
637 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
638}
639
640TEST(GetFruRecordByOption, testGoodEncodeResponse)
641{
642 uint8_t completionCode = PLDM_SUCCESS;
643 uint8_t instanceId = 2;
644 uint32_t dataTransferHandle = 3;
645 uint8_t transferFlag = 5;
646
647 std::array<uint8_t, 5> fruData = {1, 2, 3, 4, 5};
648 constexpr auto payLoadLength =
649 sizeof(pldm_get_fru_record_by_option_resp) - 1 + fruData.size();
650
651 std::array<uint8_t, sizeof(pldm_msg_hdr) + payLoadLength> response;
652 auto respMsg = reinterpret_cast<pldm_msg*>(response.data());
653
654 auto rc = encode_get_fru_record_by_option_resp(
655 instanceId, completionCode, dataTransferHandle, transferFlag,
656 fruData.data(), fruData.size(), respMsg, payLoadLength);
657
658 auto payLoadMsg =
659 reinterpret_cast<pldm_get_fru_record_by_option_resp*>(respMsg->payload);
660
661 EXPECT_EQ(rc, PLDM_SUCCESS);
662 EXPECT_EQ(payLoadMsg->completion_code, completionCode);
663 EXPECT_EQ(payLoadMsg->next_data_transfer_handle,
664 htole32(dataTransferHandle));
665 EXPECT_EQ(payLoadMsg->transfer_flag, transferFlag);
666
667 EXPECT_EQ(std::memcmp(payLoadMsg->fru_structure_data, fruData.data(),
668 fruData.size()),
669 0);
670}
671
672TEST(GetFruRecordByOption, testBadEncodeResponse)
673{
674 uint8_t completionCode = PLDM_SUCCESS;
675 uint8_t instanceId = 2;
676 uint32_t dataTransferHandle = 3;
677 uint8_t transferFlag = 5;
678
679 std::array<uint8_t, 5> fruData = {1, 2, 3, 4, 5};
680 constexpr auto payLoadLength =
681 sizeof(pldm_get_fru_record_by_option_resp) - 1 + fruData.size();
682
683 std::array<uint8_t, sizeof(pldm_msg_hdr) + payLoadLength> response;
684 auto respMsg = reinterpret_cast<pldm_msg*>(response.data());
685
686 auto rc = encode_get_fru_record_by_option_resp(
687 instanceId, completionCode, dataTransferHandle, transferFlag, nullptr,
688 fruData.size(), respMsg, payLoadLength);
689
690 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
691
692 rc = encode_get_fru_record_by_option_resp(
693 instanceId, completionCode, dataTransferHandle, transferFlag,
694 fruData.data(), fruData.size(), respMsg, payLoadLength - 1);
695
696 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
697}
698
699TEST(GetFruRecordByOption, testGoodDecodeResponse)
700{
701 uint8_t completionCode = PLDM_SUCCESS;
702 uint8_t instanceId = 2;
703 uint32_t dataTransferHandle = 3;
704 uint8_t transferFlag = 5;
705
706 std::array<uint8_t, 5> fruData = {1, 2, 3, 4, 5};
707 constexpr auto payLoadLength =
708 sizeof(pldm_get_fru_record_by_option_resp) - 1 + fruData.size();
709
710 std::array<uint8_t, sizeof(pldm_msg_hdr) + payLoadLength> response;
711 auto respMsg = reinterpret_cast<pldm_msg*>(response.data());
712
713 auto rc = encode_get_fru_record_by_option_resp(
714 instanceId, completionCode, dataTransferHandle, transferFlag,
715 fruData.data(), fruData.size(), respMsg, payLoadLength);
716
717 EXPECT_EQ(rc, PLDM_SUCCESS);
718
719 uint8_t retCompletionCode;
720 uint32_t retDataTransferHandle;
721 uint8_t retTransferFlag;
722 variable_field retFruData;
723
724 rc = decode_get_fru_record_by_option_resp(
725 respMsg, payLoadLength, &retCompletionCode, &retDataTransferHandle,
726 &retTransferFlag, &retFruData);
727
728 EXPECT_EQ(rc, PLDM_SUCCESS);
729 EXPECT_EQ(retCompletionCode, completionCode);
730 EXPECT_EQ(retDataTransferHandle, dataTransferHandle);
731 EXPECT_EQ(retTransferFlag, transferFlag);
732 EXPECT_EQ(retFruData.length, fruData.size());
733 EXPECT_EQ(std::memcmp(fruData.data(), retFruData.ptr, fruData.size()), 0);
734}
735
736TEST(GetFruRecordByOption, testBadDecodeResponse)
737{
738
739 uint8_t completionCode = PLDM_SUCCESS;
740 uint8_t instanceId = 2;
741 uint32_t dataTransferHandle = 3;
742 uint8_t transferFlag = 5;
743
744 std::array<uint8_t, 5> fruData = {1, 2, 3, 4, 5};
745 constexpr auto payLoadLength =
746 sizeof(pldm_get_fru_record_by_option_resp) - 1 + fruData.size();
747
748 std::array<uint8_t, sizeof(pldm_msg_hdr) + payLoadLength> response;
749 auto respMsg = reinterpret_cast<pldm_msg*>(response.data());
750
751 auto rc = encode_get_fru_record_by_option_resp(
752 instanceId, completionCode, dataTransferHandle, transferFlag,
753 fruData.data(), fruData.size(), respMsg, payLoadLength);
754
755 EXPECT_EQ(rc, PLDM_SUCCESS);
756
757 uint8_t retCompletionCode;
758 uint32_t retDataTransferHandle;
759 uint8_t retTransferFlag;
760 variable_field retFruData;
761
762 rc = decode_get_fru_record_by_option_resp(respMsg, payLoadLength, nullptr,
763 &retDataTransferHandle,
764 &retTransferFlag, &retFruData);
765
766 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
767
768 rc = decode_get_fru_record_by_option_resp(
769 respMsg, PLDM_GET_FRU_RECORD_BY_OPTION_MIN_RESP_BYTES - 1,
770 &retCompletionCode, &retDataTransferHandle, &retTransferFlag,
771 &retFruData);
772
773 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
774}