blob: 95e0a32d25276d5adc261d00ba86d949dd514b7b [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. */
49 getToUpdateCompleted(UpdateStatus::success);
50
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{
64 getToUpdateCompleted(UpdateStatus::success);
65 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(
71 static_cast<std::uint8_t>(UpdateStatus::success));
72
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{
81 getToUpdateCompleted(UpdateStatus::failed);
82 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(
88 static_cast<std::uint8_t>(UpdateStatus::failed));
89
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