1ef3aeadcSPatrick Venture #include "ipmi.hpp" 2*cd8dab49SPatrick Venture #include "manager_mock.hpp" 3ef3aeadcSPatrick Venture 4ef3aeadcSPatrick Venture #include <cstring> 5ef3aeadcSPatrick Venture #include <vector> 6ef3aeadcSPatrick Venture 7ef3aeadcSPatrick Venture #include <gtest/gtest.h> 8ef3aeadcSPatrick Venture 9ef3aeadcSPatrick Venture namespace blobs 10ef3aeadcSPatrick Venture { 11ef3aeadcSPatrick Venture 12ef3aeadcSPatrick Venture using ::testing::Return; 13ef3aeadcSPatrick Venture 14ef3aeadcSPatrick Venture // ipmid.hpp isn't installed where we can grab it and this value is per BMC 15ef3aeadcSPatrick Venture // SoC. 16ef3aeadcSPatrick Venture #define MAX_IPMI_BUFFER 64 17ef3aeadcSPatrick Venture 18ef3aeadcSPatrick Venture TEST(BlobReadTest, ManagerReturnsNoData) 19ef3aeadcSPatrick Venture { 20ef3aeadcSPatrick Venture // Verify that if no data is returned the IPMI command reply has no 21ef3aeadcSPatrick Venture // payload. The manager, in all failures, will just return 0 bytes. 22ef3aeadcSPatrick Venture 23ef3aeadcSPatrick Venture ManagerMock mgr; 24ef3aeadcSPatrick Venture size_t dataLen; 25ef3aeadcSPatrick Venture uint8_t request[MAX_IPMI_BUFFER] = {0}; 26ef3aeadcSPatrick Venture uint8_t reply[MAX_IPMI_BUFFER] = {0}; 27ef3aeadcSPatrick Venture auto req = reinterpret_cast<struct BmcBlobReadTx*>(request); 28ef3aeadcSPatrick Venture 29ef3aeadcSPatrick Venture req->cmd = BlobOEMCommands::bmcBlobRead; 30ef3aeadcSPatrick Venture req->crc = 0; 31ef3aeadcSPatrick Venture req->sessionId = 0x54; 32ef3aeadcSPatrick Venture req->offset = 0x100; 33ef3aeadcSPatrick Venture req->requestedSize = 0x10; 34ef3aeadcSPatrick Venture 35ef3aeadcSPatrick Venture dataLen = sizeof(struct BmcBlobReadTx); 36ef3aeadcSPatrick Venture 37ef3aeadcSPatrick Venture std::vector<uint8_t> data; 38ef3aeadcSPatrick Venture 39ef3aeadcSPatrick Venture EXPECT_CALL(mgr, read(req->sessionId, req->offset, req->requestedSize)) 40ef3aeadcSPatrick Venture .WillOnce(Return(data)); 41ef3aeadcSPatrick Venture 42ef3aeadcSPatrick Venture EXPECT_EQ(IPMI_CC_OK, readBlob(&mgr, request, reply, &dataLen)); 43ef3aeadcSPatrick Venture EXPECT_EQ(sizeof(struct BmcBlobReadRx), dataLen); 44ef3aeadcSPatrick Venture } 45ef3aeadcSPatrick Venture 46ef3aeadcSPatrick Venture TEST(BlobReadTest, ManagerReturnsData) 47ef3aeadcSPatrick Venture { 48ef3aeadcSPatrick Venture // Verify that if data is returned, it's placed in the expected location. 49ef3aeadcSPatrick Venture 50ef3aeadcSPatrick Venture ManagerMock mgr; 51ef3aeadcSPatrick Venture size_t dataLen; 52ef3aeadcSPatrick Venture uint8_t request[MAX_IPMI_BUFFER] = {0}; 53ef3aeadcSPatrick Venture uint8_t reply[MAX_IPMI_BUFFER] = {0}; 54ef3aeadcSPatrick Venture auto req = reinterpret_cast<struct BmcBlobReadTx*>(request); 55ef3aeadcSPatrick Venture 56ef3aeadcSPatrick Venture req->cmd = BlobOEMCommands::bmcBlobRead; 57ef3aeadcSPatrick Venture req->crc = 0; 58ef3aeadcSPatrick Venture req->sessionId = 0x54; 59ef3aeadcSPatrick Venture req->offset = 0x100; 60ef3aeadcSPatrick Venture req->requestedSize = 0x10; 61ef3aeadcSPatrick Venture 62ef3aeadcSPatrick Venture dataLen = sizeof(struct BmcBlobReadTx); 63ef3aeadcSPatrick Venture 64ef3aeadcSPatrick Venture std::vector<uint8_t> data = {0x02, 0x03, 0x05, 0x06}; 65ef3aeadcSPatrick Venture 66ef3aeadcSPatrick Venture EXPECT_CALL(mgr, read(req->sessionId, req->offset, req->requestedSize)) 67ef3aeadcSPatrick Venture .WillOnce(Return(data)); 68ef3aeadcSPatrick Venture 69ef3aeadcSPatrick Venture EXPECT_EQ(IPMI_CC_OK, readBlob(&mgr, request, reply, &dataLen)); 70ef3aeadcSPatrick Venture EXPECT_EQ(sizeof(struct BmcBlobReadRx) + data.size(), dataLen); 71ef3aeadcSPatrick Venture EXPECT_EQ(0, std::memcmp(&reply[sizeof(struct BmcBlobReadRx)], data.data(), 72ef3aeadcSPatrick Venture data.size())); 73ef3aeadcSPatrick Venture } 74ef3aeadcSPatrick Venture 75ef3aeadcSPatrick Venture /* TODO(venture): We need a test that handles other checks such as if the size 76ef3aeadcSPatrick Venture * requested won't fit into a packet response. 77ef3aeadcSPatrick Venture */ 78ef3aeadcSPatrick Venture } // namespace blobs 79