blob: cb50b8efa974be74068a8655b8ac8e2a4d4e5445 [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 Venture63902a42020-10-06 12:13:31 -070017
Patrick Ventureffcc5502018-11-16 12:32:38 -080018using ::testing::Return;
Patrick Venturecabc1172018-11-16 16:14:26 -080019using ::testing::StrEq;
Patrick Ventureffcc5502018-11-16 12:32:38 -080020
Patrick Venture481cd4a2019-05-17 17:53:11 -070021class FirmwareHandlerCommitTest : public ::testing::Test
22{
23 protected:
Patrick Ventured4e20de2019-07-18 12:48:05 -070024 ImageHandlerMock *imageMock1, *imageMock2;
Patrick Venture481cd4a2019-05-17 17:53:11 -070025 std::vector<HandlerPack> blobs;
26 std::vector<DataHandlerPack> data;
27
28 void SetUp() override
29 {
Patrick Ventured4e20de2019-07-18 12:48:05 -070030 std::unique_ptr<ImageHandlerInterface> image =
31 std::make_unique<ImageHandlerMock>();
32 imageMock1 = reinterpret_cast<ImageHandlerMock*>(image.get());
Patrick Venturec6ba8ff2020-09-23 12:42:57 -070033 blobs.emplace_back(hashBlobId, std::move(image));
Patrick Ventured4e20de2019-07-18 12:48:05 -070034
35 image = std::make_unique<ImageHandlerMock>();
36 imageMock2 = reinterpret_cast<ImageHandlerMock*>(image.get());
Patrick Venturec6ba8ff2020-09-23 12:42:57 -070037 blobs.emplace_back("asdf", std::move(image));
Patrick Venture481cd4a2019-05-17 17:53:11 -070038
Patrick Venture4934daa2020-09-22 16:37:44 -070039 data.emplace_back(FirmwareFlags::UpdateFlags::ipmi, nullptr);
Patrick Venture481cd4a2019-05-17 17:53:11 -070040 }
41};
42
43TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnFlashImage)
Patrick Ventureffcc5502018-11-16 12:32:38 -080044{
45 /* Verify the flash image returns failure on this command. It's a fairly
46 * artificial test.
47 */
Patrick Venture4eb55952018-11-16 15:36:24 -080048 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Ventureda4d4a42020-09-28 11:41:05 -070049 std::move(blobs), std::move(data), CreateActionMap("asdf"));
Patrick Ventureffcc5502018-11-16 12:32:38 -080050
Patrick Ventured4e20de2019-07-18 12:48:05 -070051 EXPECT_CALL(*imageMock2, open("asdf")).WillOnce(Return(true));
Patrick Ventureffcc5502018-11-16 12:32:38 -080052
53 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070054 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, "asdf"));
Patrick Ventureffcc5502018-11-16 12:32:38 -080055
56 EXPECT_FALSE(handler->commit(0, {}));
57}
58
Patrick Venture481cd4a2019-05-17 17:53:11 -070059TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnHashFile)
Patrick Ventureffcc5502018-11-16 12:32:38 -080060{
61 /* Verify the hash file returns failure on this command. It's a fairly
62 * artificial test.
63 */
Patrick Venture4eb55952018-11-16 15:36:24 -080064 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Ventureda4d4a42020-09-28 11:41:05 -070065 std::move(blobs), std::move(data), CreateActionMap("asdf"));
Patrick Ventureffcc5502018-11-16 12:32:38 -080066
Patrick Ventured4e20de2019-07-18 12:48:05 -070067 EXPECT_CALL(*imageMock1, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Ventureffcc5502018-11-16 12:32:38 -080068
69 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070070 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi,
Patrick Venture7dad86f2019-05-17 08:52:20 -070071 hashBlobId));
Patrick Ventureffcc5502018-11-16 12:32:38 -080072
73 EXPECT_FALSE(handler->commit(0, {}));
74}
75
Patrick Venturefa06a5f2019-07-01 09:22:38 -070076} // namespace
Patrick Venture1d5a31c2019-05-20 11:38:22 -070077} // namespace ipmi_flash