blob: 2ab03b787170b0c46860643cd922800e8d7c4423 [file] [log] [blame]
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05301#include <endian.h>
Andrew Jeffery9c766792022-08-10 23:12:49 +09302#include <string.h>
3
4#include <array>
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05305#include <cstdint>
6#include <vector>
Andrew Jeffery9c766792022-08-10 23:12:49 +09307
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05308#include "base.h"
Andrew Jeffery9c766792022-08-10 23:12:49 +09309#include "oem/ibm/libpldm/host.h"
10
11#include <gtest/gtest.h>
12
13constexpr auto hdrSize = sizeof(pldm_msg_hdr);
14
15TEST(GetAlertStatus, testGoodEncodeRequest)
16{
17 std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_REQ_BYTES> requestMsg{};
18
19 uint8_t versionId = 0x0;
20
21 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
22 auto rc = encode_get_alert_status_req(0, versionId, request,
23 PLDM_GET_ALERT_STATUS_REQ_BYTES);
24 EXPECT_EQ(rc, PLDM_SUCCESS);
25 EXPECT_EQ(versionId, request->payload[0]);
26}
27
28TEST(GetAlertStatus, testBadEncodeRequest)
29{
30 std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_REQ_BYTES> requestMsg{};
31
32 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
33 auto rc = encode_get_alert_status_req(0, 0x0, request,
34 PLDM_GET_ALERT_STATUS_REQ_BYTES + 1);
35 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
36}
37
38TEST(GetAlertStatus, testGoodDecodeResponse)
39{
40 uint8_t completionCode = PLDM_SUCCESS;
41 uint32_t rack_entry = 0xFF000030;
42 uint32_t pri_cec_node = 0x00008030;
43 std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_RESP_BYTES>
44 responseMsg{};
45
46 uint8_t retCompletionCode = 0;
47 uint32_t retRack_entry = 0;
48 uint32_t retPri_cec_node = 0;
49
50 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
51 struct pldm_get_alert_status_resp* resp =
52 reinterpret_cast<struct pldm_get_alert_status_resp*>(response->payload);
53 resp->completion_code = completionCode;
54 resp->rack_entry = htole32(rack_entry);
55 resp->pri_cec_node = htole32(pri_cec_node);
56
57 auto rc = decode_get_alert_status_resp(
58 response, responseMsg.size() - hdrSize, &retCompletionCode,
59 &retRack_entry, &retPri_cec_node);
60 EXPECT_EQ(rc, PLDM_SUCCESS);
61 EXPECT_EQ(retCompletionCode, completionCode);
62 EXPECT_EQ(retRack_entry, rack_entry);
63 EXPECT_EQ(retPri_cec_node, pri_cec_node);
64}
65
66TEST(GetAlertStatus, testBadDecodeResponse)
67{
68 auto rc = decode_get_alert_status_resp(NULL, 0, NULL, NULL, NULL);
69 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
70
71 uint8_t completionCode = PLDM_SUCCESS;
72 uint32_t rack_entry = 0xFF000030;
73 uint32_t pri_cec_node = 0x00008030;
74 std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_RESP_BYTES>
75 responseMsg{};
76
77 uint8_t retCompletionCode = 0;
78 uint32_t retRack_entry = 0;
79 uint32_t retPri_cec_node = 0;
80
81 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
82 struct pldm_get_alert_status_resp* resp =
83 reinterpret_cast<struct pldm_get_alert_status_resp*>(response->payload);
84 resp->completion_code = completionCode;
85 resp->rack_entry = htole32(rack_entry);
86 resp->pri_cec_node = htole32(pri_cec_node);
87
88 rc = decode_get_alert_status_resp(
89 response, responseMsg.size() - hdrSize + 1, &retCompletionCode,
90 &retRack_entry, &retPri_cec_node);
91 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
92}
93
94TEST(GetAlertStatus, testGoodEncodeResponse)
95{
96 uint8_t completionCode = 0;
97 uint32_t rack_entry = 0xFF000030;
98 uint32_t pri_cec_node = 0x00008030;
99
100 std::vector<uint8_t> responseMsg(hdrSize +
101 PLDM_GET_ALERT_STATUS_RESP_BYTES);
102 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
103
104 auto rc =
105 encode_get_alert_status_resp(0, PLDM_SUCCESS, rack_entry, pri_cec_node,
106 response, responseMsg.size() - hdrSize);
107
108 EXPECT_EQ(rc, PLDM_SUCCESS);
109 struct pldm_get_alert_status_resp* resp =
110 reinterpret_cast<struct pldm_get_alert_status_resp*>(response->payload);
111
112 EXPECT_EQ(completionCode, resp->completion_code);
113 EXPECT_EQ(rack_entry, le32toh(resp->rack_entry));
114 EXPECT_EQ(pri_cec_node, le32toh(resp->pri_cec_node));
115}
116
117TEST(GetAlertStatus, testBadEncodeResponse)
118{
119 uint32_t rack_entry = 0xFF000030;
120 uint32_t pri_cec_node = 0x00008030;
121
122 std::vector<uint8_t> responseMsg(hdrSize +
123 PLDM_GET_ALERT_STATUS_RESP_BYTES);
124 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
125
126 auto rc = encode_get_alert_status_resp(0, PLDM_SUCCESS, rack_entry,
127 pri_cec_node, response,
128 responseMsg.size() - hdrSize + 1);
129
130 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
131}
132
133TEST(GetAlertStatus, testGoodDecodeRequest)
134{
135 std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_REQ_BYTES> requestMsg{};
136
137 uint8_t versionId = 0x0;
138 uint8_t retVersionId;
139
140 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
141
142 req->payload[0] = versionId;
143
144 auto rc = decode_get_alert_status_req(req, requestMsg.size() - hdrSize,
145 &retVersionId);
146
147 EXPECT_EQ(rc, PLDM_SUCCESS);
148 EXPECT_EQ(retVersionId, versionId);
149}
150
151TEST(GetAlertStatus, testBadDecodeRequest)
152{
153 std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_REQ_BYTES> requestMsg{};
154
155 uint8_t versionId = 0x0;
156 uint8_t retVersionId;
157
158 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
159
160 req->payload[0] = versionId;
161
162 auto rc = decode_get_alert_status_req(req, requestMsg.size() - hdrSize + 1,
163 &retVersionId);
164
165 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
166}