1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/**
* The goal of these tests is to verify opening the ubi tarball changes state
* as expected and does not regress.
*/
#include "firmware_handler.hpp"
#include "firmware_unittest.hpp"
#include <memory>
#include <string>
#include <vector>
#include <gtest/gtest.h>
namespace ipmi_flash
{
namespace
{
using ::testing::UnorderedElementsAreArray;
class FirmwareHandlerNotYetStartedUbitTest : public ::testing::Test
{
protected:
void SetUp() override
{
std::unique_ptr<ImageHandlerInterface> image =
std::make_unique<ImageHandlerMock>();
hashImageMock = reinterpret_cast<ImageHandlerMock*>(image.get());
blobs.push_back(std::move(HandlerPack(hashBlobId, std::move(image))));
image = std::make_unique<ImageHandlerMock>();
imageMock = reinterpret_cast<ImageHandlerMock*>(image.get());
blobs.push_back(
std::move(HandlerPack(ubiTarballBlobId, std::move(image))));
std::unique_ptr<TriggerableActionInterface> verifyMock =
std::make_unique<TriggerMock>();
verifyMockPtr = reinterpret_cast<TriggerMock*>(verifyMock.get());
std::unique_ptr<TriggerableActionInterface> updateMock =
std::make_unique<TriggerMock>();
updateMockPtr = reinterpret_cast<TriggerMock*>(updateMock.get());
std::unique_ptr<ActionPack> actionPack = std::make_unique<ActionPack>();
actionPack->preparation = CreateTriggerMock();
actionPack->verification = std::move(verifyMock);
actionPack->update = std::move(updateMock);
ActionMap packs;
packs[ubiTarballBlobId] = std::move(actionPack);
handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
std::move(blobs), data, std::move(packs));
}
void expectedState(FirmwareBlobHandler::UpdateState state)
{
auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
EXPECT_EQ(state, realHandler->getCurrentState());
}
void openToInProgress(const std::string& blobId)
{
if (blobId == hashBlobId)
{
EXPECT_CALL(*hashImageMock, open(blobId)).WillOnce(Return(true));
}
else
{
EXPECT_CALL(*imageMock, open(blobId)).WillOnce(Return(true));
}
EXPECT_TRUE(handler->open(session, flags, blobId));
expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
}
ImageHandlerMock *hashImageMock, *imageMock;
std::vector<HandlerPack> blobs;
std::vector<DataHandlerPack> data = {
{FirmwareFlags::UpdateFlags::ipmi, nullptr}};
std::unique_ptr<blobs::GenericBlobInterface> handler;
TriggerMock* verifyMockPtr;
TriggerMock* updateMockPtr;
std::uint16_t session = 1;
std::uint16_t flags =
blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi;
};
TEST_F(FirmwareHandlerNotYetStartedUbitTest,
OpeningTarballMovesToUploadInProgress)
{
expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
EXPECT_THAT(handler->getBlobIds(),
UnorderedElementsAreArray({hashBlobId, ubiTarballBlobId}));
openToInProgress(ubiTarballBlobId);
EXPECT_THAT(handler->getBlobIds(),
UnorderedElementsAreArray(
{hashBlobId, ubiTarballBlobId, activeImageBlobId}));
}
} // namespace
} // namespace ipmi_flash
|