Fix test

Signed-off-by: Tim Zhang <tim@hyper.sh>
This commit is contained in:
Tim Zhang
2020-12-03 17:53:26 +08:00
parent 42ee1bafbd
commit 438d774866
10 changed files with 35 additions and 43 deletions

View File

@@ -20,8 +20,7 @@
//! # use cgroups::devices::*;
//! # use cgroups::cgroup_builder::*;
//! let h = cgroups::hierarchies::auto();
//! let h = Box::new(&*h);
//! let cgroup: Cgroup = CgroupBuilder::new("hello", h)
//! let cgroup: Cgroup = CgroupBuilder::new("hello")
//! .memory()
//! .kernel_memory_limit(1024 * 1024)
//! .memory_hard_limit(1024 * 1024)
@@ -58,7 +57,7 @@
//! .read(6, 1, 10)
//! .write(11, 1, 100)
//! .done()
//! .build();
//! .build(h);
//! ```
use crate::{

View File

@@ -18,12 +18,11 @@ use cgroups::*;
#[test]
pub fn test_cpu_res_build() {
let h = cgroups::hierarchies::auto();
let h = Box::new(&*h);
let cg: Cgroup = CgroupBuilder::new("test_cpu_res_build", h)
let cg: Cgroup = CgroupBuilder::new("test_cpu_res_build")
.cpu()
.shares(85)
.done()
.build();
.build(h);
{
let cpu: &CpuController = cg.controller_of().unwrap();
@@ -37,14 +36,13 @@ pub fn test_cpu_res_build() {
#[test]
pub fn test_memory_res_build() {
let h = cgroups::hierarchies::auto();
let h = Box::new(&*h);
let cg: Cgroup = CgroupBuilder::new("test_memory_res_build", h)
let cg: Cgroup = CgroupBuilder::new("test_memory_res_build")
.memory()
.kernel_memory_limit(128 * 1024 * 1024)
.swappiness(70)
.memory_hard_limit(1024 * 1024 * 1024)
.done()
.build();
.build(h);
{
let c: &MemController = cg.controller_of().unwrap();
@@ -61,12 +59,11 @@ pub fn test_memory_res_build() {
#[test]
pub fn test_pid_res_build() {
let h = cgroups::hierarchies::auto();
let h = Box::new(&*h);
let cg: Cgroup = CgroupBuilder::new("test_pid_res_build", h)
let cg: Cgroup = CgroupBuilder::new("test_pid_res_build")
.pid()
.maximum_number_of_processes(MaxValue::Value(123))
.done()
.build();
.build(h);
{
let c: &PidController = cg.controller_of().unwrap();
@@ -81,12 +78,11 @@ pub fn test_pid_res_build() {
#[ignore] // ignore this test for now, not sure why my kernel doesn't like it
pub fn test_devices_res_build() {
let h = cgroups::hierarchies::auto();
let h = Box::new(&*h);
let cg: Cgroup = CgroupBuilder::new("test_devices_res_build", h)
let cg: Cgroup = CgroupBuilder::new("test_devices_res_build")
.devices()
.device(1, 6, DeviceType::Char, true, vec![DevicePermissions::Read])
.done()
.build();
.build(h);
{
let c: &DevicesController = cg.controller_of().unwrap();
@@ -112,12 +108,11 @@ pub fn test_network_res_build() {
// FIXME add cases for v2
return;
}
let h = Box::new(&*h);
let cg: Cgroup = CgroupBuilder::new("test_network_res_build", h)
let cg: Cgroup = CgroupBuilder::new("test_network_res_build")
.network()
.class_id(1337)
.done()
.build();
.build(h);
{
let c: &NetClsController = cg.controller_of().unwrap();
@@ -134,12 +129,11 @@ pub fn test_hugepages_res_build() {
// FIXME add cases for v2
return;
}
let h = Box::new(&*h);
let cg: Cgroup = CgroupBuilder::new("test_hugepages_res_build", h)
let cg: Cgroup = CgroupBuilder::new("test_hugepages_res_build")
.hugepages()
.limit("2MB".to_string(), 4 * 2 * 1024 * 1024)
.done()
.build();
.build(h);
{
let c: &HugeTlbController = cg.controller_of().unwrap();
@@ -156,12 +150,11 @@ pub fn test_hugepages_res_build() {
#[ignore] // high version kernel not support `blkio.weight`
pub fn test_blkio_res_build() {
let h = cgroups::hierarchies::auto();
let h = Box::new(&*h);
let cg: Cgroup = CgroupBuilder::new("test_blkio_res_build", h)
let cg: Cgroup = CgroupBuilder::new("test_blkio_res_build")
.blkio()
.weight(100)
.done()
.build();
.build(h);
{
let c: &BlkIoController = cg.controller_of().unwrap();

View File

@@ -13,7 +13,7 @@ use cgroups::{Cgroup, CgroupPid, Subsystem};
fn test_tasks_iterator() {
let h = cgroups::hierarchies::auto();
let pid = libc::pid_t::from(nix::unistd::getpid()) as u64;
let cg = Cgroup::new(&*h, String::from("test_tasks_iterator"));
let cg = Cgroup::new(h, String::from("test_tasks_iterator"));
{
// Add a task to the control group.
cg.add_task(CgroupPid::from(pid)).unwrap();
@@ -45,7 +45,7 @@ fn test_cgroup_with_relative_paths() {
let cgroup_root = h.root();
let cgroup_name = "test_cgroup_with_relative_paths";
let cg = Cgroup::load(&*h, String::from(cgroup_name));
let cg = Cgroup::load(h, String::from(cgroup_name));
{
let subsystems = cg.subsystems();
subsystems.into_iter().for_each(|sub| match sub {
@@ -83,14 +83,14 @@ fn test_cgroup_v2() {
return;
}
let h = cgroups::hierarchies::auto();
let cg = Cgroup::load(&*h, String::from("test_v2"));
let cg = Cgroup::new(h, String::from("test_v2"));
let mem_controller: &MemController = cg.controller_of().unwrap();
let (mem, swp, rev) = (4 * 1024 * 1000, 2 * 1024 * 1000, 1024 * 1000);
let _ = mem_controller.set_limit(mem);
let _ = mem_controller.set_memswap_limit(swp);
let _ = mem_controller.set_soft_limit(rev);
mem_controller.set_limit(mem).unwrap();
mem_controller.set_memswap_limit(swp).unwrap();
mem_controller.set_soft_limit(rev).unwrap();
let memory_stat = mem_controller.memory_stat();
println!("memory_stat {:?}", memory_stat);

View File

@@ -10,7 +10,7 @@ use cgroups::Cgroup;
#[test]
fn test_cfs_quota_and_periods() {
let h = cgroups::hierarchies::auto();
let cg = Cgroup::new(&*h, String::from("test_cfs_quota_and_periods"));
let cg = Cgroup::new(h, String::from("test_cfs_quota_and_periods"));
let cpu_controller: &CpuController = cg.controller_of().unwrap();

View File

@@ -13,7 +13,7 @@ use std::fs;
#[test]
fn test_cpuset_memory_pressure_root_cg() {
let h = cgroups::hierarchies::auto();
let cg = Cgroup::new(&*h, String::from("test_cpuset_memory_pressure_root_cg"));
let cg = Cgroup::new(h, String::from("test_cpuset_memory_pressure_root_cg"));
{
let cpuset: &CpuSetController = cg.controller_of().unwrap();
@@ -27,7 +27,7 @@ fn test_cpuset_memory_pressure_root_cg() {
#[test]
fn test_cpuset_set_cpus() {
let h = cgroups::hierarchies::auto();
let cg = Cgroup::new(&*h, String::from("test_cpuset_set_cpus"));
let cg = Cgroup::new(h, String::from("test_cpuset_set_cpus"));
{
let cpuset: &CpuSetController = cg.controller_of().unwrap();
@@ -65,7 +65,7 @@ fn test_cpuset_set_cpus() {
#[test]
fn test_cpuset_set_cpus_add_task() {
let h = cgroups::hierarchies::auto();
let cg = Cgroup::new(&*h, String::from("test_cpuset_set_cpus_add_task/sub-dir"));
let cg = Cgroup::new(h, String::from("test_cpuset_set_cpus_add_task/sub-dir"));
let cpuset: &CpuSetController = cg.controller_of().unwrap();
let set = cpuset.cpuset();

View File

@@ -17,7 +17,7 @@ fn test_devices_parsing() {
}
let h = cgroups::hierarchies::auto();
let cg = Cgroup::new(&*h, String::from("test_devices_parsing"));
let cg = Cgroup::new(h, String::from("test_devices_parsing"));
{
let devices: &DevicesController = cg.controller_of().unwrap();

View File

@@ -17,7 +17,7 @@ fn test_hugetlb_sizes() {
}
let h = cgroups::hierarchies::auto();
let cg = Cgroup::new(&*h, String::from("test_hugetlb_sizes"));
let cg = Cgroup::new(h, String::from("test_hugetlb_sizes"));
{
let hugetlb_controller: &HugeTlbController = cg.controller_of().unwrap();
let _ = hugetlb_controller.get_sizes();

View File

@@ -11,7 +11,7 @@ use cgroups::{Cgroup, MaxValue};
#[test]
fn test_disable_oom_killer() {
let h = cgroups::hierarchies::auto();
let cg = Cgroup::new(&*h, String::from("test_disable_oom_killer"));
let cg = Cgroup::new(h, String::from("test_disable_oom_killer"));
{
let mem_controller: &MemController = cg.controller_of().unwrap();
@@ -40,7 +40,7 @@ fn set_mem_v2() {
return;
}
let cg = Cgroup::new(&*h, String::from("set_mem_v2"));
let cg = Cgroup::new(h, String::from("set_mem_v2"));
{
let mem_controller: &MemController = cg.controller_of().unwrap();

View File

@@ -17,7 +17,7 @@ use libc::pid_t;
#[test]
fn create_and_delete_cgroup() {
let h = cgroups::hierarchies::auto();
let cg = Cgroup::new(&*h, String::from("create_and_delete_cgroup"));
let cg = Cgroup::new(h, String::from("create_and_delete_cgroup"));
{
let pidcontroller: &PidController = cg.controller_of().unwrap();
pidcontroller.set_pid_max(MaxValue::Value(1337)).unwrap();
@@ -31,7 +31,7 @@ fn create_and_delete_cgroup() {
#[test]
fn test_pids_current_is_zero() {
let h = cgroups::hierarchies::auto();
let cg = Cgroup::new(&*h, String::from("test_pids_current_is_zero"));
let cg = Cgroup::new(h, String::from("test_pids_current_is_zero"));
{
let pidcontroller: &PidController = cg.controller_of().unwrap();
let current = pidcontroller.get_pid_current();
@@ -43,7 +43,7 @@ fn test_pids_current_is_zero() {
#[test]
fn test_pids_events_is_zero() {
let h = cgroups::hierarchies::auto();
let cg = Cgroup::new(&*h, String::from("test_pids_events_is_zero"));
let cg = Cgroup::new(h, String::from("test_pids_events_is_zero"));
{
let pidcontroller: &PidController = cg.controller_of().unwrap();
let events = pidcontroller.get_pid_events();
@@ -56,7 +56,7 @@ fn test_pids_events_is_zero() {
#[test]
fn test_pid_events_is_not_zero() {
let h = cgroups::hierarchies::auto();
let cg = Cgroup::new(&*h, String::from("test_pid_events_is_not_zero"));
let cg = Cgroup::new(h, String::from("test_pid_events_is_not_zero"));
{
let pids: &PidController = cg.controller_of().unwrap();
let before = pids.get_pid_events();

View File

@@ -11,7 +11,7 @@ use cgroups::{Cgroup, MaxValue, PidResources, Resources};
#[test]
fn pid_resources() {
let h = cgroups::hierarchies::auto();
let cg = Cgroup::new(&*h, String::from("pid_resources"));
let cg = Cgroup::new(h, String::from("pid_resources"));
{
let res = Resources {
pid: PidResources {