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