blob: 819f26a88cb9f39d1792795af1b9c8f0a4b0968d [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
8#include <gtest/gtest.h>
9
10namespace ipmi_flash
11{
12namespace
13{
14
Patrick Ventureb1a8f702019-05-23 10:10:57 -070015using ::testing::Return;
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070016using ::testing::UnorderedElementsAreArray;
17
18class FirmwareHandlerNotYetStartedTest : public IpmiOnlyFirmwareStaticTest
19{
20};
21
22/*
23 * There are the following calls (parameters may vary):
24 * Note: you cannot have a session yet, so only commands that don't take a
25 * session parameter are valid. Once you open() from this state, we will vary
26 * you transition out of this state (ensuring the above is true). Technically
27 * the firmware handler receives the session number with open(), but the blob
28 * manager is providing this normally.
29 *
30 * canHandleBlob
31 * getBlobIds
32 * deleteBlob
33 * stat
34 * open
35 *
36 * canHandleBlob is just a count check (or something similar) against what is
37 * returned by getBlobIds. It is tested in firmware_canhandle_unittest
38 */
39
40TEST_F(FirmwareHandlerNotYetStartedTest, GetBlobListValidateListContents)
41{
Patrick Venture86c22082019-05-23 09:53:25 -070042 /* TODO: Presently, /flash/verify is present from the beginning, however,
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070043 * this is going to change to simplify handling of open().
44 */
45 std::vector<std::string> expectedBlobs = {staticLayoutBlobId, hashBlobId,
46 verifyBlobId};
47
48 EXPECT_THAT(handler->getBlobIds(),
49 UnorderedElementsAreArray(expectedBlobs));
50}
51
Patrick Venture86c22082019-05-23 09:53:25 -070052/* TODO: Try deleting some blobs -- in this state it should just return failure,
53 * but it's not yet implemented
54 */
55
56/* stat(blob_id) */
57TEST_F(FirmwareHandlerNotYetStartedTest, StatEachBlobIdVerifyResults)
58{
59 /* In this original state, calling stat() on the blob ids will return the
60 * transported supported.
61 */
62 blobs::BlobMeta expected;
63 expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi;
64 expected.size = 0;
65
66 /* TODO: note, once verifyblobid isn't present in this state we can use
67 * getblobids()'s output as input
68 */
69 std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId};
70 for (const auto& blob : testBlobs)
71 {
72 blobs::BlobMeta meta = {};
73 EXPECT_TRUE(handler->stat(blob, &meta));
74 EXPECT_EQ(expected, meta);
75 }
76}
77
Patrick Ventureb1a8f702019-05-23 10:10:57 -070078/* open(each blob id) (verifyblobid will no longer be available at this state.
79 */
80TEST_F(FirmwareHandlerNotYetStartedTest, OpenStaticImageFileVerifyStateChange)
81{
82 std::uint16_t flags =
83 blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
84 auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
85
86 EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
87
88 EXPECT_TRUE(handler->open(1, flags, staticLayoutBlobId));
89 EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
90 realHandler->getCurrentState());
91}
92
93TEST_F(FirmwareHandlerNotYetStartedTest, OpenHashFileVerifyStateChange)
94{
95 std::uint16_t flags =
96 blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
97 auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
98
99 EXPECT_CALL(imageMock, open(hashBlobId)).WillOnce(Return(true));
100
101 EXPECT_TRUE(handler->open(1, flags, hashBlobId));
102 EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
103 realHandler->getCurrentState());
104}
Patrick Venture86c22082019-05-23 09:53:25 -0700105
Patrick Venture8a4f2aa2019-05-23 08:40:21 -0700106} // namespace
107} // namespace ipmi_flash