blob: fcdbbf03f3b53ea7a3161cc94f25c2524ac029b3 [file] [log] [blame]
George Liu6492f522020-06-16 10:34:05 +08001#include "libpldm/base.h"
2#include "libpldm/file_io.h"
3
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +05304#include <string.h>
5
6#include <array>
7
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +05308#include <gtest/gtest.h>
9
Zahed Hossain223a73d2019-07-04 12:46:18 -050010constexpr auto hdrSize = sizeof(pldm_msg_hdr);
11
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053012TEST(ReadWriteFileMemory, testGoodDecodeRequest)
13{
Zahed Hossain223a73d2019-07-04 12:46:18 -050014 std::array<uint8_t, PLDM_RW_FILE_MEM_REQ_BYTES + hdrSize> requestMsg{};
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053015
16 // Random value for fileHandle, offset, length, address
17 uint32_t fileHandle = 0x12345678;
18 uint32_t offset = 0x87654321;
19 uint32_t length = 0x13245768;
20 uint64_t address = 0x124356879ACBDE0F;
Lei YU2d5c7452020-03-03 14:43:45 +080021 uint32_t fileHandleLe = htole32(fileHandle);
22 uint32_t offsetLe = htole32(offset);
23 uint32_t lengthLe = htole32(length);
24 uint64_t addressLe = htole64(address);
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053025
Lei YU2d5c7452020-03-03 14:43:45 +080026 memcpy(requestMsg.data() + hdrSize, &fileHandleLe, sizeof(fileHandleLe));
27 memcpy(requestMsg.data() + sizeof(fileHandleLe) + hdrSize, &offsetLe,
28 sizeof(offsetLe));
29 memcpy(requestMsg.data() + sizeof(fileHandleLe) + sizeof(offsetLe) +
30 hdrSize,
31 &lengthLe, sizeof(lengthLe));
32 memcpy(requestMsg.data() + sizeof(fileHandleLe) + sizeof(offsetLe) +
33 sizeof(lengthLe) + hdrSize,
34 &addressLe, sizeof(addressLe));
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053035
36 uint32_t retFileHandle = 0;
37 uint32_t retOffset = 0;
38 uint32_t retLength = 0;
39 uint64_t retAddress = 0;
40
Zahed Hossain223a73d2019-07-04 12:46:18 -050041 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
42
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053043 // Invoke decode the read file memory request
Zahed Hossain223a73d2019-07-04 12:46:18 -050044 auto rc = decode_rw_file_memory_req(request, requestMsg.size() - hdrSize,
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053045 &retFileHandle, &retOffset, &retLength,
46 &retAddress);
47
48 ASSERT_EQ(rc, PLDM_SUCCESS);
49 ASSERT_EQ(fileHandle, retFileHandle);
50 ASSERT_EQ(offset, retOffset);
51 ASSERT_EQ(length, retLength);
52 ASSERT_EQ(address, retAddress);
53}
54
55TEST(ReadWriteFileMemory, testBadDecodeRequest)
56{
57 uint32_t fileHandle = 0;
58 uint32_t offset = 0;
59 uint32_t length = 0;
60 uint64_t address = 0;
61
62 // Request payload message is missing
63 auto rc = decode_rw_file_memory_req(NULL, 0, &fileHandle, &offset, &length,
64 &address);
65 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
66
67 std::array<uint8_t, PLDM_RW_FILE_MEM_REQ_BYTES> requestMsg{};
68
Zahed Hossain223a73d2019-07-04 12:46:18 -050069 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
70
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053071 // Address is NULL
Zahed Hossain223a73d2019-07-04 12:46:18 -050072 rc = decode_rw_file_memory_req(request, requestMsg.size() - hdrSize,
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053073 &fileHandle, &offset, &length, NULL);
74 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
75
76 // Payload length is invalid
Zahed Hossain223a73d2019-07-04 12:46:18 -050077 rc = decode_rw_file_memory_req(request, 0, &fileHandle, &offset, &length,
78 &address);
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053079 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
80}
81
82TEST(ReadWriteFileMemory, testGoodEncodeResponse)
83{
84 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_RESP_BYTES>
85 responseMsg{};
86 uint32_t length = 0xFF00EE11;
Lei YU2d5c7452020-03-03 14:43:45 +080087 uint32_t lengthLe = htole32(length);
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053088 pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
89
90 // ReadFileIntoMemory
91 auto rc = encode_rw_file_memory_resp(0, PLDM_READ_FILE_INTO_MEMORY,
92 PLDM_SUCCESS, length, response);
93
94 ASSERT_EQ(rc, PLDM_SUCCESS);
95 ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
96 ASSERT_EQ(response->hdr.instance_id, 0);
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050097 ASSERT_EQ(response->hdr.type, PLDM_OEM);
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +053098 ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_INTO_MEMORY);
99 ASSERT_EQ(response->payload[0], PLDM_SUCCESS);
100 ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]),
Lei YU2d5c7452020-03-03 14:43:45 +0800101 &lengthLe, sizeof(lengthLe)));
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530102
103 // WriteFileFromMemory
104 rc = encode_rw_file_memory_resp(0, PLDM_WRITE_FILE_FROM_MEMORY,
105 PLDM_SUCCESS, length, response);
106
107 ASSERT_EQ(rc, PLDM_SUCCESS);
108 ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
109 ASSERT_EQ(response->hdr.instance_id, 0);
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500110 ASSERT_EQ(response->hdr.type, PLDM_OEM);
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530111 ASSERT_EQ(response->hdr.command, PLDM_WRITE_FILE_FROM_MEMORY);
112 ASSERT_EQ(response->payload[0], PLDM_SUCCESS);
113 ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]),
Lei YU2d5c7452020-03-03 14:43:45 +0800114 &lengthLe, sizeof(lengthLe)));
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530115}
116
117TEST(ReadWriteFileMemory, testBadEncodeResponse)
118{
119 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_RESP_BYTES>
120 responseMsg{};
121 uint32_t length = 0;
122 pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
123
124 // ReadFileIntoMemory
125 auto rc = encode_rw_file_memory_resp(0, PLDM_READ_FILE_INTO_MEMORY,
126 PLDM_ERROR, length, response);
127
128 ASSERT_EQ(rc, PLDM_SUCCESS);
129 ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
130 ASSERT_EQ(response->hdr.instance_id, 0);
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500131 ASSERT_EQ(response->hdr.type, PLDM_OEM);
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530132 ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_INTO_MEMORY);
133 ASSERT_EQ(response->payload[0], PLDM_ERROR);
134
135 // WriteFileFromMemory
136 rc = encode_rw_file_memory_resp(0, PLDM_WRITE_FILE_FROM_MEMORY, PLDM_ERROR,
137 length, response);
138
139 ASSERT_EQ(rc, PLDM_SUCCESS);
140 ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
141 ASSERT_EQ(response->hdr.instance_id, 0);
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500142 ASSERT_EQ(response->hdr.type, PLDM_OEM);
Jinu Joy Thomas7f57f442019-06-13 20:38:49 +0530143 ASSERT_EQ(response->hdr.command, PLDM_WRITE_FILE_FROM_MEMORY);
144 ASSERT_EQ(response->payload[0], PLDM_ERROR);
145}
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530146
Priyanga8b976652019-06-27 11:30:33 -0500147TEST(ReadWriteFileIntoMemory, testGoodDecodeResponse)
148{
Zahed Hossain223a73d2019-07-04 12:46:18 -0500149 std::array<uint8_t, PLDM_RW_FILE_MEM_RESP_BYTES + hdrSize> responseMsg{};
Priyanga8b976652019-06-27 11:30:33 -0500150 // Random value for length
151 uint32_t length = 0xFF00EE12;
Lei YU2d5c7452020-03-03 14:43:45 +0800152 uint32_t lengthLe = htole32(length);
Priyanga8b976652019-06-27 11:30:33 -0500153 uint8_t completionCode = 0;
154
Zahed Hossain223a73d2019-07-04 12:46:18 -0500155 memcpy(responseMsg.data() + hdrSize, &completionCode,
156 sizeof(completionCode));
Lei YU2d5c7452020-03-03 14:43:45 +0800157 memcpy(responseMsg.data() + sizeof(completionCode) + hdrSize, &lengthLe,
158 sizeof(lengthLe));
Priyanga8b976652019-06-27 11:30:33 -0500159
160 uint8_t retCompletionCode = 0;
161 uint32_t retLength = 0;
162
Zahed Hossain223a73d2019-07-04 12:46:18 -0500163 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
164
Priyanga8b976652019-06-27 11:30:33 -0500165 // Invoke decode the read file memory response
Zahed Hossain223a73d2019-07-04 12:46:18 -0500166 auto rc = decode_rw_file_memory_resp(response, responseMsg.size() - hdrSize,
Priyanga8b976652019-06-27 11:30:33 -0500167 &retCompletionCode, &retLength);
168 ASSERT_EQ(rc, PLDM_SUCCESS);
169 ASSERT_EQ(completionCode, retCompletionCode);
170 ASSERT_EQ(length, retLength);
171}
172
173TEST(ReadWriteFileIntoMemory, testBadDecodeResponse)
174{
175 uint32_t length = 0;
176 uint8_t completionCode = 0;
177
178 // Request payload message is missing
179 auto rc = decode_rw_file_memory_resp(NULL, 0, &completionCode, &length);
180 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
181
182 std::array<uint8_t, PLDM_RW_FILE_MEM_RESP_BYTES> responseMsg{};
183
Zahed Hossain223a73d2019-07-04 12:46:18 -0500184 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
185
Priyanga8b976652019-06-27 11:30:33 -0500186 // Payload length is invalid
Zahed Hossain223a73d2019-07-04 12:46:18 -0500187 rc = decode_rw_file_memory_resp(response, 0, &completionCode, &length);
Priyanga8b976652019-06-27 11:30:33 -0500188 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
189}
190
191TEST(ReadWriteFileIntoMemory, testGoodEncodeRequest)
192{
193 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_REQ_BYTES>
194 requestMsg{};
195
196 uint32_t fileHandle = 0x12345678;
197 uint32_t offset = 0x87654321;
198 uint32_t length = 0x13245768;
199 uint64_t address = 0x124356879ACBDE0F;
Lei YU2d5c7452020-03-03 14:43:45 +0800200 uint32_t fileHandleLe = htole32(fileHandle);
201 uint32_t offsetLe = htole32(offset);
202 uint32_t lengthLe = htole32(length);
203 uint64_t addressLe = htole64(address);
Priyanga8b976652019-06-27 11:30:33 -0500204
205 pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data());
206
207 auto rc =
208 encode_rw_file_memory_req(0, PLDM_READ_FILE_INTO_MEMORY, fileHandle,
209 offset, length, address, request);
210
211 ASSERT_EQ(rc, PLDM_SUCCESS);
212 ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
213 ASSERT_EQ(request->hdr.instance_id, 0);
214 ASSERT_EQ(request->hdr.type, PLDM_OEM);
215 ASSERT_EQ(request->hdr.command, PLDM_READ_FILE_INTO_MEMORY);
216
Lei YU2d5c7452020-03-03 14:43:45 +0800217 ASSERT_EQ(0, memcmp(request->payload, &fileHandleLe, sizeof(fileHandleLe)));
Priyanga8b976652019-06-27 11:30:33 -0500218
Lei YU2d5c7452020-03-03 14:43:45 +0800219 ASSERT_EQ(0, memcmp(request->payload + sizeof(fileHandleLe), &offsetLe,
220 sizeof(offsetLe)));
221 ASSERT_EQ(0,
222 memcmp(request->payload + sizeof(fileHandleLe) + sizeof(offsetLe),
223 &lengthLe, sizeof(lengthLe)));
224 ASSERT_EQ(0, memcmp(request->payload + sizeof(fileHandleLe) +
225 sizeof(offsetLe) + sizeof(lengthLe),
226 &addressLe, sizeof(addressLe)));
Priyanga8b976652019-06-27 11:30:33 -0500227}
228
229TEST(ReadWriteFileIntoMemory, testBadEncodeRequest)
230{
231 uint32_t fileHandle = 0;
232 uint32_t offset = 0;
233 uint32_t length = 0;
234 uint64_t address = 0;
235
236 auto rc =
237 encode_rw_file_memory_req(0, PLDM_READ_FILE_INTO_MEMORY, fileHandle,
238 offset, length, address, NULL);
239
240 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
241}
242
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530243TEST(GetFileTable, GoodDecodeRequest)
244{
Zahed Hossain223a73d2019-07-04 12:46:18 -0500245 std::array<uint8_t, PLDM_GET_FILE_TABLE_REQ_BYTES + hdrSize> requestMsg{};
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530246
247 // Random value for DataTransferHandle, TransferOperationFlag, TableType
248 uint32_t transferHandle = 0x12345678;
Lei YU2d5c7452020-03-03 14:43:45 +0800249 uint32_t transferHandleLe = htole32(transferHandle);
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530250 uint8_t transferOpFlag = 1;
251 uint8_t tableType = 1;
252
Lei YU2d5c7452020-03-03 14:43:45 +0800253 memcpy(requestMsg.data() + hdrSize, &transferHandleLe,
254 sizeof(transferHandleLe));
Zahed Hossain223a73d2019-07-04 12:46:18 -0500255 memcpy(requestMsg.data() + sizeof(transferHandle) + hdrSize,
256 &transferOpFlag, sizeof(transferOpFlag));
257 memcpy(requestMsg.data() + sizeof(transferHandle) + sizeof(transferOpFlag) +
258 hdrSize,
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530259 &tableType, sizeof(tableType));
260
261 uint32_t retTransferHandle = 0;
262 uint8_t retTransferOpFlag = 0;
263 uint8_t retTableType = 0;
264
Zahed Hossain223a73d2019-07-04 12:46:18 -0500265 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
266
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530267 // Invoke decode get file table request
Zahed Hossain223a73d2019-07-04 12:46:18 -0500268 auto rc = decode_get_file_table_req(request, requestMsg.size() - hdrSize,
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530269 &retTransferHandle, &retTransferOpFlag,
270 &retTableType);
271
272 ASSERT_EQ(rc, PLDM_SUCCESS);
273 ASSERT_EQ(transferHandle, retTransferHandle);
274 ASSERT_EQ(transferOpFlag, retTransferOpFlag);
275 ASSERT_EQ(tableType, retTableType);
276}
277
278TEST(GetFileTable, BadDecodeRequest)
279{
280 uint32_t transferHandle = 0;
281 uint8_t transferOpFlag = 0;
282 uint8_t tableType = 0;
283
284 // Request payload message is missing
285 auto rc = decode_get_file_table_req(nullptr, 0, &transferHandle,
286 &transferOpFlag, &tableType);
287 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
288
289 std::array<uint8_t, PLDM_GET_FILE_TABLE_REQ_BYTES> requestMsg{};
290
Zahed Hossain223a73d2019-07-04 12:46:18 -0500291 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
292
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530293 // TableType is NULL
Zahed Hossain223a73d2019-07-04 12:46:18 -0500294 rc = decode_get_file_table_req(request, requestMsg.size() - hdrSize,
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530295 &transferHandle, &transferOpFlag, nullptr);
296 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
297
298 // Payload length is invalid
Zahed Hossain223a73d2019-07-04 12:46:18 -0500299 rc = decode_get_file_table_req(request, 0, &transferHandle, &transferOpFlag,
300 &tableType);
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530301 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
302}
303
304TEST(GetFileTable, GoodEncodeResponse)
305{
306 // Random value for NextDataTransferHandle and TransferFlag
307 uint8_t completionCode = 0;
308 uint32_t nextTransferHandle = 0x87654321;
Lei YU2d5c7452020-03-03 14:43:45 +0800309 uint32_t nextTransferHandleLe = htole32(nextTransferHandle);
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530310 uint8_t transferFlag = 5;
311 // Mock file table contents of size 5
312 std::array<uint8_t, 5> fileTable = {1, 2, 3, 4, 5};
313 constexpr size_t responseSize = sizeof(completionCode) +
314 sizeof(nextTransferHandle) +
315 sizeof(transferFlag) + fileTable.size();
316
317 std::array<uint8_t, sizeof(pldm_msg_hdr) + responseSize> responseMsg{};
318 pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
319
320 // GetFileTable
321 auto rc = encode_get_file_table_resp(0, PLDM_SUCCESS, nextTransferHandle,
322 transferFlag, fileTable.data(),
323 fileTable.size(), response);
324
325 ASSERT_EQ(rc, PLDM_SUCCESS);
326 ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
327 ASSERT_EQ(response->hdr.instance_id, 0);
328 ASSERT_EQ(response->hdr.type, PLDM_OEM);
329 ASSERT_EQ(response->hdr.command, PLDM_GET_FILE_TABLE);
330 ASSERT_EQ(response->payload[0], PLDM_SUCCESS);
331 ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]),
Lei YU2d5c7452020-03-03 14:43:45 +0800332 &nextTransferHandleLe, sizeof(nextTransferHandle)));
Tom Joseph0c6d22c2019-06-26 09:58:41 +0530333 ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
334 sizeof(nextTransferHandle),
335 &transferFlag, sizeof(transferFlag)));
336 ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
337 sizeof(nextTransferHandle),
338 &transferFlag, sizeof(transferFlag)));
339 ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
340 sizeof(nextTransferHandle) + sizeof(transferFlag),
341 fileTable.data(), fileTable.size()));
342}
343
344TEST(GetFileTable, BadEncodeResponse)
345{
346 uint8_t completionCode = 0;
347 uint32_t nextTransferHandle = 0;
348 uint8_t transferFlag = 0;
349 constexpr size_t responseSize = sizeof(completionCode) +
350 sizeof(nextTransferHandle) +
351 sizeof(transferFlag);
352
353 std::array<uint8_t, sizeof(pldm_msg_hdr) + responseSize> responseMsg{};
354 pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
355
356 // GetFileTable
357 auto rc = encode_get_file_table_resp(0, PLDM_ERROR, nextTransferHandle,
358 transferFlag, nullptr, 0, response);
359
360 ASSERT_EQ(rc, PLDM_SUCCESS);
361 ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
362 ASSERT_EQ(response->hdr.instance_id, 0);
363 ASSERT_EQ(response->hdr.type, PLDM_OEM);
364 ASSERT_EQ(response->hdr.command, PLDM_GET_FILE_TABLE);
365 ASSERT_EQ(response->payload[0], PLDM_ERROR);
366}
vkaverap2ffe3292019-06-24 00:08:13 -0500367
Pavithra Barithayad15c8092020-05-12 02:26:26 -0500368TEST(GetFileTable, GoodEncodeRequest)
369{
370 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_FILE_TABLE_REQ_BYTES>
371 requestMsg{};
372 uint32_t transferHandle = 0x0;
373 uint8_t transferOpFlag = 0x01;
374 uint8_t tableType = PLDM_FILE_ATTRIBUTE_TABLE;
375
376 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
377 auto rc = encode_get_file_table_req(0, transferHandle, transferOpFlag,
378 tableType, request);
379 EXPECT_EQ(rc, PLDM_SUCCESS);
380
381 struct pldm_get_file_table_req* req =
382 reinterpret_cast<struct pldm_get_file_table_req*>(request->payload);
383 EXPECT_EQ(transferHandle, le32toh(req->transfer_handle));
384 EXPECT_EQ(transferOpFlag, req->operation_flag);
385 EXPECT_EQ(tableType, req->table_type);
386}
387
388TEST(GetFileTable, BadEncodeRequest)
389{
390 uint32_t transferHandle = 0x0;
391 uint8_t transferOpFlag = 0x01;
392 uint8_t tableType = PLDM_FILE_ATTRIBUTE_TABLE;
393
394 auto rc = encode_get_file_table_req(0, transferHandle, transferOpFlag,
395 tableType, nullptr);
396
397 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
398}
399
400TEST(GetFileTable, GoodDecodeResponse)
401{
402 uint32_t nextTransferHandle = 32;
403 uint8_t completionCode = PLDM_SUCCESS;
404 uint8_t transferFlag = PLDM_START_AND_END;
405 std::vector<uint8_t> fileTableData = {1, 2, 3, 4, 5, 6, 7, 8, 9};
406
407 std::vector<uint8_t> responseMsg(
408 hdrSize + PLDM_GET_FILE_TABLE_MIN_RESP_BYTES + fileTableData.size());
409
410 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
411 size_t payload_length = responseMsg.size() - hdrSize;
412
413 auto resp = reinterpret_cast<struct pldm_get_file_table_resp*>(
414 responsePtr->payload);
415
416 resp->completion_code = completionCode;
417 resp->next_transfer_handle = htole32(nextTransferHandle);
418 resp->transfer_flag = transferFlag;
419 memcpy(resp->table_data, fileTableData.data(), fileTableData.size());
420
421 uint8_t retCompletionCode;
422 uint32_t retNextTransferHandle;
423 uint8_t retTransferFlag;
424 std::vector<uint8_t> retFileTableData(9, 0);
425 size_t retFileTableDataLength = 0;
426
427 auto rc = decode_get_file_table_resp(
428 responsePtr, payload_length, &retCompletionCode, &retNextTransferHandle,
429 &retTransferFlag, retFileTableData.data(), &retFileTableDataLength);
430
431 ASSERT_EQ(rc, PLDM_SUCCESS);
432 ASSERT_EQ(completionCode, retCompletionCode);
433 ASSERT_EQ(nextTransferHandle, retNextTransferHandle);
434 ASSERT_EQ(transferFlag, retTransferFlag);
435 ASSERT_EQ(0, memcmp(fileTableData.data(), resp->table_data,
436 retFileTableDataLength));
437 ASSERT_EQ(fileTableData.size(), retFileTableDataLength);
438}
439
440TEST(GetFileTable, BadDecodeResponse)
441{
442 uint32_t nextTransferHandle = 32;
443 uint8_t completionCode = PLDM_SUCCESS;
444 uint8_t transferFlag = PLDM_START_AND_END;
445 std::vector<uint8_t> fileTableData(9, 0);
446 size_t file_table_data_length = 0;
447
448 std::vector<uint8_t> responseMsg(
449 hdrSize + PLDM_GET_FILE_TABLE_MIN_RESP_BYTES + fileTableData.size());
450
451 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
452
453 auto rc = decode_get_file_table_resp(
454 nullptr, 0, &completionCode, &nextTransferHandle, &transferFlag,
455 fileTableData.data(), &file_table_data_length);
456
457 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
458
459 rc = decode_get_file_table_resp(
460 responsePtr, 0, &completionCode, &nextTransferHandle, &transferFlag,
461 fileTableData.data(), &file_table_data_length);
462
463 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
464}
465
vkaverap2ffe3292019-06-24 00:08:13 -0500466TEST(ReadFile, testGoodDecodeRequest)
467{
468 std::array<uint8_t, PLDM_READ_FILE_REQ_BYTES + sizeof(pldm_msg_hdr)>
469 requestMsg{};
470
471 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
472 size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
473 auto request = reinterpret_cast<pldm_read_file_req*>(requestPtr->payload);
474
475 // Random value for fileHandle, offset and length
476 uint32_t fileHandle = 0x12345678;
477 uint32_t offset = 0x87654321;
478 uint32_t length = 0x13245768;
479
Lei YU2d5c7452020-03-03 14:43:45 +0800480 request->file_handle = htole32(fileHandle);
481 request->offset = htole32(offset);
482 request->length = htole32(length);
vkaverap2ffe3292019-06-24 00:08:13 -0500483
484 uint32_t retFileHandle = 0;
485 uint32_t retOffset = 0;
486 uint32_t retLength = 0;
487
488 // Invoke decode the read file request
489 auto rc = decode_read_file_req(requestPtr, payload_length, &retFileHandle,
490 &retOffset, &retLength);
491
492 ASSERT_EQ(rc, PLDM_SUCCESS);
493 ASSERT_EQ(fileHandle, retFileHandle);
494 ASSERT_EQ(offset, retOffset);
495 ASSERT_EQ(length, retLength);
496}
497
498TEST(WriteFile, testGoodDecodeRequest)
499{
500 // Random value for fileHandle, offset, length and file data
501 uint32_t fileHandle = 0x12345678;
502 uint32_t offset = 0x87654321;
503 uint32_t length = 0x467;
504
505 std::vector<uint8_t> requestMsg(PLDM_WRITE_FILE_REQ_BYTES +
506 sizeof(pldm_msg_hdr) + length);
507 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
508 size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
509 auto request = reinterpret_cast<pldm_write_file_req*>(requestPtr->payload);
510
511 size_t fileDataOffset =
512 sizeof(fileHandle) + sizeof(offset) + sizeof(length);
513
Lei YU2d5c7452020-03-03 14:43:45 +0800514 request->file_handle = htole32(fileHandle);
515 request->offset = htole32(offset);
516 request->length = htole32(length);
vkaverap2ffe3292019-06-24 00:08:13 -0500517
518 uint32_t retFileHandle = 0;
519 uint32_t retOffset = 0;
520 uint32_t retLength = 0;
521 size_t retFileDataOffset = 0;
522
523 // Invoke decode the write file request
524 auto rc = decode_write_file_req(requestPtr, payload_length, &retFileHandle,
525 &retOffset, &retLength, &retFileDataOffset);
526
527 ASSERT_EQ(rc, PLDM_SUCCESS);
528 ASSERT_EQ(fileHandle, retFileHandle);
529 ASSERT_EQ(offset, retOffset);
530 ASSERT_EQ(length, retLength);
531 ASSERT_EQ(fileDataOffset, retFileDataOffset);
532}
533
534TEST(ReadFile, testGoodDecodeResponse)
535{
536 // Random value for length
537 uint32_t length = 0x10;
538 uint8_t completionCode = PLDM_SUCCESS;
539
540 std::vector<uint8_t> responseMsg(PLDM_READ_FILE_RESP_BYTES +
541 sizeof(pldm_msg_hdr) + length);
542 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
543 size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
544 auto response =
545 reinterpret_cast<pldm_read_file_resp*>(responsePtr->payload);
546
547 response->completion_code = completionCode;
Lei YU2d5c7452020-03-03 14:43:45 +0800548 response->length = htole32(length);
vkaverap2ffe3292019-06-24 00:08:13 -0500549
550 size_t fileDataOffset = sizeof(completionCode) + sizeof(length);
551
552 uint32_t retLength = 0;
553 uint8_t retCompletionCode = 0;
554 size_t retFileDataOffset = 0;
555
556 // Invoke decode the read file response
557 auto rc =
558 decode_read_file_resp(responsePtr, payload_length, &retCompletionCode,
559 &retLength, &retFileDataOffset);
560
561 ASSERT_EQ(rc, PLDM_SUCCESS);
562 ASSERT_EQ(completionCode, retCompletionCode);
563 ASSERT_EQ(length, retLength);
564 ASSERT_EQ(fileDataOffset, retFileDataOffset);
565}
566
567TEST(WriteFile, testGoodDecodeResponse)
568{
569 std::array<uint8_t, PLDM_WRITE_FILE_RESP_BYTES + sizeof(pldm_msg_hdr)>
570 responseMsg{};
571 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
572 size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
573 auto response =
574 reinterpret_cast<pldm_write_file_resp*>(responsePtr->payload);
575
576 uint8_t completionCode = PLDM_SUCCESS;
577 uint32_t length = 0x4678;
578
579 response->completion_code = completionCode;
Lei YU2d5c7452020-03-03 14:43:45 +0800580 response->length = htole32(length);
vkaverap2ffe3292019-06-24 00:08:13 -0500581
582 uint32_t retLength = 0;
583 uint8_t retCompletionCode = 0;
584
585 // Invoke decode the write file response
586 auto rc = decode_write_file_resp(responsePtr, payload_length,
587 &retCompletionCode, &retLength);
588
589 ASSERT_EQ(rc, PLDM_SUCCESS);
590 ASSERT_EQ(completionCode, retCompletionCode);
591 ASSERT_EQ(length, retLength);
592}
593
594TEST(ReadWriteFile, testBadDecodeResponse)
595{
596 uint32_t length = 0;
597 uint8_t completionCode = 0;
598 size_t fileDataOffset = 0;
599
600 // Bad decode response for read file
601 std::vector<uint8_t> responseMsg(PLDM_READ_FILE_RESP_BYTES +
602 sizeof(pldm_msg_hdr) + length);
603 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
604
605 // Request payload message is missing
606 auto rc = decode_read_file_resp(NULL, 0, &completionCode, &length,
607 &fileDataOffset);
608 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
609
610 // Payload length is invalid
611 rc = decode_read_file_resp(responsePtr, 0, &completionCode, &length,
612 &fileDataOffset);
613 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
614
615 // Bad decode response for write file
616 std::array<uint8_t, PLDM_WRITE_FILE_RESP_BYTES + sizeof(pldm_msg_hdr)>
617 responseMsgWr{};
618 auto responseWr = reinterpret_cast<pldm_msg*>(responseMsgWr.data());
619
620 // Request payload message is missing
621 rc = decode_write_file_resp(NULL, 0, &completionCode, &length);
622 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
623
624 // Payload length is invalid
625 rc = decode_write_file_resp(responseWr, 0, &completionCode, &length);
626 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
627}
628
629TEST(ReadWriteFile, testBadDecodeRequest)
630{
631 uint32_t fileHandle = 0;
632 uint32_t offset = 0;
633 uint32_t length = 0;
634
635 // Bad decode request for read file
636 std::array<uint8_t, PLDM_READ_FILE_REQ_BYTES + sizeof(pldm_msg_hdr)>
637 requestMsg{};
638 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
639
640 // Request payload message is missing
641 auto rc = decode_read_file_req(NULL, 0, &fileHandle, &offset, &length);
642 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
643
644 // Payload length is invalid
645 rc = decode_read_file_req(requestPtr, 0, &fileHandle, &offset, &length);
646 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
647
648 // Bad decode request for write file
649 size_t fileDataOffset = 0;
650 std::array<uint8_t, PLDM_WRITE_FILE_REQ_BYTES> requestMsgWr{};
651 auto requestWr = reinterpret_cast<pldm_msg*>(requestMsgWr.data());
652
653 // Request payload message is missing
654 rc = decode_write_file_req(NULL, 0, &fileHandle, &offset, &length,
655 &fileDataOffset);
656 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
657
658 // Payload length is invalid
659 rc = decode_write_file_req(requestWr, 0, &fileHandle, &offset, &length,
660 &fileDataOffset);
661 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
662}
663
664TEST(ReadFile, testGoodEncodeResponse)
665{
666 // Good encode response for read file
667 uint32_t length = 0x4;
668
669 std::vector<uint8_t> responseMsg(PLDM_READ_FILE_RESP_BYTES +
670 sizeof(pldm_msg_hdr) + length);
671 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
672 auto response =
673 reinterpret_cast<pldm_read_file_resp*>(responsePtr->payload);
674
675 // ReadFile
676 auto rc = encode_read_file_resp(0, PLDM_SUCCESS, length, responsePtr);
677
678 ASSERT_EQ(rc, PLDM_SUCCESS);
679 ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE);
680 ASSERT_EQ(responsePtr->hdr.instance_id, 0);
681 ASSERT_EQ(responsePtr->hdr.type, PLDM_OEM);
682 ASSERT_EQ(responsePtr->hdr.command, PLDM_READ_FILE);
683 ASSERT_EQ(response->completion_code, PLDM_SUCCESS);
Lei YU2d5c7452020-03-03 14:43:45 +0800684 ASSERT_EQ(le32toh(response->length), length);
vkaverap2ffe3292019-06-24 00:08:13 -0500685}
686
687TEST(WriteFile, testGoodEncodeResponse)
688{
689 uint32_t length = 0x467;
690
691 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_WRITE_FILE_RESP_BYTES>
692 responseMsg{};
693
694 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
695 auto response =
696 reinterpret_cast<pldm_write_file_resp*>(responsePtr->payload);
697
698 // WriteFile
699 auto rc = encode_write_file_resp(0, PLDM_SUCCESS, length, responsePtr);
700 ASSERT_EQ(rc, PLDM_SUCCESS);
701 ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE);
702 ASSERT_EQ(responsePtr->hdr.instance_id, 0);
703 ASSERT_EQ(responsePtr->hdr.type, PLDM_OEM);
704 ASSERT_EQ(responsePtr->hdr.command, PLDM_WRITE_FILE);
705 ASSERT_EQ(response->completion_code, PLDM_SUCCESS);
Lei YU2d5c7452020-03-03 14:43:45 +0800706 ASSERT_EQ(le32toh(response->length), length);
vkaverap2ffe3292019-06-24 00:08:13 -0500707}
708
709TEST(ReadFile, testGoodEncodeRequest)
710{
711 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_READ_FILE_REQ_BYTES>
712 requestMsg{};
713
714 uint32_t fileHandle = 0x12345678;
715 uint32_t offset = 0x87654321;
716 uint32_t length = 0x13245768;
717 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
718 auto request = reinterpret_cast<pldm_read_file_req*>(requestPtr->payload);
719
720 // ReadFile
721 auto rc = encode_read_file_req(0, fileHandle, offset, length, requestPtr);
722
723 ASSERT_EQ(rc, PLDM_SUCCESS);
724 ASSERT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
725 ASSERT_EQ(requestPtr->hdr.instance_id, 0);
726 ASSERT_EQ(requestPtr->hdr.type, PLDM_OEM);
727 ASSERT_EQ(requestPtr->hdr.command, PLDM_READ_FILE);
Lei YU2d5c7452020-03-03 14:43:45 +0800728 ASSERT_EQ(le32toh(request->file_handle), fileHandle);
729 ASSERT_EQ(le32toh(request->offset), offset);
730 ASSERT_EQ(le32toh(request->length), length);
vkaverap2ffe3292019-06-24 00:08:13 -0500731}
732
733TEST(WriteFile, testGoodEncodeRequest)
734{
735 uint32_t fileHandle = 0x12345678;
736 uint32_t offset = 0x87654321;
737 uint32_t length = 0x456;
738
739 std::vector<uint8_t> requestMsg(PLDM_WRITE_FILE_REQ_BYTES +
740 sizeof(pldm_msg_hdr) + length);
741 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
742 auto request = reinterpret_cast<pldm_write_file_req*>(requestPtr->payload);
743
744 // WriteFile
745 auto rc = encode_write_file_req(0, fileHandle, offset, length, requestPtr);
746
747 ASSERT_EQ(rc, PLDM_SUCCESS);
748 ASSERT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
749 ASSERT_EQ(requestPtr->hdr.instance_id, 0);
750 ASSERT_EQ(requestPtr->hdr.type, PLDM_OEM);
751 ASSERT_EQ(requestPtr->hdr.command, PLDM_WRITE_FILE);
Lei YU2d5c7452020-03-03 14:43:45 +0800752 ASSERT_EQ(le32toh(request->file_handle), fileHandle);
753 ASSERT_EQ(le32toh(request->offset), offset);
754 ASSERT_EQ(le32toh(request->length), length);
vkaverap2ffe3292019-06-24 00:08:13 -0500755}
756
757TEST(ReadWriteFile, testBadEncodeRequest)
758{
759 // Bad encode request for read file
760 uint32_t fileHandle = 0;
761 uint32_t offset = 0;
762 uint32_t length = 0;
763
764 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_READ_FILE_REQ_BYTES>
765 requestMsg{};
766 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
767
768 // ReadFile check invalid file length
769 auto rc = encode_read_file_req(0, fileHandle, offset, length, requestPtr);
770
Deepak Kodihalli3bf5c552020-04-20 06:16:01 -0500771 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
vkaverap2ffe3292019-06-24 00:08:13 -0500772
773 // Bad encode request for write file
774 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_WRITE_FILE_REQ_BYTES>
775 requestMsgWr{};
776 auto requestWr = reinterpret_cast<pldm_msg*>(requestMsgWr.data());
777
778 // WriteFile check for invalid file length
779 rc = encode_write_file_req(0, fileHandle, offset, length, requestWr);
780
Deepak Kodihalli3bf5c552020-04-20 06:16:01 -0500781 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
vkaverap2ffe3292019-06-24 00:08:13 -0500782}
783
784TEST(ReadWriteFile, testBadEncodeResponse)
785{
786 // Bad encode response for read file
787 uint32_t length = 0;
788
789 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_READ_FILE_RESP_BYTES>
790 responseMsg{};
791 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
792
793 // ReadFile
794 auto rc = encode_read_file_resp(0, PLDM_ERROR, length, responsePtr);
795
796 ASSERT_EQ(rc, PLDM_SUCCESS);
797 ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE);
798 ASSERT_EQ(responsePtr->hdr.instance_id, 0);
799 ASSERT_EQ(responsePtr->hdr.type, PLDM_OEM);
800 ASSERT_EQ(responsePtr->hdr.command, PLDM_READ_FILE);
801 ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR);
802
803 // Bad encode response for write file
804 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_WRITE_FILE_RESP_BYTES>
805 responseMsgWr{};
806 auto responseWr = reinterpret_cast<pldm_msg*>(responseMsgWr.data());
807
808 // WriteFile
809 rc = encode_write_file_resp(0, PLDM_ERROR, length, responseWr);
810
811 ASSERT_EQ(rc, PLDM_SUCCESS);
812 ASSERT_EQ(responseWr->hdr.request, PLDM_RESPONSE);
813 ASSERT_EQ(responseWr->hdr.instance_id, 0);
814 ASSERT_EQ(responseWr->hdr.type, PLDM_OEM);
815 ASSERT_EQ(responseWr->hdr.command, PLDM_WRITE_FILE);
816 ASSERT_EQ(responseWr->payload[0], PLDM_ERROR);
817}
vkaverap07404562019-08-05 22:57:11 -0500818
819TEST(ReadWriteFileByTypeMemory, testGoodDecodeRequest)
820{
821 std::array<uint8_t,
822 PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES + sizeof(pldm_msg_hdr)>
823 requestMsg{};
824
825 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
826 size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
827 auto request = reinterpret_cast<pldm_read_write_file_by_type_memory_req*>(
828 requestPtr->payload);
829
830 // Random value for fileHandle, offset and length
831 uint16_t fileType = 0;
832 uint32_t fileHandle = 0x12345678;
833 uint32_t offset = 0x87654321;
834 uint32_t length = 0x13245768;
835 uint64_t address = 0x124356879ACBD456;
836
Lei YU2d5c7452020-03-03 14:43:45 +0800837 request->file_type = htole16(fileType);
838 request->file_handle = htole32(fileHandle);
839 request->offset = htole32(offset);
840 request->length = htole32(length);
841 request->address = htole64(address);
vkaverap07404562019-08-05 22:57:11 -0500842
843 uint16_t retFileType = 0x1;
844 uint32_t retFileHandle = 0;
845 uint32_t retOffset = 0;
846 uint32_t retLength = 0;
847 uint64_t retAddress = 0;
848
849 // Invoke decode the read file request
850 auto rc = decode_rw_file_by_type_memory_req(
851 requestPtr, payload_length, &retFileType, &retFileHandle, &retOffset,
852 &retLength, &retAddress);
853
854 ASSERT_EQ(rc, PLDM_SUCCESS);
855 ASSERT_EQ(fileType, retFileType);
856 ASSERT_EQ(fileHandle, retFileHandle);
857 ASSERT_EQ(offset, retOffset);
858 ASSERT_EQ(length, retLength);
859 ASSERT_EQ(address, retAddress);
860}
861
862TEST(ReadWriteFileByTypeMemory, testGoodDecodeResponse)
863{
864 std::array<uint8_t,
865 PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES + sizeof(pldm_msg_hdr)>
866 responseMsg{};
867
868 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
869 size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
870 auto response = reinterpret_cast<pldm_read_write_file_by_type_memory_resp*>(
871 responsePtr->payload);
872
873 // Random value for completion code and length
874 uint8_t completionCode = 0x0;
875 uint32_t length = 0x13245768;
876
877 response->completion_code = completionCode;
Lei YU2d5c7452020-03-03 14:43:45 +0800878 response->length = htole32(length);
vkaverap07404562019-08-05 22:57:11 -0500879
880 uint8_t retCompletionCode = 0x1;
881 uint32_t retLength = 0;
882
883 // Invoke decode the read/write file response
884 auto rc = decode_rw_file_by_type_memory_resp(
885 responsePtr, payload_length, &retCompletionCode, &retLength);
886
887 ASSERT_EQ(rc, PLDM_SUCCESS);
888 ASSERT_EQ(completionCode, retCompletionCode);
889 ASSERT_EQ(length, retLength);
890}
891
892TEST(ReadWriteFileByTypeMemory, testBadDecodeRequest)
893{
894 uint16_t fileType = 0;
895 uint32_t fileHandle = 0;
896 uint32_t offset = 0;
897 uint32_t length = 0;
898 uint64_t address = 0;
899
900 // Request payload message is missing
901 auto rc = decode_rw_file_by_type_memory_req(NULL, 0, &fileType, &fileHandle,
902 &offset, &length, &address);
903 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
904
905 std::array<uint8_t,
906 PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES + sizeof(pldm_msg_hdr)>
907 requestMsg{};
908
909 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
910
911 // Address is NULL
912 rc = decode_rw_file_by_type_memory_req(
913 requestPtr, requestMsg.size() - hdrSize, &fileType, &fileHandle,
914 &offset, &length, NULL);
915 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
916
917 // Payload length is invalid
918 rc = decode_rw_file_by_type_memory_req(
919 requestPtr, 0, &fileType, &fileHandle, &offset, &length, &address);
920 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
921}
922
923TEST(ReadWriteFileByTypeMemory, testBadDecodeResponse)
924{
925 uint32_t length = 0;
926 uint8_t completionCode = 0;
927
928 // Request payload message is missing
929 auto rc =
930 decode_rw_file_by_type_memory_resp(NULL, 0, &completionCode, &length);
931 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
932
933 std::array<uint8_t,
934 PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES + sizeof(pldm_msg_hdr)>
935 responseMsg{};
936
937 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
938
939 // Length is NULL
940 rc = decode_rw_file_by_type_memory_resp(
941 responsePtr, responseMsg.size() - hdrSize, &completionCode, NULL);
942 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
943
944 // Payload length is invalid
945 rc = decode_rw_file_by_type_memory_resp(responsePtr, 0, &completionCode,
946 &length);
947 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
948}
949
950TEST(ReadWriteFileByTypeMemory, testGoodEncodeRequest)
951{
952 std::array<uint8_t,
953 sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES>
954 requestMsg{};
955
956 uint16_t fileType = 0;
957 uint32_t fileHandle = 0x12345678;
958 uint32_t offset = 0x87654321;
959 uint32_t length = 0x13245768;
960 uint64_t address = 0x124356879ACBDE0F;
Lei YU2d5c7452020-03-03 14:43:45 +0800961 uint16_t fileTypeLe = htole16(fileType);
962 uint32_t fileHandleLe = htole32(fileHandle);
963 uint32_t offsetLe = htole32(offset);
964 uint32_t lengthLe = htole32(length);
965 uint64_t addressLe = htole64(address);
vkaverap07404562019-08-05 22:57:11 -0500966
967 pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data());
968
969 auto rc = encode_rw_file_by_type_memory_req(
970 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, fileType, fileHandle, offset,
971 length, address, request);
972
973 ASSERT_EQ(rc, PLDM_SUCCESS);
974 ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
975 ASSERT_EQ(request->hdr.instance_id, 0);
976 ASSERT_EQ(request->hdr.type, PLDM_OEM);
977 ASSERT_EQ(request->hdr.command, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY);
978
Lei YU2d5c7452020-03-03 14:43:45 +0800979 ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
980 ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe,
981 sizeof(fileHandleLe)));
vkaverap07404562019-08-05 22:57:11 -0500982
Lei YU2d5c7452020-03-03 14:43:45 +0800983 ASSERT_EQ(
984 0, memcmp(request->payload + sizeof(fileTypeLe) + sizeof(fileHandleLe),
985 &offsetLe, sizeof(offsetLe)));
986 ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
987 sizeof(fileHandleLe) + sizeof(offsetLe),
988 &lengthLe, sizeof(lengthLe)));
989 ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
990 sizeof(fileHandleLe) + sizeof(offsetLe) +
991 sizeof(lengthLe),
992 &addressLe, sizeof(addressLe)));
vkaverap07404562019-08-05 22:57:11 -0500993}
994
995TEST(ReadWriteFileByTypeMemory, testGoodEncodeResponse)
996{
997 std::array<uint8_t,
998 sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES>
999 responseMsg{};
1000
1001 uint32_t length = 0x13245768;
Lei YU2d5c7452020-03-03 14:43:45 +08001002 uint32_t lengthLe = htole32(length);
vkaverap07404562019-08-05 22:57:11 -05001003 uint8_t completionCode = 0x0;
1004
1005 pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1006
1007 auto rc = encode_rw_file_by_type_memory_resp(
1008 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, completionCode, length,
1009 response);
1010
1011 ASSERT_EQ(rc, PLDM_SUCCESS);
1012 ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
1013 ASSERT_EQ(response->hdr.instance_id, 0);
1014 ASSERT_EQ(response->hdr.type, PLDM_OEM);
1015 ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY);
1016
1017 ASSERT_EQ(
1018 0, memcmp(response->payload, &completionCode, sizeof(completionCode)));
Lei YU2d5c7452020-03-03 14:43:45 +08001019 ASSERT_EQ(0, memcmp(response->payload + sizeof(completionCode), &lengthLe,
1020 sizeof(lengthLe)));
vkaverap07404562019-08-05 22:57:11 -05001021}
1022
1023TEST(ReadWriteFileByTypeMemory, testBadEncodeResponse)
1024{
1025 std::array<uint8_t,
1026 sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES>
1027 responseMsg{};
1028 uint32_t length = 0;
1029 pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1030
1031 // completion code is PLDM_ERROR
1032 auto rc = encode_rw_file_by_type_memory_resp(
1033 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, PLDM_ERROR, length, response);
1034
1035 ASSERT_EQ(rc, PLDM_SUCCESS);
1036 ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
1037 ASSERT_EQ(response->hdr.instance_id, 0);
1038 ASSERT_EQ(response->hdr.type, PLDM_OEM);
1039 ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY);
1040 ASSERT_EQ(response->payload[0], PLDM_ERROR);
1041
1042 // response is NULL pointer
1043 rc = encode_rw_file_by_type_memory_resp(
1044 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, PLDM_SUCCESS, length, NULL);
1045
1046 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1047}
1048
1049TEST(ReadWriteFileByTypeMemory, testBadEncodeRequest)
1050{
1051 uint8_t fileType = 0;
1052 uint32_t fileHandle = 0;
1053 uint32_t offset = 0;
1054 uint32_t length = 0;
1055 uint64_t address = 0;
1056
1057 // request is NULL pointer
1058 auto rc = encode_rw_file_by_type_memory_req(
1059 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, fileType, fileHandle, offset,
1060 length, address, NULL);
1061
1062 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1063}
vkaverapa9aac722019-08-22 02:10:15 -05001064
1065TEST(NewFile, testGoodDecodeRequest)
1066{
1067 std::array<uint8_t, PLDM_NEW_FILE_REQ_BYTES + sizeof(pldm_msg_hdr)>
1068 requestMsg{};
1069
1070 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
1071 size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
1072 auto request = reinterpret_cast<pldm_new_file_req*>(requestPtr->payload);
1073
1074 // Random value for fileHandle and length
1075 uint16_t fileType = 0xFF;
1076 uint32_t fileHandle = 0x12345678;
Deepak Kodihalli83388762020-01-28 04:09:58 -06001077 uint64_t length = 0x13245768;
vkaverapa9aac722019-08-22 02:10:15 -05001078
Lei YU2d5c7452020-03-03 14:43:45 +08001079 request->file_type = htole16(fileType);
1080 request->file_handle = htole32(fileHandle);
1081 request->length = htole64(length);
vkaverapa9aac722019-08-22 02:10:15 -05001082
1083 uint16_t retFileType = 0xFF;
1084 uint32_t retFileHandle = 0;
Deepak Kodihalli83388762020-01-28 04:09:58 -06001085 uint64_t retLength = 0;
vkaverapa9aac722019-08-22 02:10:15 -05001086
1087 // Invoke decode the read file request
1088 auto rc = decode_new_file_req(requestPtr, payload_length, &retFileType,
1089 &retFileHandle, &retLength);
1090
1091 ASSERT_EQ(rc, PLDM_SUCCESS);
1092 ASSERT_EQ(fileType, retFileType);
1093 ASSERT_EQ(fileHandle, retFileHandle);
1094 ASSERT_EQ(length, retLength);
1095}
1096
1097TEST(NewFile, testGoodDecodeResponse)
1098{
1099 std::array<uint8_t, PLDM_NEW_FILE_RESP_BYTES + sizeof(pldm_msg_hdr)>
1100 responseMsg{};
1101
1102 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
1103 size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
1104 auto response = reinterpret_cast<pldm_new_file_resp*>(responsePtr->payload);
1105
1106 // Random value for completion code
1107 uint8_t completionCode = 0x0;
1108
1109 response->completion_code = completionCode;
1110
1111 uint8_t retCompletionCode = PLDM_SUCCESS;
1112
1113 // Invoke decode the read/write file response
1114 auto rc =
1115 decode_new_file_resp(responsePtr, payload_length, &retCompletionCode);
1116
1117 ASSERT_EQ(rc, PLDM_SUCCESS);
1118 ASSERT_EQ(completionCode, retCompletionCode);
1119}
1120
1121TEST(NewFile, testBadDecodeRequest)
1122{
1123 uint16_t fileType = 0;
1124 uint32_t fileHandle = 0;
Deepak Kodihalli83388762020-01-28 04:09:58 -06001125 uint64_t length = 0;
vkaverapa9aac722019-08-22 02:10:15 -05001126
1127 // Request payload message is missing
1128 auto rc = decode_new_file_req(NULL, 0, &fileType, &fileHandle, &length);
1129
1130 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1131
1132 std::array<uint8_t, PLDM_NEW_FILE_REQ_BYTES + sizeof(pldm_msg_hdr)>
1133 requestMsg{};
1134
1135 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
1136
1137 // Payload length is invalid
1138 rc = decode_new_file_req(requestPtr, 0, &fileType, &fileHandle, &length);
1139 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1140}
1141
1142TEST(NewFile, testBadDecodeResponse)
1143{
1144 uint8_t completionCode = 0;
1145
1146 // Request payload message is missing
1147 auto rc = decode_new_file_resp(NULL, 0, &completionCode);
1148 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1149
1150 std::array<uint8_t, PLDM_NEW_FILE_RESP_BYTES + sizeof(pldm_msg_hdr)>
1151 responseMsg{};
1152
1153 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
1154
1155 // Payload length is invalid
1156 rc = decode_new_file_resp(responsePtr, 0, &completionCode);
1157 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1158}
1159
1160TEST(NewFile, testGoodEncodeRequest)
1161{
1162 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_NEW_FILE_REQ_BYTES>
1163 requestMsg{};
1164
1165 uint16_t fileType = 0xFF;
1166 uint32_t fileHandle = 0x12345678;
1167 uint32_t length = 0x13245768;
Lei YU2d5c7452020-03-03 14:43:45 +08001168 uint16_t fileTypeLe = htole16(fileType);
1169 uint32_t fileHandleLe = htole32(fileHandle);
1170 uint32_t lengthLe = htole32(length);
vkaverapa9aac722019-08-22 02:10:15 -05001171
1172 pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1173
1174 auto rc = encode_new_file_req(0, fileType, fileHandle, length, request);
1175
1176 ASSERT_EQ(rc, PLDM_SUCCESS);
1177 ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
1178 ASSERT_EQ(request->hdr.instance_id, 0);
1179 ASSERT_EQ(request->hdr.type, PLDM_OEM);
1180 ASSERT_EQ(request->hdr.command, PLDM_NEW_FILE_AVAILABLE);
Lei YU2d5c7452020-03-03 14:43:45 +08001181 ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
1182 ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe,
1183 sizeof(fileHandleLe)));
1184 ASSERT_EQ(
1185 0, memcmp(request->payload + sizeof(fileTypeLe) + sizeof(fileHandleLe),
1186 &lengthLe, sizeof(lengthLe)));
vkaverapa9aac722019-08-22 02:10:15 -05001187}
1188
1189TEST(NewFile, testGoodEncodeResponse)
1190{
1191 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_NEW_FILE_RESP_BYTES>
1192 responseMsg{};
1193
1194 uint8_t completionCode = 0x0;
1195
1196 pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1197
1198 auto rc = encode_new_file_resp(0, completionCode, response);
1199
1200 ASSERT_EQ(rc, PLDM_SUCCESS);
1201 ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
1202 ASSERT_EQ(response->hdr.instance_id, 0);
1203 ASSERT_EQ(response->hdr.type, PLDM_OEM);
1204 ASSERT_EQ(response->hdr.command, PLDM_NEW_FILE_AVAILABLE);
1205 ASSERT_EQ(
1206 0, memcmp(response->payload, &completionCode, sizeof(completionCode)));
1207}
1208
1209TEST(NewFile, testBadEncodeResponse)
1210{
1211 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_NEW_FILE_RESP_BYTES>
1212 responseMsg{};
1213 pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1214
1215 // completion code is PLDM_ERROR
1216 auto rc = encode_new_file_resp(0, PLDM_ERROR, response);
1217
1218 ASSERT_EQ(rc, PLDM_SUCCESS);
1219 ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
1220 ASSERT_EQ(response->hdr.instance_id, 0);
1221 ASSERT_EQ(response->hdr.type, PLDM_OEM);
1222 ASSERT_EQ(response->hdr.command, PLDM_NEW_FILE_AVAILABLE);
1223 ASSERT_EQ(response->payload[0], PLDM_ERROR);
1224
1225 // response is NULL pointer
1226 rc = encode_new_file_resp(0, PLDM_SUCCESS, NULL);
1227
1228 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1229}
1230
1231TEST(NewFile, testBadEncodeRequest)
1232{
1233 uint8_t fileType = 0xFF;
1234 uint32_t fileHandle = 0;
1235 uint32_t length = 0;
1236
1237 // request is NULL pointer
1238 auto rc = encode_new_file_req(0, fileType, fileHandle, length, NULL);
1239
1240 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1241}
Deepak Kodihallidce1c992019-11-19 07:06:53 -06001242
1243TEST(ReadWriteFileByType, testGoodDecodeRequest)
1244{
1245 std::array<uint8_t, PLDM_RW_FILE_BY_TYPE_REQ_BYTES + sizeof(pldm_msg_hdr)>
1246 requestMsg{};
1247
1248 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
1249 size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
1250 auto request = reinterpret_cast<pldm_read_write_file_by_type_req*>(
1251 requestPtr->payload);
1252
1253 // Random value for fileHandle, offset and length
1254 uint16_t fileType = 0;
1255 uint32_t fileHandle = 0x12345678;
1256 uint32_t offset = 0x87654321;
1257 uint32_t length = 0x13245768;
1258
Lei YU2d5c7452020-03-03 14:43:45 +08001259 request->file_handle = htole32(fileHandle);
1260 request->offset = htole32(offset);
1261 request->length = htole32(length);
Deepak Kodihallidce1c992019-11-19 07:06:53 -06001262
1263 uint16_t retFileType = 0x1;
1264 uint32_t retFileHandle = 0;
1265 uint32_t retOffset = 0;
1266 uint32_t retLength = 0;
1267
1268 // Invoke decode the read file request
1269 auto rc =
1270 decode_rw_file_by_type_req(requestPtr, payload_length, &retFileType,
1271 &retFileHandle, &retOffset, &retLength);
1272
1273 ASSERT_EQ(rc, PLDM_SUCCESS);
1274 ASSERT_EQ(fileType, retFileType);
1275 ASSERT_EQ(fileHandle, retFileHandle);
1276 ASSERT_EQ(offset, retOffset);
1277 ASSERT_EQ(length, retLength);
1278}
1279
1280TEST(ReadWriteFileByType, testGoodDecodeResponse)
1281{
1282 std::array<uint8_t, PLDM_RW_FILE_BY_TYPE_RESP_BYTES + sizeof(pldm_msg_hdr)>
1283 responseMsg{};
1284
1285 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
1286 size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
1287 auto response = reinterpret_cast<pldm_read_write_file_by_type_resp*>(
1288 responsePtr->payload);
1289
1290 // Random value for completion code and length
1291 uint8_t completionCode = 0x0;
1292 uint32_t length = 0x13245768;
1293
1294 response->completion_code = completionCode;
Lei YU2d5c7452020-03-03 14:43:45 +08001295 response->length = htole32(length);
Deepak Kodihallidce1c992019-11-19 07:06:53 -06001296
1297 uint8_t retCompletionCode = 0x1;
1298 uint32_t retLength = 0;
1299
1300 // Invoke decode the read/write file response
1301 auto rc = decode_rw_file_by_type_resp(responsePtr, payload_length,
1302 &retCompletionCode, &retLength);
1303
1304 ASSERT_EQ(rc, PLDM_SUCCESS);
1305 ASSERT_EQ(completionCode, retCompletionCode);
1306 ASSERT_EQ(length, retLength);
1307}
1308
1309TEST(ReadWriteFileByType, testBadDecodeRequest)
1310{
1311 uint16_t fileType = 0;
1312 uint32_t fileHandle = 0;
1313 uint32_t offset = 0;
1314 uint32_t length = 0;
1315
1316 // Request payload message is missing
1317 auto rc = decode_rw_file_by_type_req(NULL, 0, &fileType, &fileHandle,
1318 &offset, &length);
1319 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1320
1321 std::array<uint8_t, PLDM_RW_FILE_BY_TYPE_REQ_BYTES + sizeof(pldm_msg_hdr)>
1322 requestMsg{};
1323
1324 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
1325
1326 // Payload length is invalid
1327 rc = decode_rw_file_by_type_req(requestPtr, 0, &fileType, &fileHandle,
1328 &offset, &length);
1329 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1330}
1331
1332TEST(ReadWriteFileByType, testBadDecodeResponse)
1333{
1334 uint32_t length = 0;
1335 uint8_t completionCode = 0;
1336
1337 // Request payload message is missing
1338 auto rc = decode_rw_file_by_type_resp(NULL, 0, &completionCode, &length);
1339 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1340
1341 std::array<uint8_t, PLDM_RW_FILE_BY_TYPE_RESP_BYTES + sizeof(pldm_msg_hdr)>
1342 responseMsg{};
1343
1344 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
1345
1346 // Length is NULL
1347 rc = decode_rw_file_by_type_resp(responsePtr, responseMsg.size() - hdrSize,
1348 &completionCode, NULL);
1349 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1350
1351 // Payload length is invalid
1352 rc = decode_rw_file_by_type_resp(responsePtr, 0, &completionCode, &length);
1353 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1354}
1355
1356TEST(ReadWriteFileByType, testGoodEncodeRequest)
1357{
1358 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_REQ_BYTES>
1359 requestMsg{};
1360
1361 uint16_t fileType = 0;
1362 uint32_t fileHandle = 0x12345678;
1363 uint32_t offset = 0x87654321;
1364 uint32_t length = 0x13245768;
Lei YU2d5c7452020-03-03 14:43:45 +08001365 uint16_t fileTypeLe = htole16(fileType);
1366 uint32_t fileHandleLe = htole32(fileHandle);
1367 uint32_t offsetLe = htole32(offset);
1368 uint32_t lengthLe = htole32(length);
Deepak Kodihallidce1c992019-11-19 07:06:53 -06001369
1370 pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1371
1372 auto rc = encode_rw_file_by_type_req(0, PLDM_READ_FILE_BY_TYPE, fileType,
1373 fileHandle, offset, length, request);
1374
1375 ASSERT_EQ(rc, PLDM_SUCCESS);
1376 ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
1377 ASSERT_EQ(request->hdr.instance_id, 0);
1378 ASSERT_EQ(request->hdr.type, PLDM_OEM);
1379 ASSERT_EQ(request->hdr.command, PLDM_READ_FILE_BY_TYPE);
1380
Lei YU2d5c7452020-03-03 14:43:45 +08001381 ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
1382 ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe,
1383 sizeof(fileHandleLe)));
Deepak Kodihallidce1c992019-11-19 07:06:53 -06001384
Lei YU2d5c7452020-03-03 14:43:45 +08001385 ASSERT_EQ(
1386 0, memcmp(request->payload + sizeof(fileTypeLe) + sizeof(fileHandleLe),
1387 &offsetLe, sizeof(offsetLe)));
1388 ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
1389 sizeof(fileHandleLe) + sizeof(offsetLe),
1390 &lengthLe, sizeof(lengthLe)));
Deepak Kodihallidce1c992019-11-19 07:06:53 -06001391}
1392
1393TEST(ReadWriteFileByType, testGoodEncodeResponse)
1394{
1395 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_RESP_BYTES>
1396 responseMsg{};
1397
1398 uint32_t length = 0x13245768;
Lei YU2d5c7452020-03-03 14:43:45 +08001399 uint32_t lengthLe = htole32(length);
Deepak Kodihallidce1c992019-11-19 07:06:53 -06001400 uint8_t completionCode = 0x0;
Deepak Kodihallidce1c992019-11-19 07:06:53 -06001401 pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1402
1403 auto rc = encode_rw_file_by_type_resp(0, PLDM_READ_FILE_BY_TYPE,
1404 completionCode, length, response);
1405
1406 ASSERT_EQ(rc, PLDM_SUCCESS);
1407 ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
1408 ASSERT_EQ(response->hdr.instance_id, 0);
1409 ASSERT_EQ(response->hdr.type, PLDM_OEM);
1410 ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_BY_TYPE);
1411
1412 ASSERT_EQ(
1413 0, memcmp(response->payload, &completionCode, sizeof(completionCode)));
Lei YU2d5c7452020-03-03 14:43:45 +08001414 ASSERT_EQ(0, memcmp(response->payload + sizeof(completionCode), &lengthLe,
1415 sizeof(lengthLe)));
Deepak Kodihallidce1c992019-11-19 07:06:53 -06001416}
1417
1418TEST(ReadWriteFileByType, testBadEncodeResponse)
1419{
1420 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_RESP_BYTES>
1421 responseMsg{};
1422 uint32_t length = 0;
1423 pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1424
1425 // completion code is PLDM_ERROR
1426 auto rc = encode_rw_file_by_type_resp(0, PLDM_READ_FILE_BY_TYPE, PLDM_ERROR,
1427 length, response);
1428
1429 ASSERT_EQ(rc, PLDM_SUCCESS);
1430 ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
1431 ASSERT_EQ(response->hdr.instance_id, 0);
1432 ASSERT_EQ(response->hdr.type, PLDM_OEM);
1433 ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_BY_TYPE);
1434 ASSERT_EQ(response->payload[0], PLDM_ERROR);
1435
1436 // response is NULL pointer
1437 rc = encode_rw_file_by_type_resp(0, PLDM_READ_FILE_BY_TYPE, PLDM_SUCCESS,
1438 length, NULL);
1439
1440 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1441}
1442
1443TEST(ReadWriteFileByType, testBadEncodeRequest)
1444{
1445 uint8_t fileType = 0;
1446 uint32_t fileHandle = 0;
1447 uint32_t offset = 0;
1448 uint32_t length = 0;
1449
1450 // request is NULL pointer
1451 auto rc = encode_rw_file_by_type_req(0, PLDM_READ_FILE_BY_TYPE, fileType,
1452 fileHandle, offset, length, NULL);
1453
1454 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1455}
vkaverapf4e0a492019-11-19 01:47:35 -06001456
1457TEST(FileAck, testGoodDecodeRequest)
1458{
1459 std::array<uint8_t, PLDM_FILE_ACK_REQ_BYTES + sizeof(pldm_msg_hdr)>
1460 requestMsg{};
1461
1462 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
1463 size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
1464 auto request = reinterpret_cast<pldm_file_ack_req*>(requestPtr->payload);
1465
1466 // Random value for fileHandle
1467 uint16_t fileType = 0xFFFF;
1468 uint32_t fileHandle = 0x12345678;
Lei YU2d5c7452020-03-03 14:43:45 +08001469 uint8_t fileStatus = 0xFF;
vkaverapf4e0a492019-11-19 01:47:35 -06001470
Lei YU2d5c7452020-03-03 14:43:45 +08001471 request->file_type = htole16(fileType);
1472 request->file_handle = htole32(fileHandle);
vkaverapf4e0a492019-11-19 01:47:35 -06001473 request->file_status = fileStatus;
1474
1475 uint16_t retFileType = 0xFF;
1476 uint32_t retFileHandle = 0;
1477 uint8_t retFileStatus = 0;
1478
1479 // Invoke decode the read file request
1480 auto rc = decode_file_ack_req(requestPtr, payload_length, &retFileType,
1481 &retFileHandle, &retFileStatus);
1482
1483 ASSERT_EQ(rc, PLDM_SUCCESS);
1484 ASSERT_EQ(fileType, retFileType);
1485 ASSERT_EQ(fileHandle, retFileHandle);
1486 ASSERT_EQ(fileStatus, retFileStatus);
1487}
1488
1489TEST(FileAck, testGoodDecodeResponse)
1490{
1491 std::array<uint8_t, PLDM_FILE_ACK_RESP_BYTES + sizeof(pldm_msg_hdr)>
1492 responseMsg{};
1493
1494 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
1495 size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
1496 auto response = reinterpret_cast<pldm_file_ack_resp*>(responsePtr->payload);
1497
1498 // Random value for completion code
1499 uint8_t completionCode = 0x0;
1500
1501 response->completion_code = completionCode;
1502
1503 uint8_t retCompletionCode = PLDM_SUCCESS;
1504
1505 // Invoke decode the read/write file response
1506 auto rc =
1507 decode_file_ack_resp(responsePtr, payload_length, &retCompletionCode);
1508
1509 ASSERT_EQ(rc, PLDM_SUCCESS);
1510 ASSERT_EQ(completionCode, retCompletionCode);
1511}
1512
1513TEST(FileAck, testBadDecodeRequest)
1514{
1515 uint16_t fileType = 0;
1516 uint32_t fileHandle = 0;
1517 uint8_t fileStatus = 0;
1518
1519 // Request payload message is missing
1520 auto rc = decode_file_ack_req(NULL, 0, &fileType, &fileHandle, &fileStatus);
1521
1522 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1523
1524 std::array<uint8_t, PLDM_FILE_ACK_REQ_BYTES + sizeof(pldm_msg_hdr)>
1525 requestMsg{};
1526
1527 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
1528
1529 // Payload length is invalid
1530 rc =
1531 decode_file_ack_req(requestPtr, 0, &fileType, &fileHandle, &fileStatus);
1532 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1533}
1534
1535TEST(FileAck, testBadDecodeResponse)
1536{
1537 uint8_t completionCode = 0;
1538
1539 // Request payload message is missing
1540 auto rc = decode_file_ack_resp(NULL, 0, &completionCode);
1541 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1542
1543 std::array<uint8_t, PLDM_FILE_ACK_RESP_BYTES + sizeof(pldm_msg_hdr)>
1544 responseMsg{};
1545
1546 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
1547
1548 // Payload length is invalid
1549 rc = decode_file_ack_resp(responsePtr, 0, &completionCode);
1550 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1551}
1552
1553TEST(FileAck, testGoodEncodeRequest)
1554{
1555 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_REQ_BYTES>
1556 requestMsg{};
1557
1558 uint16_t fileType = 0xFFFF;
1559 uint32_t fileHandle = 0x12345678;
1560 uint8_t fileStatus = 0xFF;
Lei YU2d5c7452020-03-03 14:43:45 +08001561 uint16_t fileTypeLe = htole16(fileType);
1562 uint32_t fileHandleLe = htole32(fileHandle);
vkaverapf4e0a492019-11-19 01:47:35 -06001563
1564 pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1565
1566 auto rc = encode_file_ack_req(0, fileType, fileHandle, fileStatus, request);
1567
1568 ASSERT_EQ(rc, PLDM_SUCCESS);
1569 ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
1570 ASSERT_EQ(request->hdr.instance_id, 0);
1571 ASSERT_EQ(request->hdr.type, PLDM_OEM);
1572 ASSERT_EQ(request->hdr.command, PLDM_FILE_ACK);
Lei YU2d5c7452020-03-03 14:43:45 +08001573 ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
1574 ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe,
1575 sizeof(fileHandleLe)));
vkaverapf4e0a492019-11-19 01:47:35 -06001576}
1577
1578TEST(FileAck, testGoodEncodeResponse)
1579{
1580 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_RESP_BYTES>
1581 responseMsg{};
1582
1583 uint8_t completionCode = 0x0;
1584
1585 pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1586
1587 auto rc = encode_file_ack_resp(0, completionCode, response);
1588
1589 ASSERT_EQ(rc, PLDM_SUCCESS);
1590 ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
1591 ASSERT_EQ(response->hdr.instance_id, 0);
1592 ASSERT_EQ(response->hdr.type, PLDM_OEM);
1593 ASSERT_EQ(response->hdr.command, PLDM_FILE_ACK);
1594 ASSERT_EQ(
1595 0, memcmp(response->payload, &completionCode, sizeof(completionCode)));
1596}
1597
1598TEST(FileAck, testBadEncodeResponse)
1599{
1600 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_RESP_BYTES>
1601 responseMsg{};
1602 pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1603
1604 // completion code is PLDM_ERROR
1605 auto rc = encode_file_ack_resp(0, PLDM_ERROR, response);
1606
1607 ASSERT_EQ(rc, PLDM_SUCCESS);
1608 ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
1609 ASSERT_EQ(response->hdr.instance_id, 0);
1610 ASSERT_EQ(response->hdr.type, PLDM_OEM);
1611 ASSERT_EQ(response->hdr.command, PLDM_FILE_ACK);
1612 ASSERT_EQ(response->payload[0], PLDM_ERROR);
1613
1614 // response is NULL pointer
1615 rc = encode_file_ack_resp(0, PLDM_SUCCESS, NULL);
1616
1617 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1618}
1619
1620TEST(FileAck, testBadEncodeRequest)
1621{
1622 uint8_t fileType = 0xFF;
1623 uint32_t fileHandle = 0;
1624 uint8_t fileStatus = 0;
1625
1626 // request is NULL pointer
1627 auto rc = encode_file_ack_req(0, fileType, fileHandle, fileStatus, nullptr);
1628
1629 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1630}
Sridevi Ramesh8b51fa22022-06-13 06:28:13 -05001631
1632TEST(FileAckWithMetadata, testGoodEncodeResponse)
1633{
1634 std::array<uint8_t,
1635 sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES>
1636 responseMsg{};
1637
1638 uint8_t completionCode = 0x0;
1639
1640 pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1641
1642 auto rc = encode_file_ack_with_meta_data_resp(0, completionCode, response);
1643
1644 ASSERT_EQ(rc, PLDM_SUCCESS);
1645 ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
1646 ASSERT_EQ(response->hdr.instance_id, 0);
1647 ASSERT_EQ(response->hdr.type, PLDM_OEM);
1648 ASSERT_EQ(response->hdr.command, PLDM_FILE_ACK_WITH_META_DATA);
1649 ASSERT_EQ(
1650 0, memcmp(response->payload, &completionCode, sizeof(completionCode)));
1651}
1652
1653TEST(FileAckWithMetadata, testBadEncodeResponse)
1654{
1655 std::array<uint8_t,
1656 sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES>
1657 responseMsg{};
1658 pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1659
1660 // completion code is PLDM_ERROR
1661 auto rc = encode_file_ack_with_meta_data_resp(0, PLDM_ERROR, response);
1662
1663 ASSERT_EQ(rc, PLDM_SUCCESS);
1664 ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
1665 ASSERT_EQ(response->hdr.instance_id, 0);
1666 ASSERT_EQ(response->hdr.type, PLDM_OEM);
1667 ASSERT_EQ(response->hdr.command, PLDM_FILE_ACK_WITH_META_DATA);
1668 ASSERT_EQ(response->payload[0], PLDM_ERROR);
1669
1670 // response is NULL pointer
1671 rc = encode_file_ack_with_meta_data_resp(0, PLDM_SUCCESS, NULL);
1672
1673 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1674}
1675
1676TEST(FileAckWithMetadata, testGoodDecodeResponse)
1677{
1678 std::array<uint8_t,
1679 PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES + sizeof(pldm_msg_hdr)>
1680 responseMsg{};
1681
1682 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
1683 size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
1684 auto response = reinterpret_cast<pldm_file_ack_with_meta_data_resp*>(
1685 responsePtr->payload);
1686
1687 // Random value for completion code
1688 uint8_t completionCode = 0x0;
1689
1690 response->completion_code = completionCode;
1691
1692 uint8_t retCompletionCode = PLDM_SUCCESS;
1693
1694 // Invoke decode the read/write file response
1695 auto rc = decode_file_ack_with_meta_data_resp(responsePtr, payload_length,
1696 &retCompletionCode);
1697
1698 ASSERT_EQ(rc, PLDM_SUCCESS);
1699 ASSERT_EQ(completionCode, retCompletionCode);
1700}
1701
1702TEST(FileAckWithMetadata, testBadDecodeResponse)
1703{
1704 uint8_t completionCode = 0;
1705
1706 // Request payload message is missing
1707 auto rc = decode_file_ack_with_meta_data_resp(NULL, 0, &completionCode);
1708 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1709
1710 std::array<uint8_t,
1711 PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES + sizeof(pldm_msg_hdr)>
1712 responseMsg{};
1713
1714 auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
1715
1716 // Payload length is invalid
1717 rc = decode_file_ack_with_meta_data_resp(responsePtr, 0, &completionCode);
1718 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1719}
1720
1721TEST(FileAckWithMetadata, testGoodEncodeRequest)
1722{
1723 std::array<uint8_t,
1724 sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES>
1725 requestMsg{};
1726
1727 uint16_t fileType = 0xFFFF;
1728 uint32_t fileHandle = 0x12345678;
1729 uint8_t fileStatus = 0xFF;
1730 uint32_t fileMetaData1 = 0xFFFFFFFF;
1731 uint32_t fileMetaData2 = 0xFFFFFFFF;
1732 uint32_t fileMetaData3 = 0xFFFFFFFF;
1733 uint32_t fileMetaData4 = 0xFFFFFFFF;
1734
1735 uint16_t fileTypeLe = htole16(fileType);
1736 uint32_t fileHandleLe = htole32(fileHandle);
1737 uint32_t fileMetaData1Le = htole32(fileMetaData1);
1738 uint32_t fileMetaData2Le = htole32(fileMetaData2);
1739 uint32_t fileMetaData3Le = htole32(fileMetaData3);
1740 uint32_t fileMetaData4Le = htole32(fileMetaData4);
1741
1742 pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1743
1744 auto rc = encode_file_ack_with_meta_data_req(
1745 0, fileType, fileHandle, fileStatus, fileMetaData1, fileMetaData2,
1746 fileMetaData3, fileMetaData4, request);
1747
1748 ASSERT_EQ(rc, PLDM_SUCCESS);
1749 ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
1750 ASSERT_EQ(request->hdr.instance_id, 0);
1751 ASSERT_EQ(request->hdr.type, PLDM_OEM);
1752 ASSERT_EQ(request->hdr.command, PLDM_FILE_ACK_WITH_META_DATA);
1753 ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
1754 ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe,
1755 sizeof(fileHandleLe)));
1756 ASSERT_EQ(
1757 0, memcmp(request->payload + sizeof(fileTypeLe) + sizeof(fileHandleLe),
1758 &fileStatus, sizeof(fileStatus)));
1759 ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
1760 sizeof(fileHandleLe) + sizeof(fileStatus),
1761 &fileMetaData1Le, sizeof(fileMetaData1Le)));
1762 ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
1763 sizeof(fileHandleLe) + sizeof(fileStatus) +
1764 sizeof(fileMetaData1Le),
1765 &fileMetaData2Le, sizeof(fileMetaData2Le)));
1766
1767 ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
1768 sizeof(fileHandleLe) + sizeof(fileStatus) +
1769 sizeof(fileMetaData1Le) + sizeof(fileMetaData2Le),
1770 &fileMetaData3Le, sizeof(fileMetaData3Le)));
1771
1772 ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
1773 sizeof(fileHandleLe) + sizeof(fileStatus) +
1774 sizeof(fileMetaData1Le) + sizeof(fileMetaData2Le) +
1775 sizeof(fileMetaData3Le),
1776 &fileMetaData4Le, sizeof(fileMetaData4Le)));
1777}
1778
1779TEST(FileAckWithMetadata, testBadEncodeRequest)
1780{
1781 uint8_t fileType = 0xFF;
1782 uint32_t fileHandle = 0;
1783 uint8_t fileStatus = 0;
1784 uint32_t fileMetaData1 = 0;
1785 uint32_t fileMetaData2 = 0;
1786 uint32_t fileMetaData3 = 0;
1787 uint32_t fileMetaData4 = 0;
1788
1789 // request is NULL pointer
1790 auto rc = encode_file_ack_with_meta_data_req(
1791 0, fileType, fileHandle, fileStatus, fileMetaData1, fileMetaData2,
1792 fileMetaData3, fileMetaData4, nullptr);
1793
1794 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1795}
1796
1797TEST(FileAckWithMetadata, testGoodDecodeRequest)
1798{
1799 std::array<uint8_t,
1800 sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES>
1801 requestMsg{};
1802
1803 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
1804 size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
1805 auto request = reinterpret_cast<pldm_file_ack_with_meta_data_req*>(
1806 requestPtr->payload);
1807
1808 uint16_t fileType = 0xFFFF;
1809 uint32_t fileHandle = 0x12345678;
1810 uint8_t fileStatus = 0xFF;
1811 uint32_t fileMetaData1 = 0x12345678;
1812 uint32_t fileMetaData2 = 0x87654321;
1813 uint32_t fileMetaData3 = 0x22121117;
1814 uint32_t fileMetaData4 = 0x12334345;
1815
1816 request->file_type = htole16(fileType);
1817 request->file_handle = htole32(fileHandle);
1818 request->file_status = fileStatus;
1819 request->file_meta_data_1 = htole32(fileMetaData1);
1820 request->file_meta_data_2 = htole32(fileMetaData2);
1821 request->file_meta_data_3 = htole32(fileMetaData3);
1822 request->file_meta_data_4 = htole32(fileMetaData4);
1823
1824 uint16_t retFileType = 0xFFFF;
1825 uint32_t retFileHandle = 0;
1826 uint8_t retFileStatus = 0;
1827 uint32_t retFileMetaData1 = 0;
1828 uint32_t retFileMetaData2 = 0;
1829 uint32_t retFileMetaData3 = 0;
1830 uint32_t retFileMetaData4 = 0;
1831
1832 auto rc = decode_file_ack_with_meta_data_req(
1833 requestPtr, payload_length, &retFileType, &retFileHandle,
1834 &retFileStatus, &retFileMetaData1, &retFileMetaData2, &retFileMetaData3,
1835 &retFileMetaData4);
1836 ASSERT_EQ(rc, PLDM_SUCCESS);
1837 ASSERT_EQ(fileType, retFileType);
1838 ASSERT_EQ(fileHandle, retFileHandle);
1839 ASSERT_EQ(fileStatus, retFileStatus);
1840 ASSERT_EQ(fileMetaData1, retFileMetaData1);
1841 ASSERT_EQ(fileMetaData2, retFileMetaData2);
1842 ASSERT_EQ(fileMetaData3, retFileMetaData3);
1843 ASSERT_EQ(fileMetaData4, retFileMetaData4);
1844}
1845
1846TEST(FileAckWithMetadata, testBadDecodeRequest)
1847{
1848 uint16_t fileType = 0;
1849 uint32_t fileHandle = 0;
1850 uint8_t fileStatus = 0;
1851 uint32_t fileMetaData1 = 0;
1852 uint32_t fileMetaData2 = 0;
1853 uint32_t fileMetaData3 = 0;
1854 uint32_t fileMetaData4 = 0;
1855
1856 // Request payload message is missing
1857 auto rc = decode_file_ack_with_meta_data_req(
1858 NULL, 0, &fileType, &fileHandle, &fileStatus, &fileMetaData1,
1859 &fileMetaData2, &fileMetaData3, &fileMetaData4);
1860
1861 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1862
1863 std::array<uint8_t,
1864 PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES + sizeof(pldm_msg_hdr)>
1865 requestMsg{};
1866
1867 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
1868
1869 // Payload length is invalid
1870 rc = decode_file_ack_with_meta_data_req(
1871 requestPtr, 0, &fileType, &fileHandle, &fileStatus, &fileMetaData1,
1872 &fileMetaData2, &fileMetaData3, &fileMetaData4);
1873 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1874}