blob: 07362937198bbb4fe5011df908d28383cb243c24 [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{
Patrick Venture63902a42020-10-06 12:13:31 -070014
Patrick Venturecc7d1602018-11-15 13:58:33 -080015using ::testing::Return;
16
Patrick Venture1361a122019-05-20 07:36:05 -070017class FirmwareSessionStateTestIpmiOnly : public IpmiOnlyFirmwareTest
Patrick Venture9b37b092020-05-28 20:58:57 -070018{};
Patrick Venture3a036312019-05-17 18:56:41 -070019
Patrick Venture1361a122019-05-20 07:36:05 -070020class FirmwareSessionStateTestLpc : public FakeLpcFirmwareTest
Patrick Venture9b37b092020-05-28 20:58:57 -070021{};
Patrick Venture1361a122019-05-20 07:36:05 -070022
23TEST_F(FirmwareSessionStateTestIpmiOnly, DataTypeIpmiNoMetadata)
Patrick Venturecc7d1602018-11-15 13:58:33 -080024{
25 /* Verifying running stat if the type of data session is IPMI returns no
26 * metadata.
27 */
Patrick Ventured4e20de2019-07-18 12:48:05 -070028 EXPECT_CALL(*imageMock, open("asdf")).WillOnce(Return(true));
Patrick Venturecc7d1602018-11-15 13:58:33 -080029
30 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070031 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, "asdf"));
Patrick Venturecc7d1602018-11-15 13:58:33 -080032
33 int size = 512;
Patrick Ventured4e20de2019-07-18 12:48:05 -070034 EXPECT_CALL(*imageMock, getSize()).WillOnce(Return(size));
Patrick Venturecc7d1602018-11-15 13:58:33 -080035
Patrick Venturee312f392019-06-04 07:44:37 -070036 blobs::BlobMeta meta;
Patrick Venturecc7d1602018-11-15 13:58:33 -080037 EXPECT_TRUE(handler->stat(0, &meta));
38 EXPECT_EQ(meta.blobState,
Patrick Venture84778b82019-06-26 20:11:09 -070039 blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi);
Patrick Venturecc7d1602018-11-15 13:58:33 -080040 EXPECT_EQ(meta.size, size);
41 EXPECT_EQ(meta.metadata.size(), 0);
42}
43
Patrick Venture1361a122019-05-20 07:36:05 -070044TEST_F(FirmwareSessionStateTestLpc, DataTypeP2AReturnsMetadata)
Patrick Venturecc7d1602018-11-15 13:58:33 -080045{
46 /* Really any type that isn't IPMI can return metadata, but we only expect
47 * P2A to for now. Later, LPC may have reason to provide data, and can by
48 * simply implementing read().
49 */
Patrick Venture4934daa2020-09-22 16:37:44 -070050 EXPECT_CALL(*dataMock, open()).WillOnce(Return(true));
Patrick Ventured4e20de2019-07-18 12:48:05 -070051 EXPECT_CALL(*imageMock, open("asdf")).WillOnce(Return(true));
Patrick Venturecc7d1602018-11-15 13:58:33 -080052
53 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070054 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::lpc, "asdf"));
Patrick Venturecc7d1602018-11-15 13:58:33 -080055
56 int size = 512;
Patrick Ventured4e20de2019-07-18 12:48:05 -070057 EXPECT_CALL(*imageMock, getSize()).WillOnce(Return(size));
Patrick Venturecc7d1602018-11-15 13:58:33 -080058 std::vector<std::uint8_t> mBytes = {0x01, 0x02};
Patrick Venture4934daa2020-09-22 16:37:44 -070059 EXPECT_CALL(*dataMock, readMeta()).WillOnce(Return(mBytes));
Patrick Venturecc7d1602018-11-15 13:58:33 -080060
Patrick Venturee312f392019-06-04 07:44:37 -070061 blobs::BlobMeta meta;
Patrick Venturecc7d1602018-11-15 13:58:33 -080062 EXPECT_TRUE(handler->stat(0, &meta));
63 EXPECT_EQ(meta.blobState,
Patrick Venture84778b82019-06-26 20:11:09 -070064 blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::lpc);
Patrick Venturecc7d1602018-11-15 13:58:33 -080065 EXPECT_EQ(meta.size, size);
66 EXPECT_EQ(meta.metadata.size(), mBytes.size());
67 EXPECT_EQ(meta.metadata[0], mBytes[0]);
68 EXPECT_EQ(meta.metadata[1], mBytes[1]);
69}
70
Patrick Venture1d5a31c2019-05-20 11:38:22 -070071} // namespace ipmi_flash