add health_metric_config implementation
Add the health_metric_config interface and implementation for
phosphor-health-monitor. This interface will be used in the
re-write of phosphor-health-monitor.
This change is in relation to following design and D-Bus interface
update-
https://gerrit.openbmc.org/c/openbmc/docs/+/64917
https://gerrit.openbmc.org/c/openbmc/phosphor-dbus-interfaces/+/64914
gtest added for UT.
Change-Id: Ic40faafbb57597023cc70036428d46ee69a895a2
Signed-off-by: Jagpal Singh Gill <paligill@gmail.com>
diff --git a/test/test_health_metric_config.cpp b/test/test_health_metric_config.cpp
new file mode 100644
index 0000000..471bf2b
--- /dev/null
+++ b/test/test_health_metric_config.cpp
@@ -0,0 +1,73 @@
+#include "health_metric_config.hpp"
+
+#include <sdbusplus/test/sdbus_mock.hpp>
+
+#include <iostream>
+#include <set>
+#include <utility>
+
+#include <gtest/gtest.h>
+
+using namespace phosphor::health;
+using namespace phosphor::health::metric::config;
+
+constexpr auto minConfigSize = 1;
+
+TEST(HealthMonitorConfigTest, TestConfigSize)
+{
+ auto healthMetricConfigs = getHealthMetricConfigs();
+ EXPECT_GE(healthMetricConfigs.size(), minConfigSize);
+}
+
+bool isValidSubType(metric::Type type, metric::SubType subType)
+{
+ std::cout << "Metric Type: " << std::to_underlying(type)
+ << " Metric SubType: " << std::to_underlying(subType)
+ << std::endl;
+
+ using set_t = std::set<metric::SubType>;
+
+ switch (type)
+ {
+ case metric::Type::cpu:
+ return set_t{metric::SubType::cpuTotal, metric::SubType::cpuKernel,
+ metric::SubType::cpuUser}
+ .contains(subType);
+
+ case metric::Type::memory:
+ return set_t{metric::SubType::memoryAvailable,
+ metric::SubType::memoryBufferedAndCached,
+ metric::SubType::memoryFree,
+ metric::SubType::memoryShared,
+ metric::SubType::memoryTotal}
+ .contains(subType);
+
+ case metric::Type::storage:
+ return set_t{metric::SubType::storageReadWrite, metric::SubType::NA}
+ .contains(subType);
+
+ case metric::Type::inode:
+ return set_t{metric::SubType::NA}.contains(subType);
+
+ default:
+ return false;
+ }
+}
+
+TEST(HealthMonitorConfigTest, TestConfigValues)
+{
+ auto healthMetricConfigs = getHealthMetricConfigs();
+ for (const auto& [type, configs] : healthMetricConfigs)
+ {
+ EXPECT_NE(type, metric::Type::unknown);
+ EXPECT_GE(configs.size(), minConfigSize);
+ for (const auto& config : configs)
+ {
+ EXPECT_NE(config.name, std::string(""));
+ EXPECT_TRUE(isValidSubType(type, config.subType));
+ EXPECT_GE(config.collectionFreq, HealthMetric::defaults::frequency);
+ EXPECT_GE(config.windowSize, HealthMetric::defaults::windowSize);
+ EXPECT_GE(config.thresholds.size(), minConfigSize);
+ }
+ }
+}