1 #include "ipmi.hpp"
2 #include "manager_mock.hpp"
3 
4 #include <cstring>
5 #include <string>
6 
7 #include <gtest/gtest.h>
8 
9 namespace blobs
10 {
11 
12 using ::testing::Return;
13 
14 // ipmid.hpp isn't installed where we can grab it and this value is per BMC
15 // SoC.
16 #define MAX_IPMI_BUFFER 64
17 
18 TEST(BlobCloseTest, ManagerRejectsCloseReturnsFailure)
19 {
20     // The session manager returned failure to close, which we need to pass on.
21 
22     ManagerMock mgr;
23     uint16_t sessionId = 0x54;
24     size_t dataLen;
25     uint8_t request[MAX_IPMI_BUFFER] = {0};
26     uint8_t reply[MAX_IPMI_BUFFER] = {0};
27     struct BmcBlobCloseTx req;
28 
29     req.cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobClose);
30     req.crc = 0;
31     req.sessionId = sessionId;
32 
33     dataLen = sizeof(req);
34 
35     std::memcpy(request, &req, sizeof(req));
36 
37     EXPECT_CALL(mgr, close(sessionId)).WillOnce(Return(false));
38     EXPECT_EQ(IPMI_CC_UNSPECIFIED_ERROR,
39               closeBlob(&mgr, request, reply, &dataLen));
40 }
41 
42 TEST(BlobCloseTest, BlobClosedReturnsSuccess)
43 {
44     // Verify that if all goes right, success is returned.
45 
46     ManagerMock mgr;
47     uint16_t sessionId = 0x54;
48     size_t dataLen;
49     uint8_t request[MAX_IPMI_BUFFER] = {0};
50     uint8_t reply[MAX_IPMI_BUFFER] = {0};
51     struct BmcBlobCloseTx req;
52 
53     req.cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobClose);
54     req.crc = 0;
55     req.sessionId = sessionId;
56 
57     dataLen = sizeof(req);
58 
59     std::memcpy(request, &req, sizeof(req));
60 
61     EXPECT_CALL(mgr, close(sessionId)).WillOnce(Return(true));
62     EXPECT_EQ(IPMI_CC_OK, closeBlob(&mgr, request, reply, &dataLen));
63 }
64 } // namespace blobs
65