blob: 158ce47fef6a9754cd605d2dee4a70c3f82f873c [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;
16
17TEST(UpdaterTest, NormalWalkthroughAllHappy)
18{
19 /* Call updaterMain and have everything respond happily. */
20 DataInterfaceMock handlerMock;
Patrick Venture664c5bc2019-03-07 08:09:45 -080021 ipmiblob::BlobInterfaceMock blobMock;
Patrick Ventureaa32a362018-12-13 10:52:33 -080022 std::string firmwareImage = "image.bin";
23 std::string signatureFile = "image.sig";
Patrick Venture339dece2018-12-14 18:32:04 -080024 std::string expectedBlob = "/flash/image";
Patrick Ventureaa32a362018-12-13 10:52:33 -080025
Patrick Venture339dece2018-12-14 18:32:04 -080026 std::vector<std::string> blobList = {expectedBlob};
Patrick Venture664c5bc2019-03-07 08:09:45 -080027 ipmiblob::StatResponse statObj;
Patrick Ventureaa32a362018-12-13 10:52:33 -080028 statObj.blob_state = blobs::FirmwareBlobHandler::UpdateFlags::ipmi |
29 blobs::FirmwareBlobHandler::UpdateFlags::lpc;
30 statObj.size = 0;
Patrick Venture664c5bc2019-03-07 08:09:45 -080031 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 Ventureaa32a362018-12-13 10:52:33 -080035 std::uint16_t session = 0xbeef;
36
37 EXPECT_CALL(blobMock, getBlobList()).WillOnce(Return(blobList));
38
Patrick Venture339dece2018-12-14 18:32:04 -080039 EXPECT_CALL(blobMock, getStat(Eq(expectedBlob))).WillOnce(Return(statObj));
Patrick Ventureaa32a362018-12-13 10:52:33 -080040
Patrick Venture664c5bc2019-03-07 08:09:45 -080041 EXPECT_CALL(handlerMock, supportedType())
42 .WillOnce(Return(blobs::FirmwareBlobHandler::UpdateFlags::lpc));
Patrick Ventureaa32a362018-12-13 10:52:33 -080043
Patrick Venture339dece2018-12-14 18:32:04 -080044 EXPECT_CALL(blobMock, openBlob(StrEq(expectedBlob.c_str()), Eq(supported)))
Patrick Ventureaa32a362018-12-13 10:52:33 -080045 .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 Venture9b534f02018-12-13 16:10:02 -080053
54} // namespace host_tool