blob: bdfffcb646c104262724cd2ad9286c43bc60fe40 [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 */
Patrick Venture930c7b72019-05-24 11:11:08 -070053 std::vector<std::string> expectedBlobs = {staticLayoutBlobId, hashBlobId};
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070054
55 EXPECT_THAT(handler->getBlobIds(),
56 UnorderedElementsAreArray(expectedBlobs));
Patrick Venture02c0ead2019-05-24 09:01:54 -070057
58 for (const auto& blob : expectedBlobs)
59 {
60 EXPECT_TRUE(handler->canHandleBlob(blob));
61 }
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070062}
63
Patrick Venture86c22082019-05-23 09:53:25 -070064/* TODO: Try deleting some blobs -- in this state it should just return failure,
65 * but it's not yet implemented
66 */
67
68/* stat(blob_id) */
69TEST_F(FirmwareHandlerNotYetStartedTest, StatEachBlobIdVerifyResults)
70{
71 /* In this original state, calling stat() on the blob ids will return the
72 * transported supported.
73 */
74 blobs::BlobMeta expected;
75 expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi;
76 expected.size = 0;
77
Patrick Venture930c7b72019-05-24 11:11:08 -070078 auto blobs = handler->getBlobIds();
79 for (const auto& blob : blobs)
Patrick Venture86c22082019-05-23 09:53:25 -070080 {
81 blobs::BlobMeta meta = {};
82 EXPECT_TRUE(handler->stat(blob, &meta));
83 EXPECT_EQ(expected, meta);
84 }
85}
86
Patrick Ventureb1a8f702019-05-23 10:10:57 -070087/* open(each blob id) (verifyblobid will no longer be available at this state.
88 */
89TEST_F(FirmwareHandlerNotYetStartedTest, OpenStaticImageFileVerifyStateChange)
90{
Patrick Ventureb1a8f702019-05-23 10:10:57 -070091 auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
92
93 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 Ventureb1a8f702019-05-23 10:10:57 -070096 EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
97 realHandler->getCurrentState());
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 auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
105
106 EXPECT_CALL(imageMock, open(hashBlobId)).WillOnce(Return(true));
107
Patrick Venture65055fb2019-05-23 17:36:01 -0700108 EXPECT_TRUE(handler->open(session, flags, hashBlobId));
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700109 EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
110 realHandler->getCurrentState());
Patrick Ventureefba42d2019-05-24 10:48:16 -0700111
112 EXPECT_TRUE(handler->canHandleBlob(activeHashBlobId));
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700113}
Patrick Venture86c22082019-05-23 09:53:25 -0700114
Patrick Venture8a4f2aa2019-05-23 08:40:21 -0700115} // namespace
116} // namespace ipmi_flash