From a9ba18d48c4980ecb7c4f243c73a08d4c7f7509e Mon Sep 17 00:00:00 2001 From: Ruoqing He Date: Tue, 9 Sep 2025 04:20:19 +0000 Subject: [PATCH 1/4] libs: Fix test_execute_hook test Case 4 of `test_execute_hook` would fail because `args` could not be empty, while by providing `build_oci_hook` with `vec![]` would result in empty args at execution stage. Modify `build_oci_hook` to set args as `None` when empty vector is provided. Signed-off-by: Ruoqing He --- src/libs/kata-sys-util/src/hooks.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libs/kata-sys-util/src/hooks.rs b/src/libs/kata-sys-util/src/hooks.rs index 8dea2e499f..3fdd5c0138 100644 --- a/src/libs/kata-sys-util/src/hooks.rs +++ b/src/libs/kata-sys-util/src/hooks.rs @@ -375,7 +375,11 @@ mod tests { fn build_oci_hook(self) -> oci::Hook { let mut hook = oci::Hook::default(); hook.set_path(PathBuf::from(self.path)); - hook.set_args(Some(self.args)); + if self.args.is_empty() { + hook.set_args(None); + } else { + hook.set_args(Some(self.args)); + } hook.set_env(Some(self.env)); hook.set_timeout(self.timeout); From efeba0b8edf42c733ac9f809f5778857c54fdb7c Mon Sep 17 00:00:00 2001 From: Ruoqing He Date: Wed, 10 Sep 2025 07:00:33 +0000 Subject: [PATCH 2/4] libs: Detect guest protection before testing `test_arch_guest_protection_*` test cases get triggered simultaneously, which is impossible for a single machine to pass. Modify tests to detect protection file before preceding. Signed-off-by: Ruoqing He --- src/libs/kata-sys-util/src/protection.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libs/kata-sys-util/src/protection.rs b/src/libs/kata-sys-util/src/protection.rs index 33695e00d4..4ce83c61c6 100644 --- a/src/libs/kata-sys-util/src/protection.rs +++ b/src/libs/kata-sys-util/src/protection.rs @@ -216,6 +216,11 @@ mod tests { // Test snp let dir = tempdir().unwrap(); let snp_file_path = dir.path().join("sev_snp"); + if !snp_file_path.exists() { + println!("INFO: skipping {} which needs sev_snp", module_path!()); + return; + } + let path = snp_file_path.clone(); let mut snp_file = fs::File::create(snp_file_path).unwrap(); writeln!(snp_file, "Y").unwrap(); @@ -235,6 +240,11 @@ mod tests { // Test sev let dir = tempdir().unwrap(); let sev_file_path = dir.path().join("sev"); + if !sev_file_path.exists() { + println!("INFO: skipping {} which needs sev", module_path!()); + return; + } + let sev_path = sev_file_path.clone(); let mut sev_file = fs::File::create(sev_file_path).unwrap(); writeln!(sev_file, "Y").unwrap(); @@ -257,6 +267,11 @@ mod tests { let invalid_dir = invalid_dir.to_str().unwrap(); let tdx_file_path = dir.path().join("tdx"); + if !tdx_file_path.exists() { + println!("INFO: skipping {} which needs tdx", module_path!()); + return; + } + let tdx_path = tdx_file_path; std::fs::create_dir_all(tdx_path.clone()).unwrap(); From b10e5a2250f726348372b594ae4c77c6ab746fe8 Mon Sep 17 00:00:00 2001 From: Ruoqing He Date: Wed, 10 Sep 2025 07:50:27 +0000 Subject: [PATCH 3/4] libs: Fix test_get_uds_with_sid_ok Preset directory `kata98654sandboxpath1` will produce more than one `target_id` in `get_uds_with_sid`, which causes test to fail. Remove that directory to make this test work. Signed-off-by: Ruoqing He --- src/libs/shim-interface/src/lib.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/libs/shim-interface/src/lib.rs b/src/libs/shim-interface/src/lib.rs index 46ebe21027..9bc607442a 100644 --- a/src/libs/shim-interface/src/lib.rs +++ b/src/libs/shim-interface/src/lib.rs @@ -138,10 +138,8 @@ mod tests { #[test] fn test_get_uds_with_sid_ok() { let run_path = tempdir().unwrap(); - let dir1 = run_path.path().join("kata98654sandboxpath1"); - let dir2 = run_path.path().join("aata98654dangboxpath1"); - fs::create_dir_all(dir1.as_path()).unwrap(); - fs::create_dir_all(dir2.as_path()).unwrap(); + let dir = run_path.path().join("aata98654dangboxpath1"); + fs::create_dir_all(dir.as_path()).unwrap(); let result = get_uds_with_sid("kata", &run_path.path().display().to_string()); assert!(result.is_ok()); @@ -151,7 +149,7 @@ mod tests { "unix://{}", run_path .path() - .join("kata98654sandboxpath1") + .join("kata") .join(SHIM_MGMT_SOCK_NAME) .display() ) From f6e93c20944ee9d8f6bab99f21834d6b13c600c1 Mon Sep 17 00:00:00 2001 From: Ruoqing He Date: Wed, 10 Sep 2025 08:13:01 +0000 Subject: [PATCH 4/4] libs: Fix test_get_uds_with_sid_with_zero Test case for `get_uds_with_sid` with an empty run directory would not hit the 0 match arm, i.e. "sandbox with the provided prefix {short_id:?} is not found", because `get_uds_with_sid` will try to create the directory with provided short id before detecting `target_id`. Signed-off-by: Ruoqing He --- src/libs/shim-interface/src/lib.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/libs/shim-interface/src/lib.rs b/src/libs/shim-interface/src/lib.rs index 9bc607442a..2863b84e2b 100644 --- a/src/libs/shim-interface/src/lib.rs +++ b/src/libs/shim-interface/src/lib.rs @@ -158,21 +158,20 @@ mod tests { #[test] fn test_get_uds_with_sid_with_zero() { - let result = get_uds_with_sid("acdsdfe", KATA_PATH); - assert!(result.is_err()); - if let Err(err) = result { - let left = format!("{:?}", err.to_string()); - let left_unquoted = &left[1..left.len() - 1]; - let left_unescaped = left_unquoted.replace("\\\"", "\""); - - assert_eq!( - left_unescaped, - format!( - "sandbox with the provided prefix {:?} is not found", - "acdsdfe" - ) + let run_path = tempdir().unwrap(); + let result = get_uds_with_sid("acdsdfe", &run_path.path().display().to_string()); + assert!(result.is_ok()); + assert_eq!( + result.unwrap(), + format!( + "unix://{}", + run_path + .path() + .join("acdsdfe") + .join(SHIM_MGMT_SOCK_NAME) + .display() ) - } + ) } #[test]