Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 1 | #include "ipmi.hpp" |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 2 | |
Patrick Venture | 7210b31 | 2018-10-03 14:01:35 -0700 | [diff] [blame] | 3 | #include <blobs-ipmid/test/manager_mock.hpp> |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 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)); |
Patrick Venture | 4125880 | 2018-11-12 10:46:30 -0800 | [diff] [blame] | 41 | EXPECT_EQ(IPMI_CC_UNSPECIFIED_ERROR, |
| 42 | closeBlob(&mgr, request, reply, &dataLen)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | TEST(BlobCloseTest, BlobClosedReturnsSuccess) |
| 46 | { |
| 47 | // Verify that if all goes right, success is returned. |
| 48 | |
| 49 | ManagerMock mgr; |
| 50 | uint16_t sessionId = 0x54; |
| 51 | size_t dataLen; |
| 52 | uint8_t request[MAX_IPMI_BUFFER] = {0}; |
| 53 | uint8_t reply[MAX_IPMI_BUFFER] = {0}; |
| 54 | struct BmcBlobCloseTx req; |
| 55 | |
| 56 | req.cmd = BlobOEMCommands::bmcBlobClose; |
| 57 | req.crc = 0; |
| 58 | req.sessionId = sessionId; |
| 59 | |
| 60 | dataLen = sizeof(req); |
| 61 | |
| 62 | std::memcpy(request, &req, sizeof(req)); |
| 63 | |
| 64 | EXPECT_CALL(mgr, close(sessionId)).WillOnce(Return(true)); |
| 65 | EXPECT_EQ(IPMI_CC_OK, closeBlob(&mgr, request, reply, &dataLen)); |
| 66 | } |
| 67 | } // namespace blobs |