-
Notifications
You must be signed in to change notification settings - Fork 347
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 process rlimits #2977
Merged
Merged
Add test process rlimits #2977
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0b07cfe
add process rlimits test
sat0ken a1b2542
fix newline code
sat0ken 7e4eb5e
fix fmt
sat0ken f829e0c
Merge branch 'main' into add-test-process-rlimits
sat0ken b4368a3
fix format err
sat0ken abe0ce8
Merge branch 'add-test-process-rlimits' of github.com:sat0ken/youki i…
sat0ken 5625de5
add process args to run test
sat0ken bc23f93
fix unsafe code by use nix
sat0ken 272bfb1
remove unused import
sat0ken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod process_rlimits_test; | ||
pub use process_rlimits_test::get_process_rlimits_test; |
67 changes: 67 additions & 0 deletions
67
tests/contest/contest/src/tests/process_rlimits/process_rlimits_test.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use anyhow::{Context, Ok, Result}; | ||
use oci_spec::runtime::{ | ||
PosixRlimit, PosixRlimitBuilder, PosixRlimitType, ProcessBuilder, Spec, SpecBuilder, | ||
}; | ||
use test_framework::{test_result, Test, TestGroup, TestResult}; | ||
|
||
use crate::utils::test_inside_container; | ||
|
||
const GIGABYTES: u64 = 1024 * 1024 * 1024; | ||
|
||
fn create_rlimit( | ||
rlimit_type: PosixRlimitType, | ||
hard_val: u64, | ||
soft_val: u64, | ||
) -> Result<PosixRlimit> { | ||
let rlimit = PosixRlimitBuilder::default() | ||
.typ(rlimit_type) | ||
.hard(hard_val) | ||
.soft(soft_val) | ||
.build()?; | ||
Ok(rlimit) | ||
} | ||
|
||
#[allow(clippy::identity_op)] | ||
fn create_spec() -> Result<Spec> { | ||
let spec = SpecBuilder::default() | ||
.process( | ||
ProcessBuilder::default() | ||
.args(vec![ | ||
"runtimetest".to_string(), | ||
"process_rlimits".to_string(), | ||
]) | ||
.rlimits(vec![ | ||
create_rlimit(PosixRlimitType::RlimitAs, 2 * GIGABYTES, 1 * GIGABYTES).unwrap(), | ||
create_rlimit(PosixRlimitType::RlimitCore, 4 * GIGABYTES, 3 * GIGABYTES) | ||
.unwrap(), | ||
create_rlimit(PosixRlimitType::RlimitData, 6 * GIGABYTES, 5 * GIGABYTES) | ||
.unwrap(), | ||
create_rlimit(PosixRlimitType::RlimitFsize, 8 * GIGABYTES, 7 * GIGABYTES) | ||
.unwrap(), | ||
create_rlimit(PosixRlimitType::RlimitStack, 10 * GIGABYTES, 9 * GIGABYTES) | ||
.unwrap(), | ||
create_rlimit(PosixRlimitType::RlimitCpu, 120, 60).unwrap(), | ||
create_rlimit(PosixRlimitType::RlimitNofile, 4000, 3000).unwrap(), | ||
]) | ||
.build() | ||
.expect("error in creating process config"), | ||
) | ||
.build() | ||
.context("failed to build spec")?; | ||
|
||
Ok(spec) | ||
} | ||
|
||
fn process_rlimits_test() -> TestResult { | ||
let spec = test_result!(create_spec()); | ||
test_inside_container(spec, &|_| Ok(())) | ||
} | ||
|
||
pub fn get_process_rlimits_test() -> TestGroup { | ||
let mut process_rlimits_test_group = TestGroup::new("process_rlimits"); | ||
|
||
let test = Test::new("process_rlimits_test", Box::new(process_rlimits_test)); | ||
process_rlimits_test_group.add(vec![Box::new(test)]); | ||
|
||
process_rlimits_test_group | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,10 +6,13 @@ use std::path::Path; | |||||
use anyhow::{bail, Result}; | ||||||
use nix::errno::Errno; | ||||||
use nix::libc; | ||||||
use nix::sys::resource::{getrlimit, Resource}; | ||||||
use nix::sys::utsname; | ||||||
use nix::unistd::getcwd; | ||||||
use oci_spec::runtime::IOPriorityClass::{self, IoprioClassBe, IoprioClassIdle, IoprioClassRt}; | ||||||
use oci_spec::runtime::{LinuxDevice, LinuxDeviceType, LinuxSchedulerPolicy, Spec}; | ||||||
use oci_spec::runtime::{ | ||||||
LinuxDevice, LinuxDeviceType, LinuxSchedulerPolicy, PosixRlimit, PosixRlimitType, Spec, | ||||||
}; | ||||||
|
||||||
use crate::utils::{self, test_read_access, test_write_access}; | ||||||
|
||||||
|
@@ -546,6 +549,53 @@ pub fn test_io_priority_class(spec: &Spec, io_priority_class: IOPriorityClass) { | |||||
} | ||||||
} | ||||||
|
||||||
pub fn validate_process_rlimits(spec: &Spec) { | ||||||
let process = spec.process().as_ref().unwrap(); | ||||||
let spec_rlimits: &Vec<PosixRlimit> = process.rlimits().as_ref().unwrap(); | ||||||
|
||||||
for spec_rlimit in spec_rlimits.iter() { | ||||||
let (soft_limit, hard_limit) = getrlimit(change_resource_type(spec_rlimit.typ())).unwrap(); | ||||||
if spec_rlimit.hard() != hard_limit { | ||||||
eprintln!( | ||||||
"error type of {:?} hard rlimit expected {:?} , got {:?}", | ||||||
spec_rlimit.typ(), | ||||||
spec_rlimit.hard(), | ||||||
hard_limit | ||||||
) | ||||||
} | ||||||
|
||||||
if spec_rlimit.soft() != soft_limit { | ||||||
eprintln!( | ||||||
"error type of {:?} soft rlimit expected {:?} , got {:?}", | ||||||
spec_rlimit.typ(), | ||||||
spec_rlimit.soft(), | ||||||
soft_limit | ||||||
) | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
fn change_resource_type(resource_type: PosixRlimitType) -> Resource { | ||||||
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.
Suggested change
my reasoning is |
||||||
match resource_type { | ||||||
PosixRlimitType::RlimitCpu => Resource::RLIMIT_CPU, | ||||||
PosixRlimitType::RlimitFsize => Resource::RLIMIT_FSIZE, | ||||||
PosixRlimitType::RlimitData => Resource::RLIMIT_DATA, | ||||||
PosixRlimitType::RlimitStack => Resource::RLIMIT_STACK, | ||||||
PosixRlimitType::RlimitCore => Resource::RLIMIT_CORE, | ||||||
PosixRlimitType::RlimitRss => Resource::RLIMIT_RSS, | ||||||
PosixRlimitType::RlimitNproc => Resource::RLIMIT_NPROC, | ||||||
PosixRlimitType::RlimitNofile => Resource::RLIMIT_NOFILE, | ||||||
PosixRlimitType::RlimitMemlock => Resource::RLIMIT_MEMLOCK, | ||||||
PosixRlimitType::RlimitAs => Resource::RLIMIT_AS, | ||||||
PosixRlimitType::RlimitLocks => Resource::RLIMIT_LOCKS, | ||||||
PosixRlimitType::RlimitSigpending => Resource::RLIMIT_SIGPENDING, | ||||||
PosixRlimitType::RlimitMsgqueue => Resource::RLIMIT_MSGQUEUE, | ||||||
PosixRlimitType::RlimitNice => Resource::RLIMIT_NICE, | ||||||
PosixRlimitType::RlimitRtprio => Resource::RLIMIT_RTPRIO, | ||||||
PosixRlimitType::RlimitRttime => Resource::RLIMIT_RTTIME, | ||||||
} | ||||||
} | ||||||
|
||||||
// the validate_rootfs function is used to validate the rootfs of the container is | ||||||
// as expected. This function is used in the no_pivot test to validate the rootfs | ||||||
pub fn validate_rootfs() { | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Same for soft limit