dbus event subscriptions: test dbus_log_watcher
Currently that code is still unfinished,
but we can already define some trivial testcases.
The main result of this function is populating EventLogObjectsType.
Tested: Unit tests pass.
Change-Id: I2e23147190be33192d41176413c16cd98c7bfd81
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/meson.build b/meson.build
index 7a2bf69..cc9f824 100644
--- a/meson.build
+++ b/meson.build
@@ -434,6 +434,7 @@
'test/include/ossl_random.cpp',
'test/include/ssl_key_handler_test.cpp',
'test/include/str_utility_test.cpp',
+ 'test/redfish-core/include/dbus_log_watcher_test.cpp',
'test/redfish-core/include/event_log_test.cpp',
'test/redfish-core/include/event_matches_filter_test.cpp',
'test/redfish-core/include/filter_expr_executor_test.cpp',
diff --git a/redfish-core/include/dbus_log_watcher.hpp b/redfish-core/include/dbus_log_watcher.hpp
index 233b9be..6c0f2e0 100644
--- a/redfish-core/include/dbus_log_watcher.hpp
+++ b/redfish-core/include/dbus_log_watcher.hpp
@@ -1,5 +1,8 @@
#pragma once
+#include "dbus_utility.hpp"
+#include "event_logs_object_type.hpp"
+
#include <sdbusplus/bus/match.hpp>
namespace redfish
{
@@ -8,6 +11,10 @@
public:
DbusEventLogMonitor();
sdbusplus::bus::match_t dbusEventLogMonitor;
+
+ static bool
+ eventLogObjectFromDBus(const dbus::utility::DBusPropertiesMap& map,
+ EventLogObjectsType& event);
};
class DbusTelemetryMonitor
diff --git a/redfish-core/src/dbus_log_watcher.cpp b/redfish-core/src/dbus_log_watcher.cpp
index a371f87..c6ca381 100644
--- a/redfish-core/src/dbus_log_watcher.cpp
+++ b/redfish-core/src/dbus_log_watcher.cpp
@@ -22,8 +22,8 @@
namespace redfish
{
-static bool eventLogObjectFromDBus(const dbus::utility::DBusPropertiesMap& map,
- EventLogObjectsType& event)
+bool DbusEventLogMonitor::eventLogObjectFromDBus(
+ const dbus::utility::DBusPropertiesMap& map, EventLogObjectsType& event)
{
std::optional<DbusEventLogEntry> optEntry =
fillDbusEventLogEntryFromPropertyMap(map);
@@ -60,7 +60,7 @@
{
std::vector<EventLogObjectsType> eventRecords;
EventLogObjectsType& event = eventRecords.emplace_back();
- bool success = eventLogObjectFromDBus(map, event);
+ bool success = DbusEventLogMonitor::eventLogObjectFromDBus(map, event);
if (!success)
{
BMCWEB_LOG_ERROR("Could not parse event log entry from dbus");
diff --git a/test/redfish-core/include/dbus_log_watcher_test.cpp b/test/redfish-core/include/dbus_log_watcher_test.cpp
new file mode 100644
index 0000000..c2a33df
--- /dev/null
+++ b/test/redfish-core/include/dbus_log_watcher_test.cpp
@@ -0,0 +1,76 @@
+#include "dbus_log_watcher.hpp"
+#include "dbus_utility.hpp"
+#include "event_logs_object_type.hpp"
+
+#include <cstdint>
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+namespace redfish
+{
+
+using namespace dbus::utility;
+
+TEST(DBusLogWatcher, EventLogObjectFromDBusSuccess)
+{
+ const DBusPropertiesMap propMapStub = {
+ {"AdditionalData",
+ DbusVariantType(std::vector<std::string>{"KEY=VALUE"})},
+ {"EventId", DbusVariantType("")},
+ {"Id", DbusVariantType(static_cast<uint32_t>(1838))},
+
+ // use 'Message' for MessageId as per the design
+ // https://github.com/openbmc/docs/blob/d886ce89fe66c128b3ab492e530ad48fa0c1b4eb/designs/event-logging.md?plain=1#L448
+ {"Message", DbusVariantType("OpenBMC.0.1.PowerButtonPressed")},
+ {"Resolution", DbusVariantType("")},
+ {"Resolved", DbusVariantType(true)},
+ {"ServiceProviderNotify", DbusVariantType("")},
+ {"Severity", DbusVariantType("")},
+ {"Timestamp", DbusVariantType(static_cast<uint64_t>(1638312095123))},
+ {"UpdateTimestamp", DbusVariantType(static_cast<uint64_t>(3899))},
+ };
+
+ EventLogObjectsType event;
+
+ const bool status =
+ DbusEventLogMonitor::eventLogObjectFromDBus(propMapStub, event);
+
+ EXPECT_TRUE(status);
+
+ EXPECT_EQ(event.id, "1838");
+
+ EXPECT_EQ(event.timestamp, "2021-11-30T22:41:35.123+00:00");
+
+ EXPECT_EQ(event.messageId, "OpenBMC.0.1.PowerButtonPressed");
+
+ // dbus event subscriptions currently do not support message args
+ EXPECT_TRUE(event.messageArgs.empty());
+}
+
+TEST(DBusLogWatcher, EventLogObjectFromDBusFailMissingProperty)
+{
+ // missing 'Resolved'
+ const DBusPropertiesMap propMapWrong = {
+ {"AdditionalData",
+ DbusVariantType(std::vector<std::string>{"KEY=VALUE"})},
+ {"EventId", DbusVariantType("")},
+ {"Id", DbusVariantType(static_cast<uint32_t>(1838))},
+ {"Message", DbusVariantType("")},
+ {"Resolution", DbusVariantType("")},
+ {"ServiceProviderNotify", DbusVariantType("")},
+ {"Severity", DbusVariantType("")},
+ {"Timestamp", DbusVariantType(static_cast<uint64_t>(3832))},
+ {"UpdateTimestamp", DbusVariantType(static_cast<uint64_t>(3899))},
+ };
+
+ EventLogObjectsType event;
+
+ const bool status =
+ DbusEventLogMonitor::eventLogObjectFromDBus(propMapWrong, event);
+
+ EXPECT_FALSE(status);
+}
+
+} // namespace redfish