blob: 6e241079e03b231b6d34bede25a64e9b6de8921a [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());
Patrick Venturec6ba8ff2020-09-23 12:42:57 -070036 blobs.emplace_back(hashBlobId, std::move(image));
Patrick Ventured4e20de2019-07-18 12:48:05 -070037
38 image = std::make_unique<ImageHandlerMock>();
39 imageMock2 = reinterpret_cast<ImageHandlerMock*>(image.get());
Patrick Venturec6ba8ff2020-09-23 12:42:57 -070040 blobs.emplace_back("asdf", std::move(image));
Patrick Venture481cd4a2019-05-17 17:53:11 -070041
Patrick Venture4934daa2020-09-22 16:37:44 -070042 data.emplace_back(FirmwareFlags::UpdateFlags::ipmi, nullptr);
Patrick Venture481cd4a2019-05-17 17:53:11 -070043 }
44};
45
46TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnFlashImage)
Patrick Ventureffcc5502018-11-16 12:32:38 -080047{
48 /* Verify the flash image returns failure on this command. It's a fairly
49 * artificial test.
50 */
Patrick Venture4eb55952018-11-16 15:36:24 -080051 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Ventureda4d4a42020-09-28 11:41:05 -070052 std::move(blobs), std::move(data), CreateActionMap("asdf"));
Patrick Ventureffcc5502018-11-16 12:32:38 -080053
Patrick Ventured4e20de2019-07-18 12:48:05 -070054 EXPECT_CALL(*imageMock2, open("asdf")).WillOnce(Return(true));
Patrick Ventureffcc5502018-11-16 12:32:38 -080055
56 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070057 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, "asdf"));
Patrick Ventureffcc5502018-11-16 12:32:38 -080058
59 EXPECT_FALSE(handler->commit(0, {}));
60}
61
Patrick Venture481cd4a2019-05-17 17:53:11 -070062TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnHashFile)
Patrick Ventureffcc5502018-11-16 12:32:38 -080063{
64 /* Verify the hash file returns failure on this command. It's a fairly
65 * artificial test.
66 */
Patrick Venture4eb55952018-11-16 15:36:24 -080067 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Ventureda4d4a42020-09-28 11:41:05 -070068 std::move(blobs), std::move(data), CreateActionMap("asdf"));
Patrick Ventureffcc5502018-11-16 12:32:38 -080069
Patrick Ventured4e20de2019-07-18 12:48:05 -070070 EXPECT_CALL(*imageMock1, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Ventureffcc5502018-11-16 12:32:38 -080071
72 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070073 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi,
Patrick Venture7dad86f2019-05-17 08:52:20 -070074 hashBlobId));
Patrick Ventureffcc5502018-11-16 12:32:38 -080075
76 EXPECT_FALSE(handler->commit(0, {}));
77}
78
Patrick Venturefa06a5f2019-07-01 09:22:38 -070079} // namespace
Patrick Venture1d5a31c2019-05-20 11:38:22 -070080} // namespace ipmi_flash