blob: 628c12354b8c7d354f323eb30aecf2024dc9e4c3 [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>
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +09308#include <new>
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05309#include <vector>
Andrew Jeffery9c766792022-08-10 23:12:49 +093010
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +093011#include <gmock/gmock.h>
Andrew Jeffery9c766792022-08-10 23:12:49 +093012#include <gtest/gtest.h>
13
Andrew Jeffery9c766792022-08-10 23:12:49 +093014TEST(GetAlertStatus, testGoodEncodeRequest)
15{
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +093016 PLDM_MSG_DEFINE_P(request, PLDM_GET_ALERT_STATUS_REQ_BYTES);
Andrew Jeffery9c766792022-08-10 23:12:49 +093017
18 uint8_t versionId = 0x0;
19
Andrew Jeffery9c766792022-08-10 23:12:49 +093020 auto rc = encode_get_alert_status_req(0, versionId, request,
21 PLDM_GET_ALERT_STATUS_REQ_BYTES);
22 EXPECT_EQ(rc, PLDM_SUCCESS);
23 EXPECT_EQ(versionId, request->payload[0]);
24}
25
26TEST(GetAlertStatus, testBadEncodeRequest)
27{
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +093028 PLDM_MSG_DEFINE_P(request, PLDM_GET_ALERT_STATUS_REQ_BYTES);
Andrew Jeffery9c766792022-08-10 23:12:49 +093029 auto rc = encode_get_alert_status_req(0, 0x0, request,
30 PLDM_GET_ALERT_STATUS_REQ_BYTES + 1);
31 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
32}
33
34TEST(GetAlertStatus, testGoodDecodeResponse)
35{
36 uint8_t completionCode = PLDM_SUCCESS;
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -060037 uint32_t rack_entry = 0xff000030;
Andrew Jeffery9c766792022-08-10 23:12:49 +093038 uint32_t pri_cec_node = 0x00008030;
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +093039
40 PLDM_MSG_DEFINE_P(response, PLDM_GET_ALERT_STATUS_RESP_BYTES);
41 auto* resp = new (response->payload) pldm_get_alert_status_resp;
42 resp->completion_code = completionCode;
43 resp->rack_entry = htole32(rack_entry);
44 resp->pri_cec_node = htole32(pri_cec_node);
Andrew Jeffery9c766792022-08-10 23:12:49 +093045
46 uint8_t retCompletionCode = 0;
47 uint32_t retRack_entry = 0;
48 uint32_t retPri_cec_node = 0;
49
Andrew Jeffery9c766792022-08-10 23:12:49 +093050 auto rc = decode_get_alert_status_resp(
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +093051 response, PLDM_GET_ALERT_STATUS_RESP_BYTES, &retCompletionCode,
Andrew Jeffery9c766792022-08-10 23:12:49 +093052 &retRack_entry, &retPri_cec_node);
53 EXPECT_EQ(rc, PLDM_SUCCESS);
54 EXPECT_EQ(retCompletionCode, completionCode);
55 EXPECT_EQ(retRack_entry, rack_entry);
56 EXPECT_EQ(retPri_cec_node, pri_cec_node);
57}
58
59TEST(GetAlertStatus, testBadDecodeResponse)
60{
61 auto rc = decode_get_alert_status_resp(NULL, 0, NULL, NULL, NULL);
62 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
63
64 uint8_t completionCode = PLDM_SUCCESS;
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -060065 uint32_t rack_entry = 0xff000030;
Andrew Jeffery9c766792022-08-10 23:12:49 +093066 uint32_t pri_cec_node = 0x00008030;
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +093067
68 PLDM_MSG_DEFINE_P(response, PLDM_GET_ALERT_STATUS_RESP_BYTES);
69 auto* resp = new (response->payload) pldm_get_alert_status_resp;
70 resp->completion_code = completionCode;
71 resp->rack_entry = htole32(rack_entry);
72 resp->pri_cec_node = htole32(pri_cec_node);
Andrew Jeffery9c766792022-08-10 23:12:49 +093073
74 uint8_t retCompletionCode = 0;
75 uint32_t retRack_entry = 0;
76 uint32_t retPri_cec_node = 0;
77
Andrew Jeffery9c766792022-08-10 23:12:49 +093078 rc = decode_get_alert_status_resp(
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +093079 response, PLDM_GET_ALERT_STATUS_RESP_BYTES + 1, &retCompletionCode,
Andrew Jeffery9c766792022-08-10 23:12:49 +093080 &retRack_entry, &retPri_cec_node);
81 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
82}
83
84TEST(GetAlertStatus, testGoodEncodeResponse)
85{
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -060086 uint32_t rack_entry = 0xff000030;
Andrew Jeffery9c766792022-08-10 23:12:49 +093087 uint32_t pri_cec_node = 0x00008030;
88
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +093089 PLDM_MSG_DEFINE_P(response, PLDM_GET_ALERT_STATUS_RESP_BYTES);
Andrew Jeffery9c766792022-08-10 23:12:49 +093090
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +093091 auto rc = encode_get_alert_status_resp(0, PLDM_SUCCESS, rack_entry,
92 pri_cec_node, response,
93 PLDM_GET_ALERT_STATUS_RESP_BYTES);
Andrew Jeffery9c766792022-08-10 23:12:49 +093094
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +093095 ASSERT_EQ(rc, PLDM_SUCCESS);
96 EXPECT_THAT(response_buf, testing::ElementsAreArray(
97 {0x00, 0x3f, 0xf0, 0x00, 0x30, 0x00, 0x00,
98 0xff, 0x30, 0x80, 0x00, 0x00}));
Andrew Jeffery9c766792022-08-10 23:12:49 +093099}
100
101TEST(GetAlertStatus, testBadEncodeResponse)
102{
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -0600103 uint32_t rack_entry = 0xff000030;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930104 uint32_t pri_cec_node = 0x00008030;
105
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +0930106 PLDM_MSG_DEFINE_P(response, PLDM_GET_ALERT_STATUS_RESP_BYTES);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930107
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +0930108 auto rc = encode_get_alert_status_resp(
109 0, PLDM_SUCCESS, rack_entry, pri_cec_node, response,
110 PLDM_GET_ALERT_STATUS_RESP_BYTES + 1);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930111
112 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
113}
114
115TEST(GetAlertStatus, testGoodDecodeRequest)
116{
Andrew Jeffery9c766792022-08-10 23:12:49 +0930117 uint8_t versionId = 0x0;
118 uint8_t retVersionId;
119
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +0930120 PLDM_MSG_DEFINE_P(req, PLDM_GET_ALERT_STATUS_REQ_BYTES);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930121 req->payload[0] = versionId;
122
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +0930123 auto rc = decode_get_alert_status_req(req, PLDM_GET_ALERT_STATUS_REQ_BYTES,
Andrew Jeffery9c766792022-08-10 23:12:49 +0930124 &retVersionId);
125
126 EXPECT_EQ(rc, PLDM_SUCCESS);
127 EXPECT_EQ(retVersionId, versionId);
128}
129
130TEST(GetAlertStatus, testBadDecodeRequest)
131{
Andrew Jeffery9c766792022-08-10 23:12:49 +0930132 uint8_t versionId = 0x0;
133 uint8_t retVersionId;
134
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +0930135 PLDM_MSG_DEFINE_P(req, PLDM_GET_ALERT_STATUS_REQ_BYTES);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930136 req->payload[0] = versionId;
137
Andrew Jeffery7a3c14e2024-09-09 12:23:27 +0930138 auto rc = decode_get_alert_status_req(
139 req, PLDM_GET_ALERT_STATUS_REQ_BYTES + 1, &retVersionId);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930140
141 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
142}