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 | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 5 | #include "triggerable_mock.hpp" |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 6 | #include "util.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 | { |
Patrick Venture | 63902a4 | 2020-10-06 12:13:31 -0700 | [diff] [blame^] | 14 | |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 15 | using ::testing::Return; |
| 16 | |
Patrick Venture | 1361a12 | 2019-05-20 07:36:05 -0700 | [diff] [blame] | 17 | class FirmwareSessionStateTestIpmiOnly : public IpmiOnlyFirmwareTest |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 18 | {}; |
Patrick Venture | 3a03631 | 2019-05-17 18:56:41 -0700 | [diff] [blame] | 19 | |
Patrick Venture | 1361a12 | 2019-05-20 07:36:05 -0700 | [diff] [blame] | 20 | class FirmwareSessionStateTestLpc : public FakeLpcFirmwareTest |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 21 | {}; |
Patrick Venture | 1361a12 | 2019-05-20 07:36:05 -0700 | [diff] [blame] | 22 | |
| 23 | TEST_F(FirmwareSessionStateTestIpmiOnly, DataTypeIpmiNoMetadata) |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 24 | { |
| 25 | /* Verifying running stat if the type of data session is IPMI returns no |
| 26 | * metadata. |
| 27 | */ |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 28 | EXPECT_CALL(*imageMock, open("asdf")).WillOnce(Return(true)); |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 29 | |
| 30 | EXPECT_TRUE(handler->open( |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 31 | 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, "asdf")); |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 32 | |
| 33 | int size = 512; |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 34 | EXPECT_CALL(*imageMock, getSize()).WillOnce(Return(size)); |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 35 | |
Patrick Venture | e312f39 | 2019-06-04 07:44:37 -0700 | [diff] [blame] | 36 | blobs::BlobMeta meta; |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 37 | EXPECT_TRUE(handler->stat(0, &meta)); |
| 38 | EXPECT_EQ(meta.blobState, |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 39 | blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi); |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 40 | EXPECT_EQ(meta.size, size); |
| 41 | EXPECT_EQ(meta.metadata.size(), 0); |
| 42 | } |
| 43 | |
Patrick Venture | 1361a12 | 2019-05-20 07:36:05 -0700 | [diff] [blame] | 44 | TEST_F(FirmwareSessionStateTestLpc, DataTypeP2AReturnsMetadata) |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 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 | */ |
Patrick Venture | 4934daa | 2020-09-22 16:37:44 -0700 | [diff] [blame] | 50 | EXPECT_CALL(*dataMock, open()).WillOnce(Return(true)); |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 51 | EXPECT_CALL(*imageMock, open("asdf")).WillOnce(Return(true)); |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 52 | |
| 53 | EXPECT_TRUE(handler->open( |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 54 | 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::lpc, "asdf")); |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 55 | |
| 56 | int size = 512; |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 57 | EXPECT_CALL(*imageMock, getSize()).WillOnce(Return(size)); |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 58 | std::vector<std::uint8_t> mBytes = {0x01, 0x02}; |
Patrick Venture | 4934daa | 2020-09-22 16:37:44 -0700 | [diff] [blame] | 59 | EXPECT_CALL(*dataMock, readMeta()).WillOnce(Return(mBytes)); |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 60 | |
Patrick Venture | e312f39 | 2019-06-04 07:44:37 -0700 | [diff] [blame] | 61 | blobs::BlobMeta meta; |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 62 | EXPECT_TRUE(handler->stat(0, &meta)); |
| 63 | EXPECT_EQ(meta.blobState, |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 64 | blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::lpc); |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 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 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 71 | } // namespace ipmi_flash |