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::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(BlobEnumerateTest, VerifyIfRequestByIdInvalidReturnsFailure) 19 { 20 // This tests to verify that if the index is invalid, it'll return failure. 21 22 ManagerMock mgr; 23 size_t dataLen; 24 uint8_t reply[MAX_IPMI_BUFFER] = {0}; 25 struct BmcBlobEnumerateTx req; 26 uint8_t* request = reinterpret_cast<uint8_t*>(&req); 27 28 req.cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate); 29 req.blobIdx = 0; 30 dataLen = sizeof(struct BmcBlobEnumerateTx); 31 32 EXPECT_CALL(mgr, getBlobId(req.blobIdx)).WillOnce(Return("")); 33 34 EXPECT_EQ(IPMI_CC_INVALID_FIELD_REQUEST, 35 enumerateBlob(&mgr, request, reply, &dataLen)); 36 } 37 38 TEST(BlobEnumerateTest, BoringRequestByIdAndReceive) 39 { 40 // This tests that if an index into the blob_id cache is valid, the command 41 // will return the blobId. 42 43 ManagerMock mgr; 44 size_t dataLen; 45 uint8_t reply[MAX_IPMI_BUFFER] = {0}; 46 struct BmcBlobEnumerateTx req; 47 struct BmcBlobEnumerateRx* rep; 48 uint8_t* request = reinterpret_cast<uint8_t*>(&req); 49 std::string blobId = "/asdf"; 50 51 req.cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate); 52 req.blobIdx = 0; 53 dataLen = sizeof(struct BmcBlobEnumerateTx); 54 55 EXPECT_CALL(mgr, getBlobId(req.blobIdx)).WillOnce(Return(blobId)); 56 57 EXPECT_EQ(IPMI_CC_OK, enumerateBlob(&mgr, request, reply, &dataLen)); 58 59 // We're expecting this as a response. 60 // blobId.length + 1 + sizeof(uint16_t); 61 EXPECT_EQ(blobId.length() + 1 + sizeof(uint16_t), dataLen); 62 63 rep = reinterpret_cast<struct BmcBlobEnumerateRx*>(reply); 64 EXPECT_EQ(0, std::memcmp(rep + 1, blobId.c_str(), blobId.length() + 1)); 65 } 66 } // namespace blobs 67