Files
cgroups-rs/tests/cgroup.rs
2020-08-27 23:06:44 +08:00

27 lines
872 B
Rust

//! Simple unit tests about the control groups system.
use cgroups::{Cgroup, CgroupPid, Hierarchy};
#[test]
fn test_tasks_iterator() {
let h = cgroups::hierarchies::auto();
let h = Box::new(&*h);
let pid = libc::pid_t::from(nix::unistd::getpid()) as u64;
let cg = Cgroup::new(h, String::from("test_tasks_iterator"));
{
// Add a task to the control group.
cg.add_task(CgroupPid::from(pid));
let mut tasks = cg.tasks().into_iter();
// Verify that the task is indeed in the control group
assert_eq!(tasks.next(), Some(CgroupPid::from(pid)));
assert_eq!(tasks.next(), None);
// Now, try removing it.
cg.remove_task(CgroupPid::from(pid));
tasks = cg.tasks().into_iter();
// Verify that it was indeed removed.
assert_eq!(tasks.next(), None);
}
cg.delete();
}