Jagpal Singh Gill | 7e11ab0 | 2023-12-08 11:41:41 -0800 | [diff] [blame] | 1 | #include "health_metric_config.hpp" |
| 2 | |
| 3 | #include <sdbusplus/test/sdbus_mock.hpp> |
| 4 | |
| 5 | #include <iostream> |
| 6 | #include <set> |
| 7 | #include <utility> |
| 8 | |
| 9 | #include <gtest/gtest.h> |
| 10 | |
| 11 | using namespace phosphor::health; |
| 12 | using namespace phosphor::health::metric::config; |
| 13 | |
| 14 | constexpr auto minConfigSize = 1; |
| 15 | |
| 16 | TEST(HealthMonitorConfigTest, TestConfigSize) |
| 17 | { |
| 18 | auto healthMetricConfigs = getHealthMetricConfigs(); |
| 19 | EXPECT_GE(healthMetricConfigs.size(), minConfigSize); |
| 20 | } |
| 21 | |
| 22 | bool isValidSubType(metric::Type type, metric::SubType subType) |
| 23 | { |
| 24 | std::cout << "Metric Type: " << std::to_underlying(type) |
| 25 | << " Metric SubType: " << std::to_underlying(subType) |
| 26 | << std::endl; |
| 27 | |
| 28 | using set_t = std::set<metric::SubType>; |
| 29 | |
| 30 | switch (type) |
| 31 | { |
| 32 | case metric::Type::cpu: |
| 33 | return set_t{metric::SubType::cpuTotal, metric::SubType::cpuKernel, |
| 34 | metric::SubType::cpuUser} |
| 35 | .contains(subType); |
| 36 | |
| 37 | case metric::Type::memory: |
| 38 | return set_t{metric::SubType::memoryAvailable, |
| 39 | metric::SubType::memoryBufferedAndCached, |
| 40 | metric::SubType::memoryFree, |
| 41 | metric::SubType::memoryShared, |
| 42 | metric::SubType::memoryTotal} |
| 43 | .contains(subType); |
| 44 | |
| 45 | case metric::Type::storage: |
Jagpal Singh Gill | 7e11ab0 | 2023-12-08 11:41:41 -0800 | [diff] [blame] | 46 | case metric::Type::inode: |
| 47 | return set_t{metric::SubType::NA}.contains(subType); |
| 48 | |
| 49 | default: |
| 50 | return false; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | TEST(HealthMonitorConfigTest, TestConfigValues) |
| 55 | { |
| 56 | auto healthMetricConfigs = getHealthMetricConfigs(); |
Patrick Williams | c00c19e | 2024-02-23 19:07:32 -0600 | [diff] [blame] | 57 | auto count_with_thresholds = 0; |
Jagpal Singh Gill | 7e11ab0 | 2023-12-08 11:41:41 -0800 | [diff] [blame] | 58 | for (const auto& [type, configs] : healthMetricConfigs) |
| 59 | { |
| 60 | EXPECT_NE(type, metric::Type::unknown); |
| 61 | EXPECT_GE(configs.size(), minConfigSize); |
| 62 | for (const auto& config : configs) |
| 63 | { |
| 64 | EXPECT_NE(config.name, std::string("")); |
| 65 | EXPECT_TRUE(isValidSubType(type, config.subType)); |
Jagpal Singh Gill | 7e11ab0 | 2023-12-08 11:41:41 -0800 | [diff] [blame] | 66 | EXPECT_GE(config.windowSize, HealthMetric::defaults::windowSize); |
Jagpal Singh Gill | a102762 | 2024-03-05 17:57:33 -0800 | [diff] [blame] | 67 | EXPECT_GE(config.hysteresis, HealthMetric::defaults::hysteresis); |
Patrick Williams | c00c19e | 2024-02-23 19:07:32 -0600 | [diff] [blame] | 68 | if (config.thresholds.size()) |
| 69 | { |
| 70 | count_with_thresholds++; |
| 71 | } |
Jagpal Singh Gill | 7e11ab0 | 2023-12-08 11:41:41 -0800 | [diff] [blame] | 72 | } |
Patrick Williams | c00c19e | 2024-02-23 19:07:32 -0600 | [diff] [blame] | 73 | |
| 74 | EXPECT_GE(count_with_thresholds, 1); |
Jagpal Singh Gill | 7e11ab0 | 2023-12-08 11:41:41 -0800 | [diff] [blame] | 75 | } |
| 76 | } |