blob: 0cc724d1b54674110b24c74d570d77b5ff449d3d [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
48TEST_F(FirmwareHandlerNotYetStartedTest, GetBlobListValidateListContents)
49{
Patrick Venture86c22082019-05-23 09:53:25 -070050 /* TODO: Presently, /flash/verify is present from the beginning, however,
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070051 * this is going to change to simplify handling of open().
52 */
53 std::vector<std::string> expectedBlobs = {staticLayoutBlobId, hashBlobId,
54 verifyBlobId};
55
56 EXPECT_THAT(handler->getBlobIds(),
57 UnorderedElementsAreArray(expectedBlobs));
Patrick Venture02c0ead2019-05-24 09:01:54 -070058
59 for (const auto& blob : expectedBlobs)
60 {
61 EXPECT_TRUE(handler->canHandleBlob(blob));
62 }
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070063}
64
Patrick Venture86c22082019-05-23 09:53:25 -070065/* TODO: Try deleting some blobs -- in this state it should just return failure,
66 * but it's not yet implemented
67 */
68
69/* stat(blob_id) */
70TEST_F(FirmwareHandlerNotYetStartedTest, StatEachBlobIdVerifyResults)
71{
72 /* In this original state, calling stat() on the blob ids will return the
73 * transported supported.
74 */
75 blobs::BlobMeta expected;
76 expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi;
77 expected.size = 0;
78
79 /* TODO: note, once verifyblobid isn't present in this state we can use
80 * getblobids()'s output as input
81 */
82 std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId};
83 for (const auto& blob : testBlobs)
84 {
85 blobs::BlobMeta meta = {};
86 EXPECT_TRUE(handler->stat(blob, &meta));
87 EXPECT_EQ(expected, meta);
88 }
89}
90
Patrick Ventureb1a8f702019-05-23 10:10:57 -070091/* open(each blob id) (verifyblobid will no longer be available at this state.
92 */
93TEST_F(FirmwareHandlerNotYetStartedTest, OpenStaticImageFileVerifyStateChange)
94{
Patrick Ventureb1a8f702019-05-23 10:10:57 -070095 auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
96
97 EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
98
Patrick Venture65055fb2019-05-23 17:36:01 -070099 EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700100 EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
101 realHandler->getCurrentState());
102}
103
104TEST_F(FirmwareHandlerNotYetStartedTest, OpenHashFileVerifyStateChange)
105{
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700106 auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
107
108 EXPECT_CALL(imageMock, open(hashBlobId)).WillOnce(Return(true));
109
Patrick Venture65055fb2019-05-23 17:36:01 -0700110 EXPECT_TRUE(handler->open(session, flags, hashBlobId));
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700111 EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
112 realHandler->getCurrentState());
113}
Patrick Venture86c22082019-05-23 09:53:25 -0700114
Patrick Venture8a4f2aa2019-05-23 08:40:21 -0700115} // namespace
116} // namespace ipmi_flash