diff --git a/justfile b/justfile index 853a0cf1..cc8e6b90 100644 --- a/justfile +++ b/justfile @@ -55,11 +55,11 @@ test-oci: # run rust oci integration tests test-contest: youki-release contest - {{ cwd }}/scripts/contest.sh {{ cwd }}/youki + sudo {{ cwd }}/scripts/contest.sh {{ cwd }}/youki # validate rust oci integration tests on runc validate-contest-runc: contest - {{ cwd }}/scripts/contest.sh runc + sudo RUNTIME_KIND="runc" {{ cwd }}/scripts/contest.sh runc # test podman rootless works with youki test-rootless-podman: diff --git a/scripts/contest.sh b/scripts/contest.sh index 235a21f6..c3109d07 100755 --- a/scripts/contest.sh +++ b/scripts/contest.sh @@ -24,7 +24,7 @@ if [ ! -f ${ROOT}/bundle.tar.gz ]; then fi touch ${LOGFILE} -sudo ${ROOT}/contest run --runtime "$RUNTIME" --runtimetest ${ROOT}/runtimetest > $LOGFILE +${ROOT}/contest run --runtime "$RUNTIME" --runtimetest ${ROOT}/runtimetest > $LOGFILE if [ 0 -ne $(grep "not ok" $LOGFILE | wc -l ) ]; then cat $LOGFILE diff --git a/tests/contest/contest/src/main.rs b/tests/contest/contest/src/main.rs index a24e1740..b1b81281 100644 --- a/tests/contest/contest/src/main.rs +++ b/tests/contest/contest/src/main.rs @@ -103,11 +103,9 @@ fn main() -> Result<()> { let ro_paths = get_ro_paths_test(); let hostname = get_hostname_test(); let mounts_recursive = get_mounts_recursive_test(); - #[allow(unused_variables)] let domainname = get_domainname_tests(); let intel_rdt = get_intel_rdt_test(); let sysctl = get_sysctl_test(); - #[allow(unused_variables)] let scheduler = get_scheduler_test(); tm.add_test_group(Box::new(cl)); @@ -127,10 +125,10 @@ fn main() -> Result<()> { tm.add_test_group(Box::new(ro_paths)); tm.add_test_group(Box::new(hostname)); tm.add_test_group(Box::new(mounts_recursive)); - // tm.add_test_group(Box::new(domainname)); // TODO (YJDoc2) fix in #2616 + tm.add_test_group(Box::new(domainname)); tm.add_test_group(Box::new(intel_rdt)); tm.add_test_group(Box::new(sysctl)); - // tm.add_test_group(Box::new(scheduler)); + tm.add_test_group(Box::new(scheduler)); tm.add_cleanup(Box::new(cgroups::cleanup_v1)); tm.add_cleanup(Box::new(cgroups::cleanup_v2)); diff --git a/tests/contest/contest/src/tests/domainname/mod.rs b/tests/contest/contest/src/tests/domainname/mod.rs index 1c0ff2d6..b8eb4c68 100644 --- a/tests/contest/contest/src/tests/domainname/mod.rs +++ b/tests/contest/contest/src/tests/domainname/mod.rs @@ -1,6 +1,6 @@ -use crate::utils::test_inside_container; +use crate::utils::{is_runtime_runc, test_inside_container}; use oci_spec::runtime::{ProcessBuilder, Spec, SpecBuilder}; -use test_framework::{Test, TestGroup, TestResult}; +use test_framework::{ConditionalTest, TestGroup, TestResult}; fn get_spec(domainname: &str) -> Spec { SpecBuilder::default() @@ -25,7 +25,11 @@ fn set_domainname_test() -> TestResult { pub fn get_domainname_tests() -> TestGroup { let mut tg = TestGroup::new("domainname_test"); - let set_domainname_test = Test::new("set_domainname_test", Box::new(set_domainname_test)); + let set_domainname_test = ConditionalTest::new( + "set_domainname_test", + Box::new(|| !is_runtime_runc()), + Box::new(set_domainname_test), + ); tg.add(vec![Box::new(set_domainname_test)]); tg diff --git a/tests/contest/contest/src/tests/scheduler/scheduler_policy.rs b/tests/contest/contest/src/tests/scheduler/scheduler_policy.rs index fbfed9c8..bbf68712 100644 --- a/tests/contest/contest/src/tests/scheduler/scheduler_policy.rs +++ b/tests/contest/contest/src/tests/scheduler/scheduler_policy.rs @@ -2,9 +2,9 @@ use anyhow::{Context, Result}; use oci_spec::runtime::{ LinuxSchedulerPolicy, ProcessBuilder, SchedulerBuilder, Spec, SpecBuilder, }; -use test_framework::{test_result, Test, TestGroup, TestResult}; +use test_framework::{test_result, ConditionalTest, TestGroup, TestResult}; -use crate::utils::test_inside_container; +use crate::utils::{is_runtime_runc, test_inside_container}; fn create_spec(policy: LinuxSchedulerPolicy, execute_test: &str) -> Result { let sc = SchedulerBuilder::default() @@ -46,11 +46,17 @@ fn scheduler_policy_batch_test() -> TestResult { pub fn get_scheduler_test() -> TestGroup { let mut scheduler_policy_group = TestGroup::new("set_scheduler_policy"); - let policy_fifo_test = Test::new("policy_other", Box::new(scheduler_policy_other_test)); - let policy_rr_test = Test::new("policy_batch", Box::new(scheduler_policy_batch_test)); - - scheduler_policy_group.add(vec![Box::new(policy_fifo_test)]); - scheduler_policy_group.add(vec![Box::new(policy_rr_test)]); + let policy_fifo_test = ConditionalTest::new( + "policy_other", + Box::new(|| !is_runtime_runc()), + Box::new(scheduler_policy_other_test), + ); + let policy_rr_test = ConditionalTest::new( + "policy_batch", + Box::new(|| !is_runtime_runc()), + Box::new(scheduler_policy_batch_test), + ); + scheduler_policy_group.add(vec![Box::new(policy_fifo_test), Box::new(policy_rr_test)]); scheduler_policy_group } diff --git a/tests/contest/contest/src/utils/mod.rs b/tests/contest/contest/src/utils/mod.rs index 77789fe5..fe546b87 100644 --- a/tests/contest/contest/src/utils/mod.rs +++ b/tests/contest/contest/src/utils/mod.rs @@ -1,8 +1,8 @@ pub mod support; pub mod test_utils; pub use support::{ - generate_uuid, get_project_path, get_runtime_path, get_runtimetest_path, prepare_bundle, - set_config, set_runtime_path, + generate_uuid, get_project_path, get_runtime_path, get_runtimetest_path, is_runtime_runc, + prepare_bundle, set_config, set_runtime_path, }; pub use test_utils::{ create_container, delete_container, get_state, kill_container, test_inside_container, diff --git a/tests/contest/contest/src/utils/support.rs b/tests/contest/contest/src/utils/support.rs index 9f735d71..b86f848f 100644 --- a/tests/contest/contest/src/utils/support.rs +++ b/tests/contest/contest/src/utils/support.rs @@ -91,3 +91,10 @@ pub fn set_config>(project_path: P, config: &Spec) -> Result<()> config.save(path)?; Ok(()) } + +pub fn is_runtime_runc() -> bool { + match std::env::var("RUNTIME_KIND") { + Err(_) => false, + Ok(s) => s == "runc", + } +} diff --git a/tests/contest/runtimetest/src/tests.rs b/tests/contest/runtimetest/src/tests.rs index ceda0ad8..8b4b90cb 100644 --- a/tests/contest/runtimetest/src/tests.rs +++ b/tests/contest/runtimetest/src/tests.rs @@ -1,10 +1,7 @@ use crate::utils::{self, test_read_access, test_write_access}; use anyhow::{bail, Result}; -use libc::getdomainname; -use nix::errno::Errno; -use nix::unistd::getcwd; +use nix::{errno::Errno, sys::utsname, unistd::getcwd}; use oci_spec::runtime::{LinuxSchedulerPolicy, Spec}; -use std::ffi::CStr; use std::fs::{self, read_dir}; use std::mem; use std::path::Path; @@ -90,23 +87,13 @@ pub fn validate_domainname(spec: &Spec) { return; } - const MAX_DOMAINNAME_SIZE: usize = 254; - let actual_domainname: [i8; MAX_DOMAINNAME_SIZE] = [0; MAX_DOMAINNAME_SIZE]; - - // TODO (YJDoc2) : libc now has support for getdomainname, update this to use that - let ret = - unsafe { getdomainname(actual_domainname.as_ptr() as *mut i8, MAX_DOMAINNAME_SIZE) }; - if ret == -1 { - eprintln!("Failed to get domainname"); - } - - let actual_domainname_cstr = - unsafe { CStr::from_ptr(actual_domainname.as_ptr() as *mut i8) }; - if actual_domainname_cstr.to_str().unwrap() != expected_domainname { + let uname_info = utsname::uname().unwrap(); + let actual_domainname = uname_info.domainname(); + if actual_domainname.to_str().unwrap() != expected_domainname { eprintln!( "Unexpected domainname, expected: {:?} found: {:?}", expected_domainname, - actual_domainname_cstr.to_str().unwrap() + actual_domainname.to_str().unwrap() ); } }