summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2019-05-23 14:29:16 -0500
committerMatt Spinler <spinler@us.ibm.com>2019-07-16 21:30:24 +0000
commit99c2b4059e708a7cba6740a0e832ef5f480a9f12 (patch)
treee7279c67ccf6281dde4adea17162e822eb031b38
parent3b81846a764c4f87977b726188df224c0107c760 (diff)
downloadphosphor-logging-99c2b4059e708a7cba6740a0e832ef5f480a9f12.tar.gz
phosphor-logging-99c2b4059e708a7cba6740a0e832ef5f480a9f12.zip
OpenPower PEL Extension support framework
The goal of extensions is to extend phosphor-logging's `xyz.openbmc_project.Logging.Entry` log support to allow other log formats to be created without incurring extra D-Bus call overhead. The README.md change in this commit provides additional documentation on how extensions work. The summary is that they allow code that resides in this repository to provide functions that can be called at certain points (startup, log creation/deletion) such that the code can then create their own logs based on the contents of an OpenBMC log. A specific extension's code is compiled in using a --enable configure option, so platforms that did not use those log formats would incur no performance/size penalties. This commit provides the support for extensions, plus a basic OpenPower PEL (Platform Event Log) extension as the first extension. PELs are event logs used only on some OpenPower systems. Signed-off-by: Matt Spinler <spinler@us.ibm.com> Change-Id: Ifbb31325261c157678c29bbebc7f6d32d282582f
-rw-r--r--Makefile.am7
-rw-r--r--README.md97
-rw-r--r--configure.ac5
-rw-r--r--extensions.cpp16
-rw-r--r--extensions.hpp246
-rw-r--r--extensions/extensions.mk3
-rw-r--r--extensions/openpower-pels/entry_points.cpp42
-rw-r--r--extensions/openpower-pels/openpower-pels.mk3
-rw-r--r--log_manager.cpp87
-rw-r--r--log_manager.hpp8
-rw-r--r--log_manager_main.cpp15
-rw-r--r--test/Makefile.am20
-rw-r--r--test/extensions_test.cpp98
13 files changed, 636 insertions, 11 deletions
diff --git a/Makefile.am b/Makefile.am
index 82d6c86..e1ec5c3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -40,7 +40,8 @@ phosphor_log_manager_SOURCES = \
elog-process-metadata.cpp \
elog_meta.cpp \
elog_serialize.cpp \
- sdjournal.cpp
+ sdjournal.cpp \
+ extensions.cpp
# Be sure to build needed files before compiling
BUILT_SOURCES = \
@@ -75,6 +76,10 @@ phosphor_log_manager_CXXFLAGS = \
$(SDBUSPLUS_CFLAGS) \
$(PHOSPHOR_DBUS_INTERFACES_CFLAGS)
+
+include extensions/extensions.mk
+
+
xyz/openbmc_project/Logging/Internal/Manager/server.cpp: xyz/openbmc_project/Logging/Internal/Manager.interface.yaml xyz/openbmc_project/Logging/Internal/Manager/server.hpp
@mkdir -p `dirname $@`
$(SDBUSPLUSPLUS) -r $(srcdir) interface server-cpp xyz.openbmc_project.Logging.Internal.Manager > $@
diff --git a/README.md b/README.md
index f8ab729..665fbfc 100644
--- a/README.md
+++ b/README.md
@@ -242,5 +242,102 @@ PACKAGECONFIG_remove_class-target = "install_error_yaml"
#### Local build
* During local build use --prefix=/usr for the configure script.
+## Event Log Extensions
+
+The extension concept is a way to allow code that creates other formats of
+error logs besides phosphor-logging's event logs to still reside in the
+phosphor-log-manager application.
+
+The extension code lives in the `extensions/<extension>` subdirectories,
+and is enabled with a `--enable-<extension>` configure flag. The
+extension code won't compile unless enabled with this flag.
+
+Extensions can register themselves to have functions called at the following
+points using the REGISTER_EXTENSION_FUNCTION macro.
+* On startup
+ * Function type void(internal::Manager&)
+* After an event log is created
+ * Function type void(args)
+ * The args are:
+ * const std::string& - The Message property
+ * uin32_t - The event log ID
+ * uint64_t - The event log timestamp
+ * Level - The event level
+ * const AdditionalDataArg& - the additional data
+ * const AssociationEndpointsArg& - Association endpoints (callouts)
+* Before an event log is deleted, to check if it is allowed.
+ * Function type void(std::uint32_t, bool&) that takes the event ID
+* After an event log is deleted
+ * Function type void(std::uint32_t) that takes the event ID
+
+Using these callback points, they can create their own event log for each
+OpenBMC event log that is created, and delete these logs when the corresponding
+OpenBMC event log is deleted.
+
+In addition, an extension has the option of disabling phosphor-logging's
+default error log capping policy so that it can use its own. The macro
+DISABLE_LOG_ENTRY_CAPS() is used for that.
+
+### Motivation
+
+The reason for adding support for extensions inside the phosphor-log-manager
+daemon as opposed to just creating new daemons that listen for D-Bus signals is
+to allow interactions that would be complicated or expensive if just done over
+D-Bus, such as:
+* Allowing for custom old log retention algorithms.
+* Prohibiting manual deleting of certain logs based on an extension's
+ requirements.
+
+### Creating extensions
+
+1. Add a new flag to configure.ac to enable the extension:
+```
+AC_ARG_ENABLE([foo-extension],
+ AS_HELP_STRING([--enable-foo-extension],
+ [Create Foo logs]))
+AM_CONDITIONAL([ENABLE_FOO_EXTENSION],
+ [test "x$enable_foo_extension" == "xyes"])
+```
+2. Add the code in `extensions/<extension>/`.
+3. Create a makefile include to add the new code to phosphor-log-manager:
+```
+phosphor_log_manager_SOURCES += \
+ extensions/foo/foo.cpp
+```
+3. In `extensions/extensions.mk`, add the makefile include:
+```
+if ENABLE_FOO_EXTENSION
+include extensions/foo/foo.mk
+endif
+```
+4. In the extension code, register the functions to call and optionally disable
+ log capping using the provided macros:
+```
+DISABLE_LOG_ENTRY_CAPS();
+
+void fooStartup(internal::Manager& manager)
+{
+ // Initialize
+}
+
+REGISTER_EXTENSION_FUNCTION(fooStartup);
+
+void fooCreate(const std::string& message, uint32_t id, uint64_t timestamp,
+ Entry::Level severity, const AdditionalDataArg& additionalData,
+ const AssociationEndpointsArg& assocs)
+{
+ // Create a different type of error log based on 'entry'.
+}
+
+REGISTER_EXTENSION_FUNCTION(fooCreate);
+
+void fooRemove(uint32_t id)
+{
+ // Delete the extension error log that corresponds to 'id'.
+}
+
+REGISTER_EXTENSION_FUNCTION(fooRemove);
+```
+
**Reference**
* https://github.com/openbmc/openpower-debug-collector/blob/master/README.md
diff --git a/configure.ac b/configure.ac
index f918ba6..3139382 100644
--- a/configure.ac
+++ b/configure.ac
@@ -146,6 +146,11 @@ AC_DEFINE(SYSTEMD_BUSNAME, "org.freedesktop.systemd1", [systemd busname.])
AC_DEFINE(SYSTEMD_PATH, "/org/freedesktop/systemd1", [systemd path.])
AC_DEFINE(SYSTEMD_INTERFACE, "org.freedesktop.systemd1.Manager", [systemd interface.])
+AC_ARG_ENABLE([openpower-pel-extension],
+ AS_HELP_STRING([--enable-openpower-pel-extension], [Create PELs])
+)
+AM_CONDITIONAL([ENABLE_PEL_EXTENSION], [test "x$enable_openpower_pel_extension" == "xyes"])
+
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile test/Makefile phosphor-rsyslog-config/Makefile])
AC_CONFIG_FILES([phosphor-logging.pc])
diff --git a/extensions.cpp b/extensions.cpp
new file mode 100644
index 0000000..ffeb059
--- /dev/null
+++ b/extensions.cpp
@@ -0,0 +1,16 @@
+#include "extensions.hpp"
+
+namespace phosphor
+{
+namespace logging
+{
+
+StartupFunctions Extensions::startupFunctions{};
+CreateFunctions Extensions::createFunctions{};
+DeleteFunctions Extensions::deleteFunctions{};
+DeleteProhibitedFunctions Extensions::deleteProhibitedFunctions{};
+Extensions::DefaultErrorCaps Extensions::defaultErrorCaps =
+ Extensions::DefaultErrorCaps::enable;
+
+} // namespace logging
+} // namespace phosphor
diff --git a/extensions.hpp b/extensions.hpp
new file mode 100644
index 0000000..3897894
--- /dev/null
+++ b/extensions.hpp
@@ -0,0 +1,246 @@
+#pragma once
+
+#include "elog_entry.hpp"
+#include "log_manager.hpp"
+
+#include <functional>
+#include <vector>
+
+namespace phosphor
+{
+namespace logging
+{
+
+/**
+ * @brief The function type that will be called on start up.
+ * @param[in] internal::Manager& - A reference to the Manager class.
+ */
+using StartupFunction = std::function<void(internal::Manager&)>;
+
+using AdditionalDataArg = std::vector<std::string>;
+using AssociationEndpointsArg = std::vector<std::string>;
+/**
+ * @brief The function type that will be called after an event log
+ * is created.
+ * @param[in] const std::string& - The Message property
+ * @param[in] uin32_t - The event log ID
+ * @param[in] uint64_t - The event log timestamp
+ * @param[in] Level - The event level
+ * @param[in] const AdditionalDataArg&) - the additional data
+ * @param[in] const AssociationEndpoints& - Association endpoints (callouts)
+ */
+using CreateFunction = std::function<void(
+ const std::string&, uint32_t, uint64_t, Entry::Level,
+ const AdditionalDataArg&, const AssociationEndpointsArg&)>;
+
+/**
+ * @brief The function type that will be called after an event log is deleted.
+ * @param[in] uint32_t - The event log ID
+ */
+using DeleteFunction = std::function<void(uint32_t)>;
+
+/**
+ * @brief The function type that will to check if an event log is prohibited
+ * from being deleted.
+ * @param[in] uint32_t - The event log ID
+ * @param[out] bool - set to true if the delete is prohibited
+ */
+using DeleteProhibitedFunction = std::function<void(uint32_t, bool&)>;
+
+using StartupFunctions = std::vector<StartupFunction>;
+using CreateFunctions = std::vector<CreateFunction>;
+using DeleteFunctions = std::vector<DeleteFunction>;
+using DeleteProhibitedFunctions = std::vector<DeleteProhibitedFunction>;
+
+/**
+ * @brief Register an extension hook function
+ *
+ * Call this macro at global scope to register a hook to call.
+ * Each hook point has a unique function prototype.
+ */
+#define REGISTER_EXTENSION_FUNCTION(func) \
+ namespace func##_ns \
+ { \
+ Extensions e{func}; \
+ }
+
+/**
+ * @brief Disable default error log capping
+ *
+ * Call this macro at global scope to tell phosphor-logging to disable its
+ * default error log capping algorithm, so that an extension can use its own
+ * instead.
+ */
+#define DISABLE_LOG_ENTRY_CAPS() \
+ namespace disable_caps##_ns \
+ { \
+ Extensions e{Extensions::DefaultErrorCaps::disable}; \
+ }
+
+/**
+ * @class Extensions
+ *
+ * This class manages any error log extensions. Extensions can register
+ * their hook functions with this class with the provided macros so that they
+ * are then able to create their own types of logs based on the native logs.
+ *
+ * The class should only be constructed at a global scope via the macros.
+ */
+class Extensions
+{
+ public:
+ Extensions() = delete;
+ ~Extensions() = default;
+ Extensions(const Extensions&) = delete;
+ Extensions& operator=(const Extensions&) = delete;
+ Extensions(Extensions&&) = delete;
+ Extensions& operator=(Extensions&&) = delete;
+
+ enum class DefaultErrorCaps
+ {
+ disable,
+ enable
+ };
+
+ /**
+ * @brief Constructor to register a startup function
+ *
+ * Functions registered with this contructor will be called
+ * when phosphor-log-manager starts up.
+ *
+ * @param[in] func - The startup function to register
+ */
+ explicit Extensions(StartupFunction func)
+ {
+ startupFunctions.push_back(func);
+ }
+
+ /**
+ * @brief Constructor to register a create function
+ *
+ * Functions registered with this contructor will be called
+ * after phosphor-log-manager creates an event log.
+ *
+ * @param[in] func - The create function to register
+ */
+ explicit Extensions(CreateFunction func)
+ {
+ createFunctions.push_back(func);
+ }
+
+ /**
+ * @brief Constructor to register a delete function
+ *
+ * Functions registered with this contructor will be called
+ * after phosphor-log-manager deletes an event log.
+ *
+ * @param[in] func - The delete function to register
+ */
+ explicit Extensions(DeleteFunction func)
+ {
+ deleteFunctions.push_back(func);
+ }
+
+ /**
+ * @brief Constructor to register a delete prohibition function
+ *
+ * Functions registered with this contructor will be called
+ * before phosphor-log-manager deletes an event log to ensure
+ * deleting the log is allowed.
+ *
+ * @param[in] func - The function to register
+ */
+ explicit Extensions(DeleteProhibitedFunction func)
+ {
+ deleteProhibitedFunctions.push_back(func);
+ }
+
+ /**
+ * @brief Constructor to disable event log capping
+ *
+ * This constructor should only be called by the
+ * DISABLE_LOG_ENTRY_CAPS macro to disable the default
+ * event log capping so that the extension can use their own.
+ *
+ * @param[in] defaultCaps - Enable or disable default capping.
+ */
+ explicit Extensions(DefaultErrorCaps defaultCaps)
+ {
+ defaultErrorCaps = defaultCaps;
+ }
+
+ /**
+ * @brief Returns the Startup functions
+ * @return StartupFunctions - the Startup functions
+ */
+ static StartupFunctions& getStartupFunctions()
+ {
+ return startupFunctions;
+ }
+
+ /**
+ * @brief Returns the Create functions
+ * @return CreateFunctions - the Create functions
+ */
+ static CreateFunctions& getCreateFunctions()
+ {
+ return createFunctions;
+ }
+
+ /**
+ * @brief Returns the Delete functions
+ * @return DeleteFunctions - the Delete functions
+ */
+ static DeleteFunctions& getDeleteFunctions()
+ {
+ return deleteFunctions;
+ }
+
+ /**
+ * @brief Returns the DeleteProhibited functions
+ * @return DeleteProhibitedFunctions - the DeleteProhibited functions
+ */
+ static DeleteProhibitedFunctions& getDeleteProhibitedFunctions()
+ {
+ return deleteProhibitedFunctions;
+ }
+
+ /**
+ * @brief Say if the default log capping policy should be disabled
+ * @return bool - true if it should be disabled
+ */
+ static bool disableDefaultLogCaps()
+ {
+ return defaultErrorCaps == DefaultErrorCaps::disable;
+ }
+
+ private:
+ /**
+ * @brief Vector of functions to call on app startup.
+ */
+ static StartupFunctions startupFunctions;
+
+ /**
+ * @brief Vector of functions to call after creating an event log.
+ */
+ static CreateFunctions createFunctions;
+
+ /**
+ * @brief Vector of functions to call after deleting an event log.
+ */
+ static DeleteFunctions deleteFunctions;
+
+ /**
+ * @brief Vector of functions to call to check if deleting a
+ * particular event log is prohibited.
+ */
+ static DeleteProhibitedFunctions deleteProhibitedFunctions;
+
+ /**
+ * @brief If default log capping should be disabled.
+ */
+ static DefaultErrorCaps defaultErrorCaps;
+};
+
+} // namespace logging
+} // namespace phosphor
diff --git a/extensions/extensions.mk b/extensions/extensions.mk
new file mode 100644
index 0000000..e7648a8
--- /dev/null
+++ b/extensions/extensions.mk
@@ -0,0 +1,3 @@
+if ENABLE_PEL_EXTENSION
+include extensions/openpower-pels/openpower-pels.mk
+endif
diff --git a/extensions/openpower-pels/entry_points.cpp b/extensions/openpower-pels/entry_points.cpp
new file mode 100644
index 0000000..1b29ec5
--- /dev/null
+++ b/extensions/openpower-pels/entry_points.cpp
@@ -0,0 +1,42 @@
+#include "elog_entry.hpp"
+#include "extensions.hpp"
+#include "sdbusplus/bus.hpp"
+
+namespace openpower
+{
+namespace pels
+{
+
+using namespace phosphor::logging;
+
+DISABLE_LOG_ENTRY_CAPS();
+
+void pelStartup(internal::Manager& logManager)
+{
+}
+
+REGISTER_EXTENSION_FUNCTION(pelStartup);
+
+void pelCreate(const std::string& message, uint32_t id, uint64_t timestamp,
+ Entry::Level severity, const AdditionalDataArg& additionalData,
+ const AssociationEndpointsArg& assocs)
+{
+}
+
+REGISTER_EXTENSION_FUNCTION(pelCreate);
+
+void pelDelete(uint32_t id)
+{
+}
+
+REGISTER_EXTENSION_FUNCTION(pelDelete);
+
+void pelDeleteProhibited(uint32_t id, bool& prohibited)
+{
+ prohibited = false;
+}
+
+REGISTER_EXTENSION_FUNCTION(pelDeleteProhibited);
+
+} // namespace pels
+} // namespace openpower
diff --git a/extensions/openpower-pels/openpower-pels.mk b/extensions/openpower-pels/openpower-pels.mk
new file mode 100644
index 0000000..717fdca
--- /dev/null
+++ b/extensions/openpower-pels/openpower-pels.mk
@@ -0,0 +1,3 @@
+phosphor_log_manager_SOURCES += \
+ extensions/openpower-pels/entry_points.cpp
+
diff --git a/log_manager.cpp b/log_manager.cpp
index 3dc14d7..0f4e57c 100644
--- a/log_manager.cpp
+++ b/log_manager.cpp
@@ -5,6 +5,7 @@
#include "elog_entry.hpp"
#include "elog_meta.hpp"
#include "elog_serialize.hpp"
+#include "extensions.hpp"
#include <poll.h>
#include <sys/inotify.h>
@@ -12,6 +13,7 @@
#include <systemd/sd-journal.h>
#include <unistd.h>
+#include <cassert>
#include <chrono>
#include <cstdio>
#include <cstring>
@@ -77,20 +79,24 @@ void Manager::commitWithLvl(uint64_t transactionId, std::string errMsg,
void Manager::_commit(uint64_t transactionId, std::string&& errMsg,
Entry::Level errLvl)
{
- if (errLvl < Entry::sevLowerLimit)
+ if (!Extensions::disableDefaultLogCaps())
{
- if (realErrors.size() >= ERROR_CAP)
+ if (errLvl < Entry::sevLowerLimit)
{
- erase(realErrors.front());
+ if (realErrors.size() >= ERROR_CAP)
+ {
+ erase(realErrors.front());
+ }
}
- }
- else
- {
- if (infoErrors.size() >= ERROR_INFO_CAP)
+ else
{
- erase(infoErrors.front());
+ if (infoErrors.size() >= ERROR_INFO_CAP)
+ {
+ erase(infoErrors.front());
+ }
}
}
+
constexpr const auto transactionIdVar = "TRANSACTION_ID";
// Length of 'TRANSACTION_ID' string.
constexpr const auto transactionIdVarSize = std::strlen(transactionIdVar);
@@ -217,9 +223,39 @@ void Manager::_commit(uint64_t transactionId, std::string&& errMsg,
std::move(additionalData),
std::move(objects), fwVersion, *this);
serialize(*e);
+
+ doExtensionLogCreate(*e);
+
entries.insert(std::make_pair(entryId, std::move(e)));
}
+void Manager::doExtensionLogCreate(const Entry& entry)
+{
+ // Make the association <endpointpath>/<endpointtype> paths
+ std::vector<std::string> assocs;
+ for (const auto& [forwardType, reverseType, endpoint] :
+ entry.associations())
+ {
+ std::string e{endpoint};
+ e += '/' + reverseType;
+ assocs.push_back(e);
+ }
+
+ for (auto& create : Extensions::getCreateFunctions())
+ {
+ try
+ {
+ create(entry.message(), entry.id(), entry.timestamp(),
+ entry.severity(), entry.additionalData(), assocs);
+ }
+ catch (std::exception& e)
+ {
+ log<level::ERR>("An extension's create function threw an exception",
+ phosphor::logging::entry("ERROR=%s", e.what()));
+ }
+ }
+}
+
void Manager::processMetadata(const std::string& errorName,
const std::vector<std::string>& additionalData,
AssociationList& objects) const
@@ -246,6 +282,27 @@ void Manager::erase(uint32_t entryId)
auto entryFound = entries.find(entryId);
if (entries.end() != entryFound)
{
+ for (auto& func : Extensions::getDeleteProhibitedFunctions())
+ {
+ try
+ {
+ bool prohibited = false;
+ func(entryId, prohibited);
+ if (prohibited)
+ {
+ // Future work remains to throw an error here.
+ return;
+ }
+ }
+ catch (std::exception& e)
+ {
+ log<level::ERR>(
+ "An extension's deleteProhibited function threw "
+ "an exception",
+ entry("ERROR=%s", e.what()));
+ }
+ }
+
// Delete the persistent representation of this error.
fs::path errorPath(ERRLOG_PERSIST_PATH);
errorPath /= std::to_string(entryId);
@@ -267,6 +324,20 @@ void Manager::erase(uint32_t entryId)
removeId(realErrors, entryId);
}
entries.erase(entryFound);
+
+ for (auto& remove : Extensions::getDeleteFunctions())
+ {
+ try
+ {
+ remove(entryId);
+ }
+ catch (std::exception& e)
+ {
+ log<level::ERR>("An extension's delete function threw an "
+ "exception",
+ entry("ERROR=%s", e.what()));
+ }
+ }
}
else
{
diff --git a/log_manager.hpp b/log_manager.hpp
index e6714af..4b09952 100644
--- a/log_manager.hpp
+++ b/log_manager.hpp
@@ -154,6 +154,14 @@ class Manager : public details::ServerObject<details::ManagerIface>
*/
static std::string readFWVersion();
+ /** @brief Call any create() functions provided by any extensions.
+ * This is called right after an event log is created to allow
+ * extensions to create their own log based on this one.
+ *
+ * @param[in] entry - the new event log entry
+ */
+ void doExtensionLogCreate(const Entry& entry);
+
/** @brief Persistent sdbusplus DBus bus connection. */
sdbusplus::bus::bus& busLog;
diff --git a/log_manager_main.cpp b/log_manager_main.cpp
index 48a7dee..ddcb063 100644
--- a/log_manager_main.cpp
+++ b/log_manager_main.cpp
@@ -1,5 +1,6 @@
#include "config.h"
+#include "extensions.hpp"
#include "log_manager.hpp"
#include <experimental/filesystem>
@@ -25,6 +26,20 @@ int main(int argc, char* argv[])
bus.request_name(BUSNAME_LOGGING);
+ for (auto& startup : phosphor::logging::Extensions::getStartupFunctions())
+ {
+ try
+ {
+ startup(iMgr);
+ }
+ catch (std::exception& e)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "An extension's startup function threw an exception",
+ phosphor::logging::entry("ERROR=%s", e.what()));
+ }
+ }
+
while (true)
{
bus.process_discard();
diff --git a/test/Makefile.am b/test/Makefile.am
index 7fd38d1..a55e9a9 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -9,7 +9,8 @@ check_PROGRAMS = \
remote_logging_test_address \
remote_logging_test_port \
remote_logging_test_config \
- sdjournal_mock_test
+ sdjournal_mock_test \
+ extensions_test
test_cppflags = \
-Igtest \
@@ -38,7 +39,8 @@ test_ldadd = \
$(top_builddir)/elog_meta.o \
$(top_builddir)/elog-lookup.o \
$(top_builddir)/elog-process-metadata.o \
- $(top_builddir)/sdjournal.o
+ $(top_builddir)/sdjournal.o \
+ $(top_builddir)/extensions.o
remote_logging_test_ldadd = \
$(top_builddir)/phosphor-rsyslog-config/server-conf.o \
@@ -98,5 +100,19 @@ sdjournal_mock_test_SOURCES = sdtest.cpp
sdjournal_mock_test_LDADD = $(top_builddir)/sdjournal.o
sdjournal_mock_test_LDFLAGS = $(test_ldflags)
+extensions_test_CPPFLAGS = $(test_cppflags)
+extensions_test_CXXFLAGS = $(test_cxxflags)
+extensions_test_SOURCES = extensions_test.cpp
+extensions_test_LDADD = \
+ $(top_builddir)/elog_entry.o \
+ $(top_builddir)/elog-lookup.o \
+ $(top_builddir)/elog_meta.o \
+ $(top_builddir)/elog-process-metadata.o \
+ $(top_builddir)/elog_serialize.o \
+ $(top_builddir)/log_manager.o \
+ $(top_builddir)/org.openbmc.Associations.o \
+ $(top_builddir)/xyz/openbmc_project/Logging/Internal/Manager/server.o
+extensions_test_LDFLAGS = $(test_ldflags) -lstdc++fs
+
# TODO Remove once the test-case failure is resolved openbmc/phosphor-logging#11
XFAIL_TESTS = elog_errorwrap_test
diff --git a/test/extensions_test.cpp b/test/extensions_test.cpp
new file mode 100644
index 0000000..17c3395
--- /dev/null
+++ b/test/extensions_test.cpp
@@ -0,0 +1,98 @@
+#include "elog_entry.hpp"
+#include "extensions.hpp"
+
+#include <gtest/gtest.h>
+
+using namespace phosphor::logging;
+
+// gtest doesn't like this happening in another file, so do it here.
+StartupFunctions Extensions::startupFunctions{};
+CreateFunctions Extensions::createFunctions{};
+DeleteFunctions Extensions::deleteFunctions{};
+DeleteProhibitedFunctions Extensions::deleteProhibitedFunctions{};
+Extensions::DefaultErrorCaps Extensions::defaultErrorCaps =
+ Extensions::DefaultErrorCaps::enable;
+
+void startup1(internal::Manager& manager)
+{
+}
+
+void startup2(internal::Manager& manager)
+{
+}
+
+void create1(const std::string& message, uint32_t id, uint64_t timestamp,
+ Entry::Level severity, const AdditionalDataArg& additionalData,
+ const AssociationEndpointsArg& assocs)
+{
+}
+
+void create2(const std::string& message, uint32_t id, uint64_t timestamp,
+ Entry::Level severity, const AdditionalDataArg& additionalData,
+ const AssociationEndpointsArg& assocs)
+{
+}
+
+void deleteLog1(uint32_t id)
+{
+}
+
+void deleteLog2(uint32_t id)
+{
+}
+
+void deleteProhibited1(uint32_t id, bool& prohibited)
+{
+ prohibited = true;
+}
+
+void deleteProhibited2(uint32_t id, bool& prohibited)
+{
+ prohibited = true;
+}
+
+DISABLE_LOG_ENTRY_CAPS();
+REGISTER_EXTENSION_FUNCTION(startup1);
+REGISTER_EXTENSION_FUNCTION(startup2);
+REGISTER_EXTENSION_FUNCTION(create1);
+REGISTER_EXTENSION_FUNCTION(create2);
+REGISTER_EXTENSION_FUNCTION(deleteProhibited1);
+REGISTER_EXTENSION_FUNCTION(deleteProhibited2);
+REGISTER_EXTENSION_FUNCTION(deleteLog1);
+REGISTER_EXTENSION_FUNCTION(deleteLog2);
+
+TEST(ExtensionsTest, FunctionCallTest)
+{
+ auto bus = sdbusplus::bus::new_default();
+ internal::Manager manager(bus, "testpath");
+
+ EXPECT_EQ(Extensions::getStartupFunctions().size(), 2);
+ for (auto& s : Extensions::getStartupFunctions())
+ {
+ s(manager);
+ }
+
+ AdditionalDataArg ad;
+ AssociationEndpointsArg assocs;
+ EXPECT_EQ(Extensions::getCreateFunctions().size(), 2);
+ for (auto& c : Extensions::getCreateFunctions())
+ {
+ c("test", 5, 6, Entry::Level::Informational, ad, assocs);
+ }
+
+ EXPECT_EQ(Extensions::getDeleteFunctions().size(), 2);
+ for (auto& d : Extensions::getDeleteFunctions())
+ {
+ d(5);
+ }
+
+ EXPECT_EQ(Extensions::getDeleteProhibitedFunctions().size(), 2);
+ for (auto& p : Extensions::getDeleteProhibitedFunctions())
+ {
+ bool prohibited = false;
+ p(5, prohibited);
+ EXPECT_TRUE(prohibited);
+ }
+
+ EXPECT_TRUE(Extensions::disableDefaultLogCaps());
+}
OpenPOWER on IntegriCloud