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