blob: f6628200781e91f6a60dd2a388fff836ad297ebe [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{
Patrick Venture65055fb2019-05-23 17:36:01 -070024 protected:
25 std::uint16_t session = 1;
26 std::uint16_t flags =
27 blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070028};
29
30/*
31 * There are the following calls (parameters may vary):
32 * Note: you cannot have a session yet, so only commands that don't take a
33 * session parameter are valid. Once you open() from this state, we will vary
34 * you transition out of this state (ensuring the above is true). Technically
35 * the firmware handler receives the session number with open(), but the blob
36 * manager is providing this normally.
37 *
38 * canHandleBlob
39 * getBlobIds
40 * deleteBlob
41 * stat
42 * open
43 *
44 * canHandleBlob is just a count check (or something similar) against what is
45 * returned by getBlobIds. It is tested in firmware_canhandle_unittest
46 */
47
Patrick Venture9b57a4c2019-05-28 12:54:09 -070048/* canHandleBlob, getBlobIds */
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070049TEST_F(FirmwareHandlerNotYetStartedTest, GetBlobListValidateListContents)
50{
Patrick Venture9b57a4c2019-05-28 12:54:09 -070051 /* By only checking that the hash and static blob ids are present to start
52 * with, we're also verifying others aren't.
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070053 */
Patrick Venture930c7b72019-05-24 11:11:08 -070054 std::vector<std::string> expectedBlobs = {staticLayoutBlobId, hashBlobId};
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070055
56 EXPECT_THAT(handler->getBlobIds(),
57 UnorderedElementsAreArray(expectedBlobs));
Patrick Venture02c0ead2019-05-24 09:01:54 -070058
Patrick Venture9b57a4c2019-05-28 12:54:09 -070059 /* Verify canHandleBlob is reading from the same list (basically) */
Patrick Venture02c0ead2019-05-24 09:01:54 -070060 for (const auto& blob : expectedBlobs)
61 {
62 EXPECT_TRUE(handler->canHandleBlob(blob));
63 }
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070064}
65
Patrick Venture86c22082019-05-23 09:53:25 -070066/* TODO: Try deleting some blobs -- in this state it should just return failure,
67 * but it's not yet implemented
68 */
69
70/* stat(blob_id) */
71TEST_F(FirmwareHandlerNotYetStartedTest, StatEachBlobIdVerifyResults)
72{
73 /* In this original state, calling stat() on the blob ids will return the
74 * transported supported.
75 */
76 blobs::BlobMeta expected;
77 expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi;
78 expected.size = 0;
79
Patrick Venture930c7b72019-05-24 11:11:08 -070080 auto blobs = handler->getBlobIds();
81 for (const auto& blob : blobs)
Patrick Venture86c22082019-05-23 09:53:25 -070082 {
83 blobs::BlobMeta meta = {};
84 EXPECT_TRUE(handler->stat(blob, &meta));
85 EXPECT_EQ(expected, meta);
86 }
87}
88
Patrick Ventureb1a8f702019-05-23 10:10:57 -070089/* open(each blob id) (verifyblobid will no longer be available at this state.
90 */
91TEST_F(FirmwareHandlerNotYetStartedTest, OpenStaticImageFileVerifyStateChange)
92{
Patrick Ventureb1a8f702019-05-23 10:10:57 -070093 EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
94
Patrick Venture65055fb2019-05-23 17:36:01 -070095 EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
Patrick Venture6fdd02e2019-05-28 13:02:04 -070096
97 expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
Patrick Ventureefba42d2019-05-24 10:48:16 -070098
99 EXPECT_TRUE(handler->canHandleBlob(activeImageBlobId));
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700100}
101
102TEST_F(FirmwareHandlerNotYetStartedTest, OpenHashFileVerifyStateChange)
103{
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700104 EXPECT_CALL(imageMock, open(hashBlobId)).WillOnce(Return(true));
105
Patrick Venture65055fb2019-05-23 17:36:01 -0700106 EXPECT_TRUE(handler->open(session, flags, hashBlobId));
Patrick Venture6fdd02e2019-05-28 13:02:04 -0700107
108 expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
Patrick Ventureefba42d2019-05-24 10:48:16 -0700109
110 EXPECT_TRUE(handler->canHandleBlob(activeHashBlobId));
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700111}
Patrick Venture86c22082019-05-23 09:53:25 -0700112
Patrick Venture8a4f2aa2019-05-23 08:40:21 -0700113} // namespace
114} // namespace ipmi_flash