-
Notifications
You must be signed in to change notification settings - Fork 355
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
Add test code linux_cgroups_devices #3000
base: main
Are you sure you want to change the base?
Changes from 2 commits
1cbfba4
f19119d
c183114
2d32484
0ea31ff
dc5a1c1
22a5225
4bcf5f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use std::path::Path; | ||
|
||
use anyhow::Context; | ||
use oci_spec::runtime::{ | ||
LinuxBuilder, LinuxDeviceCgroup, LinuxDeviceCgroupBuilder, LinuxDeviceType, | ||
LinuxResourcesBuilder, Spec, SpecBuilder, | ||
}; | ||
use test_framework::{test_result, ConditionalTest, TestGroup, TestResult}; | ||
|
||
use crate::utils::test_outside_container; | ||
use crate::utils::test_utils::check_container_created; | ||
|
||
fn can_run() -> bool { | ||
Path::new("/sys/fs/cgroup/devices").exists() | ||
} | ||
|
||
fn linux_device_build( | ||
allow: bool, | ||
dev_type: LinuxDeviceType, | ||
major: i64, | ||
minor: i64, | ||
access: String, | ||
) -> LinuxDeviceCgroup { | ||
LinuxDeviceCgroupBuilder::default() | ||
.access(allow.to_string()) | ||
.typ(dev_type) | ||
.major(major) | ||
.minor(minor) | ||
.access(access) | ||
.build() | ||
.unwrap() | ||
} | ||
|
||
fn create_spec(cgroup_name: &str, devices: Vec<LinuxDeviceCgroup>) -> anyhow::Result<Spec> { | ||
let spec = SpecBuilder::default() | ||
.linux( | ||
LinuxBuilder::default() | ||
.cgroups_path(Path::new("/runtime-test").join(cgroup_name)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is incorrect. For absolute cgroups path, it should be single level at root like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Becouse, I check https://github.com/youki-dev/youki/blob/main/tests/contest/contest/src/tests/cgroups/blkio.rs#L95 |
||
.resources( | ||
LinuxResourcesBuilder::default() | ||
.devices(devices) | ||
.build() | ||
.context("failed to build resource spec")?, | ||
) | ||
.build() | ||
.context("failed to build linux spec")?, | ||
) | ||
.build() | ||
.context("failed to build spec")?; | ||
|
||
Ok(spec) | ||
} | ||
|
||
fn test_devices_cgroups() -> TestResult { | ||
let cgroup_name = "test_devices_cgroups"; | ||
let linux_devices = vec![ | ||
linux_device_build(true, LinuxDeviceType::C, 10, 229, "rwm".to_string()), | ||
linux_device_build(true, LinuxDeviceType::B, 8, 20, "rw".to_string()), | ||
linux_device_build(true, LinuxDeviceType::B, 10, 200, "r".to_string()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed it. |
||
]; | ||
let spec = test_result!(create_spec(cgroup_name, linux_devices)); | ||
|
||
let test_result = test_outside_container(spec, &|data| { | ||
test_result!(check_container_created(&data)); | ||
TestResult::Passed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed about like original test, read devices.list file, and compare to spec. |
||
}); | ||
if let TestResult::Failed(_) = test_result { | ||
return test_result; | ||
} | ||
test_result | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is no-op, we can simply return the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed it. |
||
} | ||
|
||
pub fn get_test_group() -> TestGroup { | ||
let mut test_group = TestGroup::new("cgroup_v1_devices"); | ||
let linux_cgroups_devices = ConditionalTest::new( | ||
"test_linux_cgroups_devices", | ||
Box::new(can_run), | ||
Box::new(crate::tests::cgroups::devices::test_devices_cgroups), | ||
); | ||
|
||
test_group.add(vec![Box::new(linux_cgroups_devices)]); | ||
|
||
test_group | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we setting access twice? Is one of them supposed to be allow instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's my mistake. I fixed it.
0ea31ff