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