mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
Add SPDX-License-Identifier for all existing codes. Fixes: #2 Signed-off-by: bin liu <bin@hyper.sh>
31 lines
934 B
Rust
31 lines
934 B
Rust
// Copyright (c) 2018 Levente Kurusa
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0 or MIT
|
|
//
|
|
|
|
//! Simple unit tests about the control groups system.
|
|
use cgroups::{Cgroup, CgroupPid};
|
|
|
|
#[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();
|
|
}
|