blob: eb1121145b7aba5407a5ddb35bb39201c6e9acab [file] [log] [blame]
Patrick Ventureffcc5502018-11-16 12:32:38 -08001#include "data_mock.hpp"
2#include "firmware_handler.hpp"
Patrick Venture84778b82019-06-26 20:11:09 -07003#include "flags.hpp"
Patrick Ventureffcc5502018-11-16 12:32:38 -08004#include "image_mock.hpp"
Patrick Venture1d66fe62019-06-03 14:57:27 -07005#include "triggerable_mock.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -07006#include "util.hpp"
Patrick Ventureffcc5502018-11-16 12:32:38 -08007
Patrick Venture481cd4a2019-05-17 17:53:11 -07008#include <memory>
Patrick Ventureffcc5502018-11-16 12:32:38 -08009#include <vector>
10
11#include <gtest/gtest.h>
12
Patrick Venture1d5a31c2019-05-20 11:38:22 -070013namespace ipmi_flash
Patrick Ventureffcc5502018-11-16 12:32:38 -080014{
Patrick Venturefa06a5f2019-07-01 09:22:38 -070015namespace
16{
Patrick Venturecabc1172018-11-16 16:14:26 -080017using ::testing::_;
18using ::testing::IsNull;
19using ::testing::NotNull;
Patrick Ventureffcc5502018-11-16 12:32:38 -080020using ::testing::Return;
Patrick Venturecabc1172018-11-16 16:14:26 -080021using ::testing::StrEq;
22using ::testing::StrictMock;
Patrick Ventureffcc5502018-11-16 12:32:38 -080023
Patrick Venture481cd4a2019-05-17 17:53:11 -070024class FirmwareHandlerCommitTest : public ::testing::Test
25{
26 protected:
Patrick Ventured4e20de2019-07-18 12:48:05 -070027 ImageHandlerMock *imageMock1, *imageMock2;
Patrick Venture481cd4a2019-05-17 17:53:11 -070028 std::vector<HandlerPack> blobs;
29 std::vector<DataHandlerPack> data;
30
31 void SetUp() override
32 {
Patrick Ventured4e20de2019-07-18 12:48:05 -070033 std::unique_ptr<ImageHandlerInterface> image =
34 std::make_unique<ImageHandlerMock>();
35 imageMock1 = reinterpret_cast<ImageHandlerMock*>(image.get());
36 blobs.push_back(std::move(HandlerPack(hashBlobId, std::move(image))));
37
38 image = std::make_unique<ImageHandlerMock>();
39 imageMock2 = reinterpret_cast<ImageHandlerMock*>(image.get());
40 blobs.push_back(std::move(HandlerPack("asdf", std::move(image))));
Patrick Venture481cd4a2019-05-17 17:53:11 -070041
42 data = {
Patrick Venture84778b82019-06-26 20:11:09 -070043 {FirmwareFlags::UpdateFlags::ipmi, nullptr},
Patrick Venture481cd4a2019-05-17 17:53:11 -070044 };
45 }
46};
47
48TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnFlashImage)
Patrick Ventureffcc5502018-11-16 12:32:38 -080049{
50 /* Verify the flash image returns failure on this command. It's a fairly
51 * artificial test.
52 */
Patrick Ventureffcc5502018-11-16 12:32:38 -080053
Patrick Venture3ecb3502019-05-17 11:03:51 -070054 /* Verify it doesn't get called by using StrictMock. */
Patrick Venture1d66fe62019-06-03 14:57:27 -070055 std::unique_ptr<TriggerableActionInterface> verifyMock =
56 std::make_unique<StrictMock<TriggerMock>>();
Patrick Venture4eb55952018-11-16 15:36:24 -080057
58 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture7b783432020-09-22 15:55:08 -070059 std::move(blobs), std::move(data), std::move(CreateActionMap("asdf")));
Patrick Ventureffcc5502018-11-16 12:32:38 -080060
Patrick Ventured4e20de2019-07-18 12:48:05 -070061 EXPECT_CALL(*imageMock2, open("asdf")).WillOnce(Return(true));
Patrick Ventureffcc5502018-11-16 12:32:38 -080062
63 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070064 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, "asdf"));
Patrick Ventureffcc5502018-11-16 12:32:38 -080065
66 EXPECT_FALSE(handler->commit(0, {}));
67}
68
Patrick Venture481cd4a2019-05-17 17:53:11 -070069TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnHashFile)
Patrick Ventureffcc5502018-11-16 12:32:38 -080070{
71 /* Verify the hash file returns failure on this command. It's a fairly
72 * artificial test.
73 */
Patrick Ventureffcc5502018-11-16 12:32:38 -080074
Patrick Venture3ecb3502019-05-17 11:03:51 -070075 /* Verify it doesn't get called by using StrictMock. */
Patrick Venture1d66fe62019-06-03 14:57:27 -070076 std::unique_ptr<TriggerableActionInterface> verifyMock =
77 std::make_unique<StrictMock<TriggerMock>>();
Patrick Venture4eb55952018-11-16 15:36:24 -080078
79 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture7b783432020-09-22 15:55:08 -070080 std::move(blobs), std::move(data), std::move(CreateActionMap("asdf")));
Patrick Ventureffcc5502018-11-16 12:32:38 -080081
Patrick Ventured4e20de2019-07-18 12:48:05 -070082 EXPECT_CALL(*imageMock1, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Ventureffcc5502018-11-16 12:32:38 -080083
84 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070085 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi,
Patrick Venture7dad86f2019-05-17 08:52:20 -070086 hashBlobId));
Patrick Ventureffcc5502018-11-16 12:32:38 -080087
88 EXPECT_FALSE(handler->commit(0, {}));
89}
90
Patrick Venturefa06a5f2019-07-01 09:22:38 -070091} // namespace
Patrick Venture1d5a31c2019-05-20 11:38:22 -070092} // namespace ipmi_flash