#[cfg(test)]
mod tests {
#[test]
fn test_meminfo() {
let info = procfs2::proc::meminfo().expect("Failed to read /proc/meminfo");
assert!(info.total.0 > 0);
assert!(info.available.0 <= info.total.0);
}
#[test]
fn test_meminfo_fields() {
let info = procfs2::proc::meminfo().expect("Failed to read /proc/meminfo");
let _ = info.free;
let _ = info.buffers;
let _ = info.cached;
let _ = info.swap_total;
let _ = info.swap_free;
}
#[test]
fn test_uptime() {
let uptime = procfs2::proc::uptime().expect("Failed to read /proc/uptime");
assert!(uptime.total.as_secs() > 0, "Uptime should be > 0");
}
#[test]
fn test_uptime_values() {
let uptime = procfs2::proc::uptime().expect("Failed to read /proc/uptime");
assert!(uptime.total.as_secs() > 0);
assert!(uptime.idle.as_secs_f64() >= 0.0);
}
#[test]
fn test_loadavg() {
let load = procfs2::proc::loadavg().expect("Failed to read /proc/loadavg");
assert!(load.one >= 0.0);
assert!(load.five >= 0.0);
assert!(load.fifteen >= 0.0);
}
#[test]
fn test_loadavg_fields() {
let load = procfs2::proc::loadavg().expect("Failed to read /proc/loadavg");
assert!(load.runnable >= 1);
}
#[test]
fn test_stat() {
let stat = procfs2::proc::stat().expect("Failed to read /proc/stat");
assert!(!stat.per_cpu.is_empty(), "Should have at least one CPU");
}
#[test]
fn test_stat_cpu_fields() {
let stat = procfs2::proc::stat().expect("Failed to read /proc/stat");
let cpu = &stat.per_cpu[0];
let _ = cpu.times.user;
let _ = cpu.times.nice;
let _ = cpu.times.system;
}
#[test]
fn test_stat_system_fields() {
let stat = procfs2::proc::stat().expect("Failed to read /proc/stat");
assert!(stat.btime > 0, "Boot time should be > 0");
assert!(stat.processes > 0, "Processes should be > 0");
}
#[test]
fn test_version() {
let version = procfs2::proc::version().expect("Failed to read /proc/version");
assert!(version.major > 0, "Major version should be > 0");
}
#[test]
fn test_version_format() {
let version = procfs2::proc::version().expect("Failed to read /proc/version");
assert!(version.major >= 2);
}
#[test]
fn test_cpuinfo() {
let cpus = procfs2::proc::cpuinfo().expect("Failed to read /proc/cpuinfo");
assert!(!cpus.is_empty(), "Should have at least one CPU");
}
#[test]
fn test_cpuinfo_fields() {
let cpus = procfs2::proc::cpuinfo().expect("Failed to read /proc/cpuinfo");
for cpu in &cpus {
let _ = cpu.processor;
}
}
#[test]
fn test_cmdline() {
let args = procfs2::proc::cmdline().expect("Failed to read /proc/cmdline");
assert!(!args.is_empty(), "Should have at least one argument");
}
#[test]
fn test_cmdline_fields() {
let args = procfs2::proc::cmdline().expect("Failed to read /proc/cmdline");
for arg in &args {
assert!(!arg.is_empty(), "Argument should not be empty");
}
}
#[test]
fn test_cgroups() {
let cgroups = procfs2::proc::cgroups().expect("Failed to read /proc/cgroups");
for cg in &cgroups {
assert!(
!cg.subsys_name.is_empty(),
"Controller name should not be empty"
);
}
}
#[test]
fn test_mounts() {
let mounts = procfs2::proc::mounts().expect("Failed to read /proc/mounts");
assert!(!mounts.is_empty(), "Should have at least one mount");
}
#[test]
fn test_net_dev() {
let devices: Vec<_> = procfs2::proc::net::dev().filter_map(|r| r.ok()).collect();
assert!(!devices.is_empty(), "Should have at least one interface");
}
#[test]
fn test_net_route() {
let routes: Vec<_> = procfs2::proc::net::route().filter_map(|r| r.ok()).collect();
assert!(!routes.is_empty(), "Should have at least one route");
}
#[test]
fn test_net_arp() {
let entries: Vec<_> = procfs2::proc::net::arp().collect();
assert!(
entries.iter().all(|r| r.is_ok()),
"ARP entries should parse"
);
}
#[test]
fn test_net_tcp() {
let entries: Vec<_> = procfs2::proc::net::tcp().collect();
assert!(
entries.iter().all(|r| r.is_ok()),
"TCP entries should parse"
);
}
#[test]
fn test_net_tcp6() {
let _ = procfs2::proc::net::tcp6().count();
}
#[test]
fn test_net_udp() {
let entries: Vec<_> = procfs2::proc::net::udp().collect();
assert!(
entries.iter().all(|r| r.is_ok()),
"UDP entries should parse"
);
}
#[test]
fn test_net_udp6() {
let entries: Vec<_> = procfs2::proc::net::udp6().collect();
assert!(
entries.iter().all(|r| r.is_ok()),
"UDP6 entries should parse"
);
}
#[test]
fn test_net_unix() {
let entries: Vec<_> = procfs2::proc::net::unix().collect();
assert!(
entries.iter().all(|r| r.is_ok()),
"Unix socket entries should parse"
);
}
}