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 | |
| 6 | #include <gtest/gtest.h> |
| 7 | |
| 8 | namespace blobs |
| 9 | { |
| 10 | |
| 11 | using ::testing::ElementsAreArray; |
| 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(BlobWriteTest, ManagerReturnsFailureReturnsFailure) |
| 19 | { |
| 20 | // This verifies a failure from the manager is passed back. |
| 21 | |
| 22 | ManagerMock mgr; |
| 23 | size_t dataLen; |
| 24 | uint8_t request[MAX_IPMI_BUFFER] = {0}; |
| 25 | uint8_t reply[MAX_IPMI_BUFFER] = {0}; |
| 26 | auto req = reinterpret_cast<struct BmcBlobWriteTx*>(request); |
| 27 | |
Patrick Venture | 00d5f0d | 2019-05-17 19:21:35 -0700 | [diff] [blame^] | 28 | req->cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobWrite); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 29 | req->crc = 0; |
| 30 | req->sessionId = 0x54; |
| 31 | req->offset = 0x100; |
| 32 | |
| 33 | uint8_t expectedBytes[2] = {0x66, 0x67}; |
| 34 | std::memcpy(req->data, &expectedBytes[0], sizeof(expectedBytes)); |
| 35 | |
| 36 | dataLen = sizeof(struct BmcBlobWriteTx) + sizeof(expectedBytes); |
| 37 | |
| 38 | EXPECT_CALL(mgr, |
| 39 | write(req->sessionId, req->offset, |
| 40 | ElementsAreArray(expectedBytes, sizeof(expectedBytes)))) |
| 41 | .WillOnce(Return(false)); |
| 42 | |
Patrick Venture | 4125880 | 2018-11-12 10:46:30 -0800 | [diff] [blame] | 43 | EXPECT_EQ(IPMI_CC_UNSPECIFIED_ERROR, |
| 44 | writeBlob(&mgr, request, reply, &dataLen)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | TEST(BlobWriteTest, ManagerReturnsTrueWriteSucceeds) |
| 48 | { |
| 49 | // The case where everything works. |
| 50 | |
| 51 | ManagerMock mgr; |
| 52 | size_t dataLen; |
| 53 | uint8_t request[MAX_IPMI_BUFFER] = {0}; |
| 54 | uint8_t reply[MAX_IPMI_BUFFER] = {0}; |
| 55 | auto req = reinterpret_cast<struct BmcBlobWriteTx*>(request); |
| 56 | |
Patrick Venture | 00d5f0d | 2019-05-17 19:21:35 -0700 | [diff] [blame^] | 57 | req->cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobWrite); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 58 | req->crc = 0; |
| 59 | req->sessionId = 0x54; |
| 60 | req->offset = 0x100; |
| 61 | |
| 62 | uint8_t expectedBytes[2] = {0x66, 0x67}; |
| 63 | std::memcpy(req->data, &expectedBytes[0], sizeof(expectedBytes)); |
| 64 | |
| 65 | dataLen = sizeof(struct BmcBlobWriteTx) + sizeof(expectedBytes); |
| 66 | |
| 67 | EXPECT_CALL(mgr, |
| 68 | write(req->sessionId, req->offset, |
| 69 | ElementsAreArray(expectedBytes, sizeof(expectedBytes)))) |
| 70 | .WillOnce(Return(true)); |
| 71 | |
| 72 | EXPECT_EQ(IPMI_CC_OK, writeBlob(&mgr, request, reply, &dataLen)); |
| 73 | } |
| 74 | } // namespace blobs |