mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
add basic v2 cpu/memory functions
Signed-off-by: bin liu <bin@hyper.sh>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
//! Simple unit tests about the control groups system.
|
||||
use cgroups::{Cgroup, CgroupPid, Hierarchy};
|
||||
use cgroups::{Cgroup, CgroupPid, Hierarchy, Subsystem};
|
||||
use cgroups::memory::{MemController, SetMemory};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[test]
|
||||
fn test_tasks_iterator() {
|
||||
@@ -24,3 +26,24 @@ fn test_tasks_iterator() {
|
||||
}
|
||||
cg.delete();
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_cgroup_with_prefix() {
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let h = Box::new(&*h);
|
||||
let mut prefixes = HashMap::new();
|
||||
prefixes.insert("memory".to_string(), "/memory/abc/def".to_string());
|
||||
let cg = Cgroup::new_with_prefix(h, String::from("test_cgroup_with_prefix"), prefixes);
|
||||
{
|
||||
let subsystems = cg.subsystems();
|
||||
println!("mem path: {:?}", &subsystems);
|
||||
subsystems.into_iter().for_each(|sub| match sub {
|
||||
Subsystem::Pid(c) => {println!("path {:?}", c);},
|
||||
// base: "/sys/fs/cgroup", path: "/sys/fs/cgroup/memory/abc/def/test_cgroup_with_prefix"
|
||||
Subsystem::Mem(c) => {println!("path {:?}", c);},
|
||||
_ => {},
|
||||
});
|
||||
}
|
||||
cg.delete();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user