blob: 594bd2bbfa5d9901bcb943b4fc3813134d833503 [file] [log] [blame]
Patrick Venture61d2ed42019-05-23 18:16:31 -07001/**
2 * The goal of these tests is to verify the behavior of all blob commands given
3 * the current state is verificationPending. This state is achieved as a
4 * transition out of uploadInProgress.
5 */
6#include "firmware_handler.hpp"
7#include "firmware_unittest.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
21using ::testing::Return;
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 * Testing canHandleBlob is uninteresting in this state. Getting the BlobIDs
38 * will inform what canHandleBlob will return.
39 */
40
41class FirmwareHandlerVerificationPendingTest : public IpmiOnlyFirmwareStaticTest
42{
43 protected:
44 void getToVerificationPending(const std::string& blobId)
45 {
46 auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
47 EXPECT_CALL(imageMock, open(blobId)).WillOnce(Return(true));
48 EXPECT_TRUE(handler->open(session, flags, blobId));
49 EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
50 realHandler->getCurrentState());
51 EXPECT_CALL(imageMock, close()).WillRepeatedly(Return());
52 handler->close(session);
53 EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationPending,
54 realHandler->getCurrentState());
55 }
56
57 std::uint16_t session = 1;
58 std::uint16_t flags =
59 blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
60};
61
62/*
63 * getBlobIds
Patrick Venture61d2ed42019-05-23 18:16:31 -070064 */
Patrick Venture61d2ed42019-05-23 18:16:31 -070065TEST_F(FirmwareHandlerVerificationPendingTest, VerifyBlobIdAvailableInState)
66{
67 /* Only in the verificationPending state (and later), should the
68 * verifyBlobId be present. */
69
70 /* TODO: Add this test in when the change is made. */
71 // EXPECT_FALSE(handler->canHandleBlob(verifyBlobId));
72 getToVerificationPending(staticLayoutBlobId);
73 EXPECT_TRUE(handler->canHandleBlob(verifyBlobId));
Patrick Ventureb386b862019-05-23 18:42:54 -070074 EXPECT_TRUE(handler->canHandleBlob(activeImageBlobId));
Patrick Venture61d2ed42019-05-23 18:16:31 -070075}
76
Patrick Ventureb386b862019-05-23 18:42:54 -070077/*
78 * delete(blob) TODO: Implement this.
79 */
80
81/*
82 * stat(blob)
83 */
84TEST_F(FirmwareHandlerVerificationPendingTest, StatOnActiveImageReturnsFailure)
85{
86 getToVerificationPending(staticLayoutBlobId);
87
88 blobs::BlobMeta meta;
89 EXPECT_FALSE(handler->stat(activeImageBlobId, &meta));
90}
91
92TEST_F(FirmwareHandlerVerificationPendingTest, StatOnActiveHashReturnsFailure)
93{
94 getToVerificationPending(hashBlobId);
95
96 blobs::BlobMeta meta;
97 EXPECT_FALSE(handler->stat(activeHashBlobId, &meta));
98}
99
100TEST_F(FirmwareHandlerVerificationPendingTest,
101 StatOnVerificationBlobReturnsFailure)
102{
103 getToVerificationPending(hashBlobId);
104
105 blobs::BlobMeta meta;
106 EXPECT_FALSE(handler->stat(verifyBlobId, &meta));
107}
108
109TEST_F(FirmwareHandlerVerificationPendingTest, StatOnNormalBlobsReturnsSuccess)
110{
111 getToVerificationPending(staticLayoutBlobId);
112
113 blobs::BlobMeta expected;
114 expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi;
115 expected.size = 0;
116
117 std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId};
118 for (const auto& blob : testBlobs)
119 {
120 blobs::BlobMeta meta = {};
121 EXPECT_TRUE(handler->stat(blob, &meta));
122 EXPECT_EQ(expected, meta);
123 }
124}
125
126/*
Patrick Ventureb386b862019-05-23 18:42:54 -0700127 * open(blob)
128 */
Patrick Ventureda8fcd12019-05-23 18:53:50 -0700129TEST_F(FirmwareHandlerVerificationPendingTest, OpenVerifyBlobSucceeds)
130{
131 getToVerificationPending(staticLayoutBlobId);
132
133 /* the session is safe because it was already closed to get to this state.
134 */
135 EXPECT_TRUE(handler->open(session, flags, verifyBlobId));
136}
137
138TEST_F(FirmwareHandlerVerificationPendingTest, OpenActiveImageBlobFails)
139{
140 /* Try opening the active blob Id. This test is equivalent to trying to
141 * open the active hash blob id, in that neither are ever allowed.
142 */
143 getToVerificationPending(staticLayoutBlobId);
144 EXPECT_FALSE(handler->open(session, flags, activeImageBlobId));
145}
146
147TEST_F(FirmwareHandlerVerificationPendingTest,
148 OpenImageBlobTransitionsToUploadInProgress)
149{
150 getToVerificationPending(staticLayoutBlobId);
151 EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
152 EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
153
154 auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
155 EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
156 realHandler->getCurrentState());
157}
158
159/*
160 * stat(session) - in this state, you can only open(verifyBlobId) without
161 * changing state.
162 */
163
Patrick Ventureb386b862019-05-23 18:42:54 -0700164/*
165 * close(session)
166 */
167/*
168 * writemeta(session)
169 */
170/*
171 * write(session)
172 */
173/*
174 * read(session)
175 */
176/*
177 * commit(session)
178 */
179
Patrick Venture61d2ed42019-05-23 18:16:31 -0700180} // namespace
181} // namespace ipmi_flash