blob: d4e7cf86b07eb6fe8fa4ed0740a78c13a601b21b [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 Venture68bb1432018-11-09 20:08:48 -080024{
Patrick Venture79412582019-05-17 17:34:45 -070025};
26
27TEST_F(FirmwareHandlerCloseTest, CloseSucceedsWithDataHandler)
28{
29 /* Boring test where you open a blob_id, then verify that when it's closed
30 * everything looks right.
31 */
Patrick Venture68bb1432018-11-09 20:08:48 -080032 EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
Patrick Venture7dad86f2019-05-17 08:52:20 -070033 EXPECT_CALL(imageMock, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Venture68bb1432018-11-09 20:08:48 -080034
35 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070036 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::lpc,
Patrick Venture7dad86f2019-05-17 08:52:20 -070037 hashBlobId));
Patrick Venture68bb1432018-11-09 20:08:48 -080038
39 /* The active hash blob_id was added. */
40 auto currentBlobs = handler->getBlobIds();
Patrick Venture930c7b72019-05-24 11:11:08 -070041 EXPECT_EQ(3, currentBlobs.size());
Patrick Venture68bb1432018-11-09 20:08:48 -080042 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070043 activeHashBlobId));
Patrick Venture68bb1432018-11-09 20:08:48 -080044
45 /* Set up close() expectations. */
46 EXPECT_CALL(dataMock, close());
47 EXPECT_CALL(imageMock, close());
48 EXPECT_TRUE(handler->close(0));
49
50 /* Close does not delete the active blob id. This indicates that there is
51 * data queued.
52 */
53}
54
Patrick Venture79412582019-05-17 17:34:45 -070055TEST_F(FirmwareHandlerCloseTest, CloseSucceedsWithoutDataHandler)
Patrick Venture68bb1432018-11-09 20:08:48 -080056{
57 /* Boring test where you open a blob_id using ipmi, so there's no data
58 * handler, and it's closed and everything looks right.
59 */
Patrick Venture7dad86f2019-05-17 08:52:20 -070060 EXPECT_CALL(imageMock, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Venture68bb1432018-11-09 20:08:48 -080061
62 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070063 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi,
Patrick Venture7dad86f2019-05-17 08:52:20 -070064 hashBlobId));
Patrick Venture68bb1432018-11-09 20:08:48 -080065
66 /* The active hash blob_id was added. */
67 auto currentBlobs = handler->getBlobIds();
Patrick Venture930c7b72019-05-24 11:11:08 -070068 EXPECT_EQ(3, currentBlobs.size());
Patrick Venture68bb1432018-11-09 20:08:48 -080069 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070070 activeHashBlobId));
Patrick Venture68bb1432018-11-09 20:08:48 -080071
72 /* Set up close() expectations. */
73 EXPECT_CALL(imageMock, close());
74 EXPECT_TRUE(handler->close(0));
75}
76
Patrick Venture930c7b72019-05-24 11:11:08 -070077} // namespace
Patrick Venture1d5a31c2019-05-20 11:38:22 -070078} // namespace ipmi_flash