blob: 6d1fe55ad2508f4207682b2bbaa7237590a02397 [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::Return;
20using ::testing::StrEq;
21
Patrick Venture1361a122019-05-20 07:36:05 -070022class FirmwareHandlerCloseTest : public FakeLpcFirmwareTest
Patrick Venture9b37b092020-05-28 20:58:57 -070023{};
Patrick Venture79412582019-05-17 17:34:45 -070024
25TEST_F(FirmwareHandlerCloseTest, CloseSucceedsWithDataHandler)
26{
27 /* Boring test where you open a blob_id, then verify that when it's closed
28 * everything looks right.
29 */
Patrick Venture4934daa2020-09-22 16:37:44 -070030 EXPECT_CALL(*dataMock, open()).WillOnce(Return(true));
Patrick Ventured4e20de2019-07-18 12:48:05 -070031 EXPECT_CALL(*hashImageMock, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Venture68bb1432018-11-09 20:08:48 -080032
33 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070034 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::lpc,
Patrick Venture7dad86f2019-05-17 08:52:20 -070035 hashBlobId));
Patrick Venture68bb1432018-11-09 20:08:48 -080036
37 /* The active hash blob_id was added. */
38 auto currentBlobs = handler->getBlobIds();
Patrick Venture930c7b72019-05-24 11:11:08 -070039 EXPECT_EQ(3, currentBlobs.size());
Patrick Venture68bb1432018-11-09 20:08:48 -080040 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070041 activeHashBlobId));
Patrick Venture68bb1432018-11-09 20:08:48 -080042
43 /* Set up close() expectations. */
Patrick Venture4934daa2020-09-22 16:37:44 -070044 EXPECT_CALL(*dataMock, close());
Patrick Ventured4e20de2019-07-18 12:48:05 -070045 EXPECT_CALL(*hashImageMock, close());
Patrick Venture68bb1432018-11-09 20:08:48 -080046 EXPECT_TRUE(handler->close(0));
47
48 /* Close does not delete the active blob id. This indicates that there is
49 * data queued.
50 */
51}
52
Patrick Venture79412582019-05-17 17:34:45 -070053TEST_F(FirmwareHandlerCloseTest, CloseSucceedsWithoutDataHandler)
Patrick Venture68bb1432018-11-09 20:08:48 -080054{
55 /* Boring test where you open a blob_id using ipmi, so there's no data
56 * handler, and it's closed and everything looks right.
57 */
Patrick Ventured4e20de2019-07-18 12:48:05 -070058 EXPECT_CALL(*hashImageMock, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Venture68bb1432018-11-09 20:08:48 -080059
60 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070061 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi,
Patrick Venture7dad86f2019-05-17 08:52:20 -070062 hashBlobId));
Patrick Venture68bb1432018-11-09 20:08:48 -080063
64 /* The active hash blob_id was added. */
65 auto currentBlobs = handler->getBlobIds();
Patrick Venture930c7b72019-05-24 11:11:08 -070066 EXPECT_EQ(3, currentBlobs.size());
Patrick Venture68bb1432018-11-09 20:08:48 -080067 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070068 activeHashBlobId));
Patrick Venture68bb1432018-11-09 20:08:48 -080069
70 /* Set up close() expectations. */
Patrick Ventured4e20de2019-07-18 12:48:05 -070071 EXPECT_CALL(*hashImageMock, close());
Patrick Venture68bb1432018-11-09 20:08:48 -080072 EXPECT_TRUE(handler->close(0));
73}
74
Patrick Venture930c7b72019-05-24 11:11:08 -070075} // namespace
Patrick Venture1d5a31c2019-05-20 11:38:22 -070076} // namespace ipmi_flash