summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2018-10-26 18:14:00 -0700
committerPatrick Venture <venture@google.com>2018-10-26 18:16:27 -0700
commitf18bf836d206b1bc5b4fd849127a2e706eddf0aa (patch)
tree5c61f65861a2350f84080f21c6b996d33d0c2ab3
parentaabb92ef56c4faa8f05487e9fcdf83f1053f1a22 (diff)
downloadphosphor-logging-f18bf836d206b1bc5b4fd849127a2e706eddf0aa.zip
phosphor-logging-f18bf836d206b1bc5b4fd849127a2e706eddf0aa.tar.gz
add .clang-format
Change-Id: I2c36b7886a25d0b235693b0776019d29608e1d52 Signed-off-by: Patrick Venture <venture@google.com>
-rw-r--r--.clang-format99
-rw-r--r--callouts/callout_test.cpp18
-rw-r--r--elog.cpp21
-rw-r--r--elog_entry.cpp18
-rw-r--r--elog_entry.hpp197
-rw-r--r--elog_meta.cpp36
-rw-r--r--elog_meta.hpp66
-rw-r--r--elog_serialize.cpp43
-rw-r--r--elog_serialize.hpp8
-rw-r--r--log_manager.cpp113
-rw-r--r--log_manager.hpp339
-rw-r--r--log_manager_main.cpp12
-rw-r--r--logging_test.cpp224
-rw-r--r--org.openbmc.Associations.cpp84
-rw-r--r--org/openbmc/Associations/server.hpp156
-rw-r--r--phosphor-logging/elog.hpp110
-rw-r--r--phosphor-logging/log.hpp81
-rw-r--r--phosphor-rsyslog-config/main.cpp12
-rw-r--r--phosphor-rsyslog-config/server-conf.cpp17
-rw-r--r--phosphor-rsyslog-config/server-conf.hpp172
-rw-r--r--phosphor-rsyslog-config/utils.hpp8
-rw-r--r--test/elog_errorwrap_test.cpp9
-rw-r--r--test/elog_errorwrap_test.hpp106
-rw-r--r--test/remote_logging_test_address.cpp6
-rw-r--r--test/remote_logging_test_config.cpp7
-rw-r--r--test/remote_logging_test_port.cpp6
-rw-r--r--test/remote_logging_tests.hpp66
-rw-r--r--test/serialization_test_path.cpp9
-rw-r--r--test/serialization_test_properties.cpp22
-rw-r--r--test/serialization_tests.hpp37
30 files changed, 1052 insertions, 1050 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..ea71ad6
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,99 @@
+---
+Language: Cpp
+# BasedOnStyle: LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: true
+ AfterEnum: true
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: true
+ AfterStruct: true
+ AfterUnion: true
+ BeforeCatch: true
+ BeforeElse: true
+ IndentBraces: false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: AfterColon
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+PointerAlignment: Left
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IncludeBlocks: Regroup
+IncludeCategories:
+ - Regex: '^[<"](gtest|gmock)'
+ Priority: 5
+ - Regex: '^"config.h"'
+ Priority: -1
+ - Regex: '^".*\.hpp"'
+ Priority: 1
+ - Regex: '^<.*\.h>'
+ Priority: 2
+ - Regex: '^<.*'
+ Priority: 3
+ - Regex: '.*'
+ Priority: 4
+IndentCaseLabels: true
+IndentWidth: 4
+IndentWrappedFunctionNames: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+ReflowComments: true
+SortIncludes: true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 4
+UseTab: Never
+...
+
diff --git a/callouts/callout_test.cpp b/callouts/callout_test.cpp
index 2eff6a0..729bbf5 100644
--- a/callouts/callout_test.cpp
+++ b/callouts/callout_test.cpp
@@ -1,14 +1,15 @@
+#include "elog_meta.hpp"
+
#include <iostream>
-#include <sdbusplus/exception.hpp>
-#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/elog-errors.hpp>
-#include "elog_meta.hpp"
+#include <phosphor-logging/elog.hpp>
+#include <sdbusplus/exception.hpp>
using namespace phosphor::logging;
int main(int argc, char** argv)
{
- if(2 != argc)
+ if (2 != argc)
{
std::cerr << "usage: callout-test <sysfs path>" << std::endl;
return -1;
@@ -17,10 +18,9 @@ int main(int argc, char** argv)
using namespace example::xyz::openbmc_project::Example::Elog;
try
{
- elog<TestCallout>(
- TestCallout::DEV_ADDR(0xDEADEAD),
- TestCallout::CALLOUT_ERRNO_TEST(0),
- TestCallout::CALLOUT_DEVICE_PATH_TEST(argv[1]));
+ elog<TestCallout>(TestCallout::DEV_ADDR(0xDEADEAD),
+ TestCallout::CALLOUT_ERRNO_TEST(0),
+ TestCallout::CALLOUT_DEVICE_PATH_TEST(argv[1]));
}
catch (TestCallout& e)
{
@@ -29,5 +29,3 @@ int main(int argc, char** argv)
return 0;
}
-
-
diff --git a/elog.cpp b/elog.cpp
index 363553b..5cefe81 100644
--- a/elog.cpp
+++ b/elog.cpp
@@ -1,4 +1,5 @@
#include "config.h"
+
#include <phosphor-logging/elog.hpp>
#include <stdexcept>
@@ -17,16 +18,14 @@ auto _prepareMsg(const char* funcName)
constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
- constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Logging.Internal.Manager");
+ constexpr auto IFACE_INTERNAL(
+ "xyz.openbmc_project.Logging.Internal.Manager");
// Transaction id is located at the end of the string separated by a period.
auto b = sdbusplus::bus::new_default();
- auto mapper = b.new_method_call(
- MAPPER_BUSNAME,
- MAPPER_PATH,
- MAPPER_INTERFACE,
- "GetObject");
+ auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
+ MAPPER_INTERFACE, "GetObject");
mapper.append(OBJ_INTERNAL, std::vector<std::string>({IFACE_INTERNAL}));
auto mapperResponseMsg = b.call(mapper);
@@ -43,12 +42,9 @@ auto _prepareMsg(const char* funcName)
}
const auto& host = mapperResponse.cbegin()->first;
- auto m = b.new_method_call(
- host.c_str(),
- OBJ_INTERNAL,
- IFACE_INTERNAL,
- funcName);
- return m;
+ auto m =
+ b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL, funcName);
+ return m;
}
void commit(const char* name)
@@ -78,4 +74,3 @@ void commit(std::string&& name)
} // namespace logging
} // namespace phosphor
-
diff --git a/elog_entry.cpp b/elog_entry.cpp
index 74fcc4b..04aa917 100644
--- a/elog_entry.cpp
+++ b/elog_entry.cpp
@@ -1,6 +1,7 @@
#include "elog_entry.hpp"
-#include "log_manager.hpp"
+
#include "elog_serialize.hpp"
+#include "log_manager.hpp"
namespace phosphor
{
@@ -16,15 +17,14 @@ void Entry::delete_()
bool Entry::resolved(bool value)
{
- auto current = sdbusplus::xyz::openbmc_project::
- Logging::server::Entry::resolved();
+ auto current =
+ sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved();
if (value != current)
{
- value ?
- associations({}) :
- associations(assocs);
- current = sdbusplus::xyz::openbmc_project::
- Logging::server::Entry::resolved(value);
+ value ? associations({}) : associations(assocs);
+ current =
+ sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved(
+ value);
serialize(*this);
}
@@ -32,4 +32,4 @@ bool Entry::resolved(bool value)
}
} // namespace logging
-} // namepsace phosphor
+} // namespace phosphor
diff --git a/elog_entry.hpp b/elog_entry.hpp
index 5ee8f5f..abcfe50 100644
--- a/elog_entry.hpp
+++ b/elog_entry.hpp
@@ -1,11 +1,12 @@
#pragma once
-#include <sdbusplus/bus.hpp>
-#include <sdbusplus/server/object.hpp>
+#include "org/openbmc/Associations/server.hpp"
#include "xyz/openbmc_project/Logging/Entry/server.hpp"
#include "xyz/openbmc_project/Object/Delete/server.hpp"
#include "xyz/openbmc_project/Software/Version/server.hpp"
-#include "org/openbmc/Associations/server.hpp"
+
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/server/object.hpp>
namespace phosphor
{
@@ -19,7 +20,7 @@ using EntryIfaces = sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::Software::server::Version>;
using AssociationList =
- std::vector<std::tuple<std::string, std::string, std::string>>;
+ std::vector<std::tuple<std::string, std::string, std::string>>;
namespace internal
{
@@ -34,104 +35,96 @@ class Manager;
*/
class Entry : public EntryIfaces
{
- public:
- Entry() = delete;
- Entry(const Entry&) = delete;
- Entry& operator=(const Entry&) = delete;
- Entry(Entry&&) = delete;
- Entry& operator=(Entry&&) = delete;
- virtual ~Entry() = default;
-
- /** @brief Constructor to put object onto bus at a dbus path.
- * Defer signal registration (pass true for deferSignal to the
- * base class) until after the properties are set.
- * @param[in] bus - Bus to attach to.
- * @param[in] path - Path to attach at.
- * @param[in] idErr - The error entry id.
- * @param[in] timestampErr - The commit timestamp.
- * @param[in] severityErr - The severity of the error.
- * @param[in] msgErr - The message of the error.
- * @param[in] additionalDataErr - The error metadata.
- * @param[in] objects - The list of associations.
- * @param[in] fwVersion - The BMC code version.
- * @param[in] parent - The error's parent.
- */
- Entry(sdbusplus::bus::bus& bus,
- const std::string& path,
- uint32_t idErr,
- uint64_t timestampErr,
- Level severityErr,
- std::string&& msgErr,
- std::vector<std::string>&& additionalDataErr,
- AssociationList&& objects,
- const std::string& fwVersion,
- internal::Manager& parent) :
- EntryIfaces(bus, path.c_str(), true),
- parent(parent)
- {
- id(idErr);
- severity(severityErr);
- timestamp(timestampErr);
- message(std::move(msgErr));
- additionalData(std::move(additionalDataErr));
- associations(std::move(objects));
- // Store a copy of associations in case we need to recreate
- assocs = associations();
- sdbusplus::xyz::openbmc_project::
- Logging::server::Entry::resolved(false);
-
- version(fwVersion);
- purpose(VersionPurpose::BMC);
-
- // Emit deferred signal.
- this->emit_object_added();
- };
-
- /** @brief Constructor that puts an "empty" error object on the bus,
- * with only the id property populated. Rest of the properties
- * to be set by the caller. Caller should emit the added signal.
- * @param[in] bus - Bus to attach to.
- * @param[in] path - Path to attach at.
- * @param[in] id - The error entry id.
- * @param[in] parent - The error's parent.
- */
- Entry(sdbusplus::bus::bus& bus,
- const std::string& path,
- uint32_t entryId,
- internal::Manager& parent) :
- EntryIfaces(bus, path.c_str(), true),
- parent(parent)
- {
- id(entryId);
- };
-
- /** @brief Set resolution status of the error.
- * @param[in] value - boolean indicating resolution
- * status (true = resolved)
- * @returns value of 'Resolved' property
- */
- bool resolved(bool value) override;
-
- using sdbusplus::xyz::openbmc_project::
- Logging::server::Entry::resolved;
-
- /** @brief Delete this d-bus object.
- */
- void delete_() override;
-
- /** @brief Severity level to check in cap.
- * @details Errors with severity lesser than this will be
- * considered as low priority and maximum ERROR_INFO_CAP
- * number errors of this category will be captured.
- */
- static constexpr auto sevLowerLimit = Entry::Level::Informational;
-
- private:
- /** @brief This entry's associations */
- AssociationList assocs = {};
-
- /** @brief This entry's parent */
- internal::Manager& parent;
+ public:
+ Entry() = delete;
+ Entry(const Entry&) = delete;
+ Entry& operator=(const Entry&) = delete;
+ Entry(Entry&&) = delete;
+ Entry& operator=(Entry&&) = delete;
+ virtual ~Entry() = default;
+
+ /** @brief Constructor to put object onto bus at a dbus path.
+ * Defer signal registration (pass true for deferSignal to the
+ * base class) until after the properties are set.
+ * @param[in] bus - Bus to attach to.
+ * @param[in] path - Path to attach at.
+ * @param[in] idErr - The error entry id.
+ * @param[in] timestampErr - The commit timestamp.
+ * @param[in] severityErr - The severity of the error.
+ * @param[in] msgErr - The message of the error.
+ * @param[in] additionalDataErr - The error metadata.
+ * @param[in] objects - The list of associations.
+ * @param[in] fwVersion - The BMC code version.
+ * @param[in] parent - The error's parent.
+ */
+ Entry(sdbusplus::bus::bus& bus, const std::string& path, uint32_t idErr,
+ uint64_t timestampErr, Level severityErr, std::string&& msgErr,
+ std::vector<std::string>&& additionalDataErr,
+ AssociationList&& objects, const std::string& fwVersion,
+ internal::Manager& parent) :
+ EntryIfaces(bus, path.c_str(), true),
+ parent(parent)
+ {
+ id(idErr);
+ severity(severityErr);
+ timestamp(timestampErr);
+ message(std::move(msgErr));
+ additionalData(std::move(additionalDataErr));
+ associations(std::move(objects));
+ // Store a copy of associations in case we need to recreate
+ assocs = associations();
+ sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved(
+ false);
+
+ version(fwVersion);
+ purpose(VersionPurpose::BMC);
+
+ // Emit deferred signal.
+ this->emit_object_added();
+ };
+
+ /** @brief Constructor that puts an "empty" error object on the bus,
+ * with only the id property populated. Rest of the properties
+ * to be set by the caller. Caller should emit the added signal.
+ * @param[in] bus - Bus to attach to.
+ * @param[in] path - Path to attach at.
+ * @param[in] id - The error entry id.
+ * @param[in] parent - The error's parent.
+ */
+ Entry(sdbusplus::bus::bus& bus, const std::string& path, uint32_t entryId,
+ internal::Manager& parent) :
+ EntryIfaces(bus, path.c_str(), true),
+ parent(parent)
+ {
+ id(entryId);
+ };
+
+ /** @brief Set resolution status of the error.
+ * @param[in] value - boolean indicating resolution
+ * status (true = resolved)
+ * @returns value of 'Resolved' property
+ */
+ bool resolved(bool value) override;
+
+ using sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved;
+
+ /** @brief Delete this d-bus object.
+ */
+ void delete_() override;
+
+ /** @brief Severity level to check in cap.
+ * @details Errors with severity lesser than this will be
+ * considered as low priority and maximum ERROR_INFO_CAP
+ * number errors of this category will be captured.
+ */
+ static constexpr auto sevLowerLimit = Entry::Level::Informational;
+
+ private:
+ /** @brief This entry's associations */
+ AssociationList assocs = {};
+
+ /** @brief This entry's parent */
+ internal::Manager& parent;
};
} // namespace logging
diff --git a/elog_meta.cpp b/elog_meta.cpp
index 514296e..98425d4 100644
--- a/elog_meta.cpp
+++ b/elog_meta.cpp
@@ -1,4 +1,5 @@
#include "config.h"
+
#include "elog_meta.hpp"
namespace phosphor
@@ -13,41 +14,34 @@ namespace associations
#if defined PROCESS_META
template <>
-void build<xyz::openbmc_project::Common::
- Callout::Device::CALLOUT_DEVICE_PATH>(
- const std::string& match,
- const std::vector<std::string>& data,
+void build<xyz::openbmc_project::Common::Callout::Device::CALLOUT_DEVICE_PATH>(
+ const std::string& match, const std::vector<std::string>& data,
AssociationList& list)
{
std::map<std::string, std::string> metadata;
parse(data, metadata);
auto iter = metadata.find(match);
- if(metadata.end() != iter)
+ if (metadata.end() != iter)
{
- auto comp = [](const auto& first, const auto& second)
- {
+ auto comp = [](const auto& first, const auto& second) {
return (strcmp(std::get<0>(first), second) < 0);
};
- auto callout = std::lower_bound(callouts.begin(),
- callouts.end(),
- (iter->second).c_str(),
- comp);
- if((callouts.end() != callout) &&
- !strcmp((iter->second).c_str(), std::get<0>(*callout)))
+ auto callout = std::lower_bound(callouts.begin(), callouts.end(),
+ (iter->second).c_str(), comp);
+ if ((callouts.end() != callout) &&
+ !strcmp((iter->second).c_str(), std::get<0>(*callout)))
{
- list.emplace_back(std::make_tuple(CALLOUT_FWD_ASSOCIATION,
- CALLOUT_REV_ASSOCIATION,
- std::string(INVENTORY_ROOT) +
- std::get<1>(*callout)));
+ list.emplace_back(std::make_tuple(
+ CALLOUT_FWD_ASSOCIATION, CALLOUT_REV_ASSOCIATION,
+ std::string(INVENTORY_ROOT) + std::get<1>(*callout)));
}
}
}
template <>
-void build<xyz::openbmc_project::Common::
- Callout::Inventory::CALLOUT_INVENTORY_PATH>(
- const std::string& match,
- const std::vector<std::string>& data,
+void build<
+ xyz::openbmc_project::Common::Callout::Inventory::CALLOUT_INVENTORY_PATH>(
+ const std::string& match, const std::vector<std::string>& data,
AssociationList& list)
{
std::map<std::string, std::string> metadata;
diff --git a/elog_meta.hpp b/elog_meta.hpp
index c0de428..0fe05f2 100644
--- a/elog_meta.hpp
+++ b/elog_meta.hpp
@@ -1,13 +1,14 @@
#pragma once
-#include <vector>
-#include <string>
-#include <tuple>
+#include "callouts-gen.hpp"
+#include "elog_entry.hpp"
+
#include <algorithm>
#include <cstring>
#include <phosphor-logging/elog-errors.hpp>
-#include "elog_entry.hpp"
-#include "callouts-gen.hpp"
+#include <string>
+#include <tuple>
+#include <vector>
namespace phosphor
{
@@ -21,8 +22,7 @@ using Metadata = std::string;
namespace associations
{
-using Type = void(const std::string&,
- const std::vector<std::string>&,
+using Type = void(const std::string&, const std::vector<std::string>&,
AssociationList& list);
/** @brief Pull out metadata name and value from the string
@@ -34,10 +34,10 @@ inline void parse(const std::vector<std::string>& data,
std::map<std::string, std::string>& metadata)
{
constexpr auto separator = '=';
- for(const auto& entry: data)
+ for (const auto& entry : data)
{
auto pos = entry.find(separator);
- if(std::string::npos != pos)
+ if (std::string::npos != pos)
{
auto key = entry.substr(0, entry.find(separator));
auto value = entry.substr(entry.find(separator) + 1);
@@ -54,8 +54,7 @@ inline void parse(const std::vector<std::string>& data,
* @param [out] list - list of error association objects
*/
template <typename M>
-void build(const std::string& match,
- const std::vector<std::string>& data,
+void build(const std::string& match, const std::vector<std::string>& data,
AssociationList& list) = delete;
// Example template specialization - we don't want to do anything
@@ -69,33 +68,28 @@ inline void build<TestErrorTwo::DEV_ID>(const std::string& match,
}
template <>
-inline void build<example::xyz::openbmc_project::
- Example::Device::Callout::CALLOUT_DEVICE_PATH_TEST>(
- const std::string& match,
- const std::vector<std::string>& data,
- AssociationList& list)
+inline void
+ build<example::xyz::openbmc_project::Example::Device::Callout::
+ CALLOUT_DEVICE_PATH_TEST>(const std::string& match,
+ const std::vector<std::string>& data,
+ AssociationList& list)
{
constexpr auto ROOT = "/xyz/openbmc_project/inventory";
std::map<std::string, std::string> metadata;
parse(data, metadata);
auto iter = metadata.find(match);
- if(metadata.end() != iter)
+ if (metadata.end() != iter)
{
- auto comp = [](const auto& first, const auto& second)
- {
+ auto comp = [](const auto& first, const auto& second) {
return (strcmp(std::get<0>(first), second) < 0);
};
- auto callout = std::lower_bound(callouts.begin(),
- callouts.end(),
- (iter->second).c_str(),
- comp);
- if((callouts.end() != callout) &&
- !strcmp((iter->second).c_str(), std::get<0>(*callout)))
+ auto callout = std::lower_bound(callouts.begin(), callouts.end(),
+ (iter->second).c_str(), comp);
+ if ((callouts.end() != callout) &&
+ !strcmp((iter->second).c_str(), std::get<0>(*callout)))
{
- list.push_back(std::make_tuple("callout",
- "fault",
- std::string(ROOT) +
- std::get<1>(*callout)));
+ list.push_back(std::make_tuple(
+ "callout", "fault", std::string(ROOT) + std::get<1>(*callout)));
}
}
}
@@ -107,22 +101,18 @@ inline void build<example::xyz::openbmc_project::
#if defined PROCESS_META
template <>
-void build<xyz::openbmc_project::Common::
- Callout::Device::CALLOUT_DEVICE_PATH>(
- const std::string& match,
- const std::vector<std::string>& data,
+void build<xyz::openbmc_project::Common::Callout::Device::CALLOUT_DEVICE_PATH>(
+ const std::string& match, const std::vector<std::string>& data,
AssociationList& list);
template <>
-void build<xyz::openbmc_project::Common::
- Callout::Inventory::CALLOUT_INVENTORY_PATH>(
- const std::string& match,
- const std::vector<std::string>& data,
+void build<
+ xyz::openbmc_project::Common::Callout::Inventory::CALLOUT_INVENTORY_PATH>(
+ const std::string& match, const std::vector<std::string>& data,
AssociationList& list);
#endif // PROCESS_META
-
} // namespace associations
} // namespace metadata
} // namespace logging
diff --git a/elog_serialize.cpp b/elog_serialize.cpp
index d807a93..72534a4 100644
--- a/elog_serialize.cpp
+++ b/elog_serialize.cpp
@@ -1,12 +1,13 @@
+#include "config.h"
+
+#include "elog_serialize.hpp"
+
+#include <cereal/archives/binary.hpp>
#include <cereal/types/string.hpp>
-#include <cereal/types/vector.hpp>
#include <cereal/types/tuple.hpp>
-#include <cereal/archives/binary.hpp>
+#include <cereal/types/vector.hpp>
#include <fstream>
-
-#include "elog_serialize.hpp"
#include <phosphor-logging/log.hpp>
-#include "config.h"
// Register class version
// From cereal documentation;
@@ -25,12 +26,11 @@ namespace logging
* @param[in] version - Class version that enables handling
* a serialized data across code levels
*/
-template<class Archive>
+template <class Archive>
void save(Archive& a, const Entry& e, const std::uint32_t version)
{
- a(e.id(), e.severity(), e.timestamp(),
- e.message(), e.additionalData(), e.associations(), e.resolved(),
- e.version());
+ a(e.id(), e.severity(), e.timestamp(), e.message(), e.additionalData(),
+ e.associations(), e.resolved(), e.version());
}
/** @brief Function required by Cereal to perform deserialization.
@@ -40,11 +40,10 @@ void save(Archive& a, const Entry& e, const std::uint32_t version)
* @param[in] version - Class version that enables handling
* a serialized data across code levels
*/
-template<class Archive>
+template <class Archive>
void load(Archive& a, Entry& e, const std::uint32_t version)
{
- using namespace
- sdbusplus::xyz::openbmc_project::Logging::server;
+ using namespace sdbusplus::xyz::openbmc_project::Logging::server;
uint32_t id{};
Entry::Level severity{};
@@ -57,13 +56,13 @@ void load(Archive& a, Entry& e, const std::uint32_t version)
if (version < std::stoul(FIRST_CEREAL_CLASS_VERSION_WITH_FWLEVEL))
{
- a(id, severity, timestamp, message,
- additionalData, associations, resolved);
+ a(id, severity, timestamp, message, additionalData, associations,
+ resolved);
}
else
{
- a(id, severity, timestamp, message,
- additionalData, associations, resolved, fwVersion);
+ a(id, severity, timestamp, message, additionalData, associations,
+ resolved, fwVersion);
}
e.id(id);
@@ -71,12 +70,12 @@ void load(Archive& a, Entry& e, const std::uint32_t version)
e.timestamp(timestamp);
e.message(message);
e.additionalData(additionalData);
- e.sdbusplus::xyz::openbmc_project::
- Logging::server::Entry::resolved(resolved);
+ e.sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved(
+ resolved);
e.associations(associations);
e.version(fwVersion);
- e.purpose(sdbusplus::xyz::openbmc_project::Software::
- server::Version::VersionPurpose::BMC);
+ e.purpose(sdbusplus::xyz::openbmc_project::Software::server::Version::
+ VersionPurpose::BMC);
}
fs::path serialize(const Entry& e, const fs::path& dir)
@@ -101,13 +100,13 @@ bool deserialize(const fs::path& path, Entry& e)
}
return false;
}
- catch(cereal::Exception& e)
+ catch (cereal::Exception& e)
{
log<level::ERR>(e.what());
fs::remove(path);
return false;
}
- catch(const std::length_error& e)
+ catch (const std::length_error& e)
{
// Running into: USCiLab/cereal#192
// This may be indicating some other issue in the
diff --git a/elog_serialize.hpp b/elog_serialize.hpp
index f7f3bd9..eaa47d4 100644
--- a/elog_serialize.hpp
+++ b/elog_serialize.hpp
@@ -1,10 +1,12 @@
#pragma once
+#include "config.h"
+
+#include "elog_entry.hpp"
+
+#include <experimental/filesystem>
#include <string>
#include <vector>
-#include <experimental/filesystem>
-#include "elog_entry.hpp"
-#include "config.h"
namespace phosphor
{
diff --git a/log_manager.cpp b/log_manager.cpp
index ca48210..46ada75 100644
--- a/log_manager.cpp
+++ b/log_manager.cpp
@@ -1,28 +1,33 @@
-#include <fstream>
-#include <future>
-#include <iostream>
-#include <chrono>
-#include <cstdio>
+#include "config.h"
+
+#include "log_manager.hpp"
+
+#include "elog_entry.hpp"
+#include "elog_meta.hpp"
+#include "elog_serialize.hpp"
+
#include <poll.h>
-#include <set>
-#include <string>
-#include <vector>
-#include <sdbusplus/vtable.hpp>
#include <sys/inotify.h>
#include <systemd/sd-bus.h>
#include <systemd/sd-journal.h>
#include <unistd.h>
-#include "config.h"
-#include "elog_entry.hpp"
+
+#include <chrono>
+#include <cstdio>
+#include <fstream>
+#include <future>
+#include <iostream>
#include <phosphor-logging/log.hpp>
-#include "log_manager.hpp"
-#include "elog_meta.hpp"
-#include "elog_serialize.hpp"
+#include <sdbusplus/vtable.hpp>
+#include <set>
+#include <string>
+#include <vector>
using namespace phosphor::logging;
using namespace std::chrono;
extern const std::map<metadata::Metadata,
- std::function<metadata::associations::Type>> meta;
+ std::function<metadata::associations::Type>>
+ meta;
namespace phosphor
{
@@ -92,12 +97,13 @@ void Manager::_commit(uint64_t transactionId, std::string&& errMsg,
// Flush all the pending log messages into the journal
journalSync();
- sd_journal *j = nullptr;
+ sd_journal* j = nullptr;
int rc = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
if (rc < 0)
{
- logging::log<logging::level::ERR>("Failed to open journal",
- logging::entry("DESCRIPTION=%s", strerror(-rc)));
+ logging::log<logging::level::ERR>(
+ "Failed to open journal",
+ logging::entry("DESCRIPTION=%s", strerror(-rc)));
return;
}
@@ -109,7 +115,7 @@ void Manager::_commit(uint64_t transactionId, std::string&& errMsg,
metalist.insert(metamap->second.begin(), metamap->second.end());
}
- //Add _PID field information in AdditionalData.
+ // Add _PID field information in AdditionalData.
metalist.insert("_PID");
std::vector<std::string> additionalData;
@@ -118,12 +124,12 @@ void Manager::_commit(uint64_t transactionId, std::string&& errMsg,
// The result from the sd_journal_get_data() is of the form VARIABLE=value.
SD_JOURNAL_FOREACH_BACKWARDS(j)
{
- const char *data = nullptr;
+ const char* data = nullptr;
size_t length = 0;
// Look for the transaction id metadata variable
- rc = sd_journal_get_data(j, transactionIdVar, (const void **)&data,
- &length);
+ rc = sd_journal_get_data(j, transactionIdVar, (const void**)&data,
+ &length);
if (rc < 0)
{
// This journal entry does not have the TRANSACTION_ID
@@ -140,8 +146,7 @@ void Manager::_commit(uint64_t transactionId, std::string&& errMsg,
// 'data + transactionIdVarOffset' will be in the form of '1234'.
// 'length - transactionIdVarOffset' will be the length of '1234'.
if ((length <= (transactionIdVarOffset)) ||
- (transactionIdStr.compare(0,
- transactionIdStr.size(),
+ (transactionIdStr.compare(0, transactionIdStr.size(),
data + transactionIdVarOffset,
length - transactionIdVarOffset) != 0))
{
@@ -153,8 +158,8 @@ void Manager::_commit(uint64_t transactionId, std::string&& errMsg,
// Search for all metadata variables in the current journal entry.
for (auto i = metalist.cbegin(); i != metalist.cend();)
{
- rc = sd_journal_get_data(j, (*i).c_str(),
- (const void **)&data, &length);
+ rc = sd_journal_get_data(j, (*i).c_str(), (const void**)&data,
+ &length);
if (rc < 0)
{
// Metadata variable not found, check next metadata variable.
@@ -177,8 +182,9 @@ void Manager::_commit(uint64_t transactionId, std::string&& errMsg,
// Not all the metadata variables were found in the journal.
for (auto& metaVarStr : metalist)
{
- logging::log<logging::level::INFO>("Failed to find metadata",
- logging::entry("META_FIELD=%s", metaVarStr.c_str()));
+ logging::log<logging::level::INFO>(
+ "Failed to find metadata",
+ logging::entry("META_FIELD=%s", metaVarStr.c_str()));
}
}
@@ -195,24 +201,18 @@ void Manager::_commit(uint64_t transactionId, std::string&& errMsg,
realErrors.push_back(entryId);
}
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
- std::chrono::system_clock::now().time_since_epoch()).count();
- auto objPath = std::string(OBJ_ENTRY) + '/' +
- std::to_string(entryId);
+ std::chrono::system_clock::now().time_since_epoch())
+ .count();
+ auto objPath = std::string(OBJ_ENTRY) + '/' + std::to_string(entryId);
- AssociationList objects {};
+ AssociationList objects{};
processMetadata(errMsg, additionalData, objects);
- auto e = std::make_unique<Entry>(
- busLog,
- objPath,
- entryId,
- ms, // Milliseconds since 1970
- errLvl,
- std::move(errMsg),
- std::move(additionalData),
- std::move(objects),
- fwVersion,
- *this);
+ auto e = std::make_unique<Entry>(busLog, objPath, entryId,
+ ms, // Milliseconds since 1970
+ errLvl, std::move(errMsg),
+ std::move(additionalData),
+ std::move(objects), fwVersion, *this);
serialize(*e);
entries.insert(std::make_pair(entryId, std::move(e)));
}
@@ -223,14 +223,14 @@ void Manager::processMetadata(const std::string& errorName,
{
// additionalData is a list of "metadata=value"
constexpr auto separator = '=';
- for(const auto& entry: additionalData)
+ for (const auto& entry : additionalData)
{
auto found = entry.find(separator);
- if(std::string::npos != found)
+ if (std::string::npos != found)
{
auto metadata = entry.substr(0, found);
auto iter = meta.find(metadata);
- if(meta.end() != iter)
+ if (meta.end() != iter)
{
(iter->second)(metadata, additionalData, objects);
}
@@ -241,15 +241,14 @@ void Manager::processMetadata(const std::string& errorName,
void Manager::erase(uint32_t entryId)
{
auto entry = entries.find(entryId);
- if(entries.end() != entry)
+ if (entries.end() != entry)
{
// Delete the persistent representation of this error.
fs::path errorPath(ERRLOG_PERSIST_PATH);
errorPath /= std::to_string(entryId);
fs::remove(errorPath);
- auto removeId = [](std::list<uint32_t>& ids , uint32_t id)
- {
+ auto removeId = [](std::list<uint32_t>& ids, uint32_t id) {
auto it = std::find(ids.begin(), ids.end(), id);
if (it != ids.end())
{
@@ -269,14 +268,13 @@ void Manager::erase(uint32_t entryId)
else
{
logging::log<level::ERR>("Invalid entry ID to delete",
- logging::entry("ID=%d", entryId));
+ logging::entry("ID=%d", entryId));
}
}
void Manager::restore()
{
- auto sanity = [](const auto& id, const auto& restoredId)
- {
+ auto sanity = [](const auto& id, const auto& restoredId) {
return id == restoredId;
};
std::vector<uint32_t> errorIds;
@@ -287,18 +285,15 @@ void Manager::restore()
return;
}
- for(auto& file: fs::directory_iterator(dir))
+ for (auto& file : fs::directory_iterator(dir))
{
auto id = file.path().filename().c_str();
auto idNum = std::stol(id);
auto e = std::make_unique<Entry>(
- busLog,
- std::string(OBJ_ENTRY) + '/' + id,
- idNum,
- *this);
+ busLog, std::string(OBJ_ENTRY) + '/' + id, idNum, *this);
if (deserialize(file.path(), *e))
{
- //validate the restored error entry id
+ // validate the restored error entry id
if (sanity(static_cast<uint32_t>(idNum), e->id()))
{
e->emit_object_added();
@@ -490,4 +485,4 @@ std::string Manager::readFWVersion()
} // namespace internal
} // namespace logging
-} // namepsace phosphor
+} // namespace phosphor
diff --git a/log_manager.hpp b/log_manager.hpp
index 3da450d..864de1a 100644
--- a/log_manager.hpp
+++ b/log_manager.hpp
@@ -1,22 +1,23 @@
#pragma once
-#include <list>
-#include <sdbusplus/bus.hpp>
-#include <phosphor-logging/log.hpp>
#include "elog_entry.hpp"
-#include "xyz/openbmc_project/Logging/Internal/Manager/server.hpp"
#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
+#include "xyz/openbmc_project/Logging/Internal/Manager/server.hpp"
+
+#include <list>
+#include <phosphor-logging/log.hpp>
+#include <sdbusplus/bus.hpp>
namespace phosphor
{
namespace logging
{
-extern const std::map<std::string,std::vector<std::string>> g_errMetaMap;
-extern const std::map<std::string,level> g_errLevelMap;
+extern const std::map<std::string, std::vector<std::string>> g_errMetaMap;
+extern const std::map<std::string, level> g_errLevelMap;
-using DeleteAllIface = sdbusplus::server::object::object <
- sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll >;
+using DeleteAllIface = sdbusplus::server::object::object<
+ sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
namespace details
{
@@ -39,142 +40,140 @@ namespace internal
*/
class Manager : public details::ServerObject<details::ManagerIface>
{
- public:
- Manager() = delete;
- Manager(const Manager&) = delete;
- Manager& operator=(const Manager&) = delete;
- Manager(Manager&&) = delete;
- Manager& operator=(Manager&&) = delete;
- virtual ~Manager() = default;
-
- /** @brief Constructor to put object onto bus at a dbus path.
- * @param[in] bus - Bus to attach to.
- * @param[in] path - Path to attach at.
- */
- Manager(sdbusplus::bus::bus& bus, const char* objPath) :
- details::ServerObject<details::ManagerIface>(bus, objPath),
- busLog(bus),
- entryId(0),
- fwVersion(readFWVersion()) {};
-
- /*
- * @fn commit()
- * @brief sd_bus Commit method implementation callback.
- * @details Create an error/event log based on transaction id and
- * error message.
- * @param[in] transactionId - Unique identifier of the journal entries
- * to be committed.
- * @param[in] errMsg - The error exception message associated with the
- * error log to be committed.
- */
- void commit(uint64_t transactionId, std::string errMsg) override;
-
- /*
- * @fn commit()
- * @brief sd_bus CommitWithLvl method implementation callback.
- * @details Create an error/event log based on transaction id and
- * error message.
- * @param[in] transactionId - Unique identifier of the journal entries
- * to be committed.
- * @param[in] errMsg - The error exception message associated with the
- * error log to be committed.
- * @param[in] errLvl - level of the error
- */
- void commitWithLvl(uint64_t transactionId, std::string errMsg,
- uint32_t errLvl) override;
-
- /** @brief Erase specified entry d-bus object
- *
- * @param[in] entryId - unique identifier of the entry
- */
- void erase(uint32_t entryId);
-
- /** @brief Construct error d-bus objects from their persisted
- * representations.
- */
- void restore();
-
- /** @brief Erase all error log entries
- *
- */
- void eraseAll()
+ public:
+ Manager() = delete;
+ Manager(const Manager&) = delete;
+ Manager& operator=(const Manager&) = delete;
+ Manager(Manager&&) = delete;
+ Manager& operator=(Manager&&) = delete;
+ virtual ~Manager() = default;
+
+ /** @brief Constructor to put object onto bus at a dbus path.
+ * @param[in] bus - Bus to attach to.
+ * @param[in] path - Path to attach at.
+ */
+ Manager(sdbusplus::bus::bus& bus, const char* objPath) :
+ details::ServerObject<details::ManagerIface>(bus, objPath), busLog(bus),
+ entryId(0), fwVersion(readFWVersion()){};
+
+ /*
+ * @fn commit()
+ * @brief sd_bus Commit method implementation callback.
+ * @details Create an error/event log based on transaction id and
+ * error message.
+ * @param[in] transactionId - Unique identifier of the journal entries
+ * to be committed.
+ * @param[in] errMsg - The error exception message associated with the
+ * error log to be committed.
+ */
+ void commit(uint64_t transactionId, std::string errMsg) override;
+
+ /*
+ * @fn commit()
+ * @brief sd_bus CommitWithLvl method implementation callback.
+ * @details Create an error/event log based on transaction id and
+ * error message.
+ * @param[in] transactionId - Unique identifier of the journal entries
+ * to be committed.
+ * @param[in] errMsg - The error exception message associated with the
+ * error log to be committed.
+ * @param[in] errLvl - level of the error
+ */
+ void commitWithLvl(uint64_t transactionId, std::string errMsg,
+ uint32_t errLvl) override;
+
+ /** @brief Erase specified entry d-bus object
+ *
+ * @param[in] entryId - unique identifier of the entry
+ */
+ void erase(uint32_t entryId);
+
+ /** @brief Construct error d-bus objects from their persisted
+ * representations.
+ */
+ void restore();
+
+ /** @brief Erase all error log entries
+ *
+ */
+ void eraseAll()
+ {
+ auto iter = entries.begin();
+ while (iter != entries.end())
{
- auto iter = entries.begin();
- while (iter != entries.end())
- {
- auto entry = iter->first;
- ++iter;
- erase(entry);
- }
+ auto entry = iter->first;
+ ++iter;
+ erase(entry);
}
-
- /** @brief Returns the count of high severity errors
- *
- * @return int - count of real errors
- */
- int getRealErrSize();
-
- /** @brief Returns the count of Info errors
- *
- * @return int - count of info errors
- */
- int getInfoErrSize();
-
- private:
- /*
- * @fn _commit()
- * @brief commit() helper
- * @param[in] transactionId - Unique identifier of the journal entries
- * to be committed.
- * @param[in] errMsg - The error exception message associated with the
- * error log to be committed.
- * @param[in] errLvl - level of the error
- */
- void _commit(uint64_t transactionId, std::string&& errMsg,
- Entry::Level errLvl);
-
- /** @brief Call metadata handler(s), if any. Handlers may create
- * associations.
- * @param[in] errorName - name of the error
- * @param[in] additionalData - list of metadata (in key=value format)
- * @param[out] objects - list of error's association objects
- */
- void processMetadata(const std::string& errorName,
- const std::vector<std::string>& additionalData,
- AssociationList& objects) const;
-
- /** @brief Synchronize unwritten journal messages to disk.
- * @details This is the same implementation as the systemd command
- * "journalctl --sync".
- */
- void journalSync();
-
- /** @brief Reads the BMC code level
- *
- * @return std::string - the version string
- */
- static std::string readFWVersion();
-
- /** @brief Persistent sdbusplus DBus bus connection. */
- sdbusplus::bus::bus& busLog;
-
- /** @brief Persistent map of Entry dbus objects and their ID */
- std::map<uint32_t, std::unique_ptr<Entry>> entries;
-
- /** @brief List of error ids for high severity errors */
- std::list<uint32_t> realErrors;
-
- /** @brief List of error ids for Info(and below) severity */
- std::list<uint32_t> infoErrors;
-
- /** @brief Id of last error log entry */
- uint32_t entryId;
-
- /** @brief The BMC firmware version */
- const std::string fwVersion;
+ }
+
+ /** @brief Returns the count of high severity errors
+ *
+ * @return int - count of real errors
+ */
+ int getRealErrSize();
+
+ /** @brief Returns the count of Info errors
+ *
+ * @return int - count of info errors
+ */
+ int getInfoErrSize();
+
+ private:
+ /*
+ * @fn _commit()
+ * @brief commit() helper
+ * @param[in] transactionId - Unique identifier of the journal entries
+ * to be committed.
+ * @param[in] errMsg - The error exception message associated with the
+ * error log to be committed.
+ * @param[in] errLvl - level of the error
+ */
+ void _commit(uint64_t transactionId, std::string&& errMsg,
+ Entry::Level errLvl);
+
+ /** @brief Call metadata handler(s), if any. Handlers may create
+ * associations.
+ * @param[in] errorName - name of the error
+ * @param[in] additionalData - list of metadata (in key=value format)
+ * @param[out] objects - list of error's association objects
+ */
+ void processMetadata(const std::string& errorName,
+ const std::vector<std::string>& additionalData,
+ AssociationList& objects) const;
+
+ /** @brief Synchronize unwritten journal messages to disk.
+ * @details This is the same implementation as the systemd command
+ * "journalctl --sync".
+ */
+ void journalSync();
+
+ /** @brief Reads the BMC code level
+ *
+ * @return std::string - the version string
+ */
+ static std::string readFWVersion();
+
+ /** @brief Persistent sdbusplus DBus bus connection. */
+ sdbusplus::bus::bus& busLog;
+
+ /** @brief Persistent map of Entry dbus objects and their ID */
+ std::map<uint32_t, std::unique_ptr<Entry>> entries;
+
+ /** @brief List of error ids for high severity errors */
+ std::list<uint32_t> realErrors;
+
+ /** @brief List of error ids for Info(and below) severity */
+ std::list<uint32_t> infoErrors;
+
+ /** @brief Id of last error log entry */
+ uint32_t entryId;
+
+ /** @brief The BMC firmware version */
+ const std::string fwVersion;
};
-} //namespace internal
+} // namespace internal
/** @class Manager
* @brief Implementation for delete all error log entries.
@@ -183,36 +182,36 @@ class Manager : public details::ServerObject<details::ManagerIface>
*/
class Manager : public DeleteAllIface
{
- public:
- Manager() = delete;
- Manager(const Manager&) = delete;
- Manager& operator=(const Manager&) = delete;
- Manager(Manager&&) = delete;
- Manager& operator=(Manager&&) = delete;
- virtual ~Manager() = default;
-
- /** @brief Constructor to put object onto bus at a dbus path.
- * Defer signal registration (pass true for deferSignal to the
- * base class) until after the properties are set.
- * @param[in] bus - Bus to attach to.
- * @param[in] path - Path to attach at.
- * @param[in] manager - Reference to internal manager object.
- */
- Manager(sdbusplus::bus::bus& bus,
- const std::string& path,
- internal::Manager& manager) :
- DeleteAllIface(bus, path.c_str(), true),
- manager(manager) {};
-
- /** @brief Delete all d-bus objects.
- */
- void deleteAll()
- {
- manager.eraseAll();
- }
- private:
- /** @brief This is a reference to manager object */
- internal::Manager& manager;
+ public:
+ Manager() = delete;
+ Manager(const Manager&) = delete;
+ Manager& operator=(const Manager&) = delete;
+ Manager(Manager&&) = delete;
+ Manager& operator=(Manager&&) = delete;
+ virtual ~Manager() = default;
+
+ /** @brief Constructor to put object onto bus at a dbus path.
+ * Defer signal registration (pass true for deferSignal to the
+ * base class) until after the properties are set.
+ * @param[in] bus - Bus to attach to.
+ * @param[in] path - Path to attach at.
+ * @param[in] manager - Reference to internal manager object.
+ */
+ Manager(sdbusplus::bus::bus& bus, const std::string& path,
+ internal::Manager& manager) :
+ DeleteAllIface(bus, path.c_str(), true),
+ manager(manager){};
+
+ /** @brief Delete all d-bus objects.
+ */
+ void deleteAll()
+ {
+ manager.eraseAll();
+ }
+
+ private:
+ /** @brief This is a reference to manager object */
+ internal::Manager& manager;
};
} // namespace logging
diff --git a/log_manager_main.cpp b/log_manager_main.cpp
index f06a79d..48a7dee 100644
--- a/log_manager_main.cpp
+++ b/log_manager_main.cpp
@@ -1,10 +1,12 @@
-#include <sdbusplus/bus.hpp>
-#include <sdbusplus/server/manager.hpp>
-#include <experimental/filesystem>
#include "config.h"
+
#include "log_manager.hpp"
-int main(int argc, char *argv[])
+#include <experimental/filesystem>
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/server/manager.hpp>
+
+int main(int argc, char* argv[])
{
auto bus = sdbusplus::bus::new_default();
@@ -23,7 +25,7 @@ int main(int argc, char *argv[])
bus.request_name(BUSNAME_LOGGING);
- while(true)
+ while (true)
{
bus.process_discard();
bus.wait();
diff --git a/logging_test.cpp b/logging_test.cpp
index 0ad10b7..3a144f8 100644
--- a/logging_test.cpp
+++ b/logging_test.cpp
@@ -1,18 +1,19 @@
// A basic unit test that runs on a BMC (qemu or hardware)
#include <getopt.h>
-#include <iostream>
#include <systemd/sd-journal.h>
-#include <sstream>
-#include <sdbusplus/exception.hpp>
+
+#include <iostream>
+#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/log.hpp>
-#include <phosphor-logging/elog-errors.hpp>
+#include <sdbusplus/exception.hpp>
+#include <sstream>
using namespace phosphor;
using namespace logging;
-const char *usage = "Usage: logging-test [OPTION] \n\n\
+const char* usage = "Usage: logging-test [OPTION] \n\n\
Options: \n\
[NONE] Default test case. \n\
-h, --help Display this usage text. \n\
@@ -21,29 +22,31 @@ Valid errors to commit: \n\
AutoTestSimple, AutoTestCreateAndCommit\n";
// validate the journal metadata equals the input value
-int validate_journal(const char *i_entry, const char *i_value)
+int validate_journal(const char* i_entry, const char* i_value)
{
- sd_journal *journal;
- const void *data;
+ sd_journal* journal;
+ const void* data;
size_t l;
int rc;
bool validated = false;
rc = sd_journal_open(&journal, SD_JOURNAL_LOCAL_ONLY);
- if (rc < 0) {
- std::cerr << "Failed to open journal: " << strerror(-rc) << "\n";
- return 1;
+ if (rc < 0)
+ {
+ std::cerr << "Failed to open journal: " << strerror(-rc) << "\n";
+ return 1;
}
rc = sd_journal_query_unique(journal, i_entry);
- if (rc < 0) {
- std::cerr << "Failed to query journal: " << strerror(-rc) << "\n";
- return 1;
+ if (rc < 0)
+ {
+ std::cerr << "Failed to query journal: " << strerror(-rc) << "\n";
+ return 1;
}
SD_JOURNAL_FOREACH_UNIQUE(journal, data, l)
{
std::string journ_entry((const char*)data);
std::cout << journ_entry << "\n";
- if(journ_entry.find(i_value) != std::string::npos)
+ if (journ_entry.find(i_value) != std::string::npos)
{
std::cout << "We found it!\n";
validated = true;
@@ -54,10 +57,11 @@ int validate_journal(const char *i_entry, const char *i_value)
sd_journal_close(journal);
rc = (validated) ? 0 : 1;
- if(rc)
+ if (rc)
{
std::cerr << "Failed to find " << i_entry << " with value " << i_value
- <<" in journal!" << "\n";
+ << " in journal!"
+ << "\n";
}
return rc;
@@ -69,35 +73,36 @@ int elog_test()
log<level::DEBUG>("Basic phosphor logging test");
// TEST 2 - Log with metadata field
- const char *file_name = "phosphor_logging_test.txt";
+ const char* file_name = "phosphor_logging_test.txt";
int number = 0xFEFE;
- log<level::DEBUG>("phosphor logging test with attribute",
- entry("FILE_NAME_WITH_NUM_TEST=%s_%x", file_name, number));
+ log<level::DEBUG>(
+ "phosphor logging test with attribute",
+ entry("FILE_NAME_WITH_NUM_TEST=%s_%x", file_name, number));
// Now read back and verify our data made it into the journal
int rc = validate_journal("FILE_NAME_WITH_NUM_TEST",
"phosphor_logging_test.txt_fefe");
- if(rc)
- return(rc);
+ if (rc)
+ return (rc);
// TEST 3 - Create error log with 2 meta data fields (rvalue and lvalue)
number = 0x1234;
- const char *test_string = "/tmp/test_string/";
+ const char* test_string = "/tmp/test_string/";
try
{
elog<example::xyz::openbmc_project::Example::Elog::TestErrorOne>(
- example::xyz::openbmc_project::Example::Elog::
- TestErrorOne::ERRNUM(number),
- example::xyz::openbmc_project::Example::Elog::
- TestErrorOne::FILE_PATH(test_string),
- example::xyz::openbmc_project::Example::Elog::
- TestErrorOne::FILE_NAME("elog_test_3.txt"),
- example::xyz::openbmc_project::Example::Elog::
- TestErrorTwo::DEV_ADDR(0xDEADDEAD),
- example::xyz::openbmc_project::Example::Elog::
- TestErrorTwo::DEV_ID(100),
- example::xyz::openbmc_project::Example::Elog::
- TestErrorTwo::DEV_NAME("test case 3"));
+ example::xyz::openbmc_project::Example::Elog::TestErrorOne::ERRNUM(
+ number),
+ example::xyz::openbmc_project::Example::Elog::TestErrorOne::
+ FILE_PATH(test_string),
+ example::xyz::openbmc_project::Example::Elog::TestErrorOne::
+ FILE_NAME("elog_test_3.txt"),
+ example::xyz::openbmc_project::Example::Elog::TestErrorTwo::
+ DEV_ADDR(0xDEADDEAD),
+ example::xyz::openbmc_project::Example::Elog::TestErrorTwo::DEV_ID(
+ 100),
+ example::xyz::openbmc_project::Example::Elog::TestErrorTwo::
+ DEV_NAME("test case 3"));
}
catch (example::xyz::openbmc_project::Example::Elog::TestErrorOne& e)
{
@@ -112,44 +117,39 @@ int elog_test()
stream << std::hex << number;
rc = validate_journal(TestErrorOne::ERRNUM::str_short,
std::string(stream.str()).c_str());
- if(rc)
- return(rc);
-
- rc = validate_journal(TestErrorOne::FILE_PATH::str_short,
- test_string);
- if(rc)
- return(rc);
-
- rc = validate_journal(TestErrorOne::FILE_NAME::str_short,
- "elog_test_3.txt");
- if(rc)
- return(rc);
-
- rc = validate_journal(TestErrorTwo::DEV_ADDR::str_short,
- "0xDEADDEAD");
- if(rc)
- return(rc);
-
- rc = validate_journal(TestErrorTwo::DEV_ID::str_short,
- "100");
- if(rc)
- return(rc);
-
- rc = validate_journal(TestErrorTwo::DEV_NAME::str_short,
- "test case 3");
- if(rc)
- return(rc);
+ if (rc)
+ return (rc);
+
+ rc = validate_journal(TestErrorOne::FILE_PATH::str_short, test_string);
+ if (rc)
+ return (rc);
+
+ rc =
+ validate_journal(TestErrorOne::FILE_NAME::str_short, "elog_test_3.txt");
+ if (rc)
+ return (rc);
+
+ rc = validate_journal(TestErrorTwo::DEV_ADDR::str_short, "0xDEADDEAD");
+ if (rc)
+ return (rc);
+
+ rc = validate_journal(TestErrorTwo::DEV_ID::str_short, "100");
+ if (rc)
+ return (rc);
+
+ rc = validate_journal(TestErrorTwo::DEV_NAME::str_short, "test case 3");
+ if (rc)
+ return (rc);
// TEST 4 - Create error log with previous entry use
number = 0x9876;
try
{
- elog<TestErrorOne>(TestErrorOne::ERRNUM(number),
- prev_entry<TestErrorOne::FILE_PATH>(),
- TestErrorOne::FILE_NAME("elog_test_4.txt"),
- TestErrorTwo::DEV_ADDR(0xDEADDEAD),
- TestErrorTwo::DEV_ID(100),
- TestErrorTwo::DEV_NAME("test case 4"));
+ elog<TestErrorOne>(
+ TestErrorOne::ERRNUM(number), prev_entry<TestErrorOne::FILE_PATH>(),
+ TestErrorOne::FILE_NAME("elog_test_4.txt"),
+ TestErrorTwo::DEV_ADDR(0xDEADDEAD), TestErrorTwo::DEV_ID(100),
+ TestErrorTwo::DEV_NAME("test case 4"));
}
catch (sdbusplus::exception_t& e)
{
@@ -161,62 +161,56 @@ int elog_test()
stream << std::hex << number;
rc = validate_journal(TestErrorOne::ERRNUM::str_short,
std::string(stream.str()).c_str());
- if(rc)
- return(rc);
+ if (rc)
+ return (rc);
// This should just be equal to what we put in test 3
- rc = validate_journal(TestErrorOne::FILE_PATH::str_short,
- test_string);
- if(rc)
- return(rc);
-
- rc = validate_journal(TestErrorOne::FILE_NAME::str_short,
- "elog_test_4.txt");
- if(rc)
- return(rc);
-
- rc = validate_journal(TestErrorTwo::DEV_ADDR::str_short,
- "0xDEADDEAD");
- if(rc)
- return(rc);
-
- rc = validate_journal(TestErrorTwo::DEV_ID::str_short,
- "100");
- if(rc)
- return(rc);
-
- rc = validate_journal(TestErrorTwo::DEV_NAME::str_short,
- "test case 4");
- if(rc)
- return(rc);
+ rc = validate_journal(TestErrorOne::FILE_PATH::str_short, test_string);
+ if (rc)
+ return (rc);
+
+ rc =
+ validate_journal(TestErrorOne::FILE_NAME::str_short, "elog_test_4.txt");
+ if (rc)
+ return (rc);
+
+ rc = validate_journal(TestErrorTwo::DEV_ADDR::str_short, "0xDEADDEAD");
+ if (rc)
+ return (rc);
+
+ rc = validate_journal(TestErrorTwo::DEV_ID::str_short, "100");
+ if (rc)
+ return (rc);
+
+ rc = validate_journal(TestErrorTwo::DEV_NAME::str_short, "test case 4");
+ if (rc)
+ return (rc);
// Compile fail tests
// Simple test to prove we fail to compile due to missing param
- //elog<TestErrorOne>(TestErrorOne::ERRNUM(1),
+ // elog<TestErrorOne>(TestErrorOne::ERRNUM(1),
// TestErrorOne::FILE_PATH("test"));
// Simple test to prove we fail to compile due to invalid param
- //elog<TestErrorOne>(TestErrorOne::ERRNUM(1),
+ // elog<TestErrorOne>(TestErrorOne::ERRNUM(1),
// TestErrorOne::FILE_PATH("test"),
// TestErrorOne::FILE_NAME(1));
return 0;
}
-void commitError(const char *text)
+void commitError(const char* text)
{
if (strcmp(text, "AutoTestSimple") == 0)
{
try
{
- elog<example::xyz::openbmc_project::Example::Elog::
- AutoTestSimple>(
- example::xyz::openbmc_project::Example::Elog::
- AutoTestSimple::STRING("FOO"));
+ elog<example::xyz::openbmc_project::Example::Elog::AutoTestSimple>(
+ example::xyz::openbmc_project::Example::Elog::AutoTestSimple::
+ STRING("FOO"));
}
- catch (example::xyz::openbmc_project::Example::Elog::
- AutoTestSimple& e)
+ catch (example::xyz::openbmc_project::Example::Elog::AutoTestSimple& e)
{
std::cout << "elog exception caught: " << e.what() << std::endl;
commit(e.name());
@@ -224,31 +218,29 @@ void commitError(const char *text)
}
else if (strcmp(text, "AutoTestCreateAndCommit") == 0)
{
- report<example::xyz::openbmc_project::Example::Elog::
- AutoTestSimple>(
- example::xyz::openbmc_project::Example::Elog::
- AutoTestSimple::STRING("FOO"));
+ report<example::xyz::openbmc_project::Example::Elog::AutoTestSimple>(
+ example::xyz::openbmc_project::Example::Elog::AutoTestSimple::
+ STRING("FOO"));
}
return;
}
-int main(int argc, char *argv[])
+int main(int argc, char* argv[])
{
char arg;
if (argc == 1)
return elog_test();
- static struct option long_options[] =
- {
- {"help", no_argument, 0, 'h'},
- {"commit", required_argument, 0, 'c'},
- {0, 0, 0, 0}
- };
+ static struct option long_options[] = {
+ {"help", no_argument, 0, 'h'},
+ {"commit", required_argument, 0, 'c'},
+ {0, 0, 0, 0}};
int option_index = 0;
- while((arg=getopt_long(argc,argv,"hc:",long_options,&option_index)) != -1)
+ while ((arg = getopt_long(argc, argv, "hc:", long_options,
+ &option_index)) != -1)
{
switch (arg)
{
@@ -259,10 +251,8 @@ int main(int argc, char *argv[])
case '?':
std::cerr << usage;
return 1;
-
}
}
return 0;
-
}
diff --git a/org.openbmc.Associations.cpp b/org.openbmc.Associations.cpp
index d4580c9..25d79fd 100644
--- a/org.openbmc.Associations.cpp
+++ b/org.openbmc.Associations.cpp
@@ -1,7 +1,7 @@
#include <algorithm>
-#include <sdbusplus/server.hpp>
-#include <sdbusplus/exception.hpp>
#include <org/openbmc/Associations/server.hpp>
+#include <sdbusplus/exception.hpp>
+#include <sdbusplus/server.hpp>
namespace sdbusplus
{
@@ -12,15 +12,15 @@ namespace openbmc
namespace server
{
-Associations::Associations(bus::bus& bus, const char* path)
- : _org_openbmc_Associations_interface(
- bus, path, _interface, _vtable, this)
+Associations::Associations(bus::bus& bus, const char* path) :
+ _org_openbmc_Associations_interface(bus, path, _interface, _vtable, this)
{
}
-Associations::Associations(bus::bus& bus, const char* path,
- const std::map<std::string, PropertiesVariant>& vals)
- : Associations(bus, path)
+Associations::Associations(
+ bus::bus& bus, const char* path,
+ const std::map<std::string, PropertiesVariant>& vals) :
+ Associations(bus, path)
{
for (const auto& v : vals)
{
@@ -28,18 +28,17 @@ Associations::Associations(bus::bus& bus, const char* path,
}
}
-
-
-auto Associations::associations() const ->
- std::vector<std::tuple<std::string, std::string, std::string>>
+auto Associations::associations() const
+ -> std::vector<std::tuple<std::string, std::string, std::string>>
{
return _associations;
}
-int Associations::_callback_get_associations(
- sd_bus* bus, const char* path, const char* interface,
- const char* property, sd_bus_message* reply, void* context,
- sd_bus_error* error)
+int Associations::_callback_get_associations(sd_bus* bus, const char* path,
+ const char* interface,
+ const char* property,
+ sd_bus_message* reply,
+ void* context, sd_bus_error* error)
{
using sdbusplus::server::binding::details::convertForMessage;
@@ -50,15 +49,15 @@ int Associations::_callback_get_associations(
{
auto tbus = m.get_bus();
sdbusplus::server::transaction::Transaction t(tbus, m);
- sdbusplus::server::transaction::set_id
- (std::hash<sdbusplus::server::transaction::Transaction>{}(t));
+ sdbusplus::server::transaction::set_id(
+ std::hash<sdbusplus::server::transaction::Transaction>{}(t));
}
#endif
auto o = static_cast<Associations*>(context);
m.append(convertForMessage(o->associations()));
}
- catch(sdbusplus::internal_exception_t& e)
+ catch (sdbusplus::internal_exception_t& e)
{
sd_bus_error_set_const(error, e.name(), e.description());
return -EINVAL;
@@ -67,8 +66,9 @@ int Associations::_callback_get_associations(
return true;
}
-auto Associations::associations(std::vector<std::tuple<std::string, std::string, std::string>> value) ->
- std::vector<std::tuple<std::string, std::string, std::string>>
+auto Associations::associations(
+ std::vector<std::tuple<std::string, std::string, std::string>> value)
+ -> std::vector<std::tuple<std::string, std::string, std::string>>
{
if (_associations != value)
{
@@ -79,10 +79,11 @@ auto Associations::associations(std::vector<std::tuple<std::string, std::string,
return _associations;
}
-int Associations::_callback_set_associations(
- sd_bus* bus, const char* path, const char* interface,
- const char* property, sd_bus_message* value, void* context,
- sd_bus_error* error)
+int Associations::_callback_set_associations(sd_bus* bus, const char* path,
+ const char* interface,
+ const char* property,
+ sd_bus_message* value,
+ void* context, sd_bus_error* error)
{
try
{
@@ -91,8 +92,8 @@ int Associations::_callback_set_associations(
{
auto tbus = m.get_bus();
sdbusplus::server::transaction::Transaction t(tbus, m);
- sdbusplus::server::transaction::set_id
- (std::hash<sdbusplus::server::transaction::Transaction>{}(t));
+ sdbusplus::server::transaction::set_id(
+ std::hash<sdbusplus::server::transaction::Transaction>{}(t));
}
#endif
@@ -102,7 +103,7 @@ int Associations::_callback_set_associations(
m.read(v);
o->associations(v);
}
- catch(sdbusplus::internal_exception_t& e)
+ catch (sdbusplus::internal_exception_t& e)
{
sd_bus_error_set_const(error, e.name(), e.description());
return -EINVAL;
@@ -115,25 +116,27 @@ namespace details
{
namespace Associations
{
-static const auto _property_associations =
- utility::tuple_to_array(message::types::type_id<
- std::vector<std::tuple<std::string, std::string, std::string>>>());
-}
+static const auto _property_associations = utility::tuple_to_array(
+ message::types::type_id<
+ std::vector<std::tuple<std::string, std::string, std::string>>>());
}
+} // namespace details
void Associations::setPropertyByName(const std::string& name,
const PropertiesVariant& val)
{
if (name == "associations")
{
- auto& v = message::variant_ns::get<std::vector<std::tuple<std::string, std::string, std::string>>>(val);
+ auto& v = message::variant_ns::get<
+ std::vector<std::tuple<std::string, std::string, std::string>>>(
+ val);
associations(v);
return;
}
}
-auto Associations::getPropertyByName(const std::string& name) ->
- PropertiesVariant
+auto Associations::getPropertyByName(const std::string& name)
+ -> PropertiesVariant
{
if (name == "associations")
{
@@ -143,20 +146,15 @@ auto Associations::getPropertyByName(const std::string& name) ->
return PropertiesVariant();
}
-
const vtable::vtable_t Associations::_vtable[] = {
vtable::start(),
vtable::property("associations",
- details::Associations::_property_associations
- .data(),
- _callback_get_associations,
- _callback_set_associations,
+ details::Associations::_property_associations.data(),
+ _callback_get_associations, _callback_set_associations,
vtable::property_::emits_change),
- vtable::end()
-};
+ vtable::end()};
} // namespace server
} // namespace openbmc
} // namespace org
} // namespace sdbusplus
-
diff --git a/org/openbmc/Associations/server.hpp b/org/openbmc/Associations/server.hpp
index 5fc71e0..fb3ff7e 100644
--- a/org/openbmc/Associations/server.hpp
+++ b/org/openbmc/Associations/server.hpp
@@ -1,7 +1,8 @@
#pragma once
-#include <tuple>
#include <systemd/sd-bus.h>
+
#include <sdbusplus/server.hpp>
+#include <tuple>
namespace sdbusplus
{
@@ -14,88 +15,83 @@ namespace server
class Associations
{
- public:
- /* Define all of the basic class operations:
- * Not allowed:
- * - Default constructor to avoid nullptrs.
- * - Copy operations due to internal unique_ptr.
- * - Move operations due to 'this' being registered as the
- * 'context' with sdbus.
- * Allowed:
- * - Destructor.
- */
- Associations() = delete;
- Associations(const Associations&) = delete;
- Associations& operator=(const Associations&) = delete;
- Associations(Associations&&) = delete;
- Associations& operator=(Associations&&) = delete;
- virtual ~Associations() = default;
-
- /** @brief Constructor to put object onto bus at a dbus path.
- * @param[in] bus - Bus to attach to.
- * @param[in] path - Path to attach at.
- */
- Associations(bus::bus& bus, const char* path);
-
-
- using PropertiesVariant = sdbusplus::message::variant<
- std::vector<std::tuple<std::string, std::string, std::string>>>;
-
- /** @brief Constructor to initialize the object from a map of
- * properties.
- *
- * @param[in] bus - Bus to attach to.
- * @param[in] path - Path to attach at.
- * @param[in] vals - Map of property name to value for initialization.
- */
- Associations(bus::bus& bus, const char* path,
- const std::map<std::string, PropertiesVariant>& vals);
-
-
-
- /** Get value of associations */
- virtual std::vector<std::tuple<std::string, std::string, std::string>> associations() const;
- /** Set value of associations */
- virtual std::vector<std::tuple<std::string, std::string, std::string>> associations(std::vector<std::tuple<std::string, std::string, std::string>> value);
-
- /** @brief Sets a property by name.
- * @param[in] name - A string representation of the property name.
- * @param[in] val - A variant containing the value to set.
- */
- void setPropertyByName(const std::string& name,
- const PropertiesVariant& val);
-
- /** @brief Gets a property by name.
- * @param[in] name - A string representation of the property name.
- * @return - A variant containing the value of the property.
- */
- PropertiesVariant getPropertyByName(const std::string& name);
-
-
- private:
-
- /** @brief sd-bus callback for get-property 'associations' */
- static int _callback_get_associations(
- sd_bus*, const char*, const char*, const char*,
- sd_bus_message*, void*, sd_bus_error*);
- /** @brief sd-bus callback for set-property 'associations' */
- static int _callback_set_associations(
- sd_bus*, const char*, const char*, const char*,
- sd_bus_message*, void*, sd_bus_error*);
-
-
- static constexpr auto _interface = "org.openbmc.Associations";
- static const vtable::vtable_t _vtable[];
- sdbusplus::server::interface::interface
- _org_openbmc_Associations_interface;
-
- std::vector<std::tuple<std::string, std::string, std::string>> _associations{};
-
+ public:
+ /* Define all of the basic class operations:
+ * Not allowed:
+ * - Default constructor to avoid nullptrs.
+ * - Copy operations due to internal unique_ptr.
+ * - Move operations due to 'this' being registered as the
+ * 'context' with sdbus.
+ * Allowed:
+ * - Destructor.
+ */
+ Associations() = delete;
+ Associations(const Associations&) = delete;
+ Associations& operator=(const Associations&) = delete;
+ Associations(Associations&&) = delete;
+ Associations& operator=(Associations&&) = delete;
+ virtual ~Associations() = default;
+
+ /** @brief Constructor to put object onto bus at a dbus path.
+ * @param[in] bus - Bus to attach to.
+ * @param[in] path - Path to attach at.
+ */
+ Associations(bus::bus& bus, const char* path);
+
+ using PropertiesVariant = sdbusplus::message::variant<
+ std::vector<std::tuple<std::string, std::string, std::string>>>;
+
+ /** @brief Constructor to initialize the object from a map of
+ * properties.
+ *
+ * @param[in] bus - Bus to attach to.
+ * @param[in] path - Path to attach at.
+ * @param[in] vals - Map of property name to value for initialization.
+ */
+ Associations(bus::bus& bus, const char* path,
+ const std::map<std::string, PropertiesVariant>& vals);
+
+ /** Get value of associations */
+ virtual std::vector<std::tuple<std::string, std::string, std::string>>
+ associations() const;
+ /** Set value of associations */
+ virtual std::vector<std::tuple<std::string, std::string, std::string>>
+ associations(
+ std::vector<std::tuple<std::string, std::string, std::string>>
+ value);
+
+ /** @brief Sets a property by name.
+ * @param[in] name - A string representation of the property name.
+ * @param[in] val - A variant containing the value to set.
+ */
+ void setPropertyByName(const std::string& name,
+ const PropertiesVariant& val);
+
+ /** @brief Gets a property by name.
+ * @param[in] name - A string representation of the property name.
+ * @return - A variant containing the value of the property.
+ */
+ PropertiesVariant getPropertyByName(const std::string& name);
+
+ private:
+ /** @brief sd-bus callback for get-property 'associations' */
+ static int _callback_get_associations(sd_bus*, const char*, const char*,
+ const char*, sd_bus_message*, void*,
+ sd_bus_error*);
+ /** @brief sd-bus callback for set-property 'associations' */
+ static int _callback_set_associations(sd_bus*, const char*, const char*,
+ const char*, sd_bus_message*, void*,
+ sd_bus_error*);
+
+ static constexpr auto _interface = "org.openbmc.Associations";
+ static const vtable::vtable_t _vtable[];
+ sdbusplus::server::interface::interface _org_openbmc_Associations_interface;
+
+ std::vector<std::tuple<std::string, std::string, std::string>>
+ _associations{};
};
-
} // namespace server
} // namespace openbmc
} // namespace org
} // namespace sdbusplus
-
diff --git a/phosphor-logging/elog.hpp b/phosphor-logging/elog.hpp
index b76bd6c..5aace07 100644
--- a/phosphor-logging/elog.hpp
+++ b/phosphor-logging/elog.hpp
@@ -1,9 +1,10 @@
#pragma once
-#include <tuple>
-#include <utility>
+#include "xyz/openbmc_project/Logging/Entry/server.hpp"
+
#include <phosphor-logging/log.hpp>
#include <sdbusplus/exception.hpp>
-#include "xyz/openbmc_project/Logging/Entry/server.hpp"
+#include <tuple>
+#include <utility>
namespace phosphor
{
@@ -16,15 +17,13 @@ using namespace sdbusplus::xyz::openbmc_project::Logging::server;
/**
* @brief Structure used by callers to indicate they want to use the last value
* put in the journal for input parameter.
-*/
+ */
template <typename T>
struct prev_entry
{
using type = T;
};
-
-
namespace details
{
/**
@@ -40,7 +39,10 @@ struct deduce_entry_type
{
using type = T;
- auto get() { return value._entry; }
+ auto get()
+ {
+ return value._entry;
+ }
T value;
};
@@ -56,7 +58,10 @@ template <typename T>
struct deduce_entry_type<prev_entry<T>>
{
using type = T;
- auto get() { return std::make_tuple(); }
+ auto get()
+ {
+ return std::make_tuple();
+ }
prev_entry<T> value;
};
@@ -64,8 +69,8 @@ struct deduce_entry_type<prev_entry<T>>
/**
* @brief Typedef for above structure usage
*/
-template <typename T> using deduce_entry_type_t =
- typename deduce_entry_type<T>::type;
+template <typename T>
+using deduce_entry_type_t = typename deduce_entry_type<T>::type;
/**
* @brief Used to map an sdbusplus error to a phosphor-logging error type
@@ -84,8 +89,8 @@ struct map_exception_type
/**
* @brief Typedef for above structure usage
*/
-template <typename T> using map_exception_type_t =
- typename map_exception_type<T>::type;
+template <typename T>
+using map_exception_type_t = typename map_exception_type<T>::type;
/** @fn commit()
* @brief Create an error log entry based on journal
@@ -116,10 +121,8 @@ template <typename T>
void commit()
{
// Validate if the exception is derived from sdbusplus::exception.
- static_assert(
- std::is_base_of<sdbusplus::exception::exception, T>::value,
- "T must be a descendant of sdbusplus::exception::exception"
- );
+ static_assert(std::is_base_of<sdbusplus::exception::exception, T>::value,
+ "T must be a descendant of sdbusplus::exception::exception");
details::commit(T::errName);
}
@@ -132,40 +135,32 @@ template <typename T>
void commit(Entry::Level level)
{
// Validate if the exception is derived from sdbusplus::exception.
- static_assert(
- std::is_base_of<sdbusplus::exception::exception, T>::value,
- "T must be a descendant of sdbusplus::exception::exception"
- );
+ static_assert(std::is_base_of<sdbusplus::exception::exception, T>::value,
+ "T must be a descendant of sdbusplus::exception::exception");
details::commit(T::errName, level);
}
-
/** @fn elog()
* @brief Create a journal log entry based on predefined
* error log information
* @tparam T - Error log type
* @param[in] i_args - Metadata fields to be added to the journal entry
*/
-template <typename T, typename ...Args>
+template <typename T, typename... Args>
void elog(Args... i_args)
{
// Validate if the exception is derived from sdbusplus::exception.
- static_assert(
- std::is_base_of<sdbusplus::exception::exception, T>::value,
- "T must be a descendant of sdbusplus::exception::exception"
- );
+ static_assert(std::is_base_of<sdbusplus::exception::exception, T>::value,
+ "T must be a descendant of sdbusplus::exception::exception");
// Validate the caller passed in the required parameters
- static_assert(std::is_same<typename details::
- map_exception_type_t<T>::metadata_types,
- std::tuple<
- details::deduce_entry_type_t<Args>...>>
- ::value,
- "You are not passing in required arguments for this error");
+ static_assert(
+ std::is_same<typename details::map_exception_type_t<T>::metadata_types,
+ std::tuple<details::deduce_entry_type_t<Args>...>>::value,
+ "You are not passing in required arguments for this error");
log<details::map_exception_type_t<T>::L>(
- T::errDesc,
- details::deduce_entry_type<Args>{i_args}.get()...);
+ T::errDesc, details::deduce_entry_type<Args>{i_args}.get()...);
// Now throw an exception for this error
throw T();
@@ -177,26 +172,21 @@ void elog(Args... i_args)
* @tparam T - exception
* @param[in] i_args - Metadata fields to be added to the journal entry
*/
-template <typename T, typename ...Args>
+template <typename T, typename... Args>
void report(Args... i_args)
{
- //validate if the exception is derived from sdbusplus::exception.
- static_assert(
- std::is_base_of<sdbusplus::exception::exception, T>::value,
- "T must be a descendant of sdbusplus::exception::exception"
- );
+ // validate if the exception is derived from sdbusplus::exception.
+ static_assert(std::is_base_of<sdbusplus::exception::exception, T>::value,
+ "T must be a descendant of sdbusplus::exception::exception");
// Validate the caller passed in the required parameters
- static_assert(std::is_same<typename details::
- map_exception_type_t<T>::metadata_types,
- std::tuple<
- details::deduce_entry_type_t<Args>...>>
- ::value,
- "You are not passing in required arguments for this error");
+ static_assert(
+ std::is_same<typename details::map_exception_type_t<T>::metadata_types,
+ std::tuple<details::deduce_entry_type_t<Args>...>>::value,
+ "You are not passing in required arguments for this error");
log<details::map_exception_type_t<T>::L>(
- T::errDesc,
- details::deduce_entry_type<Args>{i_args}.get()...);
+ T::errDesc, details::deduce_entry_type<Args>{i_args}.get()...);
commit<T>();
}
@@ -209,26 +199,21 @@ void report(Args... i_args)
* @param[in] level - level of the error
* @param[in] i_args - Metadata fields to be added to the journal entry
*/
-template <typename T, typename ...Args>
+template <typename T, typename... Args>
void report(Entry::Level level, Args... i_args)
{
- //validate if the exception is derived from sdbusplus::exception.
- static_assert(
- std::is_base_of<sdbusplus::exception::exception, T>::value,
- "T must be a descendant of sdbusplus::exception::exception"
- );
+ // validate if the exception is derived from sdbusplus::exception.
+ static_assert(std::is_base_of<sdbusplus::exception::exception, T>::value,
+ "T must be a descendant of sdbusplus::exception::exception");
// Validate the caller passed in the required parameters
- static_assert(std::is_same<typename details::
- map_exception_type_t<T>::metadata_types,
- std::tuple<
- details::deduce_entry_type_t<Args>...>>
- ::value,
- "You are not passing in required arguments for this error");
+ static_assert(
+ std::is_same<typename details::map_exception_type_t<T>::metadata_types,
+ std::tuple<details::deduce_entry_type_t<Args>...>>::value,
+ "You are not passing in required arguments for this error");
log<details::map_exception_type_t<T>::L>(
- T::errDesc,
- details::deduce_entry_type<Args>{i_args}.get()...);
+ T::errDesc, details::deduce_entry_type<Args>{i_args}.get()...);
commit<T>(level);
}
@@ -236,4 +221,3 @@ void report(Entry::Level level, Args... i_args)
} // namespace logging
} // namespace phosphor
-
diff --git a/phosphor-logging/log.hpp b/phosphor-logging/log.hpp
index a933591..e20605b 100644
--- a/phosphor-logging/log.hpp
+++ b/phosphor-logging/log.hpp
@@ -16,10 +16,11 @@
#pragma once
-#include <tuple>
-#include <type_traits>
#include <systemd/sd-journal.h>
+
#include <sdbusplus/server/transaction.hpp>
+#include <tuple>
+#include <type_traits>
namespace phosphor
{
@@ -32,14 +33,14 @@ namespace logging
*/
enum class level
{
- EMERG = LOG_EMERG,
- ALERT = LOG_ALERT,
- CRIT = LOG_CRIT,
- ERR = LOG_ERR,
+ EMERG = LOG_EMERG,
+ ALERT = LOG_ALERT,
+ CRIT = LOG_CRIT,
+ ERR = LOG_ERR,
WARNING = LOG_WARNING,
- NOTICE = LOG_NOTICE,
- INFO = LOG_INFO,
- DEBUG = LOG_DEBUG,
+ NOTICE = LOG_NOTICE,
+ INFO = LOG_INFO,
+ DEBUG = LOG_DEBUG,
};
/** @fn log()
@@ -55,7 +56,7 @@ enum class level
* msg_str,
* entry("MY_METADATA=%s_%x, name, number));
*/
-template <level L, typename Msg, typename ...Entry>
+template <level L, typename Msg, typename... Entry>
void log(Msg msg, Entry... entry);
/** @fn entry()
@@ -68,7 +69,7 @@ void log(Msg msg, Entry... entry);
* value is of any size and format
* @param[in] args - Remaining metadata strings
*/
-template <typename Arg, typename ...Args>
+template <typename Arg, typename... Args>
constexpr auto entry(Arg&& arg, Args&&... args);
namespace details
@@ -82,7 +83,7 @@ namespace details
template <level L>
constexpr auto prio()
{
- constexpr const char *prio_str = "PRIORITY=%d";
+ constexpr const char* prio_str = "PRIORITY=%d";
constexpr const auto prio_tuple = std::make_tuple(prio_str, L);
return prio_tuple;
}
@@ -94,7 +95,7 @@ constexpr auto prio()
* @param[in] e - Tuple containing the data to be logged
* @param[unnamed] - std::integer_sequence of tuple's index values
*/
-template <typename T, size_t ...I>
+template <typename T, size_t... I>
void helper_log(T&& e, std::integer_sequence<size_t, I...>)
{
// https://www.freedesktop.org/software/systemd/man/sd_journal_print.html
@@ -116,63 +117,63 @@ void log(T&& e)
} // namespace details
-template <level L, typename Msg, typename ...Entry>
+template <level L, typename Msg, typename... Entry>
void log(Msg msg, Entry... e)
{
static_assert((std::is_same<const char*, std::decay_t<Msg>>::value ||
std::is_same<char*, std::decay_t<Msg>>::value),
"First parameter must be a C-string.");
- constexpr const char *msg_str = "MESSAGE=%s";
+ constexpr const char* msg_str = "MESSAGE=%s";
const auto msg_tuple = std::make_tuple(msg_str, std::forward<Msg>(msg));
constexpr auto transactionStr = "TRANSACTION_ID=%lld";
auto transactionId = sdbusplus::server::transaction::get_id();
- auto log_tuple = std::tuple_cat(details::prio<L>(),
- msg_tuple,
+ auto log_tuple = std::tuple_cat(details::prio<L>(), msg_tuple,
entry(transactionStr, transactionId),
std::forward<Entry>(e)...);
details::log(log_tuple);
}
-template<class T>
+template <class T>
struct is_printf_argtype
: std::integral_constant<
- bool,
- (std::is_integral<typename std::remove_reference<T>::type>::value ||
- std::is_enum<typename std::remove_reference<T>::type>::value ||
- std::is_floating_point<typename
- std::remove_reference<T>::type>::value ||
- std::is_pointer<typename std::decay<T>::type>::value)>
-{};
-
-template<class T>
+ bool,
+ (std::is_integral<typename std::remove_reference<T>::type>::value ||
+ std::is_enum<typename std::remove_reference<T>::type>::value ||
+ std::is_floating_point<
+ typename std::remove_reference<T>::type>::value ||
+ std::is_pointer<typename std::decay<T>::type>::value)>
+{
+};
+
+template <class T>
struct is_char_ptr_argtype
: std::integral_constant<
- bool,
- (std::is_pointer<typename std::decay<T>::type>::value &&
- std::is_same<typename std::remove_cv<typename
- std::remove_pointer<typename
- std::decay<T>::type>::type>::type,
- char>::value)>
-{};
-
-template<bool...>
+ bool,
+ (std::is_pointer<typename std::decay<T>::type>::value &&
+ std::is_same<typename std::remove_cv<typename std::remove_pointer<
+ typename std::decay<T>::type>::type>::type,
+ char>::value)>
+{
+};
+
+template <bool...>
struct bool_pack;
-template<bool... bs>
+template <bool... bs>
using all_true = std::is_same<bool_pack<bs..., true>, bool_pack<true, bs...>>;
-template <typename Arg, typename ...Args>
+template <typename Arg, typename... Args>
constexpr auto entry(Arg&& arg, Args&&... args)
{
static_assert(is_char_ptr_argtype<Arg>::value,
"bad argument type: use char*");
static_assert(all_true<is_printf_argtype<Args>::value...>::value,
"bad argument type: use string.c_str() if needed");
- const auto entry_tuple = std::make_tuple(std::forward<Arg>(arg),
- std::forward<Args>(args)...);
+ const auto entry_tuple =
+ std::make_tuple(std::forward<Arg>(arg), std::forward<Args>(args)...);
return entry_tuple;
}
diff --git a/phosphor-rsyslog-config/main.cpp b/phosphor-rsyslog-config/main.cpp
index 3e4d928..ea0ca03 100644
--- a/phosphor-rsyslog-config/main.cpp
+++ b/phosphor-rsyslog-config/main.cpp
@@ -1,19 +1,19 @@
#include "config.h"
+
#include "server-conf.hpp"
+
#include <sdbusplus/bus.hpp>
-int main(int argc, char *argv[])
+int main(int argc, char* argv[])
{
auto bus = sdbusplus::bus::new_default();
- phosphor::rsyslog_config::Server
- serverConf(bus,
- BUSPATH_REMOTE_LOGGING_CONFIG,
- RSYSLOG_SERVER_CONFIG_FILE);
+ phosphor::rsyslog_config::Server serverConf(
+ bus, BUSPATH_REMOTE_LOGGING_CONFIG, RSYSLOG_SERVER_CONFIG_FILE);
bus.request_name(BUSNAME_SYSLOG_CONFIG);
- while(true)
+ while (true)
{
bus.process_discard();
bus.wait();
diff --git a/phosphor-rsyslog-config/server-conf.cpp b/phosphor-rsyslog-config/server-conf.cpp
index 4bf8c79..4bf167c 100644
--- a/phosphor-rsyslog-config/server-conf.cpp
+++ b/phosphor-rsyslog-config/server-conf.cpp
@@ -1,6 +1,8 @@
#include "server-conf.hpp"
+
#include "utils.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
+
#include <fstream>
#include <phosphor-logging/elog.hpp>
#if __has_include("../../usr/include/phosphor-logging/elog-errors.hpp")
@@ -8,8 +10,8 @@
#else
#include <phosphor-logging/elog-errors.hpp>
#endif
-#include <netdb.h>
#include <arpa/inet.h>
+#include <netdb.h>
namespace phosphor
{
@@ -23,7 +25,7 @@ using namespace sdbusplus::xyz::openbmc_project::Common::Error;
std::string Server::address(std::string value)
{
using Argument = xyz::openbmc_project::Common::InvalidArgument;
- std::string result {};
+ std::string result{};
try
{
@@ -61,7 +63,7 @@ std::string Server::address(std::string value)
uint16_t Server::port(uint16_t value)
{
- uint16_t result {};
+ uint16_t result{};
try
{
@@ -87,10 +89,8 @@ uint16_t Server::port(uint16_t value)
return result;
}
-void Server::writeConfig(
- const std::string& serverAddress,
- uint16_t serverPort,
- const char* filePath)
+void Server::writeConfig(const std::string& serverAddress, uint16_t serverPort,
+ const char* filePath)
{
std::fstream stream(filePath, std::fstream::out);
@@ -119,8 +119,7 @@ bool Server::addressValid(const std::string& address)
auto result = getaddrinfo(address.c_str(), nullptr, &hints, &res);
if (result)
{
- log<level::ERR>("bad address",
- entry("ADDRESS=%s", address.c_str()),
+ log<level::ERR>("bad address", entry("ADDRESS=%s", address.c_str()),
entry("ERRNO=%d", result));
return false;
}
diff --git a/phosphor-rsyslog-config/server-conf.hpp b/phosphor-rsyslog-config/server-conf.hpp
index 8660416..8e1b2cb 100644
--- a/phosphor-rsyslog-config/server-conf.hpp
+++ b/phosphor-rsyslog-config/server-conf.hpp
@@ -1,10 +1,11 @@
#pragma once
+#include "xyz/openbmc_project/Network/Client/server.hpp"
+
+#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server/object.hpp>
#include <string>
-#include <phosphor-logging/log.hpp>
-#include "xyz/openbmc_project/Network/Client/server.hpp"
namespace phosphor
{
@@ -24,96 +25,93 @@ namespace sdbusRule = sdbusplus::bus::match::rules;
*/
class Server : public Iface
{
- public:
- Server() = delete;
- Server(const Server&) = delete;
- Server& operator=(const Server&) = delete;
- Server(Server&&) = delete;
- Server& operator=(Server&&) = delete;
- virtual ~Server() = default;
-
- /** @brief Constructor to put object onto bus at a dbus path.
- * @param[in] bus - Bus to attach to.
- * @param[in] path - Path to attach at.
- * @param[in] filePath - rsyslog remote logging config file
- */
- Server(sdbusplus::bus::bus& bus,
- const std::string& path,
- const char* filePath) :
- Iface(bus, path.c_str(), true),
- configFilePath(filePath),
- hostnameChange(
- bus,
- sdbusRule::propertiesChanged(
- "/org/freedesktop/hostname1", "org.freedesktop.hostname1"),
- std::bind(std::mem_fn(&Server::hostnameChanged),
- this, std::placeholders::_1))
+ public:
+ Server() = delete;
+ Server(const Server&) = delete;
+ Server& operator=(const Server&) = delete;
+ Server(Server&&) = delete;
+ Server& operator=(Server&&) = delete;
+ virtual ~Server() = default;
+
+ /** @brief Constructor to put object onto bus at a dbus path.
+ * @param[in] bus - Bus to attach to.
+ * @param[in] path - Path to attach at.
+ * @param[in] filePath - rsyslog remote logging config file
+ */
+ Server(sdbusplus::bus::bus& bus, const std::string& path,
+ const char* filePath) :
+ Iface(bus, path.c_str(), true),
+ configFilePath(filePath),
+ hostnameChange(
+ bus,
+ sdbusRule::propertiesChanged("/org/freedesktop/hostname1",
+ "org.freedesktop.hostname1"),
+ std::bind(std::mem_fn(&Server::hostnameChanged), this,
+ std::placeholders::_1))
+ {
+ try
{
- try
- {
- restore(configFilePath.c_str());
- }
- catch(const std::exception& e)
- {
- log<level::ERR>(e.what());
- }
-
- emit_object_added();
+ restore(configFilePath.c_str());
}
-
- using NetworkClient::address;
- using NetworkClient::port;
-
- /** @brief Override that updates rsyslog config file as well
- * @param[in] value - remote server address
- * @returns value of changed address
- */
- virtual std::string address(std::string value) override;
-
- /** @brief Override that updates rsyslog config file as well
- * @param[in] value - remote server port
- * @returns value of changed port
- */
- virtual uint16_t port(uint16_t value) override;
-
- /** @brief Restart rsyslog's systemd unit
- */
- virtual void restart();
-
- private:
- /** @brief Update remote server address and port in
- * rsyslog config file.
- * @param[in] serverAddress - remote server address
- * @param[in] serverPort - remote server port
- * @param[in] filePath - rsyslog config file path
- */
- void writeConfig(
- const std::string& serverAddress,
- uint16_t serverPort,
- const char* filePath);
-
- /** @brief Checks if input IP address is valid (uses getaddrinfo)
- * @param[in] address - server address
- * @returns true if valid, false otherwise
- */
- bool addressValid(const std::string& address);
-
- /** @brief Populate existing config into D-Bus properties
- * @param[in] filePath - rsyslog config file path
- */
- void restore(const char* filePath);
-
- std::string configFilePath{};
-
- /** @brief React to hostname change
- * @param[in] msg - sdbusplus message
- */
- void hostnameChanged(sdbusplus::message::message& msg)
+ catch (const std::exception& e)
{
- restart();
+ log<level::ERR>(e.what());
}
- sdbusplus::bus::match_t hostnameChange;
+ emit_object_added();
+ }
+
+ using NetworkClient::address;
+ using NetworkClient::port;
+
+ /** @brief Override that updates rsyslog config file as well
+ * @param[in] value - remote server address
+ * @returns value of changed address
+ */
+ virtual std::string address(std::string value) override;
+
+ /** @brief Override that updates rsyslog config file as well
+ * @param[in] value - remote server port
+ * @returns value of changed port
+ */
+ virtual uint16_t port(uint16_t value) override;
+
+ /** @brief Restart rsyslog's systemd unit
+ */
+ virtual void restart();
+
+ private:
+ /** @brief Update remote server address and port in
+ * rsyslog config file.
+ * @param[in] serverAddress - remote server address
+ * @param[in] serverPort - remote server port
+ * @param[in] filePath - rsyslog config file path
+ */
+ void writeConfig(const std::string& serverAddress, uint16_t serverPort,
+ const char* filePath);
+
+ /** @brief Checks if input IP address is valid (uses getaddrinfo)
+ * @param[in] address - server address
+ * @returns true if valid, false otherwise
+ */
+ bool addressValid(const std::string& address);
+
+ /** @brief Populate existing config into D-Bus properties
+ * @param[in] filePath - rsyslog config file path
+ */
+ void restore(const char* filePath);
+
+ std::string configFilePath{};
+
+ /** @brief React to hostname change
+ * @param[in] msg - sdbusplus message
+ */
+ void hostnameChanged(sdbusplus::message::message& msg)
+ {
+ restart();
+ }
+
+ sdbusplus::bus::match_t hostnameChange;
};
} // namespace rsyslog_config
diff --git a/phosphor-rsyslog-config/utils.hpp b/phosphor-rsyslog-config/utils.hpp
index ea7984d..017a439 100644
--- a/phosphor-rsyslog-config/utils.hpp
+++ b/phosphor-rsyslog-config/utils.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "config.h"
+
#include <sdbusplus/bus.hpp>
namespace phosphor
@@ -13,11 +14,8 @@ namespace rsyslog_utils
void restart()
{
auto bus = sdbusplus::bus::new_default();
- auto method = bus.new_method_call(
- SYSTEMD_BUSNAME,
- SYSTEMD_PATH,
- SYSTEMD_INTERFACE,
- "RestartUnit");
+ auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "RestartUnit");
method.append("rsyslog.service", "replace");
bus.call_noreply(method);
}
diff --git a/test/elog_errorwrap_test.cpp b/test/elog_errorwrap_test.cpp
index f341447..c94c638 100644
--- a/test/elog_errorwrap_test.cpp
+++ b/test/elog_errorwrap_test.cpp
@@ -16,7 +16,7 @@ TEST_F(TestLogManager, logCap)
// Max num of Info( and below Sev) errors can be created is qual to
// ERROR_INFO_CAP
- EXPECT_EQ(ERROR_INFO_CAP , manager.getInfoErrSize());
+ EXPECT_EQ(ERROR_INFO_CAP, manager.getInfoErrSize());
for (auto i = 0; i < ERROR_CAP + 20; i++)
{
@@ -24,9 +24,8 @@ TEST_F(TestLogManager, logCap)
}
// Max num of high severity errors can be created is qual to ERROR_CAP
EXPECT_EQ(ERROR_CAP, manager.getRealErrSize());
-
}
-}// namespace internal
-}// namespace logging
-}// namespace phosphor
+} // namespace internal
+} // namespace logging
+} // namespace phosphor
diff --git a/test/elog_errorwrap_test.hpp b/test/elog_errorwrap_test.hpp
index 7c673b6..537a7ff 100644
--- a/test/elog_errorwrap_test.hpp
+++ b/test/elog_errorwrap_test.hpp
@@ -1,14 +1,17 @@
+#include "config.h"
+
+#include "elog_serialize.hpp"
#include "log_manager.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
-#include <gtest/gtest.h>
-#include <gmock/gmock.h>
-#include <sdbusplus/bus.hpp>
+
#include <experimental/filesystem>
+#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/log.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-#include "elog_serialize.hpp"
-#include "config.h"
+#include <sdbusplus/bus.hpp>
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
namespace phosphor
{
@@ -21,30 +24,24 @@ namespace fs = std::experimental::filesystem;
class journalInterface
{
- public:
- virtual void journalSync() = 0;
- virtual int sd_journal_open(sd_journal** j, int k) = 0;
- virtual int sd_journal_get_data(sd_journal* j,
- const char* transactionIdVar,
- const void** data,
- size_t length) = 0;
- virtual void sd_journal_close(sd_journal* j) = 0;
+ public:
+ virtual void journalSync() = 0;
+ virtual int sd_journal_open(sd_journal** j, int k) = 0;
+ virtual int sd_journal_get_data(sd_journal* j, const char* transactionIdVar,
+ const void** data, size_t length) = 0;
+ virtual void sd_journal_close(sd_journal* j) = 0;
};
class journalImpl : public journalInterface
{
- public:
- void journalSync();
- int sd_journal_open(sd_journal** j, int k);
- int sd_journal_get_data(sd_journal* j,
- const char* transactionIdVar,
- const void** data,
- size_t length);
- void sd_journal_close(sd_journal* j);
+ public:
+ void journalSync();
+ int sd_journal_open(sd_journal** j, int k);
+ int sd_journal_get_data(sd_journal* j, const char* transactionIdVar,
+ const void** data, size_t length);
+ void sd_journal_close(sd_journal* j);
};
-
-
int journalImpl::sd_journal_open(sd_journal** j, int k)
{
return 1;
@@ -57,8 +54,7 @@ void journalImpl::journalSync()
int journalImpl::sd_journal_get_data(sd_journal* j,
const char* transactionIdVar,
- const void** data,
- size_t length)
+ const void** data, size_t length)
{
return 1;
}
@@ -68,42 +64,36 @@ void journalImpl::sd_journal_close(sd_journal* j)
return;
}
-
-class MockJournal : public Manager
+class MockJournal : public Manager
{
- public:
- MockJournal(sdbusplus::bus::bus& bus,
- const char* objPath): Manager(bus, objPath) {};
- MOCK_METHOD0(journalSync, void());
- MOCK_METHOD2(sd_journal_open, int(sd_journal**, int));
- MOCK_METHOD4(sd_journal_get_data, int(sd_journal*,
- const char*,
- const void**, size_t));
- MOCK_METHOD1(sd_journal_close, void(sd_journal*));
+ public:
+ MockJournal(sdbusplus::bus::bus& bus, const char* objPath) :
+ Manager(bus, objPath){};
+ MOCK_METHOD0(journalSync, void());
+ MOCK_METHOD2(sd_journal_open, int(sd_journal**, int));
+ MOCK_METHOD4(sd_journal_get_data,
+ int(sd_journal*, const char*, const void**, size_t));
+ MOCK_METHOD1(sd_journal_close, void(sd_journal*));
};
-
-
class TestLogManager : public testing::Test
{
- public:
- sdbusplus::bus::bus bus;
- MockJournal manager;
- TestLogManager()
- : bus(sdbusplus::bus::new_default()),
- manager(bus, "/xyz/openbmc_test/abc")
- {
- fs::create_directories(ERRLOG_PERSIST_PATH);
- }
-
- ~TestLogManager()
- {
- fs::remove_all(ERRLOG_PERSIST_PATH);
- }
-
+ public:
+ sdbusplus::bus::bus bus;
+ MockJournal manager;
+ TestLogManager() :
+ bus(sdbusplus::bus::new_default()),
+ manager(bus, "/xyz/openbmc_test/abc")
+ {
+ fs::create_directories(ERRLOG_PERSIST_PATH);
+ }
+
+ ~TestLogManager()
+ {
+ fs::remove_all(ERRLOG_PERSIST_PATH);
+ }
};
-
-}// nmaespace internal
-}// namespace logging
-}// namespace phosphor
+} // namespace internal
+} // namespace logging
+} // namespace phosphor
diff --git a/test/remote_logging_test_address.cpp b/test/remote_logging_test_address.cpp
index 1291a2e..5c8794e 100644
--- a/test/remote_logging_test_address.cpp
+++ b/test/remote_logging_test_address.cpp
@@ -21,6 +21,6 @@ TEST_F(TestRemoteLogging, testBadAddress)
EXPECT_THROW(config->address("not_an_IP"), InvalidArgument);
}
-}// namespace test
-}// namespace logging
-}// namespace phosphor
+} // namespace test
+} // namespace logging
+} // namespace phosphor
diff --git a/test/remote_logging_test_config.cpp b/test/remote_logging_test_config.cpp
index 8c3a98a..59feedd 100644
--- a/test/remote_logging_test_config.cpp
+++ b/test/remote_logging_test_config.cpp
@@ -1,4 +1,5 @@
#include "remote_logging_tests.hpp"
+
#include <fstream>
namespace phosphor
@@ -53,6 +54,6 @@ TEST_F(TestRemoteLogging, testClearPort)
EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port");
}
-}// namespace test
-}// namespace logging
-}// namespace phosphor
+} // namespace test
+} // namespace logging
+} // namespace phosphor
diff --git a/test/remote_logging_test_port.cpp b/test/remote_logging_test_port.cpp
index a9d3bc3..cf1a42e 100644
--- a/test/remote_logging_test_port.cpp
+++ b/test/remote_logging_test_port.cpp
@@ -13,6 +13,6 @@ TEST_F(TestRemoteLogging, testGoodPort)
EXPECT_EQ(config->port(), 100);
}
-}// namespace test
-}// namespace logging
-}// namespace phosphor
+} // namespace test
+} // namespace logging
+} // namespace phosphor
diff --git a/test/remote_logging_tests.hpp b/test/remote_logging_tests.hpp
index 3606f5a..936e3bb 100644
--- a/test/remote_logging_tests.hpp
+++ b/test/remote_logging_tests.hpp
@@ -1,9 +1,12 @@
-#include <gtest/gtest.h>
-#include <experimental/filesystem>
-#include <sdbusplus/bus.hpp>
#include "config.h"
+
#include "phosphor-rsyslog-config/server-conf.hpp"
+
+#include <experimental/filesystem>
+#include <sdbusplus/bus.hpp>
+
#include "gmock/gmock.h"
+#include <gtest/gtest.h>
namespace phosphor
{
@@ -20,45 +23,40 @@ fs::path dir(fs::path(mkdtemp(tmplt)));
class MockServer : public phosphor::rsyslog_config::Server
{
- public:
- MockServer(sdbusplus::bus::bus& bus,
- const std::string& path,
+ public:
+ MockServer(sdbusplus::bus::bus& bus, const std::string& path,
const char* filePath) :
- phosphor::rsyslog_config::Server(bus, path, filePath)
- {
- }
+ phosphor::rsyslog_config::Server(bus, path, filePath)
+ {
+ }
- MOCK_METHOD0(restart, void());
+ MOCK_METHOD0(restart, void());
};
class TestRemoteLogging : public testing::Test
{
- public:
- TestRemoteLogging()
- {
- configFilePath = std::string(dir.c_str()) + "/server.conf";
- config =
- new MockServer(bus,
- BUSPATH_REMOTE_LOGGING_CONFIG,
- configFilePath.c_str());
- }
-
- ~TestRemoteLogging()
- {
- delete config;
- }
-
- static void TearDownTestCase()
- {
- fs::remove_all(dir);
- }
-
- MockServer* config;
- std::string configFilePath;
+ public:
+ TestRemoteLogging()
+ {
+ configFilePath = std::string(dir.c_str()) + "/server.conf";
+ config = new MockServer(bus, BUSPATH_REMOTE_LOGGING_CONFIG,
+ configFilePath.c_str());
+ }
+
+ ~TestRemoteLogging()
+ {
+ delete config;
+ }
+
+ static void TearDownTestCase()
+ {
+ fs::remove_all(dir);
+ }
+
+ MockServer* config;
+ std::string configFilePath;
};
} // namespace test
} // namespace logging
} // namespace phosphor
-
-
diff --git a/test/serialization_test_path.cpp b/test/serialization_test_path.cpp
index 50e7d08..379b124 100644
--- a/test/serialization_test_path.cpp
+++ b/test/serialization_test_path.cpp
@@ -1,6 +1,6 @@
-#include "serialization_tests.hpp"
#include "elog_entry.hpp"
#include "elog_serialize.hpp"
+#include "serialization_tests.hpp"
namespace phosphor
{
@@ -13,10 +13,7 @@ TEST_F(TestSerialization, testPath)
{
auto id = 99;
auto e = std::make_unique<Entry>(
- bus,
- std::string(OBJ_ENTRY) + '/' + std::to_string(id),
- id,
- manager);
+ bus, std::string(OBJ_ENTRY) + '/' + std::to_string(id), id, manager);
auto path = serialize(*e, TestSerialization::dir);
EXPECT_EQ(path.c_str(), TestSerialization::dir / std::to_string(id));
}
@@ -24,5 +21,3 @@ TEST_F(TestSerialization, testPath)
} // namespace test
} // namespace logging
} // namespace phosphor
-
-
diff --git a/test/serialization_test_properties.cpp b/test/serialization_test_properties.cpp
index be9a7c7..8c92024 100644
--- a/test/serialization_test_properties.cpp
+++ b/test/serialization_test_properties.cpp
@@ -1,6 +1,6 @@
-#include "serialization_tests.hpp"
#include "elog_entry.hpp"
#include "elog_serialize.hpp"
+#include "serialization_tests.hpp"
namespace phosphor
{
@@ -18,25 +18,15 @@ TEST_F(TestSerialization, testProperties)
std::string message{"test error"};
std::string fwLevel{"level42"};
auto input = std::make_unique<Entry>(
- bus,
- std::string(OBJ_ENTRY) + '/' + std::to_string(id),
- id,
- timestamp,
- Entry::Level::Informational,
- std::move(message),
- std::move(testData),
- std::move(assocations),
- fwLevel,
- manager);
+ bus, std::string(OBJ_ENTRY) + '/' + std::to_string(id), id, timestamp,
+ Entry::Level::Informational, std::move(message), std::move(testData),
+ std::move(assocations), fwLevel, manager);
auto path = serialize(*input, TestSerialization::dir);
auto idStr = path.filename().c_str();
id = std::stol(idStr);
auto output = std::make_unique<Entry>(
- bus,
- std::string(OBJ_ENTRY) + '/' + idStr,
- id,
- manager);
+ bus, std::string(OBJ_ENTRY) + '/' + idStr, id, manager);
deserialize(path, *output);
EXPECT_EQ(input->id(), output->id());
@@ -53,5 +43,3 @@ TEST_F(TestSerialization, testProperties)
} // namespace test
} // namespace logging
} // namespace phosphor
-
-
diff --git a/test/serialization_tests.hpp b/test/serialization_tests.hpp
index a8054d3..6e41379 100644
--- a/test/serialization_tests.hpp
+++ b/test/serialization_tests.hpp
@@ -1,9 +1,13 @@
-#include <gtest/gtest.h>
-#include <experimental/filesystem>
+#include "config.h"
+
+#include "log_manager.hpp"
+
#include <stdlib.h>
+
+#include <experimental/filesystem>
#include <sdbusplus/bus.hpp>
-#include "log_manager.hpp"
-#include "config.h"
+
+#include <gtest/gtest.h>
namespace phosphor
{
@@ -20,22 +24,19 @@ phosphor::logging::internal::Manager manager(bus, OBJ_INTERNAL);
class TestSerialization : public testing::Test
{
- public:
- TestSerialization() :
- dir(fs::path(mkdtemp(tmplt)))
- {
- }
-
- ~TestSerialization()
- {
- fs::remove_all(dir);
- }
-
- fs::path dir;
+ public:
+ TestSerialization() : dir(fs::path(mkdtemp(tmplt)))
+ {
+ }
+
+ ~TestSerialization()
+ {
+ fs::remove_all(dir);
+ }
+
+ fs::path dir;
};
} // namespace test
} // namespace logging
} // namespace phosphor
-
-
OpenPOWER on IntegriCloud