blob: 2f222910878dbcd3dc98974028570f853a93cd3a [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 */
65
66TEST_F(FirmwareHandlerVerificationPendingTest, VerifyBlobIdAvailableInState)
67{
68 /* Only in the verificationPending state (and later), should the
69 * verifyBlobId be present. */
70
71 /* TODO: Add this test in when the change is made. */
72 // EXPECT_FALSE(handler->canHandleBlob(verifyBlobId));
73 getToVerificationPending(staticLayoutBlobId);
74 EXPECT_TRUE(handler->canHandleBlob(verifyBlobId));
Patrick Ventureb386b862019-05-23 18:42:54 -070075 EXPECT_TRUE(handler->canHandleBlob(activeImageBlobId));
Patrick Venture61d2ed42019-05-23 18:16:31 -070076}
77
Patrick Ventureb386b862019-05-23 18:42:54 -070078/*
79 * delete(blob) TODO: Implement this.
80 */
81
82/*
83 * stat(blob)
84 */
85TEST_F(FirmwareHandlerVerificationPendingTest, StatOnActiveImageReturnsFailure)
86{
87 getToVerificationPending(staticLayoutBlobId);
88
89 blobs::BlobMeta meta;
90 EXPECT_FALSE(handler->stat(activeImageBlobId, &meta));
91}
92
93TEST_F(FirmwareHandlerVerificationPendingTest, StatOnActiveHashReturnsFailure)
94{
95 getToVerificationPending(hashBlobId);
96
97 blobs::BlobMeta meta;
98 EXPECT_FALSE(handler->stat(activeHashBlobId, &meta));
99}
100
101TEST_F(FirmwareHandlerVerificationPendingTest,
102 StatOnVerificationBlobReturnsFailure)
103{
104 getToVerificationPending(hashBlobId);
105
106 blobs::BlobMeta meta;
107 EXPECT_FALSE(handler->stat(verifyBlobId, &meta));
108}
109
110TEST_F(FirmwareHandlerVerificationPendingTest, StatOnNormalBlobsReturnsSuccess)
111{
112 getToVerificationPending(staticLayoutBlobId);
113
114 blobs::BlobMeta expected;
115 expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi;
116 expected.size = 0;
117
118 std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId};
119 for (const auto& blob : testBlobs)
120 {
121 blobs::BlobMeta meta = {};
122 EXPECT_TRUE(handler->stat(blob, &meta));
123 EXPECT_EQ(expected, meta);
124 }
125}
126
127/*
128 * stat(session)
129 */
130/*
131 * open(blob)
132 */
133/*
134 * close(session)
135 */
136/*
137 * writemeta(session)
138 */
139/*
140 * write(session)
141 */
142/*
143 * read(session)
144 */
145/*
146 * commit(session)
147 */
148
Patrick Venture61d2ed42019-05-23 18:16:31 -0700149} // namespace
150} // namespace ipmi_flash