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; |
Patrick Venture | b58f561 | 2019-05-07 09:22:07 -0700 | [diff] [blame] | 16 | using ::testing::TypedEq; |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 17 | |
| 18 | TEST(UpdaterTest, NormalWalkthroughAllHappy) |
| 19 | { |
| 20 | /* Call updaterMain and have everything respond happily. */ |
| 21 | DataInterfaceMock handlerMock; |
Patrick Venture | 664c5bc | 2019-03-07 08:09:45 -0800 | [diff] [blame] | 22 | ipmiblob::BlobInterfaceMock blobMock; |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 23 | std::string firmwareImage = "image.bin"; |
| 24 | std::string signatureFile = "image.sig"; |
Patrick Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 25 | std::string expectedBlob = "/flash/image"; |
Patrick Venture | 7352838 | 2019-05-14 12:43:37 -0700 | [diff] [blame^] | 26 | std::string expectedHash = "/flash/hash"; |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 27 | |
Patrick Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 28 | std::vector<std::string> blobList = {expectedBlob}; |
Patrick Venture | 664c5bc | 2019-03-07 08:09:45 -0800 | [diff] [blame] | 29 | ipmiblob::StatResponse statObj; |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 30 | statObj.blob_state = blobs::FirmwareBlobHandler::UpdateFlags::ipmi | |
| 31 | blobs::FirmwareBlobHandler::UpdateFlags::lpc; |
| 32 | statObj.size = 0; |
Patrick Venture | 664c5bc | 2019-03-07 08:09:45 -0800 | [diff] [blame] | 33 | std::uint16_t supported = |
| 34 | static_cast<std::uint16_t>( |
| 35 | blobs::FirmwareBlobHandler::UpdateFlags::lpc) | |
| 36 | static_cast<std::uint16_t>(blobs::OpenFlags::write); |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 37 | std::uint16_t session = 0xbeef; |
| 38 | |
| 39 | EXPECT_CALL(blobMock, getBlobList()).WillOnce(Return(blobList)); |
| 40 | |
Patrick Venture | b58f561 | 2019-05-07 09:22:07 -0700 | [diff] [blame] | 41 | EXPECT_CALL(blobMock, getStat(TypedEq<const std::string&>(expectedBlob))) |
| 42 | .WillOnce(Return(statObj)); |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 43 | |
Patrick Venture | 664c5bc | 2019-03-07 08:09:45 -0800 | [diff] [blame] | 44 | EXPECT_CALL(handlerMock, supportedType()) |
| 45 | .WillOnce(Return(blobs::FirmwareBlobHandler::UpdateFlags::lpc)); |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 46 | |
Patrick Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 47 | EXPECT_CALL(blobMock, openBlob(StrEq(expectedBlob.c_str()), Eq(supported))) |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 48 | .WillOnce(Return(session)); |
| 49 | |
| 50 | EXPECT_CALL(handlerMock, |
| 51 | sendContents(StrEq(firmwareImage.c_str()), Eq(session))) |
| 52 | .WillOnce(Return(true)); |
| 53 | |
Patrick Venture | 7352838 | 2019-05-14 12:43:37 -0700 | [diff] [blame^] | 54 | EXPECT_CALL(blobMock, openBlob(StrEq(expectedHash.c_str()), Eq(supported))) |
| 55 | .WillOnce(Return(session)); |
| 56 | |
| 57 | EXPECT_CALL(handlerMock, |
| 58 | sendContents(StrEq(signatureFile.c_str()), Eq(session))) |
| 59 | .WillOnce(Return(true)); |
| 60 | |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 61 | updaterMain(&blobMock, &handlerMock, firmwareImage, signatureFile); |
| 62 | } |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame] | 63 | |
| 64 | } // namespace host_tool |