blob: c5c0fee524935a2e343332681357afef585ec6c0 [file] [log] [blame]
Patrick Ventureebcc5222019-05-23 10:36:40 -07001/**
2 * The goal of these tests is to verify the behavior of all blob commands given
3 * the current state is uploadInProgress. This state is achieved when an image
4 * or hash blob is opened and the handler is expected to receive bytes.
5 */
6#include "firmware_handler.hpp"
7#include "firmware_unittest.hpp"
8
9#include <gtest/gtest.h>
10
11namespace ipmi_flash
12{
13namespace
14{
15
16using ::testing::Return;
17using ::testing::UnorderedElementsAreArray;
18
19/*
20 * There are the following calls (parameters may vary):
21 * canHandleBlob(blob)
22 * getBlobIds
23 * deleteBlob(blob)
24 * stat(blob)
25 * stat(session)
26 * open(blob)
27 * close(session)
28 * writemeta(session)
29 * write(session)
30 * read(session)
31 *
32 * Testing canHandleBlob is uninteresting in this state. Getting the BlobIDs
33 * will inform what canHandleBlob will return.
34 */
35class FirmwareHandlerUploadInProgressTest : public IpmiOnlyFirmwareStaticTest
36{
37};
38
39TEST_F(FirmwareHandlerUploadInProgressTest, GetBlobIdsVerifyOutputActiveImage)
40{
41 /* Opening the image file will add the active image blob id */
42 std::uint16_t flags =
43 blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
44 auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
45
46 EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
47
48 EXPECT_TRUE(handler->open(1, flags, staticLayoutBlobId));
49 EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
50 realHandler->getCurrentState());
51
52 std::vector<std::string> expectedAfterImage = {
53 staticLayoutBlobId, hashBlobId, verifyBlobId, activeImageBlobId};
54 EXPECT_THAT(handler->getBlobIds(),
55 UnorderedElementsAreArray(expectedAfterImage));
56}
57
58TEST_F(FirmwareHandlerUploadInProgressTest, GetBlobIdsVerifyOutputActiveHash)
59{
60 /* Opening the image file will add the active image blob id */
61 std::uint16_t flags =
62 blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
63 auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
64
65 EXPECT_CALL(imageMock, open(hashBlobId)).WillOnce(Return(true));
66
67 EXPECT_TRUE(handler->open(1, flags, hashBlobId));
68 EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
69 realHandler->getCurrentState());
70
71 std::vector<std::string> expectedAfterImage = {
72 staticLayoutBlobId, hashBlobId, verifyBlobId, activeHashBlobId};
73 EXPECT_THAT(handler->getBlobIds(),
74 UnorderedElementsAreArray(expectedAfterImage));
75}
76
77} // namespace
78} // namespace ipmi_flash