1 #include "data_mock.hpp" 2 #include "firmware_handler.hpp" 3 #include "firmware_unittest.hpp" 4 #include "image_mock.hpp" 5 #include "triggerable_mock.hpp" 6 #include "util.hpp" 7 8 #include <vector> 9 10 #include <gtest/gtest.h> 11 12 namespace ipmi_flash 13 { 14 15 using ::testing::Return; 16 17 class FirmwareSessionStateTestIpmiOnly : public IpmiOnlyFirmwareTest 18 {}; 19 20 class FirmwareSessionStateTestLpc : public FakeLpcFirmwareTest 21 {}; 22 23 TEST_F(FirmwareSessionStateTestIpmiOnly, DataTypeIpmiNoMetadata) 24 { 25 /* Verifying running stat if the type of data session is IPMI returns no 26 * metadata. 27 */ 28 EXPECT_CALL(*imageMock, open("asdf")).WillOnce(Return(true)); 29 30 EXPECT_TRUE(handler->open( 31 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, "asdf")); 32 33 int size = 512; 34 EXPECT_CALL(*imageMock, getSize()).WillOnce(Return(size)); 35 36 blobs::BlobMeta meta; 37 EXPECT_TRUE(handler->stat(0, &meta)); 38 EXPECT_EQ(meta.blobState, 39 blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi); 40 EXPECT_EQ(meta.size, size); 41 EXPECT_EQ(meta.metadata.size(), 0); 42 } 43 44 TEST_F(FirmwareSessionStateTestLpc, DataTypeP2AReturnsMetadata) 45 { 46 /* Really any type that isn't IPMI can return metadata, but we only expect 47 * P2A to for now. Later, LPC may have reason to provide data, and can by 48 * simply implementing read(). 49 */ 50 EXPECT_CALL(*dataMock, open()).WillOnce(Return(true)); 51 EXPECT_CALL(*imageMock, open("asdf")).WillOnce(Return(true)); 52 53 EXPECT_TRUE(handler->open( 54 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::lpc, "asdf")); 55 56 int size = 512; 57 EXPECT_CALL(*imageMock, getSize()).WillOnce(Return(size)); 58 std::vector<std::uint8_t> mBytes = {0x01, 0x02}; 59 EXPECT_CALL(*dataMock, readMeta()).WillOnce(Return(mBytes)); 60 61 blobs::BlobMeta meta; 62 EXPECT_TRUE(handler->stat(0, &meta)); 63 EXPECT_EQ(meta.blobState, 64 blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::lpc); 65 EXPECT_EQ(meta.size, size); 66 EXPECT_EQ(meta.metadata.size(), mBytes.size()); 67 EXPECT_EQ(meta.metadata[0], mBytes[0]); 68 EXPECT_EQ(meta.metadata[1], mBytes[1]); 69 } 70 71 } // namespace ipmi_flash 72