blob: 580fcf46ef8a45d19791117bf888bcc7eb5e4944 [file] [log] [blame]
Patrick Venture68bb1432018-11-09 20:08:48 -08001#include "data_mock.hpp"
2#include "firmware_handler.hpp"
Patrick Venture1361a122019-05-20 07:36:05 -07003#include "firmware_unittest.hpp"
Patrick Venture68bb1432018-11-09 20:08:48 -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 Venture68bb1432018-11-09 20:08:48 -08007
Patrick Venture79412582019-05-17 17:34:45 -07008#include <memory>
Patrick Venture68bb1432018-11-09 20:08:48 -08009#include <vector>
10
11#include <gmock/gmock.h>
12#include <gtest/gtest.h>
13
Patrick Venture1d5a31c2019-05-20 11:38:22 -070014namespace ipmi_flash
Patrick Venture68bb1432018-11-09 20:08:48 -080015{
Patrick Venture930c7b72019-05-24 11:11:08 -070016namespace
17{
18
Patrick Venture68bb1432018-11-09 20:08:48 -080019using ::testing::Eq;
20using ::testing::Return;
21using ::testing::StrEq;
22
Patrick Venture1361a122019-05-20 07:36:05 -070023class FirmwareHandlerCloseTest : public FakeLpcFirmwareTest
Patrick Venture9b37b092020-05-28 20:58:57 -070024{};
Patrick Venture79412582019-05-17 17:34:45 -070025
26TEST_F(FirmwareHandlerCloseTest, CloseSucceedsWithDataHandler)
27{
28 /* Boring test where you open a blob_id, then verify that when it's closed
29 * everything looks right.
30 */
Patrick Venture68bb1432018-11-09 20:08:48 -080031 EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
Patrick Ventured4e20de2019-07-18 12:48:05 -070032 EXPECT_CALL(*hashImageMock, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Venture68bb1432018-11-09 20:08:48 -080033
34 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070035 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::lpc,
Patrick Venture7dad86f2019-05-17 08:52:20 -070036 hashBlobId));
Patrick Venture68bb1432018-11-09 20:08:48 -080037
38 /* The active hash blob_id was added. */
39 auto currentBlobs = handler->getBlobIds();
Patrick Venture930c7b72019-05-24 11:11:08 -070040 EXPECT_EQ(3, currentBlobs.size());
Patrick Venture68bb1432018-11-09 20:08:48 -080041 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070042 activeHashBlobId));
Patrick Venture68bb1432018-11-09 20:08:48 -080043
44 /* Set up close() expectations. */
45 EXPECT_CALL(dataMock, close());
Patrick Ventured4e20de2019-07-18 12:48:05 -070046 EXPECT_CALL(*hashImageMock, close());
Patrick Venture68bb1432018-11-09 20:08:48 -080047 EXPECT_TRUE(handler->close(0));
48
49 /* Close does not delete the active blob id. This indicates that there is
50 * data queued.
51 */
52}
53
Patrick Venture79412582019-05-17 17:34:45 -070054TEST_F(FirmwareHandlerCloseTest, CloseSucceedsWithoutDataHandler)
Patrick Venture68bb1432018-11-09 20:08:48 -080055{
56 /* Boring test where you open a blob_id using ipmi, so there's no data
57 * handler, and it's closed and everything looks right.
58 */
Patrick Ventured4e20de2019-07-18 12:48:05 -070059 EXPECT_CALL(*hashImageMock, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Venture68bb1432018-11-09 20:08:48 -080060
61 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070062 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi,
Patrick Venture7dad86f2019-05-17 08:52:20 -070063 hashBlobId));
Patrick Venture68bb1432018-11-09 20:08:48 -080064
65 /* The active hash blob_id was added. */
66 auto currentBlobs = handler->getBlobIds();
Patrick Venture930c7b72019-05-24 11:11:08 -070067 EXPECT_EQ(3, currentBlobs.size());
Patrick Venture68bb1432018-11-09 20:08:48 -080068 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070069 activeHashBlobId));
Patrick Venture68bb1432018-11-09 20:08:48 -080070
71 /* Set up close() expectations. */
Patrick Ventured4e20de2019-07-18 12:48:05 -070072 EXPECT_CALL(*hashImageMock, close());
Patrick Venture68bb1432018-11-09 20:08:48 -080073 EXPECT_TRUE(handler->close(0));
74}
75
Patrick Venture930c7b72019-05-24 11:11:08 -070076} // namespace
Patrick Venture1d5a31c2019-05-20 11:38:22 -070077} // namespace ipmi_flash