blob: 16d98819c443888ad055cbe4c95b25f47851adca [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:
27 ImageHandlerMock imageMock1, imageMock2;
28 std::vector<HandlerPack> blobs;
29 std::vector<DataHandlerPack> data;
30
31 void SetUp() override
32 {
33 blobs = {
34 {hashBlobId, &imageMock1},
35 {"asdf", &imageMock2},
36 };
37
38 data = {
Patrick Venture84778b82019-06-26 20:11:09 -070039 {FirmwareFlags::UpdateFlags::ipmi, nullptr},
Patrick Venture481cd4a2019-05-17 17:53:11 -070040 };
41 }
42};
43
44TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnFlashImage)
Patrick Ventureffcc5502018-11-16 12:32:38 -080045{
46 /* Verify the flash image returns failure on this command. It's a fairly
47 * artificial test.
48 */
Patrick Ventureffcc5502018-11-16 12:32:38 -080049
Patrick Venture3ecb3502019-05-17 11:03:51 -070050 /* Verify it doesn't get called by using StrictMock. */
Patrick Venture1d66fe62019-06-03 14:57:27 -070051 std::unique_ptr<TriggerableActionInterface> verifyMock =
52 std::make_unique<StrictMock<TriggerMock>>();
Patrick Venture4eb55952018-11-16 15:36:24 -080053
54 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venturefa06a5f2019-07-01 09:22:38 -070055 blobs, data, std::move(CreateActionMap("asdf")));
Patrick Ventureffcc5502018-11-16 12:32:38 -080056
57 EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
58
59 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070060 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, "asdf"));
Patrick Ventureffcc5502018-11-16 12:32:38 -080061
62 EXPECT_FALSE(handler->commit(0, {}));
63}
64
Patrick Venture481cd4a2019-05-17 17:53:11 -070065TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnHashFile)
Patrick Ventureffcc5502018-11-16 12:32:38 -080066{
67 /* Verify the hash file returns failure on this command. It's a fairly
68 * artificial test.
69 */
Patrick Ventureffcc5502018-11-16 12:32:38 -080070
Patrick Venture3ecb3502019-05-17 11:03:51 -070071 /* Verify it doesn't get called by using StrictMock. */
Patrick Venture1d66fe62019-06-03 14:57:27 -070072 std::unique_ptr<TriggerableActionInterface> verifyMock =
73 std::make_unique<StrictMock<TriggerMock>>();
Patrick Venture4eb55952018-11-16 15:36:24 -080074
75 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venturefa06a5f2019-07-01 09:22:38 -070076 blobs, data, std::move(CreateActionMap("asdf")));
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 Venturefa06a5f2019-07-01 09:22:38 -070087} // namespace
Patrick Venture1d5a31c2019-05-20 11:38:22 -070088} // namespace ipmi_flash