blob: 9f87573db73c96338c9170d5500d4c9dc3672d53 [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:
47 void getToVerificationCompleted()
48 {
49 auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
50 EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
51 EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
52 EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
53 realHandler->getCurrentState());
54 EXPECT_CALL(imageMock, close()).WillRepeatedly(Return());
55 handler->close(session);
56 EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationPending,
57 realHandler->getCurrentState());
58
59 EXPECT_TRUE(handler->open(session, flags, verifyBlobId));
60 EXPECT_CALL(*verifyMockPtr, triggerVerification())
61 .WillOnce(Return(true));
62
63 EXPECT_TRUE(handler->commit(session, {}));
64 EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationStarted,
65 realHandler->getCurrentState());
66
67 EXPECT_CALL(*verifyMockPtr, checkVerificationState())
68 .WillOnce(Return(VerifyCheckResponses::success));
69 blobs::BlobMeta meta;
70 EXPECT_TRUE(handler->stat(session, &meta));
71 EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationCompleted,
72 realHandler->getCurrentState());
73 }
74
75 std::uint16_t session = 1;
76 std::uint16_t flags =
77 blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
78};
79
80/*
81 * canHandleBlob(blob)
82 * getBlobIds
83 * deleteBlob(blob)
84 *
85 */
86
87/*
88 * stat(blob)
89 */
90
91/*
92 * stat(session) - the verify blobid is open in this state, so stat on that once
93 * completed should have no effect.
94 *
95 * open(blob) - all open should fail
96 *
97 * close(session) - close on the verify blobid:
98 * 1. if successful adds update blob id, changes state to UpdatePending
99 * 2. if unsuccessful doesn't add update blob id, changes state to?
100 */
101
102/*
103 * writemeta(session) - write meta should fail.
104 * write(session) - write should fail.
105 * read(session) - read returns empty.
106 * commit(session) - ?
107 */
108
109} // namespace
110} // namespace ipmi_flash