pldmd: move to libpldm instance ID alloc/free
Refactor the dbus_api::Requester class to be implemented in terms of
libpldm's instance ID database. To make that easier to deal with we
introduce a light-weight RAII C++ binding along with a helper class for
unit tests.
Change-Id: Ia03de8245dfb114e6266ba36dcf26ca4398a4ce0
Signed-off-by: Rashmica Gupta <rashmica@linux.ibm.com>
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/requester/test/handler_test.cpp b/requester/test/handler_test.cpp
index 5de1055..69facdb 100644
--- a/requester/test/handler_test.cpp
+++ b/requester/test/handler_test.cpp
@@ -3,6 +3,7 @@
#include "mock_request.hpp"
#include "pldmd/dbus_impl_requester.hpp"
#include "requester/handler.hpp"
+#include "test/test_instance_id.hpp"
#include <libpldm/base.h>
@@ -22,14 +23,15 @@
{
protected:
HandlerTest() :
- event(sdeventplus::Event::get_default()),
+ event(sdeventplus::Event::get_default()), instanceIdDb(),
dbusImplReq(pldm::utils::DBusHandler::getBus(),
- "/xyz/openbmc_project/pldm")
+ "/xyz/openbmc_project/pldm", instanceIdDb)
{}
int fd = 0;
mctp_eid_t eid = 0;
sdeventplus::Event event;
+ TestInstanceIdDb instanceIdDb;
pldm::dbus_api::Requester dbusImplReq;
/** @brief This function runs the sd_event_run in a loop till all the events
@@ -78,6 +80,7 @@
fd, event, dbusImplReq, false, 90000, seconds(1), 2, milliseconds(100));
pldm::Request request{};
auto instanceId = dbusImplReq.getInstanceId(eid);
+ EXPECT_EQ(instanceId, 0);
auto rc = reqHandler.registerRequest(
eid, instanceId, 0, 0, std::move(request),
std::move(std::bind_front(&HandlerTest::pldmResponseCallBack, this)));
@@ -88,10 +91,7 @@
reqHandler.handleResponse(eid, instanceId, 0, 0, responsePtr,
sizeof(response));
- // handleResponse() will free the instance ID after calling the response
- // handler, so the same instance ID is granted next as well
EXPECT_EQ(validResponse, true);
- EXPECT_EQ(instanceId, dbusImplReq.getInstanceId(eid));
}
TEST_F(HandlerTest, singleRequestInstanceIdTimerExpired)
@@ -100,6 +100,7 @@
fd, event, dbusImplReq, false, 90000, seconds(1), 2, milliseconds(100));
pldm::Request request{};
auto instanceId = dbusImplReq.getInstanceId(eid);
+ EXPECT_EQ(instanceId, 0);
auto rc = reqHandler.registerRequest(
eid, instanceId, 0, 0, std::move(request),
std::move(std::bind_front(&HandlerTest::pldmResponseCallBack, this)));
@@ -108,9 +109,6 @@
// Waiting for 500ms so that the instance ID expiry callback is invoked
waitEventExpiry(milliseconds(500));
- // cleanup() will free the instance ID after calling the response
- // handler will no response, so the same instance ID is granted next
- EXPECT_EQ(instanceId, dbusImplReq.getInstanceId(eid));
EXPECT_EQ(nullResponse, true);
}
@@ -120,6 +118,7 @@
fd, event, dbusImplReq, false, 90000, seconds(2), 2, milliseconds(100));
pldm::Request request{};
auto instanceId = dbusImplReq.getInstanceId(eid);
+ EXPECT_EQ(instanceId, 0);
auto rc = reqHandler.registerRequest(
eid, instanceId, 0, 0, std::move(request),
std::move(std::bind_front(&HandlerTest::pldmResponseCallBack, this)));
@@ -127,6 +126,7 @@
pldm::Request requestNxt{};
auto instanceIdNxt = dbusImplReq.getInstanceId(eid);
+ EXPECT_EQ(instanceIdNxt, 1);
rc = reqHandler.registerRequest(
eid, instanceIdNxt, 0, 0, std::move(requestNxt),
std::move(std::bind_front(&HandlerTest::pldmResponseCallBack, this)));
@@ -149,5 +149,4 @@
EXPECT_EQ(validResponse, true);
EXPECT_EQ(callbackCount, 2);
- EXPECT_EQ(instanceId, dbusImplReq.getInstanceId(eid));
}
diff --git a/requester/test/meson.build b/requester/test/meson.build
index 1e63997..b7a929f 100644
--- a/requester/test/meson.build
+++ b/requester/test/meson.build
@@ -1,10 +1,3 @@
-requester_inc = include_directories('../../')
-test_src = declare_dependency(
- sources: [
- '../../pldmd/dbus_impl_requester.cpp',
- '../../pldmd/instance_id.cpp'],
- include_directories:requester_inc)
-
tests = [
'handler_test',
'request_test',
@@ -13,6 +6,7 @@
foreach t : tests
test(t, executable(t.underscorify(), t + '.cpp',
implicit_include_directories: false,
+ include_directories: [ '../../', '../../pldmd' ],
link_args: dynamic_linker,
build_rpath: get_option('oe-sdk').enabled() ? rpath : '',
dependencies: [
@@ -24,6 +18,6 @@
phosphor_logging_dep,
sdbusplus,
sdeventplus,
- test_src]),
+ ]),
workdir: meson.current_source_dir())
endforeach