-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add e2e test: process rlimits (#2977)
* add process rlimits test Signed-off-by: sat0ken <[email protected]> * fix newline code Signed-off-by: sat0ken <[email protected]> * fix fmt Signed-off-by: sat0ken <[email protected]> * fix format err Signed-off-by: sat0ken <[email protected]> * add process args to run test Signed-off-by: sat0ken <[email protected]> * fix unsafe code by use nix Signed-off-by: sat0ken <[email protected]> * remove unused import Signed-off-by: sat0ken <[email protected]> --------- Signed-off-by: sat0ken <[email protected]>
- Loading branch information
Showing
6 changed files
with
125 additions
and
1 deletion.
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