blob: 98fb6daa9cb366099ab59bc04826bcf8b6bacb47 [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
Patrick Venture1d5a31c2019-05-20 11:38:22 -070012namespace ipmi_flash
Patrick Venturecc7d1602018-11-15 13:58:33 -080013{
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(
Patrick Venture1d5a31c2019-05-20 11:38:22 -070033 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi,
34 "asdf"));
Patrick Venturecc7d1602018-11-15 13:58:33 -080035
36 int size = 512;
Patrick Venture1361a122019-05-20 07:36:05 -070037 EXPECT_CALL(imageMock, getSize()).WillOnce(Return(size));
Patrick Venturecc7d1602018-11-15 13:58:33 -080038
Patrick Venture1d5a31c2019-05-20 11:38:22 -070039 struct blobs::BlobMeta meta;
Patrick Venturecc7d1602018-11-15 13:58:33 -080040 EXPECT_TRUE(handler->stat(0, &meta));
41 EXPECT_EQ(meta.blobState,
Patrick Venture1d5a31c2019-05-20 11:38:22 -070042 blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi);
Patrick Venturecc7d1602018-11-15 13:58:33 -080043 EXPECT_EQ(meta.size, size);
44 EXPECT_EQ(meta.metadata.size(), 0);
45}
46
Patrick Venture1361a122019-05-20 07:36:05 -070047TEST_F(FirmwareSessionStateTestLpc, DataTypeP2AReturnsMetadata)
Patrick Venturecc7d1602018-11-15 13:58:33 -080048{
49 /* Really any type that isn't IPMI can return metadata, but we only expect
50 * P2A to for now. Later, LPC may have reason to provide data, and can by
51 * simply implementing read().
52 */
Patrick Venturecc7d1602018-11-15 13:58:33 -080053 EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
Patrick Venture1361a122019-05-20 07:36:05 -070054 EXPECT_CALL(imageMock, open("asdf")).WillOnce(Return(true));
Patrick Venturecc7d1602018-11-15 13:58:33 -080055
56 EXPECT_TRUE(handler->open(
Patrick Venture1d5a31c2019-05-20 11:38:22 -070057 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc,
58 "asdf"));
Patrick Venturecc7d1602018-11-15 13:58:33 -080059
60 int size = 512;
Patrick Venture1361a122019-05-20 07:36:05 -070061 EXPECT_CALL(imageMock, getSize()).WillOnce(Return(size));
Patrick Venturecc7d1602018-11-15 13:58:33 -080062 std::vector<std::uint8_t> mBytes = {0x01, 0x02};
Patrick Venture74304642019-01-17 09:31:04 -080063 EXPECT_CALL(dataMock, readMeta()).WillOnce(Return(mBytes));
Patrick Venturecc7d1602018-11-15 13:58:33 -080064
Patrick Venture1d5a31c2019-05-20 11:38:22 -070065 struct blobs::BlobMeta meta;
Patrick Venturecc7d1602018-11-15 13:58:33 -080066 EXPECT_TRUE(handler->stat(0, &meta));
67 EXPECT_EQ(meta.blobState,
Patrick Venture1d5a31c2019-05-20 11:38:22 -070068 blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc);
Patrick Venturecc7d1602018-11-15 13:58:33 -080069 EXPECT_EQ(meta.size, size);
70 EXPECT_EQ(meta.metadata.size(), mBytes.size());
71 EXPECT_EQ(meta.metadata[0], mBytes[0]);
72 EXPECT_EQ(meta.metadata[1], mBytes[1]);
73}
74
Patrick Venture1d5a31c2019-05-20 11:38:22 -070075} // namespace ipmi_flash