blob: bb6fecfbcda560240e78726bca67a2f87f00de4f [file] [log] [blame]
Patrick Venture8a4f2aa2019-05-23 08:40:21 -07001/**
2 * The goal of these tests is to verify the behavior of all blob commands given
3 * the current state is notYetStarted. The initial state.
4 */
5#include "firmware_handler.hpp"
6#include "firmware_unittest.hpp"
7
Patrick Venture65055fb2019-05-23 17:36:01 -07008#include <cstdint>
9#include <string>
10#include <vector>
11
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070012#include <gtest/gtest.h>
13
14namespace ipmi_flash
15{
16namespace
17{
18
Patrick Ventureb1a8f702019-05-23 10:10:57 -070019using ::testing::Return;
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070020using ::testing::UnorderedElementsAreArray;
21
22class FirmwareHandlerNotYetStartedTest : public IpmiOnlyFirmwareStaticTest
23{
24};
25
26/*
27 * There are the following calls (parameters may vary):
28 * Note: you cannot have a session yet, so only commands that don't take a
29 * session parameter are valid. Once you open() from this state, we will vary
30 * you transition out of this state (ensuring the above is true). Technically
31 * the firmware handler receives the session number with open(), but the blob
32 * manager is providing this normally.
33 *
34 * canHandleBlob
35 * getBlobIds
36 * deleteBlob
37 * stat
38 * open
39 *
40 * canHandleBlob is just a count check (or something similar) against what is
41 * returned by getBlobIds. It is tested in firmware_canhandle_unittest
42 */
43
Patrick Venture9b57a4c2019-05-28 12:54:09 -070044/* canHandleBlob, getBlobIds */
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070045TEST_F(FirmwareHandlerNotYetStartedTest, GetBlobListValidateListContents)
46{
Patrick Venture9b57a4c2019-05-28 12:54:09 -070047 /* By only checking that the hash and static blob ids are present to start
48 * with, we're also verifying others aren't.
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070049 */
Patrick Venture930c7b72019-05-24 11:11:08 -070050 std::vector<std::string> expectedBlobs = {staticLayoutBlobId, hashBlobId};
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070051
52 EXPECT_THAT(handler->getBlobIds(),
53 UnorderedElementsAreArray(expectedBlobs));
Patrick Venture02c0ead2019-05-24 09:01:54 -070054
Patrick Venture9b57a4c2019-05-28 12:54:09 -070055 /* Verify canHandleBlob is reading from the same list (basically) */
Patrick Venture02c0ead2019-05-24 09:01:54 -070056 for (const auto& blob : expectedBlobs)
57 {
58 EXPECT_TRUE(handler->canHandleBlob(blob));
59 }
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070060}
61
Patrick Venture86c22082019-05-23 09:53:25 -070062/* TODO: Try deleting some blobs -- in this state it should just return failure,
63 * but it's not yet implemented
64 */
65
66/* stat(blob_id) */
67TEST_F(FirmwareHandlerNotYetStartedTest, StatEachBlobIdVerifyResults)
68{
69 /* In this original state, calling stat() on the blob ids will return the
70 * transported supported.
71 */
72 blobs::BlobMeta expected;
73 expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi;
74 expected.size = 0;
75
Patrick Venture930c7b72019-05-24 11:11:08 -070076 auto blobs = handler->getBlobIds();
77 for (const auto& blob : blobs)
Patrick Venture86c22082019-05-23 09:53:25 -070078 {
79 blobs::BlobMeta meta = {};
80 EXPECT_TRUE(handler->stat(blob, &meta));
81 EXPECT_EQ(expected, meta);
82 }
83}
84
Patrick Ventureb1a8f702019-05-23 10:10:57 -070085/* open(each blob id) (verifyblobid will no longer be available at this state.
86 */
87TEST_F(FirmwareHandlerNotYetStartedTest, OpenStaticImageFileVerifyStateChange)
88{
Patrick Ventureb1a8f702019-05-23 10:10:57 -070089 EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
90
Patrick Venture65055fb2019-05-23 17:36:01 -070091 EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
Patrick Venture6fdd02e2019-05-28 13:02:04 -070092
93 expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
Patrick Ventureefba42d2019-05-24 10:48:16 -070094
95 EXPECT_TRUE(handler->canHandleBlob(activeImageBlobId));
Patrick Ventureb1a8f702019-05-23 10:10:57 -070096}
97
98TEST_F(FirmwareHandlerNotYetStartedTest, OpenHashFileVerifyStateChange)
99{
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700100 EXPECT_CALL(imageMock, open(hashBlobId)).WillOnce(Return(true));
101
Patrick Venture65055fb2019-05-23 17:36:01 -0700102 EXPECT_TRUE(handler->open(session, flags, hashBlobId));
Patrick Venture6fdd02e2019-05-28 13:02:04 -0700103
104 expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
Patrick Ventureefba42d2019-05-24 10:48:16 -0700105
106 EXPECT_TRUE(handler->canHandleBlob(activeHashBlobId));
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700107}
Patrick Venture86c22082019-05-23 09:53:25 -0700108
Patrick Venture8a4f2aa2019-05-23 08:40:21 -0700109} // namespace
110} // namespace ipmi_flash