Skip to content

Commit

Permalink
add test process_oom_score_adj
Browse files Browse the repository at this point in the history
Signed-off-by: Yusuke Sakurai <[email protected]>
  • Loading branch information
saku3 committed Nov 13, 2024
1 parent 41e4fb5 commit 9307ee1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/contest/contest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::tests::mounts_recursive::get_mounts_recursive_test;
use crate::tests::no_pivot::get_no_pivot_test;
use crate::tests::pidfile::get_pidfile_test;
use crate::tests::process_rlimits::get_process_rlimits_test;
use crate::tests::process_oom_score_adj::get_process_oom_score_adj_test;
use crate::tests::readonly_paths::get_ro_paths_test;
use crate::tests::scheduler::get_scheduler_test;
use crate::tests::seccomp::get_seccomp_test;
Expand Down Expand Up @@ -117,6 +118,7 @@ fn main() -> Result<()> {
let devices = get_devices_test();
let process_rlimtis = get_process_rlimits_test();
let no_pivot = get_no_pivot_test();
let process_oom_score_adj = get_process_oom_score_adj_test();

tm.add_test_group(Box::new(cl));
tm.add_test_group(Box::new(cc));
Expand All @@ -142,6 +144,7 @@ fn main() -> Result<()> {
tm.add_test_group(Box::new(devices));
tm.add_test_group(Box::new(process_rlimtis));
tm.add_test_group(Box::new(no_pivot));
tm.add_test_group(Box::new(process_oom_score_adj));

tm.add_test_group(Box::new(io_priority_test));
tm.add_cleanup(Box::new(cgroups::cleanup_v1));
Expand Down
1 change: 1 addition & 0 deletions tests/contest/contest/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod mounts_recursive;
pub mod no_pivot;
pub mod pidfile;
pub mod process_rlimits;
pub mod process_oom_score_adj;
pub mod readonly_paths;
pub mod scheduler;
pub mod seccomp;
Expand Down
2 changes: 2 additions & 0 deletions tests/contest/contest/src/tests/process_oom_score_adj/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod process_oom_score_adj_test;
pub use process_oom_score_adj_test::get_process_oom_score_adj_test;
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use crate::utils::test_inside_container;

Check warning on line 1 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 1 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 1 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 1 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 1 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 1 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 1 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 1 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs
use anyhow::{Context, Ok, Result};
use oci_spec::runtime::{ProcessBuilder, Spec, SpecBuilder};
use test_framework::{test_result, Test, TestGroup, TestResult};

Check warning on line 5 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 5 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 5 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 5 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 5 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 5 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 5 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 5 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs
fn create_spec() -> Result<Spec> {
let spec = SpecBuilder::default().process(
ProcessBuilder::default()
.args(vec![
"runtimetest".to_string(),
"process_oom_score_adj".to_string(),
])
.oom_score_adj(500)
.build()
.expect("error in creating process config"),
).build().context("failed to build spec")?;

Ok(spec)
}

fn process_oom_score_adj_test() -> TestResult {
let spec = test_result!(create_spec());
test_inside_container(spec, &|_| Ok(()))
}

pub fn get_process_oom_score_adj_test() -> TestGroup {

Check warning on line 26 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 26 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 26 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 26 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 26 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 26 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 26 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

Check warning on line 26 in tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/contest/src/tests/process_oom_score_adj/process_oom_score_adj_test.rs
let mut process_oom_score_adj_test_group = TestGroup::new("process_oom_score_adj");

let test = Test::new("process_oom_score_adj", Box::new(process_oom_score_adj_test));
process_oom_score_adj_test_group.add(vec![Box::new(test)]);

process_oom_score_adj_test_group
}
1 change: 1 addition & 0 deletions tests/contest/runtimetest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fn main() {
"devices" => tests::validate_devices(&spec),
"process_rlimits" => tests::validate_process_rlimits(&spec),
"no_pivot" => tests::validate_rootfs(),
"process_oom_score_adj" => tests::validate_process_oom_score_adj(&spec),
_ => eprintln!("error due to unexpected execute test name: {execute_test}"),
}
}
17 changes: 17 additions & 0 deletions tests/contest/runtimetest/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,3 +629,20 @@ pub fn validate_rootfs() {
eprintln!("error due to rootfs want {expected:?}, got {entries:?}");
}
}

pub fn validate_process_oom_score_adj(spec: &Spec) {
let process = spec.process().as_ref().unwrap();
let expected_value = process.oom_score_adj().unwrap();

let pid = std::process::id();
let oom_score_adj_path = format!("/proc/{}/oom_score_adj", pid);

let actual_value = fs::read_to_string(oom_score_adj_path)
.unwrap_or_else(|_| panic!("Failed to read file content"));

Check warning on line 641 in tests/contest/runtimetest/src/tests.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/runtimetest/src/tests.rs

Check warning on line 641 in tests/contest/runtimetest/src/tests.rs

View workflow job for this annotation

GitHub Actions / check (x86_64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/runtimetest/src/tests.rs

Check warning on line 641 in tests/contest/runtimetest/src/tests.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, musl)

Diff in /home/runner/work/youki/youki/tests/contest/runtimetest/src/tests.rs

Check warning on line 641 in tests/contest/runtimetest/src/tests.rs

View workflow job for this annotation

GitHub Actions / check (aarch64, gnu)

Diff in /home/runner/work/youki/youki/tests/contest/runtimetest/src/tests.rs

if actual_value != expected_value.to_string() {
eprintln!(
"Unexpected oom_score_adj, expected: {expected_value} found: {actual_value}"
);
}
}

0 comments on commit 9307ee1

Please sign in to comment.