Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 1 | #include "ipmi.hpp" |
Patrick Venture | cd8dab4 | 2019-01-15 19:57:38 -0800 | [diff] [blame] | 2 | #include "manager_mock.hpp" |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 3 | |
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 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 12 | using ::testing::Return; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 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 | |
Patrick Venture | 00d5f0d | 2019-05-17 19:21:35 -0700 | [diff] [blame] | 29 | req.cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobClose); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 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)); |
Patrick Venture | 4125880 | 2018-11-12 10:46:30 -0800 | [diff] [blame] | 38 | EXPECT_EQ(IPMI_CC_UNSPECIFIED_ERROR, |
| 39 | closeBlob(&mgr, request, reply, &dataLen)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 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 | |
Patrick Venture | 00d5f0d | 2019-05-17 19:21:35 -0700 | [diff] [blame] | 53 | req.cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobClose); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 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 |