blob: e37623213d0d6843d12212b7aff2bdf6c49fa0f6 [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
64 * deleteBlob(blob)
65 * stat(blob)
66 * stat(session)
67 * open(blob)
68 * close(session)
69 * writemeta(session)
70 * write(session)
71 * read(session)
72 * commit(session)
73 */
74
75TEST_F(FirmwareHandlerVerificationPendingTest, VerifyBlobIdAvailableInState)
76{
77 /* Only in the verificationPending state (and later), should the
78 * verifyBlobId be present. */
79
80 /* TODO: Add this test in when the change is made. */
81 // EXPECT_FALSE(handler->canHandleBlob(verifyBlobId));
82 getToVerificationPending(staticLayoutBlobId);
83 EXPECT_TRUE(handler->canHandleBlob(verifyBlobId));
84}
85
86} // namespace
87} // namespace ipmi_flash