blob: 3c2bc3e4e2642adbe991a0d9c86509a3c97913cb [file] [log] [blame]
Patrick Venture0cd945c2019-05-30 13:36:53 -07001/* The goal of these tests is to verify the behavior of all blob commands given
2 * the current state is updatePending. This state is achieved as an exit from
3 * verificationCompleted.
4 */
5#include "firmware_handler.hpp"
6#include "firmware_unittest.hpp"
7#include "status.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 FirmwareHandlerUpdatePendingTest : public IpmiOnlyFirmwareStaticTest
42{
43 protected:
44 void getToUpdatePending()
45 {
46 /* The hash was not sent up, as it's technically optional. Therefore,
47 * there is no active hash file.
48 */
49 EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
50 EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
51 expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
52
53 EXPECT_CALL(imageMock, close()).WillRepeatedly(Return());
54 handler->close(session);
55 expectedState(FirmwareBlobHandler::UpdateState::verificationPending);
56
57 EXPECT_TRUE(handler->open(session, flags, verifyBlobId));
58 EXPECT_CALL(*verifyMockPtr, triggerVerification())
59 .WillOnce(Return(true));
60
61 EXPECT_TRUE(handler->commit(session, {}));
62 expectedState(FirmwareBlobHandler::UpdateState::verificationStarted);
63
64 EXPECT_CALL(*verifyMockPtr, checkVerificationState())
65 .WillOnce(Return(VerifyCheckResponses::success));
66 blobs::BlobMeta meta;
67 EXPECT_TRUE(handler->stat(session, &meta));
68 expectedState(FirmwareBlobHandler::UpdateState::verificationCompleted);
69
70 handler->close(session);
71 expectedState(FirmwareBlobHandler::UpdateState::updatePending);
72 }
73
74 std::uint16_t session = 1;
75 std::uint16_t flags =
76 blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
77};
78
79/*
80 * There are the following calls (parameters may vary):
81 * canHandleBlob(blob)
82 * getBlobIds
83 */
84/*
85 * deleteBlob(blob)
86 */
87
88/*
89 * stat(blob)
90 */
91
92/*
93 * stat(session)
94 */
95
96/*
97 * open(blob)
98 */
99
100/*
101 * close(session)
102 */
103
104/*
105 * writemeta(session)
106 */
107
108/*
109 * write(session)
110 */
111
112/*
113 * read(session)
114 */
115
116/*
117 * commit(session)
118 */
119
120} // namespace
121} // namespace ipmi_flash