blob: cb0ec5a6cb13ff94829a900484aabe084260f6e7 [file] [log] [blame]
gokulsanker138ceba2021-04-05 13:25:25 +05301#include "libpldm/base.h"
2#include "libpldm/firmware_update.h"
3
4#include <gtest/gtest.h>
5
6constexpr auto hdrSize = sizeof(pldm_msg_hdr);
7
8TEST(QueryDeviceIdentifiers, goodPathEncodeRequest)
9{
10 std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
11 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
12
13 uint8_t instanceId = 0x01;
14
15 auto rc = encode_query_device_identifiers_req(
16 instanceId, PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES, requestPtr);
17 EXPECT_EQ(rc, PLDM_SUCCESS);
18 EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
19 EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
20 EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
21 EXPECT_EQ(requestPtr->hdr.command, PLDM_QUERY_DEVICE_IDENTIFIERS);
22}
gokulsankereca3e192021-04-05 14:57:41 +053023
24TEST(QueryDeviceIdentifiers, goodPathDecodeResponse)
25{
26 // descriptorDataLen is not fixed here taking it as 6
27 constexpr uint8_t descriptorDataLen = 6;
28 std::array<uint8_t, hdrSize +
29 sizeof(struct pldm_query_device_identifiers_resp) +
30 descriptorDataLen>
31 responseMsg{};
32 auto inResp = reinterpret_cast<struct pldm_query_device_identifiers_resp*>(
33 responseMsg.data() + hdrSize);
34
35 inResp->completion_code = PLDM_SUCCESS;
36 inResp->device_identifiers_len = htole32(descriptorDataLen);
37 inResp->descriptor_count = 1;
38
39 // filling descriptor data
40 std::fill_n(responseMsg.data() + hdrSize +
41 sizeof(struct pldm_query_device_identifiers_resp),
42 descriptorDataLen, 0xFF);
43
44 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
45 uint8_t completionCode = PLDM_SUCCESS;
46 uint32_t deviceIdentifiersLen = 0;
47 uint8_t descriptorCount = 0;
48 uint8_t* outDescriptorData = nullptr;
49
50 auto rc = decode_query_device_identifiers_resp(
51 response, responseMsg.size() - hdrSize, &completionCode,
52 &deviceIdentifiersLen, &descriptorCount, &outDescriptorData);
53
54 EXPECT_EQ(rc, PLDM_SUCCESS);
55 EXPECT_EQ(completionCode, PLDM_SUCCESS);
56 EXPECT_EQ(deviceIdentifiersLen, inResp->device_identifiers_len);
57 EXPECT_EQ(descriptorCount, inResp->descriptor_count);
58 EXPECT_EQ(true,
59 std::equal(outDescriptorData,
60 outDescriptorData + deviceIdentifiersLen,
61 responseMsg.begin() + hdrSize +
62 sizeof(struct pldm_query_device_identifiers_resp),
63 responseMsg.end()));
64}
gokulsanker981fbfb2021-04-05 15:17:25 +053065
66TEST(GetFirmwareParameters, goodPathEncodeRequest)
67{
68 std::array<uint8_t, sizeof(pldm_msg_hdr)> requestMsg{};
69 auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
70 uint8_t instanceId = 0x01;
71
72 auto rc = encode_get_firmware_parameters_req(
73 instanceId, PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES, requestPtr);
74 EXPECT_EQ(rc, PLDM_SUCCESS);
75 EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
76 EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
77 EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
78 EXPECT_EQ(requestPtr->hdr.command, PLDM_GET_FIRMWARE_PARAMETERS);
79}