Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration test: cgroup v1 relative-cpus tests #2898

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
78 changes: 78 additions & 0 deletions tests/contest/contest/src/tests/cgroups/cpu/v1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use std::fs;
use std::path::Path;
use std::string::ToString;

use anyhow::Result;
use libcgroups::common;
use libcgroups::v1::{util, ControllerType};
use num_cpus;
use test_framework::{test_result, ConditionalTest, TestGroup, TestResult};

Expand Down Expand Up @@ -219,6 +223,74 @@ fn test_cpu_cgroups() -> TestResult {
TestResult::Passed
}

fn check_cgroup_subsystem(
cgroup_name: &str,
subsystem: &ControllerType,
filename: &str,
expected: &dyn ToString,
) -> Result<()> {
let mount_point = util::get_subsystem_mount_point(subsystem)?;
let cgroup_path = mount_point
.join("runtime-test")
.join(cgroup_name)
.join(filename);

let content = fs::read_to_string(&cgroup_path)?;
let trimmed = content.trim();
assert_eq!(trimmed, expected.to_string());
Ok(())
}

fn test_relative_cpus() -> TestResult {
let case = test_result!(create_cpu_spec(
1024,
100000,
50000,
None,
"0-1",
"0",
get_realtime_period(),
get_realtime_runtime(),
));
let spec = test_result!(create_spec("test_relative_cpus", case.clone()));

test_outside_container(spec, &|data| {
test_result!(check_container_created(&data));
let cgroup_name = "test_relative_cpus";
test_result!(check_cgroup_subsystem(
cgroup_name,
&ControllerType::CpuAcct,
"cpu.shares",
&case.shares().unwrap(),
));
test_result!(check_cgroup_subsystem(
cgroup_name,
&ControllerType::CpuAcct,
"cpu.cfs_period_us",
&case.period().unwrap(),
));
test_result!(check_cgroup_subsystem(
cgroup_name,
&ControllerType::CpuAcct,
"cpu.cfs_quota_us",
&case.quota().unwrap(),
));
test_result!(check_cgroup_subsystem(
cgroup_name,
&ControllerType::CpuSet,
"cpuset.cpus",
&case.cpus().to_owned().unwrap(),
));
test_result!(check_cgroup_subsystem(
cgroup_name,
&ControllerType::CpuSet,
"cpuset.mems",
&case.mems().to_owned().unwrap()
));
TestResult::Passed
})
}

fn test_empty_cpu() -> TestResult {
let cgroup_name = "test_empty_cpu";
let spec = test_result!(create_empty_spec(cgroup_name));
Expand Down Expand Up @@ -317,12 +389,18 @@ pub fn get_test_group() -> TestGroup {
Box::new(can_run_idle),
Box::new(test_cpu_idle_set),
);
let relative_cpus = ConditionalTest::new(
"test_relative_cpus",
Box::new(can_run),
Box::new(test_relative_cpus),
);

test_group.add(vec![
Box::new(linux_cgroups_cpus),
Box::new(empty_cpu),
Box::new(cpu_idle_set),
Box::new(cpu_idle_default),
Box::new(relative_cpus),
]);

test_group
Expand Down
Loading