blob: a6ab1729e0f230721018504d3facfbe6aaa52761 [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 Venturecabc1172018-11-16 16:14:26 -080015using ::testing::_;
16using ::testing::IsNull;
17using ::testing::NotNull;
Patrick Ventureffcc5502018-11-16 12:32:38 -080018using ::testing::Return;
Patrick Venturecabc1172018-11-16 16:14:26 -080019using ::testing::StrEq;
20using ::testing::StrictMock;
Patrick Ventureffcc5502018-11-16 12:32:38 -080021
Patrick Venture481cd4a2019-05-17 17:53:11 -070022class FirmwareHandlerCommitTest : public ::testing::Test
23{
24 protected:
25 ImageHandlerMock imageMock1, imageMock2;
26 std::vector<HandlerPack> blobs;
27 std::vector<DataHandlerPack> data;
28
29 void SetUp() override
30 {
31 blobs = {
32 {hashBlobId, &imageMock1},
33 {"asdf", &imageMock2},
34 };
35
36 data = {
Patrick Venture84778b82019-06-26 20:11:09 -070037 {FirmwareFlags::UpdateFlags::ipmi, nullptr},
Patrick Venture481cd4a2019-05-17 17:53:11 -070038 };
39 }
40};
41
42TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnFlashImage)
Patrick Ventureffcc5502018-11-16 12:32:38 -080043{
44 /* Verify the flash image returns failure on this command. It's a fairly
45 * artificial test.
46 */
Patrick Ventureffcc5502018-11-16 12:32:38 -080047
Patrick Venture3ecb3502019-05-17 11:03:51 -070048 /* Verify it doesn't get called by using StrictMock. */
Patrick Venture1d66fe62019-06-03 14:57:27 -070049 std::unique_ptr<TriggerableActionInterface> verifyMock =
50 std::make_unique<StrictMock<TriggerMock>>();
Patrick Venture4eb55952018-11-16 15:36:24 -080051
52 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture6d7735d2019-06-21 10:03:19 -070053 blobs, data, CreateTriggerMock(), std::move(verifyMock),
54 CreateTriggerMock());
Patrick Ventureffcc5502018-11-16 12:32:38 -080055
56 EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
57
58 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070059 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, "asdf"));
Patrick Ventureffcc5502018-11-16 12:32:38 -080060
61 EXPECT_FALSE(handler->commit(0, {}));
62}
63
Patrick Venture481cd4a2019-05-17 17:53:11 -070064TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnHashFile)
Patrick Ventureffcc5502018-11-16 12:32:38 -080065{
66 /* Verify the hash file returns failure on this command. It's a fairly
67 * artificial test.
68 */
Patrick Ventureffcc5502018-11-16 12:32:38 -080069
Patrick Venture3ecb3502019-05-17 11:03:51 -070070 /* Verify it doesn't get called by using StrictMock. */
Patrick Venture1d66fe62019-06-03 14:57:27 -070071 std::unique_ptr<TriggerableActionInterface> verifyMock =
72 std::make_unique<StrictMock<TriggerMock>>();
Patrick Venture4eb55952018-11-16 15:36:24 -080073
74 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture6d7735d2019-06-21 10:03:19 -070075 blobs, data, CreateTriggerMock(), std::move(verifyMock),
76 CreateTriggerMock());
Patrick Ventureffcc5502018-11-16 12:32:38 -080077
Patrick Venture7dad86f2019-05-17 08:52:20 -070078 EXPECT_CALL(imageMock1, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Ventureffcc5502018-11-16 12:32:38 -080079
80 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070081 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi,
Patrick Venture7dad86f2019-05-17 08:52:20 -070082 hashBlobId));
Patrick Ventureffcc5502018-11-16 12:32:38 -080083
84 EXPECT_FALSE(handler->commit(0, {}));
85}
86
Patrick Venture1d5a31c2019-05-20 11:38:22 -070087} // namespace ipmi_flash