add Associations endpoints change delay timer
When multiple associations that point to the same interface are
created, each change (adding or removing one) leads to updating
"endpoints" property on dbus. This property update is time consuming
with many endpoints already present, because each update needs to send
the whole list of current elements plus/minus one. With a lot of
changes in short time it can cause the service to be unresponsive.
This change adds timer to delay updating dbus property. This way many
associations updates can be aggregated into single dbus property
update.
Tested: Ran on hardware with dbus sensor tester. 4000 created sensors
with interfaces are processed within 10 seconds. Time before the change
was above 2 minutes.
Signed-off-by: Kallas, Pawel <pawel.kallas@intel.com>
Change-Id: I1083c027ab12238249cffc67fb29a8ffef6baf83
diff --git a/src/associations.cpp b/src/associations.cpp
index 6dbc710..346cebd 100644
--- a/src/associations.cpp
+++ b/src/associations.cpp
@@ -1,11 +1,81 @@
#include "associations.hpp"
+#include <boost/asio/steady_timer.hpp>
#include <sdbusplus/exception.hpp>
#include <iostream>
#include <string>
-void removeAssociation(const std::string& sourcePath, const std::string& owner,
+void updateEndpointsOnDbus(sdbusplus::asio::object_server& objectServer,
+ const std::string& assocPath,
+ AssociationMaps& assocMaps)
+{
+ auto& iface = assocMaps.ifaces[assocPath];
+ auto& i = std::get<ifacePos>(iface);
+ auto& endpoints = std::get<endpointsPos>(iface);
+
+ // If the interface already exists, only need to update
+ // the property value, otherwise create it
+ if (i)
+ {
+ if (endpoints.empty())
+ {
+ objectServer.remove_interface(i);
+ i = nullptr;
+ }
+ else
+ {
+ i->set_property("endpoints", endpoints);
+ }
+ }
+ else
+ {
+ if (!endpoints.empty())
+ {
+ i = objectServer.add_interface(assocPath, xyzAssociationInterface);
+ i->register_property("endpoints", endpoints);
+ i->initialize();
+ }
+ }
+}
+
+void scheduleUpdateEndpointsOnDbus(boost::asio::io_context& io,
+ sdbusplus::asio::object_server& objectServer,
+ const std::string& assocPath,
+ AssociationMaps& assocMaps)
+{
+ static std::set<std::string> delayedUpdatePaths;
+
+ if (delayedUpdatePaths.contains(assocPath))
+ {
+ return;
+ }
+
+ auto& iface = assocMaps.ifaces[assocPath];
+ auto& endpoints = std::get<endpointsPos>(iface);
+
+ if (endpoints.size() > endpointsCountTimerThreshold)
+ {
+ delayedUpdatePaths.emplace(assocPath);
+ auto timer = std::make_shared<boost::asio::steady_timer>(
+ io, std::chrono::seconds(endpointUpdateDelaySeconds));
+ timer->async_wait([&objectServer, &assocMaps, timer,
+ assocPath](const boost::system::error_code& ec) {
+ if (!ec)
+ {
+ updateEndpointsOnDbus(objectServer, assocPath, assocMaps);
+ }
+ delayedUpdatePaths.erase(assocPath);
+ });
+ }
+ else
+ {
+ updateEndpointsOnDbus(objectServer, assocPath, assocMaps);
+ }
+}
+
+void removeAssociation(boost::asio::io_context& io,
+ const std::string& sourcePath, const std::string& owner,
sdbusplus::asio::object_server& server,
AssociationMaps& assocMaps)
{
@@ -35,7 +105,7 @@
for (const auto& [assocPath, endpointsToRemove] : assocs->second)
{
- removeAssociationEndpoints(server, assocPath, endpointsToRemove,
+ removeAssociationEndpoints(io, server, assocPath, endpointsToRemove,
assocMaps);
}
@@ -52,7 +122,8 @@
}
void removeAssociationEndpoints(
- sdbusplus::asio::object_server& objectServer, const std::string& assocPath,
+ boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
+ const std::string& assocPath,
const boost::container::flat_set<std::string>& endpointsToRemove,
AssociationMaps& assocMaps)
{
@@ -75,22 +146,12 @@
}
}
- if (endpointsInDBus.empty())
- {
- objectServer.remove_interface(std::get<ifacePos>(assoc->second));
- std::get<ifacePos>(assoc->second) = nullptr;
- std::get<endpointsPos>(assoc->second).clear();
- }
- else
- {
- std::get<ifacePos>(assoc->second)
- ->set_property("endpoints", endpointsInDBus);
- }
+ scheduleUpdateEndpointsOnDbus(io, objectServer, assocPath, assocMaps);
}
void checkAssociationEndpointRemoves(
- const std::string& sourcePath, const std::string& owner,
- const AssociationPaths& newAssociations,
+ boost::asio::io_context& io, const std::string& sourcePath,
+ const std::string& owner, const AssociationPaths& newAssociations,
sdbusplus::asio::object_server& objectServer, AssociationMaps& assocMaps)
{
// Find the services that have associations on this path.
@@ -119,7 +180,7 @@
auto newEndpoints = newAssociations.find(originalAssocPath);
if (newEndpoints == newAssociations.end())
{
- removeAssociationEndpoints(objectServer, originalAssocPath,
+ removeAssociationEndpoints(io, objectServer, originalAssocPath,
originalEndpoints, assocMaps);
}
else
@@ -139,7 +200,7 @@
}
if (!toRemove.empty())
{
- removeAssociationEndpoints(objectServer, originalAssocPath,
+ removeAssociationEndpoints(io, objectServer, originalAssocPath,
toRemove, assocMaps);
}
}
@@ -147,12 +208,12 @@
}
void addEndpointsToAssocIfaces(
- sdbusplus::asio::object_server& objectServer, const std::string& assocPath,
+ boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
+ const std::string& assocPath,
const boost::container::flat_set<std::string>& endpointPaths,
AssociationMaps& assocMaps)
{
auto& iface = assocMaps.ifaces[assocPath];
- auto& i = std::get<ifacePos>(iface);
auto& endpoints = std::get<endpointsPos>(iface);
// Only add new endpoints
@@ -163,22 +224,11 @@
endpoints.push_back(e);
}
}
-
- // If the interface already exists, only need to update
- // the property value, otherwise create it
- if (i)
- {
- i->set_property("endpoints", endpoints);
- }
- else
- {
- i = objectServer.add_interface(assocPath, xyzAssociationInterface);
- i->register_property("endpoints", endpoints);
- i->initialize();
- }
+ scheduleUpdateEndpointsOnDbus(io, objectServer, assocPath, assocMaps);
}
-void associationChanged(sdbusplus::asio::object_server& objectServer,
+void associationChanged(boost::asio::io_context& io,
+ sdbusplus::asio::object_server& objectServer,
const std::vector<Association>& associations,
const std::string& path, const std::string& owner,
const InterfaceMapType& interfaceMap,
@@ -218,12 +268,12 @@
}
for (const auto& object : objects)
{
- addEndpointsToAssocIfaces(objectServer, object.first, object.second,
+ addEndpointsToAssocIfaces(io, objectServer, object.first, object.second,
assocMaps);
}
// Check for endpoints being removed instead of added
- checkAssociationEndpointRemoves(path, owner, objects, objectServer,
+ checkAssociationEndpointRemoves(io, path, owner, objects, objectServer,
assocMaps);
if (!objects.empty())
@@ -313,7 +363,8 @@
}
}
-void addSingleAssociation(sdbusplus::asio::object_server& server,
+void addSingleAssociation(boost::asio::io_context& io,
+ sdbusplus::asio::object_server& server,
const std::string& assocPath,
const std::string& endpoint, const std::string& owner,
const std::string& ownerPath,
@@ -321,7 +372,7 @@
{
boost::container::flat_set<std::string> endpoints{endpoint};
- addEndpointsToAssocIfaces(server, assocPath, endpoints, assocMaps);
+ addEndpointsToAssocIfaces(io, server, assocPath, endpoints, assocMaps);
AssociationPaths objects;
boost::container::flat_set e{endpoint};
@@ -356,7 +407,8 @@
}
}
-void checkIfPendingAssociation(const std::string& objectPath,
+void checkIfPendingAssociation(boost::asio::io_context& io,
+ const std::string& objectPath,
const InterfaceMapType& interfaceMap,
AssociationMaps& assocMaps,
sdbusplus::asio::object_server& server)
@@ -400,13 +452,13 @@
try
{
- addSingleAssociation(server, assocPath, endpointPath, owner,
+ addSingleAssociation(io, server, assocPath, endpointPath, owner,
ownerPath, assocMaps);
// Now the reverse direction (still the same owner and ownerPath)
assocPath = endpointPath + '/' + std::get<reverseTypePos>(e);
endpointPath = objectPath;
- addSingleAssociation(server, assocPath, endpointPath, owner,
+ addSingleAssociation(io, server, assocPath, endpointPath, owner,
ownerPath, assocMaps);
}
catch (const sdbusplus::exception_t& e)
@@ -494,7 +546,8 @@
* @param[in,out] assocMaps - the association maps
* @param[in,out] server - sdbus system object
*/
-void removeAssociationIfacesEntry(const std::string& assocPath,
+void removeAssociationIfacesEntry(boost::asio::io_context& io,
+ const std::string& assocPath,
const std::string& endpointPath,
AssociationMaps& assocMaps,
sdbusplus::asio::object_server& server)
@@ -508,16 +561,7 @@
{
endpoints.erase(e);
- if (endpoints.empty())
- {
- server.remove_interface(std::get<ifacePos>(assoc->second));
- std::get<ifacePos>(assoc->second) = nullptr;
- }
- else
- {
- std::get<ifacePos>(assoc->second)
- ->set_property("endpoints", endpoints);
- }
+ scheduleUpdateEndpointsOnDbus(io, server, assocPath, assocMaps);
}
}
}
@@ -574,7 +618,8 @@
}
}
-void moveAssociationToPending(const std::string& endpointPath,
+void moveAssociationToPending(boost::asio::io_context& io,
+ const std::string& endpointPath,
AssociationMaps& assocMaps,
sdbusplus::asio::object_server& server)
{
@@ -596,9 +641,9 @@
reverseType, owner, assocMaps);
// Remove both sides of the association from assocMaps.ifaces
- removeAssociationIfacesEntry(forwardPath + '/' + forwardType,
+ removeAssociationIfacesEntry(io, forwardPath + '/' + forwardType,
reversePath, assocMaps, server);
- removeAssociationIfacesEntry(reversePath + '/' + reverseType,
+ removeAssociationIfacesEntry(io, reversePath + '/' + reverseType,
forwardPath, assocMaps, server);
// Remove both sides of the association from assocMaps.owners
diff --git a/src/associations.hpp b/src/associations.hpp
index 380b7cf..1d7b778 100644
--- a/src/associations.hpp
+++ b/src/associations.hpp
@@ -5,8 +5,12 @@
constexpr const char* xyzAssociationInterface =
"xyz.openbmc_project.Association";
+constexpr size_t endpointsCountTimerThreshold = 100;
+constexpr int endpointUpdateDelaySeconds = 1;
+
/** @brief Remove input association
*
+ * @param[in] io - io context
* @param[in] sourcePath - Path of the object that contains the
* org.openbmc.Associations
* @param[in] owner - The Dbus service having its associations
@@ -16,7 +20,8 @@
*
* @return Void, server, assocMaps updated if needed
*/
-void removeAssociation(const std::string& sourcePath, const std::string& owner,
+void removeAssociation(boost::asio::io_context& io,
+ const std::string& sourcePath, const std::string& owner,
sdbusplus::asio::object_server& server,
AssociationMaps& assocMaps);
@@ -25,6 +30,7 @@
* If the last endpoint was removed, then remove the whole
* association object, otherwise just set the property
*
+ * @param[in] io - io context
* @param[in] objectServer - sdbus system object
* @param[in] assocPath - Path of the object that contains the
* org.openbmc.Associations
@@ -34,7 +40,8 @@
* @return Void, objectServer and assocMaps updated if needed
*/
void removeAssociationEndpoints(
- sdbusplus::asio::object_server& objectServer, const std::string& assocPath,
+ boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
+ const std::string& assocPath,
const boost::container::flat_set<std::string>& endpointsToRemove,
AssociationMaps& assocMaps);
@@ -47,6 +54,7 @@
* from the endpoints property, remove that whole association object from
* D-Bus.
*
+ * @param[in] io - io context
* @param[in] sourcePath - Path of the object that contains the
* org.openbmc.Associations
* @param[in] owner - The Dbus service having it's associatons
@@ -58,8 +66,8 @@
* @return Void, objectServer and assocMaps updated if needed
*/
void checkAssociationEndpointRemoves(
- const std::string& sourcePath, const std::string& owner,
- const AssociationPaths& newAssociations,
+ boost::asio::io_context& io, const std::string& sourcePath,
+ const std::string& owner, const AssociationPaths& newAssociations,
sdbusplus::asio::object_server& objectServer, AssociationMaps& assocMaps);
/** @brief Handle new or changed association interfaces
@@ -67,6 +75,7 @@
* Called when either a new org.openbmc.Associations interface was
* created, or the associations property on that interface changed
*
+ * @param[in] io - io context
* @param[in,out] objectServer - sdbus system object
* @param[in] associations - New associations to look at for change
* @param[in] path - Path of the object that contains the
@@ -78,7 +87,8 @@
*
* @return Void, objectServer and assocMaps updated if needed
*/
-void associationChanged(sdbusplus::asio::object_server& objectServer,
+void associationChanged(boost::asio::io_context& io,
+ sdbusplus::asio::object_server& objectServer,
const std::vector<Association>& associations,
const std::string& path, const std::string& owner,
const InterfaceMapType& interfaceMap,
@@ -123,6 +133,7 @@
/** @brief Adds a single association D-Bus object (<path>/<type>)
*
+ * @param[in] io - io context
* @param[in,out] server - sdbus system object
* @param[in] assocPath - The association D-Bus path
* @param[in] endpoint - The association's D-Bus endpoint path
@@ -130,7 +141,8 @@
* @param[in] ownerPath - The D-Bus path hosting the Associations property
* @param[in,out] assocMaps - The association maps
*/
-void addSingleAssociation(sdbusplus::asio::object_server& server,
+void addSingleAssociation(boost::asio::io_context& io,
+ sdbusplus::asio::object_server& server,
const std::string& assocPath,
const std::string& endpoint, const std::string& owner,
const std::string& ownerPath,
@@ -143,12 +155,14 @@
* map, create the 2 real association objects and remove its pending
* associations entry. Used when a new path shows up in D-Bus.
*
+ * @param[in] io - io context
* @param[in] objectPath - the path to check
* @param[in] interfaceMap - The master interface map
* @param[in,out] assocMaps - The association maps
* @param[in,out] server - sdbus system object
*/
-void checkIfPendingAssociation(const std::string& objectPath,
+void checkIfPendingAssociation(boost::asio::io_context& io,
+ const std::string& objectPath,
const InterfaceMapType& interfaceMap,
AssociationMaps& assocMaps,
sdbusplus::asio::object_server& server);
@@ -172,10 +186,12 @@
* association endpoint (the path that owns the association is still
* on D-Bus), then move the association it's involved in to pending.
*
+ * @param[in] io - io context
* @param[in] endpointPath - the D-Bus endpoint path to check
* @param[in,out] assocMaps - The association maps
* @param[in,out] server - sdbus system object
*/
-void moveAssociationToPending(const std::string& endpointPath,
+void moveAssociationToPending(boost::asio::io_context& io,
+ const std::string& endpointPath,
AssociationMaps& assocMaps,
sdbusplus::asio::object_server& server);
diff --git a/src/main.cpp b/src/main.cpp
index c309d87..767bda0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -128,7 +128,8 @@
#endif
};
-void doAssociations(sdbusplus::asio::connection* systemBus,
+void doAssociations(boost::asio::io_context& io,
+ sdbusplus::asio::connection* systemBus,
InterfaceMapType& interfaceMap,
sdbusplus::asio::object_server& objectServer,
const std::string& processName, const std::string& path,
@@ -136,7 +137,7 @@
{
constexpr int maxTimeoutRetries = 3;
systemBus->async_method_call(
- [&objectServer, path, processName, &interfaceMap, systemBus,
+ [&io, &objectServer, path, processName, &interfaceMap, systemBus,
timeoutRetries](
const boost::system::error_code ec,
const std::variant<std::vector<Association>>& variantAssociations) {
@@ -145,7 +146,7 @@
if (ec.value() == boost::system::errc::timed_out &&
timeoutRetries < maxTimeoutRetries)
{
- doAssociations(systemBus, interfaceMap, objectServer,
+ doAssociations(io, systemBus, interfaceMap, objectServer,
processName, path, timeoutRetries + 1);
return;
}
@@ -153,14 +154,15 @@
}
std::vector<Association> associations =
std::get<std::vector<Association>>(variantAssociations);
- associationChanged(objectServer, associations, path, processName,
- interfaceMap, associationMaps);
+ associationChanged(io, objectServer, associations, path,
+ processName, interfaceMap, associationMaps);
},
processName, path, "org.freedesktop.DBus.Properties", "Get",
assocDefsInterface, assocDefsProperty);
}
-void doIntrospect(sdbusplus::asio::connection* systemBus,
+void doIntrospect(boost::asio::io_context& io,
+ sdbusplus::asio::connection* systemBus,
const std::shared_ptr<InProgressIntrospect>& transaction,
InterfaceMapType& interfaceMap,
sdbusplus::asio::object_server& objectServer,
@@ -168,7 +170,7 @@
{
constexpr int maxTimeoutRetries = 3;
systemBus->async_method_call(
- [&interfaceMap, &objectServer, transaction, path, systemBus,
+ [&io, &interfaceMap, &objectServer, transaction, path, systemBus,
timeoutRetries](const boost::system::error_code ec,
const std::string& introspectXml) {
if (ec)
@@ -176,7 +178,7 @@
if (ec.value() == boost::system::errc::timed_out &&
timeoutRetries < maxTimeoutRetries)
{
- doIntrospect(systemBus, transaction, interfaceMap,
+ doIntrospect(io, systemBus, transaction, interfaceMap,
objectServer, path, timeoutRetries + 1);
return;
}
@@ -217,7 +219,7 @@
if (std::strcmp(ifaceName, assocDefsInterface) == 0)
{
- doAssociations(systemBus, interfaceMap, objectServer,
+ doAssociations(io, systemBus, interfaceMap, objectServer,
transaction->processName, path);
}
@@ -226,7 +228,7 @@
// Check if this new path has a pending association that can
// now be completed.
- checkIfPendingAssociation(path, interfaceMap,
+ checkIfPendingAssociation(io, path, interfaceMap,
transaction->assocMaps, objectServer);
pElement = pRoot->FirstChildElement("node");
@@ -241,7 +243,7 @@
parentPath.clear();
}
- doIntrospect(systemBus, transaction, interfaceMap,
+ doIntrospect(io, systemBus, transaction, interfaceMap,
objectServer, parentPath + "/" + childPath);
}
pElement = pElement->NextSiblingElement("node");
@@ -272,7 +274,8 @@
#endif
);
- doIntrospect(systemBus, transaction, interfaceMap, objectServer, "/");
+ doIntrospect(io, systemBus, transaction, interfaceMap, objectServer,
+ "/");
}
}
@@ -677,7 +680,7 @@
if (!oldOwner.empty())
{
- processNameChangeDelete(nameOwners, name, oldOwner,
+ processNameChangeDelete(io, nameOwners, name, oldOwner,
interfaceMap, associationMaps, server);
}
@@ -707,7 +710,8 @@
sdbusplus::bus::match::rules::nameOwnerChanged(), nameChangeHandler);
std::function<void(sdbusplus::message_t & message)> interfacesAddedHandler =
- [&interfaceMap, &nameOwners, &server](sdbusplus::message_t& message) {
+ [&io, &interfaceMap, &nameOwners,
+ &server](sdbusplus::message_t& message) {
sdbusplus::message::object_path objPath;
InterfacesAdded interfacesAdded;
message.read(objPath, interfacesAdded);
@@ -718,8 +722,9 @@
}
if (needToIntrospect(wellKnown))
{
- processInterfaceAdded(interfaceMap, objPath, interfacesAdded,
- wellKnown, associationMaps, server);
+ processInterfaceAdded(io, interfaceMap, objPath,
+ interfacesAdded, wellKnown,
+ associationMaps, server);
}
};
@@ -729,7 +734,7 @@
interfacesAddedHandler);
std::function<void(sdbusplus::message_t & message)>
- interfacesRemovedHandler = [&interfaceMap, &nameOwners,
+ interfacesRemovedHandler = [&io, &interfaceMap, &nameOwners,
&server](sdbusplus::message_t& message) {
sdbusplus::message::object_path objPath;
std::vector<std::string> interfacesRemoved;
@@ -755,7 +760,7 @@
if (interface == assocDefsInterface)
{
- removeAssociation(objPath.str, sender, server,
+ removeAssociation(io, objPath.str, sender, server,
associationMaps);
}
@@ -778,8 +783,8 @@
{
// Remove the 2 association D-Bus paths and move the
// association to pending.
- moveAssociationToPending(objPath.str, associationMaps,
- server);
+ moveAssociationToPending(io, objPath.str,
+ associationMaps, server);
}
}
}
@@ -799,7 +804,7 @@
interfacesRemovedHandler);
std::function<void(sdbusplus::message_t & message)>
- associationChangedHandler = [&server, &nameOwners, &interfaceMap](
+ associationChangedHandler = [&io, &server, &nameOwners, &interfaceMap](
sdbusplus::message_t& message) {
std::string objectName;
boost::container::flat_map<std::string,
@@ -817,7 +822,7 @@
{
return;
}
- associationChanged(server, associations, message.get_path(),
+ associationChanged(io, server, associations, message.get_path(),
wellKnown, interfaceMap, associationMaps);
}
};
diff --git a/src/processing.cpp b/src/processing.cpp
index 5590d16..4298541 100644
--- a/src/processing.cpp
+++ b/src/processing.cpp
@@ -40,6 +40,7 @@
}
void processNameChangeDelete(
+ boost::asio::io_context& io,
boost::container::flat_map<std::string, std::string>& nameOwners,
const std::string& wellKnown, const std::string& oldOwner,
InterfaceMapType& interfaceMap, AssociationMaps& assocMaps,
@@ -67,7 +68,8 @@
assocDefsInterface);
if (assoc != ifaces->second.end())
{
- removeAssociation(pathIt->first, wellKnown, server, assocMaps);
+ removeAssociation(io, pathIt->first, wellKnown, server,
+ assocMaps);
}
// Instead of checking if every single path is the endpoint of an
@@ -80,7 +82,7 @@
{
// Remove the 2 association D-Bus paths and move the
// association to pending.
- moveAssociationToPending(pathIt->first, assocMaps, server);
+ moveAssociationToPending(io, pathIt->first, assocMaps, server);
}
}
pathIt->second.erase(wellKnown);
@@ -95,7 +97,8 @@
}
}
-void processInterfaceAdded(InterfaceMapType& interfaceMap,
+void processInterfaceAdded(boost::asio::io_context& io,
+ InterfaceMapType& interfaceMap,
const sdbusplus::message::object_path& objPath,
const InterfacesAdded& intfAdded,
const std::string& wellKnown,
@@ -127,7 +130,7 @@
}
std::vector<Association> associations =
std::get<std::vector<Association>>(*variantAssociations);
- associationChanged(server, associations, objPath.str, wellKnown,
+ associationChanged(io, server, associations, objPath.str, wellKnown,
interfaceMap, assocMaps);
}
}
@@ -174,5 +177,5 @@
}
// The new interface might have an association pending
- checkIfPendingAssociation(objPath.str, interfaceMap, assocMaps, server);
+ checkIfPendingAssociation(io, objPath.str, interfaceMap, assocMaps, server);
}
diff --git a/src/processing.hpp b/src/processing.hpp
index 3777ff4..d33f15f 100644
--- a/src/processing.hpp
+++ b/src/processing.hpp
@@ -52,6 +52,7 @@
/** @brief Handle the removal of an existing name in objmgr data structures
*
+ * @param[in] io - io context
* @param[in,out] nameOwners - Map of unique name to well known name
* @param[in] wellKnown - Well known name that has new owner
* @param[in] oldOwner - Old unique name
@@ -61,6 +62,7 @@
*
*/
void processNameChangeDelete(
+ boost::asio::io_context& io,
boost::container::flat_map<std::string, std::string>& nameOwners,
const std::string& wellKnown, const std::string& oldOwner,
InterfaceMapType& interfaceMap, AssociationMaps& assocMaps,
@@ -68,6 +70,7 @@
/** @brief Handle an interfaces added signal
*
+ * @param[in] io - io context
* @param[in,out] interfaceMap - Global map of interfaces
* @param[in] objPath - New path to process
* @param[in] interfacesAdded - New interfaces to process
@@ -76,7 +79,8 @@
* @param[in,out] server - sdbus system object
*
*/
-void processInterfaceAdded(InterfaceMapType& interfaceMap,
+void processInterfaceAdded(boost::asio::io_context& io,
+ InterfaceMapType& interfaceMap,
const sdbusplus::message::object_path& objPath,
const InterfacesAdded& intfAdded,
const std::string& wellKnown,
diff --git a/src/test/associations.cpp b/src/test/associations.cpp
index cf2f7d0..62aefab 100644
--- a/src/test/associations.cpp
+++ b/src/test/associations.cpp
@@ -10,7 +10,14 @@
#include <gtest/gtest.h>
class TestAssociations : public AsioServerClassTest
-{};
+{
+ public:
+ boost::asio::io_context io;
+ virtual void SetUp()
+ {
+ io.run();
+ }
+};
sdbusplus::asio::object_server* TestAssociations::AsioServerClassTest::server =
nullptr;
@@ -21,7 +28,7 @@
std::string sourcePath = "/xyz/openbmc_project/no/association";
AssociationMaps assocMaps;
- removeAssociation(sourcePath, defaultDbusSvc, *server, assocMaps);
+ removeAssociation(io, sourcePath, defaultDbusSvc, *server, assocMaps);
}
// Verify call when owner is not in associated owners
@@ -30,7 +37,8 @@
AssociationMaps assocMaps;
assocMaps.owners = createDefaultOwnerAssociation();
- removeAssociation(defaultSourcePath, defaultDbusSvc, *server, assocMaps);
+ removeAssociation(io, defaultSourcePath, defaultDbusSvc, *server,
+ assocMaps);
}
// Verify call when path is not in associated interfaces
@@ -40,7 +48,8 @@
assocMaps.owners = createDefaultOwnerAssociation();
- removeAssociation(defaultSourcePath, defaultDbusSvc, *server, assocMaps);
+ removeAssociation(io, defaultSourcePath, defaultDbusSvc, *server,
+ assocMaps);
EXPECT_TRUE(assocMaps.owners.empty());
}
@@ -54,7 +63,8 @@
assocMaps.owners = createDefaultOwnerAssociation();
assocMaps.ifaces = createDefaultInterfaceAssociation(server);
- removeAssociation(defaultSourcePath, defaultDbusSvc, *server, assocMaps);
+ removeAssociation(io, defaultSourcePath, defaultDbusSvc, *server,
+ assocMaps);
// Verify owner association was deleted
EXPECT_TRUE(assocMaps.owners.empty());
@@ -79,7 +89,8 @@
// Add another endpoint to the assoc interfaces
addEndpointToInterfaceAssociation(assocMaps.ifaces);
- removeAssociation(defaultSourcePath, defaultDbusSvc, *server, assocMaps);
+ removeAssociation(io, defaultSourcePath, defaultDbusSvc, *server,
+ assocMaps);
// Verify owner association was deleted
EXPECT_TRUE(assocMaps.owners.empty());
@@ -102,7 +113,7 @@
assocMaps.owners = createDefaultOwnerAssociation();
assocMaps.ifaces = createDefaultInterfaceAssociation(server);
- checkAssociationEndpointRemoves(defaultSourcePath, defaultDbusSvc,
+ checkAssociationEndpointRemoves(io, defaultSourcePath, defaultDbusSvc,
newAssocPaths, *server, assocMaps);
// Verify endpoints were not deleted because they matche with what was
@@ -123,7 +134,7 @@
assocMaps.owners = createDefaultOwnerAssociation();
assocMaps.ifaces = createDefaultInterfaceAssociation(server);
- checkAssociationEndpointRemoves(defaultSourcePath, defaultDbusSvc,
+ checkAssociationEndpointRemoves(io, defaultSourcePath, defaultDbusSvc,
newAssocPaths, *server, assocMaps);
// Verify initial endpoints were deleted because the new path
@@ -145,7 +156,7 @@
assocMaps.owners = createDefaultOwnerAssociation();
assocMaps.ifaces = createDefaultInterfaceAssociation(server);
- checkAssociationEndpointRemoves(defaultSourcePath, defaultDbusSvc,
+ checkAssociationEndpointRemoves(io, defaultSourcePath, defaultDbusSvc,
newAssocPaths, *server, assocMaps);
// Verify initial endpoints were deleted because of different endpoints
@@ -168,8 +179,8 @@
assocMaps.ifaces = createDefaultInterfaceAssociation(server);
// Empty endpoint will result in deletion of corresponding assocInterface
- associationChanged(*server, associations, defaultSourcePath, defaultDbusSvc,
- interfaceMap, assocMaps);
+ associationChanged(io, *server, associations, defaultSourcePath,
+ defaultDbusSvc, interfaceMap, assocMaps);
// Both of these should be 0 since we have an invalid endpoint
auto intfEndpoints =
@@ -196,7 +207,7 @@
{"/new/source/path", {{defaultDbusSvc, {"a"}}}},
{"/xyz/openbmc_project/new/endpoint", {{defaultDbusSvc, {"a"}}}}};
- associationChanged(*server, associations, "/new/source/path",
+ associationChanged(io, *server, associations, "/new/source/path",
defaultDbusSvc, interfaceMap, assocMaps);
// Two source paths
@@ -230,8 +241,8 @@
// Make it look like the assoc endpoints are on D-Bus
InterfaceMapType interfaceMap = createDefaultInterfaceMap();
- associationChanged(*server, associations, defaultSourcePath, defaultDbusSvc,
- interfaceMap, assocMaps);
+ associationChanged(io, *server, associations, defaultSourcePath,
+ defaultDbusSvc, interfaceMap, assocMaps);
// New associations so ensure it now contains a single entry
EXPECT_EQ(assocMaps.owners.size(), 1);
@@ -266,7 +277,7 @@
assocMaps.owners = createDefaultOwnerAssociation();
assocMaps.ifaces = createDefaultInterfaceAssociation(server);
- associationChanged(*server, associations, defaultSourcePath, newOwner,
+ associationChanged(io, *server, associations, defaultSourcePath, newOwner,
interfaceMap, assocMaps);
// New endpoint so assocOwners should be same size
@@ -299,8 +310,8 @@
assocMaps.owners = createDefaultOwnerAssociation();
assocMaps.ifaces = createDefaultInterfaceAssociation(server);
- associationChanged(*server, associations, defaultSourcePath, defaultDbusSvc,
- interfaceMap, assocMaps);
+ associationChanged(io, *server, associations, defaultSourcePath,
+ defaultDbusSvc, interfaceMap, assocMaps);
// Should have 3 entries in AssociationInterfaces, one is just missing an
// endpoint
@@ -398,7 +409,7 @@
AssociationMaps assocMaps;
InterfaceMapType interfaceMap;
- associationChanged(*server, associations, "/new/source/path",
+ associationChanged(io, *server, associations, "/new/source/path",
defaultDbusSvc, interfaceMap, assocMaps);
// No associations were actually added
@@ -450,7 +461,7 @@
EXPECT_EQ(assocMaps.pending.size(), 1);
// Move the pending association to a real association
- checkIfPendingAssociation(defaultSourcePath, interfaceMap, assocMaps,
+ checkIfPendingAssociation(io, defaultSourcePath, interfaceMap, assocMaps,
*server);
EXPECT_TRUE(assocMaps.pending.empty());
@@ -458,7 +469,8 @@
EXPECT_EQ(assocMaps.ifaces.size(), 2);
// This shouldn't do anything, since /new/path isn't pending
- checkIfPendingAssociation("/new/path", interfaceMap, assocMaps, *server);
+ checkIfPendingAssociation(io, "/new/path", interfaceMap, assocMaps,
+ *server);
EXPECT_TRUE(assocMaps.pending.empty());
EXPECT_EQ(assocMaps.owners.size(), 1);
EXPECT_EQ(assocMaps.ifaces.size(), 2);
@@ -515,7 +527,7 @@
AssociationMaps assocMaps;
// Not an association, so it shouldn't do anything
- moveAssociationToPending(defaultEndpoint, assocMaps, *server);
+ moveAssociationToPending(io, defaultEndpoint, assocMaps, *server);
EXPECT_TRUE(assocMaps.pending.empty());
EXPECT_TRUE(assocMaps.owners.empty());
@@ -528,7 +540,7 @@
assocMaps.owners = createDefaultOwnerAssociation();
assocMaps.ifaces = createDefaultInterfaceAssociation(server);
- moveAssociationToPending(defaultEndpoint, assocMaps, *server);
+ moveAssociationToPending(io, defaultEndpoint, assocMaps, *server);
// Check it's now pending
EXPECT_EQ(assocMaps.pending.size(), 1);
diff --git a/src/test/interfaces_added.cpp b/src/test/interfaces_added.cpp
index 1ada2a0..63a6a26 100644
--- a/src/test/interfaces_added.cpp
+++ b/src/test/interfaces_added.cpp
@@ -37,9 +37,13 @@
auto intfAdded =
createInterfacesAdded(assocDefsInterface, assocDefsProperty);
- processInterfaceAdded(interfaceMap, defaultSourcePath, intfAdded,
+ boost::asio::io_context io;
+
+ processInterfaceAdded(io, interfaceMap, defaultSourcePath, intfAdded,
defaultDbusSvc, assocMaps, *server);
+ io.run();
+
// Interface map will get the following:
// /logging/entry/1 /logging/entry /logging/ / system/chassis
// dumpInterfaceMapType(interfaceMap);
diff --git a/src/test/name_change.cpp b/src/test/name_change.cpp
index 860a387..2730c67 100644
--- a/src/test/name_change.cpp
+++ b/src/test/name_change.cpp
@@ -5,7 +5,14 @@
#include <gtest/gtest.h>
class TestNameChange : public AsioServerClassTest
-{};
+{
+ public:
+ boost::asio::io_context io;
+ virtual void SetUp()
+ {
+ io.run();
+ }
+};
sdbusplus::asio::object_server* TestNameChange::AsioServerClassTest::server =
nullptr;
@@ -19,7 +26,7 @@
InterfaceMapType interfaceMap;
AssociationMaps assocMaps;
- processNameChangeDelete(nameOwners, wellKnown, oldOwner, interfaceMap,
+ processNameChangeDelete(io, nameOwners, wellKnown, oldOwner, interfaceMap,
assocMaps, *server);
EXPECT_EQ(nameOwners.size(), 0);
}
@@ -40,8 +47,8 @@
auto interfaceMap = createInterfaceMap(defaultSourcePath, defaultDbusSvc,
assocInterfacesSet);
- processNameChangeDelete(nameOwners, defaultDbusSvc, oldOwner, interfaceMap,
- assocMaps, *server);
+ processNameChangeDelete(io, nameOwners, defaultDbusSvc, oldOwner,
+ interfaceMap, assocMaps, *server);
EXPECT_EQ(nameOwners.size(), 0);
// Verify owner association was deleted