blob: 3424e89f7d960351b71e6ac6b418728ae0361052 [file] [log] [blame]
Patrick Venture2098ff92019-06-03 10:18:05 -07001/* The goal of these tests is to verify the behavior of all blob commands given
2 * the current state is UpdateCompleted. This state is achieved as an exit from
3 * updateStarted.
4 *
5 * This can be reached with success or failure from an update, and is reached
6 * via a stat() call from updatedStarted.
7 */
Patrick Ventureab1e9622019-06-03 10:45:06 -07008#include "firmware_handler.hpp"
9#include "firmware_unittest.hpp"
10#include "status.hpp"
11#include "util.hpp"
12
13#include <string>
14#include <vector>
15
16#include <gtest/gtest.h>
17
18namespace ipmi_flash
19{
20namespace
21{
22
Patrick Venture7441ab72019-06-05 07:44:38 -070023using ::testing::IsEmpty;
Patrick Venture0c6daf42019-06-05 09:02:50 -070024using ::testing::UnorderedElementsAreArray;
Patrick Venture7441ab72019-06-05 07:44:38 -070025
Patrick Ventureab1e9622019-06-03 10:45:06 -070026/*
27 * There are the following calls (parameters may vary):
28 * canHandleBlob(blob)
29 * getBlobIds
30 * deleteBlob(blob)
31 * stat(blob)
32 * stat(session)
33 * open(blob)
34 * close(session)
35 * writemeta(session)
36 * write(session)
37 * read(session)
38 * commit(session)
39 */
40
41class FirmwareHandlerUpdateCompletedTest : public IpmiOnlyFirmwareStaticTest
42{
43};
44
45/*
46 * open(blob)
47 */
48TEST_F(FirmwareHandlerUpdateCompletedTest,
49 AttemptToOpenFilesReturnsFailureAfterSuccess)
50{
51 /* In state updateCompleted a file is open, which means no others can be. */
Patrick Ventureda66fd82019-06-03 11:11:24 -070052 getToUpdateCompleted(ActionStatus::success);
Patrick Ventureab1e9622019-06-03 10:45:06 -070053
54 auto blobsToOpen = handler->getBlobIds();
55 for (const auto& blob : blobsToOpen)
56 {
57 EXPECT_FALSE(handler->open(session + 1, flags, blob));
58 }
59}
60
61/*
Patrick Venturea2d82392019-06-03 10:55:17 -070062 * stat(session)
63 */
64TEST_F(FirmwareHandlerUpdateCompletedTest,
65 CallingStatSessionAfterCompletedSuccessReturnsStateWithoutRechecking)
66{
Patrick Ventureda66fd82019-06-03 11:11:24 -070067 getToUpdateCompleted(ActionStatus::success);
Patrick Venturea2d82392019-06-03 10:55:17 -070068 EXPECT_CALL(*updateMockPtr, status()).Times(0);
69
70 blobs::BlobMeta meta, expectedMeta = {};
71 expectedMeta.size = 0;
72 expectedMeta.blobState = flags | blobs::StateFlags::committed;
73 expectedMeta.metadata.push_back(
Patrick Ventureda66fd82019-06-03 11:11:24 -070074 static_cast<std::uint8_t>(ActionStatus::success));
Patrick Venturea2d82392019-06-03 10:55:17 -070075
76 EXPECT_TRUE(handler->stat(session, &meta));
77 EXPECT_EQ(expectedMeta, meta);
78 expectedState(FirmwareBlobHandler::UpdateState::updateCompleted);
79}
80
81TEST_F(FirmwareHandlerUpdateCompletedTest,
82 CallingStatSessionAfterCompletedFailureReturnsStateWithoutRechecking)
83{
Patrick Ventureda66fd82019-06-03 11:11:24 -070084 getToUpdateCompleted(ActionStatus::failed);
Patrick Venturea2d82392019-06-03 10:55:17 -070085 EXPECT_CALL(*updateMockPtr, status()).Times(0);
86
87 blobs::BlobMeta meta, expectedMeta = {};
88 expectedMeta.size = 0;
89 expectedMeta.blobState = flags | blobs::StateFlags::commit_error;
90 expectedMeta.metadata.push_back(
Patrick Ventureda66fd82019-06-03 11:11:24 -070091 static_cast<std::uint8_t>(ActionStatus::failed));
Patrick Venturea2d82392019-06-03 10:55:17 -070092
93 EXPECT_TRUE(handler->stat(session, &meta));
94 EXPECT_EQ(expectedMeta, meta);
95 expectedState(FirmwareBlobHandler::UpdateState::updateCompleted);
96}
97
98/*
Patrick Venture25dfaff2019-06-03 13:17:22 -070099 * stat(blob)
100 */
101TEST_F(FirmwareHandlerUpdateCompletedTest, StatOnActiveImageReturnsFailure)
102{
103 getToUpdateCompleted(ActionStatus::success);
104
105 ASSERT_TRUE(handler->canHandleBlob(activeImageBlobId));
106
107 blobs::BlobMeta meta;
108 EXPECT_FALSE(handler->stat(activeImageBlobId, &meta));
109}
110
111TEST_F(FirmwareHandlerUpdateCompletedTest, StatOnUpdateBlobReturnsFailure)
112{
113 getToUpdateCompleted(ActionStatus::success);
114
115 ASSERT_TRUE(handler->canHandleBlob(updateBlobId));
116
117 blobs::BlobMeta meta;
118 EXPECT_FALSE(handler->stat(updateBlobId, &meta));
119}
120
121TEST_F(FirmwareHandlerUpdateCompletedTest, StatOnNormalBlobsReturnsSuccess)
122{
123 getToUpdateCompleted(ActionStatus::success);
124
125 blobs::BlobMeta expected;
126 expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi;
127 expected.size = 0;
128
129 std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId};
130 for (const auto& blob : testBlobs)
131 {
132 ASSERT_TRUE(handler->canHandleBlob(blob));
133
134 blobs::BlobMeta meta = {};
135 EXPECT_TRUE(handler->stat(blob, &meta));
136 EXPECT_EQ(expected, meta);
137 }
138}
139
140/*
Patrick Venture58202b22019-06-03 13:38:09 -0700141 * writemeta(session)
142 */
143TEST_F(FirmwareHandlerUpdateCompletedTest, WriteMetaToUpdateBlobReturnsFailure)
144{
145 getToUpdateCompleted(ActionStatus::success);
146
147 EXPECT_FALSE(handler->writeMeta(session, 0, {0x01}));
148}
149
150/*
Patrick Venture254b4cf2019-06-03 13:44:49 -0700151 * write(session)
152 */
153TEST_F(FirmwareHandlerUpdateCompletedTest, WriteToUpdateBlobReturnsFailure)
154{
155 getToUpdateCompleted(ActionStatus::success);
156
157 EXPECT_FALSE(handler->write(session, 0, {0x01}));
158}
159
160/*
Patrick Venturefdeb8642019-06-03 14:30:34 -0700161 * commit(session) - returns failure
162 */
163TEST_F(FirmwareHandlerUpdateCompletedTest,
164 CommitOnUpdateBlobAfterSuccessReturnsFailure)
165{
166 getToUpdateCompleted(ActionStatus::success);
167
Patrick Venture1d66fe62019-06-03 14:57:27 -0700168 EXPECT_CALL(*updateMockPtr, trigger()).Times(0);
Patrick Venturefdeb8642019-06-03 14:30:34 -0700169 EXPECT_FALSE(handler->commit(session, {}));
170}
171
172TEST_F(FirmwareHandlerUpdateCompletedTest,
173 CommitOnUpdateBlobAfterFailureReturnsFailure)
174{
175 getToUpdateCompleted(ActionStatus::failed);
176
Patrick Venture1d66fe62019-06-03 14:57:27 -0700177 EXPECT_CALL(*updateMockPtr, trigger()).Times(0);
Patrick Venturefdeb8642019-06-03 14:30:34 -0700178 EXPECT_FALSE(handler->commit(session, {}));
179}
180
181/*
Patrick Venture7441ab72019-06-05 07:44:38 -0700182 * read(session) - nothing to read here.
183 */
184TEST_F(FirmwareHandlerUpdateCompletedTest, ReadingFromUpdateBlobReturnsNothing)
185{
186 getToUpdateCompleted(ActionStatus::success);
187
188 EXPECT_THAT(handler->read(session, 0, 1), IsEmpty());
189}
190
191/*
Patrick Ventureab1e9622019-06-03 10:45:06 -0700192 * getBlobIds
Patrick Venture0c6daf42019-06-05 09:02:50 -0700193 * canHandleBlob(blob)
194 */
195TEST_F(FirmwareHandlerUpdateCompletedTest, GetBlobListProvidesExpectedBlobs)
196{
197 getToUpdateCompleted(ActionStatus::success);
198
199 std::vector<std::string> expected = {updateBlobId, hashBlobId,
200 activeImageBlobId, staticLayoutBlobId};
201 EXPECT_THAT(handler->getBlobIds(), UnorderedElementsAreArray(expected));
202}
203
204/*
Patrick Venture85ae86b2019-06-05 09:18:40 -0700205 * close(session) - closes everything out and returns to state not-yet-started.
206 * It doesn't go and clean out any update artifacts that may be present on the
207 * system. It's up to the update implementation to deal with this before
208 * marking complete.
209 */
210TEST_F(FirmwareHandlerUpdateCompletedTest,
211 ClosingOnUpdateBlobIdAfterSuccessReturnsToNotYetStartedAndCleansBlobList)
212{
213 getToUpdateCompleted(ActionStatus::success);
214
215 handler->close(session);
216 expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
217
218 std::vector<std::string> expected = {hashBlobId, staticLayoutBlobId};
219 EXPECT_THAT(handler->getBlobIds(), UnorderedElementsAreArray(expected));
220}
221
222TEST_F(FirmwareHandlerUpdateCompletedTest,
223 ClosingOnUpdateBlobIdAfterFailureReturnsToNotYetStartedAndCleansBlobList)
224{
225 getToUpdateCompleted(ActionStatus::failed);
226
227 handler->close(session);
228 expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
229
230 std::vector<std::string> expected = {hashBlobId, staticLayoutBlobId};
231 EXPECT_THAT(handler->getBlobIds(), UnorderedElementsAreArray(expected));
232}
233
234/*
Patrick Venture0c6daf42019-06-05 09:02:50 -0700235 * There are the following calls (parameters may vary):
Patrick Venture85ae86b2019-06-05 09:18:40 -0700236 * TODO: deleteBlob(blob)
Patrick Ventureab1e9622019-06-03 10:45:06 -0700237 */
238
239} // namespace
240} // namespace ipmi_flash