blob: d514dd020025790f8d47ba378d17cadd27e013d8 [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 EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
53 EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
Patrick Venture6fdd02e2019-05-28 13:02:04 -070054 expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
55
Patrick Venturea82f99e2019-05-24 15:44:35 -070056 EXPECT_CALL(imageMock, close()).WillRepeatedly(Return());
57 handler->close(session);
Patrick Venture6fdd02e2019-05-28 13:02:04 -070058 expectedState(FirmwareBlobHandler::UpdateState::verificationPending);
Patrick Venturea82f99e2019-05-24 15:44:35 -070059
60 EXPECT_TRUE(handler->open(session, flags, verifyBlobId));
61 EXPECT_CALL(*verifyMockPtr, triggerVerification())
62 .WillOnce(Return(true));
63
64 EXPECT_TRUE(handler->commit(session, {}));
Patrick Venture6fdd02e2019-05-28 13:02:04 -070065 expectedState(FirmwareBlobHandler::UpdateState::verificationStarted);
Patrick Venturea82f99e2019-05-24 15:44:35 -070066
67 EXPECT_CALL(*verifyMockPtr, checkVerificationState())
Patrick Venture0c642fd2019-05-24 16:09:29 -070068 .WillOnce(Return(checkResponse));
Patrick Venturea82f99e2019-05-24 15:44:35 -070069 blobs::BlobMeta meta;
70 EXPECT_TRUE(handler->stat(session, &meta));
Patrick Venture6fdd02e2019-05-28 13:02:04 -070071 expectedState(FirmwareBlobHandler::UpdateState::verificationCompleted);
Patrick Venturea82f99e2019-05-24 15:44:35 -070072 }
73
74 std::uint16_t session = 1;
75 std::uint16_t flags =
76 blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
77};
78
Patrick Venture0c642fd2019-05-24 16:09:29 -070079/* TODO:
Patrick Venturea82f99e2019-05-24 15:44:35 -070080 * canHandleBlob(blob)
81 * getBlobIds
82 * deleteBlob(blob)
83 *
84 */
85
86/*
87 * stat(blob)
88 */
Patrick Venture0c642fd2019-05-24 16:09:29 -070089TEST_F(FirmwareHandlerVerificationCompletedTest,
90 StatOnActiveImageReturnsFailure)
91{
92 getToVerificationCompleted(VerifyCheckResponses::success);
93 ASSERT_TRUE(handler->canHandleBlob(activeImageBlobId));
94
95 blobs::BlobMeta meta;
96 EXPECT_FALSE(handler->stat(activeImageBlobId, &meta));
97}
98
99TEST_F(FirmwareHandlerVerificationCompletedTest, StatOnVerifyBlobReturnsFailure)
100{
101 getToVerificationCompleted(VerifyCheckResponses::success);
102 ASSERT_TRUE(handler->canHandleBlob(verifyBlobId));
103
104 blobs::BlobMeta meta;
105 EXPECT_FALSE(handler->stat(verifyBlobId, &meta));
106}
107
108TEST_F(FirmwareHandlerVerificationCompletedTest,
109 StatOnNormalBlobsReturnsSuccess)
110{
111 getToVerificationCompleted(VerifyCheckResponses::success);
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 ASSERT_TRUE(handler->canHandleBlob(blob));
121
122 blobs::BlobMeta meta = {};
123 EXPECT_TRUE(handler->stat(blob, &meta));
124 EXPECT_EQ(expected, meta);
125 }
126}
Patrick Venturea82f99e2019-05-24 15:44:35 -0700127
128/*
129 * stat(session) - the verify blobid is open in this state, so stat on that once
130 * completed should have no effect.
131 *
132 * open(blob) - all open should fail
133 *
134 * close(session) - close on the verify blobid:
135 * 1. if successful adds update blob id, changes state to UpdatePending
136 * 2. if unsuccessful doesn't add update blob id, changes state to?
137 */
138
139/*
140 * writemeta(session) - write meta should fail.
141 * write(session) - write should fail.
142 * read(session) - read returns empty.
143 * commit(session) - ?
144 */
145
146} // namespace
147} // namespace ipmi_flash