148761c62SAndrew Jeffery #include <endian.h>
248761c62SAndrew Jeffery #include <libpldm/base.h>
348761c62SAndrew Jeffery #include <libpldm/oem/ibm/host.h>
448761c62SAndrew Jeffery
548761c62SAndrew Jeffery #include <array>
648761c62SAndrew Jeffery #include <cstdint>
748761c62SAndrew Jeffery #include <cstring>
8*7a3c14ecSAndrew Jeffery #include <new>
948761c62SAndrew Jeffery #include <vector>
1048761c62SAndrew Jeffery
11*7a3c14ecSAndrew Jeffery #include <gmock/gmock.h>
1248761c62SAndrew Jeffery #include <gtest/gtest.h>
1348761c62SAndrew Jeffery
TEST(GetAlertStatus,testGoodEncodeRequest)1448761c62SAndrew Jeffery TEST(GetAlertStatus, testGoodEncodeRequest)
1548761c62SAndrew Jeffery {
16*7a3c14ecSAndrew Jeffery PLDM_MSG_DEFINE_P(request, PLDM_GET_ALERT_STATUS_REQ_BYTES);
1748761c62SAndrew Jeffery
1848761c62SAndrew Jeffery uint8_t versionId = 0x0;
1948761c62SAndrew Jeffery
2048761c62SAndrew Jeffery auto rc = encode_get_alert_status_req(0, versionId, request,
2148761c62SAndrew Jeffery PLDM_GET_ALERT_STATUS_REQ_BYTES);
2248761c62SAndrew Jeffery EXPECT_EQ(rc, PLDM_SUCCESS);
2348761c62SAndrew Jeffery EXPECT_EQ(versionId, request->payload[0]);
2448761c62SAndrew Jeffery }
2548761c62SAndrew Jeffery
TEST(GetAlertStatus,testBadEncodeRequest)2648761c62SAndrew Jeffery TEST(GetAlertStatus, testBadEncodeRequest)
2748761c62SAndrew Jeffery {
28*7a3c14ecSAndrew Jeffery PLDM_MSG_DEFINE_P(request, PLDM_GET_ALERT_STATUS_REQ_BYTES);
2948761c62SAndrew Jeffery auto rc = encode_get_alert_status_req(0, 0x0, request,
3048761c62SAndrew Jeffery PLDM_GET_ALERT_STATUS_REQ_BYTES + 1);
3148761c62SAndrew Jeffery EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
3248761c62SAndrew Jeffery }
3348761c62SAndrew Jeffery
TEST(GetAlertStatus,testGoodDecodeResponse)3448761c62SAndrew Jeffery TEST(GetAlertStatus, testGoodDecodeResponse)
3548761c62SAndrew Jeffery {
3648761c62SAndrew Jeffery uint8_t completionCode = PLDM_SUCCESS;
3748761c62SAndrew Jeffery uint32_t rack_entry = 0xff000030;
3848761c62SAndrew Jeffery uint32_t pri_cec_node = 0x00008030;
39*7a3c14ecSAndrew Jeffery
40*7a3c14ecSAndrew Jeffery PLDM_MSG_DEFINE_P(response, PLDM_GET_ALERT_STATUS_RESP_BYTES);
41*7a3c14ecSAndrew Jeffery auto* resp = new (response->payload) pldm_get_alert_status_resp;
42*7a3c14ecSAndrew Jeffery resp->completion_code = completionCode;
43*7a3c14ecSAndrew Jeffery resp->rack_entry = htole32(rack_entry);
44*7a3c14ecSAndrew Jeffery resp->pri_cec_node = htole32(pri_cec_node);
4548761c62SAndrew Jeffery
4648761c62SAndrew Jeffery uint8_t retCompletionCode = 0;
4748761c62SAndrew Jeffery uint32_t retRack_entry = 0;
4848761c62SAndrew Jeffery uint32_t retPri_cec_node = 0;
4948761c62SAndrew Jeffery
5048761c62SAndrew Jeffery auto rc = decode_get_alert_status_resp(
51*7a3c14ecSAndrew Jeffery response, PLDM_GET_ALERT_STATUS_RESP_BYTES, &retCompletionCode,
5248761c62SAndrew Jeffery &retRack_entry, &retPri_cec_node);
5348761c62SAndrew Jeffery EXPECT_EQ(rc, PLDM_SUCCESS);
5448761c62SAndrew Jeffery EXPECT_EQ(retCompletionCode, completionCode);
5548761c62SAndrew Jeffery EXPECT_EQ(retRack_entry, rack_entry);
5648761c62SAndrew Jeffery EXPECT_EQ(retPri_cec_node, pri_cec_node);
5748761c62SAndrew Jeffery }
5848761c62SAndrew Jeffery
TEST(GetAlertStatus,testBadDecodeResponse)5948761c62SAndrew Jeffery TEST(GetAlertStatus, testBadDecodeResponse)
6048761c62SAndrew Jeffery {
6148761c62SAndrew Jeffery auto rc = decode_get_alert_status_resp(NULL, 0, NULL, NULL, NULL);
6248761c62SAndrew Jeffery EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
6348761c62SAndrew Jeffery
6448761c62SAndrew Jeffery uint8_t completionCode = PLDM_SUCCESS;
6548761c62SAndrew Jeffery uint32_t rack_entry = 0xff000030;
6648761c62SAndrew Jeffery uint32_t pri_cec_node = 0x00008030;
67*7a3c14ecSAndrew Jeffery
68*7a3c14ecSAndrew Jeffery PLDM_MSG_DEFINE_P(response, PLDM_GET_ALERT_STATUS_RESP_BYTES);
69*7a3c14ecSAndrew Jeffery auto* resp = new (response->payload) pldm_get_alert_status_resp;
70*7a3c14ecSAndrew Jeffery resp->completion_code = completionCode;
71*7a3c14ecSAndrew Jeffery resp->rack_entry = htole32(rack_entry);
72*7a3c14ecSAndrew Jeffery resp->pri_cec_node = htole32(pri_cec_node);
7348761c62SAndrew Jeffery
7448761c62SAndrew Jeffery uint8_t retCompletionCode = 0;
7548761c62SAndrew Jeffery uint32_t retRack_entry = 0;
7648761c62SAndrew Jeffery uint32_t retPri_cec_node = 0;
7748761c62SAndrew Jeffery
7848761c62SAndrew Jeffery rc = decode_get_alert_status_resp(
79*7a3c14ecSAndrew Jeffery response, PLDM_GET_ALERT_STATUS_RESP_BYTES + 1, &retCompletionCode,
8048761c62SAndrew Jeffery &retRack_entry, &retPri_cec_node);
8148761c62SAndrew Jeffery EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
8248761c62SAndrew Jeffery }
8348761c62SAndrew Jeffery
TEST(GetAlertStatus,testGoodEncodeResponse)8448761c62SAndrew Jeffery TEST(GetAlertStatus, testGoodEncodeResponse)
8548761c62SAndrew Jeffery {
8648761c62SAndrew Jeffery uint32_t rack_entry = 0xff000030;
8748761c62SAndrew Jeffery uint32_t pri_cec_node = 0x00008030;
8848761c62SAndrew Jeffery
89*7a3c14ecSAndrew Jeffery PLDM_MSG_DEFINE_P(response, PLDM_GET_ALERT_STATUS_RESP_BYTES);
90*7a3c14ecSAndrew Jeffery
91*7a3c14ecSAndrew Jeffery auto rc = encode_get_alert_status_resp(0, PLDM_SUCCESS, rack_entry,
92*7a3c14ecSAndrew Jeffery pri_cec_node, response,
9348761c62SAndrew Jeffery PLDM_GET_ALERT_STATUS_RESP_BYTES);
9448761c62SAndrew Jeffery
95*7a3c14ecSAndrew Jeffery ASSERT_EQ(rc, PLDM_SUCCESS);
96*7a3c14ecSAndrew Jeffery EXPECT_THAT(response_buf, testing::ElementsAreArray(
97*7a3c14ecSAndrew Jeffery {0x00, 0x3f, 0xf0, 0x00, 0x30, 0x00, 0x00,
98*7a3c14ecSAndrew Jeffery 0xff, 0x30, 0x80, 0x00, 0x00}));
9948761c62SAndrew Jeffery }
10048761c62SAndrew Jeffery
TEST(GetAlertStatus,testBadEncodeResponse)10148761c62SAndrew Jeffery TEST(GetAlertStatus, testBadEncodeResponse)
10248761c62SAndrew Jeffery {
10348761c62SAndrew Jeffery uint32_t rack_entry = 0xff000030;
10448761c62SAndrew Jeffery uint32_t pri_cec_node = 0x00008030;
10548761c62SAndrew Jeffery
106*7a3c14ecSAndrew Jeffery PLDM_MSG_DEFINE_P(response, PLDM_GET_ALERT_STATUS_RESP_BYTES);
10748761c62SAndrew Jeffery
108*7a3c14ecSAndrew Jeffery auto rc = encode_get_alert_status_resp(
109*7a3c14ecSAndrew Jeffery 0, PLDM_SUCCESS, rack_entry, pri_cec_node, response,
110*7a3c14ecSAndrew Jeffery PLDM_GET_ALERT_STATUS_RESP_BYTES + 1);
11148761c62SAndrew Jeffery
11248761c62SAndrew Jeffery EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
11348761c62SAndrew Jeffery }
11448761c62SAndrew Jeffery
TEST(GetAlertStatus,testGoodDecodeRequest)11548761c62SAndrew Jeffery TEST(GetAlertStatus, testGoodDecodeRequest)
11648761c62SAndrew Jeffery {
11748761c62SAndrew Jeffery uint8_t versionId = 0x0;
11848761c62SAndrew Jeffery uint8_t retVersionId;
11948761c62SAndrew Jeffery
120*7a3c14ecSAndrew Jeffery PLDM_MSG_DEFINE_P(req, PLDM_GET_ALERT_STATUS_REQ_BYTES);
12148761c62SAndrew Jeffery req->payload[0] = versionId;
12248761c62SAndrew Jeffery
123*7a3c14ecSAndrew Jeffery auto rc = decode_get_alert_status_req(req, PLDM_GET_ALERT_STATUS_REQ_BYTES,
12448761c62SAndrew Jeffery &retVersionId);
12548761c62SAndrew Jeffery
12648761c62SAndrew Jeffery EXPECT_EQ(rc, PLDM_SUCCESS);
12748761c62SAndrew Jeffery EXPECT_EQ(retVersionId, versionId);
12848761c62SAndrew Jeffery }
12948761c62SAndrew Jeffery
TEST(GetAlertStatus,testBadDecodeRequest)13048761c62SAndrew Jeffery TEST(GetAlertStatus, testBadDecodeRequest)
13148761c62SAndrew Jeffery {
13248761c62SAndrew Jeffery uint8_t versionId = 0x0;
13348761c62SAndrew Jeffery uint8_t retVersionId;
13448761c62SAndrew Jeffery
135*7a3c14ecSAndrew Jeffery PLDM_MSG_DEFINE_P(req, PLDM_GET_ALERT_STATUS_REQ_BYTES);
13648761c62SAndrew Jeffery req->payload[0] = versionId;
13748761c62SAndrew Jeffery
138*7a3c14ecSAndrew Jeffery auto rc = decode_get_alert_status_req(
139*7a3c14ecSAndrew Jeffery req, PLDM_GET_ALERT_STATUS_REQ_BYTES + 1, &retVersionId);
14048761c62SAndrew Jeffery
14148761c62SAndrew Jeffery EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
14248761c62SAndrew Jeffery }
143