firmware: add logging to factory failures
Add logging to factory failures. This is now possible
with injection available for phosphor-logging.
Change-Id: I77ac959d58e44305d7acf918b656bdd21a9c4da8
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/firmware_handler.cpp b/firmware_handler.cpp
index 03cf1c2..f2740c7 100644
--- a/firmware_handler.cpp
+++ b/firmware_handler.cpp
@@ -22,9 +22,12 @@
#include <cstdint>
#include <cstring>
#include <memory>
+#include <phosphor-logging/log.hpp>
#include <string>
#include <vector>
+using namespace phosphor::logging;
+
namespace blobs
{
// systemd service to kick start a target.
@@ -47,6 +50,7 @@
/* There must be at least one. */
if (!firmwares.size())
{
+ log<level::ERR>("Must provide at least one firmware handler.");
return nullptr;
}
if (!transports.size())
diff --git a/test/Makefile.am b/test/Makefile.am
index 731a030..8e7dada 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -3,15 +3,18 @@
$(GMOCK_CFLAGS)
AM_CXXFLAGS = \
$(GTEST_MAIN_CFLAGS) \
- $(SDBUSPLUS_CFLAGS)
+ $(SDBUSPLUS_CFLAGS) \
+ $(PHOSPHOR_LOGGING_CFLAGS)
AM_LDFLAGS = \
$(GMOCK_LIBS) \
$(GTEST_MAIN_LIBS) \
$(OESDK_TESTCASE_FLAGS) \
- $(SDBUSPLUS_LIBS)
+ $(SDBUSPLUS_LIBS) \
+ $(PHOSPHOR_LOGGING_LIBS)
# Run all 'check' test programs
check_PROGRAMS = \
+ firmware_createhandler_unittest \
firmware_handler_unittest \
firmware_stat_unittest \
firmware_canhandle_unittest \
@@ -26,6 +29,9 @@
TESTS = $(check_PROGRAMS)
+firmware_createhandler_unittest_SOURCES = firmware_createhandler_unittest.cpp
+firmware_createhandler_unittest_LDADD = $(top_builddir)/firmware_handler.o
+
firmware_handler_unittest_SOURCES = firmware_handler_unittest.cpp
firmware_handler_unittest_LDADD = $(top_builddir)/firmware_handler.o
diff --git a/test/firmware_createhandler_unittest.cpp b/test/firmware_createhandler_unittest.cpp
new file mode 100644
index 0000000..78bde97
--- /dev/null
+++ b/test/firmware_createhandler_unittest.cpp
@@ -0,0 +1,44 @@
+#include "data_mock.hpp"
+#include "firmware_handler.hpp"
+
+#include <phosphor-logging/test/sdjournal_mock.hpp>
+#include <sdbusplus/test/sdbus_mock.hpp>
+
+#include <gtest/gtest.h>
+
+using namespace phosphor::logging;
+
+namespace blobs
+{
+using ::testing::Return;
+using ::testing::StrEq;
+using ::testing::StrictMock;
+
+TEST(FirmwareHandlerBlobTest, VerifyFirmareCounts)
+{
+ /* Verify the firmware count must be greater than zero. */
+
+ DataHandlerMock dataMock;
+ StrictMock<SdJournalMock> journalMock;
+ SwapJouralHandler(&journalMock);
+
+ std::vector<HandlerPack> blobs;
+
+ std::vector<DataHandlerPack> data = {
+ {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
+ {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
+ };
+
+ sdbusplus::SdBusMock sdbus_mock;
+ auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+ EXPECT_CALL(journalMock, journal_send_call(StrEq("PRIORITY=%d")))
+ .WillOnce(Return(0));
+
+ auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+ std::move(bus_mock), blobs, data);
+
+ EXPECT_EQ(handler, nullptr);
+}
+
+} // namespace blobs