blob: 85a664adc4b5d43da1f77d242250d843b4a865bf [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));
58}
59
Patrick Venture86c22082019-05-23 09:53:25 -070060/* TODO: Try deleting some blobs -- in this state it should just return failure,
61 * but it's not yet implemented
62 */
63
64/* stat(blob_id) */
65TEST_F(FirmwareHandlerNotYetStartedTest, StatEachBlobIdVerifyResults)
66{
67 /* In this original state, calling stat() on the blob ids will return the
68 * transported supported.
69 */
70 blobs::BlobMeta expected;
71 expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi;
72 expected.size = 0;
73
74 /* TODO: note, once verifyblobid isn't present in this state we can use
75 * getblobids()'s output as input
76 */
77 std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId};
78 for (const auto& blob : testBlobs)
79 {
80 blobs::BlobMeta meta = {};
81 EXPECT_TRUE(handler->stat(blob, &meta));
82 EXPECT_EQ(expected, meta);
83 }
84}
85
Patrick Ventureb1a8f702019-05-23 10:10:57 -070086/* open(each blob id) (verifyblobid will no longer be available at this state.
87 */
88TEST_F(FirmwareHandlerNotYetStartedTest, OpenStaticImageFileVerifyStateChange)
89{
Patrick Ventureb1a8f702019-05-23 10:10:57 -070090 auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
91
92 EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
93
Patrick Venture65055fb2019-05-23 17:36:01 -070094 EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
Patrick Ventureb1a8f702019-05-23 10:10:57 -070095 EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
96 realHandler->getCurrentState());
97}
98
99TEST_F(FirmwareHandlerNotYetStartedTest, OpenHashFileVerifyStateChange)
100{
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700101 auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
102
103 EXPECT_CALL(imageMock, open(hashBlobId)).WillOnce(Return(true));
104
Patrick Venture65055fb2019-05-23 17:36:01 -0700105 EXPECT_TRUE(handler->open(session, flags, hashBlobId));
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700106 EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
107 realHandler->getCurrentState());
108}
Patrick Venture86c22082019-05-23 09:53:25 -0700109
Patrick Venture8a4f2aa2019-05-23 08:40:21 -0700110} // namespace
111} // namespace ipmi_flash