blob: 98b9a561ed0a42c4846df848bd82d111481b39b8 [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
23/*
24 * There are the following calls (parameters may vary):
25 * canHandleBlob(blob)
26 * getBlobIds
27 * deleteBlob(blob)
28 * stat(blob)
29 * stat(session)
30 * open(blob)
31 * close(session)
32 * writemeta(session)
33 * write(session)
34 * read(session)
35 * commit(session)
36 */
37
38class FirmwareHandlerUpdateCompletedTest : public IpmiOnlyFirmwareStaticTest
39{
40};
41
42/*
43 * open(blob)
44 */
45TEST_F(FirmwareHandlerUpdateCompletedTest,
46 AttemptToOpenFilesReturnsFailureAfterSuccess)
47{
48 /* In state updateCompleted a file is open, which means no others can be. */
Patrick Ventureda66fd82019-06-03 11:11:24 -070049 getToUpdateCompleted(ActionStatus::success);
Patrick Ventureab1e9622019-06-03 10:45:06 -070050
51 auto blobsToOpen = handler->getBlobIds();
52 for (const auto& blob : blobsToOpen)
53 {
54 EXPECT_FALSE(handler->open(session + 1, flags, blob));
55 }
56}
57
58/*
Patrick Venturea2d82392019-06-03 10:55:17 -070059 * stat(session)
60 */
61TEST_F(FirmwareHandlerUpdateCompletedTest,
62 CallingStatSessionAfterCompletedSuccessReturnsStateWithoutRechecking)
63{
Patrick Ventureda66fd82019-06-03 11:11:24 -070064 getToUpdateCompleted(ActionStatus::success);
Patrick Venturea2d82392019-06-03 10:55:17 -070065 EXPECT_CALL(*updateMockPtr, status()).Times(0);
66
67 blobs::BlobMeta meta, expectedMeta = {};
68 expectedMeta.size = 0;
69 expectedMeta.blobState = flags | blobs::StateFlags::committed;
70 expectedMeta.metadata.push_back(
Patrick Ventureda66fd82019-06-03 11:11:24 -070071 static_cast<std::uint8_t>(ActionStatus::success));
Patrick Venturea2d82392019-06-03 10:55:17 -070072
73 EXPECT_TRUE(handler->stat(session, &meta));
74 EXPECT_EQ(expectedMeta, meta);
75 expectedState(FirmwareBlobHandler::UpdateState::updateCompleted);
76}
77
78TEST_F(FirmwareHandlerUpdateCompletedTest,
79 CallingStatSessionAfterCompletedFailureReturnsStateWithoutRechecking)
80{
Patrick Ventureda66fd82019-06-03 11:11:24 -070081 getToUpdateCompleted(ActionStatus::failed);
Patrick Venturea2d82392019-06-03 10:55:17 -070082 EXPECT_CALL(*updateMockPtr, status()).Times(0);
83
84 blobs::BlobMeta meta, expectedMeta = {};
85 expectedMeta.size = 0;
86 expectedMeta.blobState = flags | blobs::StateFlags::commit_error;
87 expectedMeta.metadata.push_back(
Patrick Ventureda66fd82019-06-03 11:11:24 -070088 static_cast<std::uint8_t>(ActionStatus::failed));
Patrick Venturea2d82392019-06-03 10:55:17 -070089
90 EXPECT_TRUE(handler->stat(session, &meta));
91 EXPECT_EQ(expectedMeta, meta);
92 expectedState(FirmwareBlobHandler::UpdateState::updateCompleted);
93}
94
95/*
Patrick Venture25dfaff2019-06-03 13:17:22 -070096 * stat(blob)
97 */
98TEST_F(FirmwareHandlerUpdateCompletedTest, StatOnActiveImageReturnsFailure)
99{
100 getToUpdateCompleted(ActionStatus::success);
101
102 ASSERT_TRUE(handler->canHandleBlob(activeImageBlobId));
103
104 blobs::BlobMeta meta;
105 EXPECT_FALSE(handler->stat(activeImageBlobId, &meta));
106}
107
108TEST_F(FirmwareHandlerUpdateCompletedTest, StatOnUpdateBlobReturnsFailure)
109{
110 getToUpdateCompleted(ActionStatus::success);
111
112 ASSERT_TRUE(handler->canHandleBlob(updateBlobId));
113
114 blobs::BlobMeta meta;
115 EXPECT_FALSE(handler->stat(updateBlobId, &meta));
116}
117
118TEST_F(FirmwareHandlerUpdateCompletedTest, StatOnNormalBlobsReturnsSuccess)
119{
120 getToUpdateCompleted(ActionStatus::success);
121
122 blobs::BlobMeta expected;
123 expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi;
124 expected.size = 0;
125
126 std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId};
127 for (const auto& blob : testBlobs)
128 {
129 ASSERT_TRUE(handler->canHandleBlob(blob));
130
131 blobs::BlobMeta meta = {};
132 EXPECT_TRUE(handler->stat(blob, &meta));
133 EXPECT_EQ(expected, meta);
134 }
135}
136
137/*
Patrick Venture58202b22019-06-03 13:38:09 -0700138 * writemeta(session)
139 */
140TEST_F(FirmwareHandlerUpdateCompletedTest, WriteMetaToUpdateBlobReturnsFailure)
141{
142 getToUpdateCompleted(ActionStatus::success);
143
144 EXPECT_FALSE(handler->writeMeta(session, 0, {0x01}));
145}
146
147/*
Patrick Venture254b4cf2019-06-03 13:44:49 -0700148 * write(session)
149 */
150TEST_F(FirmwareHandlerUpdateCompletedTest, WriteToUpdateBlobReturnsFailure)
151{
152 getToUpdateCompleted(ActionStatus::success);
153
154 EXPECT_FALSE(handler->write(session, 0, {0x01}));
155}
156
157/*
Patrick Ventureab1e9622019-06-03 10:45:06 -0700158 * There are the following calls (parameters may vary):
159 * canHandleBlob(blob)
160 * getBlobIds
161 * deleteBlob(blob)
Patrick Ventureab1e9622019-06-03 10:45:06 -0700162 * close(session)
Patrick Ventureab1e9622019-06-03 10:45:06 -0700163 * read(session)
164 * commit(session)
165 */
166
167} // namespace
168} // namespace ipmi_flash