blob: b3cfc49bfe1042b6fbced755672b869266ecf2c9 [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
Patrick Venture9b37b092020-05-28 20:58:57 -070023{};
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070024
25/*
26 * There are the following calls (parameters may vary):
27 * Note: you cannot have a session yet, so only commands that don't take a
28 * session parameter are valid. Once you open() from this state, we will vary
29 * you transition out of this state (ensuring the above is true). Technically
30 * the firmware handler receives the session number with open(), but the blob
31 * manager is providing this normally.
32 *
33 * canHandleBlob
34 * getBlobIds
35 * deleteBlob
36 * stat
37 * open
38 *
39 * canHandleBlob is just a count check (or something similar) against what is
40 * returned by getBlobIds. It is tested in firmware_canhandle_unittest
41 */
42
Patrick Venture72676762019-06-17 11:22:38 -070043/*
44 * deleteBlob()
45 */
46TEST_F(FirmwareHandlerNotYetStartedTest, DeleteBlobInStateReturnsFalse)
47{
48 auto blobs = handler->getBlobIds();
49 for (const auto& b : blobs)
50 {
51 EXPECT_FALSE(handler->deleteBlob(b));
52 }
53}
54
Patrick Venture9b57a4c2019-05-28 12:54:09 -070055/* canHandleBlob, getBlobIds */
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070056TEST_F(FirmwareHandlerNotYetStartedTest, GetBlobListValidateListContents)
57{
Patrick Venture9b57a4c2019-05-28 12:54:09 -070058 /* By only checking that the hash and static blob ids are present to start
59 * with, we're also verifying others aren't.
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070060 */
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070061 EXPECT_THAT(handler->getBlobIds(),
Patrick Venture9a69f732019-06-17 14:05:13 -070062 UnorderedElementsAreArray(startingBlobs));
Patrick Venture02c0ead2019-05-24 09:01:54 -070063
Patrick Venture9b57a4c2019-05-28 12:54:09 -070064 /* Verify canHandleBlob is reading from the same list (basically) */
Patrick Venture9a69f732019-06-17 14:05:13 -070065 for (const auto& blob : startingBlobs)
Patrick Venture02c0ead2019-05-24 09:01:54 -070066 {
67 EXPECT_TRUE(handler->canHandleBlob(blob));
68 }
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070069}
70
Patrick Venture86c22082019-05-23 09:53:25 -070071/* stat(blob_id) */
72TEST_F(FirmwareHandlerNotYetStartedTest, StatEachBlobIdVerifyResults)
73{
74 /* In this original state, calling stat() on the blob ids will return the
Benjamin Fair12901982019-11-12 13:55:46 -080075 * idle status
Patrick Venture86c22082019-05-23 09:53:25 -070076 */
Patrick Venture86c22082019-05-23 09:53:25 -070077
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));
Benjamin Fair12901982019-11-12 13:55:46 -080083 EXPECT_EQ(expectedIdleMeta, meta);
Patrick Venture86c22082019-05-23 09:53:25 -070084 }
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 Ventured4e20de2019-07-18 12:48:05 -070091 EXPECT_CALL(*imageMock2, open(staticLayoutBlobId)).WillOnce(Return(true));
Patrick Venture6d7735d2019-06-21 10:03:19 -070092 EXPECT_CALL(*prepareMockPtr, trigger()).WillOnce(Return(true));
Patrick Ventureb1a8f702019-05-23 10:10:57 -070093
Patrick Venture65055fb2019-05-23 17:36:01 -070094 EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
Patrick Venture6fdd02e2019-05-28 13:02:04 -070095
96 expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
Patrick Ventureefba42d2019-05-24 10:48:16 -070097
98 EXPECT_TRUE(handler->canHandleBlob(activeImageBlobId));
Patrick Ventureb1a8f702019-05-23 10:10:57 -070099}
100
101TEST_F(FirmwareHandlerNotYetStartedTest, OpenHashFileVerifyStateChange)
102{
Patrick Ventured4e20de2019-07-18 12:48:05 -0700103 EXPECT_CALL(*hashImageMock, open(hashBlobId)).WillOnce(Return(true));
Patrick Venturefa06a5f2019-07-01 09:22:38 -0700104 /* Opening the hash blob id doesn't trigger a preparation, only a firmware
105 * blob.
106 */
107 EXPECT_CALL(*prepareMockPtr, trigger()).Times(0);
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700108
Patrick Venture65055fb2019-05-23 17:36:01 -0700109 EXPECT_TRUE(handler->open(session, flags, hashBlobId));
Patrick Venture6fdd02e2019-05-28 13:02:04 -0700110
111 expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
Patrick Ventureefba42d2019-05-24 10:48:16 -0700112
113 EXPECT_TRUE(handler->canHandleBlob(activeHashBlobId));
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700114}
Patrick Venture86c22082019-05-23 09:53:25 -0700115
Patrick Venture8a4f2aa2019-05-23 08:40:21 -0700116} // namespace
117} // namespace ipmi_flash