From 7c83b7b2368f7b7ca69cadb9a48758b81399063d Mon Sep 17 00:00:00 2001 From: Levente Kurusa Date: Sun, 2 Sep 2018 15:33:57 +0200 Subject: [PATCH] test: cgroup: test moving to the root cg Signed-off-by: Levente Kurusa --- tests/cgroup.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/cgroup.rs diff --git a/tests/cgroup.rs b/tests/cgroup.rs new file mode 100644 index 0000000..413fca7 --- /dev/null +++ b/tests/cgroup.rs @@ -0,0 +1,29 @@ +//! Simple unit tests about the control groups system. +extern crate cgroups; +use cgroups::{Cgroup, CgroupPid}; + +extern crate nix; +extern crate libc; + +#[test] +fn test_tasks_iterator() { + let hier = cgroups::hierarchies::V1::new(); + let pid = libc::pid_t::from(nix::unistd::getpid()) as u64; + let cg = Cgroup::new(&hier, 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(); +}