blob: 7331771cd536f2f0fd60e7d1eafee9d2a1326023 [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);
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
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;
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
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;
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
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;
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
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;
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}
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
305 request->data_transfer_handle = data_transfer_handle;
306 request->transfer_operation_flag = transfer_operation_flag;
307
308 uint32_t ret_data_transfer_handle = 0;
309 uint8_t ret_transfer_operation_flag = 0;
310
311 // Invoke decode get FRU record table request api
312 auto rc = decode_get_fru_record_table_req(requestPtr, payload_length,
313 &ret_data_transfer_handle,
314 &ret_transfer_operation_flag);
315
316 ASSERT_EQ(rc, PLDM_SUCCESS);
317 ASSERT_EQ(data_transfer_handle, ret_data_transfer_handle);
318 ASSERT_EQ(transfer_operation_flag, ret_transfer_operation_flag);
319}
320
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);
362 ASSERT_EQ(responsePtr->hdr.instance_id, 0);
363 ASSERT_EQ(responsePtr->hdr.type, PLDM_FRU);
364 ASSERT_EQ(responsePtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE);
365 ASSERT_EQ(response->completion_code, PLDM_SUCCESS);
366 ASSERT_EQ(response->next_data_transfer_handle, next_data_transfer_handle);
367 ASSERT_EQ(response->transfer_flag, transfer_flag);
368}
369
370TEST(GetFruRecordTable, testBadEncodeResponse)
371{
372 uint32_t next_data_transfer_handle = 32;
373 uint8_t transfer_flag = PLDM_START_AND_END;
374
375 std::vector<uint8_t> responseMsg(sizeof(pldm_msg_hdr) +
376 PLDM_GET_FRU_RECORD_TABLE_MIN_RESP_BYTES);
377
378 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
379 auto rc = encode_get_fru_record_table_resp(
380 0, PLDM_ERROR, next_data_transfer_handle, transfer_flag, responsePtr);
381
382 ASSERT_EQ(rc, PLDM_SUCCESS);
383 ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE);
384 ASSERT_EQ(responsePtr->hdr.instance_id, 0);
385 ASSERT_EQ(responsePtr->hdr.type, PLDM_FRU);
386 ASSERT_EQ(responsePtr->hdr.command, PLDM_GET_FRU_RECORD_TABLE);
387 ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR);
388
389 rc = encode_get_fru_record_table_resp(
390 0, PLDM_SUCCESS, next_data_transfer_handle, transfer_flag, nullptr);
391
392 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
393}