blob: 592665b5e2b1baa310a346fe296da0f02c43f514 [file] [log] [blame]
Patrick Venture16ab2a12019-05-31 08:52:51 -07001/* The goal of these tests is to verify the behavior of all blob commands given
2 * the current state is updateStarted. This state is achieved as an exit from
3 * updatePending.
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;
Patrick Ventured9a95782019-05-31 10:46:56 -070022using ::testing::UnorderedElementsAreArray;
Patrick Venture16ab2a12019-05-31 08:52:51 -070023
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
39class FirmwareHandlerUpdateStartedTest : public IpmiOnlyFirmwareStaticTest
40{
41};
42
Patrick Venturef515b9c2019-05-31 10:38:16 -070043/*
44 * open(blob)
45 */
46TEST_F(FirmwareHandlerUpdateStartedTest, AttemptToOpenFilesReturnsFailure)
47{
48 /* In state updateStarted a file is open, which means no others can be. */
49 getToUpdateStarted();
50
51 auto blobsToOpen = handler->getBlobIds();
52 for (const auto& blob : blobsToOpen)
53 {
54 EXPECT_FALSE(handler->open(session + 1, flags, blob));
55 }
56}
57
Patrick Venture16ab2a12019-05-31 08:52:51 -070058/* canHandleBlob(blob)
59 * getBlobIds
60 */
Patrick Ventured9a95782019-05-31 10:46:56 -070061TEST_F(FirmwareHandlerUpdateStartedTest, VerifyListOfBlobs)
62{
63 getToUpdateStarted();
64
65 std::vector<std::string> expected = {updateBlobId, hashBlobId,
66 activeImageBlobId, staticLayoutBlobId};
67 EXPECT_THAT(handler->getBlobIds(), UnorderedElementsAreArray(expected));
68}
Patrick Venture16ab2a12019-05-31 08:52:51 -070069
70/*
71 * TODO: deleteBlob(blob)
72 */
73
74/*
75 * stat(blob)
76 */
Patrick Venturefc34cfa2019-05-31 11:02:51 -070077TEST_F(FirmwareHandlerUpdateStartedTest, StatOnActiveImageReturnsFailure)
78{
79 getToUpdateStarted();
80
81 ASSERT_TRUE(handler->canHandleBlob(activeImageBlobId));
82
83 blobs::BlobMeta meta;
84 EXPECT_FALSE(handler->stat(activeImageBlobId, &meta));
85}
86
87TEST_F(FirmwareHandlerUpdateStartedTest, StatOnUpdateBlobReturnsFailure)
88{
89 getToUpdateStarted();
90
91 ASSERT_TRUE(handler->canHandleBlob(updateBlobId));
92
93 blobs::BlobMeta meta;
94 EXPECT_FALSE(handler->stat(updateBlobId, &meta));
95}
96
97TEST_F(FirmwareHandlerUpdateStartedTest, StatOnNormalBlobsReturnsSuccess)
98{
99 getToUpdateStarted();
100
101 blobs::BlobMeta expected;
102 expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi;
103 expected.size = 0;
104
105 std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId};
106 for (const auto& blob : testBlobs)
107 {
108 ASSERT_TRUE(handler->canHandleBlob(blob));
109
110 blobs::BlobMeta meta = {};
111 EXPECT_TRUE(handler->stat(blob, &meta));
112 EXPECT_EQ(expected, meta);
113 }
114}
Patrick Venture16ab2a12019-05-31 08:52:51 -0700115
116/*
117 * stat(session)
118 */
Patrick Venture16ab2a12019-05-31 08:52:51 -0700119
120/*
121 * close(session)
122 */
123
124/*
125 * writemeta(session)
126 */
127
128/*
129 * write(session)
130 */
131
132/*
133 * read(session)
134 */
135
136/*
137 * commit(session)
138 */
139
140} // namespace
141} // namespace ipmi_flash