blob: 788214147c1012cefc541d3acedc67467d92875a [file] [log] [blame]
Patrick Venturecc7d1602018-11-15 13:58:33 -08001#include "data_mock.hpp"
2#include "firmware_handler.hpp"
3#include "image_mock.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -07004#include "util.hpp"
Patrick Venture3ecb3502019-05-17 11:03:51 -07005#include "verification_mock.hpp"
Patrick Venturecc7d1602018-11-15 13:58:33 -08006
7#include <vector>
8
9#include <gtest/gtest.h>
10
11namespace blobs
12{
13using ::testing::Eq;
14using ::testing::Return;
15
16TEST(FirmwareSessionStateTest, DataTypeIpmiNoMetadata)
17{
18 /* Verifying running stat if the type of data session is IPMI returns no
19 * metadata.
20 */
21 ImageHandlerMock imageMock1, imageMock2;
22 std::vector<HandlerPack> blobs = {
Patrick Venture7dad86f2019-05-17 08:52:20 -070023 {hashBlobId, &imageMock1},
Patrick Venturecc7d1602018-11-15 13:58:33 -080024 {"asdf", &imageMock2},
25 };
26
27 std::vector<DataHandlerPack> data = {
28 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
29 };
30
Patrick Venture4eb55952018-11-16 15:36:24 -080031 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture3ecb3502019-05-17 11:03:51 -070032 blobs, data, CreateVerifyMock());
Patrick Venturecc7d1602018-11-15 13:58:33 -080033
34 EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
35
36 EXPECT_TRUE(handler->open(
37 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, "asdf"));
38
39 int size = 512;
40 EXPECT_CALL(imageMock2, getSize()).WillOnce(Return(size));
41
42 struct BlobMeta meta;
43 EXPECT_TRUE(handler->stat(0, &meta));
44 EXPECT_EQ(meta.blobState,
45 OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi);
46 EXPECT_EQ(meta.size, size);
47 EXPECT_EQ(meta.metadata.size(), 0);
48}
49
50TEST(FirmwareSessionStateTest, DataTypeP2AReturnsMetadata)
51{
52 /* Really any type that isn't IPMI can return metadata, but we only expect
53 * P2A to for now. Later, LPC may have reason to provide data, and can by
54 * simply implementing read().
55 */
56 ImageHandlerMock imageMock1, imageMock2;
57 std::vector<HandlerPack> blobs = {
Patrick Venture7dad86f2019-05-17 08:52:20 -070058 {hashBlobId, &imageMock1},
Patrick Venturecc7d1602018-11-15 13:58:33 -080059 {"asdf", &imageMock2},
60 };
61
62 DataHandlerMock dataMock;
63
64 std::vector<DataHandlerPack> data = {
65 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
66 {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
67 };
68
Patrick Venture4eb55952018-11-16 15:36:24 -080069 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture3ecb3502019-05-17 11:03:51 -070070 blobs, data, CreateVerifyMock());
Patrick Venturecc7d1602018-11-15 13:58:33 -080071
72 EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
73 EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
74
75 EXPECT_TRUE(handler->open(
76 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc, "asdf"));
77
78 int size = 512;
79 EXPECT_CALL(imageMock2, getSize()).WillOnce(Return(size));
80 std::vector<std::uint8_t> mBytes = {0x01, 0x02};
Patrick Venture74304642019-01-17 09:31:04 -080081 EXPECT_CALL(dataMock, readMeta()).WillOnce(Return(mBytes));
Patrick Venturecc7d1602018-11-15 13:58:33 -080082
83 struct BlobMeta meta;
84 EXPECT_TRUE(handler->stat(0, &meta));
85 EXPECT_EQ(meta.blobState,
86 OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc);
87 EXPECT_EQ(meta.size, size);
88 EXPECT_EQ(meta.metadata.size(), mBytes.size());
89 EXPECT_EQ(meta.metadata[0], mBytes[0]);
90 EXPECT_EQ(meta.metadata[1], mBytes[1]);
91}
92
93} // namespace blobs