blob: 86810644c51a708601df031cbe140933a3d77945 [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
76 * transported supported.
77 */
78 blobs::BlobMeta expected;
Patrick Venture84778b82019-06-26 20:11:09 -070079 expected.blobState = FirmwareFlags::UpdateFlags::ipmi;
Patrick Venture86c22082019-05-23 09:53:25 -070080 expected.size = 0;
81
Patrick Venture930c7b72019-05-24 11:11:08 -070082 auto blobs = handler->getBlobIds();
83 for (const auto& blob : blobs)
Patrick Venture86c22082019-05-23 09:53:25 -070084 {
85 blobs::BlobMeta meta = {};
86 EXPECT_TRUE(handler->stat(blob, &meta));
87 EXPECT_EQ(expected, meta);
88 }
89}
90
Patrick Ventureb1a8f702019-05-23 10:10:57 -070091/* open(each blob id) (verifyblobid will no longer be available at this state.
92 */
93TEST_F(FirmwareHandlerNotYetStartedTest, OpenStaticImageFileVerifyStateChange)
94{
Patrick Ventureb1a8f702019-05-23 10:10:57 -070095 EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
Patrick Venture6d7735d2019-06-21 10:03:19 -070096 EXPECT_CALL(*prepareMockPtr, trigger()).WillOnce(Return(true));
Patrick Ventureb1a8f702019-05-23 10:10:57 -070097
Patrick Venture65055fb2019-05-23 17:36:01 -070098 EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
Patrick Venture6fdd02e2019-05-28 13:02:04 -070099
100 expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
Patrick Ventureefba42d2019-05-24 10:48:16 -0700101
102 EXPECT_TRUE(handler->canHandleBlob(activeImageBlobId));
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700103}
104
105TEST_F(FirmwareHandlerNotYetStartedTest, OpenHashFileVerifyStateChange)
106{
Patrick Ventureb1a8f702019-05-23 10:10:57 -0700107 EXPECT_CALL(imageMock, open(hashBlobId)).WillOnce(Return(true));
Patrick Venture6d7735d2019-06-21 10:03:19 -0700108 EXPECT_CALL(*prepareMockPtr, trigger()).WillOnce(Return(true));
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