blob: 2a100bd86ac63197843ccd2523af9d77f6edf9dc [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{
24};
25
26/*
27 * There are the following calls (parameters may vary):
28 * Note: you cannot have a session yet, so only commands that don't take a
29 * session parameter are valid. Once you open() from this state, we will vary
30 * you transition out of this state (ensuring the above is true). Technically
31 * the firmware handler receives the session number with open(), but the blob
32 * manager is providing this normally.
33 *
34 * canHandleBlob
35 * getBlobIds
36 * deleteBlob
37 * stat
38 * open
39 *
40 * canHandleBlob is just a count check (or something similar) against what is
41 * returned by getBlobIds. It is tested in firmware_canhandle_unittest
42 */
43
Patrick Venture72676762019-06-17 11:22:38 -070044/*
45 * deleteBlob()
46 */
47TEST_F(FirmwareHandlerNotYetStartedTest, DeleteBlobInStateReturnsFalse)
48{
49 auto blobs = handler->getBlobIds();
50 for (const auto& b : blobs)
51 {
52 EXPECT_FALSE(handler->deleteBlob(b));
53 }
54}
55
Patrick Venture9b57a4c2019-05-28 12:54:09 -070056/* canHandleBlob, getBlobIds */
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070057TEST_F(FirmwareHandlerNotYetStartedTest, GetBlobListValidateListContents)
58{
Patrick Venture9b57a4c2019-05-28 12:54:09 -070059 /* By only checking that the hash and static blob ids are present to start
60 * with, we're also verifying others aren't.
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070061 */
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070062 EXPECT_THAT(handler->getBlobIds(),
Patrick Venture9a69f732019-06-17 14:05:13 -070063 UnorderedElementsAreArray(startingBlobs));
Patrick Venture02c0ead2019-05-24 09:01:54 -070064
Patrick Venture9b57a4c2019-05-28 12:54:09 -070065 /* Verify canHandleBlob is reading from the same list (basically) */
Patrick Venture9a69f732019-06-17 14:05:13 -070066 for (const auto& blob : startingBlobs)
Patrick Venture02c0ead2019-05-24 09:01:54 -070067 {
68 EXPECT_TRUE(handler->canHandleBlob(blob));
69 }
Patrick Venture8a4f2aa2019-05-23 08:40:21 -070070}
71
Patrick Venture86c22082019-05-23 09:53:25 -070072/* stat(blob_id) */
73TEST_F(FirmwareHandlerNotYetStartedTest, StatEachBlobIdVerifyResults)
74{
75 /* In this original state, calling stat() on the blob ids will return the
Benjamin Fair12901982019-11-12 13:55:46 -080076 * idle status
Patrick Venture86c22082019-05-23 09:53:25 -070077 */
Patrick Venture86c22082019-05-23 09:53:25 -070078
Patrick Venture930c7b72019-05-24 11:11:08 -070079 auto blobs = handler->getBlobIds();
80 for (const auto& blob : blobs)
Patrick Venture86c22082019-05-23 09:53:25 -070081 {
82 blobs::BlobMeta meta = {};
83 EXPECT_TRUE(handler->stat(blob, &meta));
Benjamin Fair12901982019-11-12 13:55:46 -080084 EXPECT_EQ(expectedIdleMeta, meta);
Patrick Venture86c22082019-05-23 09:53:25 -070085 }
86}
87
Patrick Ventureb1a8f702019-05-23 10:10:57 -070088/* open(each blob id) (verifyblobid will no longer be available at this state.
89 */
90TEST_F(FirmwareHandlerNotYetStartedTest, OpenStaticImageFileVerifyStateChange)
91{
Patrick Ventured4e20de2019-07-18 12:48:05 -070092 EXPECT_CALL(*imageMock2, open(staticLayoutBlobId)).WillOnce(Return(true));
Patrick Venture6d7735d2019-06-21 10:03:19 -070093 EXPECT_CALL(*prepareMockPtr, trigger()).WillOnce(Return(true));
Patrick Ventureb1a8f702019-05-23 10:10:57 -070094
Patrick Venture65055fb2019-05-23 17:36:01 -070095 EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
Patrick Venture6fdd02e2019-05-28 13:02:04 -070096
97 expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
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 Ventured4e20de2019-07-18 12:48:05 -0700104 EXPECT_CALL(*hashImageMock, open(hashBlobId)).WillOnce(Return(true));
Patrick Venturefa06a5f2019-07-01 09:22:38 -0700105 /* Opening the hash blob id doesn't trigger a preparation, only a firmware
106 * blob.
107 */
108 EXPECT_CALL(*prepareMockPtr, trigger()).Times(0);
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700109
Patrick Venture65055fb2019-05-23 17:36:01 -0700110 EXPECT_TRUE(handler->open(session, flags, hashBlobId));
Patrick Venture6fdd02e2019-05-28 13:02:04 -0700111
112 expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
Patrick Ventureefba42d2019-05-24 10:48:16 -0700113
114 EXPECT_TRUE(handler->canHandleBlob(activeHashBlobId));
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700115}
Patrick Venture86c22082019-05-23 09:53:25 -0700116
Patrick Venture8a4f2aa2019-05-23 08:40:21 -0700117} // namespace
118} // namespace ipmi_flash