#include #include #include #include namespace { using Void::Testing::Test; struct MetricsTests : Void::Testing::Suite { // On Linux these return real values; elsewhere nullopt (skip). Test process_memory_is_plausible() { const auto rss = Void::SystemInfo::process_memory_bytes(); if (rss.has_value()) { Void::Testing::expect(*rss > 0); } } Test system_memory_total_positive() { const auto mem = Void::SystemInfo::system_memory(); if (mem.has_value()) { Void::Testing::expect(mem->total > 0); Void::Testing::expect(mem->available <= mem->total); } } Test cpu_sampler_is_non_negative() { Void::SystemInfo::CpuSampler sampler; // Burn a little CPU so a second sample has something to report. volatile double sink = 0.0; for (int i = 0; i < 1'000'000; ++i) { sink += static_cast(i) * 0.5; } (void)sink; const double usage = sampler.usage(); Void::Testing::expect(usage >= 0.0); } }; } // namespace