summaryrefslogtreecommitdiffstats
path: root/bmc/test/firmware_state_notyetstarted_unittest.cpp
blob: 2a100bd86ac63197843ccd2523af9d77f6edf9dc (plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
 * The goal of these tests is to verify the behavior of all blob commands given
 * the current state is notYetStarted.  The initial state.
 */
#include "firmware_handler.hpp"
#include "firmware_unittest.hpp"

#include <cstdint>
#include <string>
#include <vector>

#include <gtest/gtest.h>

namespace ipmi_flash
{
namespace
{

using ::testing::Return;
using ::testing::UnorderedElementsAreArray;

class FirmwareHandlerNotYetStartedTest : public IpmiOnlyFirmwareStaticTest
{
};

/*
 * There are the following calls (parameters may vary):
 * Note: you cannot have a session yet, so only commands that don't take a
 * session parameter are valid. Once you open() from this state, we will vary
 * you transition out of this state (ensuring the above is true). Technically
 * the firmware handler receives the session number with open(), but the blob
 * manager is providing this normally.
 *
 * canHandleBlob
 * getBlobIds
 * deleteBlob
 * stat
 * open
 *
 * canHandleBlob is just a count check (or something similar) against what is
 * returned by getBlobIds.  It is tested in firmware_canhandle_unittest
 */

/*
 * deleteBlob()
 */
TEST_F(FirmwareHandlerNotYetStartedTest, DeleteBlobInStateReturnsFalse)
{
    auto blobs = handler->getBlobIds();
    for (const auto& b : blobs)
    {
        EXPECT_FALSE(handler->deleteBlob(b));
    }
}

/* canHandleBlob, getBlobIds */
TEST_F(FirmwareHandlerNotYetStartedTest, GetBlobListValidateListContents)
{
    /* By only checking that the hash and static blob ids are present to start
     * with, we're also verifying others aren't.
     */
    EXPECT_THAT(handler->getBlobIds(),
                UnorderedElementsAreArray(startingBlobs));

    /* Verify canHandleBlob is reading from the same list (basically) */
    for (const auto& blob : startingBlobs)
    {
        EXPECT_TRUE(handler->canHandleBlob(blob));
    }
}

/* stat(blob_id) */
TEST_F(FirmwareHandlerNotYetStartedTest, StatEachBlobIdVerifyResults)
{
    /* In this original state, calling stat() on the blob ids will return the
     * idle status
     */

    auto blobs = handler->getBlobIds();
    for (const auto& blob : blobs)
    {
        blobs::BlobMeta meta = {};
        EXPECT_TRUE(handler->stat(blob, &meta));
        EXPECT_EQ(expectedIdleMeta, meta);
    }
}

/* open(each blob id) (verifyblobid will no longer be available at this state.
 */
TEST_F(FirmwareHandlerNotYetStartedTest, OpenStaticImageFileVerifyStateChange)
{
    EXPECT_CALL(*imageMock2, open(staticLayoutBlobId)).WillOnce(Return(true));
    EXPECT_CALL(*prepareMockPtr, trigger()).WillOnce(Return(true));

    EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));

    expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);

    EXPECT_TRUE(handler->canHandleBlob(activeImageBlobId));
}

TEST_F(FirmwareHandlerNotYetStartedTest, OpenHashFileVerifyStateChange)
{
    EXPECT_CALL(*hashImageMock, open(hashBlobId)).WillOnce(Return(true));
    /* Opening the hash blob id doesn't trigger a preparation, only a firmware
     * blob.
     */
    EXPECT_CALL(*prepareMockPtr, trigger()).Times(0);

    EXPECT_TRUE(handler->open(session, flags, hashBlobId));

    expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);

    EXPECT_TRUE(handler->canHandleBlob(activeHashBlobId));
}

} // namespace
} // namespace ipmi_flash
OpenPOWER on IntegriCloud