blob: f06193e6a38e9042da2d8a7401e44698b6b35974 [file] [log] [blame]
Patrick Venturea82f99e2019-05-24 15:44:35 -07001/**
2 * The goal of these tests is to verify the behavior of all blob commands given
3 * the current state is verificationCompleted. This state is achieved as a out
4 * of verificationStarted.
5 */
6#include "firmware_handler.hpp"
7#include "firmware_unittest.hpp"
8#include "status.hpp"
9#include "util.hpp"
10
11#include <cstdint>
12#include <string>
13#include <vector>
14
15#include <gtest/gtest.h>
16
17namespace ipmi_flash
18{
19namespace
20{
21
22using ::testing::Return;
23
24/*
25 * There are the following calls (parameters may vary):
26 * canHandleBlob(blob)
27 * getBlobIds
28 * deleteBlob(blob)
29 * stat(blob)
30 * stat(session)
31 * open(blob)
32 * close(session)
33 * writemeta(session)
34 * write(session)
35 * read(session)
36 * commit(session)
37 *
38 * Like the state verificationStarted, there is a file open in
39 * verificationCompleted. This state is transitioned to after a stat() command
40 * indicates a successful verification.
41 */
42
43class FirmwareHandlerVerificationCompletedTest
44 : public IpmiOnlyFirmwareStaticTest
45{
46 protected:
Patrick Venture0c642fd2019-05-24 16:09:29 -070047 void getToVerificationCompleted(VerifyCheckResponses checkResponse)
Patrick Venturea82f99e2019-05-24 15:44:35 -070048 {
Patrick Venture0c642fd2019-05-24 16:09:29 -070049 /* The hash was not sent up, as it's technically optional. Therefore,
50 * there is no active hash file.
51 */
Patrick Venturea82f99e2019-05-24 15:44:35 -070052 auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
53 EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
54 EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
55 EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
56 realHandler->getCurrentState());
57 EXPECT_CALL(imageMock, close()).WillRepeatedly(Return());
58 handler->close(session);
59 EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationPending,
60 realHandler->getCurrentState());
61
62 EXPECT_TRUE(handler->open(session, flags, verifyBlobId));
63 EXPECT_CALL(*verifyMockPtr, triggerVerification())
64 .WillOnce(Return(true));
65
66 EXPECT_TRUE(handler->commit(session, {}));
67 EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationStarted,
68 realHandler->getCurrentState());
69
70 EXPECT_CALL(*verifyMockPtr, checkVerificationState())
Patrick Venture0c642fd2019-05-24 16:09:29 -070071 .WillOnce(Return(checkResponse));
Patrick Venturea82f99e2019-05-24 15:44:35 -070072 blobs::BlobMeta meta;
73 EXPECT_TRUE(handler->stat(session, &meta));
74 EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationCompleted,
75 realHandler->getCurrentState());
76 }
77
78 std::uint16_t session = 1;
79 std::uint16_t flags =
80 blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
81};
82
Patrick Venture0c642fd2019-05-24 16:09:29 -070083/* TODO:
Patrick Venturea82f99e2019-05-24 15:44:35 -070084 * canHandleBlob(blob)
85 * getBlobIds
86 * deleteBlob(blob)
87 *
88 */
89
90/*
91 * stat(blob)
92 */
Patrick Venture0c642fd2019-05-24 16:09:29 -070093TEST_F(FirmwareHandlerVerificationCompletedTest,
94 StatOnActiveImageReturnsFailure)
95{
96 getToVerificationCompleted(VerifyCheckResponses::success);
97 ASSERT_TRUE(handler->canHandleBlob(activeImageBlobId));
98
99 blobs::BlobMeta meta;
100 EXPECT_FALSE(handler->stat(activeImageBlobId, &meta));
101}
102
103TEST_F(FirmwareHandlerVerificationCompletedTest, StatOnVerifyBlobReturnsFailure)
104{
105 getToVerificationCompleted(VerifyCheckResponses::success);
106 ASSERT_TRUE(handler->canHandleBlob(verifyBlobId));
107
108 blobs::BlobMeta meta;
109 EXPECT_FALSE(handler->stat(verifyBlobId, &meta));
110}
111
112TEST_F(FirmwareHandlerVerificationCompletedTest,
113 StatOnNormalBlobsReturnsSuccess)
114{
115 getToVerificationCompleted(VerifyCheckResponses::success);
116
117 blobs::BlobMeta expected;
118 expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi;
119 expected.size = 0;
120
121 std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId};
122 for (const auto& blob : testBlobs)
123 {
124 ASSERT_TRUE(handler->canHandleBlob(blob));
125
126 blobs::BlobMeta meta = {};
127 EXPECT_TRUE(handler->stat(blob, &meta));
128 EXPECT_EQ(expected, meta);
129 }
130}
Patrick Venturea82f99e2019-05-24 15:44:35 -0700131
132/*
133 * stat(session) - the verify blobid is open in this state, so stat on that once
134 * completed should have no effect.
135 *
136 * open(blob) - all open should fail
137 *
138 * close(session) - close on the verify blobid:
139 * 1. if successful adds update blob id, changes state to UpdatePending
140 * 2. if unsuccessful doesn't add update blob id, changes state to?
141 */
142
143/*
144 * writemeta(session) - write meta should fail.
145 * write(session) - write should fail.
146 * read(session) - read returns empty.
147 * commit(session) - ?
148 */
149
150} // namespace
151} // namespace ipmi_flash