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