blob: 392ff18394ed08ea8f33a87d916a297dd632e83f [file] [log] [blame]
Patrick Venture16ab2a12019-05-31 08:52:51 -07001/* The goal of these tests is to verify the behavior of all blob commands given
2 * the current state is updateStarted. This state is achieved as an exit from
3 * updatePending.
4 */
5#include "firmware_handler.hpp"
6#include "firmware_unittest.hpp"
7#include "status.hpp"
8#include "util.hpp"
9
10#include <cstdint>
11#include <string>
12#include <vector>
13
14#include <gtest/gtest.h>
15
16namespace ipmi_flash
17{
18namespace
19{
20
Patrick Venture73e2bdf2019-05-31 11:21:52 -070021using ::testing::IsEmpty;
Patrick Venture16ab2a12019-05-31 08:52:51 -070022using ::testing::Return;
Patrick Ventured9a95782019-05-31 10:46:56 -070023using ::testing::UnorderedElementsAreArray;
Patrick Venture16ab2a12019-05-31 08:52:51 -070024
25/*
26 * There are the following calls (parameters may vary):
27 * canHandleBlob(blob)
28 * getBlobIds
29 * deleteBlob(blob)
30 * stat(blob)
31 * stat(session)
32 * open(blob)
33 * close(session)
34 * writemeta(session)
35 * write(session)
36 * read(session)
37 * commit(session)
38 */
39
40class FirmwareHandlerUpdateStartedTest : public IpmiOnlyFirmwareStaticTest
41{
42};
43
Patrick Venturef515b9c2019-05-31 10:38:16 -070044/*
45 * open(blob)
46 */
47TEST_F(FirmwareHandlerUpdateStartedTest, AttemptToOpenFilesReturnsFailure)
48{
49 /* In state updateStarted a file is open, which means no others can be. */
50 getToUpdateStarted();
51
52 auto blobsToOpen = handler->getBlobIds();
53 for (const auto& blob : blobsToOpen)
54 {
55 EXPECT_FALSE(handler->open(session + 1, flags, blob));
56 }
57}
58
Patrick Venture16ab2a12019-05-31 08:52:51 -070059/* canHandleBlob(blob)
60 * getBlobIds
61 */
Patrick Ventured9a95782019-05-31 10:46:56 -070062TEST_F(FirmwareHandlerUpdateStartedTest, VerifyListOfBlobs)
63{
64 getToUpdateStarted();
65
66 std::vector<std::string> expected = {updateBlobId, hashBlobId,
67 activeImageBlobId, staticLayoutBlobId};
68 EXPECT_THAT(handler->getBlobIds(), UnorderedElementsAreArray(expected));
69}
Patrick Venture16ab2a12019-05-31 08:52:51 -070070
71/*
72 * TODO: deleteBlob(blob)
73 */
74
75/*
76 * stat(blob)
77 */
Patrick Venturefc34cfa2019-05-31 11:02:51 -070078TEST_F(FirmwareHandlerUpdateStartedTest, StatOnActiveImageReturnsFailure)
79{
80 getToUpdateStarted();
81
82 ASSERT_TRUE(handler->canHandleBlob(activeImageBlobId));
83
84 blobs::BlobMeta meta;
85 EXPECT_FALSE(handler->stat(activeImageBlobId, &meta));
86}
87
88TEST_F(FirmwareHandlerUpdateStartedTest, StatOnUpdateBlobReturnsFailure)
89{
90 getToUpdateStarted();
91
92 ASSERT_TRUE(handler->canHandleBlob(updateBlobId));
93
94 blobs::BlobMeta meta;
95 EXPECT_FALSE(handler->stat(updateBlobId, &meta));
96}
97
98TEST_F(FirmwareHandlerUpdateStartedTest, StatOnNormalBlobsReturnsSuccess)
99{
100 getToUpdateStarted();
101
102 blobs::BlobMeta expected;
103 expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi;
104 expected.size = 0;
105
106 std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId};
107 for (const auto& blob : testBlobs)
108 {
109 ASSERT_TRUE(handler->canHandleBlob(blob));
110
111 blobs::BlobMeta meta = {};
112 EXPECT_TRUE(handler->stat(blob, &meta));
113 EXPECT_EQ(expected, meta);
114 }
115}
Patrick Venture16ab2a12019-05-31 08:52:51 -0700116
117/*
Patrick Venture16ab2a12019-05-31 08:52:51 -0700118 * writemeta(session)
119 */
Patrick Ventureb6ce52b2019-05-31 11:16:41 -0700120TEST_F(FirmwareHandlerUpdateStartedTest, WriteMetaToUpdateBlobReturnsFailure)
121{
122 getToUpdateStarted();
123 EXPECT_FALSE(handler->writeMeta(session, 0, {0x01}));
124}
Patrick Venture16ab2a12019-05-31 08:52:51 -0700125
126/*
127 * write(session)
128 */
Patrick Venture575118d2019-05-31 11:20:35 -0700129TEST_F(FirmwareHandlerUpdateStartedTest, WriteToUpdateBlobReturnsFailure)
130{
131 getToUpdateStarted();
132 EXPECT_FALSE(handler->write(session, 0, {0x01}));
133}
Patrick Venture16ab2a12019-05-31 08:52:51 -0700134
135/*
136 * read(session)
137 */
Patrick Venture73e2bdf2019-05-31 11:21:52 -0700138TEST_F(FirmwareHandlerUpdateStartedTest, ReadFromUpdateBlobReturnsEmpty)
139{
140 getToUpdateStarted();
141 EXPECT_THAT(handler->read(session, 0, 1), IsEmpty());
142}
Patrick Venture16ab2a12019-05-31 08:52:51 -0700143
144/*
Patrick Ventureb6ce52b2019-05-31 11:16:41 -0700145 * stat(session) - this will trigger a check, and the state may change.
146 */
147
148/*
149 * TODO: close(session) - this will abort.
150 */
151
152/*
Patrick Venture16ab2a12019-05-31 08:52:51 -0700153 * commit(session)
154 */
155
156} // namespace
157} // namespace ipmi_flash