blob: 7c26688efe377ad66a15ca1294ce7d6ca87a246a [file] [log] [blame]
Patrick Venture2098ff92019-06-03 10:18:05 -07001/* The goal of these tests is to verify the behavior of all blob commands given
2 * the current state is UpdateCompleted. This state is achieved as an exit from
3 * updateStarted.
4 *
5 * This can be reached with success or failure from an update, and is reached
6 * via a stat() call from updatedStarted.
7 */
Patrick Ventureab1e9622019-06-03 10:45:06 -07008#include "firmware_handler.hpp"
9#include "firmware_unittest.hpp"
10#include "status.hpp"
11#include "util.hpp"
12
13#include <string>
14#include <vector>
15
16#include <gtest/gtest.h>
17
18namespace ipmi_flash
19{
20namespace
21{
22
23/*
24 * There are the following calls (parameters may vary):
25 * canHandleBlob(blob)
26 * getBlobIds
27 * deleteBlob(blob)
28 * stat(blob)
29 * stat(session)
30 * open(blob)
31 * close(session)
32 * writemeta(session)
33 * write(session)
34 * read(session)
35 * commit(session)
36 */
37
38class FirmwareHandlerUpdateCompletedTest : public IpmiOnlyFirmwareStaticTest
39{
40};
41
42/*
43 * open(blob)
44 */
45TEST_F(FirmwareHandlerUpdateCompletedTest,
46 AttemptToOpenFilesReturnsFailureAfterSuccess)
47{
48 /* In state updateCompleted a file is open, which means no others can be. */
Patrick Ventureda66fd82019-06-03 11:11:24 -070049 getToUpdateCompleted(ActionStatus::success);
Patrick Ventureab1e9622019-06-03 10:45:06 -070050
51 auto blobsToOpen = handler->getBlobIds();
52 for (const auto& blob : blobsToOpen)
53 {
54 EXPECT_FALSE(handler->open(session + 1, flags, blob));
55 }
56}
57
58/*
Patrick Venturea2d82392019-06-03 10:55:17 -070059 * stat(session)
60 */
61TEST_F(FirmwareHandlerUpdateCompletedTest,
62 CallingStatSessionAfterCompletedSuccessReturnsStateWithoutRechecking)
63{
Patrick Ventureda66fd82019-06-03 11:11:24 -070064 getToUpdateCompleted(ActionStatus::success);
Patrick Venturea2d82392019-06-03 10:55:17 -070065 EXPECT_CALL(*updateMockPtr, status()).Times(0);
66
67 blobs::BlobMeta meta, expectedMeta = {};
68 expectedMeta.size = 0;
69 expectedMeta.blobState = flags | blobs::StateFlags::committed;
70 expectedMeta.metadata.push_back(
Patrick Ventureda66fd82019-06-03 11:11:24 -070071 static_cast<std::uint8_t>(ActionStatus::success));
Patrick Venturea2d82392019-06-03 10:55:17 -070072
73 EXPECT_TRUE(handler->stat(session, &meta));
74 EXPECT_EQ(expectedMeta, meta);
75 expectedState(FirmwareBlobHandler::UpdateState::updateCompleted);
76}
77
78TEST_F(FirmwareHandlerUpdateCompletedTest,
79 CallingStatSessionAfterCompletedFailureReturnsStateWithoutRechecking)
80{
Patrick Ventureda66fd82019-06-03 11:11:24 -070081 getToUpdateCompleted(ActionStatus::failed);
Patrick Venturea2d82392019-06-03 10:55:17 -070082 EXPECT_CALL(*updateMockPtr, status()).Times(0);
83
84 blobs::BlobMeta meta, expectedMeta = {};
85 expectedMeta.size = 0;
86 expectedMeta.blobState = flags | blobs::StateFlags::commit_error;
87 expectedMeta.metadata.push_back(
Patrick Ventureda66fd82019-06-03 11:11:24 -070088 static_cast<std::uint8_t>(ActionStatus::failed));
Patrick Venturea2d82392019-06-03 10:55:17 -070089
90 EXPECT_TRUE(handler->stat(session, &meta));
91 EXPECT_EQ(expectedMeta, meta);
92 expectedState(FirmwareBlobHandler::UpdateState::updateCompleted);
93}
94
95/*
Patrick Ventureab1e9622019-06-03 10:45:06 -070096 * There are the following calls (parameters may vary):
97 * canHandleBlob(blob)
98 * getBlobIds
99 * deleteBlob(blob)
100 * stat(blob)
Patrick Ventureab1e9622019-06-03 10:45:06 -0700101 * close(session)
102 * writemeta(session)
103 * write(session)
104 * read(session)
105 * commit(session)
106 */
107
108} // namespace
109} // namespace ipmi_flash