blob: 0ca5c62f314f876765ce71a34bf1caae369d1cc8 [file] [log] [blame]
Patrick Venture8c535332018-11-08 15:58:00 -08001#include "data_mock.hpp"
2#include "firmware_handler.hpp"
Patrick Venture1361a122019-05-20 07:36:05 -07003#include "firmware_unittest.hpp"
Patrick Venture8c535332018-11-08 15:58:00 -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 Venture4eb55952018-11-16 15:36:24 -08007
Patrick Venturead7c73d2019-05-17 18:50:27 -07008#include <memory>
9#include <vector>
10
Patrick Venture8c535332018-11-08 15:58:00 -080011#include <gtest/gtest.h>
12
13namespace blobs
14{
15using ::testing::Eq;
16using ::testing::Return;
17
Patrick Venture1361a122019-05-20 07:36:05 -070018class FirmwareHandlerWriteMetaTest : public FakeLpcFirmwareTest
Patrick Venture8c535332018-11-08 15:58:00 -080019{
Patrick Venturead7c73d2019-05-17 18:50:27 -070020};
Patrick Venture8c535332018-11-08 15:58:00 -080021
Patrick Venturead7c73d2019-05-17 18:50:27 -070022TEST_F(FirmwareHandlerWriteMetaTest, WriteConfigParametersFailIfOverIPMI)
23{
Patrick Venture1361a122019-05-20 07:36:05 -070024 EXPECT_CALL(imageMock, open("asdf")).WillOnce(Return(true));
Patrick Venture8c535332018-11-08 15:58:00 -080025
26 EXPECT_TRUE(handler->open(
Patrick Venture05abf7e2018-11-09 11:02:56 -080027 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, "asdf"));
Patrick Venture8c535332018-11-08 15:58:00 -080028
29 std::vector<std::uint8_t> bytes = {0xaa, 0x55};
30
31 EXPECT_FALSE(handler->writeMeta(0, 0, bytes));
32}
33
Patrick Venturead7c73d2019-05-17 18:50:27 -070034TEST_F(FirmwareHandlerWriteMetaTest, WriteConfigParametersPassedThrough)
Patrick Venture8c535332018-11-08 15:58:00 -080035{
Patrick Venture6e307a72018-11-09 18:21:17 -080036 EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
Patrick Venture1361a122019-05-20 07:36:05 -070037 EXPECT_CALL(imageMock, open("asdf")).WillOnce(Return(true));
Patrick Venture8c535332018-11-08 15:58:00 -080038
39 EXPECT_TRUE(handler->open(
Patrick Venture05abf7e2018-11-09 11:02:56 -080040 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc, "asdf"));
Patrick Venture8c535332018-11-08 15:58:00 -080041
42 std::vector<std::uint8_t> bytes = {0x01, 0x02, 0x03, 0x04};
43
Patrick Venture74304642019-01-17 09:31:04 -080044 EXPECT_CALL(dataMock, writeMeta(Eq(bytes))).WillOnce(Return(true));
Patrick Venture8c535332018-11-08 15:58:00 -080045 EXPECT_TRUE(handler->writeMeta(0, 0, bytes));
46}
47
48} // namespace blobs