firmware: add read/write configuration methods
A data handler may require the host-side client to read or write
configuration information. Therefore, implement a method for
controlling this in the data handler object.
Change-Id: Id7f8ff54d90cece2e8751773a8696638c2a2ea77
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index 243e733..aeb3758 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -14,7 +14,8 @@
firmware_stat_unittest \
firmware_canhandle_unittest \
firmware_open_unittest \
- firmware_write_unittest
+ firmware_write_unittest \
+ firmware_writemeta_unittest
TESTS = $(check_PROGRAMS)
@@ -32,3 +33,6 @@
firmware_write_unittest_SOURCES = firmware_write_unittest.cpp
firmware_write_unittest_LDADD = $(top_builddir)/firmware_handler.o
+
+firmware_writemeta_unittest_SOURCES = firmware_writemeta_unittest.cpp
+firmware_writemeta_unittest_LDADD = $(top_builddir)/firmware_handler.o
diff --git a/test/data_mock.hpp b/test/data_mock.hpp
index 1fd1fae..a79c562 100644
--- a/test/data_mock.hpp
+++ b/test/data_mock.hpp
@@ -13,6 +13,8 @@
virtual ~DataHandlerMock() = default;
MOCK_METHOD1(copyFrom, std::vector<std::uint8_t>(std::uint32_t));
+ MOCK_METHOD1(write, bool(const std::vector<std::uint8_t>&));
+ MOCK_METHOD0(read, std::vector<std::uint8_t>());
};
} // namespace blobs
diff --git a/test/firmware_writemeta_unittest.cpp b/test/firmware_writemeta_unittest.cpp
new file mode 100644
index 0000000..0a795c9
--- /dev/null
+++ b/test/firmware_writemeta_unittest.cpp
@@ -0,0 +1,69 @@
+#include "data_mock.hpp"
+#include "firmware_handler.hpp"
+#include "image_mock.hpp"
+
+#include <gtest/gtest.h>
+
+namespace blobs
+{
+using ::testing::Eq;
+using ::testing::Return;
+
+TEST(FirmwareHandlerWriteMetaTest, WriteConfigParametersFailIfOverIPMI)
+{
+ ImageHandlerMock imageMock1, imageMock2;
+ std::vector<HandlerPack> blobs = {
+ {FirmwareBlobHandler::hashBlobID, &imageMock1},
+ {"asdf", &imageMock2},
+ };
+
+ DataHandlerMock dataMock;
+
+ std::vector<DataHandlerPack> data = {
+ {FirmwareBlobHandler::FirmwareUpdateFlags::ipmi, nullptr},
+ {FirmwareBlobHandler::FirmwareUpdateFlags::lpc, &dataMock},
+ };
+
+ auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+
+ EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
+
+ EXPECT_TRUE(handler->open(
+ 0, OpenFlags::write | FirmwareBlobHandler::FirmwareUpdateFlags::ipmi,
+ "asdf"));
+
+ std::vector<std::uint8_t> bytes = {0xaa, 0x55};
+
+ EXPECT_FALSE(handler->writeMeta(0, 0, bytes));
+}
+
+TEST(FirmwareHandlerWriteMetaTest, WriteConfigParametersPassedThrough)
+{
+ ImageHandlerMock imageMock1, imageMock2;
+ std::vector<HandlerPack> blobs = {
+ {FirmwareBlobHandler::hashBlobID, &imageMock1},
+ {"asdf", &imageMock2},
+ };
+
+ DataHandlerMock dataMock;
+
+ std::vector<DataHandlerPack> data = {
+ {FirmwareBlobHandler::FirmwareUpdateFlags::ipmi, nullptr},
+ {FirmwareBlobHandler::FirmwareUpdateFlags::lpc, &dataMock},
+ };
+
+ auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+
+ EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
+
+ EXPECT_TRUE(handler->open(
+ 0, OpenFlags::write | FirmwareBlobHandler::FirmwareUpdateFlags::lpc,
+ "asdf"));
+
+ std::vector<std::uint8_t> bytes = {0x01, 0x02, 0x03, 0x04};
+
+ EXPECT_CALL(dataMock, write(Eq(bytes))).WillOnce(Return(true));
+ EXPECT_TRUE(handler->writeMeta(0, 0, bytes));
+}
+
+} // namespace blobs