1 #include "ipmi.hpp" 2 #include "manager_mock.hpp" 3 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 28 req->cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobWrite); 29 req->crc = 0; 30 req->sessionId = 0x54; 31 req->offset = 0x100; 32 33 uint8_t expectedBytes[2] = {0x66, 0x67}; 34 std::memcpy(req + 1, &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 43 EXPECT_EQ(IPMI_CC_UNSPECIFIED_ERROR, 44 writeBlob(&mgr, request, reply, &dataLen)); 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 57 req->cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobWrite); 58 req->crc = 0; 59 req->sessionId = 0x54; 60 req->offset = 0x100; 61 62 uint8_t expectedBytes[2] = {0x66, 0x67}; 63 std::memcpy(req + 1, &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 75