blob: 6242d5414def8fcdad0c414169434efa27ffbd6d [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 Venture7dad86f2019-05-17 08:52:20 -07005#include "util.hpp"
Patrick Venture3ecb3502019-05-17 11:03:51 -07006#include "verification_mock.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{
16using ::testing::Eq;
17using ::testing::Return;
18using ::testing::StrEq;
19
Patrick Venture1361a122019-05-20 07:36:05 -070020class FirmwareHandlerCloseTest : public FakeLpcFirmwareTest
Patrick Venture68bb1432018-11-09 20:08:48 -080021{
Patrick Venture79412582019-05-17 17:34:45 -070022};
23
24TEST_F(FirmwareHandlerCloseTest, CloseSucceedsWithDataHandler)
25{
26 /* Boring test where you open a blob_id, then verify that when it's closed
27 * everything looks right.
28 */
Patrick Venture68bb1432018-11-09 20:08:48 -080029 EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
Patrick Venture7dad86f2019-05-17 08:52:20 -070030 EXPECT_CALL(imageMock, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Venture68bb1432018-11-09 20:08:48 -080031
32 EXPECT_TRUE(handler->open(
Patrick Venture1d5a31c2019-05-20 11:38:22 -070033 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc,
Patrick Venture7dad86f2019-05-17 08:52:20 -070034 hashBlobId));
Patrick Venture68bb1432018-11-09 20:08:48 -080035
36 /* The active hash blob_id was added. */
37 auto currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080038 EXPECT_EQ(4, currentBlobs.size());
Patrick Venture68bb1432018-11-09 20:08:48 -080039 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070040 activeHashBlobId));
Patrick Venture68bb1432018-11-09 20:08:48 -080041
42 /* Set up close() expectations. */
43 EXPECT_CALL(dataMock, close());
44 EXPECT_CALL(imageMock, close());
45 EXPECT_TRUE(handler->close(0));
46
47 /* Close does not delete the active blob id. This indicates that there is
48 * data queued.
49 */
50}
51
Patrick Venture79412582019-05-17 17:34:45 -070052TEST_F(FirmwareHandlerCloseTest, CloseSucceedsWithoutDataHandler)
Patrick Venture68bb1432018-11-09 20:08:48 -080053{
54 /* Boring test where you open a blob_id using ipmi, so there's no data
55 * handler, and it's closed and everything looks right.
56 */
Patrick Venture7dad86f2019-05-17 08:52:20 -070057 EXPECT_CALL(imageMock, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Venture68bb1432018-11-09 20:08:48 -080058
59 EXPECT_TRUE(handler->open(
Patrick Venture1d5a31c2019-05-20 11:38:22 -070060 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi,
Patrick Venture7dad86f2019-05-17 08:52:20 -070061 hashBlobId));
Patrick Venture68bb1432018-11-09 20:08:48 -080062
63 /* The active hash blob_id was added. */
64 auto currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080065 EXPECT_EQ(4, currentBlobs.size());
Patrick Venture68bb1432018-11-09 20:08:48 -080066 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070067 activeHashBlobId));
Patrick Venture68bb1432018-11-09 20:08:48 -080068
69 /* Set up close() expectations. */
70 EXPECT_CALL(imageMock, close());
71 EXPECT_TRUE(handler->close(0));
72}
73
Patrick Venture1d5a31c2019-05-20 11:38:22 -070074} // namespace ipmi_flash