blob: 6596f35ae473b4af085155cde00f16f3bcbd1c16 [file] [log] [blame]
George Liu9008d282020-03-12 11:20:35 +08001#include <string.h>
2
3#include <array>
4
5#include "oem/ibm/libpldm/host.h"
6
7#include <gtest/gtest.h>
8
9constexpr auto hdrSize = sizeof(pldm_msg_hdr);
10
11TEST(GetAlertStatus, testGoodEncodeRequest)
12{
13 std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_REQ_BYTES> requestMsg{};
14
15 uint8_t versionId = 0x0;
16
17 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
18 auto rc = encode_get_alert_status_req(0, versionId, request,
19 PLDM_GET_ALERT_STATUS_REQ_BYTES);
20 EXPECT_EQ(rc, PLDM_SUCCESS);
21 EXPECT_EQ(versionId, request->payload[0]);
22}
23
24TEST(GetAlertStatus, testBadEncodeRequest)
25{
26 std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_REQ_BYTES> requestMsg{};
27
28 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
29 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;
37 uint32_t rack_entry = 0xFF000030;
38 uint32_t pri_cec_node = 0x00008030;
39 std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_RESP_BYTES>
40 responseMsg{};
41
42 uint8_t retCompletionCode = 0;
43 uint32_t retRack_entry = 0;
44 uint32_t retPri_cec_node = 0;
45
46 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
47 struct pldm_get_alert_status_resp* resp =
48 reinterpret_cast<struct pldm_get_alert_status_resp*>(response->payload);
49 resp->completion_code = completionCode;
50 resp->rack_entry = htole32(rack_entry);
51 resp->pri_cec_node = htole32(pri_cec_node);
52
53 auto rc = decode_get_alert_status_resp(
54 response, responseMsg.size() - hdrSize, &retCompletionCode,
55 &retRack_entry, &retPri_cec_node);
56 EXPECT_EQ(rc, PLDM_SUCCESS);
57 EXPECT_EQ(retCompletionCode, completionCode);
58 EXPECT_EQ(retRack_entry, rack_entry);
59 EXPECT_EQ(retPri_cec_node, pri_cec_node);
60}
61
62TEST(GetAlertStatus, testBadDecodeResponse)
63{
64 auto rc = decode_get_alert_status_resp(NULL, 0, NULL, NULL, NULL);
65 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
66
67 uint8_t completionCode = PLDM_SUCCESS;
68 uint32_t rack_entry = 0xFF000030;
69 uint32_t pri_cec_node = 0x00008030;
70 std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_RESP_BYTES>
71 responseMsg{};
72
73 uint8_t retCompletionCode = 0;
74 uint32_t retRack_entry = 0;
75 uint32_t retPri_cec_node = 0;
76
77 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
78 struct pldm_get_alert_status_resp* resp =
79 reinterpret_cast<struct pldm_get_alert_status_resp*>(response->payload);
80 resp->completion_code = completionCode;
81 resp->rack_entry = htole32(rack_entry);
82 resp->pri_cec_node = htole32(pri_cec_node);
83
84 rc = decode_get_alert_status_resp(
85 response, responseMsg.size() - hdrSize + 1, &retCompletionCode,
86 &retRack_entry, &retPri_cec_node);
87 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
88}