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