blob: d3d35f9954aff8dcf4dfe0ea456c6d4129e62f66 [file] [log] [blame]
Patrick Venturecc7d1602018-11-15 13:58:33 -08001#include "data_mock.hpp"
2#include "firmware_handler.hpp"
Patrick Venture1361a122019-05-20 07:36:05 -07003#include "firmware_unittest.hpp"
Patrick Venturecc7d1602018-11-15 13:58:33 -08004#include "image_mock.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -07005#include "util.hpp"
Patrick Venture3ecb3502019-05-17 11:03:51 -07006#include "verification_mock.hpp"
Patrick Venturecc7d1602018-11-15 13:58:33 -08007
8#include <vector>
9
10#include <gtest/gtest.h>
11
12namespace blobs
13{
14using ::testing::Eq;
15using ::testing::Return;
16
Patrick Venture1361a122019-05-20 07:36:05 -070017class FirmwareSessionStateTestIpmiOnly : public IpmiOnlyFirmwareTest
Patrick Venture3a036312019-05-17 18:56:41 -070018{
Patrick Venture3a036312019-05-17 18:56:41 -070019};
20
Patrick Venture1361a122019-05-20 07:36:05 -070021class FirmwareSessionStateTestLpc : public FakeLpcFirmwareTest
22{
23};
24
25TEST_F(FirmwareSessionStateTestIpmiOnly, DataTypeIpmiNoMetadata)
Patrick Venturecc7d1602018-11-15 13:58:33 -080026{
27 /* Verifying running stat if the type of data session is IPMI returns no
28 * metadata.
29 */
Patrick Venture1361a122019-05-20 07:36:05 -070030 EXPECT_CALL(imageMock, open("asdf")).WillOnce(Return(true));
Patrick Venturecc7d1602018-11-15 13:58:33 -080031
32 EXPECT_TRUE(handler->open(
33 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, "asdf"));
34
35 int size = 512;
Patrick Venture1361a122019-05-20 07:36:05 -070036 EXPECT_CALL(imageMock, getSize()).WillOnce(Return(size));
Patrick Venturecc7d1602018-11-15 13:58:33 -080037
38 struct BlobMeta meta;
39 EXPECT_TRUE(handler->stat(0, &meta));
40 EXPECT_EQ(meta.blobState,
41 OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi);
42 EXPECT_EQ(meta.size, size);
43 EXPECT_EQ(meta.metadata.size(), 0);
44}
45
Patrick Venture1361a122019-05-20 07:36:05 -070046TEST_F(FirmwareSessionStateTestLpc, DataTypeP2AReturnsMetadata)
Patrick Venturecc7d1602018-11-15 13:58:33 -080047{
48 /* Really any type that isn't IPMI can return metadata, but we only expect
49 * P2A to for now. Later, LPC may have reason to provide data, and can by
50 * simply implementing read().
51 */
Patrick Venturecc7d1602018-11-15 13:58:33 -080052 EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
Patrick Venture1361a122019-05-20 07:36:05 -070053 EXPECT_CALL(imageMock, open("asdf")).WillOnce(Return(true));
Patrick Venturecc7d1602018-11-15 13:58:33 -080054
55 EXPECT_TRUE(handler->open(
56 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc, "asdf"));
57
58 int size = 512;
Patrick Venture1361a122019-05-20 07:36:05 -070059 EXPECT_CALL(imageMock, getSize()).WillOnce(Return(size));
Patrick Venturecc7d1602018-11-15 13:58:33 -080060 std::vector<std::uint8_t> mBytes = {0x01, 0x02};
Patrick Venture74304642019-01-17 09:31:04 -080061 EXPECT_CALL(dataMock, readMeta()).WillOnce(Return(mBytes));
Patrick Venturecc7d1602018-11-15 13:58:33 -080062
63 struct BlobMeta meta;
64 EXPECT_TRUE(handler->stat(0, &meta));
65 EXPECT_EQ(meta.blobState,
66 OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc);
67 EXPECT_EQ(meta.size, size);
68 EXPECT_EQ(meta.metadata.size(), mBytes.size());
69 EXPECT_EQ(meta.metadata[0], mBytes[0]);
70 EXPECT_EQ(meta.metadata[1], mBytes[1]);
71}
72
73} // namespace blobs