2026-01-23 06:52:31 +00:00

54 lines
1.6 KiB
Rust

use prometeu_core::telemetry::CertificationConfig;
pub fn load_cap_config(path: &str) -> Option<CertificationConfig> {
let content = std::fs::read_to_string(path).ok()?;
let mut config = CertificationConfig {
enabled: true,
..Default::default()
};
for line in content.lines() {
let line = line.trim();
if line.is_empty() || line.starts_with('#') { continue; }
let parts: Vec<&str> = line.split('=').collect();
if parts.len() != 2 { continue; }
let key = parts[0].trim();
let val = parts[1].trim();
match key {
"cycles_budget" => config.cycles_budget_per_frame = val.parse().ok(),
"max_syscalls" => config.max_syscalls_per_frame = val.parse().ok(),
"max_host_cpu_us" => config.max_host_cpu_us_per_frame = val.parse().ok(),
_ => {}
}
}
Some(config)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_load_cap_config() {
let content = "cycles_budget=500\nmax_syscalls=10\n# comment\nmax_host_cpu_us=2000";
let path = "test_cap.cfg";
std::fs::write(path, content).unwrap();
let config = load_cap_config(path).unwrap();
assert!(config.enabled);
assert_eq!(config.cycles_budget_per_frame, Some(500));
assert_eq!(config.max_syscalls_per_frame, Some(10));
assert_eq!(config.max_host_cpu_us_per_frame, Some(2000));
std::fs::remove_file(path).unwrap();
}
#[test]
fn test_load_cap_config_not_found() {
let config = load_cap_config("non_existent.cfg");
assert!(config.is_none());
}
}