Enable clang-format
Ideally would have done this from the beginning,
but better later than never.
Change-Id: Ib4c73085c4817496c9f2ee505c19149a67b394dc
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..bbc1bb1
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,85 @@
+---
+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: false
+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: true
+PointerAlignment: Left
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
+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
+PointerAlignment: Right
+ReflowComments: true
+SortIncludes: false
+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/dbus.cpp b/dbus.cpp
index 1741019..17ad210 100644
--- a/dbus.cpp
+++ b/dbus.cpp
@@ -21,18 +21,15 @@
namespace logging
{
-ObjectValueTree getManagedObjects(
- sdbusplus::bus::bus& bus,
- const std::string& service,
- const std::string& objPath)
+ObjectValueTree getManagedObjects(sdbusplus::bus::bus& bus,
+ const std::string& service,
+ const std::string& objPath)
{
ObjectValueTree interfaces;
- auto method = bus.new_method_call(
- service.c_str(),
- objPath.c_str(),
- "org.freedesktop.DBus.ObjectManager",
- "GetManagedObjects");
+ auto method = bus.new_method_call(service.c_str(), objPath.c_str(),
+ "org.freedesktop.DBus.ObjectManager",
+ "GetManagedObjects");
auto reply = bus.call(method);
@@ -40,7 +37,7 @@
{
using namespace phosphor::logging;
log<level::ERR>("Failed to get managed objects",
- entry("PATH=%s", objPath.c_str()));
+ entry("PATH=%s", objPath.c_str()));
}
else
{
@@ -49,6 +46,5 @@
return interfaces;
}
-
}
}
diff --git a/dbus.hpp b/dbus.hpp
index 468e327..38e62bd 100644
--- a/dbus.hpp
+++ b/dbus.hpp
@@ -12,8 +12,7 @@
using DbusInterface = std::string;
using DbusProperty = std::string;
-using Value = sdbusplus::message::variant<bool, uint32_t, uint64_t,
- std::string,
+using Value = sdbusplus::message::variant<bool, uint32_t, uint64_t, std::string,
std::vector<std::string>>;
using DbusPropertyMap = std::map<DbusProperty, Value>;
@@ -23,10 +22,8 @@
using ObjectValueTree =
std::map<sdbusplus::message::object_path, DbusInterfaceMap>;
-ObjectValueTree getManagedObjects(
- sdbusplus::bus::bus& bus,
- const std::string& service,
- const std::string& objPath);
+ObjectValueTree getManagedObjects(sdbusplus::bus::bus& bus,
+ const std::string& service,
+ const std::string& objPath);
}
}
-
diff --git a/interfaces.hpp b/interfaces.hpp
index df62545..0dfa668 100644
--- a/interfaces.hpp
+++ b/interfaces.hpp
@@ -17,6 +17,5 @@
{
POLICY
};
-
}
}
diff --git a/manager.cpp b/manager.cpp
index f09464a..59d7d44 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -23,21 +23,20 @@
{
Manager::Manager(sdbusplus::bus::bus& bus) :
- bus(bus),
- addMatch(
- bus,
- sdbusplus::bus::match::rules::interfacesAdded() +
- sdbusplus::bus::match::rules::path_namespace(LOGGING_PATH),
- std::bind(std::mem_fn(&Manager::interfaceAdded),
- this, std::placeholders::_1)),
- removeMatch(
- bus,
+ bus(bus),
+ addMatch(bus,
+ sdbusplus::bus::match::rules::interfacesAdded() +
+ sdbusplus::bus::match::rules::path_namespace(LOGGING_PATH),
+ std::bind(std::mem_fn(&Manager::interfaceAdded), this,
+ std::placeholders::_1)),
+ removeMatch(bus,
sdbusplus::bus::match::rules::interfacesRemoved() +
- sdbusplus::bus::match::rules::path_namespace(LOGGING_PATH),
- std::bind(std::mem_fn(&Manager::interfaceRemoved),
- this, std::placeholders::_1))
+ sdbusplus::bus::match::rules::path_namespace(LOGGING_PATH),
+ std::bind(std::mem_fn(&Manager::interfaceRemoved), this,
+ std::placeholders::_1))
#ifdef USE_POLICY_INTERFACE
- , policies(POLICY_JSON_PATH)
+ ,
+ policies(POLICY_JSON_PATH)
#endif
{
createAll();
@@ -45,20 +44,15 @@
void Manager::createAll()
{
- auto objects = getManagedObjects(
- bus, LOGGING_BUSNAME, LOGGING_PATH);
+ auto objects = getManagedObjects(bus, LOGGING_BUSNAME, LOGGING_PATH);
for (const auto& object : objects)
{
const auto& interfaces = object.second;
auto propertyMap = std::find_if(
- interfaces.begin(),
- interfaces.end(),
- [](const auto& i)
- {
- return i.first == LOGGING_IFACE;
- });
+ interfaces.begin(), interfaces.end(),
+ [](const auto& i) { return i.first == LOGGING_IFACE; });
if (propertyMap != interfaces.end())
{
@@ -67,26 +61,22 @@
}
}
-void Manager::create(
- const std::string& objectPath,
- const DbusPropertyMap& properties)
+void Manager::create(const std::string& objectPath,
+ const DbusPropertyMap& properties)
{
#ifdef USE_POLICY_INTERFACE
createPolicyInterface(objectPath, properties);
#endif
-
}
#ifdef USE_POLICY_INTERFACE
-void Manager::createPolicyInterface(
- const std::string& objectPath,
- const DbusPropertyMap& properties)
+void Manager::createPolicyInterface(const std::string& objectPath,
+ const DbusPropertyMap& properties)
{
auto values = policy::find(policies, properties);
- auto object = std::make_shared<PolicyObject>(
- bus, objectPath.c_str(), true);
+ auto object = std::make_shared<PolicyObject>(bus, objectPath.c_str(), true);
object->eventID(std::get<policy::EIDField>(values));
object->description(std::get<policy::MsgField>(values));
@@ -109,7 +99,6 @@
}
#endif
-
void Manager::interfaceAdded(sdbusplus::message::message& msg)
{
sdbusplus::message::object_path path;
@@ -117,15 +106,11 @@
msg.read(path, interfaces);
- //Find the Logging.Entry interface with all of its properties
- //to pass to create().
- auto propertyMap = std::find_if(
- interfaces.begin(),
- interfaces.end(),
- [](const auto& i)
- {
- return i.first == LOGGING_IFACE;
- });
+ // Find the Logging.Entry interface with all of its properties
+ // to pass to create().
+ auto propertyMap =
+ std::find_if(interfaces.begin(), interfaces.end(),
+ [](const auto& i) { return i.first == LOGGING_IFACE; });
if (propertyMap != interfaces.end())
{
@@ -140,13 +125,10 @@
msg.read(path, interfaces);
- //If the Logging.Entry interface was removed, then remove
- //our object
+ // If the Logging.Entry interface was removed, then remove
+ // our object
- auto i = std::find(
- interfaces.begin(),
- interfaces.end(),
- LOGGING_IFACE);
+ auto i = std::find(interfaces.begin(), interfaces.end(), LOGGING_IFACE);
if (i != interfaces.end())
{
@@ -159,6 +141,5 @@
}
}
}
-
}
}
diff --git a/manager.hpp b/manager.hpp
index 60b3d75..55d6f5c 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -16,7 +16,6 @@
namespace logging
{
-
/**
* @class Manager
*
@@ -28,120 +27,115 @@
*/
class Manager
{
- public:
+ public:
+ Manager() = delete;
+ ~Manager() = default;
+ Manager(const Manager&) = delete;
+ Manager& operator=(const Manager&) = delete;
+ Manager(Manager&&) = delete;
+ Manager& operator=(Manager&&) = delete;
- Manager() = delete;
- ~Manager() = default;
- Manager(const Manager&) = delete;
- Manager& operator=(const Manager&) = delete;
- Manager(Manager&&) = delete;
- Manager& operator=(Manager&&) = delete;
+ /**
+ * Constructor
+ *
+ * @param[in] bus - the D-Bus bus object
+ */
+ explicit Manager(sdbusplus::bus::bus& bus);
- /**
- * Constructor
- *
- * @param[in] bus - the D-Bus bus object
- */
- explicit Manager(sdbusplus::bus::bus& bus);
+ private:
+ /**
+ * The callback for an interfaces added signal
+ *
+ * Creates the IBM interfaces for the log entry
+ * that was just created.
+ *
+ * @param[in] msg - the sdbusplus message
+ */
+ void interfaceAdded(sdbusplus::message::message& msg);
- private:
+ /**
+ * The callback for an interfaces removed signal
+ *
+ * Removes the IBM interfaces for the log entry
+ * that was just removed.
+ *
+ * @param[in] msg - the sdbusplus message
+ */
+ void interfaceRemoved(sdbusplus::message::message& msg);
- /**
- * The callback for an interfaces added signal
- *
- * Creates the IBM interfaces for the log entry
- * that was just created.
- *
- * @param[in] msg - the sdbusplus message
- */
- void interfaceAdded(sdbusplus::message::message& msg);
+ /**
+ * Creates the IBM interfaces for all existing error log
+ * entries.
+ */
+ void createAll();
- /**
- * The callback for an interfaces removed signal
- *
- * Removes the IBM interfaces for the log entry
- * that was just removed.
- *
- * @param[in] msg - the sdbusplus message
- */
- void interfaceRemoved(sdbusplus::message::message& msg);
-
- /**
- * Creates the IBM interfaces for all existing error log
- * entries.
- */
- void createAll();
-
- /**
- * Creates the IBM interface(s) for a single error log.
- *
- * @param[in] objectPath - object path of the error log
- * @param[in] properties - the xyz.openbmc_project.Logging.Entry
- * properties
- */
- void create(
- const std::string& objectPath,
+ /**
+ * Creates the IBM interface(s) for a single error log.
+ *
+ * @param[in] objectPath - object path of the error log
+ * @param[in] properties - the xyz.openbmc_project.Logging.Entry
+ * properties
+ */
+ void create(const std::string& objectPath,
const DbusPropertyMap& properties);
- /**
- * Creates the IBM policy interface for a single error log
- * and saves it in the list of interfaces.
- *
- * @param[in] objectPath - object path of the error log
- * @param[in] properties - the xyz.openbmc_project.Logging.Entry
- * properties
- */
+ /**
+ * Creates the IBM policy interface for a single error log
+ * and saves it in the list of interfaces.
+ *
+ * @param[in] objectPath - object path of the error log
+ * @param[in] properties - the xyz.openbmc_project.Logging.Entry
+ * properties
+ */
#ifdef USE_POLICY_INTERFACE
- void createPolicyInterface(
- const std::string& objectPath,
- const DbusPropertyMap& properties);
+ void createPolicyInterface(const std::string& objectPath,
+ const DbusPropertyMap& properties);
#endif
- /**
- * Returns the entry ID for a log
- *
- * @param[in] objectPath - the object path of the log
- *
- * @return uint32_t - the ID
- */
- inline uint32_t getEntryID(const std::string& objectPath)
- {
- std::experimental::filesystem::path path(objectPath);
- return std::stoul(path.filename());
- }
+ /**
+ * Returns the entry ID for a log
+ *
+ * @param[in] objectPath - the object path of the log
+ *
+ * @return uint32_t - the ID
+ */
+ inline uint32_t getEntryID(const std::string& objectPath)
+ {
+ std::experimental::filesystem::path path(objectPath);
+ return std::stoul(path.filename());
+ }
- /**
- * The sdbusplus bus object
- */
- sdbusplus::bus::bus& bus;
+ /**
+ * The sdbusplus bus object
+ */
+ sdbusplus::bus::bus& bus;
- /**
- * The match object for interfacesAdded
- */
- sdbusplus::bus::match_t addMatch;
+ /**
+ * The match object for interfacesAdded
+ */
+ sdbusplus::bus::match_t addMatch;
- /**
- * The match object for interfacesRemoved
- */
- sdbusplus::bus::match_t removeMatch;
+ /**
+ * The match object for interfacesRemoved
+ */
+ sdbusplus::bus::match_t removeMatch;
- using EntryID = uint32_t;
- using InterfaceMap = std::map<InterfaceType, std::experimental::any>;
- using EntryMap = std::map<EntryID, InterfaceMap>;
+ using EntryID = uint32_t;
+ using InterfaceMap = std::map<InterfaceType, std::experimental::any>;
+ using EntryMap = std::map<EntryID, InterfaceMap>;
- /**
- * A map of the error log IDs to their IBM interface objects.
- * There may be multiple interfaces per ID.
- */
- EntryMap entries;
+ /**
+ * A map of the error log IDs to their IBM interface objects.
+ * There may be multiple interfaces per ID.
+ */
+ EntryMap entries;
#ifdef USE_POLICY_INTERFACE
- /**
- * The class the wraps the IBM error logging policy table.
- */
- policy::Table policies;
+ /**
+ * The class the wraps the IBM error logging policy table.
+ */
+ policy::Table policies;
#endif
};
-
}
}
diff --git a/policy_find.cpp b/policy_find.cpp
index daf872c..b8b671a 100644
--- a/policy_find.cpp
+++ b/policy_find.cpp
@@ -35,10 +35,9 @@
*
* @return optional<T> - the property value
*/
-template<typename T>
-optional_ns::optional<T> getProperty(
- const DbusPropertyMap& properties,
- const std::string& name)
+template <typename T>
+optional_ns::optional<T> getProperty(const DbusPropertyMap& properties,
+ const std::string& name)
{
auto prop = properties.find(name);
@@ -61,13 +60,13 @@
*
* @return optional<std::string> - the data value
*/
-optional_ns::optional<std::string> getAdditionalDataItem(
- const std::vector<std::string>& additionalData,
- const std::string& name)
+optional_ns::optional<std::string>
+ getAdditionalDataItem(const std::vector<std::string>& additionalData,
+ const std::string& name)
{
for (const auto& item : additionalData)
{
- if (item.find(name+"=") != std::string::npos)
+ if (item.find(name + "=") != std::string::npos)
{
return item.substr(item.find('=') + 1);
}
@@ -91,8 +90,7 @@
* @return string - the search modifier
* may be empty if none found
*/
-auto getSearchModifier(
- const DbusPropertyMap& properties)
+auto getSearchModifier(const DbusPropertyMap& properties)
{
// The modifier may be one of several things within the
// AdditionalData property. Try them all until one
@@ -151,8 +149,8 @@
if (!value.empty())
{
- std::transform(
- value.begin(), value.end(), value.begin(), toupper);
+ std::transform(value.begin(), value.end(), value.begin(),
+ toupper);
return value;
}
}
@@ -167,12 +165,11 @@
return std::string{};
}
-PolicyProps find(
- const policy::Table& policy,
- const DbusPropertyMap& errorLogProperties)
+PolicyProps find(const policy::Table& policy,
+ const DbusPropertyMap& errorLogProperties)
{
- auto errorMsg = getProperty<std::string>(
- errorLogProperties, "Message"); //e.g. xyz.X.Error.Y
+ auto errorMsg = getProperty<std::string>(errorLogProperties,
+ "Message"); // e.g. xyz.X.Error.Y
if (errorMsg)
{
auto modifier = getSearchModifier(errorLogProperties);
@@ -192,7 +189,6 @@
return {policy.defaultEID(), policy.defaultMsg()};
}
-
}
}
}
diff --git a/policy_find.hpp b/policy_find.hpp
index 7dd415a..e8a4c50 100644
--- a/policy_find.hpp
+++ b/policy_find.hpp
@@ -24,10 +24,8 @@
* interface
* @return PolicyProps - a tuple of policy details.
*/
-PolicyProps find(
- const Table& policy,
- const DbusPropertyMap& errorLogProperties);
-
+PolicyProps find(const Table& policy,
+ const DbusPropertyMap& errorLogProperties);
}
}
}
diff --git a/policy_table.cpp b/policy_table.cpp
index 429c2c4..a912667 100644
--- a/policy_table.cpp
+++ b/policy_table.cpp
@@ -38,7 +38,7 @@
else
{
log<level::INFO>("Policy table JSON file does not exist",
- entry("FILE=%s", jsonFile.c_str()));
+ entry("FILE=%s", jsonFile.c_str()));
}
}
@@ -70,33 +70,30 @@
catch (std::exception& e)
{
log<level::ERR>("Failed loading policy table json file",
- entry("FILE=%s", jsonFile.c_str()),
- entry("ERROR=%s", e.what()));
+ entry("FILE=%s", jsonFile.c_str()),
+ entry("ERROR=%s", e.what()));
loaded = false;
}
}
-optional_ns::optional<DetailsReference> Table::find(
- const std::string& error,
- const std::string& modifier) const
+optional_ns::optional<DetailsReference>
+ Table::find(const std::string& error, const std::string& modifier) const
{
- //First find the entry based on the error, and then find which
- //underlying details object it is with the help of the modifier.
+ // First find the entry based on the error, and then find which
+ // underlying details object it is with the help of the modifier.
auto policy = policies.find(error);
if (policy != policies.end())
{
- //Not all policy entries have a modifier defined, so if it is
- //empty that will return as a match.
+ // Not all policy entries have a modifier defined, so if it is
+ // empty that will return as a match.
auto details = std::find_if(
- policy->second.begin(),
- policy->second.end(),
- [&modifier](const auto& d)
- {
- return d.modifier.empty() || (modifier == d.modifier);
- });
+ policy->second.begin(), policy->second.end(),
+ [&modifier](const auto& d) {
+ return d.modifier.empty() || (modifier == d.modifier);
+ });
if (details != policy->second.end())
{
@@ -106,8 +103,6 @@
return {};
}
-
-
}
}
}
diff --git a/policy_table.hpp b/policy_table.hpp
index 07226e6..9272daa 100644
--- a/policy_table.hpp
+++ b/policy_table.hpp
@@ -12,7 +12,6 @@
namespace policy
{
-
/**
* The details of a policy table entry:
* - search modifier
@@ -43,98 +42,94 @@
*/
class Table
{
- public:
+ public:
+ Table() = delete;
+ ~Table() = default;
+ Table(const Table&) = default;
+ Table& operator=(const Table&) = default;
+ Table(Table&&) = default;
+ Table& operator=(Table&&) = default;
- Table() = delete;
- ~Table() = default;
- Table(const Table&) = default;
- Table& operator=(const Table&) = default;
- Table(Table&&) = default;
- Table& operator=(Table&&) = default;
+ /**
+ * Constructor
+ *
+ * @param[in] jsonFile - the path to the policy JSON.
+ */
+ explicit Table(const std::string& jsonFile);
- /**
- * Constructor
- *
- * @param[in] jsonFile - the path to the policy JSON.
- */
- explicit Table(const std::string& jsonFile);
+ /**
+ * Says if the JSON has been loaded successfully.
+ *
+ * @return bool
+ */
+ inline bool isLoaded() const
+ {
+ return loaded;
+ }
- /**
- * Says if the JSON has been loaded successfully.
- *
- * @return bool
- */
- inline bool isLoaded() const
- {
- return loaded;
- }
+ /**
+ * Finds an entry in the policy table based on the
+ * error and the search modifier.
+ *
+ * @param[in] error - the error, like xyz.openbmc_project.Error.X
+ * @param[in] modifier - the search modifier, used to find the entry
+ * when multiple ones share the same error
+ *
+ * @return optional<DetailsReference> - the details entry
+ */
+ optional_ns::optional<DetailsReference>
+ find(const std::string& error, const std::string& modifier) const;
- /**
- * Finds an entry in the policy table based on the
- * error and the search modifier.
- *
- * @param[in] error - the error, like xyz.openbmc_project.Error.X
- * @param[in] modifier - the search modifier, used to find the entry
- * when multiple ones share the same error
- *
- * @return optional<DetailsReference> - the details entry
- */
- optional_ns::optional<DetailsReference> find(
- const std::string& error,
- const std::string& modifier) const;
+ /**
+ * The default event ID to use when a match in the table
+ * wasn't found.
+ *
+ * @return std::string
+ */
+ inline std::string defaultEID() const
+ {
+ return defaultPolicyEID;
+ }
- /**
- * The default event ID to use when a match in the table
- * wasn't found.
- *
- * @return std::string
- */
- inline std::string defaultEID() const
- {
- return defaultPolicyEID;
- }
+ /**
+ * The default error message to use when a match in the table
+ * wasn't found.
+ *
+ * @return std::string
+ */
+ inline std::string defaultMsg() const
+ {
+ return defaultPolicyMessage;
+ }
- /**
- * The default error message to use when a match in the table
- * wasn't found.
- *
- * @return std::string
- */
- inline std::string defaultMsg() const
- {
- return defaultPolicyMessage;
- }
+ private:
+ /**
+ * The default event ID
+ */
+ const std::string defaultPolicyEID{DEFAULT_POLICY_EID};
- private:
- /**
- * The default event ID
- */
- const std::string defaultPolicyEID{DEFAULT_POLICY_EID};
+ /**
+ * The default event message
+ */
+ const std::string defaultPolicyMessage{DEFAULT_POLICY_MSG};
- /**
- * The default event message
- */
- const std::string defaultPolicyMessage{DEFAULT_POLICY_MSG};
+ /**
+ * Loads the JSON data into the PolicyMap map
+ *
+ * @param[in] jsonFile - the path to the .json file
+ */
+ void load(const std::string& jsonFile);
- /**
- * Loads the JSON data into the PolicyMap map
- *
- * @param[in] jsonFile - the path to the .json file
- */
- void load(const std::string& jsonFile);
+ /**
+ * Reflects if the JSON was successfully loaded or not.
+ */
+ bool loaded = false;
- /**
- * Reflects if the JSON was successfully loaded or not.
- */
- bool loaded = false;
-
- /**
- * The policy table
- */
- PolicyMap policies;
+ /**
+ * The policy table
+ */
+ PolicyMap policies;
};
-
-
}
}
}
diff --git a/test/test_policy.cpp b/test/test_policy.cpp
index 0993e8f..a9cb0ec 100644
--- a/test/test_policy.cpp
+++ b/test/test_policy.cpp
@@ -117,36 +117,33 @@
}
])";
-
/**
* Helper class to write the above json to a file and then
* remove it when the tests are over.
*/
class PolicyTableTest : public ::testing::Test
{
- protected:
+ protected:
+ virtual void SetUp()
+ {
+ char dir[] = {"./jsonTestXXXXXX"};
- virtual void SetUp()
- {
- char dir[] = {"./jsonTestXXXXXX"};
+ jsonDir = mkdtemp(dir);
+ jsonFile = jsonDir / "policy.json";
- jsonDir = mkdtemp(dir);
- jsonFile = jsonDir / "policy.json";
+ std::ofstream f{jsonFile};
+ f << json;
+ }
- std::ofstream f{jsonFile};
- f << json;
- }
+ virtual void TearDown()
+ {
+ fs::remove_all(jsonDir);
+ }
- virtual void TearDown()
- {
- fs::remove_all(jsonDir);
- }
-
- fs::path jsonDir;
- fs::path jsonFile;
+ fs::path jsonDir;
+ fs::path jsonFile;
};
-
/**
* Test finding entries in the policy table
*/
@@ -156,7 +153,7 @@
ASSERT_EQ(policy.isLoaded(), true);
////////////////////////////////////
- //Basic search, no modifier
+ // Basic search, no modifier
std::string err{"xyz.openbmc_project.Error.Test2"};
std::string mod;
@@ -169,13 +166,13 @@
}
/////////////////////////////////////
- //Not found
+ // Not found
err = "foo";
details = policy.find(err, mod);
ASSERT_EQ(static_cast<bool>(details), false);
/////////////////////////////////////
- //Test with a modifier
+ // Test with a modifier
err = "xyz.openbmc_project.Error.Test3";
mod = "mod3";
@@ -199,120 +196,93 @@
policy::Table policy{jsonFile};
ASSERT_EQ(policy.isLoaded(), true);
- //A basic search with no modifier
+ // A basic search with no modifier
{
- DbusPropertyMap testProperties
- {
- {"Message"s, Value{"xyz.openbmc_project.Error.Test1"s}}
- };
+ DbusPropertyMap testProperties{
+ {"Message"s, Value{"xyz.openbmc_project.Error.Test1"s}}};
auto values = policy::find(policy, testProperties);
ASSERT_EQ(std::get<policy::EIDField>(values), "ABCD1234");
ASSERT_EQ(std::get<policy::MsgField>(values), "Error ABCD1234");
}
- //Use CALLOUT_INVENTORY_PATH from the AdditionalData property
+ // Use CALLOUT_INVENTORY_PATH from the AdditionalData property
{
- std::vector<std::string> ad{
- "FOO=BAR"s,
- "CALLOUT_INVENTORY_PATH=mod2"s};
- DbusPropertyMap testProperties
- {
+ std::vector<std::string> ad{"FOO=BAR"s, "CALLOUT_INVENTORY_PATH=mod2"s};
+ DbusPropertyMap testProperties{
{"Message"s, Value{"xyz.openbmc_project.Error.Test3"s}},
- {"AdditionalData"s, ad}
- };
+ {"AdditionalData"s, ad}};
auto values = policy::find(policy, testProperties);
ASSERT_EQ(std::get<policy::EIDField>(values), "BBBBBB");
ASSERT_EQ(std::get<policy::MsgField>(values), "Error BBBBBB");
}
- //Use an I2C DEVICE_PATH from the AdditionalData property
+ // Use an I2C DEVICE_PATH from the AdditionalData property
{
- std::vector<std::string> ad{
- "FOO=BAR"s,
- "CALLOUT_DEVICE_PATH=/some/i2c/path"s};
- DbusPropertyMap testProperties
- {
+ std::vector<std::string> ad{"FOO=BAR"s,
+ "CALLOUT_DEVICE_PATH=/some/i2c/path"s};
+ DbusPropertyMap testProperties{
{"Message"s, Value{"xyz.openbmc_project.Error.Test4"s}},
- {"AdditionalData"s, ad}
- };
+ {"AdditionalData"s, ad}};
auto values = policy::find(policy, testProperties);
ASSERT_EQ(std::get<policy::EIDField>(values), "DDDDDDDD");
ASSERT_EQ(std::get<policy::MsgField>(values), "Error DDDDDDDD");
}
- //Use an FSI DEVICE_PATH from the AdditionalData property
+ // Use an FSI DEVICE_PATH from the AdditionalData property
{
- std::vector<std::string> ad{
- "FOO=BAR"s,
- "CALLOUT_DEVICE_PATH=/some/fsi/path"s};
- DbusPropertyMap testProperties
- {
+ std::vector<std::string> ad{"FOO=BAR"s,
+ "CALLOUT_DEVICE_PATH=/some/fsi/path"s};
+ DbusPropertyMap testProperties{
{"Message"s, Value{"xyz.openbmc_project.Error.Test4"s}},
- {"AdditionalData"s, ad}
- };
+ {"AdditionalData"s, ad}};
auto values = policy::find(policy, testProperties);
ASSERT_EQ(std::get<policy::EIDField>(values), "EEEEEEEE");
ASSERT_EQ(std::get<policy::MsgField>(values), "Error EEEEEEEE");
}
- //Use PROCEDURE from the AdditionalData property
+ // Use PROCEDURE from the AdditionalData property
{
- std::vector<std::string> ad{
- "FOO=BAR"s,
- "PROCEDURE=109"s};
- DbusPropertyMap testProperties
- {
+ std::vector<std::string> ad{"FOO=BAR"s, "PROCEDURE=109"s};
+ DbusPropertyMap testProperties{
{"Message"s, Value{"xyz.openbmc_project.Error.Test5"s}},
- {"AdditionalData"s, ad}
- };
+ {"AdditionalData"s, ad}};
auto values = policy::find(policy, testProperties);
ASSERT_EQ(std::get<policy::EIDField>(values), "FFFFFFFF");
ASSERT_EQ(std::get<policy::MsgField>(values), "Error FFFFFFFF");
}
- //Use RAIL_NAME from the AdditionalData property
+ // Use RAIL_NAME from the AdditionalData property
{
- std::vector<std::string> ad{
- "FOO=BAR"s,
- "RAIL_NAME=RAIL_5"s};
- DbusPropertyMap testProperties
- {
+ std::vector<std::string> ad{"FOO=BAR"s, "RAIL_NAME=RAIL_5"s};
+ DbusPropertyMap testProperties{
{"Message"s, Value{"xyz.openbmc_project.Error.Test6"s}},
- {"AdditionalData"s, ad}
- };
+ {"AdditionalData"s, ad}};
auto values = policy::find(policy, testProperties);
ASSERT_EQ(std::get<policy::EIDField>(values), "GGGGGGGG");
ASSERT_EQ(std::get<policy::MsgField>(values), "Error GGGGGGGG");
}
- //Use INPUT_NAME from the AdditionalData property
+ // Use INPUT_NAME from the AdditionalData property
{
- std::vector<std::string> ad{
- "FOO=BAR"s,
- "INPUT_NAME=INPUT_42"s};
- DbusPropertyMap testProperties
- {
+ std::vector<std::string> ad{"FOO=BAR"s, "INPUT_NAME=INPUT_42"s};
+ DbusPropertyMap testProperties{
{"Message"s, Value{"xyz.openbmc_project.Error.Test7"s}},
- {"AdditionalData"s, ad}
- };
+ {"AdditionalData"s, ad}};
auto values = policy::find(policy, testProperties);
ASSERT_EQ(std::get<policy::EIDField>(values), "HHHHHHHH");
ASSERT_EQ(std::get<policy::MsgField>(values), "Error HHHHHHHH");
}
- //Test not finding an entry.
+ // Test not finding an entry.
{
- DbusPropertyMap testProperties
- {
- {"Message"s, Value{"hello world"s}}
- };
+ DbusPropertyMap testProperties{{"Message"s, Value{"hello world"s}}};
auto values = policy::find(policy, testProperties);
ASSERT_EQ(std::get<policy::EIDField>(values), policy.defaultEID());
@@ -321,18 +291,13 @@
// Test that strange AdditionalData values don't break anything
{
- std::vector<std::string> ad{
- "FOO"s,
- "INPUT_NAME="s};
- DbusPropertyMap testProperties
- {
+ std::vector<std::string> ad{"FOO"s, "INPUT_NAME="s};
+ DbusPropertyMap testProperties{
{"Message"s, Value{"xyz.openbmc_project.Error.Test7"s}},
- {"AdditionalData"s, ad}
- };
+ {"AdditionalData"s, ad}};
auto values = policy::find(policy, testProperties);
ASSERT_EQ(std::get<policy::EIDField>(values), policy.defaultEID());
ASSERT_EQ(std::get<policy::MsgField>(values), policy.defaultMsg());
}
}
-