blob: 04720e09e00132b700fb24c2e043712a961095dd [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 Venture7dcca5d2019-05-15 12:32:33 -070013using ::testing::_;
Patrick Ventureaa32a362018-12-13 10:52:33 -080014using ::testing::Eq;
15using ::testing::Return;
16using ::testing::StrEq;
Patrick Ventureb58f5612019-05-07 09:22:07 -070017using ::testing::TypedEq;
Patrick Ventureaa32a362018-12-13 10:52:33 -080018
19TEST(UpdaterTest, NormalWalkthroughAllHappy)
20{
21 /* Call updaterMain and have everything respond happily. */
22 DataInterfaceMock handlerMock;
Patrick Venture664c5bc2019-03-07 08:09:45 -080023 ipmiblob::BlobInterfaceMock blobMock;
Patrick Ventureaa32a362018-12-13 10:52:33 -080024 std::string firmwareImage = "image.bin";
25 std::string signatureFile = "image.sig";
Patrick Venture339dece2018-12-14 18:32:04 -080026 std::string expectedBlob = "/flash/image";
Patrick Venture73528382019-05-14 12:43:37 -070027 std::string expectedHash = "/flash/hash";
Patrick Venture7dcca5d2019-05-15 12:32:33 -070028 std::string expectedVerify = "/flash/verify";
Patrick Ventureaa32a362018-12-13 10:52:33 -080029
Patrick Venture339dece2018-12-14 18:32:04 -080030 std::vector<std::string> blobList = {expectedBlob};
Patrick Venture664c5bc2019-03-07 08:09:45 -080031 ipmiblob::StatResponse statObj;
Patrick Ventureaa32a362018-12-13 10:52:33 -080032 statObj.blob_state = blobs::FirmwareBlobHandler::UpdateFlags::ipmi |
33 blobs::FirmwareBlobHandler::UpdateFlags::lpc;
34 statObj.size = 0;
Patrick Venture664c5bc2019-03-07 08:09:45 -080035 std::uint16_t supported =
36 static_cast<std::uint16_t>(
37 blobs::FirmwareBlobHandler::UpdateFlags::lpc) |
38 static_cast<std::uint16_t>(blobs::OpenFlags::write);
Patrick Ventureaa32a362018-12-13 10:52:33 -080039 std::uint16_t session = 0xbeef;
40
41 EXPECT_CALL(blobMock, getBlobList()).WillOnce(Return(blobList));
42
Patrick Ventureb58f5612019-05-07 09:22:07 -070043 EXPECT_CALL(blobMock, getStat(TypedEq<const std::string&>(expectedBlob)))
44 .WillOnce(Return(statObj));
Patrick Ventureaa32a362018-12-13 10:52:33 -080045
Patrick Venture664c5bc2019-03-07 08:09:45 -080046 EXPECT_CALL(handlerMock, supportedType())
47 .WillOnce(Return(blobs::FirmwareBlobHandler::UpdateFlags::lpc));
Patrick Ventureaa32a362018-12-13 10:52:33 -080048
Patrick Venture339dece2018-12-14 18:32:04 -080049 EXPECT_CALL(blobMock, openBlob(StrEq(expectedBlob.c_str()), Eq(supported)))
Patrick Ventureaa32a362018-12-13 10:52:33 -080050 .WillOnce(Return(session));
51
52 EXPECT_CALL(handlerMock,
53 sendContents(StrEq(firmwareImage.c_str()), Eq(session)))
54 .WillOnce(Return(true));
55
Patrick Venture73528382019-05-14 12:43:37 -070056 EXPECT_CALL(blobMock, openBlob(StrEq(expectedHash.c_str()), Eq(supported)))
57 .WillOnce(Return(session));
58
59 EXPECT_CALL(handlerMock,
60 sendContents(StrEq(signatureFile.c_str()), Eq(session)))
61 .WillOnce(Return(true));
62
Patrick Venture7dcca5d2019-05-15 12:32:33 -070063 EXPECT_CALL(blobMock,
64 openBlob(StrEq(expectedVerify.c_str()), Eq(supported)))
65 .WillOnce(Return(session));
66
67 EXPECT_CALL(blobMock, commit(Eq(session), _)).WillOnce(Return());
68
Patrick Ventureaa32a362018-12-13 10:52:33 -080069 updaterMain(&blobMock, &handlerMock, firmwareImage, signatureFile);
70}
Patrick Venture9b534f02018-12-13 16:10:02 -080071
72} // namespace host_tool