blob: 357458c3b1d84b27737b6afe904127d6430de3b3 [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;
24
Patrick Ventureab1e9622019-06-03 10:45:06 -070025/*
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 FirmwareHandlerUpdateCompletedTest : public IpmiOnlyFirmwareStaticTest
41{
42};
43
44/*
45 * open(blob)
46 */
47TEST_F(FirmwareHandlerUpdateCompletedTest,
48 AttemptToOpenFilesReturnsFailureAfterSuccess)
49{
50 /* In state updateCompleted a file is open, which means no others can be. */
Patrick Ventureda66fd82019-06-03 11:11:24 -070051 getToUpdateCompleted(ActionStatus::success);
Patrick Ventureab1e9622019-06-03 10:45:06 -070052
53 auto blobsToOpen = handler->getBlobIds();
54 for (const auto& blob : blobsToOpen)
55 {
56 EXPECT_FALSE(handler->open(session + 1, flags, blob));
57 }
58}
59
60/*
Patrick Venturea2d82392019-06-03 10:55:17 -070061 * stat(session)
62 */
63TEST_F(FirmwareHandlerUpdateCompletedTest,
64 CallingStatSessionAfterCompletedSuccessReturnsStateWithoutRechecking)
65{
Patrick Ventureda66fd82019-06-03 11:11:24 -070066 getToUpdateCompleted(ActionStatus::success);
Patrick Venturea2d82392019-06-03 10:55:17 -070067 EXPECT_CALL(*updateMockPtr, status()).Times(0);
68
69 blobs::BlobMeta meta, expectedMeta = {};
70 expectedMeta.size = 0;
71 expectedMeta.blobState = flags | blobs::StateFlags::committed;
72 expectedMeta.metadata.push_back(
Patrick Ventureda66fd82019-06-03 11:11:24 -070073 static_cast<std::uint8_t>(ActionStatus::success));
Patrick Venturea2d82392019-06-03 10:55:17 -070074
75 EXPECT_TRUE(handler->stat(session, &meta));
76 EXPECT_EQ(expectedMeta, meta);
77 expectedState(FirmwareBlobHandler::UpdateState::updateCompleted);
78}
79
80TEST_F(FirmwareHandlerUpdateCompletedTest,
81 CallingStatSessionAfterCompletedFailureReturnsStateWithoutRechecking)
82{
Patrick Ventureda66fd82019-06-03 11:11:24 -070083 getToUpdateCompleted(ActionStatus::failed);
Patrick Venturea2d82392019-06-03 10:55:17 -070084 EXPECT_CALL(*updateMockPtr, status()).Times(0);
85
86 blobs::BlobMeta meta, expectedMeta = {};
87 expectedMeta.size = 0;
88 expectedMeta.blobState = flags | blobs::StateFlags::commit_error;
89 expectedMeta.metadata.push_back(
Patrick Ventureda66fd82019-06-03 11:11:24 -070090 static_cast<std::uint8_t>(ActionStatus::failed));
Patrick Venturea2d82392019-06-03 10:55:17 -070091
92 EXPECT_TRUE(handler->stat(session, &meta));
93 EXPECT_EQ(expectedMeta, meta);
94 expectedState(FirmwareBlobHandler::UpdateState::updateCompleted);
95}
96
97/*
Patrick Venture25dfaff2019-06-03 13:17:22 -070098 * stat(blob)
99 */
100TEST_F(FirmwareHandlerUpdateCompletedTest, StatOnActiveImageReturnsFailure)
101{
102 getToUpdateCompleted(ActionStatus::success);
103
104 ASSERT_TRUE(handler->canHandleBlob(activeImageBlobId));
105
106 blobs::BlobMeta meta;
107 EXPECT_FALSE(handler->stat(activeImageBlobId, &meta));
108}
109
110TEST_F(FirmwareHandlerUpdateCompletedTest, StatOnUpdateBlobReturnsFailure)
111{
112 getToUpdateCompleted(ActionStatus::success);
113
114 ASSERT_TRUE(handler->canHandleBlob(updateBlobId));
115
116 blobs::BlobMeta meta;
117 EXPECT_FALSE(handler->stat(updateBlobId, &meta));
118}
119
120TEST_F(FirmwareHandlerUpdateCompletedTest, StatOnNormalBlobsReturnsSuccess)
121{
122 getToUpdateCompleted(ActionStatus::success);
123
124 blobs::BlobMeta expected;
125 expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi;
126 expected.size = 0;
127
128 std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId};
129 for (const auto& blob : testBlobs)
130 {
131 ASSERT_TRUE(handler->canHandleBlob(blob));
132
133 blobs::BlobMeta meta = {};
134 EXPECT_TRUE(handler->stat(blob, &meta));
135 EXPECT_EQ(expected, meta);
136 }
137}
138
139/*
Patrick Venture58202b22019-06-03 13:38:09 -0700140 * writemeta(session)
141 */
142TEST_F(FirmwareHandlerUpdateCompletedTest, WriteMetaToUpdateBlobReturnsFailure)
143{
144 getToUpdateCompleted(ActionStatus::success);
145
146 EXPECT_FALSE(handler->writeMeta(session, 0, {0x01}));
147}
148
149/*
Patrick Venture254b4cf2019-06-03 13:44:49 -0700150 * write(session)
151 */
152TEST_F(FirmwareHandlerUpdateCompletedTest, WriteToUpdateBlobReturnsFailure)
153{
154 getToUpdateCompleted(ActionStatus::success);
155
156 EXPECT_FALSE(handler->write(session, 0, {0x01}));
157}
158
159/*
Patrick Venturefdeb8642019-06-03 14:30:34 -0700160 * commit(session) - returns failure
161 */
162TEST_F(FirmwareHandlerUpdateCompletedTest,
163 CommitOnUpdateBlobAfterSuccessReturnsFailure)
164{
165 getToUpdateCompleted(ActionStatus::success);
166
Patrick Venture1d66fe62019-06-03 14:57:27 -0700167 EXPECT_CALL(*updateMockPtr, trigger()).Times(0);
Patrick Venturefdeb8642019-06-03 14:30:34 -0700168 EXPECT_FALSE(handler->commit(session, {}));
169}
170
171TEST_F(FirmwareHandlerUpdateCompletedTest,
172 CommitOnUpdateBlobAfterFailureReturnsFailure)
173{
174 getToUpdateCompleted(ActionStatus::failed);
175
Patrick Venture1d66fe62019-06-03 14:57:27 -0700176 EXPECT_CALL(*updateMockPtr, trigger()).Times(0);
Patrick Venturefdeb8642019-06-03 14:30:34 -0700177 EXPECT_FALSE(handler->commit(session, {}));
178}
179
180/*
Patrick Venture7441ab72019-06-05 07:44:38 -0700181 * read(session) - nothing to read here.
182 */
183TEST_F(FirmwareHandlerUpdateCompletedTest, ReadingFromUpdateBlobReturnsNothing)
184{
185 getToUpdateCompleted(ActionStatus::success);
186
187 EXPECT_THAT(handler->read(session, 0, 1), IsEmpty());
188}
189
190/*
Patrick Ventureab1e9622019-06-03 10:45:06 -0700191 * There are the following calls (parameters may vary):
192 * canHandleBlob(blob)
193 * getBlobIds
194 * deleteBlob(blob)
Patrick Ventureab1e9622019-06-03 10:45:06 -0700195 * close(session)
Patrick Ventureab1e9622019-06-03 10:45:06 -0700196 */
197
198} // namespace
199} // namespace ipmi_flash