-
Notifications
You must be signed in to change notification settings - Fork 346
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 process test #2968
base: main
Are you sure you want to change the base?
Add process test #2968
Changes from all commits
b156f6b
43a6d7a
78dfb54
aef1f45
1926533
3d52b59
ef26e24
846df14
94526b2
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,2 @@ | ||
mod process_test; | ||
pub use process_test::get_process_test; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::utils::test_inside_container; | ||
Check warning on line 1 in tests/contest/contest/src/tests/process/process_test.rs GitHub Actions / check (x86_64, gnu)
Check warning on line 1 in tests/contest/contest/src/tests/process/process_test.rs GitHub Actions / check (x86_64, gnu)
Check warning on line 1 in tests/contest/contest/src/tests/process/process_test.rs GitHub Actions / check (x86_64, musl)
Check warning on line 1 in tests/contest/contest/src/tests/process/process_test.rs GitHub Actions / check (x86_64, musl)
Check warning on line 1 in tests/contest/contest/src/tests/process/process_test.rs GitHub Actions / check (aarch64, musl)
|
||
use anyhow::{bail, Context, Ok, Result}; | ||
use oci_spec::runtime::{ProcessBuilder, Spec, SpecBuilder}; | ||
use std::fs; | ||
use std::os::unix::fs::PermissionsExt; | ||
use test_framework::{test_result, Test, TestGroup, TestResult}; | ||
|
||
fn create_spec() -> Result<Spec> { | ||
let spec = SpecBuilder::default() | ||
.process( | ||
ProcessBuilder::default() | ||
.cwd("/test") | ||
.env(vec!["testa=valuea".into(), "testb=123".into()]) | ||
.build() | ||
.expect("error in creating process config"), | ||
) | ||
.build() | ||
.context("failed to build spec")?; | ||
|
||
Ok(spec) | ||
} | ||
|
||
fn process_test() -> TestResult { | ||
let spec = test_result!(create_spec()); | ||
test_inside_container(spec, &|_| { | ||
match fs::create_dir("/test") { | ||
Result::Ok(_) => { /*This is expected*/ } | ||
Err(e) => { | ||
bail!(e) | ||
} | ||
} | ||
let metadata = fs::metadata("/test")?; | ||
let mut permissions = metadata.permissions(); | ||
permissions.set_mode(0o700); | ||
|
||
Ok(()) | ||
}) | ||
} | ||
|
||
pub fn get_process_test() -> TestGroup { | ||
let mut process_test_group = TestGroup::new("process"); | ||
|
||
let test = Test::new("process_test", Box::new(process_test)); | ||
process_test_group.add(vec![Box::new(test)]); | ||
|
||
process_test_group | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ fn get_spec() -> Spec { | |
} | ||
} | ||
|
||
////////// ANCHOR: example_runtimetest_main | ||
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. Why is this line removed here? |
||
fn main() { | ||
let spec = get_spec(); | ||
let args: Vec<String> = env::args().collect(); | ||
|
@@ -44,6 +43,7 @@ fn main() { | |
"io_priority_class_be" => tests::test_io_priority_class(&spec, IoprioClassBe), | ||
"io_priority_class_idle" => tests::test_io_priority_class(&spec, IoprioClassIdle), | ||
"devices" => tests::validate_devices(&spec), | ||
"process" => tests::validate_process(&spec), | ||
"no_pivot" => tests::validate_rootfs(), | ||
_ => eprintln!("error due to unexpected execute test name: {execute_test}"), | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
use std::env; | ||
use std::fs::{self, read_dir}; | ||
use std::os::linux::fs::MetadataExt; | ||
use std::os::unix::fs::{FileTypeExt, PermissionsExt}; | ||
use std::path::Path; | ||
Check warning on line 5 in tests/contest/runtimetest/src/tests.rs GitHub Actions / check (x86_64, gnu)
Check warning on line 5 in tests/contest/runtimetest/src/tests.rs GitHub Actions / check (x86_64, musl)
|
||
|
||
use anyhow::{bail, 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. remove this extra blank line. |
||
use nix::errno::Errno; | ||
use nix::libc; | ||
use nix::sys::utsname; | ||
|
@@ -546,6 +548,34 @@ | |
} | ||
} | ||
|
||
pub fn validate_process(spec: &Spec) { | ||
let process = spec.process().as_ref().unwrap(); | ||
|
||
if process.cwd().ne(&getcwd().unwrap()) { | ||
eprintln!( | ||
"error due to spec cwd want {:?}, got {:?}", | ||
process.cwd(), | ||
getcwd().unwrap() | ||
) | ||
} | ||
|
||
if env::var("testa").unwrap().to_string().ne("valuea") { | ||
eprintln!( | ||
"error due to spec environment value of testa want {:?}, got {:?}", | ||
"valuea", | ||
env::var("testa") | ||
) | ||
} | ||
|
||
if env::var("testb").unwrap().to_string().ne("123") { | ||
eprintln!( | ||
"error due to spec environment value of testb want {:?}, got {:?}", | ||
"123", | ||
env::var("testb") | ||
) | ||
} | ||
} | ||
Comment on lines
+562
to
+577
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 for this as well, we should cross check this with env from the spec, similar to how the go test is doing. |
||
|
||
// 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() { | ||
|
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.
This should not be
/test
, you should take the bundle param in the closure and append/test
and create that dir. This callback is run in host's fs before running the container, so you should be using bundle path and create this dir.