blob: dcb16d9349a54a7e56960e4f60fb65c5dde972f8 [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 Venture1d66fe62019-06-03 14:57:27 -07005#include "triggerable_mock.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -07006#include "util.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 Venture84778b82019-06-26 20:11:09 -070033 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, "asdf"));
Patrick Venturecc7d1602018-11-15 13:58:33 -080034
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
Patrick Venturee312f392019-06-04 07:44:37 -070038 blobs::BlobMeta meta;
Patrick Venturecc7d1602018-11-15 13:58:33 -080039 EXPECT_TRUE(handler->stat(0, &meta));
40 EXPECT_EQ(meta.blobState,
Patrick Venture84778b82019-06-26 20:11:09 -070041 blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi);
Patrick Venturecc7d1602018-11-15 13:58:33 -080042 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(
Patrick Venture84778b82019-06-26 20:11:09 -070056 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::lpc, "asdf"));
Patrick Venturecc7d1602018-11-15 13:58:33 -080057
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
Patrick Venturee312f392019-06-04 07:44:37 -070063 blobs::BlobMeta meta;
Patrick Venturecc7d1602018-11-15 13:58:33 -080064 EXPECT_TRUE(handler->stat(0, &meta));
65 EXPECT_EQ(meta.blobState,
Patrick Venture84778b82019-06-26 20:11:09 -070066 blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::lpc);
Patrick Venturecc7d1602018-11-15 13:58:33 -080067 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
Patrick Venture1d5a31c2019-05-20 11:38:22 -070073} // namespace ipmi_flash