Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 1 | #include "data_interface_mock.hpp" |
| 2 | #include "updater.hpp" |
| 3 | |
Patrick Venture | 664c5bc | 2019-03-07 08:09:45 -0800 | [diff] [blame] | 4 | #include <blobs-ipmid/blobs.hpp> |
| 5 | #include <ipmiblob/test/blob_interface_mock.hpp> |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 6 | #include <string> |
| 7 | |
| 8 | #include <gtest/gtest.h> |
| 9 | |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame] | 10 | namespace host_tool |
| 11 | { |
| 12 | |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 13 | using ::testing::Eq; |
| 14 | using ::testing::Return; |
| 15 | using ::testing::StrEq; |
| 16 | |
| 17 | TEST(UpdaterTest, NormalWalkthroughAllHappy) |
| 18 | { |
| 19 | /* Call updaterMain and have everything respond happily. */ |
| 20 | DataInterfaceMock handlerMock; |
Patrick Venture | 664c5bc | 2019-03-07 08:09:45 -0800 | [diff] [blame] | 21 | ipmiblob::BlobInterfaceMock blobMock; |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 22 | std::string firmwareImage = "image.bin"; |
| 23 | std::string signatureFile = "image.sig"; |
Patrick Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 24 | std::string expectedBlob = "/flash/image"; |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 25 | |
Patrick Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 26 | std::vector<std::string> blobList = {expectedBlob}; |
Patrick Venture | 664c5bc | 2019-03-07 08:09:45 -0800 | [diff] [blame] | 27 | ipmiblob::StatResponse statObj; |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 28 | statObj.blob_state = blobs::FirmwareBlobHandler::UpdateFlags::ipmi | |
| 29 | blobs::FirmwareBlobHandler::UpdateFlags::lpc; |
| 30 | statObj.size = 0; |
Patrick Venture | 664c5bc | 2019-03-07 08:09:45 -0800 | [diff] [blame] | 31 | std::uint16_t supported = |
| 32 | static_cast<std::uint16_t>( |
| 33 | blobs::FirmwareBlobHandler::UpdateFlags::lpc) | |
| 34 | static_cast<std::uint16_t>(blobs::OpenFlags::write); |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 35 | std::uint16_t session = 0xbeef; |
| 36 | |
| 37 | EXPECT_CALL(blobMock, getBlobList()).WillOnce(Return(blobList)); |
| 38 | |
Patrick Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 39 | EXPECT_CALL(blobMock, getStat(Eq(expectedBlob))).WillOnce(Return(statObj)); |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 40 | |
Patrick Venture | 664c5bc | 2019-03-07 08:09:45 -0800 | [diff] [blame] | 41 | EXPECT_CALL(handlerMock, supportedType()) |
| 42 | .WillOnce(Return(blobs::FirmwareBlobHandler::UpdateFlags::lpc)); |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 43 | |
Patrick Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 44 | EXPECT_CALL(blobMock, openBlob(StrEq(expectedBlob.c_str()), Eq(supported))) |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 45 | .WillOnce(Return(session)); |
| 46 | |
| 47 | EXPECT_CALL(handlerMock, |
| 48 | sendContents(StrEq(firmwareImage.c_str()), Eq(session))) |
| 49 | .WillOnce(Return(true)); |
| 50 | |
| 51 | updaterMain(&blobMock, &handlerMock, firmwareImage, signatureFile); |
| 52 | } |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame] | 53 | |
| 54 | } // namespace host_tool |