From 438d7748663b9c4c9caf8b2ffe4108d1eb0f07a1 Mon Sep 17 00:00:00 2001 From: Tim Zhang Date: Thu, 3 Dec 2020 17:53:26 +0800 Subject: [PATCH] Fix test Fix test Signed-off-by: Tim Zhang --- src/cgroup_builder.rs | 5 ++--- tests/builder.rs | 35 ++++++++++++++--------------------- tests/cgroup.rs | 12 ++++++------ tests/cpu.rs | 2 +- tests/cpuset.rs | 6 +++--- tests/devices.rs | 2 +- tests/hugetlb.rs | 2 +- tests/memory.rs | 4 ++-- tests/pids.rs | 8 ++++---- tests/resources.rs | 2 +- 10 files changed, 35 insertions(+), 43 deletions(-) diff --git a/src/cgroup_builder.rs b/src/cgroup_builder.rs index 244ca4a..f7033e4 100644 --- a/src/cgroup_builder.rs +++ b/src/cgroup_builder.rs @@ -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::{ diff --git a/tests/builder.rs b/tests/builder.rs index cf215a3..7eef071 100644 --- a/tests/builder.rs +++ b/tests/builder.rs @@ -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(); diff --git a/tests/cgroup.rs b/tests/cgroup.rs index 7a6d8dd..60ae4b3 100644 --- a/tests/cgroup.rs +++ b/tests/cgroup.rs @@ -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); diff --git a/tests/cpu.rs b/tests/cpu.rs index 9eb4e99..8d75871 100644 --- a/tests/cpu.rs +++ b/tests/cpu.rs @@ -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(); diff --git a/tests/cpuset.rs b/tests/cpuset.rs index 0e8aa2a..34808dd 100644 --- a/tests/cpuset.rs +++ b/tests/cpuset.rs @@ -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(); diff --git a/tests/devices.rs b/tests/devices.rs index c8bc33c..6758ff7 100644 --- a/tests/devices.rs +++ b/tests/devices.rs @@ -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(); diff --git a/tests/hugetlb.rs b/tests/hugetlb.rs index 505a6cb..380afd3 100644 --- a/tests/hugetlb.rs +++ b/tests/hugetlb.rs @@ -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(); diff --git a/tests/memory.rs b/tests/memory.rs index 92b508b..0f57af5 100644 --- a/tests/memory.rs +++ b/tests/memory.rs @@ -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(); diff --git a/tests/pids.rs b/tests/pids.rs index c756581..f5d7191 100644 --- a/tests/pids.rs +++ b/tests/pids.rs @@ -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(); diff --git a/tests/resources.rs b/tests/resources.rs index 7ceacfe..0cb65bc 100644 --- a/tests/resources.rs +++ b/tests/resources.rs @@ -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 {