diff options
| author | Patrick Venture <venture@google.com> | 2019-06-19 16:01:06 -0700 |
|---|---|---|
| committer | Patrick Venture <venture@google.com> | 2019-06-19 18:38:53 -0700 |
| commit | 1f09d4145f6b925cab1b2fe7420b31725704bca5 (patch) | |
| tree | 16627b3148e163c1b40ea21f9b0a2b5cbf0f3eee /tools/test | |
| parent | 00c7c72daf2c586bd95603057566a3ecd60c4db1 (diff) | |
| download | phosphor-ipmi-flash-1f09d4145f6b925cab1b2fe7420b31725704bca5.tar.gz phosphor-ipmi-flash-1f09d4145f6b925cab1b2fe7420b31725704bca5.zip | |
tool: continue the unit-tests of the host tool
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I51349fc103af2a55f1b83830bf8e74407fc15b9e
Diffstat (limited to 'tools/test')
| -rw-r--r-- | tools/test/tools_updater_unittest.cpp | 129 | ||||
| -rw-r--r-- | tools/test/updater_mock.hpp | 2 |
2 files changed, 65 insertions, 66 deletions
diff --git a/tools/test/tools_updater_unittest.cpp b/tools/test/tools_updater_unittest.cpp index cacf2b0..e54e613 100644 --- a/tools/test/tools_updater_unittest.cpp +++ b/tools/test/tools_updater_unittest.cpp @@ -1,4 +1,5 @@ #include "data_interface_mock.hpp" +#include "status.hpp" #include "updater.hpp" #include "updater_mock.hpp" #include "util.hpp" @@ -15,19 +16,23 @@ namespace host_tool using ::testing::_; using ::testing::Eq; using ::testing::Return; -using ::testing::StrEq; using ::testing::TypedEq; -TEST(UpdaterTest, CheckAvailableSuccess) +class UpdateHandlerTest : public ::testing::Test { - /* Call checkAvailable directly() to make sure it works. */ + protected: + const std::uint16_t session = 0xbeef; + DataInterfaceMock handlerMock; ipmiblob::BlobInterfaceMock blobMock; + UpdateHandler updater{&blobMock, &handlerMock}; +}; - ipmiblob::StatResponse statObj; +TEST_F(UpdateHandlerTest, CheckAvailableSuccess) +{ + ipmiblob::StatResponse statObj = {}; statObj.blob_state = ipmi_flash::FirmwareBlobHandler::UpdateFlags::ipmi | ipmi_flash::FirmwareBlobHandler::UpdateFlags::lpc; - statObj.size = 0; EXPECT_CALL(blobMock, getBlobList()) .WillOnce( @@ -39,104 +44,98 @@ TEST(UpdaterTest, CheckAvailableSuccess) EXPECT_CALL(handlerMock, supportedType()) .WillOnce(Return(ipmi_flash::FirmwareBlobHandler::UpdateFlags::lpc)); - UpdateHandler updater(&blobMock, &handlerMock); EXPECT_TRUE(updater.checkAvailable(ipmi_flash::staticLayoutBlobId)); } -TEST(UpdaterTest, SendFileSuccess) +TEST_F(UpdateHandlerTest, SendFileSuccess) { /* Call sendFile to verify it does what we expect. */ - DataInterfaceMock handlerMock; - ipmiblob::BlobInterfaceMock blobMock; - std::string firmwareImage = "image.bin"; std::uint16_t supported = static_cast<std::uint16_t>( ipmi_flash::FirmwareBlobHandler::UpdateFlags::lpc) | static_cast<std::uint16_t>(blobs::OpenFlags::write); - std::uint16_t session = 0xbeef; EXPECT_CALL(handlerMock, supportedType()) .WillOnce(Return(ipmi_flash::FirmwareBlobHandler::UpdateFlags::lpc)); - EXPECT_CALL( - blobMock, - openBlob(StrEq(ipmi_flash::staticLayoutBlobId.c_str()), supported)) + EXPECT_CALL(blobMock, openBlob(ipmi_flash::staticLayoutBlobId, supported)) .WillOnce(Return(session)); - EXPECT_CALL(handlerMock, - sendContents(StrEq(firmwareImage.c_str()), session)) + EXPECT_CALL(handlerMock, sendContents(firmwareImage, session)) .WillOnce(Return(true)); EXPECT_CALL(blobMock, closeBlob(session)).Times(1); - UpdateHandler updater(&blobMock, &handlerMock); updater.sendFile(ipmi_flash::staticLayoutBlobId, firmwareImage); } -#if 0 /* TODO: fix this up. */ -TEST(UpdaterTest, NormalWalkthroughAllHappy) +TEST_F(UpdateHandlerTest, VerifyFileHandleReturnsTrueOnSuccess) { - /* Call updaterMain and have everything respond happily. */ - DataInterfaceMock handlerMock; - ipmiblob::BlobInterfaceMock blobMock; + EXPECT_CALL(blobMock, openBlob(ipmi_flash::verifyBlobId, _)) + .WillOnce(Return(session)); + EXPECT_CALL(blobMock, commit(session, _)).WillOnce(Return()); + ipmiblob::StatResponse verificationResponse = {}; + /* the other details of the response are ignored, and should be. */ + verificationResponse.metadata.push_back( + static_cast<std::uint8_t>(ipmi_flash::ActionStatus::success)); - UpdateHandlerMock updaterMock; + EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session))) + .WillOnce(Return(verificationResponse)); + EXPECT_CALL(blobMock, closeBlob(session)).WillOnce(Return()); - std::string firmwareImage = "image.bin"; - std::string signatureFile = "image.sig"; + EXPECT_TRUE(updater.verifyFile(ipmi_flash::verifyBlobId)); +} - std::vector<std::string> blobList = {ipmi_flash::staticLayoutBlobId}; - ipmiblob::StatResponse statObj; - statObj.blob_state = ipmi_flash::FirmwareBlobHandler::UpdateFlags::ipmi | - ipmi_flash::FirmwareBlobHandler::UpdateFlags::lpc; - statObj.size = 0; - std::uint16_t supported = - static_cast<std::uint16_t>( - ipmi_flash::FirmwareBlobHandler::UpdateFlags::lpc) | - static_cast<std::uint16_t>(blobs::OpenFlags::write); +class UpdaterTest : public ::testing::Test +{ + protected: + ipmiblob::BlobInterfaceMock blobMock; std::uint16_t session = 0xbeef; +}; - EXPECT_CALL(blobMock, getBlobList()).WillOnce(Return(blobList)); +TEST_F(UpdaterTest, PollStatusReturnsAfterSuccess) +{ + ipmiblob::StatResponse verificationResponse = {}; + /* the other details of the response are ignored, and should be. */ + verificationResponse.metadata.push_back( + static_cast<std::uint8_t>(ipmi_flash::ActionStatus::success)); - EXPECT_CALL(blobMock, getStat(TypedEq<const std::string&>(ipmi_flash::staticLayoutBlobId))) - .WillOnce(Return(statObj)); + EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session))) + .WillOnce(Return(verificationResponse)); - EXPECT_CALL(handlerMock, supportedType()) - .WillOnce(Return(ipmi_flash::FirmwareBlobHandler::UpdateFlags::lpc)); + EXPECT_TRUE(pollStatus(session, &blobMock)); +} - EXPECT_CALL(blobMock, openBlob(StrEq(ipmi_flash::staticLayoutBlobId.c_str()), Eq(supported))) - .WillOnce(Return(session)); +TEST_F(UpdaterTest, PollStatusReturnsAfterFailure) +{ + ipmiblob::StatResponse verificationResponse = {}; + /* the other details of the response are ignored, and should be. */ + verificationResponse.metadata.push_back( + static_cast<std::uint8_t>(ipmi_flash::ActionStatus::failed)); - EXPECT_CALL(handlerMock, - sendContents(StrEq(firmwareImage.c_str()), Eq(session))) - .WillOnce(Return(true)); + EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session))) + .WillOnce(Return(verificationResponse)); - EXPECT_CALL(blobMock, openBlob(StrEq(blobs::hashBlobId.c_str()), Eq(supported))) - .WillOnce(Return(session)); + EXPECT_FALSE(pollStatus(session, &blobMock)); +} - EXPECT_CALL(handlerMock, - sendContents(StrEq(signatureFile.c_str()), Eq(session))) +TEST_F(UpdaterTest, UpdateMainReturnsSuccessIfAllSuccess) +{ + const std::string image = "image.bin"; + const std::string signature = "signature.bin"; + UpdateHandlerMock handler; + + EXPECT_CALL(handler, checkAvailable(_)).WillOnce(Return(true)); + EXPECT_CALL(handler, sendFile(_, image)).WillOnce(Return()); + EXPECT_CALL(handler, sendFile(_, signature)).WillOnce(Return()); + EXPECT_CALL(handler, verifyFile(ipmi_flash::verifyBlobId)) + .WillOnce(Return(true)); + EXPECT_CALL(handler, verifyFile(ipmi_flash::updateBlobId)) .WillOnce(Return(true)); - EXPECT_CALL(blobMock, - openBlob(StrEq(blobs::verifyBlobId.c_str()), Eq(supported))) - .WillOnce(Return(session)); - - EXPECT_CALL(blobMock, commit(session, _)).WillOnce(Return()); - - ipmiblob::StatResponse verificationResponse; - verificationResponse.blob_state = supported | blobs::StateFlags::committing; - verificationResponse.size = 0; - verificationResponse.metadata.push_back(static_cast<std::uint8_t>( - ipmi_flash::FirmwareBlobHandler::ActionStatus::success)); - - EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session))) - .WillOnce(Return(verificationResponse)); - - updaterMain(&blobMock, &handlerMock, firmwareImage, signatureFile); + updaterMain(&handler, image, signature); } -#endif } // namespace host_tool diff --git a/tools/test/updater_mock.hpp b/tools/test/updater_mock.hpp index d065219..ca4c4b9 100644 --- a/tools/test/updater_mock.hpp +++ b/tools/test/updater_mock.hpp @@ -9,7 +9,7 @@ namespace host_tool { -class UpdateHandlerMock : public UpdateHandler +class UpdateHandlerMock : public UpdateHandlerInterface { public: MOCK_METHOD1(checkAvailable, bool(const std::string&)); |

