1 #include "data_mock.hpp"
2 #include "firmware_handler.hpp"
3 #include "firmware_unittest.hpp"
4 #include "image_mock.hpp"
5 #include "triggerable_mock.hpp"
6 #include "util.hpp"
7
8 #include <vector>
9
10 #include <gtest/gtest.h>
11
12 namespace ipmi_flash
13 {
14
15 using ::testing::Return;
16
17 class FirmwareSessionStateTestIpmiOnly : public IpmiOnlyFirmwareTest
18 {};
19
20 class FirmwareSessionStateTestLpc : public FakeLpcFirmwareTest
21 {};
22
TEST_F(FirmwareSessionStateTestIpmiOnly,DataTypeIpmiNoMetadata)23 TEST_F(FirmwareSessionStateTestIpmiOnly, DataTypeIpmiNoMetadata)
24 {
25 /* Verifying running stat if the type of data session is IPMI returns no
26 * metadata.
27 */
28 EXPECT_CALL(*imageMock, open("asdf", std::ios::out)).WillOnce(Return(true));
29
30 EXPECT_TRUE(
31 handler->open(0,
32 static_cast<std::uint16_t>(blobs::OpenFlags::write) |
33 FirmwareFlags::UpdateFlags::ipmi,
34 "asdf"));
35
36 int size = 512;
37 EXPECT_CALL(*imageMock, getSize()).WillOnce(Return(size));
38
39 blobs::BlobMeta meta;
40 EXPECT_TRUE(handler->stat(0, &meta));
41 EXPECT_EQ(meta.blobState,
42 static_cast<std::uint16_t>(blobs::OpenFlags::write) |
43 FirmwareFlags::UpdateFlags::ipmi);
44 EXPECT_EQ(meta.size, size);
45 EXPECT_EQ(meta.metadata.size(), 0);
46 }
47
TEST_F(FirmwareSessionStateTestLpc,DataTypeP2AReturnsMetadata)48 TEST_F(FirmwareSessionStateTestLpc, DataTypeP2AReturnsMetadata)
49 {
50 /* Really any type that isn't IPMI can return metadata, but we only expect
51 * P2A to for now. Later, LPC may have reason to provide data, and can by
52 * simply implementing read().
53 */
54 EXPECT_CALL(*dataMock, open()).WillOnce(Return(true));
55 EXPECT_CALL(*imageMock, open("asdf", std::ios::out)).WillOnce(Return(true));
56
57 EXPECT_TRUE(
58 handler->open(0,
59 static_cast<std::uint16_t>(blobs::OpenFlags::write) |
60 FirmwareFlags::UpdateFlags::lpc,
61 "asdf"));
62
63 int size = 512;
64 EXPECT_CALL(*imageMock, getSize()).WillOnce(Return(size));
65 std::vector<std::uint8_t> mBytes = {0x01, 0x02};
66 EXPECT_CALL(*dataMock, readMeta()).WillOnce(Return(mBytes));
67
68 blobs::BlobMeta meta;
69 EXPECT_TRUE(handler->stat(0, &meta));
70 EXPECT_EQ(meta.blobState,
71 static_cast<std::uint16_t>(blobs::OpenFlags::write) |
72 FirmwareFlags::UpdateFlags::lpc);
73 EXPECT_EQ(meta.size, size);
74 EXPECT_EQ(meta.metadata.size(), mBytes.size());
75 EXPECT_EQ(meta.metadata[0], mBytes[0]);
76 EXPECT_EQ(meta.metadata[1], mBytes[1]);
77 }
78
79 } // namespace ipmi_flash
80