blob: 27a3fc4ade99bb7767bf8a704354fe5bec54858a [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 Venture73528382019-05-14 12:43:37 -070026 std::string expectedHash = "/flash/hash";
Patrick Ventureaa32a362018-12-13 10:52:33 -080027
Patrick Venture339dece2018-12-14 18:32:04 -080028 std::vector<std::string> blobList = {expectedBlob};
Patrick Venture664c5bc2019-03-07 08:09:45 -080029 ipmiblob::StatResponse statObj;
Patrick Ventureaa32a362018-12-13 10:52:33 -080030 statObj.blob_state = blobs::FirmwareBlobHandler::UpdateFlags::ipmi |
31 blobs::FirmwareBlobHandler::UpdateFlags::lpc;
32 statObj.size = 0;
Patrick Venture664c5bc2019-03-07 08:09:45 -080033 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 Ventureaa32a362018-12-13 10:52:33 -080037 std::uint16_t session = 0xbeef;
38
39 EXPECT_CALL(blobMock, getBlobList()).WillOnce(Return(blobList));
40
Patrick Ventureb58f5612019-05-07 09:22:07 -070041 EXPECT_CALL(blobMock, getStat(TypedEq<const std::string&>(expectedBlob)))
42 .WillOnce(Return(statObj));
Patrick Ventureaa32a362018-12-13 10:52:33 -080043
Patrick Venture664c5bc2019-03-07 08:09:45 -080044 EXPECT_CALL(handlerMock, supportedType())
45 .WillOnce(Return(blobs::FirmwareBlobHandler::UpdateFlags::lpc));
Patrick Ventureaa32a362018-12-13 10:52:33 -080046
Patrick Venture339dece2018-12-14 18:32:04 -080047 EXPECT_CALL(blobMock, openBlob(StrEq(expectedBlob.c_str()), Eq(supported)))
Patrick Ventureaa32a362018-12-13 10:52:33 -080048 .WillOnce(Return(session));
49
50 EXPECT_CALL(handlerMock,
51 sendContents(StrEq(firmwareImage.c_str()), Eq(session)))
52 .WillOnce(Return(true));
53
Patrick Venture73528382019-05-14 12:43:37 -070054 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 Ventureaa32a362018-12-13 10:52:33 -080061 updaterMain(&blobMock, &handlerMock, firmwareImage, signatureFile);
62}
Patrick Venture9b534f02018-12-13 16:10:02 -080063
64} // namespace host_tool