blob: 11ce3fc8f7aaaf20f844c18664f2f8f3c0e05e26 [file] [log] [blame]
Patrick Ventureffcc5502018-11-16 12:32:38 -08001#include "data_mock.hpp"
2#include "firmware_handler.hpp"
3#include "image_mock.hpp"
Patrick Venture1d66fe62019-06-03 14:57:27 -07004#include "triggerable_mock.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -07005#include "util.hpp"
Patrick Ventureffcc5502018-11-16 12:32:38 -08006
Patrick Venture481cd4a2019-05-17 17:53:11 -07007#include <memory>
Patrick Ventureffcc5502018-11-16 12:32:38 -08008#include <vector>
9
10#include <gtest/gtest.h>
11
Patrick Venture1d5a31c2019-05-20 11:38:22 -070012namespace ipmi_flash
Patrick Ventureffcc5502018-11-16 12:32:38 -080013{
Patrick Venturecabc1172018-11-16 16:14:26 -080014using ::testing::_;
15using ::testing::IsNull;
16using ::testing::NotNull;
Patrick Ventureffcc5502018-11-16 12:32:38 -080017using ::testing::Return;
Patrick Venturecabc1172018-11-16 16:14:26 -080018using ::testing::StrEq;
19using ::testing::StrictMock;
Patrick Ventureffcc5502018-11-16 12:32:38 -080020
Patrick Venture481cd4a2019-05-17 17:53:11 -070021class FirmwareHandlerCommitTest : public ::testing::Test
22{
23 protected:
24 ImageHandlerMock imageMock1, imageMock2;
25 std::vector<HandlerPack> blobs;
26 std::vector<DataHandlerPack> data;
27
28 void SetUp() override
29 {
30 blobs = {
31 {hashBlobId, &imageMock1},
32 {"asdf", &imageMock2},
33 };
34
35 data = {
36 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
37 };
38 }
39};
40
41TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnFlashImage)
Patrick Ventureffcc5502018-11-16 12:32:38 -080042{
43 /* Verify the flash image returns failure on this command. It's a fairly
44 * artificial test.
45 */
Patrick Ventureffcc5502018-11-16 12:32:38 -080046
Patrick Venture3ecb3502019-05-17 11:03:51 -070047 /* Verify it doesn't get called by using StrictMock. */
Patrick Venture1d66fe62019-06-03 14:57:27 -070048 std::unique_ptr<TriggerableActionInterface> verifyMock =
49 std::make_unique<StrictMock<TriggerMock>>();
Patrick Venture4eb55952018-11-16 15:36:24 -080050
51 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture1d66fe62019-06-03 14:57:27 -070052 blobs, data, std::move(verifyMock), CreateTriggerMock());
Patrick Ventureffcc5502018-11-16 12:32:38 -080053
54 EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
55
56 EXPECT_TRUE(handler->open(
Patrick Venture1d5a31c2019-05-20 11:38:22 -070057 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi,
58 "asdf"));
Patrick Ventureffcc5502018-11-16 12:32:38 -080059
60 EXPECT_FALSE(handler->commit(0, {}));
61}
62
Patrick Venture481cd4a2019-05-17 17:53:11 -070063TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnHashFile)
Patrick Ventureffcc5502018-11-16 12:32:38 -080064{
65 /* Verify the hash file returns failure on this command. It's a fairly
66 * artificial test.
67 */
Patrick Ventureffcc5502018-11-16 12:32:38 -080068
Patrick Venture3ecb3502019-05-17 11:03:51 -070069 /* Verify it doesn't get called by using StrictMock. */
Patrick Venture1d66fe62019-06-03 14:57:27 -070070 std::unique_ptr<TriggerableActionInterface> verifyMock =
71 std::make_unique<StrictMock<TriggerMock>>();
Patrick Venture4eb55952018-11-16 15:36:24 -080072
73 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture1d66fe62019-06-03 14:57:27 -070074 blobs, data, std::move(verifyMock), CreateTriggerMock());
Patrick Ventureffcc5502018-11-16 12:32:38 -080075
Patrick Venture7dad86f2019-05-17 08:52:20 -070076 EXPECT_CALL(imageMock1, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Ventureffcc5502018-11-16 12:32:38 -080077
78 EXPECT_TRUE(handler->open(
Patrick Venture1d5a31c2019-05-20 11:38:22 -070079 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi,
Patrick Venture7dad86f2019-05-17 08:52:20 -070080 hashBlobId));
Patrick Ventureffcc5502018-11-16 12:32:38 -080081
82 EXPECT_FALSE(handler->commit(0, {}));
83}
84
Patrick Venture1d5a31c2019-05-20 11:38:22 -070085} // namespace ipmi_flash