blob: 46546fa4899cea1ff7c17f88120e64ac04039cd5 [file] [log] [blame]
Patrick Ventureaa32a362018-12-13 10:52:33 -08001#include "data_interface_mock.hpp"
2#include "updater.hpp"
3
Patrick Venture664c5bc2019-03-07 08:09:45 -08004#include <blobs-ipmid/blobs.hpp>
5#include <ipmiblob/test/blob_interface_mock.hpp>
Patrick Ventureaa32a362018-12-13 10:52:33 -08006#include <string>
7
8#include <gtest/gtest.h>
9
Patrick Venture9b534f02018-12-13 16:10:02 -080010namespace host_tool
11{
12
Patrick Ventureaa32a362018-12-13 10:52:33 -080013using ::testing::Eq;
14using ::testing::Return;
15using ::testing::StrEq;
Patrick Ventureb58f5612019-05-07 09:22:07 -070016using ::testing::TypedEq;
Patrick Ventureaa32a362018-12-13 10:52:33 -080017
18TEST(UpdaterTest, NormalWalkthroughAllHappy)
19{
20 /* Call updaterMain and have everything respond happily. */
21 DataInterfaceMock handlerMock;
Patrick Venture664c5bc2019-03-07 08:09:45 -080022 ipmiblob::BlobInterfaceMock blobMock;
Patrick Ventureaa32a362018-12-13 10:52:33 -080023 std::string firmwareImage = "image.bin";
24 std::string signatureFile = "image.sig";
Patrick Venture339dece2018-12-14 18:32:04 -080025 std::string expectedBlob = "/flash/image";
Patrick Ventureaa32a362018-12-13 10:52:33 -080026
Patrick Venture339dece2018-12-14 18:32:04 -080027 std::vector<std::string> blobList = {expectedBlob};
Patrick Venture664c5bc2019-03-07 08:09:45 -080028 ipmiblob::StatResponse statObj;
Patrick Ventureaa32a362018-12-13 10:52:33 -080029 statObj.blob_state = blobs::FirmwareBlobHandler::UpdateFlags::ipmi |
30 blobs::FirmwareBlobHandler::UpdateFlags::lpc;
31 statObj.size = 0;
Patrick Venture664c5bc2019-03-07 08:09:45 -080032 std::uint16_t supported =
33 static_cast<std::uint16_t>(
34 blobs::FirmwareBlobHandler::UpdateFlags::lpc) |
35 static_cast<std::uint16_t>(blobs::OpenFlags::write);
Patrick Ventureaa32a362018-12-13 10:52:33 -080036 std::uint16_t session = 0xbeef;
37
38 EXPECT_CALL(blobMock, getBlobList()).WillOnce(Return(blobList));
39
Patrick Ventureb58f5612019-05-07 09:22:07 -070040 EXPECT_CALL(blobMock, getStat(TypedEq<const std::string&>(expectedBlob)))
41 .WillOnce(Return(statObj));
Patrick Ventureaa32a362018-12-13 10:52:33 -080042
Patrick Venture664c5bc2019-03-07 08:09:45 -080043 EXPECT_CALL(handlerMock, supportedType())
44 .WillOnce(Return(blobs::FirmwareBlobHandler::UpdateFlags::lpc));
Patrick Ventureaa32a362018-12-13 10:52:33 -080045
Patrick Venture339dece2018-12-14 18:32:04 -080046 EXPECT_CALL(blobMock, openBlob(StrEq(expectedBlob.c_str()), Eq(supported)))
Patrick Ventureaa32a362018-12-13 10:52:33 -080047 .WillOnce(Return(session));
48
49 EXPECT_CALL(handlerMock,
50 sendContents(StrEq(firmwareImage.c_str()), Eq(session)))
51 .WillOnce(Return(true));
52
53 updaterMain(&blobMock, &handlerMock, firmwareImage, signatureFile);
54}
Patrick Venture9b534f02018-12-13 16:10:02 -080055
56} // namespace host_tool