add disable oom_control function

Signed-off-by: bin liu <bin@hyper.sh>
This commit is contained in:
bin liu
2020-08-25 11:35:01 +08:00
parent 9d70467327
commit c702852fd7
3 changed files with 125 additions and 67 deletions

View File

@@ -1,10 +1,10 @@
//! Integration tests about the hugetlb subsystem
use cgroups::hugetlb::{HugeTlbController};
use cgroups::Controller;
use cgroups::hugetlb::HugeTlbController;
use cgroups::Cgroup;
use cgroups::Controller;
use cgroups::error::*;
use cgroups::error::ErrorKind::*;
use cgroups::error::*;
#[test]
fn test_hugetlb_sizes() {
@@ -20,15 +20,14 @@ fn test_hugetlb_sizes() {
let supported = hugetlb_controller.size_supported(size);
assert_eq!(supported, true);
assert_no_error( hugetlb_controller.failcnt(size));
assert_no_error( hugetlb_controller.limit_in_bytes(size));
assert_no_error( hugetlb_controller.usage_in_bytes(size));
assert_no_error( hugetlb_controller.max_usage_in_bytes(size));
assert_no_error(hugetlb_controller.failcnt(size));
assert_no_error(hugetlb_controller.limit_in_bytes(size));
assert_no_error(hugetlb_controller.usage_in_bytes(size));
assert_no_error(hugetlb_controller.max_usage_in_bytes(size));
}
cg.delete();
}
fn assert_no_error(r: Result<u64> ) {
assert_eq!(!r.is_err() , true)
}
fn assert_no_error(r: Result<u64>) {
assert_eq!(!r.is_err(), true)
}

29
tests/memory.rs Normal file
View File

@@ -0,0 +1,29 @@
//! Integration tests about the hugetlb subsystem
use cgroups::memory::MemController;
use cgroups::Cgroup;
use cgroups::Controller;
use cgroups::error::ErrorKind::*;
use cgroups::error::*;
#[test]
fn test_disable_oom_killer() {
let hier = cgroups::hierarchies::V1::new();
let cg = Cgroup::new(&hier, String::from("test_disable_oom_killer"));
{
let mem_controller: &MemController = cg.controller_of().unwrap();
// before disable
let m = mem_controller.memory_stat();
assert_eq!(m.oom_control.oom_kill_disable, false);
// disable oom killer
let r = mem_controller.disable_oom_killer();
assert_eq!(r.is_err(), false);
// after disable
let m = mem_controller.memory_stat();
assert_eq!(m.oom_control.oom_kill_disable, true);
}
cg.delete();
}