5#include <gtest/gtest.h>
13class MetricsProviderTest :
public ::testing::Test {
15 void SetUp()
override {
23TEST_F(MetricsProviderTest, FactoryCreatesProvider) {
24#if defined(__linux__) || defined(__APPLE__) || defined(_WIN32)
28 GTEST_SKIP() <<
"Unsupported platform";
33TEST_F(MetricsProviderTest, ReturnsCorrectPlatformName) {
35 GTEST_SKIP() <<
"Provider not available on this platform";
38 std::string platform_name =
provider_->get_platform_name();
39 EXPECT_FALSE(platform_name.empty());
42 EXPECT_EQ(platform_name,
"linux");
43#elif defined(__APPLE__)
44 EXPECT_EQ(platform_name,
"macos");
46 EXPECT_EQ(platform_name,
"windows");
51TEST_F(MetricsProviderTest, GetUptimeReturnsValidInfo) {
53 GTEST_SKIP() <<
"Provider not available on this platform";
59 EXPECT_TRUE(uptime.available);
60 EXPECT_GT(uptime.uptime_seconds, 0);
64TEST_F(MetricsProviderTest, GetContextSwitchesReturnsInfo) {
66 GTEST_SKIP() <<
"Provider not available on this platform";
69 auto ctx_switches =
provider_->get_context_switches();
73 if (ctx_switches.available) {
74 EXPECT_GT(ctx_switches.total_switches, 0ULL);
79TEST_F(MetricsProviderTest, GetFdStatsReturnsInfo) {
81 GTEST_SKIP() <<
"Provider not available on this platform";
84 auto fd_stats =
provider_->get_fd_stats();
86 if (fd_stats.available) {
88 EXPECT_GT(fd_stats.open_fds, 0ULL);
89 EXPECT_GT(fd_stats.max_fds, 0ULL);
90 EXPECT_GE(fd_stats.usage_percent, 0.0);
91 EXPECT_LE(fd_stats.usage_percent, 100.0);
96TEST_F(MetricsProviderTest, GetInodeStatsReturnsInfo) {
98 GTEST_SKIP() <<
"Provider not available on this platform";
101 auto inode_stats =
provider_->get_inode_stats();
105 for (
const auto& inode : inode_stats) {
106 if (inode.available) {
107 EXPECT_GT(inode.total_inodes, 0ULL);
113TEST_F(MetricsProviderTest, GetTcpStatesReturnsInfo) {
115 GTEST_SKIP() <<
"Provider not available on this platform";
118 auto tcp_states =
provider_->get_tcp_states();
120 if (tcp_states.available) {
123 EXPECT_GE(tcp_states.total, tcp_states.established);
128TEST_F(MetricsProviderTest, GetSocketBufferStatsReturnsInfo) {
130 GTEST_SKIP() <<
"Provider not available on this platform";
133 auto socket_stats =
provider_->get_socket_buffer_stats();
136 if (socket_stats.available) {
138 EXPECT_GE(socket_stats.rx_buffer_used, 0ULL);
139 EXPECT_GE(socket_stats.tx_buffer_used, 0ULL);
144TEST_F(MetricsProviderTest, GetInterruptStatsReturnsInfo) {
146 GTEST_SKIP() <<
"Provider not available on this platform";
149 auto interrupt_stats =
provider_->get_interrupt_stats();
152 for (
const auto& irq : interrupt_stats) {
153 if (irq.available && irq.name ==
"total_interrupts") {
154 EXPECT_GT(irq.count, 0ULL);
160TEST_F(MetricsProviderTest, GetSecurityInfoReturnsInfo) {
162 GTEST_SKIP() <<
"Provider not available on this platform";
165 auto security_info =
provider_->get_security_info();
173TEST_F(MetricsProviderTest, BatteryAvailabilityCheck) {
175 GTEST_SKIP() <<
"Provider not available on this platform";
179 bool battery_available =
provider_->is_battery_available();
182 if (battery_available) {
183 auto readings =
provider_->get_battery_readings();
184 EXPECT_FALSE(readings.empty());
189TEST_F(MetricsProviderTest, TemperatureAvailabilityCheck) {
191 GTEST_SKIP() <<
"Provider not available on this platform";
195 bool temp_available =
provider_->is_temperature_available();
198 if (temp_available) {
199 auto readings =
provider_->get_temperature_readings();
207 EXPECT_FALSE(readings.empty());
213TEST_F(MetricsProviderTest, PowerAvailabilityCheck) {
215 GTEST_SKIP() <<
"Provider not available on this platform";
219 bool power_available =
provider_->is_power_available();
222 if (power_available) {
223 auto power_info =
provider_->get_power_info();
224 EXPECT_TRUE(power_info.available);
229TEST_F(MetricsProviderTest, GpuAvailabilityCheck) {
231 GTEST_SKIP() <<
"Provider not available on this platform";
235 bool gpu_available =
provider_->is_gpu_available();
239 auto gpu_info =
provider_->get_gpu_info();
240 EXPECT_FALSE(gpu_info.empty());
245TEST_F(MetricsProviderTest, MultipleCallsAreConsistent) {
247 GTEST_SKIP() <<
"Provider not available on this platform";
254 if (uptime1.available && uptime2.available) {
256 EXPECT_GE(uptime2.uptime_seconds, uptime1.uptime_seconds);
258 EXPECT_LE(uptime2.uptime_seconds - uptime1.uptime_seconds, 1);
Platform abstraction layer for system metrics collection.
@ platform
Platform/system power domain.
TEST_F(AdaptiveMonitoringTest, AdaptiveConfigDefaults)
std::unique_ptr< metrics_provider > provider_