lg2: commit: extract source location information and add to event
sdbusplus will add PID and std::source_location information, from
the event origination point, to the event. Extract this and add
it to the event.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I6364ba0f74231fca2815c770bc3e56c2780d199e
diff --git a/test/log_manager_dbus_tests.cpp b/test/log_manager_dbus_tests.cpp
index ac33ded..e2bc8be 100644
--- a/test/log_manager_dbus_tests.cpp
+++ b/test/log_manager_dbus_tests.cpp
@@ -113,8 +113,10 @@
{
sdbusplus::message::object_path path{};
std::string log_count{};
+ pid_t pid = 0;
+ std::string source_file{};
- auto create_log = [this, &path, &log_count]() -> sdbusplus::async::task<> {
+ auto create_log = [&, this]() -> sdbusplus::async::task<> {
// Log an event.
path = co_await lg2::commit(data->client_ctx,
LoggingCleared("NUMBER_OF_LOGS", 6));
@@ -125,12 +127,24 @@
.path(path.str)
.additional_data();
- // Extract the NUMBER_OF_LOGS.
+ // Extract the NUMBER_OF_LOGS, PID, and CODE_FILE.
for (const auto& value : additionalData)
{
+ auto getValue = [&value]() {
+ return value.substr(value.find_first_of('=') + 1);
+ };
+
if (value.starts_with("NUMBER_OF_LOGS="))
{
- log_count = value.substr(value.find_first_of('=') + 1);
+ log_count = getValue();
+ }
+ if (value.starts_with("_PID="))
+ {
+ pid = std::stoull(getValue());
+ }
+ if (value.starts_with("_CODE_FILE="))
+ {
+ source_file = getValue();
}
}
@@ -148,6 +162,8 @@
LoggingEntry::namespace_path::entry));
EXPECT_EQ(log_count, "6");
+ EXPECT_EQ(pid, getpid());
+ EXPECT_EQ(source_file, std::source_location::current().file_name());
}
} // namespace phosphor::logging::test