blob: 7aaf7e4d7b3e4dd25a2efbef9f82a5d5f78fd645 [file] [log] [blame]
Deepak Kodihalli1b24f972019-02-01 04:09:13 -06001#include <string.h>
2
3#include <array>
4
5#include "libpldm/base.h"
6
7#include <gtest/gtest.h>
8
Zahed Hossain223a73d2019-07-04 12:46:18 -05009constexpr auto hdrSize = sizeof(pldm_msg_hdr);
10
Tom Joseph41251042019-02-07 16:17:07 +053011TEST(PackPLDMMessage, BadPathTest)
12{
13 struct pldm_header_info hdr;
14 struct pldm_header_info* hdr_ptr = NULL;
15 pldm_msg_hdr msg{};
16
17 // PLDM header information pointer is NULL
18 auto rc = pack_pldm_header(hdr_ptr, &msg);
19 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
20
21 // PLDM message pointer is NULL
22 rc = pack_pldm_header(&hdr, nullptr);
23 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
24
25 // PLDM header information pointer and PLDM message pointer is NULL
26 rc = pack_pldm_header(hdr_ptr, nullptr);
27 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
28
29 // RESERVED message type
30 hdr.msg_type = PLDM_RESERVED;
31 rc = pack_pldm_header(&hdr, &msg);
32 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
33
34 // Instance ID out of range
35 hdr.msg_type = PLDM_REQUEST;
36 hdr.instance = 32;
37 rc = pack_pldm_header(&hdr, &msg);
38 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
39
40 // PLDM type out of range
41 hdr.msg_type = PLDM_REQUEST;
42 hdr.instance = 31;
43 hdr.pldm_type = 64;
44 rc = pack_pldm_header(&hdr, &msg);
45 ASSERT_EQ(rc, PLDM_ERROR_INVALID_PLDM_TYPE);
46}
47
48TEST(PackPLDMMessage, RequestMessageGoodPath)
49{
50 struct pldm_header_info hdr;
51 pldm_msg_hdr msg{};
52
53 // Message type is REQUEST and lower range of the field values
54 hdr.msg_type = PLDM_REQUEST;
55 hdr.instance = 0;
56 hdr.pldm_type = 0;
57 hdr.command = 0;
58
59 auto rc = pack_pldm_header(&hdr, &msg);
60 ASSERT_EQ(rc, PLDM_SUCCESS);
61 ASSERT_EQ(msg.request, 1);
62 ASSERT_EQ(msg.datagram, 0);
63 ASSERT_EQ(msg.instance_id, 0);
64 ASSERT_EQ(msg.type, 0);
65 ASSERT_EQ(msg.command, 0);
66
67 // Message type is REQUEST and upper range of the field values
68 hdr.instance = 31;
69 hdr.pldm_type = 63;
70 hdr.command = 255;
71
72 rc = pack_pldm_header(&hdr, &msg);
73 ASSERT_EQ(rc, PLDM_SUCCESS);
74 ASSERT_EQ(msg.request, 1);
75 ASSERT_EQ(msg.datagram, 0);
76 ASSERT_EQ(msg.instance_id, 31);
77 ASSERT_EQ(msg.type, 63);
78 ASSERT_EQ(msg.command, 255);
79
80 // Message type is PLDM_ASYNC_REQUEST_NOTIFY
81 hdr.msg_type = PLDM_ASYNC_REQUEST_NOTIFY;
82
83 rc = pack_pldm_header(&hdr, &msg);
84 ASSERT_EQ(rc, PLDM_SUCCESS);
85 ASSERT_EQ(msg.request, 1);
86 ASSERT_EQ(msg.datagram, 1);
87 ASSERT_EQ(msg.instance_id, 31);
88 ASSERT_EQ(msg.type, 63);
89 ASSERT_EQ(msg.command, 255);
90}
91
92TEST(PackPLDMMessage, ResponseMessageGoodPath)
93{
94 struct pldm_header_info hdr;
95 pldm_msg_hdr msg{};
96
97 // Message type is PLDM_RESPONSE and lower range of the field values
98 hdr.msg_type = PLDM_RESPONSE;
99 hdr.instance = 0;
100 hdr.pldm_type = 0;
101 hdr.command = 0;
102
103 auto rc = pack_pldm_header(&hdr, &msg);
104 ASSERT_EQ(rc, PLDM_SUCCESS);
105 ASSERT_EQ(msg.request, 0);
106 ASSERT_EQ(msg.datagram, 0);
107 ASSERT_EQ(msg.instance_id, 0);
108 ASSERT_EQ(msg.type, 0);
109 ASSERT_EQ(msg.command, 0);
110
111 // Message type is PLDM_RESPONSE and upper range of the field values
112 hdr.instance = 31;
113 hdr.pldm_type = 63;
114 hdr.command = 255;
115
116 rc = pack_pldm_header(&hdr, &msg);
117 ASSERT_EQ(rc, PLDM_SUCCESS);
118 ASSERT_EQ(msg.request, 0);
119 ASSERT_EQ(msg.datagram, 0);
120 ASSERT_EQ(msg.instance_id, 31);
121 ASSERT_EQ(msg.type, 63);
122 ASSERT_EQ(msg.command, 255);
123}
124
125TEST(UnpackPLDMMessage, BadPathTest)
126{
127 struct pldm_header_info hdr;
128
129 // PLDM message pointer is NULL
130 auto rc = unpack_pldm_header(nullptr, &hdr);
131 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
132}
133
134TEST(UnpackPLDMMessage, RequestMessageGoodPath)
135{
136 struct pldm_header_info hdr;
137 pldm_msg_hdr msg{};
138
139 // Unpack PLDM request message and lower range of field values
140 msg.request = 1;
141 auto rc = unpack_pldm_header(&msg, &hdr);
142 ASSERT_EQ(rc, PLDM_SUCCESS);
143 ASSERT_EQ(hdr.msg_type, PLDM_REQUEST);
144 ASSERT_EQ(hdr.instance, 0);
145 ASSERT_EQ(hdr.pldm_type, 0);
146 ASSERT_EQ(hdr.command, 0);
147
148 // Unpack PLDM async request message and lower range of field values
149 msg.datagram = 1;
150 rc = unpack_pldm_header(&msg, &hdr);
151 ASSERT_EQ(rc, PLDM_SUCCESS);
152 ASSERT_EQ(hdr.msg_type, PLDM_ASYNC_REQUEST_NOTIFY);
153
154 // Unpack PLDM request message and upper range of field values
155 msg.datagram = 0;
156 msg.instance_id = 31;
157 msg.type = 63;
158 msg.command = 255;
159 rc = unpack_pldm_header(&msg, &hdr);
160 ASSERT_EQ(rc, PLDM_SUCCESS);
161 ASSERT_EQ(hdr.msg_type, PLDM_REQUEST);
162 ASSERT_EQ(hdr.instance, 31);
163 ASSERT_EQ(hdr.pldm_type, 63);
164 ASSERT_EQ(hdr.command, 255);
165}
166
167TEST(UnpackPLDMMessage, ResponseMessageGoodPath)
168{
169 struct pldm_header_info hdr;
170 pldm_msg_hdr msg{};
171
172 // Unpack PLDM response message and lower range of field values
173 auto rc = unpack_pldm_header(&msg, &hdr);
174 ASSERT_EQ(rc, PLDM_SUCCESS);
175 ASSERT_EQ(hdr.msg_type, PLDM_RESPONSE);
176 ASSERT_EQ(hdr.instance, 0);
177 ASSERT_EQ(hdr.pldm_type, 0);
178 ASSERT_EQ(hdr.command, 0);
179
180 // Unpack PLDM response message and upper range of field values
181 msg.instance_id = 31;
182 msg.type = 63;
183 msg.command = 255;
184 rc = unpack_pldm_header(&msg, &hdr);
185 ASSERT_EQ(rc, PLDM_SUCCESS);
186 ASSERT_EQ(hdr.msg_type, PLDM_RESPONSE);
187 ASSERT_EQ(hdr.instance, 31);
188 ASSERT_EQ(hdr.pldm_type, 63);
189 ASSERT_EQ(hdr.command, 255);
190}
191
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600192TEST(GetPLDMCommands, testEncodeRequest)
193{
194 uint8_t pldmType = 0x05;
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600195 ver32_t version{0xFF, 0xFF, 0xFF, 0xFF};
vkaverapa6575b82019-04-03 05:33:52 -0500196 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_COMMANDS_REQ_BYTES>
197 requestMsg{};
198 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600199
vkaverapa6575b82019-04-03 05:33:52 -0500200 auto rc = encode_get_commands_req(0, pldmType, version, request);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600201 ASSERT_EQ(rc, PLDM_SUCCESS);
vkaverapa6575b82019-04-03 05:33:52 -0500202 ASSERT_EQ(0, memcmp(request->payload, &pldmType, sizeof(pldmType)));
203 ASSERT_EQ(0, memcmp(request->payload + sizeof(pldmType), &version,
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600204 sizeof(version)));
205}
206
207TEST(GetPLDMCommands, testDecodeRequest)
208{
209 uint8_t pldmType = 0x05;
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600210 ver32_t version{0xFF, 0xFF, 0xFF, 0xFF};
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600211 uint8_t pldmTypeOut{};
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600212 ver32_t versionOut{0xFF, 0xFF, 0xFF, 0xFF};
Zahed Hossain223a73d2019-07-04 12:46:18 -0500213 std::array<uint8_t, hdrSize + PLDM_GET_COMMANDS_REQ_BYTES> requestMsg{};
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600214
Zahed Hossain223a73d2019-07-04 12:46:18 -0500215 memcpy(requestMsg.data() + hdrSize, &pldmType, sizeof(pldmType));
216 memcpy(requestMsg.data() + sizeof(pldmType) + hdrSize, &version,
217 sizeof(version));
218
219 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
220 auto rc = decode_get_commands_req(request, requestMsg.size() - hdrSize,
vkaverapa6575b82019-04-03 05:33:52 -0500221 &pldmTypeOut, &versionOut);
Zahed Hossain223a73d2019-07-04 12:46:18 -0500222
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600223 ASSERT_EQ(rc, PLDM_SUCCESS);
224 ASSERT_EQ(pldmTypeOut, pldmType);
225 ASSERT_EQ(0, memcmp(&versionOut, &version, sizeof(version)));
226}
227
228TEST(GetPLDMCommands, testEncodeResponse)
229{
230 uint8_t completionCode = 0;
vkaverapa6575b82019-04-03 05:33:52 -0500231 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_COMMANDS_RESP_BYTES>
232 responseMsg{};
233 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600234 std::array<bitfield8_t, PLDM_MAX_CMDS_PER_TYPE / 8> commands{};
235 commands[0].byte = 1;
236 commands[1].byte = 2;
237 commands[2].byte = 3;
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600238
239 auto rc =
vkaverapa6575b82019-04-03 05:33:52 -0500240 encode_get_commands_resp(0, PLDM_SUCCESS, commands.data(), response);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600241 ASSERT_EQ(rc, PLDM_SUCCESS);
vkaverapa6575b82019-04-03 05:33:52 -0500242 uint8_t* payload_ptr = response->payload;
243 ASSERT_EQ(completionCode, payload_ptr[0]);
244 ASSERT_EQ(1, payload_ptr[sizeof(completionCode)]);
245 ASSERT_EQ(2,
246 payload_ptr[sizeof(completionCode) + sizeof(commands[0].byte)]);
247 ASSERT_EQ(3, payload_ptr[sizeof(completionCode) + sizeof(commands[0].byte) +
248 sizeof(commands[1].byte)]);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600249}
250
251TEST(GetPLDMTypes, testEncodeResponse)
252{
253 uint8_t completionCode = 0;
vkaverapa6575b82019-04-03 05:33:52 -0500254 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_TYPES_RESP_BYTES>
255 responseMsg{};
256 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600257 std::array<bitfield8_t, PLDM_MAX_TYPES / 8> types{};
258 types[0].byte = 1;
259 types[1].byte = 2;
260 types[2].byte = 3;
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600261
vkaverapa6575b82019-04-03 05:33:52 -0500262 auto rc = encode_get_types_resp(0, PLDM_SUCCESS, types.data(), response);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600263 ASSERT_EQ(rc, PLDM_SUCCESS);
vkaverapa6575b82019-04-03 05:33:52 -0500264 uint8_t* payload_ptr = response->payload;
265 ASSERT_EQ(completionCode, payload_ptr[0]);
266 ASSERT_EQ(1, payload_ptr[sizeof(completionCode)]);
267 ASSERT_EQ(2, payload_ptr[sizeof(completionCode) + sizeof(types[0].byte)]);
268 ASSERT_EQ(3, payload_ptr[sizeof(completionCode) + sizeof(types[0].byte) +
269 sizeof(types[1].byte)]);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600270}
271
272TEST(GetPLDMTypes, testDecodeResponse)
273{
Zahed Hossain223a73d2019-07-04 12:46:18 -0500274 std::array<uint8_t, hdrSize + PLDM_GET_TYPES_RESP_BYTES> responseMsg{};
275 responseMsg[1 + hdrSize] = 1;
276 responseMsg[2 + hdrSize] = 2;
277 responseMsg[3 + hdrSize] = 3;
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600278 std::array<bitfield8_t, PLDM_MAX_TYPES / 8> outTypes{};
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600279 uint8_t completion_code;
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600280
Zahed Hossain223a73d2019-07-04 12:46:18 -0500281 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
282
283 auto rc = decode_get_types_resp(response, responseMsg.size() - hdrSize,
vkaverapa6575b82019-04-03 05:33:52 -0500284 &completion_code, outTypes.data());
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600285
286 ASSERT_EQ(rc, PLDM_SUCCESS);
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600287 ASSERT_EQ(completion_code, PLDM_SUCCESS);
Zahed Hossain223a73d2019-07-04 12:46:18 -0500288 ASSERT_EQ(responseMsg[1 + hdrSize], outTypes[0].byte);
289 ASSERT_EQ(responseMsg[2 + hdrSize], outTypes[1].byte);
290 ASSERT_EQ(responseMsg[3 + hdrSize], outTypes[2].byte);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600291}
292
293TEST(GetPLDMCommands, testDecodeResponse)
294{
Zahed Hossain223a73d2019-07-04 12:46:18 -0500295 std::array<uint8_t, hdrSize + PLDM_GET_COMMANDS_RESP_BYTES> responseMsg{};
296 responseMsg[1 + hdrSize] = 1;
297 responseMsg[2 + hdrSize] = 2;
298 responseMsg[3 + hdrSize] = 3;
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600299 std::array<bitfield8_t, PLDM_MAX_CMDS_PER_TYPE / 8> outTypes{};
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600300 uint8_t completion_code;
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600301
Zahed Hossain223a73d2019-07-04 12:46:18 -0500302 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
303
304 auto rc = decode_get_commands_resp(response, responseMsg.size() - hdrSize,
vkaverapa6575b82019-04-03 05:33:52 -0500305 &completion_code, outTypes.data());
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600306
307 ASSERT_EQ(rc, PLDM_SUCCESS);
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600308 ASSERT_EQ(completion_code, PLDM_SUCCESS);
Zahed Hossain223a73d2019-07-04 12:46:18 -0500309 ASSERT_EQ(responseMsg[1 + hdrSize], outTypes[0].byte);
310 ASSERT_EQ(responseMsg[2 + hdrSize], outTypes[1].byte);
311 ASSERT_EQ(responseMsg[3 + hdrSize], outTypes[2].byte);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600312}
Sampa Misra432e1872019-02-13 03:49:43 -0600313
Sampa Misra94d704b2019-02-22 03:36:02 -0600314TEST(GetPLDMVersion, testGoodEncodeRequest)
Sampa Misra432e1872019-02-13 03:49:43 -0600315{
vkaverapa6575b82019-04-03 05:33:52 -0500316 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_VERSION_REQ_BYTES>
317 requestMsg{};
318 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
Sampa Misra432e1872019-02-13 03:49:43 -0600319 uint8_t pldmType = 0x03;
320 uint32_t transferHandle = 0x0;
321 uint8_t opFlag = 0x01;
322
323 auto rc =
vkaverapa6575b82019-04-03 05:33:52 -0500324 encode_get_version_req(0, transferHandle, opFlag, pldmType, request);
Sampa Misra432e1872019-02-13 03:49:43 -0600325 ASSERT_EQ(rc, PLDM_SUCCESS);
vkaverapa6575b82019-04-03 05:33:52 -0500326 ASSERT_EQ(
327 0, memcmp(request->payload, &transferHandle, sizeof(transferHandle)));
328 ASSERT_EQ(0, memcmp(request->payload + sizeof(transferHandle), &opFlag,
Sampa Misra432e1872019-02-13 03:49:43 -0600329 sizeof(opFlag)));
vkaverapa6575b82019-04-03 05:33:52 -0500330 ASSERT_EQ(0,
331 memcmp(request->payload + sizeof(transferHandle) + sizeof(opFlag),
332 &pldmType, sizeof(pldmType)));
Sampa Misra432e1872019-02-13 03:49:43 -0600333}
334
Sampa Misra94d704b2019-02-22 03:36:02 -0600335TEST(GetPLDMVersion, testBadEncodeRequest)
336{
337 uint8_t pldmType = 0x03;
338 uint32_t transferHandle = 0x0;
339 uint8_t opFlag = 0x01;
340
341 auto rc =
342 encode_get_version_req(0, transferHandle, opFlag, pldmType, nullptr);
343
344 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
345}
346
Sampa Misra432e1872019-02-13 03:49:43 -0600347TEST(GetPLDMVersion, testEncodeResponse)
348{
Sampa Misra432e1872019-02-13 03:49:43 -0600349 uint8_t completionCode = 0;
350 uint32_t transferHandle = 0;
351 uint8_t flag = PLDM_START_AND_END;
vkaverapa6575b82019-04-03 05:33:52 -0500352 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_VERSION_RESP_BYTES>
353 responseMsg{};
354 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600355 ver32_t version = {0xFF, 0xFF, 0xFF, 0xFF};
Sampa Misra432e1872019-02-13 03:49:43 -0600356
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600357 auto rc = encode_get_version_resp(0, PLDM_SUCCESS, 0, PLDM_START_AND_END,
vkaverapa6575b82019-04-03 05:33:52 -0500358 &version, sizeof(ver32_t), response);
Sampa Misra432e1872019-02-13 03:49:43 -0600359
360 ASSERT_EQ(rc, PLDM_SUCCESS);
vkaverapa6575b82019-04-03 05:33:52 -0500361 ASSERT_EQ(completionCode, response->payload[0]);
362 ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]),
363 &transferHandle, sizeof(transferHandle)));
364 ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
365 sizeof(transferHandle),
366 &flag, sizeof(flag)));
367 ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
368 sizeof(transferHandle) + sizeof(flag),
369 &version, sizeof(version)));
Sampa Misra432e1872019-02-13 03:49:43 -0600370}
371
372TEST(GetPLDMVersion, testDecodeRequest)
373{
Zahed Hossain223a73d2019-07-04 12:46:18 -0500374 std::array<uint8_t, hdrSize + PLDM_GET_VERSION_REQ_BYTES> requestMsg{};
Sampa Misra432e1872019-02-13 03:49:43 -0600375 uint32_t transferHandle = 0x0;
376 uint32_t retTransferHandle = 0x0;
377 uint8_t flag = PLDM_GET_FIRSTPART;
378 uint8_t retFlag = PLDM_GET_FIRSTPART;
379 uint8_t pldmType = PLDM_BASE;
380 uint8_t retType = PLDM_BASE;
381
Zahed Hossain223a73d2019-07-04 12:46:18 -0500382 memcpy(requestMsg.data() + hdrSize, &transferHandle,
383 sizeof(transferHandle));
384 memcpy(requestMsg.data() + sizeof(transferHandle) + hdrSize, &flag,
385 sizeof(flag));
386 memcpy(requestMsg.data() + sizeof(transferHandle) + sizeof(flag) + hdrSize,
387 &pldmType, sizeof(pldmType));
Sampa Misra432e1872019-02-13 03:49:43 -0600388
Zahed Hossain223a73d2019-07-04 12:46:18 -0500389 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
390
391 auto rc = decode_get_version_req(request, requestMsg.size() - hdrSize,
vkaverapa6575b82019-04-03 05:33:52 -0500392 &retTransferHandle, &retFlag, &retType);
Sampa Misra432e1872019-02-13 03:49:43 -0600393
394 ASSERT_EQ(rc, PLDM_SUCCESS);
395 ASSERT_EQ(transferHandle, retTransferHandle);
396 ASSERT_EQ(flag, retFlag);
397 ASSERT_EQ(pldmType, retType);
398}
399
400TEST(GetPLDMVersion, testDecodeResponse)
401{
Zahed Hossain223a73d2019-07-04 12:46:18 -0500402 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_VERSION_RESP_BYTES>
403 responseMsg{};
Sampa Misra432e1872019-02-13 03:49:43 -0600404 uint32_t transferHandle = 0x0;
405 uint32_t retTransferHandle = 0x0;
406 uint8_t flag = PLDM_START_AND_END;
407 uint8_t retFlag = PLDM_START_AND_END;
408 uint8_t completionCode = 0;
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600409 ver32_t version = {0xFF, 0xFF, 0xFF, 0xFF};
410 ver32_t versionOut;
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600411 uint8_t completion_code;
Sampa Misra432e1872019-02-13 03:49:43 -0600412
Zahed Hossain223a73d2019-07-04 12:46:18 -0500413 memcpy(responseMsg.data() + sizeof(completionCode) + hdrSize,
414 &transferHandle, sizeof(transferHandle));
415 memcpy(responseMsg.data() + sizeof(completionCode) +
416 sizeof(transferHandle) + hdrSize,
Sampa Misra432e1872019-02-13 03:49:43 -0600417 &flag, sizeof(flag));
vkaverapa6575b82019-04-03 05:33:52 -0500418 memcpy(responseMsg.data() + sizeof(completionCode) +
Zahed Hossain223a73d2019-07-04 12:46:18 -0500419 sizeof(transferHandle) + sizeof(flag) + hdrSize,
Sampa Misra432e1872019-02-13 03:49:43 -0600420 &version, sizeof(version));
421
Zahed Hossain223a73d2019-07-04 12:46:18 -0500422 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
423
424 auto rc = decode_get_version_resp(response, responseMsg.size() - hdrSize,
vkaverapa6575b82019-04-03 05:33:52 -0500425 &completion_code, &retTransferHandle,
426 &retFlag, &versionOut);
Sampa Misra432e1872019-02-13 03:49:43 -0600427 ASSERT_EQ(rc, PLDM_SUCCESS);
428 ASSERT_EQ(transferHandle, retTransferHandle);
429 ASSERT_EQ(flag, retFlag);
430
431 ASSERT_EQ(versionOut.major, version.major);
432 ASSERT_EQ(versionOut.minor, version.minor);
433 ASSERT_EQ(versionOut.update, version.update);
434 ASSERT_EQ(versionOut.alpha, version.alpha);
435}
John Wang5c4f80d2019-07-29 11:12:18 +0800436
437TEST(GetTID, testEncodeResponse)
438{
439 uint8_t completionCode = 0;
440 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_TID_RESP_BYTES>
441 responseMsg{};
442 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
443 uint8_t tid = 1;
444
445 auto rc = encode_get_tid_resp(0, PLDM_SUCCESS, tid, response);
446 ASSERT_EQ(rc, PLDM_SUCCESS);
447 uint8_t* payload = response->payload;
448 ASSERT_EQ(completionCode, payload[0]);
449 ASSERT_EQ(1, payload[sizeof(completionCode)]);
450}
451
452TEST(GetTID, testDecodeResponse)
453{
454 std::array<uint8_t, hdrSize + PLDM_GET_TID_RESP_BYTES> responseMsg{};
455 responseMsg[1 + hdrSize] = 1;
456
457 uint8_t tid;
458 uint8_t completion_code;
459
460 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
461
462 auto rc = decode_get_tid_resp(response, responseMsg.size() - hdrSize,
463 &completion_code, &tid);
464
465 ASSERT_EQ(rc, PLDM_SUCCESS);
466 ASSERT_EQ(completion_code, PLDM_SUCCESS);
467 ASSERT_EQ(tid, 1);
468}